Search in sources :

Example 41 with ObjectBundleParams

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

the class ObjectBundleServiceTest method testCreatePreheatValidationsInvalidObjects.

@Test
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);
    assertTrue(validate.hasErrorReports());
    assertEquals(5, validate.getErrorReportsCountByCode(DataElement.class, ErrorCode.E5002));
    assertEquals(3, validate.getErrorReportsCountByCode(DataElement.class, ErrorCode.E4000));
}
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) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 42 with ObjectBundleParams

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

the class ObjectBundleServiceTest method testUpdateWithPersistedObjectsRequiresValidReferencesUID.

@Test
void testUpdateWithPersistedObjectsRequiresValidReferencesUID() throws IOException {
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/de_validate7.json").getInputStream(), RenderFormat.JSON);
    defaultSetup();
    ObjectBundleParams params = new ObjectBundleParams();
    params.setObjectBundleMode(ObjectBundleMode.VALIDATE);
    params.setPreheatIdentifier(PreheatIdentifier.UID);
    params.setImportStrategy(ImportStrategy.UPDATE);
    params.setAtomicMode(NONE);
    params.setObjects(metadata);
    ObjectBundle bundle = objectBundleService.create(params);
    ObjectBundleValidationReport validate = objectBundleValidationService.validate(bundle);
    assertEquals(1, validate.getErrorReportsCountByCode(DataElement.class, ErrorCode.E5001));
    assertNotEquals(0, validate.getErrorReportsCountByCode(DataElement.class, ErrorCode.E4000));
    assertEquals(0, bundle.getObjectsCount(DataElement.class));
}
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) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 43 with ObjectBundleParams

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

the class OptionObjectBundleHookTest method preCreateOptionSetAvailable.

@Test
void preCreateOptionSetAvailable() {
    OptionSet optionSet = new OptionSet();
    optionSet.setUid("jadhjSHdhs");
    Option option = new Option();
    option.setOptionSet(optionSet);
    OptionSet persistedOptionSet = new OptionSet();
    persistedOptionSet.setUid("jadhjSHdhs");
    preheat.put(PreheatIdentifier.UID, persistedOptionSet);
    ObjectBundleParams objectBundleParams = new ObjectBundleParams();
    objectBundleParams.setPreheatIdentifier(PreheatIdentifier.UID);
    ObjectBundle bundle = new ObjectBundle(objectBundleParams, preheat, Collections.singletonMap(OptionSet.class, Collections.singletonList(optionSet)));
    hook.preCreate(option, bundle);
    Assertions.assertEquals(0, persistedOptionSet.getOptions().size());
}
Also used : ObjectBundleParams(org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundleParams) ObjectBundle(org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundle) Option(org.hisp.dhis.option.Option) OptionSet(org.hisp.dhis.option.OptionSet) Test(org.junit.jupiter.api.Test)

Example 44 with ObjectBundleParams

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

the class OptionObjectBundleHookTest method preCreate.

@Test
void preCreate() {
    OptionSet optionSet = new OptionSet();
    optionSet.setUid("jadhjSHdhs");
    Option option = new Option();
    option.setOptionSet(optionSet);
    OptionSet persistedOptionSet = new OptionSet();
    persistedOptionSet.setUid("jadhjSHdhs");
    preheat.put(PreheatIdentifier.UID, persistedOptionSet);
    ObjectBundleParams objectBundleParams = new ObjectBundleParams();
    objectBundleParams.setPreheatIdentifier(PreheatIdentifier.UID);
    ObjectBundle bundle = new ObjectBundle(objectBundleParams, preheat, Collections.emptyMap());
    hook.preCreate(option, bundle);
    Assertions.assertEquals(1, persistedOptionSet.getOptions().size());
    Assertions.assertSame(option, persistedOptionSet.getOptions().get(0));
}
Also used : ObjectBundleParams(org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundleParams) ObjectBundle(org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundle) Option(org.hisp.dhis.option.Option) OptionSet(org.hisp.dhis.option.OptionSet) Test(org.junit.jupiter.api.Test)

Example 45 with ObjectBundleParams

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

the class ObjectBundleServiceTest method testCreateAndUpdateDataSetWithSections.

@Test
void testCreateAndUpdateDataSetWithSections() 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);
    assertFalse(validate.hasErrorReports());
    objectBundleService.commit(bundle);
    metadata = renderService.fromMetadata(new ClassPathResource("dxf2/dataset_with_sections.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);
    assertFalse(validate.hasErrorReports());
    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);
    assertNotNull(dataSet.getPeriodType());
    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) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

ObjectBundleValidationReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport)65 List (java.util.List)62 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)62 ClassPathResource (org.springframework.core.io.ClassPathResource)61 Test (org.junit.jupiter.api.Test)52 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)39 DataElement (org.hisp.dhis.dataelement.DataElement)32 User (org.hisp.dhis.user.User)25 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)20 DataSet (org.hisp.dhis.dataset.DataSet)18 ObjectBundleParams (org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundleParams)18 UserAuthorityGroup (org.hisp.dhis.user.UserAuthorityGroup)18 ObjectBundle (org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundle)17 DhisSpringTest (org.hisp.dhis.DhisSpringTest)9 OptionSet (org.hisp.dhis.option.OptionSet)9 ValidationRule (org.hisp.dhis.validation.ValidationRule)7 CategoryCombo (org.hisp.dhis.category.CategoryCombo)6 Section (org.hisp.dhis.dataset.Section)5 Test (org.junit.Test)5 IOException (java.io.IOException)4