Skip to content
This repository was archived by the owner on May 5, 2021. It is now read-only.

Commit b47742e

Browse files
Merge branch 'development' of https://github.com/hzi-braunschweig/SORMAS-Project into 2902-fix_event_participant_save
2 parents b682051 + b5bcd46 commit b47742e

8 files changed

Lines changed: 74 additions & 25 deletions

File tree

sormas-api/src/main/java/de/symeda/sormas/api/i18n/Strings.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,6 @@ public interface Strings {
413413
String headingSetOutbreakStatus = "headingSetOutbreakStatus";
414414
String headingSignsAndSymptoms = "headingSignsAndSymptoms";
415415
String headingSomeEventsNotDeleted = "headingSomeEventsNotDeleted";
416-
String headingSourceContacts = "headingSourceContacts";
417416
String headingStoppedFollowUp = "headingStoppedFollowUp";
418417
String headingTasksDeleted = "headingTasksDeleted";
419418
String headingTemplateNotAvailable = "headingTemplateNotAvailable";

sormas-api/src/main/resources/strings.properties

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,6 @@ headingExtendFollowUp = Extend follow-up period
478478
headingExposureInvestigation = Exposure Investigation
479479
headingEpiDataSourceCaseContacts = Contacts with Source Case
480480
headingExposureDetails = Exposure Details
481-
headingSourceContacts = Source Contacts
482481
headingAnimalContactDetails = Animal Contact Details
483482
headingBurialDetails = Burial Details
484483

@@ -640,7 +639,7 @@ messageEventDearchived = Event has been de-archived
640639
messageEventParticipantCreated = New person created
641640
messageEventParticipantSaved = Person data saved
642641
messageEventParticipantsDeleted = All selected event participants have been deleted
643-
messageEventParticipantResponsibleJurisdictionUpdated = Changing or removing the responsible jurisdiction could make the current event participant read only or pseudonymized . Are you sure you want to continue?
642+
messageEventParticipantResponsibleJurisdictionUpdated = Changing or removing the responsible jurisdiction could make the current event participant read-only or pseudonymized. Are you sure you want to continue?
644643
messageEventSaved = Event data saved
645644
messageEventsArchived = All selected events have been archived
646645
messageEventsDearchived = All selected events have been de-archived

sormas-app/app/src/main/java/de/symeda/sormas/app/backend/common/DatabaseHelper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1757,7 +1757,8 @@ public void onUpgrade(SQLiteDatabase db, ConnectionSource connectionSource, int
17571757

17581758
case 245:
17591759
currentVersion = 245;
1760-
getDao(EpiData.class).executeRaw("ALTER TABLE epidata ADD COLUMN exposureDetailsKnown varchar(255);");
1760+
// Mistakenly added
1761+
//getDao(EpiData.class).executeRaw("ALTER TABLE epidata ADD COLUMN exposureDetailsKnown varchar(255);");
17611762

17621763
case 246:
17631764
currentVersion = 246;

sormas-ui/src/main/java/de/symeda/sormas/ui/caze/CaseGridDetailed.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ protected Stream<String> getPersonColumns() {
5050
Stream.of(
5151
CaseIndexDetailedDto.SEX,
5252
CaseIndexDetailedDto.AGE_AND_BIRTH_DATE,
53+
CaseIndexDetailedDto.POSTAL_CODE,
5354
CaseIndexDetailedDto.CITY,
5455
CaseIndexDetailedDto.STREET,
5556
CaseIndexDetailedDto.HOUSE_NUMBER,
5657
CaseIndexDetailedDto.ADDITIONAL_INFORMATION,
57-
CaseIndexDetailedDto.POSTAL_CODE,
5858
CaseIndexDetailedDto.PHONE));
5959
}
6060

@@ -66,11 +66,11 @@ protected void initColumns() {
6666

6767
getColumn(CaseIndexDetailedDto.SEX).setWidth(80);
6868
getColumn(CaseIndexDetailedDto.AGE_AND_BIRTH_DATE).setWidth(100);
69+
getColumn(CaseIndexDetailedDto.POSTAL_CODE).setWidth(100);
6970
getColumn(CaseIndexDetailedDto.CITY).setWidth(150);
7071
getColumn(CaseIndexDetailedDto.STREET).setWidth(150);
7172
getColumn(CaseIndexDetailedDto.HOUSE_NUMBER).setWidth(50);
7273
getColumn(CaseIndexDetailedDto.ADDITIONAL_INFORMATION).setWidth(200);
73-
getColumn(CaseIndexDetailedDto.POSTAL_CODE).setWidth(100);
7474
getColumn(CaseIndexDetailedDto.PHONE).setWidth(100);
7575
getColumn(CaseIndexDetailedDto.EVENT_COUNT).setWidth(80).setSortable(false);
7676
getColumn(CaseIndexDetailedDto.LATEST_EVENT_ID).setWidth(80).setSortable(false);

sormas-ui/src/main/java/de/symeda/sormas/ui/contact/ContactGridDetailed.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ protected Stream<String> getPersonColumns() {
4545
ContactIndexDetailedDto.SEX,
4646
ContactIndexDetailedDto.APPROXIMATE_AGE,
4747
ContactIndexDetailedDto.DISTRICT_NAME,
48+
ContactIndexDetailedDto.POSTAL_CODE,
4849
ContactIndexDetailedDto.CITY,
4950
ContactIndexDetailedDto.STREET,
5051
ContactIndexDetailedDto.HOUSE_NUMBER,
5152
ContactIndexDetailedDto.ADDITIONAL_INFORMATION,
52-
ContactIndexDetailedDto.POSTAL_CODE,
5353
ContactIndexDetailedDto.PHONE));
5454
}
5555

@@ -67,11 +67,11 @@ protected void initColumns() {
6767
getColumn(ContactIndexDetailedDto.SEX).setWidth(80);
6868
getColumn(ContactIndexDetailedDto.APPROXIMATE_AGE).setWidth(50);
6969
getColumn(ContactIndexDetailedDto.DISTRICT_NAME).setWidth(150);
70+
getColumn(ContactIndexDetailedDto.POSTAL_CODE).setWidth(100);
7071
getColumn(ContactIndexDetailedDto.CITY).setWidth(150);
7172
getColumn(ContactIndexDetailedDto.STREET).setWidth(150);
7273
getColumn(ContactIndexDetailedDto.HOUSE_NUMBER).setWidth(50);
7374
getColumn(ContactIndexDetailedDto.ADDITIONAL_INFORMATION).setWidth(200);
74-
getColumn(ContactIndexDetailedDto.POSTAL_CODE).setWidth(100);
7575
getColumn(ContactIndexDetailedDto.PHONE).setWidth(100);
7676
((Column<ContactIndexDetailedDto, CaseReferenceDto>) getColumn(ContactIndexDetailedDto.CAZE)).setWidth(150)
7777
.setRenderer(entry -> entry != null ? entry.getUuid() : null, new UuidRenderer());

sormas-ui/src/main/java/de/symeda/sormas/ui/contact/SourceContactListComponent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ private void createSourceContactListComponent(SourceContactList sourceContactLis
6464
addComponent(list);
6565
list.reload();
6666

67-
Label sourceContactsHeader = new Label(I18nProperties.getString(Strings.headingSourceContacts));
67+
Label sourceContactsHeader = new Label(I18nProperties.getString(Strings.headingEpiDataSourceCaseContacts));
6868
sourceContactsHeader.addStyleName(CssStyles.H3);
6969
componentHeader.addComponent(sourceContactsHeader);
7070

sormas-ui/src/main/java/de/symeda/sormas/ui/document/DocumentListComponent.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
import com.vaadin.ui.HorizontalLayout;
2929
import com.vaadin.ui.Label;
3030
import com.vaadin.ui.Notification;
31+
import com.vaadin.ui.Upload;
3132
import com.vaadin.ui.VerticalLayout;
3233
import com.vaadin.ui.themes.ValoTheme;
33-
import com.vaadin.v7.ui.Upload;
3434

3535
import de.symeda.sormas.api.FacadeProvider;
3636
import de.symeda.sormas.api.ReferenceDto;
@@ -96,11 +96,10 @@ private Button buildUploadButton() {
9696
uploadLayout.setWidth(250, Unit.PIXELS);
9797

9898
DocumentReceiver receiver = new DocumentReceiver(relatedEntityType, entityRef.getUuid(), this::reload);
99-
@SuppressWarnings("deprecation")
10099
Upload upload = new Upload("", receiver);
100+
receiver.setUpload(upload);
101101
upload.setButtonCaption(I18nProperties.getCaption(Captions.importImportData));
102102
CssStyles.style(upload, CssStyles.VSPACE_2);
103-
upload.addSucceededListener(receiver);
104103

105104
uploadLayout.addComponentsAndExpand(upload);
106105

sormas-ui/src/main/java/de/symeda/sormas/ui/importer/DocumentReceiver.java

Lines changed: 64 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,24 @@
1414
*/
1515
package de.symeda.sormas.ui.importer;
1616

17+
import java.io.BufferedOutputStream;
1718
import java.io.ByteArrayOutputStream;
1819
import java.io.File;
19-
import java.io.FileNotFoundException;
20-
import java.io.FileOutputStream;
2120
import java.io.IOException;
2221
import java.io.OutputStream;
2322
import java.nio.file.Files;
2423
import java.nio.file.Paths;
2524
import java.util.Date;
2625

26+
import org.slf4j.Logger;
27+
import org.slf4j.LoggerFactory;
28+
2729
import com.vaadin.server.Page;
2830
import com.vaadin.ui.Label;
2931
import com.vaadin.ui.Notification;
30-
import com.vaadin.v7.ui.Upload;
32+
import com.vaadin.ui.Upload;
33+
import com.vaadin.ui.Upload.FailedEvent;
34+
import com.vaadin.ui.Upload.StartedEvent;
3135

3236
import de.symeda.sormas.api.FacadeProvider;
3337
import de.symeda.sormas.api.document.DocumentDto;
@@ -41,13 +45,18 @@
4145
import de.symeda.sormas.ui.UserProvider;
4246
import de.symeda.sormas.ui.utils.VaadinUiUtil;
4347

44-
@SuppressWarnings("deprecation")
45-
public class DocumentReceiver implements com.vaadin.v7.ui.Upload.Receiver, com.vaadin.v7.ui.Upload.SucceededListener {
48+
public class DocumentReceiver
49+
implements Upload.Receiver, Upload.StartedListener, Upload.ProgressListener, Upload.SucceededListener, Upload.FailedListener {
50+
51+
private static final long serialVersionUID = 1L;
52+
private static final long MAX_CONTENT_LENGTH = 52_428_800L;
4653

54+
private final Logger logger = LoggerFactory.getLogger(getClass());
4755
private final DocumentRelatedEntityType relatedEntityType;
4856
private final String relatedEntityUuid;
4957
private final Runnable callback;
5058
private File file;
59+
private Upload upload;
5160

5261
public DocumentReceiver(DocumentRelatedEntityType relatedEntityType, String relatedEntityUuid, Runnable callback) {
5362
this.relatedEntityType = relatedEntityType;
@@ -57,7 +66,6 @@ public DocumentReceiver(DocumentRelatedEntityType relatedEntityType, String rela
5766

5867
@Override
5968
public OutputStream receiveUpload(String fileName, String mimeType) {
60-
final FileOutputStream fos;
6169
// Reject empty files
6270
if (fileName == null || fileName.isEmpty()) {
6371
file = null;
@@ -73,10 +81,12 @@ public OutputStream receiveUpload(String fileName, String mimeType) {
7381
try {
7482
String newFileName = ImportExportUtils.TEMP_FILE_PREFIX + "_document_upload" + DateHelper.formatDateForExport(new Date()) + "_"
7583
+ DataHelper.getShortUuid(UserProvider.getCurrent().getUuid());
76-
file = new File(Paths.get(FacadeProvider.getConfigFacade().getTempFilesPath()).resolve(newFileName).toString());
77-
fos = new FileOutputStream(file);
78-
} catch (FileNotFoundException e) {
79-
file = null;
84+
file = Paths.get(FacadeProvider.getConfigFacade().getTempFilesPath()).resolve(newFileName).toFile();
85+
return new BufferedOutputStream(Files.newOutputStream(file.toPath()));
86+
87+
} catch (IOException e) {
88+
deleteFile();
89+
logger.error(e.getMessage(), e);
8090
new Notification(
8191
I18nProperties.getString(Strings.headingImportError),
8292
I18nProperties.getString(Strings.messageImportError),
@@ -85,12 +95,28 @@ public OutputStream receiveUpload(String fileName, String mimeType) {
8595
// Workaround because returning null here throws an uncatchable UploadException
8696
return new ByteArrayOutputStream();
8797
}
98+
}
8899

89-
return fos;
100+
@Override
101+
public void uploadStarted(StartedEvent event) {
102+
if (event.getContentLength() > MAX_CONTENT_LENGTH) {
103+
event.getUpload().interruptUpload();
104+
new Notification(I18nProperties.getString(Strings.headingImportFailed), "", Notification.Type.ERROR_MESSAGE, false)
105+
.show(Page.getCurrent());
106+
}
107+
}
108+
109+
@Override
110+
public void updateProgress(long readBytes, long contentLength) {
111+
if (contentLength < 0 && Math.max(readBytes, contentLength) > MAX_CONTENT_LENGTH) {
112+
upload.interruptUpload();
113+
new Notification(I18nProperties.getString(Strings.headingImportFailed), "", Notification.Type.ERROR_MESSAGE, false)
114+
.show(Page.getCurrent());
115+
}
90116
}
91117

92118
@Override
93-
public void uploadSucceeded(com.vaadin.v7.ui.Upload.SucceededEvent succeededEvent) {
119+
public void uploadSucceeded(Upload.SucceededEvent succeededEvent) {
94120
if (file == null) {
95121
return;
96122
}
@@ -108,13 +134,20 @@ public void uploadSucceeded(com.vaadin.v7.ui.Upload.SucceededEvent succeededEven
108134
if (ok) {
109135
FacadeProvider.getDocumentFacade().deleteDocument(existing);
110136
saveDocument(succeededEvent);
137+
} else {
138+
deleteFile();
111139
}
112140
});
113141
} else {
114142
saveDocument(succeededEvent);
115143
}
116144
}
117145

146+
@Override
147+
public void uploadFailed(FailedEvent event) {
148+
deleteFile();
149+
}
150+
118151
private void saveDocument(Upload.SucceededEvent succeededEvent) {
119152
try {
120153
DocumentDto document = DocumentDto.build();
@@ -133,8 +166,26 @@ private void saveDocument(Upload.SucceededEvent succeededEvent) {
133166
I18nProperties.getString(Strings.headingUploadSuccess),
134167
I18nProperties.getString(Strings.messageUploadSuccessful));
135168
} catch (IOException | IllegalArgumentException e) {
136-
new Notification(I18nProperties.getString(Strings.headingImportFailed), e.getMessage(), Notification.Type.ERROR_MESSAGE, false)
169+
logger.error(e.getMessage(), e);
170+
new Notification(I18nProperties.getString(Strings.headingImportFailed), "", Notification.Type.ERROR_MESSAGE, false)
137171
.show(Page.getCurrent());
172+
} finally {
173+
deleteFile();
138174
}
139175
}
176+
177+
private void deleteFile() {
178+
if (file != null) {
179+
file.delete();
180+
file = null;
181+
}
182+
}
183+
184+
public void setUpload(Upload upload) {
185+
this.upload = upload;
186+
upload.addStartedListener(this);
187+
upload.addProgressListener(this);
188+
upload.addSucceededListener(this);
189+
upload.addFailedListener(this);
190+
}
140191
}

0 commit comments

Comments
 (0)