Search in sources :

Example 66 with MetadataImportParams

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

Example 67 with MetadataImportParams

use of org.hisp.dhis.dxf2.metadata.MetadataImportParams 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 68 with MetadataImportParams

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

the class GmlImportServiceTest method testImportGml.

// -------------------------------------------------------------------------
// Tests
// -------------------------------------------------------------------------
@Test
void testImportGml() {
    MetadataImportParams importParams = new MetadataImportParams();
    importParams.setId(id);
    importParams.setUser(user);
    gmlImportService.importGml(inputStream, importParams);
    assertNotNull(boOrgUnit.getGeometry());
    assertNotNull(bontheOrgUnit.getGeometry());
    assertNotNull(ojdOrgUnit.getGeometry());
    assertNotNull(bliOrgUnit.getGeometry());
    assertNotNull(forskOrgUnit.getGeometry());
    // Check if data is correct
    assertEquals(1, getCoordinates(boOrgUnit).size());
    assertEquals(18, getCoordinates(bontheOrgUnit).size());
    assertEquals(1, getCoordinates(ojdOrgUnit).size());
    assertEquals(1, getCoordinates(bliOrgUnit).size());
    assertEquals(1, getCoordinates(forskOrgUnit).size());
    assertEquals(76, getCoordinates(boOrgUnit).get(0).getNumberOfCoordinates());
    assertEquals(189, getCoordinates(bontheOrgUnit).get(1).getNumberOfCoordinates());
    assertEquals(1, getCoordinates(ojdOrgUnit).get(0).getNumberOfCoordinates());
    assertEquals(1, getCoordinates(bliOrgUnit).get(0).getNumberOfCoordinates());
    assertEquals(76, getCoordinates(forskOrgUnit).get(0).getNumberOfCoordinates());
}
Also used : MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 69 with MetadataImportParams

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

the class TrackedEntityTypeValidationTest method shouldFailMissingTrackedEntityAttribute.

@Test
void shouldFailMissingTrackedEntityAttribute() throws IOException {
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/simple_metadata.json").getInputStream(), RenderFormat.JSON);
    MetadataImportParams importParams = new MetadataImportParams();
    importParams.setImportMode(ObjectBundleMode.COMMIT);
    importParams.setImportStrategy(ImportStrategy.CREATE);
    importParams.setObjects(metadata);
    ImportReport report = importService.importMetadata(importParams);
    assertEquals(Status.OK, report.getStatus());
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> importMetadata = renderService.fromMetadata(new ClassPathResource("dxf2/import/te_type_missing_tea.json").getInputStream(), RenderFormat.JSON);
    MetadataImportParams importParamsFail = new MetadataImportParams();
    importParamsFail.setImportMode(ObjectBundleMode.COMMIT);
    importParamsFail.setImportStrategy(ImportStrategy.CREATE_AND_UPDATE);
    importParamsFail.setObjects(importMetadata);
    ImportReport importReport = importService.importMetadata(importParamsFail);
    assertEquals(Status.ERROR, importReport.getStatus());
}
Also used : MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) List(java.util.List) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 70 with MetadataImportParams

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

the class TrackedEntityTypeValidationTest method shouldSuccessTrackedEntityAttributeExists.

@Test
void shouldSuccessTrackedEntityAttributeExists() throws IOException {
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/simple_metadata.json").getInputStream(), RenderFormat.JSON);
    MetadataImportParams importParams = new MetadataImportParams();
    importParams.setImportMode(ObjectBundleMode.COMMIT);
    importParams.setImportStrategy(ImportStrategy.CREATE);
    importParams.setObjects(metadata);
    ImportReport report = importService.importMetadata(importParams);
    assertEquals(Status.OK, report.getStatus());
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> importMetadata = renderService.fromMetadata(new ClassPathResource("dxf2/import/te_type_tea_ok.json").getInputStream(), RenderFormat.JSON);
    MetadataImportParams importParamsFail = new MetadataImportParams();
    importParamsFail.setImportMode(ObjectBundleMode.COMMIT);
    importParamsFail.setImportStrategy(ImportStrategy.CREATE_AND_UPDATE);
    importParamsFail.setObjects(importMetadata);
    ImportReport importReport = importService.importMetadata(importParamsFail);
    assertEquals(Status.OK, importReport.getStatus());
}
Also used : MetadataImportParams(org.hisp.dhis.dxf2.metadata.MetadataImportParams) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) List(java.util.List) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

ImportReport (org.hisp.dhis.dxf2.metadata.feedback.ImportReport)58 MetadataImportParams (org.hisp.dhis.dxf2.metadata.MetadataImportParams)49 List (java.util.List)38 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)38 Test (org.junit.jupiter.api.Test)38 ClassPathResource (org.springframework.core.io.ClassPathResource)31 User (org.hisp.dhis.user.User)30 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)29 DataSet (org.hisp.dhis.dataset.DataSet)12 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)12 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)11 UpdateAccessDeniedException (org.hisp.dhis.hibernate.exception.UpdateAccessDeniedException)10 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)9 BaseIdentifiableObject (org.hisp.dhis.common.BaseIdentifiableObject)8 WebMessage (org.hisp.dhis.dxf2.webmessage.WebMessage)8 HashMap (java.util.HashMap)6 UserGroup (org.hisp.dhis.user.UserGroup)6 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)6 IOException (java.io.IOException)5 InputStream (java.io.InputStream)5