Search in sources :

Example 21 with Metadata

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

the class ObjectBundleServiceProgramTest method testCreateSimpleProgramWithSectionsNoReg.

@Test
public void testCreateSimpleProgramWithSectionsNoReg() throws IOException {
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/program_noreg_sections.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<DataSet> dataSets = manager.getAll(DataSet.class);
    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<ValidationRule> validationRules = manager.getAll(ValidationRule.class);
    List<Program> programs = manager.getAll(Program.class);
    List<ProgramStage> programStages = manager.getAll(ProgramStage.class);
    List<ProgramStageDataElement> programStageDataElements = manager.getAll(ProgramStageDataElement.class);
    List<ProgramStageSection> programStageSections = manager.getAll(ProgramStageSection.class);
    assertFalse(dataSets.isEmpty());
    assertFalse(organisationUnits.isEmpty());
    assertFalse(dataElements.isEmpty());
    assertFalse(users.isEmpty());
    assertFalse(userRoles.isEmpty());
    assertEquals(1, validationRules.size());
    assertEquals(1, programs.size());
    assertEquals(1, programStages.size());
    assertEquals(3, programStageDataElements.size());
    assertEquals(2, programStageSections.size());
    ProgramStage programStage = programStages.get(0);
    assertEquals(3, programStage.getProgramStageDataElements().size());
    assertEquals(2, programStage.getProgramStageSections().size());
}
Also used : User(org.hisp.dhis.user.User) DataSet(org.hisp.dhis.dataset.DataSet) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) DataElement(org.hisp.dhis.dataelement.DataElement) List(java.util.List) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) ProgramStageSection(org.hisp.dhis.program.ProgramStageSection) Program(org.hisp.dhis.program.Program) ObjectBundleValidationReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport) ClassPathResource(org.springframework.core.io.ClassPathResource) ValidationRule(org.hisp.dhis.validation.ValidationRule) UserAuthorityGroup(org.hisp.dhis.user.UserAuthorityGroup) ProgramStage(org.hisp.dhis.program.ProgramStage) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 22 with Metadata

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

the class ObjectBundleServiceProgramTest method testCreateSimpleProgramNoReg.

@Test
public void testCreateSimpleProgramNoReg() throws IOException {
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/program_noreg.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<DataSet> dataSets = manager.getAll(DataSet.class);
    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<ValidationRule> validationRules = manager.getAll(ValidationRule.class);
    List<Program> programs = manager.getAll(Program.class);
    List<ProgramStage> programStages = manager.getAll(ProgramStage.class);
    List<ProgramStageDataElement> programStageDataElements = manager.getAll(ProgramStageDataElement.class);
    assertFalse(dataSets.isEmpty());
    assertFalse(organisationUnits.isEmpty());
    assertFalse(dataElements.isEmpty());
    assertFalse(users.isEmpty());
    assertFalse(userRoles.isEmpty());
    assertEquals(1, validationRules.size());
    assertEquals(1, programs.size());
    assertEquals(1, programStages.size());
    assertEquals(3, programStageDataElements.size());
    ProgramStage programStage = programStages.get(0);
    assertEquals(3, programStage.getProgramStageDataElements().size());
}
Also used : User(org.hisp.dhis.user.User) DataSet(org.hisp.dhis.dataset.DataSet) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) DataElement(org.hisp.dhis.dataelement.DataElement) List(java.util.List) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Program(org.hisp.dhis.program.Program) ObjectBundleValidationReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport) ClassPathResource(org.springframework.core.io.ClassPathResource) ValidationRule(org.hisp.dhis.validation.ValidationRule) UserAuthorityGroup(org.hisp.dhis.user.UserAuthorityGroup) ProgramStage(org.hisp.dhis.program.ProgramStage) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 23 with Metadata

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

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

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

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