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());
}
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());
}
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());
}
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));
}
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);
}
Aggregations