use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport in project dhis2-core by dhis2.
the class MetadataImportServiceTest method testUpdateWithSkipTranslationIsTrue.
/**
* 1. Create object with 2 translations 2. Update object with empty
* translations and skipTranslation = true Expected: updated object still
* has 2 translations
*/
@Test
void testUpdateWithSkipTranslationIsTrue() throws IOException {
User user = createUser("A", "ALL");
manager.save(user);
injectSecurityContext(user);
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/dataset_with_accesses_skipSharing.json").getInputStream(), RenderFormat.JSON);
MetadataImportParams params = createParams(ImportStrategy.CREATE, metadata);
params.setSkipTranslation(false);
params.setUser(user);
ImportReport report = importService.importMetadata(params);
assertEquals(Status.OK, report.getStatus());
DataSet dataSet = manager.get(DataSet.class, "em8Bg4LCr5k");
assertNotNull(dataSet.getSharing().getUserGroups());
assertEquals(2, dataSet.getTranslations().size());
metadata = renderService.fromMetadata(new ClassPathResource("dxf2/dataset_with_accesses_update_skipSharing.json").getInputStream(), RenderFormat.JSON);
params = createParams(ImportStrategy.UPDATE, metadata);
params.setSkipTranslation(true);
params.setUser(user);
report = importService.importMetadata(params);
assertEquals(Status.OK, report.getStatus());
dataSet = manager.get(DataSet.class, "em8Bg4LCr5k");
assertNotNull(dataSet.getSharing().getUserGroups());
assertEquals(2, dataSet.getTranslations().size());
}
use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport in project dhis2-core by dhis2.
the class CsvMetadataImportIntegrationTest method testOrgUnitImport_MoveFromParentNotInHierarchy.
@Test
void testOrgUnitImport_MoveFromParentNotInHierarchy() throws Exception {
User user = createAndInjectAdminUser("F_ORGANISATIONUNIT_MOVE", "F_ORGANISATIONUNIT_ADD");
user.setOrganisationUnits(singleton(organisationUnitService.getOrganisationUnitByCode("L2b")));
userService.updateUser(user);
ImportReport report = runImport("metadata/organisationUnits_move.csv", CsvImportClass.ORGANISATION_UNIT, null, params -> params.setImportStrategy(ImportStrategy.UPDATE));
assertEquals(Status.ERROR, report.getStatus());
assertEquals(1, report.getErrorReportsCount());
assertTrue(report.hasErrorReport(error -> error.getErrorCode() == ErrorCode.E1522));
}
use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport in project dhis2-core by dhis2.
the class CsvMetadataImportTest method testDataElementImport.
@Test
void testDataElementImport() throws Exception {
ImportReport importReport = runImport("metadata/dataElements.csv", CsvImportClass.DATA_ELEMENT, metadata -> assertEquals(2, metadata.getDataElements().size()));
assertEquals(2, importReport.getStats().getCreated());
assertEquals(2, dataElementService.getAllDataElements().size());
}
use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport in project dhis2-core by dhis2.
the class CsvMetadataImportTest method testOptionSetReplace.
@Test
void testOptionSetReplace() throws IOException {
// Import 1 OptionSet with 3 Options
ImportReport importReport = runImport("metadata/optionSet_add.csv", CsvImportClass.OPTION_SET);
assertEquals(4, importReport.getStats().getCreated());
// Send payload with 2 new Options
importReport = runImport("metadata/optionSet_update.csv", CsvImportClass.OPTION_SET);
assertEquals(2, importReport.getStats().getCreated());
OptionSet optionSet = optionService.getOptionSetByCode("COLOR");
// 3 old Options are replaced by 2 new added Options
assertEquals(2, optionSet.getOptions().size());
}
use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport in project dhis2-core by dhis2.
the class CsvMetadataImportTest method testOptionSetMerge.
@Test
void testOptionSetMerge() throws IOException {
// Import 1 OptionSet with 3 Options
ImportReport importReport = runImport("metadata/optionSet_add.csv", CsvImportClass.OPTION_SET);
assertEquals(4, importReport.getStats().getCreated());
// Send payload with 2 new Options
importReport = runImport("metadata/optionSet_update.csv", CsvImportClass.OPTION_SET, null, params -> params.setMergeMode(MergeMode.MERGE));
assertEquals(2, importReport.getStats().getCreated());
OptionSet optionSet = optionService.getOptionSetByCode("COLOR");
// Total 5 options added
assertEquals(5, optionSet.getOptions().size());
}
Aggregations