Search in sources :

Example 51 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 52 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 53 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 54 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 55 with ObjectBundleParams

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

the class ValidatingEventCheckerTest method createObjectBundle.

private ObjectBundle createObjectBundle() {
    Attribute attribute1 = new Attribute();
    attribute1.setUid("u1");
    ObjectBundleParams objectBundleParams = new ObjectBundleParams();
    Preheat preheat = new Preheat();
    final Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> objectMap = new HashMap<>();
    objectMap.put(Attribute.class, new ArrayList<>());
    objectMap.get(Attribute.class).add(attribute1);
    preheat.put(PreheatIdentifier.UID, attribute1);
    return new ObjectBundle(objectBundleParams, preheat, objectMap);
}
Also used : ObjectBundleParams(org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundleParams) ObjectBundle(org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundle) Attribute(org.hisp.dhis.attribute.Attribute) HashMap(java.util.HashMap) Preheat(org.hisp.dhis.preheat.Preheat) ArrayList(java.util.ArrayList) List(java.util.List) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject)

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