use of org.hisp.dhis.dxf2.metadata.MetadataImportParams in project dhis2-core by dhis2.
the class AttributeValueImportTest method testSaveAttributeValueAfterUpdateAttribute.
@Test
void testSaveAttributeValueAfterUpdateAttribute() throws IOException {
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> attributes = renderService.fromMetadata(new ClassPathResource("attribute/attribute.json").getInputStream(), RenderFormat.JSON);
MetadataImportParams params = new MetadataImportParams();
params.setImportMode(ObjectBundleMode.COMMIT);
params.setImportStrategy(ImportStrategy.CREATE);
params.setObjects(attributes);
final ImportReport report = importService.importMetadata(params);
assertEquals(Status.OK, report.getStatus());
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> dataSets = renderService.fromMetadata(new ClassPathResource("attribute/dataSet.json").getInputStream(), RenderFormat.JSON);
params = new MetadataImportParams();
params.setImportMode(ObjectBundleMode.COMMIT);
params.setImportStrategy(ImportStrategy.CREATE);
params.setObjects(dataSets);
final ImportReport importReport = importService.importMetadata(params);
assertEquals(Status.OK, importReport.getStatus());
manager.flush();
DataSet dataSet = manager.get(DataSet.class, "sPnR8BCInMV");
assertEquals("true", dataSet.getAttributeValue("PtyV6lLcmol").getValue());
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> attributesUpdate = renderService.fromMetadata(new ClassPathResource("attribute/attribute_update.json").getInputStream(), RenderFormat.JSON);
params = new MetadataImportParams();
params.setImportMode(ObjectBundleMode.COMMIT);
params.setImportStrategy(ImportStrategy.UPDATE);
params.setObjects(attributesUpdate);
final ImportReport importReport1 = importService.importMetadata(params);
assertEquals(Status.OK, importReport1.getStatus());
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> dataSetUpdate = renderService.fromMetadata(new ClassPathResource("attribute/dataSet_update.json").getInputStream(), RenderFormat.JSON);
params = new MetadataImportParams();
params.setImportMode(ObjectBundleMode.COMMIT);
params.setImportStrategy(ImportStrategy.UPDATE);
params.setObjects(dataSetUpdate);
final ImportReport importReport2 = importService.importMetadata(params);
assertEquals(Status.OK, importReport2.getStatus());
DataSet updatedDataSet = manager.get(DataSet.class, "sPnR8BCInMV");
assertEquals("false", updatedDataSet.getAttributeValue("PtyV6lLcmol").getValue());
}
use of org.hisp.dhis.dxf2.metadata.MetadataImportParams in project dhis2-core by dhis2.
the class MetadataSyncImportHandlerTest method testShouldThrowExceptionWhenParsingClassListMap.
@Test
void testShouldThrowExceptionWhenParsingClassListMap() throws IOException {
syncParams.setImportParams(new MetadataImportParams());
syncParams.setVersion(metadataVersion);
importReport.setStatus(Status.OK);
when(renderService.fromMetadata(any(InputStream.class), eq(RenderFormat.JSON))).thenThrow(new IOException());
assertThrows(MetadataSyncServiceException.class, () -> metadataSyncImportHandler.importMetadata(syncParams, expectedMetadataSnapshot), "Exception occurred while trying to do JSON conversion while parsing class list map");
verify(metadataImportService, never()).importMetadata(syncParams.getImportParams());
verify(metadataVersionDelegate, never()).addNewMetadataVersion(metadataVersion);
verify(metadataVersionDelegate, never()).addNewMetadataVersion(metadataVersion);
}
use of org.hisp.dhis.dxf2.metadata.MetadataImportParams in project dhis2-core by dhis2.
the class MetadataSyncImportHandlerTest method testShouldThrowExceptionWhenClassListMapIsNull.
@Test
void testShouldThrowExceptionWhenClassListMapIsNull() throws IOException {
syncParams.setImportParams(new MetadataImportParams());
syncParams.setVersion(metadataVersion);
importReport.setStatus(Status.OK);
when(renderService.fromMetadata(any(InputStream.class), eq(RenderFormat.JSON))).thenReturn(null);
assertThrows(MetadataSyncServiceException.class, () -> metadataSyncImportHandler.importMetadata(syncParams, expectedMetadataSnapshot), "ClassListMap can't be null");
verify(metadataImportService, never()).importMetadata(syncParams.getImportParams());
verify(metadataVersionDelegate, never()).addNewMetadataVersion(metadataVersion);
verify(metadataVersionDelegate, never()).addNewMetadataVersion(metadataVersion);
}
use of org.hisp.dhis.dxf2.metadata.MetadataImportParams in project dhis2-core by dhis2.
the class MetadataSyncImportHandlerTest method testShouldImportMetadata.
@Test
void testShouldImportMetadata() {
syncParams.setImportParams(new MetadataImportParams());
syncParams.setVersion(metadataVersion);
MetadataSyncSummary metadataSyncSummary = new MetadataSyncSummary();
importReport.setStatus(Status.OK);
when(metadataImportService.importMetadata(syncParams.getImportParams())).thenReturn(importReport);
metadataSyncSummary.setImportReport(importReport);
metadataSyncSummary.setMetadataVersion(metadataVersion);
doNothing().when(metadataVersionDelegate).addNewMetadataVersion(metadataVersion);
MetadataSyncSummary actualMetadataSyncSummary = metadataSyncImportHandler.importMetadata(syncParams, expectedMetadataSnapshot);
verify(metadataVersionDelegate).addNewMetadataVersion(metadataVersion);
assertEquals(metadataSyncSummary.getImportReport(), actualMetadataSyncSummary.getImportReport());
assertEquals(metadataSyncSummary.getImportSummary(), actualMetadataSyncSummary.getImportSummary());
assertEquals(metadataSyncSummary.getMetadataVersion(), actualMetadataSyncSummary.getMetadataVersion());
assertEquals(metadataSyncSummary.getMetadataVersion().getType(), actualMetadataSyncSummary.getMetadataVersion().getType());
assertEquals(metadataSyncSummary.getImportReport().getStatus(), actualMetadataSyncSummary.getImportReport().getStatus());
}
use of org.hisp.dhis.dxf2.metadata.MetadataImportParams in project dhis2-core by dhis2.
the class CsvMetadataImportTest 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