use of org.hisp.dhis.dataset.DataSetElement in project dhis2-core by dhis2.
the class ObjectBundleServiceTest method testCreateDataSetNoDSEDefaults.
@Test
@Disabled
void testCreateDataSetNoDSEDefaults() throws IOException {
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/dataset_with_compulsory.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);
List<DataSet> dataSets = manager.getAll(DataSet.class);
assertEquals(1, dataSets.size());
DataSet dataSet = dataSets.get(0);
assertEquals(dataSet.getDataSetElements().size(), 1);
DataSetElement dataSetElement = dataSet.getDataSetElements().iterator().next();
assertNull(dataSetElement.getCategoryCombo());
}
use of org.hisp.dhis.dataset.DataSetElement in project dhis2-core by dhis2.
the class DefaultDataSetReportService method getDefaultDataSetReport.
@Override
public List<Grid> getDefaultDataSetReport(DataSet dataSet, Period period, OrganisationUnit unit, Set<String> dimensions, boolean selectedUnitOnly, I18nFormat format, I18n i18n) {
ListMap<DataElementCategoryCombo, DataElement> map = new ListMap<>();
for (DataSetElement element : dataSet.getDataSetElements()) {
map.putValue(element.getResolvedCategoryCombo(), element.getDataElement());
}
DataSet tmpDataSet = new DataSet(dataSet.getName(), dataSet.getShortName(), dataSet.getPeriodType());
tmpDataSet.setDataSetElements(dataSet.getDataSetElements());
for (DataElementCategoryCombo categoryCombo : map.keySet()) {
List<DataElement> dataElements = map.get(categoryCombo);
String name = categoryCombo.isDefault() ? dataSet.getName() : categoryCombo.getName();
Section section = new Section(name, dataSet, dataElements, null);
tmpDataSet.getSections().add(section);
}
return getSectionDataSetReport(tmpDataSet, period, unit, dimensions, selectedUnitOnly, format, i18n);
}
use of org.hisp.dhis.dataset.DataSetElement in project dhis2-core by dhis2.
the class DefaultValidationRuleService method getValidationRulesForDataSet.
@Transactional(readOnly = true)
@Override
public Collection<ValidationRule> getValidationRulesForDataSet(DataSet dataSet) {
Set<String> elementsAndOptionCombos = new HashSet<>();
for (DataSetElement dataSetElement : dataSet.getDataSetElements()) {
DataElement dataElement = dataSetElement.getDataElement();
elementsAndOptionCombos.add(dataElement.getUid());
CategoryCombo catCombo = dataSetElement.hasCategoryCombo() ? dataSetElement.getCategoryCombo() : dataElement.getCategoryCombo();
for (CategoryOptionCombo optionCombo : catCombo.getOptionCombos()) {
elementsAndOptionCombos.add(dataElement.getUid() + Expression.SEPARATOR + optionCombo.getUid());
}
}
Set<ValidationRule> rulesForDataSet = new HashSet<>();
for (ValidationRule rule : getAllFormValidationRules()) {
Set<String> leftSideElementsAndCombos = expressionService.getExpressionElementAndOptionComboIds(rule.getLeftSide().getExpression(), VALIDATION_RULE_EXPRESSION);
Set<String> rightSideElementsAndCombos = expressionService.getExpressionElementAndOptionComboIds(rule.getRightSide().getExpression(), VALIDATION_RULE_EXPRESSION);
if (!Sets.intersection(leftSideElementsAndCombos, elementsAndOptionCombos).isEmpty() || !Sets.intersection(rightSideElementsAndCombos, elementsAndOptionCombos).isEmpty()) {
rulesForDataSet.add(rule);
}
}
return rulesForDataSet;
}
use of org.hisp.dhis.dataset.DataSetElement in project dhis2-core by dhis2.
the class DataSetController method getCategoryCombinations.
@GetMapping("/{uid}/categoryCombos")
@ResponseBody
public RootNode getCategoryCombinations(@PathVariable("uid") String uid, HttpServletRequest request, TranslateParams translateParams, HttpServletResponse response) throws Exception {
setUserContext(translateParams);
DataSet dataSet = manager.get(DataSet.class, uid);
if (dataSet == null) {
throw new WebMessageException(conflict("Data set does not exist: " + uid));
}
List<CategoryCombo> categoryCombos = dataSet.getDataSetElements().stream().map(DataSetElement::getResolvedCategoryCombo).distinct().collect(Collectors.toList());
Collections.sort(categoryCombos);
List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
RootNode rootNode = NodeUtils.createMetadata();
rootNode.addChild(fieldFilterService.toCollectionNode(CategoryCombo.class, new FieldFilterParams(categoryCombos, fields)));
return rootNode;
}
Aggregations