Search in sources :

Example 61 with ImportReport

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));
}
Also used : ImportStrategy(org.hisp.dhis.importexport.ImportStrategy) BeforeEach(org.junit.jupiter.api.BeforeEach) UserService(org.hisp.dhis.user.UserService) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) CsvImportClass(org.hisp.dhis.dxf2.csv.CsvImportClass) ClassPathResource(org.springframework.core.io.ClassPathResource) Autowired(org.springframework.beans.factory.annotation.Autowired) IOException(java.io.IOException) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) SchemaService(org.hisp.dhis.schema.SchemaService) OrganisationUnitService(org.hisp.dhis.organisationunit.OrganisationUnitService) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) CsvImportOptions(org.hisp.dhis.dxf2.csv.CsvImportOptions) Collections.singleton(java.util.Collections.singleton) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) User(org.hisp.dhis.user.User) ErrorCode(org.hisp.dhis.feedback.ErrorCode) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Status(org.hisp.dhis.feedback.Status) InputStream(java.io.InputStream) CsvImportService(org.hisp.dhis.dxf2.csv.CsvImportService) User(org.hisp.dhis.user.User) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 62 with ImportReport

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"));
}
Also used : User(org.hisp.dhis.user.User) DataSet(org.hisp.dhis.dataset.DataSet) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) List(java.util.List) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 63 with ImportReport

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());
}
Also used : DataSet(org.hisp.dhis.dataset.DataSet) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) List(java.util.List) Section(org.hisp.dhis.dataset.Section) ProgramStageSection(org.hisp.dhis.program.ProgramStageSection) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 64 with ImportReport

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));
}
Also used : ImportStrategy(org.hisp.dhis.importexport.ImportStrategy) RenderService(org.hisp.dhis.render.RenderService) Autowired(org.springframework.beans.factory.annotation.Autowired) Visualization(org.hisp.dhis.visualization.Visualization) UserAccess(org.hisp.dhis.user.sharing.UserAccess) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Map(java.util.Map) Status(org.hisp.dhis.feedback.Status) UserService(org.hisp.dhis.user.UserService) AccessStringHelper(org.hisp.dhis.security.acl.AccessStringHelper) UserGroup(org.hisp.dhis.user.UserGroup) Set(java.util.Set) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Section(org.hisp.dhis.dataset.Section) Test(org.junit.jupiter.api.Test) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) AclService(org.hisp.dhis.security.acl.AclService) ThematicMapType(org.hisp.dhis.mapping.ThematicMapType) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) DataSet(org.hisp.dhis.dataset.DataSet) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) ClassPathResource(org.springframework.core.io.ClassPathResource) HashMap(java.util.HashMap) EventReport(org.hisp.dhis.eventreport.EventReport) MapView(org.hisp.dhis.mapping.MapView) Program(org.hisp.dhis.program.Program) Lists(com.google.common.collect.Lists) IdentifiableObjectManager(org.hisp.dhis.common.IdentifiableObjectManager) ObjectBundleMode(org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundleMode) User(org.hisp.dhis.user.User) ErrorCode(org.hisp.dhis.feedback.ErrorCode) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) MapUtils(org.apache.commons.collections4.MapUtils) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) RenderFormat(org.hisp.dhis.render.RenderFormat) IOException(java.io.IOException) Sharing(org.hisp.dhis.user.sharing.Sharing) ProgramStageService(org.hisp.dhis.program.ProgramStageService) MergeMode(org.hisp.dhis.common.MergeMode) ProgramStage(org.hisp.dhis.program.ProgramStage) Dashboard(org.hisp.dhis.dashboard.Dashboard) ProgramStageSection(org.hisp.dhis.program.ProgramStageSection) DataSetService(org.hisp.dhis.dataset.DataSetService) Collections(java.util.Collections) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) List(java.util.List) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 65 with ImportReport

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());
}
Also used : Visualization(org.hisp.dhis.visualization.Visualization) User(org.hisp.dhis.user.User) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) List(java.util.List) ClassPathResource(org.springframework.core.io.ClassPathResource) UserGroup(org.hisp.dhis.user.UserGroup) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

ImportReport (org.hisp.dhis.dxf2.metadata.feedback.ImportReport)87 Test (org.junit.jupiter.api.Test)52 List (java.util.List)39 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)37 ClassPathResource (org.springframework.core.io.ClassPathResource)37 User (org.hisp.dhis.user.User)34 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)33 MetadataImportParams (org.hisp.dhis.dxf2.metadata.MetadataImportParams)32 DhisSpringTest (org.hisp.dhis.DhisSpringTest)12 DataSet (org.hisp.dhis.dataset.DataSet)12 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)11 IOException (java.io.IOException)10 UpdateAccessDeniedException (org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException)10 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 CsvImportOptions (org.hisp.dhis.dxf2.csv.CsvImportOptions)9 InputStream (java.io.InputStream)8 BaseIdentifiableObject (org.hisp.dhis.common.BaseIdentifiableObject)8 UserService (org.hisp.dhis.user.UserService)8 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)8 BeforeEach (org.junit.jupiter.api.BeforeEach)8