use of org.hisp.dhis.dxf2.metadata.MetadataImportParams in project dhis2-core by dhis2.
the class MetadataImportServiceTest method testImportUpdatePublicAccess.
@Test
void testImportUpdatePublicAccess() throws IOException {
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/dataset_with_accesses.json").getInputStream(), RenderFormat.JSON);
MetadataImportParams params = new MetadataImportParams();
params.setImportMode(ObjectBundleMode.COMMIT);
params.setImportStrategy(ImportStrategy.CREATE);
params.setObjects(metadata);
ImportReport report = importService.importMetadata(params);
assertEquals(Status.OK, report.getStatus());
DataSet dataSet = manager.get(DataSet.class, "em8Bg4LCr5k");
assertEquals("rw------", dataSet.getPublicAccess());
metadata = renderService.fromMetadata(new ClassPathResource("dxf2/dataset_with_publicAccess_update.json").getInputStream(), RenderFormat.JSON);
params = new MetadataImportParams();
params.setImportMode(ObjectBundleMode.COMMIT);
params.setImportStrategy(ImportStrategy.UPDATE);
params.setObjects(metadata);
report = importService.importMetadata(params);
assertEquals(Status.OK, report.getStatus());
DataSet updatedDataSet = manager.get(DataSet.class, "em8Bg4LCr5k");
assertEquals("r-------", updatedDataSet.getPublicAccess());
}
use of org.hisp.dhis.dxf2.metadata.MetadataImportParams in project dhis2-core by dhis2.
the class MetadataImportServiceTest method testCorrectStatusOnImportErrors.
@Test
void testCorrectStatusOnImportErrors() throws IOException {
createUserAndInjectSecurityContext(true);
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/dataset_with_sections.json").getInputStream(), RenderFormat.JSON);
MetadataImportParams params = createParams(ImportStrategy.CREATE, metadata);
params.setAtomicMode(AtomicMode.NONE);
ImportReport report = importService.importMetadata(params);
assertEquals(Status.WARNING, report.getStatus());
}
use of org.hisp.dhis.dxf2.metadata.MetadataImportParams in project dhis2-core by dhis2.
the class MetadataImportServiceTest method testMetadataImportWithDeletedProgramStageSection.
@Test
void testMetadataImportWithDeletedProgramStageSection() throws IOException {
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/programstage_with_sections.json").getInputStream(), RenderFormat.JSON);
MetadataImportParams params = createParams(ImportStrategy.CREATE_AND_UPDATE, metadata);
ImportReport report = importService.importMetadata(params);
assertEquals(Status.OK, report.getStatus());
dbmsManager.clearSession();
ProgramStage programStage = programStageService.getProgramStage("NpsdDv6kKSO");
assertNotNull(programStage.getProgramStageSections());
assertNotNull(manager.get(ProgramStageSection.class, "JwcV2ZifEQf"));
metadata = renderService.fromMetadata(new ClassPathResource("dxf2/programstage_with_removed_section.json").getInputStream(), RenderFormat.JSON);
params = createParams(ImportStrategy.UPDATE, metadata);
params.setMetadataSyncImport(true);
report = importService.importMetadata(params);
report.forEachErrorReport(errorReport -> log.error("Error report:" + errorReport));
assertEquals(Status.OK, report.getStatus());
programStage = manager.get(ProgramStage.class, "NpsdDv6kKSO");
assertEquals(1, programStage.getProgramStageSections().size());
assertNull(manager.get(ProgramStageSection.class, "JwcV2ZifEQf"));
metadata = renderService.fromMetadata(new ClassPathResource("dxf2/programstage_with_all_section_removed.json").getInputStream(), RenderFormat.JSON);
params.setImportMode(ObjectBundleMode.COMMIT);
params.setImportStrategy(ImportStrategy.UPDATE);
params.setObjects(metadata);
params.setMetadataSyncImport(true);
report = importService.importMetadata(params);
assertEquals(Status.OK, report.getStatus());
programStage = manager.get(ProgramStage.class, "NpsdDv6kKSO");
assertEquals(true, programStage.getProgramStageSections().isEmpty());
}
use of org.hisp.dhis.dxf2.metadata.MetadataImportParams in project dhis2-core by dhis2.
the class MetadataImportServiceTest method testMetadataImportWithDeletedDataElements.
@Test
void testMetadataImportWithDeletedDataElements() throws IOException {
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/dataset_with_sections_and_data_elements.json").getInputStream(), RenderFormat.JSON);
MetadataImportParams params = createParams(ImportStrategy.CREATE_AND_UPDATE, metadata);
ImportReport report = importService.importMetadata(params);
assertEquals(Status.OK, report.getStatus());
DataSet dataset = dataSetService.getDataSet("em8Bg4LCr5k");
assertNotNull(dataset.getSections());
assertNotNull(dataset.getDataElements());
assertTrue(dataset.getDataElements().stream().map(de -> de.getUid()).collect(Collectors.toList()).contains("R45hiT7RLui"));
assertNotNull(manager.get(Section.class, "JwcV2ZifEQf"));
assertTrue(dataset.getSections().stream().filter(s -> s.getUid().equals("JwcV2ZifEQf")).findFirst().get().getDataElements().stream().map(de -> de.getUid()).collect(Collectors.toList()).contains("R45hiT7RLui"));
metadata = renderService.fromMetadata(new ClassPathResource("dxf2/dataset_with_data_element_removed.json").getInputStream(), RenderFormat.JSON);
params = createParams(ImportStrategy.CREATE_AND_UPDATE, metadata);
params.setMetadataSyncImport(false);
report = importService.importMetadata(params);
assertEquals(Status.OK, report.getStatus());
dataset = manager.get(DataSet.class, "em8Bg4LCr5k");
assertFalse(dataset.getDataElements().stream().map(de -> de.getUid()).collect(Collectors.toList()).contains("R45hiT7RLui"));
assertNotNull(manager.get(Section.class, "JwcV2ZifEQf"));
assertFalse(dataset.getSections().stream().filter(s -> s.getUid().equals("JwcV2ZifEQf")).findFirst().get().getDataElements().stream().map(de -> de.getUid()).collect(Collectors.toList()).contains("R45hiT7RLui"));
}
use of org.hisp.dhis.dxf2.metadata.MetadataImportParams in project dhis2-core by dhis2.
the class CsvMetadataImportIntegrationTest method runImport.
private ImportReport runImport(String csvFile, CsvImportClass importClass, Consumer<Metadata> preCondition, Consumer<MetadataImportParams> modifier) throws IOException {
InputStream input = new ClassPathResource(csvFile).getInputStream();
Metadata metadata = csvImportService.fromCsv(input, new CsvImportOptions().setImportClass(importClass).setFirstRowIsHeader(true));
if (preCondition != null) {
preCondition.accept(metadata);
}
MetadataImportParams params = new MetadataImportParams();
params.addMetadata(schemaService.getMetadataSchemas(), metadata);
if (modifier != null) {
modifier.accept(params);
}
return importService.importMetadata(params);
}
Aggregations