Search in sources :

Example 71 with ImportReport

use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport 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());
}
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 72 with ImportReport

use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport in project dhis2-core by dhis2.

the class CsvMetadataImportIntegrationTest method testOrgUnitImport_MoveFromParentNotInHierarchy.

@Test
void testOrgUnitImport_MoveFromParentNotInHierarchy() throws Exception {
    User user = createAndInjectAdminUser("F_ORGANISATIONUNIT_MOVE", "F_ORGANISATIONUNIT_ADD");
    user.setOrganisationUnits(singleton(organisationUnitService.getOrganisationUnitByCode("L2b")));
    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.E1522));
}
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 73 with ImportReport

use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport in project dhis2-core by dhis2.

the class CsvMetadataImportTest method testDataElementImport.

@Test
void testDataElementImport() throws Exception {
    ImportReport importReport = runImport("metadata/dataElements.csv", CsvImportClass.DATA_ELEMENT, metadata -> assertEquals(2, metadata.getDataElements().size()));
    assertEquals(2, importReport.getStats().getCreated());
    assertEquals(2, dataElementService.getAllDataElements().size());
}
Also used : ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 74 with ImportReport

use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport in project dhis2-core by dhis2.

the class CsvMetadataImportTest method testOptionSetReplace.

@Test
void testOptionSetReplace() throws IOException {
    // Import 1 OptionSet with 3 Options
    ImportReport importReport = runImport("metadata/optionSet_add.csv", CsvImportClass.OPTION_SET);
    assertEquals(4, importReport.getStats().getCreated());
    // Send payload with 2 new Options
    importReport = runImport("metadata/optionSet_update.csv", CsvImportClass.OPTION_SET);
    assertEquals(2, importReport.getStats().getCreated());
    OptionSet optionSet = optionService.getOptionSetByCode("COLOR");
    // 3 old Options are replaced by 2 new added Options
    assertEquals(2, optionSet.getOptions().size());
}
Also used : ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) OptionSet(org.hisp.dhis.option.OptionSet) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 75 with ImportReport

use of org.hisp.dhis.dxf2.metadata.feedback.ImportReport in project dhis2-core by dhis2.

the class CsvMetadataImportTest method testOptionSetMerge.

@Test
void testOptionSetMerge() throws IOException {
    // Import 1 OptionSet with 3 Options
    ImportReport importReport = runImport("metadata/optionSet_add.csv", CsvImportClass.OPTION_SET);
    assertEquals(4, importReport.getStats().getCreated());
    // Send payload with 2 new Options
    importReport = runImport("metadata/optionSet_update.csv", CsvImportClass.OPTION_SET, null, params -> params.setMergeMode(MergeMode.MERGE));
    assertEquals(2, importReport.getStats().getCreated());
    OptionSet optionSet = optionService.getOptionSetByCode("COLOR");
    // Total 5 options added
    assertEquals(5, optionSet.getOptions().size());
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) BeforeEach(org.junit.jupiter.api.BeforeEach) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) DataElementService(org.hisp.dhis.dataelement.DataElementService) PreheatIdentifier(org.hisp.dhis.preheat.PreheatIdentifier) CsvImportClass(org.hisp.dhis.dxf2.csv.CsvImportClass) ClassPathResource(org.springframework.core.io.ClassPathResource) Autowired(org.springframework.beans.factory.annotation.Autowired) OrganisationUnitService(org.hisp.dhis.organisationunit.OrganisationUnitService) ArrayList(java.util.ArrayList) OptionGroup(org.hisp.dhis.option.OptionGroup) IdentifiableObjectManager(org.hisp.dhis.common.IdentifiableObjectManager) User(org.hisp.dhis.user.User) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) CsvImportService(org.hisp.dhis.dxf2.csv.CsvImportService) OptionService(org.hisp.dhis.option.OptionService) UserService(org.hisp.dhis.user.UserService) OptionGroupSet(org.hisp.dhis.option.OptionGroupSet) IOException(java.io.IOException) SchemaService(org.hisp.dhis.schema.SchemaService) MergeMode(org.hisp.dhis.common.MergeMode) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) List(java.util.List) Option(org.hisp.dhis.option.Option) CsvImportOptions(org.hisp.dhis.dxf2.csv.CsvImportOptions) OptionSet(org.hisp.dhis.option.OptionSet) DhisSpringTest(org.hisp.dhis.DhisSpringTest) InputStream(java.io.InputStream) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) OptionSet(org.hisp.dhis.option.OptionSet) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

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