use of org.hisp.dhis.dataelement.DataElementCategoryCombo in project dhis2-core by dhis2.
the class InputUtils method getAttributeOptionCombo.
/**
* Validates and retrieves the attribute option combo. 409 conflict as
* status code along with a textual message will be set on the response in
* case of invalid input.
*
* @param cc the category combo identifier.
* @param cp the category and option query string.
* @param skipFallback whether to skip fallback to default option combo if
* attribute option combo is not found.
* @return the attribute option combo identified from the given input, or
* null. if the input was invalid.
*/
public DataElementCategoryOptionCombo getAttributeOptionCombo(String cc, String cp, boolean skipFallback) {
Set<String> opts = TextUtils.splitToArray(cp, TextUtils.SEMICOLON);
if ((cc == null && opts != null || (cc != null && opts == null))) {
throw new IllegalQueryException("Both or none of category combination and category options must be present");
}
DataElementCategoryCombo categoryCombo = null;
if (cc != null && (categoryCombo = idObjectManager.get(DataElementCategoryCombo.class, cc)) == null) {
throw new IllegalQueryException("Illegal category combo identifier: " + cc);
}
if (categoryCombo == null && opts == null) {
if (skipFallback) {
return null;
}
categoryCombo = categoryService.getDefaultDataElementCategoryCombo();
}
return getAttributeOptionCombo(categoryCombo, cp, null, IdScheme.UID);
}
use of org.hisp.dhis.dataelement.DataElementCategoryCombo in project dhis2-core by dhis2.
the class GetMetaDataAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() {
User user = currentUserService.getCurrentUser();
Date lastUpdated = DateUtils.max(Sets.newHashSet(identifiableObjectManager.getLastUpdated(DataElement.class), identifiableObjectManager.getLastUpdated(OptionSet.class), identifiableObjectManager.getLastUpdated(Indicator.class), identifiableObjectManager.getLastUpdated(DataSet.class), identifiableObjectManager.getLastUpdated(DataElementCategoryCombo.class), identifiableObjectManager.getLastUpdated(DataElementCategory.class), identifiableObjectManager.getLastUpdated(DataElementCategoryOption.class)));
String tag = lastUpdated != null && user != null ? (DateUtils.getLongDateString(lastUpdated) + SEP + user.getUid()) : null;
if (ContextUtils.isNotModified(ServletActionContext.getRequest(), ServletActionContext.getResponse(), tag)) {
return SUCCESS;
}
if (user != null && user.getOrganisationUnits().isEmpty()) {
emptyOrganisationUnits = true;
return SUCCESS;
}
significantZeros = dataElementService.getDataElementsByZeroIsSignificant(true);
dataElements = dataElementService.getDataElementsWithDataSets();
for (DataElement dataElement : dataElements) {
if (dataElement != null && dataElement.getOptionSet() != null) {
dataElementsWithOptionSet.add(dataElement);
}
}
indicators = indicatorService.getIndicatorsWithDataSets();
expressionService.substituteExpressions(indicators, null);
dataSets = dataSetService.getCurrentUserDataSets();
Set<DataElementCategoryCombo> categoryComboSet = new HashSet<>();
Set<DataElementCategory> categorySet = new HashSet<>();
for (DataSet dataSet : dataSets) {
if (dataSet.getCategoryCombo() != null) {
categoryComboSet.add(dataSet.getCategoryCombo());
}
}
for (DataElementCategoryCombo categoryCombo : categoryComboSet) {
if (categoryCombo.getCategories() != null) {
categorySet.addAll(categoryCombo.getCategories());
}
}
categoryCombos = new ArrayList<>(categoryComboSet);
categories = new ArrayList<>(categorySet);
for (DataElementCategory category : categories) {
List<DataElementCategoryOption> categoryOptions = new ArrayList<>(categoryService.getDataElementCategoryOptions(category));
Collections.sort(categoryOptions);
categoryOptionMap.put(category.getUid(), categoryOptions);
}
Collections.sort(dataSets);
Collections.sort(categoryCombos);
Collections.sort(categories);
defaultCategoryCombo = categoryService.getDefaultDataElementCategoryCombo();
return SUCCESS;
}
use of org.hisp.dhis.dataelement.DataElementCategoryCombo in project dhis2-core by dhis2.
the class DataSetOrganisationUnitCategoryResourceTable method getPopulateTempTableContent.
/**
* Iterate over data sets and associated organisation units. If data set
* has a category combination and the organisation unit has category options,
* find the intersection of the category option combinations linked to the
* organisation unit through its category options, and the category option
* combinations linked to the data set through its category combination. If
* not, use the default category option combo.
*/
@Override
public Optional<List<Object[]>> getPopulateTempTableContent() {
List<Object[]> batchArgs = new ArrayList<>();
for (DataSet dataSet : objects) {
DataElementCategoryCombo categoryCombo = dataSet.getCategoryCombo();
for (OrganisationUnit orgUnit : dataSet.getSources()) {
if (!categoryCombo.isDefault()) {
if (orgUnit.hasCategoryOptions()) {
Set<DataElementCategoryOption> orgUnitOptions = orgUnit.getCategoryOptions();
for (DataElementCategoryOptionCombo optionCombo : categoryCombo.getOptionCombos()) {
Set<DataElementCategoryOption> optionComboOptions = optionCombo.getCategoryOptions();
if (orgUnitOptions.containsAll(optionComboOptions)) {
Date startDate = DateUtils.min(optionComboOptions.stream().map(co -> co.getStartDate()).collect(Collectors.toSet()));
Date endDate = DateUtils.max(optionComboOptions.stream().map(co -> co.getEndDate()).collect(Collectors.toSet()));
List<Object> values = Lists.newArrayList(dataSet.getId(), orgUnit.getId(), optionCombo.getId(), startDate, endDate);
batchArgs.add(values.toArray());
}
}
}
} else {
List<Object> values = Lists.newArrayList(dataSet.getId(), orgUnit.getId(), defaultOptionCombo.getId(), null, null);
batchArgs.add(values.toArray());
}
}
}
return Optional.of(batchArgs);
}
use of org.hisp.dhis.dataelement.DataElementCategoryCombo in project dhis2-core by dhis2.
the class ObjectBundleServiceTest method testPreheatValidationsWithCatCombo.
@Test
public void testPreheatValidationsWithCatCombo() throws IOException {
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/de_validate1.json").getInputStream(), RenderFormat.JSON);
DataElementCategoryCombo categoryCombo = manager.getByName(DataElementCategoryCombo.class, "default");
categoryCombo.setUid("p0KPaWEg3cf");
manager.update(categoryCombo);
OptionSet optionSet = new OptionSet("OptionSet: pQYCiuosBnZ", ValueType.TEXT);
optionSet.setAutoFields();
optionSet.setUid("pQYCiuosBnZ");
manager.save(optionSet);
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);
assertFalse(validate.getTypeReportMap().isEmpty());
List<ObjectReport> objectReports = validate.getObjectReports(DataElement.class);
assertFalse(objectReports.isEmpty());
for (ObjectReport objectReport : objectReports) {
for (ErrorCode errorCode : objectReport.getErrorCodes()) {
List<ErrorReport> errorReports = objectReport.getErrorReportsByCode().get(errorCode);
assertFalse(errorReports.isEmpty());
for (ErrorReport errorReport : errorReports) {
assertTrue(PreheatErrorReport.class.isInstance(errorReport));
PreheatErrorReport preheatErrorReport = (PreheatErrorReport) errorReport;
assertEquals(PreheatIdentifier.UID, preheatErrorReport.getPreheatIdentifier());
if (DataElementCategoryCombo.class.isInstance(preheatErrorReport.getValue())) {
assertFalse(true);
} else if (User.class.isInstance(preheatErrorReport.getValue())) {
assertEquals("GOLswS44mh8", preheatErrorReport.getObjectReference().getUid());
} else if (OptionSet.class.isInstance(preheatErrorReport.getValue())) {
assertFalse(true);
}
}
}
}
}
use of org.hisp.dhis.dataelement.DataElementCategoryCombo in project dhis2-core by dhis2.
the class DataValueDimensionTest method setUpTest.
@Override
public void setUpTest() {
male = new DataElementCategoryOption("Male");
female = new DataElementCategoryOption("Female");
under15 = new DataElementCategoryOption("<15");
over15 = new DataElementCategoryOption(">15");
categoryService.addDataElementCategoryOption(male);
categoryService.addDataElementCategoryOption(female);
categoryService.addDataElementCategoryOption(under15);
categoryService.addDataElementCategoryOption(over15);
gender = new DataElementCategory("Gender", DataDimensionType.DISAGGREGATION);
gender.getCategoryOptions().add(male);
gender.getCategoryOptions().add(female);
ageGroup = new DataElementCategory("Agegroup", DataDimensionType.DISAGGREGATION);
ageGroup.getCategoryOptions().add(under15);
ageGroup.getCategoryOptions().add(over15);
categoryService.addDataElementCategory(gender);
categoryService.addDataElementCategory(ageGroup);
genderAndAgeGroup = new DataElementCategoryCombo("Gender and Agegroup", DataDimensionType.DISAGGREGATION);
genderAndAgeGroup.getCategories().add(gender);
genderAndAgeGroup.getCategories().add(ageGroup);
categoryService.addDataElementCategoryCombo(genderAndAgeGroup);
categoryService.generateOptionCombos(genderAndAgeGroup);
dataElementA = createDataElement('A', genderAndAgeGroup);
dataElementService.addDataElement(dataElementA);
periodA = createPeriod(getDate(2000, 1, 1), getDate(2000, 2, 1));
periodService.addPeriod(periodA);
sourceA = createOrganisationUnit('A');
organisationUnitService.addOrganisationUnit(sourceA);
defaultOptionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
for (DataElementCategoryOptionCombo categoryOptionCombo : genderAndAgeGroup.getOptionCombos()) {
dataValueService.addDataValue(createDataValue(dataElementA, periodA, sourceA, "10", categoryOptionCombo, defaultOptionCombo));
}
}
Aggregations