Search in sources :

Example 31 with ObjectBundle

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

the class ObjectBundleServiceTest method testCreateDataSetWithSections.

@Test
public void testCreateDataSetWithSections() throws IOException {
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/dataset_with_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<Section> sections = manager.getAll(Section.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);
    assertFalse(organisationUnits.isEmpty());
    assertFalse(dataElements.isEmpty());
    assertFalse(dataSets.isEmpty());
    assertFalse(users.isEmpty());
    assertFalse(userRoles.isEmpty());
    assertEquals(1, dataSets.size());
    assertEquals(2, sections.size());
    DataSet dataSet = dataSets.get(0);
    assertEquals(2, dataSet.getSections().size());
    Section section1 = sections.get(0);
    Section section2 = sections.get(1);
    assertEquals(1, section1.getDataElements().size());
    assertEquals(1, section2.getDataElements().size());
    assertNotNull(section1.getDataSet());
    assertNotNull(section2.getDataSet());
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) User(org.hisp.dhis.user.User) ObjectBundleValidationReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport) DataSet(org.hisp.dhis.dataset.DataSet) Section(org.hisp.dhis.dataset.Section) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) DataElement(org.hisp.dhis.dataelement.DataElement) UserAuthorityGroup(org.hisp.dhis.user.UserAuthorityGroup) List(java.util.List) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 32 with ObjectBundle

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

the class ObjectBundleServiceTest method testCreateDataSetWithSectionsAndGreyedFields.

@Test
public void testCreateDataSetWithSectionsAndGreyedFields() throws IOException {
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/dataset_with_sections_gf.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<Section> sections = manager.getAll(Section.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<DataElementOperand> dataElementOperands = manager.getAll(DataElementOperand.class);
    List<TrackedEntity> trackedEntities = manager.getAll(TrackedEntity.class);
    List<OrganisationUnitLevel> organisationUnitLevels = manager.getAll(OrganisationUnitLevel.class);
    assertFalse(organisationUnits.isEmpty());
    assertEquals(1, organisationUnitLevels.size());
    assertEquals(1, trackedEntities.size());
    assertFalse(dataElements.isEmpty());
    assertFalse(users.isEmpty());
    assertFalse(userRoles.isEmpty());
    assertEquals(1, dataSets.size());
    assertEquals(2, sections.size());
    assertEquals(1, dataElementOperands.size());
    DataSet dataSet = dataSets.get(0);
    assertEquals(2, dataSet.getSections().size());
    Section section1 = sections.get(0);
    Section section2 = sections.get(1);
    assertEquals(1, section1.getDataElements().size());
    assertEquals(1, section2.getDataElements().size());
    assertNotNull(section1.getDataSet());
    assertNotNull(section2.getDataSet());
    Section section = manager.get(Section.class, "C50M0WxaI7y");
    assertNotNull(section.getDataSet());
    assertEquals(1, section.getCategoryCombos().size());
    assertEquals(1, section.getGreyedFields().size());
    DataElementCategoryCombo categoryCombo = manager.get(DataElementCategoryCombo.class, "faV8QvLgIwB");
    assertNotNull(categoryCombo);
    DataElementCategory category = manager.get(DataElementCategory.class, "XJGLlMAMCcn");
    assertNotNull(category);
    DataElementCategoryOption categoryOption1 = manager.get(DataElementCategoryOption.class, "JYiFOMKa25J");
    DataElementCategoryOption categoryOption2 = manager.get(DataElementCategoryOption.class, "tdaMRD34m8o");
    assertNotNull(categoryOption1);
    assertNotNull(categoryOption2);
}
Also used : User(org.hisp.dhis.user.User) DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) DataSet(org.hisp.dhis.dataset.DataSet) TrackedEntity(org.hisp.dhis.trackedentity.TrackedEntity) DataElementCategory(org.hisp.dhis.dataelement.DataElementCategory) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) DataElement(org.hisp.dhis.dataelement.DataElement) List(java.util.List) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) ObjectBundleValidationReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport) Section(org.hisp.dhis.dataset.Section) ClassPathResource(org.springframework.core.io.ClassPathResource) UserAuthorityGroup(org.hisp.dhis.user.UserAuthorityGroup) DataElementCategoryOption(org.hisp.dhis.dataelement.DataElementCategoryOption) OrganisationUnitLevel(org.hisp.dhis.organisationunit.OrganisationUnitLevel) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 33 with ObjectBundle

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

the class ObjectBundleServiceTest method testDeleteRequiresValidReferencesUID.

@Test
public void testDeleteRequiresValidReferencesUID() throws IOException {
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/de_validate4.json").getInputStream(), RenderFormat.JSON);
    ObjectBundleParams params = new ObjectBundleParams();
    params.setObjectBundleMode(ObjectBundleMode.VALIDATE);
    params.setPreheatIdentifier(PreheatIdentifier.UID);
    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 34 with ObjectBundle

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

the class ObjectBundleServiceFavoritesTest method testCreateMetadataWithCharts1.

@Test
public void testCreateMetadataWithCharts1() throws IOException {
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/favorites/metadata_with_charts1.json").getInputStream(), RenderFormat.JSON);
    ObjectBundleParams params = new ObjectBundleParams();
    params.setObjectBundleMode(ObjectBundleMode.COMMIT);
    params.setImportStrategy(ImportStrategy.CREATE_AND_UPDATE);
    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<Chart> charts = manager.getAll(Chart.class);
    assertEquals(1, dataSets.size());
    assertEquals(1, organisationUnits.size());
    assertEquals(4, dataElements.size());
    assertEquals(3, charts.size());
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) ObjectBundleValidationReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport) DataSet(org.hisp.dhis.dataset.DataSet) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) DataElement(org.hisp.dhis.dataelement.DataElement) List(java.util.List) Chart(org.hisp.dhis.chart.Chart) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 35 with ObjectBundle

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

the class ObjectBundleServiceFavoritesTest method testCreateMetadataWithReportTables1.

@Test
public void testCreateMetadataWithReportTables1() throws IOException {
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/favorites/metadata_with_rt1.json").getInputStream(), RenderFormat.JSON);
    ObjectBundleParams params = new ObjectBundleParams();
    params.setObjectBundleMode(ObjectBundleMode.COMMIT);
    params.setImportStrategy(ImportStrategy.CREATE_AND_UPDATE);
    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<ReportTable> reportTables = manager.getAll(ReportTable.class);
    assertEquals(1, dataSets.size());
    assertEquals(1, organisationUnits.size());
    assertEquals(4, dataElements.size());
    assertEquals(3, reportTables.size());
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) ObjectBundleValidationReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport) DataSet(org.hisp.dhis.dataset.DataSet) ReportTable(org.hisp.dhis.reporttable.ReportTable) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) DataElement(org.hisp.dhis.dataelement.DataElement) List(java.util.List) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)40 List (java.util.List)38 ObjectBundleValidationReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport)38 DhisSpringTest (org.hisp.dhis.DhisSpringTest)36 Test (org.junit.Test)36 ClassPathResource (org.springframework.core.io.ClassPathResource)36 DataElement (org.hisp.dhis.dataelement.DataElement)20 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)14 User (org.hisp.dhis.user.User)14 DataSet (org.hisp.dhis.dataset.DataSet)12 UserAuthorityGroup (org.hisp.dhis.user.UserAuthorityGroup)10 ObjectReport (org.hisp.dhis.feedback.ObjectReport)7 Section (org.hisp.dhis.dataset.Section)5 TypeReport (org.hisp.dhis.feedback.TypeReport)4 ObjectBundleCommitReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleCommitReport)3 Program (org.hisp.dhis.program.Program)3 ProgramStage (org.hisp.dhis.program.ProgramStage)3 ProgramStageDataElement (org.hisp.dhis.program.ProgramStageDataElement)3 ValidationRule (org.hisp.dhis.validation.ValidationRule)3 HashMap (java.util.HashMap)2