use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport in project dhis2-core by dhis2.
the class CsvMetadataImportIntegrationTest method testOrgUnitImport_MoveToParentNotInHierarchy.
@Test
void testOrgUnitImport_MoveToParentNotInHierarchy() throws Exception {
User user = createAndInjectAdminUser("F_ORGANISATIONUNIT_MOVE", "F_ORGANISATIONUNIT_ADD");
user.setOrganisationUnits(singleton(organisationUnitService.getOrganisationUnitByCode("L2a")));
userService.updateUser(user);
ImportReport report = runImport("metadata/organisationUnits_move.csv", CsvImportClass.ORGANISATION_UNIT, null, params -> params.setImportStrategy(ImportStrategy.UPDATE));
assertEquals(Status.ERROR, report.getStatus());
assertEquals(1, report.getErrorReportsCount());
assertTrue(report.hasErrorReport(error -> error.getErrorCode() == ErrorCode.E1523));
}
use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport in project dhis2-core by dhis2.
the class MetadataImportServiceTest method testImportWithSkipSharingIsTrue.
@Test
void testImportWithSkipSharingIsTrue() 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.setSkipSharing(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(1, dataSet.getSharing().getUserGroups().size());
assertEquals("fvz8d3u6jFd", dataSet.getSharing().getUserGroups().values().iterator().next().getId());
metadata = renderService.fromMetadata(new ClassPathResource("dxf2/dataset_with_accesses_update_skipSharing.json").getInputStream(), RenderFormat.JSON);
params = createParams(ImportStrategy.UPDATE, metadata);
params.setSkipSharing(true);
params.setUser(user);
report = importService.importMetadata(params);
assertEquals(Status.OK, report.getStatus());
DataSet dataSetUpdated = manager.get(DataSet.class, "em8Bg4LCr5k");
assertNotNull(dataSetUpdated.getSharing().getUserGroups());
assertEquals(1, dataSetUpdated.getSharing().getUserGroups().size());
assertNotNull(dataSetUpdated.getSharing().getUserGroups().get("fvz8d3u6jFd"));
}
use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport in project dhis2-core by dhis2.
the class MetadataImportServiceTest method testMetadataSyncWithDeletedDataSetSection.
@Test
void testMetadataSyncWithDeletedDataSetSection() throws IOException {
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/dataset_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();
DataSet dataset = dataSetService.getDataSet("em8Bg4LCr5k");
assertNotNull(dataset.getSections());
assertNotNull(manager.get(Section.class, "JwcV2ZifEQf"));
metadata = renderService.fromMetadata(new ClassPathResource("dxf2/dataset_with_removed_section.json").getInputStream(), RenderFormat.JSON);
params = createParams(ImportStrategy.UPDATE, metadata);
params.setMetadataSyncImport(true);
dbmsManager.clearSession();
report = importService.importMetadata(params);
report.forEachErrorReport(errorReport -> log.error("Error report:" + errorReport));
assertEquals(Status.OK, report.getStatus());
dataset = manager.get(DataSet.class, "em8Bg4LCr5k");
assertEquals(1, dataset.getSections().size());
assertNull(manager.get(Section.class, "JwcV2ZifEQf"));
metadata = renderService.fromMetadata(new ClassPathResource("dxf2/dataset_with_all_section_removed.json").getInputStream(), RenderFormat.JSON);
params = createParams(ImportStrategy.CREATE_AND_UPDATE, metadata);
params.setMetadataSyncImport(true);
dbmsManager.clearSession();
report = importService.importMetadata(params);
assertEquals(Status.OK, report.getStatus());
dataset = manager.get(DataSet.class, "em8Bg4LCr5k");
assertTrue(dataset.getSections().isEmpty());
}
use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport in project dhis2-core by dhis2.
the class MetadataImportServiceTest method testImportMultiPropertyUniqueness.
@Test
void testImportMultiPropertyUniqueness() throws IOException {
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/favorites/metadata_multi_property_uniqueness.json").getInputStream(), RenderFormat.JSON);
MetadataImportParams params = createParams(ImportStrategy.CREATE, metadata);
ImportReport importReport = importService.importMetadata(params);
assertTrue(importReport.hasErrorReport(errorReport -> errorReport.getErrorCode() == ErrorCode.E5005));
}
use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport in project dhis2-core by dhis2.
the class MetadataImportServiceTest method testImportEmbeddedObjectWithSkipSharingIsFalse.
@Test
void testImportEmbeddedObjectWithSkipSharingIsFalse() throws IOException {
User user = createUser('A');
manager.save(user);
User userA = manager.get(User.class, user.getUid());
assertNotNull(userA);
UserGroup userGroup = createUserGroup('A', Sets.newHashSet(userA));
manager.save(userGroup);
userGroup = manager.get(UserGroup.class, "ugabcdefghA");
assertNotNull(userGroup);
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/favorites/metadata_visualization_with_accesses.json").getInputStream(), RenderFormat.JSON);
MetadataImportParams params = createParams(ImportStrategy.CREATE, metadata);
params.setSkipSharing(false);
ImportReport report = importService.importMetadata(params);
assertEquals(Status.OK, report.getStatus());
dbmsManager.clearSession();
Visualization visualization = manager.get(Visualization.class, "gyYXi0rXAIc");
assertNotNull(visualization);
assertEquals(1, visualization.getUserGroupAccesses().size());
assertEquals(1, visualization.getUserAccesses().size());
assertEquals(user.getUid(), visualization.getUserAccesses().iterator().next().getUser().getUid());
assertEquals(userGroup.getUid(), visualization.getUserGroupAccesses().iterator().next().getUserGroup().getUid());
metadata = renderService.fromMetadata(new ClassPathResource("dxf2/favorites/metadata_visualization_with_accesses_update.json").getInputStream(), RenderFormat.JSON);
params = createParams(ImportStrategy.UPDATE, metadata);
params.setSkipSharing(false);
dbmsManager.clearSession();
report = importService.importMetadata(params);
assertEquals(Status.OK, report.getStatus());
visualization = manager.get(Visualization.class, "gyYXi0rXAIc");
assertNotNull(visualization);
assertEquals(0, visualization.getUserGroupAccesses().size());
assertEquals(0, visualization.getUserAccesses().size());
}
Aggregations