use of org.hisp.dhis.dxf2.metadata.MetadataImportParams in project dhis2-core by dhis2.
the class MetadataImportServiceTest method testImportProgramWithProgramStageAndSharing.
/**
* Payload includes Program and ProgramStage with sharing settings.
* <p>
* Expected: after created, both Program and ProgramStage are saved
* correctly together with sharing settings.
*/
@Test
void testImportProgramWithProgramStageAndSharing() throws IOException {
User user = createUser("A", "ALL");
manager.save(user);
injectSecurityContext(user);
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/program_programStage_with_sharing.json").getInputStream(), RenderFormat.JSON);
MetadataImportParams params = createParams(ImportStrategy.CREATE, metadata);
params.setSkipSharing(false);
params.setUser(user);
ImportReport report = importService.importMetadata(params);
assertEquals(Status.OK, report.getStatus());
ProgramStage programStage = programStageService.getProgramStage("oORy3Rg9hLE");
assertEquals(1, programStage.getSharing().getUserGroups().size());
Program program = manager.get("QIHW6CBdLsP");
assertEquals(1, program.getSharing().getUserGroups().size());
}
use of org.hisp.dhis.dxf2.metadata.MetadataImportParams 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.MetadataImportParams in project dhis2-core by dhis2.
the class GmlImportServiceTest method testImportGml.
// -------------------------------------------------------------------------
// Tests
// -------------------------------------------------------------------------
@Test
void testImportGml() {
MetadataImportParams importParams = new MetadataImportParams();
importParams.setId(id);
importParams.setUser(user);
gmlImportService.importGml(inputStream, importParams);
assertNotNull(boOrgUnit.getGeometry());
assertNotNull(bontheOrgUnit.getGeometry());
assertNotNull(ojdOrgUnit.getGeometry());
assertNotNull(bliOrgUnit.getGeometry());
assertNotNull(forskOrgUnit.getGeometry());
// Check if data is correct
assertEquals(1, getCoordinates(boOrgUnit).size());
assertEquals(18, getCoordinates(bontheOrgUnit).size());
assertEquals(1, getCoordinates(ojdOrgUnit).size());
assertEquals(1, getCoordinates(bliOrgUnit).size());
assertEquals(1, getCoordinates(forskOrgUnit).size());
assertEquals(76, getCoordinates(boOrgUnit).get(0).getNumberOfCoordinates());
assertEquals(189, getCoordinates(bontheOrgUnit).get(1).getNumberOfCoordinates());
assertEquals(1, getCoordinates(ojdOrgUnit).get(0).getNumberOfCoordinates());
assertEquals(1, getCoordinates(bliOrgUnit).get(0).getNumberOfCoordinates());
assertEquals(76, getCoordinates(forskOrgUnit).get(0).getNumberOfCoordinates());
}
use of org.hisp.dhis.dxf2.metadata.MetadataImportParams in project dhis2-core by dhis2.
the class TrackedEntityTypeValidationTest method shouldFailMissingTrackedEntityAttribute.
@Test
void shouldFailMissingTrackedEntityAttribute() throws IOException {
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/simple_metadata.json").getInputStream(), RenderFormat.JSON);
MetadataImportParams importParams = new MetadataImportParams();
importParams.setImportMode(ObjectBundleMode.COMMIT);
importParams.setImportStrategy(ImportStrategy.CREATE);
importParams.setObjects(metadata);
ImportReport report = importService.importMetadata(importParams);
assertEquals(Status.OK, report.getStatus());
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> importMetadata = renderService.fromMetadata(new ClassPathResource("dxf2/import/te_type_missing_tea.json").getInputStream(), RenderFormat.JSON);
MetadataImportParams importParamsFail = new MetadataImportParams();
importParamsFail.setImportMode(ObjectBundleMode.COMMIT);
importParamsFail.setImportStrategy(ImportStrategy.CREATE_AND_UPDATE);
importParamsFail.setObjects(importMetadata);
ImportReport importReport = importService.importMetadata(importParamsFail);
assertEquals(Status.ERROR, importReport.getStatus());
}
use of org.hisp.dhis.dxf2.metadata.MetadataImportParams in project dhis2-core by dhis2.
the class TrackedEntityTypeValidationTest method shouldSuccessTrackedEntityAttributeExists.
@Test
void shouldSuccessTrackedEntityAttributeExists() throws IOException {
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/simple_metadata.json").getInputStream(), RenderFormat.JSON);
MetadataImportParams importParams = new MetadataImportParams();
importParams.setImportMode(ObjectBundleMode.COMMIT);
importParams.setImportStrategy(ImportStrategy.CREATE);
importParams.setObjects(metadata);
ImportReport report = importService.importMetadata(importParams);
assertEquals(Status.OK, report.getStatus());
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> importMetadata = renderService.fromMetadata(new ClassPathResource("dxf2/import/te_type_tea_ok.json").getInputStream(), RenderFormat.JSON);
MetadataImportParams importParamsFail = new MetadataImportParams();
importParamsFail.setImportMode(ObjectBundleMode.COMMIT);
importParamsFail.setImportStrategy(ImportStrategy.CREATE_AND_UPDATE);
importParamsFail.setObjects(importMetadata);
ImportReport importReport = importService.importMetadata(importParamsFail);
assertEquals(Status.OK, importReport.getStatus());
}
Aggregations