Search in sources :

Example 26 with Metadata

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

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

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

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

the class ObjectBundleServiceTest method testPreheatValidationsWithCatCombo.

@Test
public void testPreheatValidationsWithCatCombo() throws IOException {
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/de_validate1.json").getInputStream(), RenderFormat.JSON);
    DataElementCategoryCombo categoryCombo = manager.getByName(DataElementCategoryCombo.class, "default");
    categoryCombo.setUid("p0KPaWEg3cf");
    manager.update(categoryCombo);
    OptionSet optionSet = new OptionSet("OptionSet: pQYCiuosBnZ", ValueType.TEXT);
    optionSet.setAutoFields();
    optionSet.setUid("pQYCiuosBnZ");
    manager.save(optionSet);
    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.getTypeReportMap().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())) {
                    assertFalse(true);
                } else if (User.class.isInstance(preheatErrorReport.getValue())) {
                    assertEquals("GOLswS44mh8", preheatErrorReport.getObjectReference().getUid());
                } else if (OptionSet.class.isInstance(preheatErrorReport.getValue())) {
                    assertFalse(true);
                }
            }
        }
    }
}
Also used : DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) 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) OptionSet(org.hisp.dhis.option.OptionSet) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 30 with Metadata

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

the class MetadataImportServiceTest method testCorrectStatusOnImportErrors.

@Test
public void testCorrectStatusOnImportErrors() throws IOException {
    createUserAndInjectSecurityContext(true);
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/dataset_with_sections.json").getInputStream(), RenderFormat.JSON);
    MetadataImportParams params = new MetadataImportParams();
    params.setImportMode(ObjectBundleMode.COMMIT);
    params.setImportStrategy(ImportStrategy.CREATE);
    params.setAtomicMode(AtomicMode.NONE);
    params.setObjects(metadata);
    ImportReport report = importService.importMetadata(params);
    assertEquals(Status.WARNING, report.getStatus());
}
Also used : 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.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

DhisSpringTest (org.hisp.dhis.DhisSpringTest)55 Test (org.junit.Test)55 List (java.util.List)46 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)46 ClassPathResource (org.springframework.core.io.ClassPathResource)42 ObjectBundleValidationReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport)37 DataElement (org.hisp.dhis.dataelement.DataElement)25 User (org.hisp.dhis.user.User)20 MetadataVersion (org.hisp.dhis.metadata.version.MetadataVersion)19 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)19 Metadata (com.google.android.exoplayer2.metadata.Metadata)18 DataSet (org.hisp.dhis.dataset.DataSet)15 ArrayList (java.util.ArrayList)14 MetadataVersionServiceException (org.hisp.dhis.dxf2.metadata.version.exception.MetadataVersionServiceException)14 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)14 IOException (java.io.IOException)10 Metadata (org.hisp.dhis.dxf2.metadata.Metadata)10 DhisHttpResponse (org.hisp.dhis.system.util.DhisHttpResponse)10 UserAuthorityGroup (org.hisp.dhis.user.UserAuthorityGroup)10 IntegrationTest (org.hisp.dhis.IntegrationTest)9