Search in sources :

Example 31 with IdentifiableObject

use of org.hisp.dhis.common.IdentifiableObject in project dhis2-core by dhis2.

the class ObjectBundleServiceTest method testPreheatValidationsIncludingMerge.

@Test
public void testPreheatValidationsIncludingMerge() throws IOException {
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/de_validate3.json").getInputStream(), RenderFormat.JSON);
    defaultSetup();
    ObjectBundleParams params = new ObjectBundleParams();
    params.setObjectBundleMode(ObjectBundleMode.VALIDATE);
    params.setMergeMode(MergeMode.REPLACE);
    params.setObjects(metadata);
    ObjectBundle bundle = objectBundleService.create(params);
    ObjectBundleValidationReport validate = objectBundleValidationService.validate(bundle);
    assertNotNull(validate);
}
Also used : ObjectBundleValidationReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport) List(java.util.List) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 32 with IdentifiableObject

use of org.hisp.dhis.common.IdentifiableObject in project dhis2-core by dhis2.

the class ObjectBundleServiceTest method testCreateOrgUnitWithLevels.

@Test
public void testCreateOrgUnitWithLevels() throws IOException {
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/ou_with_levels.json").getInputStream(), RenderFormat.JSON);
    ObjectBundleParams params = new ObjectBundleParams();
    params.setObjectBundleMode(ObjectBundleMode.COMMIT);
    params.setImportStrategy(ImportStrategy.CREATE_AND_UPDATE);
    params.setAtomicMode(AtomicMode.ALL);
    params.setObjects(metadata);
    ObjectBundle bundle = objectBundleService.create(params);
    assertTrue(objectBundleValidationService.validate(bundle).getErrorReports().isEmpty());
    objectBundleService.commit(bundle);
    OrganisationUnit root = manager.get(OrganisationUnit.class, "inVD5SdytkT");
    assertNull(root.getParent());
    assertEquals(3, root.getChildren().size());
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) List(java.util.List) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 33 with IdentifiableObject

use of org.hisp.dhis.common.IdentifiableObject in project dhis2-core by dhis2.

the class ObjectBundleServiceTest method testPreheatValidations.

@Test
public void testPreheatValidations() throws IOException {
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/de_validate1.json").getInputStream(), RenderFormat.JSON);
    ObjectBundleParams params = new ObjectBundleParams();
    params.setObjectBundleMode(ObjectBundleMode.VALIDATE);
    params.setImportStrategy(ImportStrategy.CREATE);
    params.setObjects(metadata);
    ObjectBundle bundle = objectBundleService.create(params);
    ObjectBundleValidationReport validate = objectBundleValidationService.validate(bundle);
    assertFalse(validate.isEmpty());
    List<ObjectReport> objectReports = validate.getObjectReports(DataElement.class);
    assertFalse(objectReports.isEmpty());
    for (ObjectReport objectReport : objectReports) {
        for (ErrorCode errorCode : objectReport.getErrorCodes()) {
            List<ErrorReport> errorReports = objectReport.getErrorReportsByCode().get(errorCode);
            assertFalse(errorReports.isEmpty());
            for (ErrorReport errorReport : errorReports) {
                assertTrue(PreheatErrorReport.class.isInstance(errorReport));
                PreheatErrorReport preheatErrorReport = (PreheatErrorReport) errorReport;
                assertEquals(PreheatIdentifier.UID, preheatErrorReport.getPreheatIdentifier());
                if (DataElementCategoryCombo.class.isInstance(preheatErrorReport.getValue())) {
                    assertEquals("p0KPaWEg3cf", preheatErrorReport.getObjectReference().getUid());
                } else if (User.class.isInstance(preheatErrorReport.getValue())) {
                    assertEquals("GOLswS44mh8", preheatErrorReport.getObjectReference().getUid());
                } else if (OptionSet.class.isInstance(preheatErrorReport.getValue())) {
                    assertEquals("pQYCiuosBnZ", preheatErrorReport.getObjectReference().getUid());
                }
            }
        }
    }
}
Also used : User(org.hisp.dhis.user.User) ObjectBundleValidationReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport) ObjectReport(org.hisp.dhis.feedback.ObjectReport) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) ErrorReport(org.hisp.dhis.feedback.ErrorReport) PreheatErrorReport(org.hisp.dhis.preheat.PreheatErrorReport) PreheatErrorReport(org.hisp.dhis.preheat.PreheatErrorReport) List(java.util.List) ErrorCode(org.hisp.dhis.feedback.ErrorCode) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 34 with IdentifiableObject

use of org.hisp.dhis.common.IdentifiableObject in project dhis2-core by dhis2.

the class ObjectBundleServiceTest method testDeleteRequiresValidReferencesCODE.

@Test
public void testDeleteRequiresValidReferencesCODE() throws IOException {
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/de_validate5.json").getInputStream(), RenderFormat.JSON);
    ObjectBundleParams params = new ObjectBundleParams();
    params.setObjectBundleMode(ObjectBundleMode.VALIDATE);
    params.setPreheatIdentifier(PreheatIdentifier.CODE);
    params.setImportStrategy(ImportStrategy.DELETE);
    params.setObjects(metadata);
    ObjectBundle bundle = objectBundleService.create(params);
    ObjectBundleValidationReport validate = objectBundleValidationService.validate(bundle);
    assertFalse(validate.getTypeReportMap(DataElement.class).getObjectReports().isEmpty());
    assertEquals(3, validate.getErrorReportsByCode(DataElement.class, ErrorCode.E5001).size());
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) ObjectBundleValidationReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport) List(java.util.List) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 35 with IdentifiableObject

use of org.hisp.dhis.common.IdentifiableObject in project dhis2-core by dhis2.

the class ObjectBundleServiceTest method testUpdateDataElementsUID.

@Test
public void testUpdateDataElementsUID() throws IOException {
    defaultSetup();
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/de_update1.json").getInputStream(), RenderFormat.JSON);
    ObjectBundleParams params = new ObjectBundleParams();
    params.setObjectBundleMode(ObjectBundleMode.COMMIT);
    params.setPreheatMode(PreheatMode.REFERENCE);
    params.setImportStrategy(ImportStrategy.UPDATE);
    params.setObjects(metadata);
    Map<String, DataElement> dataElementMap = manager.getIdMap(DataElement.class, IdScheme.UID);
    UserGroup userGroup = manager.get(UserGroup.class, "ugabcdefghA");
    assertEquals(4, dataElementMap.size());
    assertNotNull(userGroup);
    ObjectBundle bundle = objectBundleService.create(params);
    objectBundleValidationService.validate(bundle);
    objectBundleService.commit(bundle);
    DataElement dataElementA = dataElementMap.get("deabcdefghA");
    DataElement dataElementB = dataElementMap.get("deabcdefghB");
    DataElement dataElementC = dataElementMap.get("deabcdefghC");
    DataElement dataElementD = dataElementMap.get("deabcdefghD");
    assertNotNull(dataElementA);
    assertNotNull(dataElementB);
    assertNotNull(dataElementC);
    assertNotNull(dataElementD);
    assertEquals("DEA", dataElementA.getName());
    assertEquals("DEB", dataElementB.getName());
    assertEquals("DEC", dataElementC.getName());
    assertEquals("DED", dataElementD.getName());
    assertEquals("DECA", dataElementA.getCode());
    assertEquals("DECB", dataElementB.getCode());
    assertEquals("DECC", dataElementC.getCode());
    assertEquals("DECD", dataElementD.getCode());
    assertEquals("DESA", dataElementA.getShortName());
    assertEquals("DESB", dataElementB.getShortName());
    assertEquals("DESC", dataElementC.getShortName());
    assertEquals("DESD", dataElementD.getShortName());
    assertEquals("DEDA", dataElementA.getDescription());
    assertEquals("DEDB", dataElementB.getDescription());
    assertEquals("DEDC", dataElementC.getDescription());
    assertEquals("DEDD", dataElementD.getDescription());
    assertEquals(1, dataElementA.getUserGroupAccesses().size());
    assertEquals(0, dataElementB.getUserGroupAccesses().size());
    assertEquals(1, dataElementC.getUserGroupAccesses().size());
    assertEquals(0, dataElementD.getUserGroupAccesses().size());
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) List(java.util.List) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) UserGroup(org.hisp.dhis.user.UserGroup) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)124 List (java.util.List)76 Test (org.junit.Test)67 DhisSpringTest (org.hisp.dhis.DhisSpringTest)64 ClassPathResource (org.springframework.core.io.ClassPathResource)54 DataElement (org.hisp.dhis.dataelement.DataElement)44 ObjectBundleValidationReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport)39 User (org.hisp.dhis.user.User)37 DataSet (org.hisp.dhis.dataset.DataSet)24 ArrayList (java.util.ArrayList)22 ObjectReport (org.hisp.dhis.feedback.ObjectReport)22 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)22 Schema (org.hisp.dhis.schema.Schema)19 HashMap (java.util.HashMap)18 TypeReport (org.hisp.dhis.feedback.TypeReport)18 Set (java.util.Set)15 ErrorReport (org.hisp.dhis.feedback.ErrorReport)15 PreheatErrorReport (org.hisp.dhis.preheat.PreheatErrorReport)15 Map (java.util.Map)14 Property (org.hisp.dhis.schema.Property)13