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

Commit ce3265b

Browse files
author
Martin Wahnschaffe
authored
Merge pull request SORMAS-Foundation#2930 from hzi-braunschweig/2537_import-template-information
2537 import template information
2 parents 0d3a520 + 3d7fe24 commit ce3265b

100 files changed

Lines changed: 1056 additions & 214 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ public interface Captions {
111111
String aggregateReportReportFound = "aggregateReportReportFound";
112112
String aggregateReportThisWeek = "aggregateReportThisWeek";
113113
String all = "all";
114+
String Area_archived = "Area.archived";
114115
String Area_externalId = "Area.externalId";
115116
String areaActiveAreas = "areaActiveAreas";
116117
String areaAllAreas = "areaAllAreas";
@@ -366,6 +367,7 @@ public interface Captions {
366367
String columnDiseaseShort = "columnDiseaseShort";
367368
String columnNumberOfPendingTasks = "columnNumberOfPendingTasks";
368369
String community = "community";
370+
String Community_archived = "Community.archived";
369371
String Community_externalID = "Community.externalID";
370372
String communityActiveCommunities = "communityActiveCommunities";
371373
String communityAllCommunities = "communityAllCommunities";
@@ -443,6 +445,9 @@ public interface Captions {
443445
String Contact_relationToCase = "Contact.relationToCase";
444446
String Contact_reportDateTime = "Contact.reportDateTime";
445447
String Contact_reportingUser = "Contact.reportingUser";
448+
String Contact_reportLat = "Contact.reportLat";
449+
String Contact_reportLatLonAccuracy = "Contact.reportLatLonAccuracy";
450+
String Contact_reportLon = "Contact.reportLon";
446451
String Contact_resultingCase = "Contact.resultingCase";
447452
String Contact_resultingCaseUser = "Contact.resultingCaseUser";
448453
String Contact_tracingApp = "Contact.tracingApp";
@@ -646,6 +651,7 @@ public interface Captions {
646651
String DiseaseBurden_outbreakDistrictCount = "DiseaseBurden.outbreakDistrictCount";
647652
String DiseaseBurden_previousCaseCount = "DiseaseBurden.previousCaseCount";
648653
String district = "district";
654+
String District_archived = "District.archived";
649655
String District_epidCode = "District.epidCode";
650656
String District_externalID = "District.externalID";
651657
String District_growthRate = "District.growthRate";
@@ -831,6 +837,7 @@ public interface Captions {
831837
String exportSamples = "exportSamples";
832838
String exportSelectSormasData = "exportSelectSormasData";
833839
String exportSormasData = "exportSormasData";
840+
String Facility_archived = "Facility.archived";
834841
String Facility_city = "Facility.city";
835842
String Facility_community = "Facility.community";
836843
String Facility_district = "Facility.district";
@@ -840,6 +847,7 @@ public interface Captions {
840847
String Facility_name = "Facility.name";
841848
String Facility_NO_FACILITY = "Facility.NO_FACILITY";
842849
String Facility_OTHER_FACILITY = "Facility.OTHER_FACILITY";
850+
String Facility_publicOwnership = "Facility.publicOwnership";
843851
String Facility_region = "Facility.region";
844852
String Facility_type = "Facility.type";
845853
String Facility_typeGroup = "Facility.typeGroup";
@@ -1123,6 +1131,7 @@ public interface Captions {
11231131
String PrescriptionExport_caseUuid = "PrescriptionExport.caseUuid";
11241132
String prescriptionNewPrescription = "prescriptionNewPrescription";
11251133
String region = "region";
1134+
String Region_archived = "Region.archived";
11261135
String Region_epidCode = "Region.epidCode";
11271136
String Region_externalID = "Region.externalID";
11281137
String Region_growthRate = "Region.growthRate";

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ public interface Strings {
107107
String confirmationRemoveUserAsOfficer = "confirmationRemoveUserAsOfficer";
108108
String confirmationUpdateCompleteness = "confirmationUpdateCompleteness";
109109
String confirmNetworkDiagramTooManyContacts = "confirmNetworkDiagramTooManyContacts";
110+
String date = "date";
110111
String day = "day";
111112
String DiseaseNetworkDiagram_Classification_HEALTHY = "DiseaseNetworkDiagram.Classification.HEALTHY";
112113
String DiseaseNetworkDiagram_heading = "DiseaseNetworkDiagram.heading";
@@ -654,6 +655,7 @@ public interface Strings {
654655
String min = "min";
655656
String mmhg = "mmhg";
656657
String month = "month";
658+
String nameOf = "nameOf";
657659
String no = "no";
658660
String none = "none";
659661
String notAnswered = "notAnswered";
@@ -690,6 +692,7 @@ public interface Strings {
690692
String notificationVisitCompleted = "notificationVisitCompleted";
691693
String notificationVisitCompletedSubject = "notificationVisitCompletedSubject";
692694
String notSpecified = "notSpecified";
695+
String number = "number";
693696
String numberEight = "numberEight";
694697
String numberEleven = "numberEleven";
695698
String numberFive = "numberFive";
@@ -751,6 +754,7 @@ public interface Strings {
751754
String reportedBy = "reportedBy";
752755
String reportedOn = "reportedOn";
753756
String step = "step";
757+
String text = "text";
754758
String toCase = "toCase";
755759
String total = "total";
756760
String unsavedChanges_discard = "unsavedChanges.discard";
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
/*
2+
* SORMAS® - Surveillance Outbreak Response Management & Analysis System
3+
* Copyright © 2016-2020 Helmholtz-Zentrum für Infektionsforschung GmbH (HZI)
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
19+
package de.symeda.sormas.api.importexport;
20+
21+
import de.symeda.sormas.api.Disease;
22+
import de.symeda.sormas.api.ReferenceDto;
23+
import de.symeda.sormas.api.i18n.I18nProperties;
24+
import de.symeda.sormas.api.i18n.Strings;
25+
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;
31+
32+
/**
33+
* Detailed import template column entity with information like entity name, column name, caption and data type.
34+
*
35+
* @author Alex Vidrean
36+
* @since 18-Sep-20
37+
*/
38+
public class ImportColumn {
39+
40+
private String entityName;
41+
42+
private String columnName;
43+
44+
private String caption;
45+
46+
private String dataDescription;
47+
48+
private ImportColumn(String entityName, String columnName, String caption, String dataDescription) {
49+
this.entityName = entityName;
50+
this.columnName = columnName;
51+
this.caption = caption;
52+
this.dataDescription = dataDescription;
53+
}
54+
55+
public String getEntityName() {
56+
return entityName;
57+
}
58+
59+
public String getColumnName() {
60+
return columnName;
61+
}
62+
63+
public String getCaption() {
64+
return caption;
65+
}
66+
67+
public String getDataDescription() {
68+
return dataDescription;
69+
}
70+
71+
public static ImportColumn from(Class<?> entityType, String columnName, Class<?> fieldType, char currentSeparator) {
72+
String entityName = DataHelper.getHumanClassName(entityType);
73+
String caption = computeCaption(entityName, columnName);
74+
String dataType = computeDataType(fieldType, currentSeparator);
75+
return new ImportColumn(entityName, columnName, caption, dataType);
76+
}
77+
78+
/**
79+
* Computes the captions based on the entity name and column name.
80+
* <p/>
81+
* Column name is composed (ex: <code>person.firstName</code> or <code>person.address.city</code>)
82+
* -> Split it in parts and use the last part as field name
83+
* -> Combine the entity name with the field name
84+
* <p/>
85+
* Column name is simple (ex: <code>diseaseDetails</code>) -> Combine the entity name with the column name
86+
* <p/>
87+
* The result is a list with the same length as the <code>columnNames</code>
88+
*
89+
* @param entityName name of the entity from which the field is part of
90+
* @param columnName column name from the CSV
91+
* @return list of captions for each column name.
92+
*/
93+
private static String computeCaption(String entityName, String columnName) {
94+
if (StringUtils.contains(columnName, ".")) {
95+
String[] parts = columnName.split("\\.");
96+
String fieldName = parts[parts.length - 1];
97+
return I18nProperties.getPrefixCaption(entityName, fieldName);
98+
} else {
99+
return I18nProperties.getPrefixCaption(entityName, columnName);
100+
}
101+
}
102+
103+
/**
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}).
105+
*
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
108+
* @return a data type description, example or placeholder
109+
*/
110+
private static String computeDataType(Class<?> fieldType, char currentSeparator) {
111+
char separator = ImportExportUtils.getCSVSeparatorDifferentFromCurrent(currentSeparator);
112+
113+
if (String.class.isAssignableFrom(fieldType)) {
114+
return I18nProperties.getString(Strings.text);
115+
} else if (Date.class.isAssignableFrom(fieldType)) {
116+
return I18nProperties.getString(Strings.date) + ": dd/MM/yyyy";
117+
} else if (ReferenceDto.class.isAssignableFrom(fieldType)) {
118+
return String.format(I18nProperties.getString(Strings.nameOf), DataHelper.getHumanClassName(fieldType));
119+
} else if (Disease.class.isAssignableFrom(fieldType)) {
120+
return ImportFacade.ACTIVE_DISEASES_PLACEHOLDER;
121+
} else if (fieldType.isEnum()) {
122+
List<String> enumNames = new ArrayList<>();
123+
for (Object enumConstant : fieldType.getEnumConstants()) {
124+
enumNames.add(((Enum<?>) enumConstant).name());
125+
}
126+
return StringUtils.join(enumNames, separator);
127+
} else if (Number.class.isAssignableFrom(fieldType)) {
128+
return I18nProperties.getString(Strings.number);
129+
} else {
130+
return "";
131+
}
132+
}
133+
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import de.symeda.sormas.api.caze.CaseExportDto;
3030
import de.symeda.sormas.api.utils.DataHelper.Pair;
3131
import de.symeda.sormas.api.utils.Order;
32+
import org.apache.commons.lang3.CharUtils;
3233

3334
public final class ImportExportUtils {
3435

@@ -84,4 +85,12 @@ private static int getOrderValue(Method method) {
8485
// XXX throw an exception ?
8586
return -1;
8687
}
88+
89+
public static char getCSVSeparatorDifferentFromCurrent(char currentSeparator) {
90+
char separator = ',';
91+
if (CharUtils.compare(',', currentSeparator) == 0) {
92+
separator = ';';
93+
}
94+
return separator;
95+
}
8796
}

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
@@ -24,6 +24,8 @@
2424
@Remote
2525
public interface ImportFacade {
2626

27+
String ACTIVE_DISEASES_PLACEHOLDER = "${activeDiseases}";
28+
2729
/**
2830
* Creates a .csv file with one row containing all relevant column names of the case entity
2931
* and its sub-entities and returns the path to the .csv file that can then be used to offer
@@ -72,4 +74,6 @@ public interface ImportFacade {
7274
String getCaseContactImportTemplateFilePath();
7375

7476
String getContactImportTemplateFilePath();
77+
78+
String getImportTemplateContent(String templateFilePath) throws IOException;
7579
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* SORMAS® - Surveillance Outbreak Response Management & Analysis System
3+
* Copyright © 2016-2020 Helmholtz-Zentrum für Infektionsforschung GmbH (HZI)
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
19+
package de.symeda.sormas.api.utils;
20+
21+
import com.opencsv.exceptions.CsvValidationException;
22+
import com.opencsv.validators.LineValidator;
23+
import org.apache.commons.lang3.StringUtils;
24+
25+
/**
26+
* CSV Line validator which fails whenever a line which starts with {@link #DEFAULT_COMMENT_LINE_PREFIX} is found.
27+
* Can be used to ignore commented CSV file lines.
28+
*
29+
* @author Alex Vidrean
30+
* @since 14-Sep-20
31+
*/
32+
public class CSVCommentLineValidator implements LineValidator {
33+
34+
public static final String DEFAULT_COMMENT_LINE_PREFIX = "##";
35+
36+
public static final String ERROR_MESSAGE = "comment";
37+
38+
@Override
39+
public boolean isValid(String line) {
40+
return StringUtils.isBlank(line) || !StringUtils.startsWith(line, DEFAULT_COMMENT_LINE_PREFIX);
41+
}
42+
43+
@Override
44+
public void validate(String line) throws CsvValidationException {
45+
if (!isValid(line)) {
46+
throw new CsvValidationException(ERROR_MESSAGE);
47+
}
48+
}
49+
}

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,27 @@
2424
import com.opencsv.CSVReader;
2525
import com.opencsv.CSVReaderBuilder;
2626
import com.opencsv.CSVWriter;
27+
import com.opencsv.validators.LineValidator;
28+
import org.apache.commons.lang3.ArrayUtils;
2729

2830
public final class CSVUtils {
2931

3032
private CSVUtils() {
3133
// Hide Utility Class Constructor
3234
}
3335

34-
public static CSVReader createCSVReader(Reader reader, char separator) {
35-
return new CSVReaderBuilder(reader).withCSVParser(new CSVParserBuilder().withSeparator(separator).build()).build();
36+
public static CSVReader createCSVReader(Reader reader, char separator, LineValidator ...lineValidators) {
37+
final CSVReaderBuilder builder = new CSVReaderBuilder(reader).withCSVParser(new CSVParserBuilder().withSeparator(separator).build());
38+
if (ArrayUtils.isNotEmpty(lineValidators)) {
39+
for(LineValidator lineValidator: lineValidators) {
40+
builder.withLineValidator(lineValidator);
41+
}
42+
}
43+
return builder.build();
3644
}
3745

3846
public static CSVWriter createCSVWriter(Writer writer, char separator) {
3947
return new CSVWriter(writer, separator, CSVWriter.DEFAULT_QUOTE_CHARACTER, CSVWriter.DEFAULT_ESCAPE_CHARACTER, CSVWriter.DEFAULT_LINE_END);
4048
}
49+
4150
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ AggregateReport.pointOfEntry=Point of Entry
162162
areaActiveAreas = Active areas
163163
areaArchivedAreas = Archived areas
164164
areaAllAreas = All areas
165+
Area.archived = Archived
165166
Area.externalId = External ID
166167

167168
# Bulk actions
@@ -439,6 +440,7 @@ columnDiseaseShort=Disease
439440
columnNumberOfPendingTasks=Pending tasks
440441

441442
# Community
443+
Community.archived=Archived
442444
Community.externalID=External ID
443445

444446
communityActiveCommunities=Active communities
@@ -530,6 +532,9 @@ Contact.relationDescription=Relationship description
530532
Contact.relationToCase=Relationship with case
531533
Contact.reportDateTime=Report date
532534
Contact.reportingUser=Reporting user
535+
Contact.reportLat=Report GPS latitude
536+
Contact.reportLon=Report GPS longitude
537+
Contact.reportLatLonAccuracy=Report GPS accuracy in m
533538
Contact.resultingCase=Resulting case
534539
Contact.resultingCaseUser=Resulting case assigned by
535540
Contact.uuid=Contact ID
@@ -732,6 +737,7 @@ districtActiveDistricts=Active districts
732737
districtArchivedDistricts=Archived districts
733738
districtAllDistricts=All districts
734739

740+
District.archived=Archived
735741
District.epidCode=Epid code
736742
District.growthRate=Growth rate
737743
District.population=Population
@@ -945,13 +951,15 @@ facilityAllFacilities=All facilities
945951
Facility.NO_FACILITY=Home or other place
946952
Facility.OTHER_FACILITY=Other facility
947953

954+
Facility.archived=Archived
948955
Facility.city=City
949956
Facility.community=Community
950957
Facility.district=District
951958
Facility.externalID=External ID
952959
Facility.latitude=Latitude
953960
Facility.longitude=Longitude
954961
Facility.name=Name
962+
Facility.publicOwnership=Public ownership
955963
Facility.region=Region
956964
Facility.type=Facility type
957965
Facility.typeGroup=Facility category
@@ -1255,6 +1263,7 @@ regionActiveRegions=Active regions
12551263
regionArchivedRegions=Archived regions
12561264
regionAllRegions=All regions
12571265

1266+
Region.archived=Archived
12581267
Region.epidCode=Epid code
12591268
Region.growthRate=Growth rate
12601269
Region.population=Population

0 commit comments

Comments
 (0)