Search in sources :

Example 21 with IdentifiableObject

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

the class ObjectBundleServiceAttributesTest method testValidateMetadataAttributeValuesUniqueFromPayload.

@Test
public void testValidateMetadataAttributeValuesUniqueFromPayload() throws IOException {
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/metadata_with_unique_attributes_from_payload.json").getInputStream(), RenderFormat.JSON);
    ObjectBundleParams params = new ObjectBundleParams();
    params.setObjectBundleMode(ObjectBundleMode.VALIDATE);
    params.setObjects(metadata);
    ObjectBundle bundle = objectBundleService.create(params);
    ObjectBundleValidationReport validationReport = objectBundleValidationService.validate(bundle);
    List<ObjectReport> objectReports = validationReport.getObjectReports(DataElement.class);
    assertFalse(objectReports.isEmpty());
    assertEquals(2, validationReport.getErrorReportsByCode(DataElement.class, ErrorCode.E4009).size());
}
Also used : ObjectBundleValidationReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport) List(java.util.List) ObjectReport(org.hisp.dhis.feedback.ObjectReport) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 22 with IdentifiableObject

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

the class ObjectBundleServiceAttributesTest method testValidateMetadataAttributeValuesMandatory.

@Test
public void testValidateMetadataAttributeValuesMandatory() throws IOException {
    defaultSetupWithAttributes();
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/metadata_with_mandatory_attributes.json").getInputStream(), RenderFormat.JSON);
    ObjectBundleParams params = new ObjectBundleParams();
    params.setObjectBundleMode(ObjectBundleMode.VALIDATE);
    params.setObjects(metadata);
    ObjectBundle bundle = objectBundleService.create(params);
    ObjectBundleValidationReport validationReport = objectBundleValidationService.validate(bundle);
    List<ObjectReport> objectReports = validationReport.getObjectReports(DataElement.class);
    assertFalse(objectReports.isEmpty());
    assertEquals(4, objectReports.size());
    objectReports.forEach(objectReport -> assertEquals(2, objectReport.getErrorReports().size()));
}
Also used : ObjectBundleValidationReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport) List(java.util.List) ObjectReport(org.hisp.dhis.feedback.ObjectReport) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 23 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 24 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 25 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)

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