use of org.hisp.dhis.dxf2.metadata.MetadataImportParams in project dhis2-core by dhis2.
the class MetadataImportServiceTest method testImportSharingWithMergeModeReplace.
/**
* 1. Create an object with UserGroupAccessA 2. Update object with only
* UserGroupAccessB in payload and mergeMode=REPLACE Expected: updated
* object will have only UserGroupAccessB
*
* @throws IOException
*/
@Test
void testImportSharingWithMergeModeReplace() 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.setUser(user);
ImportReport report = importService.importMetadata(params);
assertEquals(Status.OK, report.getStatus());
DataSet dataSet = manager.get(DataSet.class, "em8Bg4LCr5k");
assertNotNull(dataSet.getSharing().getUserGroups());
assertEquals(1, dataSet.getSharing().getUserGroups().size());
metadata = renderService.fromMetadata(new ClassPathResource("dxf2/dataset_with_accesses_merge_mode.json").getInputStream(), RenderFormat.JSON);
params = createParams(ImportStrategy.CREATE_AND_UPDATE, metadata);
params.setMergeMode(MergeMode.REPLACE);
params.setUser(user);
report = importService.importMetadata(params);
assertEquals(Status.OK, report.getStatus());
dataSet = manager.get(DataSet.class, "em8Bg4LCr5k");
assertNotNull(dataSet.getSharing().getUserGroups());
assertEquals(1, dataSet.getSharing().getUserGroups().size());
assertNotNull(dataSet.getSharing().getUserGroups().get("FnJeHbPOtVF"));
}
use of org.hisp.dhis.dxf2.metadata.MetadataImportParams in project dhis2-core by dhis2.
the class MetadataImportServiceTest method testUpdateImmutableCreatedByField.
@Test
void testUpdateImmutableCreatedByField() throws IOException {
User userA = createUser('A', Lists.newArrayList("ALL"));
userService.addUser(userA);
injectSecurityContext(userA);
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/usergroups.json").getInputStream(), RenderFormat.JSON);
MetadataImportParams params = createParams(ImportStrategy.CREATE, metadata);
params.setUser(userA);
ImportReport report = importService.importMetadata(params);
assertEquals(Status.OK, report.getStatus());
UserGroup userGroup = manager.get(UserGroup.class, "OPVIvvXzNTw");
assertEquals(userA.getUid(), userGroup.getCreatedBy().getUid());
User userB = createUser("B", "ALL");
userB.setUid("userabcdefB");
userService.addUser(userB);
metadata = renderService.fromMetadata(new ClassPathResource("dxf2/usergroups_update.json").getInputStream(), RenderFormat.JSON);
params = createParams(ImportStrategy.UPDATE, metadata);
params.setUser(userA);
report = importService.importMetadata(params);
assertEquals(Status.OK, report.getStatus());
userGroup = manager.get(UserGroup.class, "OPVIvvXzNTw");
assertEquals("TA user group updated", userGroup.getName());
assertEquals(userA.getUid(), userGroup.getCreatedBy().getUid());
}
use of org.hisp.dhis.dxf2.metadata.MetadataImportParams in project dhis2-core by dhis2.
the class MetadataImportServiceTest method testImportEventReportWithProgramIndicators.
@Test
void testImportEventReportWithProgramIndicators() throws IOException {
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/eventreport_with_program_indicator.json").getInputStream(), RenderFormat.JSON);
MetadataImportParams params = createParams(ImportStrategy.CREATE, metadata);
ImportReport report = importService.importMetadata(params);
assertEquals(Status.OK, report.getStatus());
EventReport eventReport = manager.get(EventReport.class, "pCSijMNjMcJ");
assertNotNull(eventReport.getProgramIndicatorDimensions());
assertEquals(1, eventReport.getProgramIndicatorDimensions().size());
assertEquals("Cl00ghs775c", eventReport.getProgramIndicatorDimensions().get(0).getUid());
}
use of org.hisp.dhis.dxf2.metadata.MetadataImportParams in project dhis2-core by dhis2.
the class MetadataImportServiceTest method testUpdateUserGroupWithoutCreatedUserProperty.
@Test
void testUpdateUserGroupWithoutCreatedUserProperty() throws IOException {
User userA = createUser('A', Lists.newArrayList("ALL"));
userService.addUser(userA);
injectSecurityContext(userA);
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/usergroups.json").getInputStream(), RenderFormat.JSON);
MetadataImportParams params = createParams(ImportStrategy.CREATE, metadata);
params.setUser(userA);
ImportReport report = importService.importMetadata(params);
assertEquals(Status.OK, report.getStatus());
UserGroup userGroup = manager.get(UserGroup.class, "OPVIvvXzNTw");
assertEquals(userA.getUid(), userGroup.getSharing().getOwner());
User userB = createUser("B", "ALL");
userService.addUser(userB);
metadata = renderService.fromMetadata(new ClassPathResource("dxf2/usergroups_update.json").getInputStream(), RenderFormat.JSON);
params = createParams(ImportStrategy.UPDATE, metadata);
params.setUser(userB);
report = importService.importMetadata(params);
assertEquals(Status.OK, report.getStatus());
userGroup = manager.get(UserGroup.class, "OPVIvvXzNTw");
assertEquals("TA user group updated", userGroup.getName());
assertEquals(userA.getUid(), userGroup.getSharing().getOwner());
}
use of org.hisp.dhis.dxf2.metadata.MetadataImportParams in project dhis2-core by dhis2.
the class MetadataImportServiceTest method testImportNewObjectWithSkipTranslationIsFalse.
@Test
void testImportNewObjectWithSkipTranslationIsFalse() 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());
// Payload has translations and skipTranslation = false
assertEquals(2, dataSet.getTranslations().size());
}
Aggregations