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

Commit 750fbd7

Browse files
committed
SORMAS-Foundation#1999 add comment lines to template + move import to 'campaign data' screen
1 parent 5a14390 commit 750fbd7

6 files changed

Lines changed: 904 additions & 876 deletions

File tree

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

Lines changed: 99 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -37,97 +37,103 @@
3737
*/
3838
public class ImportColumn {
3939

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-
}
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 ImportColumn(String columnName, String caption, String dataDescription) {
56+
this.columnName = columnName;
57+
this.caption = caption;
58+
this.dataDescription = dataDescription;
59+
}
60+
61+
public String getEntityName() {
62+
return entityName;
63+
}
64+
65+
public String getColumnName() {
66+
return columnName;
67+
}
68+
69+
public String getCaption() {
70+
return caption;
71+
}
72+
73+
public String getDataDescription() {
74+
return dataDescription;
75+
}
76+
77+
public static ImportColumn from(Class<?> entityType, String columnName, Class<?> fieldType, char currentSeparator) {
78+
String entityName = DataHelper.getHumanClassName(entityType);
79+
String caption = computeCaption(entityName, columnName);
80+
String dataType = computeDataType(fieldType, currentSeparator);
81+
return new ImportColumn(entityName, columnName, caption, dataType);
82+
}
83+
84+
/**
85+
* Computes the captions based on the entity name and column name.
86+
* <p/>
87+
* Column name is composed (ex: <code>person.firstName</code> or <code>person.address.city</code>)
88+
* -> Split it in parts and use the last part as field name
89+
* -> Combine the entity name with the field name
90+
* <p/>
91+
* Column name is simple (ex: <code>diseaseDetails</code>) -> Combine the entity name with the column name
92+
* <p/>
93+
* The result is a list with the same length as the <code>columnNames</code>
94+
*
95+
* @param entityName name of the entity from which the field is part of
96+
* @param columnName column name from the CSV
97+
* @return list of captions for each column name.
98+
*/
99+
private static String computeCaption(String entityName, String columnName) {
100+
if (StringUtils.contains(columnName, ".")) {
101+
String[] parts = columnName.split("\\.");
102+
String fieldName = parts[parts.length - 1];
103+
return I18nProperties.getPrefixCaption(entityName, fieldName);
104+
} else {
105+
return I18nProperties.getPrefixCaption(entityName, columnName);
106+
}
107+
}
108+
109+
/**
110+
* 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}).
111+
*
112+
* @param fieldType type of a CSV field (column)
113+
* @param currentSeparator current CSV configured separator, used to identify a different one for joining lists
114+
* @return a data type description, example or placeholder
115+
*/
116+
private static String computeDataType(Class<?> fieldType, char currentSeparator) {
117+
char separator = ImportExportUtils.getCSVSeparatorDifferentFromCurrent(currentSeparator);
118+
119+
if (String.class.isAssignableFrom(fieldType)) {
120+
return I18nProperties.getString(Strings.text);
121+
} else if (Date.class.isAssignableFrom(fieldType)) {
122+
return I18nProperties.getString(Strings.date) + ": dd/MM/yyyy";
123+
} else if (ReferenceDto.class.isAssignableFrom(fieldType)) {
124+
return String.format(I18nProperties.getString(Strings.nameOf), DataHelper.getHumanClassName(fieldType));
125+
} else if (Disease.class.isAssignableFrom(fieldType)) {
126+
return ImportFacade.ACTIVE_DISEASES_PLACEHOLDER;
127+
} else if (fieldType.isEnum()) {
128+
List<String> enumNames = new ArrayList<>();
129+
for (Object enumConstant : fieldType.getEnumConstants()) {
130+
enumNames.add(((Enum<?>) enumConstant).name());
131+
}
132+
return StringUtils.join(enumNames, separator);
133+
} else if (Number.class.isAssignableFrom(fieldType)) {
134+
return I18nProperties.getString(Strings.number);
135+
} else {
136+
return "";
137+
}
138+
}
133139
}

0 commit comments

Comments
 (0)