Search in sources :

Example 1 with ImportColumn

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);
}
Also used : CommunityReferenceDto(de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) AgeGroup(de.symeda.sormas.api.AgeGroup) ArrayList(java.util.ArrayList) ImportColumn(de.symeda.sormas.api.importexport.ImportColumn) PopulationDataDto(de.symeda.sormas.api.infrastructure.PopulationDataDto) RegionDto(de.symeda.sormas.api.infrastructure.region.RegionDto) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto)

Example 2 with ImportColumn

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);
}
Also used : AreaDto(de.symeda.sormas.api.infrastructure.area.AreaDto) Arrays(java.util.Arrays) PlagueType(de.symeda.sormas.api.caze.PlagueType) CountryDto(de.symeda.sormas.api.infrastructure.country.CountryDto) PLAGUE_TYPE(de.symeda.sormas.api.caze.CaseDataDto.PLAGUE_TYPE) REPORT_DATE(de.symeda.sormas.api.caze.CaseDataDto.REPORT_DATE) DISTRICT(de.symeda.sormas.api.caze.CaseDataDto.DISTRICT) RESPONSIBLE_COMMUNITY(de.symeda.sormas.api.caze.CaseDataDto.RESPONSIBLE_COMMUNITY) StringUtils(org.apache.commons.lang3.StringUtils) PersonDto(de.symeda.sormas.api.person.PersonDto) EntityDto(de.symeda.sormas.api.EntityDto) COMMUNITY(de.symeda.sormas.api.caze.CaseDataDto.COMMUNITY) RESPONSIBLE_REGION(de.symeda.sormas.api.caze.CaseDataDto.RESPONSIBLE_REGION) Map(java.util.Map) Path(java.nio.file.Path) ConstraintViolation(javax.validation.ConstraintViolation) SubcontinentDto(de.symeda.sormas.api.infrastructure.subcontinent.SubcontinentDto) DENGUE_FEVER_TYPE(de.symeda.sormas.api.caze.CaseDataDto.DENGUE_FEVER_TYPE) CampaignFormElementType(de.symeda.sormas.api.campaign.form.CampaignFormElementType) RESPONSIBLE_DISTRICT(de.symeda.sormas.api.caze.CaseDataDto.RESPONSIBLE_DISTRICT) Set(java.util.Set) Validator(javax.validation.Validator) StandardCharsets(java.nio.charset.StandardCharsets) InvocationTargetException(java.lang.reflect.InvocationTargetException) RabiesType(de.symeda.sormas.api.caze.RabiesType) PropertyDescriptor(java.beans.PropertyDescriptor) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) CSVUtils(de.symeda.sormas.api.utils.CSVUtils) HEALTH_FACILITY(de.symeda.sormas.api.caze.CaseDataDto.HEALTH_FACILITY) ImportFacade(de.symeda.sormas.api.importexport.ImportFacade) PersonReferenceDto(de.symeda.sormas.api.person.PersonReferenceDto) RegionDto(de.symeda.sormas.api.infrastructure.region.RegionDto) ValidatorFactory(javax.validation.ValidatorFactory) EventGroupReferenceDto(de.symeda.sormas.api.event.EventGroupReferenceDto) CountryFacadeEjbLocal(de.symeda.sormas.backend.infrastructure.country.CountryFacadeEjb.CountryFacadeEjbLocal) ArrayList(java.util.ArrayList) PERSON(de.symeda.sormas.api.caze.CaseDataDto.PERSON) ImportIgnore(de.symeda.sormas.api.ImportIgnore) CASE_ORIGIN(de.symeda.sormas.api.caze.CaseDataDto.CASE_ORIGIN) LocalBean(javax.ejb.LocalBean) EnumService(de.symeda.sormas.backend.common.EnumService) ConfigFacadeEjbLocal(de.symeda.sormas.backend.common.ConfigFacadeEjb.ConfigFacadeEjbLocal) EJB(javax.ejb.EJB) DataHelper(de.symeda.sormas.api.utils.DataHelper) Files(java.nio.file.Files) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) FileOutputStream(java.io.FileOutputStream) UserFacadeEjbLocal(de.symeda.sormas.backend.user.UserFacadeEjb.UserFacadeEjbLocal) IOException(java.io.IOException) CSVWriter(com.opencsv.CSVWriter) CaseOrigin(de.symeda.sormas.api.caze.CaseOrigin) RABIES_TYPE(de.symeda.sormas.api.caze.CaseDataDto.RABIES_TYPE) Field(java.lang.reflect.Field) DengueFeverType(de.symeda.sormas.api.caze.DengueFeverType) Disease(de.symeda.sormas.api.Disease) ImportExportUtils(de.symeda.sormas.api.importexport.ImportExportUtils) SampleDto(de.symeda.sormas.api.sample.SampleDto) Paths(java.nio.file.Paths) AreaFacadeEjbLocal(de.symeda.sormas.backend.infrastructure.area.AreaFacadeEjb.AreaFacadeEjbLocal) FeatureTypeProperty(de.symeda.sormas.api.feature.FeatureTypeProperty) FieldVisibilityCheckers(de.symeda.sormas.api.utils.fieldvisibility.FieldVisibilityCheckers) POINT_OF_ENTRY_DETAILS(de.symeda.sormas.api.caze.CaseDataDto.POINT_OF_ENTRY_DETAILS) FeatureType(de.symeda.sormas.api.feature.FeatureType) Provider(javax.inject.Provider) Date(java.util.Date) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) URISyntaxException(java.net.URISyntaxException) LoggerFactory(org.slf4j.LoggerFactory) EventParticipantDto(de.symeda.sormas.api.event.EventParticipantDto) REGION(de.symeda.sormas.api.caze.CaseDataDto.REGION) HEALTH_FACILITY_DETAILS(de.symeda.sormas.api.caze.CaseDataDto.HEALTH_FACILITY_DETAILS) AgeGroup(de.symeda.sormas.api.AgeGroup) CommunityDto(de.symeda.sormas.api.infrastructure.community.CommunityDto) CountryReferenceDto(de.symeda.sormas.api.infrastructure.country.CountryReferenceDto) URI(java.net.URI) ParseException(java.text.ParseException) Method(java.lang.reflect.Method) PointOfEntryDto(de.symeda.sormas.api.infrastructure.pointofentry.PointOfEntryDto) Stateless(javax.ejb.Stateless) ConstrainValidationHelper(de.symeda.sormas.api.utils.ConstrainValidationHelper) DiseaseConfigurationFacadeEjbLocal(de.symeda.sormas.backend.disease.DiseaseConfigurationFacadeEjb.DiseaseConfigurationFacadeEjbLocal) CountryFacadeEjb(de.symeda.sormas.backend.infrastructure.country.CountryFacadeEjb) ImportLineResultDto(de.symeda.sormas.api.importexport.ImportLineResultDto) FacilityType(de.symeda.sormas.api.infrastructure.facility.FacilityType) Collection(java.util.Collection) Sex(de.symeda.sormas.api.person.Sex) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) Region(de.symeda.sormas.backend.infrastructure.region.Region) EventDto(de.symeda.sormas.api.event.EventDto) ImportErrorException(de.symeda.sormas.api.importexport.ImportErrorException) Collectors(java.util.stream.Collectors) CommunityReferenceDto(de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto) DISEASE(de.symeda.sormas.api.caze.CaseDataDto.DISEASE) List(java.util.List) ImportParserService(de.symeda.sormas.backend.importexport.parser.ImportParserService) FORM_DATE(de.symeda.sormas.api.campaign.data.CampaignFormDataDto.FORM_DATE) ContactDto(de.symeda.sormas.api.contact.ContactDto) Modifier(java.lang.reflect.Modifier) DistrictDto(de.symeda.sormas.api.infrastructure.district.DistrictDto) CampaignFormMetaDto(de.symeda.sormas.api.campaign.form.CampaignFormMetaDto) SubcontinentReferenceDto(de.symeda.sormas.api.infrastructure.subcontinent.SubcontinentReferenceDto) FeatureConfigurationFacadeEjbLocal(de.symeda.sormas.backend.feature.FeatureConfigurationFacadeEjb.FeatureConfigurationFacadeEjbLocal) FacilityDto(de.symeda.sormas.api.infrastructure.facility.FacilityDto) WordUtils(org.apache.commons.lang3.text.WordUtils) HashMap(java.util.HashMap) FACILITY_TYPE(de.symeda.sormas.api.caze.CaseDataDto.FACILITY_TYPE) CampaignFormDataDto(de.symeda.sormas.api.campaign.data.CampaignFormDataDto) ImportColumn(de.symeda.sormas.api.importexport.ImportColumn) Charset(java.nio.charset.Charset) SYMPTOMS(de.symeda.sormas.api.caze.CaseDataDto.SYMPTOMS) FeatureTypeFieldVisibilityChecker(de.symeda.sormas.api.utils.fieldvisibility.checkers.FeatureTypeFieldVisibilityChecker) OutputStreamWriter(java.io.OutputStreamWriter) Validation(javax.validation.Validation) ContinentDto(de.symeda.sormas.api.infrastructure.continent.ContinentDto) SymptomsDto(de.symeda.sormas.api.symptoms.SymptomsDto) PathogenTestDto(de.symeda.sormas.api.sample.PathogenTestDto) CampaignFormMetaFacadeEjbLocal(de.symeda.sormas.backend.campaign.form.CampaignFormMetaFacadeEjb.CampaignFormMetaFacadeEjbLocal) EPID_NUMBER(de.symeda.sormas.api.caze.CaseDataDto.EPID_NUMBER) Logger(org.slf4j.Logger) Validations(de.symeda.sormas.api.i18n.Validations) FeatureConfigurationDto(de.symeda.sormas.api.feature.FeatureConfigurationDto) RegionService(de.symeda.sormas.backend.infrastructure.region.RegionService) FacilityReferenceDto(de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto) POINT_OF_ENTRY(de.symeda.sormas.api.caze.CaseDataDto.POINT_OF_ENTRY) UserReferenceDto(de.symeda.sormas.api.user.UserReferenceDto) PopulationDataDto(de.symeda.sormas.api.infrastructure.PopulationDataDto) VaccinationDto(de.symeda.sormas.api.vaccination.VaccinationDto) PointOfEntryReferenceDto(de.symeda.sormas.api.infrastructure.pointofentry.PointOfEntryReferenceDto) DISEASE_DETAILS(de.symeda.sormas.api.caze.CaseDataDto.DISEASE_DETAILS) Collections(java.util.Collections) ContinentReferenceDto(de.symeda.sormas.api.infrastructure.continent.ContinentReferenceDto) CSVCommentLineValidator(de.symeda.sormas.api.utils.CSVCommentLineValidator) CommunityReferenceDto(de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto) CampaignFormDataDto(de.symeda.sormas.api.campaign.data.CampaignFormDataDto) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) ArrayList(java.util.ArrayList) CampaignFormMetaDto(de.symeda.sormas.api.campaign.form.CampaignFormMetaDto) ImportColumn(de.symeda.sormas.api.importexport.ImportColumn) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) Date(java.util.Date)

Example 3 with ImportColumn

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();
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) CSVWriter(com.opencsv.CSVWriter) ImportColumn(de.symeda.sormas.api.importexport.ImportColumn) OutputStreamWriter(java.io.OutputStreamWriter)

Aggregations

ImportColumn (de.symeda.sormas.api.importexport.ImportColumn)3 CSVWriter (com.opencsv.CSVWriter)2 AgeGroup (de.symeda.sormas.api.AgeGroup)2 FileOutputStream (java.io.FileOutputStream)2 OutputStreamWriter (java.io.OutputStreamWriter)2 Disease (de.symeda.sormas.api.Disease)1 EntityDto (de.symeda.sormas.api.EntityDto)1 ImportIgnore (de.symeda.sormas.api.ImportIgnore)1 CampaignFormDataDto (de.symeda.sormas.api.campaign.data.CampaignFormDataDto)1 FORM_DATE (de.symeda.sormas.api.campaign.data.CampaignFormDataDto.FORM_DATE)1 CampaignFormElementType (de.symeda.sormas.api.campaign.form.CampaignFormElementType)1 CampaignFormMetaDto (de.symeda.sormas.api.campaign.form.CampaignFormMetaDto)1 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)1 CASE_ORIGIN (de.symeda.sormas.api.caze.CaseDataDto.CASE_ORIGIN)1 COMMUNITY (de.symeda.sormas.api.caze.CaseDataDto.COMMUNITY)1 DENGUE_FEVER_TYPE (de.symeda.sormas.api.caze.CaseDataDto.DENGUE_FEVER_TYPE)1 DISEASE (de.symeda.sormas.api.caze.CaseDataDto.DISEASE)1 DISEASE_DETAILS (de.symeda.sormas.api.caze.CaseDataDto.DISEASE_DETAILS)1 DISTRICT (de.symeda.sormas.api.caze.CaseDataDto.DISTRICT)1 EPID_NUMBER (de.symeda.sormas.api.caze.CaseDataDto.EPID_NUMBER)1