Search in sources :

Example 6 with ObjectBundleValidationReport

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

the class ObjectBundleServiceProgramTest method testCreateSimpleProgramReg.

@Test
public void testCreateSimpleProgramReg() throws IOException {
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/program_reg1.json").getInputStream(), RenderFormat.JSON);
    ObjectBundleParams params = new ObjectBundleParams();
    params.setObjectBundleMode(ObjectBundleMode.COMMIT);
    params.setImportStrategy(ImportStrategy.CREATE);
    params.setObjects(metadata);
    ObjectBundle bundle = objectBundleService.create(params);
    ObjectBundleValidationReport validate = objectBundleValidationService.validate(bundle);
    assertTrue(validate.getErrorReports().isEmpty());
    objectBundleService.commit(bundle);
    List<OrganisationUnit> organisationUnits = manager.getAll(OrganisationUnit.class);
    List<DataElement> dataElements = manager.getAll(DataElement.class);
    List<UserAuthorityGroup> userRoles = manager.getAll(UserAuthorityGroup.class);
    List<User> users = manager.getAll(User.class);
    List<Program> programs = manager.getAll(Program.class);
    List<ProgramStage> programStages = manager.getAll(ProgramStage.class);
    List<ProgramStageDataElement> programStageDataElements = manager.getAll(ProgramStageDataElement.class);
    List<ProgramTrackedEntityAttribute> programTrackedEntityAttributes = manager.getAll(ProgramTrackedEntityAttribute.class);
    assertFalse(organisationUnits.isEmpty());
    assertFalse(dataElements.isEmpty());
    assertFalse(users.isEmpty());
    assertFalse(userRoles.isEmpty());
    assertEquals(1, programs.size());
    assertEquals(2, programStages.size());
    assertEquals(4, programStageDataElements.size());
    assertEquals(2, programTrackedEntityAttributes.size());
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) User(org.hisp.dhis.user.User) Program(org.hisp.dhis.program.Program) ObjectBundleValidationReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) DataElement(org.hisp.dhis.dataelement.DataElement) UserAuthorityGroup(org.hisp.dhis.user.UserAuthorityGroup) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute) List(java.util.List) ProgramStage(org.hisp.dhis.program.ProgramStage) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 7 with ObjectBundleValidationReport

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

the class ObjectBundleReportTest method testImportReportMerge.

@Test
public void testImportReportMerge() {
    TypeReport typeReport0 = createTypeReport(DataElement.class, DataElementGroup.class);
    TypeReport typeReport1 = createTypeReport(Indicator.class, IndicatorGroup.class);
    TypeReport typeReport2 = createTypeReport(Indicator.class, IndicatorGroup.class);
    TypeReport typeReport3 = createTypeReport(OrganisationUnit.class, OrganisationUnitGroup.class);
    ObjectBundleValidationReport objectBundleValidationReport = new ObjectBundleValidationReport();
    objectBundleValidationReport.addTypeReport(typeReport0);
    objectBundleValidationReport.addTypeReport(typeReport1);
    assertEquals(6, objectBundleValidationReport.getErrorReports().size());
    assertEquals(3, objectBundleValidationReport.getErrorReportsByCode(DataElement.class, ErrorCode.E3000).size());
    assertEquals(3, objectBundleValidationReport.getErrorReportsByCode(Indicator.class, ErrorCode.E3000).size());
    ObjectBundleCommitReport objectBundleCommitReport = new ObjectBundleCommitReport();
    objectBundleCommitReport.addTypeReport(typeReport2);
    objectBundleCommitReport.addTypeReport(typeReport3);
    assertEquals(6, objectBundleCommitReport.getErrorReports().size());
    assertEquals(3, objectBundleCommitReport.getErrorReportsByCode(Indicator.class, ErrorCode.E3000).size());
    assertEquals(3, objectBundleCommitReport.getErrorReportsByCode(OrganisationUnit.class, ErrorCode.E3000).size());
    ImportReport importReport = new ImportReport();
    importReport.addTypeReports(objectBundleValidationReport.getTypeReportMap());
    importReport.addTypeReports(objectBundleCommitReport.getTypeReportMap());
    assertEquals(3, importReport.getTypeReportMap().size());
    assertEquals(3, importReport.getTypeReportMap().get(DataElement.class).getErrorReports().size());
    assertEquals(3, importReport.getTypeReportMap().get(OrganisationUnit.class).getErrorReports().size());
    assertEquals(6, importReport.getTypeReportMap().get(Indicator.class).getErrorReports().size());
    assertEquals(3, importReport.getTypeReportMap().get(DataElement.class).getObjectReports().size());
    assertEquals(3, importReport.getTypeReportMap().get(Indicator.class).getObjectReports().size());
    assertEquals(3, importReport.getTypeReportMap().get(OrganisationUnit.class).getObjectReports().size());
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) ObjectBundleCommitReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleCommitReport) TypeReport(org.hisp.dhis.feedback.TypeReport) ObjectBundleValidationReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport) Indicator(org.hisp.dhis.indicator.Indicator) Test(org.junit.Test)

Example 8 with ObjectBundleValidationReport

use of org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport 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 9 with ObjectBundleValidationReport

use of org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport 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 10 with ObjectBundleValidationReport

use of org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport 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)

Aggregations

ObjectBundleValidationReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport)40 Test (org.junit.Test)38 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)37 List (java.util.List)36 DhisSpringTest (org.hisp.dhis.DhisSpringTest)36 ClassPathResource (org.springframework.core.io.ClassPathResource)36 DataElement (org.hisp.dhis.dataelement.DataElement)21 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)15 User (org.hisp.dhis.user.User)14 DataSet (org.hisp.dhis.dataset.DataSet)11 UserAuthorityGroup (org.hisp.dhis.user.UserAuthorityGroup)10 ObjectReport (org.hisp.dhis.feedback.ObjectReport)6 Section (org.hisp.dhis.dataset.Section)4 TypeReport (org.hisp.dhis.feedback.TypeReport)4 ValidationRule (org.hisp.dhis.validation.ValidationRule)4 Program (org.hisp.dhis.program.Program)3 ProgramStage (org.hisp.dhis.program.ProgramStage)3 ProgramStageDataElement (org.hisp.dhis.program.ProgramStageDataElement)3 Chart (org.hisp.dhis.chart.Chart)2 SystemTimer (org.hisp.dhis.commons.timer.SystemTimer)2