Search in sources :

Example 66 with ObjectBundleParams

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

the class ProgramStageObjectBundleHookTest method testValidateDataElementAcl.

@Test
void testValidateDataElementAcl() {
    ObjectBundleParams objectBundleParams = new ObjectBundleParams();
    objectBundleParams.setPreheatIdentifier(PreheatIdentifier.UID);
    objectBundleParams.setUser(user);
    ObjectBundle bundle = new ObjectBundle(objectBundleParams, preheat, Collections.singletonMap(OptionSet.class, Collections.singletonList(programStage)));
    List<ErrorReport> errors = subject.validate(programStage, bundle);
    Assertions.assertEquals(1, errors.size());
    Assertions.assertEquals(ErrorCode.E3012, errors.get(0).getErrorCode());
}
Also used : ErrorReport(org.hisp.dhis.feedback.ErrorReport) ObjectBundleParams(org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundleParams) ObjectBundle(org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundle) OptionSet(org.hisp.dhis.option.OptionSet) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 67 with ObjectBundleParams

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

the class ObjectBundleServiceFavoritesTest method testCreateMetadataWithVisualization.

@Test
void testCreateMetadataWithVisualization() throws IOException {
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/favorites/metadata_with_visualization.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.hasErrorReports());
    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<Visualization> visualizations = manager.getAll(Visualization.class);
    assertEquals(1, dataSets.size());
    assertEquals(1, organisationUnits.size());
    assertEquals(4, dataElements.size());
    assertEquals(3, visualizations.size());
    assertNotNull(visualizations.get(0).getFontSize());
    assertNotNull(visualizations.get(1).getFontSize());
    assertNotNull(visualizations.get(2).getFontSize());
    assertNotNull(visualizations.get(0).getSeries());
    assertNotNull(visualizations.get(1).getSeries());
    assertNotNull(visualizations.get(2).getSeries());
    assertNotNull(visualizations.get(0).getAxes());
    assertNotNull(visualizations.get(1).getAxes());
    assertNotNull(visualizations.get(2).getAxes());
    assertNotNull(visualizations.get(0).getSeriesKey());
    assertNotNull(visualizations.get(1).getSeriesKey());
    assertNotNull(visualizations.get(2).getSeriesKey());
    assertEquals(2, visualizations.get(0).getSeries().size());
    assertEquals(2, visualizations.get(1).getSeries().size());
    assertEquals(2, visualizations.get(2).getSeries().size());
    assertEquals(2, visualizations.get(0).getAxes().size());
    assertEquals(2, visualizations.get(1).getAxes().size());
    assertEquals(2, visualizations.get(2).getAxes().size());
    assertNotNull(visualizations.get(0).getFontStyle());
    assertNotNull(visualizations.get(1).getFontStyle());
    assertNotNull(visualizations.get(2).getFontStyle());
    assertNotNull(visualizations.get(0).getFontStyle().getVisualizationTitle());
    assertNotNull(visualizations.get(1).getFontStyle().getVisualizationTitle());
    assertNotNull(visualizations.get(2).getFontStyle().getVisualizationTitle());
    assertEquals("color_set_01", visualizations.get(0).getColorSet());
    assertEquals("color_set_01", visualizations.get(1).getColorSet());
    assertEquals("color_set_01", visualizations.get(2).getColorSet());
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Visualization(org.hisp.dhis.visualization.Visualization) 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) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 68 with ObjectBundleParams

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

the class ObjectBundleServiceProgramTest method testProgramRuleCreation.

@Test
void testProgramRuleCreation() throws IOException {
    createProgramRuleMetadata();
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata1 = renderService.fromMetadata(new ClassPathResource("dxf2/duplicate_program_rule.json").getInputStream(), RenderFormat.JSON);
    ObjectBundleParams params1 = new ObjectBundleParams();
    params1.setObjectBundleMode(ObjectBundleMode.COMMIT);
    params1.setImportStrategy(ImportStrategy.CREATE);
    params1.setObjects(metadata1);
    ObjectBundle bundle1 = objectBundleService.create(params1);
    ObjectBundleValidationReport validate1 = objectBundleValidationService.validate(bundle1);
    assertFalse(validate1.hasErrorReports());
    assertEquals(0, validate1.getErrorReportsCount());
}
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 69 with ObjectBundleParams

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

the class ObjectBundleServiceProgramTest method testInvalidProgramRuleAction.

@Test
void testInvalidProgramRuleAction() throws IOException {
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/metadata_with_program_and_program_rules_with_invalid_ruleActions.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);
    validate.forEachErrorReport(System.out::println);
    assertTrue(validate.hasErrorReports());
    assertTrue(validate.hasErrorReport(report -> report.getErrorCode() == ErrorCode.E4047));
}
Also used : ImportStrategy(org.hisp.dhis.importexport.ImportStrategy) ObjectBundleValidationReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport) DataSet(org.hisp.dhis.dataset.DataSet) RenderService(org.hisp.dhis.render.RenderService) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) ClassPathResource(org.springframework.core.io.ClassPathResource) Autowired(org.springframework.beans.factory.annotation.Autowired) Program(org.hisp.dhis.program.Program) DataElement(org.hisp.dhis.dataelement.DataElement) UserAccess(org.hisp.dhis.user.sharing.UserAccess) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) IdentifiableObjectManager(org.hisp.dhis.common.IdentifiableObjectManager) Map(java.util.Map) User(org.hisp.dhis.user.User) ErrorCode(org.hisp.dhis.feedback.ErrorCode) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) UserService(org.hisp.dhis.user.UserService) RenderFormat(org.hisp.dhis.render.RenderFormat) IOException(java.io.IOException) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) ValidationRule(org.hisp.dhis.validation.ValidationRule) ProgramStage(org.hisp.dhis.program.ProgramStage) ProgramStageSection(org.hisp.dhis.program.ProgramStageSection) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Test(org.junit.jupiter.api.Test) List(java.util.List) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute) UserAuthorityGroup(org.hisp.dhis.user.UserAuthorityGroup) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) 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 70 with ObjectBundleParams

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

the class TrackerEventBundleServiceTest method initTest.

@Override
protected void initTest() throws IOException {
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("tracker/event_metadata.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 validationReport = objectBundleValidationService.validate(bundle);
    assertFalse(validationReport.hasErrorReports());
    objectBundleService.commit(bundle);
}
Also used : ObjectBundleParams(org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundleParams) ObjectBundle(org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundle) 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)

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