use of de.symeda.sormas.api.importexport.ImportColumn in project SORMAS-Project by hzi-braunschweig.
the class ImportFacadeEjb method generatePopulationDataImportTemplateFile.
@Override
public void generatePopulationDataImportTemplateFile() throws IOException {
createExportDirectoryIfNecessary();
char separator = configFacade.getCsvSeparator();
List<ImportColumn> importColumns = new ArrayList<>();
importColumns.add(ImportColumn.from(PopulationDataDto.class, PopulationDataDto.REGION, RegionReferenceDto.class, separator));
importColumns.add(ImportColumn.from(PopulationDataDto.class, PopulationDataDto.DISTRICT, DistrictReferenceDto.class, separator));
importColumns.add(ImportColumn.from(PopulationDataDto.class, PopulationDataDto.COMMUNITY, CommunityReferenceDto.class, separator));
importColumns.add(ImportColumn.from(RegionDto.class, RegionDto.GROWTH_RATE, Float.class, separator));
importColumns.add(ImportColumn.from(PopulationDataDto.class, "TOTAL", Integer.class, separator));
importColumns.add(ImportColumn.from(PopulationDataDto.class, "MALE_TOTAL", Integer.class, separator));
importColumns.add(ImportColumn.from(PopulationDataDto.class, "FEMALE_TOTAL", Integer.class, separator));
importColumns.add(ImportColumn.from(PopulationDataDto.class, "OTHER_TOTAL", Integer.class, separator));
for (AgeGroup ageGroup : AgeGroup.values()) {
importColumns.add(ImportColumn.from(PopulationDataDto.class, "TOTAL_" + ageGroup.name(), Integer.class, separator));
importColumns.add(ImportColumn.from(PopulationDataDto.class, "MALE_" + ageGroup.name(), Integer.class, separator));
importColumns.add(ImportColumn.from(PopulationDataDto.class, "FEMALE_" + ageGroup.name(), Integer.class, separator));
importColumns.add(ImportColumn.from(PopulationDataDto.class, "OTHER_" + ageGroup.name(), Integer.class, separator));
}
writeTemplate(Paths.get(getPopulationDataImportTemplateFilePath()), importColumns, false);
}
use of de.symeda.sormas.api.importexport.ImportColumn in project SORMAS-Project by hzi-braunschweig.
the class ImportFacadeEjb method generateCampaignFormImportTemplateFile.
@Override
public void generateCampaignFormImportTemplateFile(String campaignFormUuid) throws IOException {
createExportDirectoryIfNecessary();
List<ImportColumn> importColumns = new ArrayList<>();
char separator = configFacade.getCsvSeparator();
/* importColumns.add(ImportColumn.from(CampaignFormDataDto.class, CAMPAIGN, CampaignReferenceDto.class, separator)); */
importColumns.add(ImportColumn.from(CampaignFormDataDto.class, FORM_DATE, Date.class, separator));
importColumns.add(ImportColumn.from(CampaignFormDataDto.class, REGION, RegionReferenceDto.class, separator));
importColumns.add(ImportColumn.from(CampaignFormDataDto.class, DISTRICT, DistrictReferenceDto.class, separator));
importColumns.add(ImportColumn.from(CampaignFormDataDto.class, COMMUNITY, CommunityReferenceDto.class, separator));
CampaignFormMetaDto campaignFormMetaDto = campaignFormMetaFacade.getCampaignFormMetaByUuid(campaignFormUuid);
campaignFormMetaDto.getCampaignFormElements().stream().filter(e -> !(CampaignFormElementType.SECTION.name().equalsIgnoreCase(e.getType()) || CampaignFormElementType.LABEL.name().equalsIgnoreCase(e.getType()))).forEach(formElement -> importColumns.add(new ImportColumn(formElement.getId(), formElement.getCaption(), formElement.getType())));
writeTemplate(Paths.get(getCampaignFormImportTemplateFilePath()), importColumns, false);
}
use of de.symeda.sormas.api.importexport.ImportColumn in project SORMAS-Project by hzi-braunschweig.
the class ImportFacadeEjb method writeTemplate.
/**
* Writes template files with the following lines:
* <ul>
* <li><code>entityNames</code> - only if <code>includeEntityNames</code> is <code>true</code></li>
* <li><code>columnNames</code> - represent the DTO properties that can be filled</li>
* <li><code>captions</code> - (commented) internationalized caption for each field</li>
* <li><code>dataDescription</code> - (commented) data examples or description for each field</li>
* </ul>
*
* @param templatePath
* path to write the template to
* @param importColumns
* details about each CSV column
* @param includeEntityNames
* weather to include the <code>entityNames</code> or not
* @throws IOException
*/
private void writeTemplate(Path templatePath, List<ImportColumn> importColumns, boolean includeEntityNames) throws IOException {
try (CSVWriter writer = CSVUtils.createCSVWriter(new OutputStreamWriter(new FileOutputStream(templatePath.toString()), StandardCharsets.UTF_8.newEncoder()), configFacade.getCsvSeparator())) {
if (includeEntityNames) {
writer.writeNext(importColumns.stream().map(ImportColumn::getEntityName).toArray(String[]::new));
}
writer.writeNext(importColumns.stream().map(ImportColumn::getColumnName).toArray(String[]::new));
writeCommentLine(writer, importColumns.stream().map(ImportColumn::getCaption).toArray(String[]::new));
writeCommentLine(writer, importColumns.stream().map(ImportColumn::getDataDescription).toArray(String[]::new));
writer.flush();
}
}
Aggregations