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

Commit 764ad67

Browse files
author
Martin Wahnschaffe
authored
Merge pull request SORMAS-Foundation#3000 from hzi-braunschweig/feature-1999-import-campaign-form-data
Feature 1999 import campaign form data
2 parents 0d32d96 + 5def247 commit 764ad67

16 files changed

Lines changed: 765 additions & 308 deletions

File tree

sormas-api/src/main/java/de/symeda/sormas/api/campaign/data/CampaignFormDataDto.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@
2020

2121
package de.symeda.sormas.api.campaign.data;
2222

23+
import java.util.Date;
24+
import java.util.List;
25+
2326
import de.symeda.sormas.api.EntityDto;
27+
import de.symeda.sormas.api.ImportIgnore;
2428
import de.symeda.sormas.api.campaign.CampaignReferenceDto;
2529
import de.symeda.sormas.api.campaign.form.CampaignFormMetaReferenceDto;
2630
import de.symeda.sormas.api.region.CommunityReferenceDto;
@@ -29,9 +33,6 @@
2933
import de.symeda.sormas.api.user.UserReferenceDto;
3034
import de.symeda.sormas.api.utils.DataHelper;
3135

32-
import java.util.Date;
33-
import java.util.List;
34-
3536
public class CampaignFormDataDto extends EntityDto {
3637

3738
private static final long serialVersionUID = -8087195060395038093L;
@@ -71,6 +72,12 @@ public static CampaignFormDataDto build(
7172
return campaignFormData;
7273
}
7374

75+
public static CampaignFormDataDto build() {
76+
CampaignFormDataDto campaignFormData = new CampaignFormDataDto();
77+
campaignFormData.setUuid(DataHelper.createUuid());
78+
return campaignFormData;
79+
}
80+
7481
public List<CampaignFormDataEntry> getFormValues() {
7582
return formValues;
7683
}
@@ -79,6 +86,7 @@ public void setFormValues(List<CampaignFormDataEntry> formValues) {
7986
this.formValues = formValues;
8087
}
8188

89+
@ImportIgnore
8290
public CampaignFormMetaReferenceDto getCampaignFormMeta() {
8391
return campaignFormMeta;
8492
}
@@ -87,6 +95,7 @@ public void setCampaignFormMeta(CampaignFormMetaReferenceDto campaignFormMeta) {
8795
this.campaignFormMeta = campaignFormMeta;
8896
}
8997

98+
@ImportIgnore
9099
public CampaignReferenceDto getCampaign() {
91100
return campaign;
92101
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ public interface Strings {
357357
String headingSamplesDeleted = "headingSamplesDeleted";
358358
String headingSaveNotification = "headingSaveNotification";
359359
String headingSaveUser = "headingSaveUser";
360+
String headingSelectCampaign = "headingSelectCampaign";
360361
String headingSelectSourceCase = "headingSelectSourceCase";
361362
String headingSetOutbreakStatus = "headingSetOutbreakStatus";
362363
String headingSignsAndSymptoms = "headingSignsAndSymptoms";

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public interface Validations {
6262
String importRegionAlreadyExists = "importRegionAlreadyExists";
6363
String importRegionNotUnique = "importRegionNotUnique";
6464
String importUnexpectedError = "importUnexpectedError";
65+
String importWrongDataTypeError = "importWrongDataTypeError";
6566
String investigationStatusUnclassifiedCase = "investigationStatusUnclassifiedCase";
6667
String noCommunityInDistrict = "noCommunityInDistrict";
6768
String noDistrictInRegion = "noDistrictInRegion";

sormas-api/src/main/java/de/symeda/sormas/api/importexport/ImportColumn.java

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,31 @@
11
/*
22
* SORMAS® - Surveillance Outbreak Response Management & Analysis System
33
* Copyright © 2016-2020 Helmholtz-Zentrum für Infektionsforschung GmbH (HZI)
4-
*
54
* This program is free software: you can redistribute it and/or modify
65
* it under the terms of the GNU General Public License as published by
76
* the Free Software Foundation, either version 3 of the License, or
87
* (at your option) any later version.
9-
*
108
* This program is distributed in the hope that it will be useful,
119
* but WITHOUT ANY WARRANTY; without even the implied warranty of
1210
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1311
* GNU General Public License for more details.
14-
*
1512
* You should have received a copy of the GNU General Public License
1613
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1714
*/
1815

1916
package de.symeda.sormas.api.importexport;
2017

18+
import java.util.ArrayList;
19+
import java.util.Date;
20+
import java.util.List;
21+
22+
import org.apache.commons.lang3.StringUtils;
23+
2124
import de.symeda.sormas.api.Disease;
2225
import de.symeda.sormas.api.ReferenceDto;
2326
import de.symeda.sormas.api.i18n.I18nProperties;
2427
import de.symeda.sormas.api.i18n.Strings;
2528
import de.symeda.sormas.api.utils.DataHelper;
26-
import org.apache.commons.lang3.StringUtils;
27-
28-
import java.util.ArrayList;
29-
import java.util.Date;
30-
import java.util.List;
3129

3230
/**
3331
* Detailed import template column entity with information like entity name, column name, caption and data type.
@@ -52,6 +50,12 @@ private ImportColumn(String entityName, String columnName, String caption, Strin
5250
this.dataDescription = dataDescription;
5351
}
5452

53+
public ImportColumn(String columnName, String caption, String dataDescription) {
54+
this.columnName = columnName;
55+
this.caption = caption;
56+
this.dataDescription = dataDescription;
57+
}
58+
5559
public String getEntityName() {
5660
return entityName;
5761
}
@@ -86,8 +90,10 @@ public static ImportColumn from(Class<?> entityType, String columnName, Class<?>
8690
* <p/>
8791
* The result is a list with the same length as the <code>columnNames</code>
8892
*
89-
* @param entityName name of the entity from which the field is part of
90-
* @param columnName column name from the CSV
93+
* @param entityName
94+
* name of the entity from which the field is part of
95+
* @param columnName
96+
* column name from the CSV
9197
* @return list of captions for each column name.
9298
*/
9399
private static String computeCaption(String entityName, String columnName) {
@@ -101,10 +107,13 @@ private static String computeCaption(String entityName, String columnName) {
101107
}
102108

103109
/**
104-
* Computes the data type accepted for a certain field type. For values which cannot be determined at start a placeholder will be used (ex: {@link ImportFacade#ACTIVE_DISEASES_PLACEHOLDER}).
110+
* Computes the data type accepted for a certain field type. For values which cannot be determined at start a placeholder will be used
111+
* (ex: {@link ImportFacade#ACTIVE_DISEASES_PLACEHOLDER}).
105112
*
106-
* @param fieldType type of a CSV field (column)
107-
* @param currentSeparator current CSV configured separator, used to identify a different one for joining lists
113+
* @param fieldType
114+
* type of a CSV field (column)
115+
* @param currentSeparator
116+
* current CSV configured separator, used to identify a different one for joining lists
108117
* @return a data type description, example or placeholder
109118
*/
110119
private static String computeDataType(Class<?> fieldType, char currentSeparator) {
@@ -115,7 +124,7 @@ private static String computeDataType(Class<?> fieldType, char currentSeparator)
115124
} else if (Date.class.isAssignableFrom(fieldType)) {
116125
return I18nProperties.getString(Strings.date) + ": dd/MM/yyyy";
117126
} else if (ReferenceDto.class.isAssignableFrom(fieldType)) {
118-
return String.format(I18nProperties.getString(Strings.nameOf), DataHelper.getHumanClassName(fieldType));
127+
return String.format(I18nProperties.getString(Strings.nameOf), DataHelper.getHumanClassCaption(fieldType));
119128
} else if (Disease.class.isAssignableFrom(fieldType)) {
120129
return ImportFacade.ACTIVE_DISEASES_PLACEHOLDER;
121130
} else if (fieldType.isEnum()) {

sormas-api/src/main/java/de/symeda/sormas/api/importexport/ImportFacade.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public interface ImportFacade {
3333
*/
3434
void generateCaseImportTemplateFile() throws IOException;
3535

36+
void generateCampaignFormImportTemplateFile(String campaignFormUuid) throws IOException;
37+
3638
void generateCaseContactImportTemplateFile() throws IOException;
3739

3840
void generateCaseLineListingImportTemplateFile() throws IOException;
@@ -55,6 +57,8 @@ public interface ImportFacade {
5557

5658
String getCaseImportTemplateFilePath();
5759

60+
String getCampaignFormImportTemplateFilePath();
61+
5862
String getPointOfEntryImportTemplateFilePath();
5963

6064
String getPopulationDataImportTemplateFilePath();

sormas-api/src/main/java/de/symeda/sormas/api/utils/DataHelper.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@ public static String capitalize(String input) {
206206
return input.substring(0, 1).toUpperCase() + input.substring(1);
207207
}
208208

209+
public static String lowercaseFirst(String input) {
210+
return input.substring(0, 1).toLowerCase() + input.substring(1);
211+
}
212+
209213
public static BigDecimal getTruncatedBigDecimal(BigDecimal number) {
210214
return number.remainder(BigDecimal.ONE).compareTo(BigDecimal.ZERO) == 0 ? number.setScale(0, RoundingMode.HALF_UP) : number;
211215
}
@@ -299,6 +303,15 @@ public static String getHumanClassName(Class<?> classType) {
299303
return className;
300304
}
301305

306+
public static String getHumanClassCaption(Class<?> classType) {
307+
308+
String className = classType.getSimpleName();
309+
className = className.replaceAll("Dto$", "");
310+
className = className.replaceAll("Reference$", "");
311+
I18nProperties.getCaption(DataHelper.lowercaseFirst(className), className);
312+
return className;
313+
}
314+
302315
/**
303316
* @return null when NumberFormatException is thrown
304317
*/

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ headingRequestedPathogenTests = Requested pathogen tests:
368368
headingResults = Results
369369
headingSamplesDeleted = Samples deleted
370370
headingSaveNotification = Save notification
371+
headingSelectCampaign = Select a campaign
371372
headingSetOutbreakStatus = Set status of all districts:
372373
headingSignsAndSymptoms = Clinical Signs and Symptoms
373374
headingTasksDeleted = Tasks deleted

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ importCasesPropertyTypeNotAllowed = Property type %s not allowed when importing
2727
importPropertyTypeNotAllowed = Property type %s not allowed
2828
importCasesUnexpectedError = Unexpected error when trying to import this case. Please send your error report file to an administrator and remove this case from your import file.
2929
importUnexpectedError = Unexpected error when trying to import this row. Please send your error report file to an administrator and remove this row from your import file.
30+
importWrongDataTypeError = Value %s in column %s does not match expected data type.
3031
importCommunityNotUnique = Invalid value %s in column %s; Community name is not unique in the chosen district, make sure there is only one community with this name belonging to the chosen district in the database
3132
importDistrictNotUnique = Invalid value %s in column %s; District name is not unique in the chosen region, make sure there is only one district with this name belonging to the chosen region in the database
3233
importEntryDoesNotExist = Invalid value %s in column %s; Entry does not exist in the database or is archived

sormas-api/src/test/java/de/symeda/sormas/api/utils/DataHelperTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import de.symeda.sormas.api.Disease;
99
import de.symeda.sormas.api.caze.CaseDataDto;
10+
import de.symeda.sormas.api.region.RegionReferenceDto;
1011

1112
public class DataHelperTest {
1213

@@ -15,6 +16,7 @@ public void testGetHumanClassName() {
1516

1617
assertEquals("CaseData", DataHelper.getHumanClassName(CaseDataDto.class));
1718
assertEquals("Disease", DataHelper.getHumanClassName(Disease.class));
19+
assertEquals("RegionReference", DataHelper.getHumanClassName(RegionReferenceDto.class));
1820
}
1921

2022
@Test

0 commit comments

Comments
 (0)