use of org.hisp.dhis.dxf2.csv.CsvImportOptions in project dhis2-core by dhis2.
the class DefaultCsvImportService method fromCsv.
// -------------------------------------------------------------------------
// CsvImportService implementation
// -------------------------------------------------------------------------
// TODO Add unit tests
@Override
public Metadata fromCsv(InputStream input, CsvImportOptions options) throws IOException {
CsvReader reader = CsvUtils.getReader(input);
// Disabled due to large geometry
reader.setSafetySwitch(false);
if (options.isFirstRowIsHeader()) {
// Ignore first row
reader.readRecord();
}
Metadata metadata = new Metadata();
switch(options.getImportClass()) {
case DATA_ELEMENT:
metadata.setDataElements(dataElementsFromCsv(reader));
break;
case DATA_ELEMENT_GROUP:
metadata.setDataElementGroups(dataElementGroupsFromCsv(reader));
break;
case DATA_ELEMENT_GROUP_MEMBERSHIP:
metadata.setDataElementGroups(dataElementGroupMembersFromCsv(reader));
break;
case INDICATOR_GROUP_MEMBERSHIP:
metadata.setIndicatorGroups(indicatorGroupMembersFromCsv(reader));
break;
case CATEGORY_OPTION:
metadata.setCategoryOptions(categoryOptionsFromCsv(reader));
break;
case CATEGORY:
metadata.setCategories(categoriesFromCsv(reader));
break;
case CATEGORY_COMBO:
metadata.setCategoryCombos(categoryCombosFromCsv(reader));
break;
case CATEGORY_OPTION_GROUP:
metadata.setCategoryOptionGroups(categoryOptionGroupsFromCsv(reader));
break;
case ORGANISATION_UNIT:
metadata.setOrganisationUnits(orgUnitsFromCsv(reader));
break;
case ORGANISATION_UNIT_GROUP:
metadata.setOrganisationUnitGroups(orgUnitGroupsFromCsv(reader));
break;
case ORGANISATION_UNIT_GROUP_MEMBERSHIP:
metadata.setOrganisationUnitGroups(orgUnitGroupMembersFromCsv(reader));
break;
case VALIDATION_RULE:
metadata.setValidationRules(validationRulesFromCsv(reader));
break;
case OPTION_SET:
setOptionSetsFromCsv(reader, metadata);
break;
case OPTION_GROUP:
setOptionGroupsFromCsv(reader, metadata);
break;
case OPTION_GROUP_SET:
metadata.setOptionGroupSets(setOptionGroupSetFromCsv(reader));
break;
case OPTION_GROUP_SET_MEMBERSHIP:
metadata.setOptionGroupSets(optionGroupSetMembersFromCsv(reader));
break;
default:
break;
}
return metadata;
}
use of org.hisp.dhis.dxf2.csv.CsvImportOptions in project dhis2-core by dhis2.
the class CsvImportServiceTest method testCategoryOptionImportNoHeader.
@Test
void testCategoryOptionImportNoHeader() throws IOException {
inputBasicObjects = new ClassPathResource("csv/basic_objects_no_header.csv").getInputStream();
Metadata metadata = csvImportService.fromCsv(inputBasicObjects, new CsvImportOptions().setImportClass(CsvImportClass.CATEGORY_OPTION).setFirstRowIsHeader(false));
assertEquals(3, metadata.getCategoryOptions().size());
for (CategoryOption categoryOption : metadata.getCategoryOptions()) {
assertNotNull(categoryOption.getUid());
assertNotNull(categoryOption.getName());
assertNotNull(categoryOption.getShortName());
}
}
use of org.hisp.dhis.dxf2.csv.CsvImportOptions in project dhis2-core by dhis2.
the class CsvImportServiceTest method testCategoryOptionImport.
@Test
void testCategoryOptionImport() throws IOException {
Metadata metadata = csvImportService.fromCsv(inputBasicObjects, new CsvImportOptions().setImportClass(CsvImportClass.CATEGORY_OPTION).setFirstRowIsHeader(true));
assertEquals(3, metadata.getCategoryOptions().size());
for (CategoryOption categoryOption : metadata.getCategoryOptions()) {
assertNotNull(categoryOption.getUid());
assertNotNull(categoryOption.getName());
assertNotNull(categoryOption.getShortName());
}
}
use of org.hisp.dhis.dxf2.csv.CsvImportOptions in project dhis2-core by dhis2.
the class CsvImportServiceTest method testOrganisationUnitGroupMembershipImport.
@Test
void testOrganisationUnitGroupMembershipImport() throws IOException {
InputStream in = new ClassPathResource("csv/org_unit_group_memberships.csv").getInputStream();
Metadata metadata = csvImportService.fromCsv(in, new CsvImportOptions().setImportClass(CsvImportClass.ORGANISATION_UNIT_GROUP_MEMBERSHIP).setFirstRowIsHeader(true));
assertEquals(2, metadata.getOrganisationUnitGroups().size());
}
Aggregations