Search in sources :

Example 46 with ObjectBundleParams

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

the class ObjectBundleServiceTest method testCreateAndUpdateDataSetsWithUgaUID.

@Test
void testCreateAndUpdateDataSetsWithUgaUID() throws IOException {
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/simple_metadata_uga.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/simple_metadata_uga.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<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<UserGroup> userGroups = manager.getAll(UserGroup.class);
    assertEquals(1, organisationUnits.size());
    assertEquals(2, dataElements.size());
    assertEquals(1, userRoles.size());
    assertEquals(1, users.size());
    assertEquals(2, userGroups.size());
    assertEquals(1, dataElements.get(0).getUserGroupAccesses().size());
    assertEquals(1, dataElements.get(1).getUserGroupAccesses().size());
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) User(org.hisp.dhis.user.User) ObjectBundleValidationReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) UserGroup(org.hisp.dhis.user.UserGroup) 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)

Example 47 with ObjectBundleParams

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

the class ObjectBundleServiceTest method testDeleteRequiresValidReferencesUID.

@Test
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);
    assertTrue(validate.getTypeReport(DataElement.class).hasObjectReports());
    assertEquals(3, validate.getErrorReportsCountByCode(DataElement.class, ErrorCode.E5001));
}
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 48 with ObjectBundleParams

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

the class ObjectBundleServiceTest method testCreateMetadataWithInvalidExpressionValidationRules.

@Test
void testCreateMetadataWithInvalidExpressionValidationRules() throws IOException {
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/metadata_with_vr_invalid_expression.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);
    assertEquals(1, validate.getErrorReportsCount());
    assertTrue(validate.hasErrorReport(report -> "leftSide.description".equals(report.getErrorProperty()) && ErrorCode.E4001 == report.getErrorCode()));
}
Also used : AtomicMode(org.hisp.dhis.dxf2.metadata.AtomicMode) ImportStrategy(org.hisp.dhis.importexport.ImportStrategy) ObjectBundleValidationReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport) CategoryOption(org.hisp.dhis.category.CategoryOption) ValueType(org.hisp.dhis.common.ValueType) RenderService(org.hisp.dhis.render.RenderService) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) Autowired(org.springframework.beans.factory.annotation.Autowired) Disabled(org.junit.jupiter.api.Disabled) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Map(java.util.Map) PreheatErrorReport(org.hisp.dhis.preheat.PreheatErrorReport) UserService(org.hisp.dhis.user.UserService) UserGroup(org.hisp.dhis.user.UserGroup) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Category(org.hisp.dhis.category.Category) Sets(com.google.common.collect.Sets) Section(org.hisp.dhis.dataset.Section) NONE(org.hisp.dhis.dxf2.metadata.AtomicMode.NONE) Test(org.junit.jupiter.api.Test) List(java.util.List) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) UserAuthorityGroup(org.hisp.dhis.user.UserAuthorityGroup) TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) CategoryCombo(org.hisp.dhis.category.CategoryCombo) Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) DataSetElement(org.hisp.dhis.dataset.DataSetElement) PreheatIdentifier(org.hisp.dhis.preheat.PreheatIdentifier) DataSet(org.hisp.dhis.dataset.DataSet) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) ClassPathResource(org.springframework.core.io.ClassPathResource) DataElement(org.hisp.dhis.dataelement.DataElement) PreheatMode(org.hisp.dhis.preheat.PreheatMode) IdentifiableObjectManager(org.hisp.dhis.common.IdentifiableObjectManager) Indicator(org.hisp.dhis.indicator.Indicator) User(org.hisp.dhis.user.User) StreamSupport(java.util.stream.StreamSupport) ErrorCode(org.hisp.dhis.feedback.ErrorCode) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) RenderFormat(org.hisp.dhis.render.RenderFormat) IOException(java.io.IOException) ValidationRule(org.hisp.dhis.validation.ValidationRule) MergeMode(org.hisp.dhis.common.MergeMode) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) OptionSet(org.hisp.dhis.option.OptionSet) PeriodType(org.hisp.dhis.period.PeriodType) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) OrganisationUnitLevel(org.hisp.dhis.organisationunit.OrganisationUnitLevel) IdScheme(org.hisp.dhis.common.IdScheme) 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 49 with ObjectBundleParams

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

the class ObjectBundleServiceTest method testUpdateRequiresValidReferencesUID.

@Test
void testUpdateRequiresValidReferencesUID() 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.UPDATE);
    params.setObjects(metadata);
    ObjectBundle bundle = objectBundleService.create(params);
    ObjectBundleValidationReport validate = objectBundleValidationService.validate(bundle);
    assertEquals(3, validate.getTypeReport(DataElement.class).getObjectReportsCount());
}
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) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 50 with ObjectBundleParams

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

the class ObjectBundleServiceTest method testUpdatePreheatValidationsInvalidObjects.

@Test
void testUpdatePreheatValidationsInvalidObjects() 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.UPDATE);
    params.setObjects(metadata);
    ObjectBundle bundle = objectBundleService.create(params);
    ObjectBundleValidationReport validate = objectBundleValidationService.validate(bundle);
    assertTrue(validate.hasErrorReports());
    assertEquals(3, validate.getErrorReportsCountByCode(DataElement.class, ErrorCode.E5001));
}
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)

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