use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport in project dhis2-core by dhis2.
the class MetadataImportServiceTest method testImportMapCreateAndUpdate.
@Test
void testImportMapCreateAndUpdate() throws IOException {
java.util.Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/map_new.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());
List<org.hisp.dhis.mapping.Map> maps = manager.getAll(org.hisp.dhis.mapping.Map.class);
assertEquals(1, maps.size());
assertEquals("test1", maps.get(0).getName());
assertEquals(1, maps.get(0).getMapViews().size());
org.hisp.dhis.mapping.Map map = manager.get(org.hisp.dhis.mapping.Map.class, "LTNgXfzTFTv");
assertNotNull(map);
assertEquals(1, map.getMapViews().size());
MapView mapView = map.getMapViews().get(0);
assertNotNull(mapView);
assertEquals("#ddeeff", mapView.getNoDataColor());
assertEquals("#aabbcc", mapView.getOrganisationUnitColor());
assertEquals(ThematicMapType.CHOROPLETH, mapView.getThematicMapType());
metadata = renderService.fromMetadata(new ClassPathResource("dxf2/map_update.json").getInputStream(), RenderFormat.JSON);
params = new MetadataImportParams();
params.setImportMode(ObjectBundleMode.COMMIT);
params.setImportStrategy(ImportStrategy.CREATE_AND_UPDATE);
params.setObjects(metadata);
report = importService.importMetadata(params);
assertEquals(Status.OK, report.getStatus());
map = manager.get(org.hisp.dhis.mapping.Map.class, "LTNgXfzTFTv");
assertNotNull(map);
assertEquals(1, map.getMapViews().size());
mapView = map.getMapViews().get(0);
assertNotNull(mapView);
assertEquals("#ddeeff", mapView.getNoDataColor());
assertEquals("#aabbcc", mapView.getOrganisationUnitColor());
assertEquals(ThematicMapType.CHOROPLETH, mapView.getThematicMapType());
}
use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport in project dhis2-core by dhis2.
the class MetadataImportServiceTest method testImportProgramWithProgramStageSections.
@Test
void testImportProgramWithProgramStageSections() throws IOException {
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/program_noreg_sections.json").getInputStream(), RenderFormat.JSON);
MetadataImportParams params = createParams(ImportStrategy.CREATE, metadata);
ImportReport report = importService.importMetadata(params);
assertEquals(Status.OK, report.getStatus());
Program program = manager.get(Program.class, "s5uvS0Q7jnX");
assertNotNull(program);
assertEquals(1, program.getProgramStages().size());
ProgramStage programStage = program.getProgramStages().iterator().next();
assertNotNull(programStage.getProgram());
assertEquals(3, programStage.getProgramStageDataElements().size());
programStage.getProgramStageDataElements().forEach(psde -> {
assertNotNull(psde.getSkipAnalytics());
assertFalse(psde.getSkipAnalytics());
});
Set<ProgramStageSection> programStageSections = programStage.getProgramStageSections();
assertNotNull(programStageSections);
assertEquals(2, programStageSections.size());
ProgramStageSection programStageSection = programStageSections.iterator().next();
assertNotNull(programStageSection.getProgramStage());
}
use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport in project dhis2-core by dhis2.
the class MetadataImportServiceTest method testImportNewObjectWithSkipTranslationIsTrue.
@Test
void testImportNewObjectWithSkipTranslationIsTrue() 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(true);
params.setUser(user);
ImportReport report = importService.importMetadata(params);
assertEquals(Status.OK, report.getStatus());
DataSet dataSet = manager.get(DataSet.class, "em8Bg4LCr5k");
assertNotNull(dataSet.getSharing().getUserGroups());
// Payload has translations but skipTranslation = true
assertEquals(0, dataSet.getTranslations().size());
}
use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport in project dhis2-core by dhis2.
the class MetadataImportServiceTest method testImportWithSkipSharingIsTrueAndWritePermission.
/**
* User have READ-WRITE access to Dashboard object User try to update
* Dashboard with: skipSharing=true, and payload doesn't include sharing
* data. Expected: import successfully
*/
@Test
void testImportWithSkipSharingIsTrueAndWritePermission() {
User userA = createUser('A');
userService.addUser(userA);
injectSecurityContext(userA);
Dashboard dashboard = new Dashboard();
dashboard.setName("DashboardA");
Sharing sharing = new Sharing();
sharing.setPublicAccess(AccessStringHelper.DEFAULT);
sharing.addUserAccess(new UserAccess(userA, AccessStringHelper.READ_WRITE));
dashboard.setSharing(sharing);
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = new HashMap<>();
metadata.put(Dashboard.class, Collections.singletonList(dashboard));
MetadataImportParams params = createParams(ImportStrategy.CREATE, metadata);
params.setSkipSharing(false);
// Create Dashboard
ImportReport report = importService.importMetadata(params);
assertEquals(Status.OK, report.getStatus());
// Check all sharing data
IdentifiableObject savedDashboard = manager.get(Dashboard.class, dashboard.getUid());
assertTrue(aclService.canWrite(userA, savedDashboard));
assertTrue(aclService.canRead(userA, savedDashboard));
// Update Dashboard with skipSharing=true and no sharing data in payload
dashboard.setSharing(null);
metadata.put(Dashboard.class, Collections.singletonList(dashboard));
params = createParams(ImportStrategy.UPDATE, metadata);
params.setSkipSharing(true);
params.setUser(userA);
report = importService.importMetadata(params);
assertEquals(Status.OK, report.getStatus());
}
use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport 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());
}
Aggregations