Search in sources :

Example 16 with ObjectBundleParams

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

the class ObjectBundleServiceTest method testCreateMetadataWithSuperuserRoleInjected.

@Test
public void testCreateMetadataWithSuperuserRoleInjected() throws IOException {
    createUserAndInjectSecurityContext(true);
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/metadata_superuser_bug.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);
    assertFalse(validate.isEmpty());
    assertEquals(1, validate.getErrorReportsByCode(UserAuthorityGroup.class, ErrorCode.E5003).size());
}
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 17 with ObjectBundleParams

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

the class ObjectBundleServiceTest method testUpdateMetadataWithValidationRules.

@Test
public void testUpdateMetadataWithValidationRules() throws IOException {
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/metadata_with_vr.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);
    metadata = renderService.fromMetadata(new ClassPathResource("dxf2/metadata_with_vr_update.json").getInputStream(), RenderFormat.JSON);
    params = new ObjectBundleParams();
    params.setObjectBundleMode(ObjectBundleMode.COMMIT);
    params.setImportStrategy(ImportStrategy.UPDATE);
    params.setObjects(metadata);
    bundle = objectBundleService.create(params);
    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);
    assertFalse(dataSets.isEmpty());
    assertFalse(organisationUnits.isEmpty());
    assertFalse(dataElements.isEmpty());
    assertFalse(users.isEmpty());
    assertFalse(userRoles.isEmpty());
    assertEquals(2, validationRules.size());
    ValidationRule validationRule1 = manager.get(ValidationRule.class, "ztzsVjSIWg7");
    assertNotNull(validationRule1.getLeftSide());
    assertNotNull(validationRule1.getRightSide());
    ValidationRule validationRule2 = manager.get(ValidationRule.class, "TGvH4Hiyduc");
    assertNotNull(validationRule2.getLeftSide());
    assertNotNull(validationRule2.getRightSide());
}
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) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) ValidationRule(org.hisp.dhis.validation.ValidationRule) 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 18 with ObjectBundleParams

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

the class MetadataImportParams method toObjectBundleParams.

public ObjectBundleParams toObjectBundleParams() {
    ObjectBundleParams params = new ObjectBundleParams();
    params.setUser(user);
    params.setSkipSharing(skipSharing);
    params.setSkipValidation(skipValidation);
    params.setTaskId(taskId);
    params.setImportStrategy(importStrategy);
    params.setAtomicMode(atomicMode);
    params.setObjects(objects);
    params.setPreheatIdentifier(identifier);
    params.setPreheatMode(preheatMode);
    params.setObjectBundleMode(importMode);
    params.setMergeMode(mergeMode);
    params.setFlushMode(flushMode);
    params.setImportReportMode(importReportMode);
    return params;
}
Also used : ObjectBundleParams(org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundleParams)

Example 19 with ObjectBundleParams

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

the class ObjectBundleServiceTest method testCreatePreheatValidationsInvalidObjects.

@Test
public void testCreatePreheatValidationsInvalidObjects() throws IOException {
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/de_validate2.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.getTypeReportMap().isEmpty());
    assertEquals(5, validate.getErrorReportsByCode(DataElement.class, ErrorCode.E5002).size());
    assertEquals(3, validate.getErrorReportsByCode(DataElement.class, ErrorCode.E4000).size());
}
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 20 with ObjectBundleParams

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

the class ObjectBundleServiceTest method testUpdateDataSetWithSectionsAndGreyedFields.

@Test
public void testUpdateDataSetWithSectionsAndGreyedFields() 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);
    Section section1 = manager.get(Section.class, "JwcV2ZifEQf");
    assertNotNull(section1.getDataSet());
    assertEquals(1, section1.getCategoryCombos().size());
    assertTrue(section1.getGreyedFields().isEmpty());
    assertEquals(1, section1.getDataElements().size());
    assertNotNull(section1.getDataSet());
    Section section2 = manager.get(Section.class, "C50M0WxaI7y");
    assertNotNull(section2.getDataSet());
    assertEquals(1, section2.getCategoryCombos().size());
    assertEquals(1, section2.getGreyedFields().size());
    assertEquals(1, section2.getDataElements().size());
    assertNotNull(section2.getDataSet());
    metadata = renderService.fromMetadata(new ClassPathResource("dxf2/dataset_with_sections_gf_update.json").getInputStream(), RenderFormat.JSON);
    params = new ObjectBundleParams();
    params.setObjectBundleMode(ObjectBundleMode.COMMIT);
    params.setImportStrategy(ImportStrategy.UPDATE);
    params.setObjects(metadata);
    bundle = objectBundleService.create(params);
    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);
    assertFalse(organisationUnits.isEmpty());
    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("Updated Data Set", dataSet.getName());
    assertEquals(2, dataSet.getSections().size());
    assertNotNull(dataSet.getUser());
    section1 = manager.get(Section.class, "JwcV2ZifEQf");
    assertNotNull(section1.getDataSet());
    assertEquals(1, section1.getCategoryCombos().size());
    assertEquals(1, section1.getGreyedFields().size());
    assertEquals(1, section1.getDataElements().size());
    assertNotNull(section1.getDataSet());
    section2 = manager.get(Section.class, "C50M0WxaI7y");
    assertNotNull(section2.getDataSet());
    assertEquals(1, section2.getCategoryCombos().size());
    assertTrue(section2.getGreyedFields().isEmpty());
    assertEquals(1, section2.getDataElements().size());
    assertNotNull(section2.getDataSet());
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) 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)

Aggregations

ObjectBundleValidationReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport)37 List (java.util.List)36 DhisSpringTest (org.hisp.dhis.DhisSpringTest)36 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)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)11 UserAuthorityGroup (org.hisp.dhis.user.UserAuthorityGroup)10 ObjectReport (org.hisp.dhis.feedback.ObjectReport)6 Section (org.hisp.dhis.dataset.Section)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 DataElementCategoryCombo (org.hisp.dhis.dataelement.DataElementCategoryCombo)2 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)2