use of org.hisp.dhis.common.DimensionalItemId in project dhis2-core by dhis2.
the class DataDimensionExtractor method getItemObjectMap.
/**
* Gets a map from dimension item ids to their dimension item objects.
*
* @param itemIds a set of ids of the dimension item objects to get.
* @param atomicObjects a map from each class of atomic objects to a map
* that associates each id of that class with an atomic object.
* @return a map from the item ids to the dimension item objects.
*/
Map<DimensionalItemId, DimensionalItemObject> getItemObjectMap(final Set<DimensionalItemId> itemIds, final MapMap<Class<? extends IdentifiableObject>, String, IdentifiableObject> atomicObjects) {
final Map<DimensionalItemId, DimensionalItemObject> itemObjectMap = new HashMap<>();
for (final DimensionalItemId id : itemIds) {
if (id.hasValidIds()) {
final BaseDimensionalItemObject dimensionalItemObject = getBaseDimensionalItemObject(atomicObjects, id);
if (dimensionalItemObject != null) {
dimensionalItemObject.setQueryMods(id.getQueryMods());
itemObjectMap.put(id, dimensionalItemObject);
}
}
}
return itemObjectMap;
}
use of org.hisp.dhis.common.DimensionalItemId in project dhis2-core by dhis2.
the class CategoryOptionGroupTaglessResolver method resolve.
/**
* Resolves a Data Element Operand expression containing one or two Category
* Option Group UID to an equivalent expression where the associated
* Category Option Combos for the given Category Option Group are "exploded"
* into the expression.
*
* Resolves one of the expressions below:
*
* 1) #{DEUID.COGUID.AOCUID} 2) #{DEUID.COCUID.COGUID} 3)
* #{DEUID.COG1UID.COG2UID}
*
* to:
*
* 1) #{DEUID.COCUID1.AOCUID} + #{DEUID.COCUID2.AOCUID} +
* #{DEUID.COCUID3.AOCUID} where COCUID1,2,3... are resolved by fetching all
* COCUID by COGUID
*
* 2) #{DEUID.COCUID} + #{DEUID.COCUID1} + #{DEUID.COCUID2} +
* #{DEUID.COCUID3} + #{DEUID.COCUID4} where COCUID1,2,3... are resolved by
* fetching all COCUID by COGUID
*
* 3) #{DEUID.COCUID1} + #{DEUID.COCUID2} + #{DEUID.COCUID3} +
* #{DEUID.COCUID4} where COCUID1 and COCUID2 are resolved from COG1UID and
* COCUID3 and COCUID4 are resolved from COGUID2
*
* DEUID = Data Element UID COCUID = Category Option Combo UID COGUID =
* Category Option Group UID
*
* @param expression a Data Element Expression
* @return an expression containing additional CategoryOptionCombos based on
* the given Category Option Group
*/
@Override
@Transactional(readOnly = true)
public String resolve(String expression) {
// Get a DimensionalItemId from the expression. The expression is parsed
// and
// each element placed in the DimensionalItemId
Set<DimensionalItemId> dimItemIds = expressionService.getExpressionDimensionalItemIds(expression, INDICATOR_EXPRESSION);
List<String> resolvedOperands = new ArrayList<>();
if (isDataElementOperand(dimItemIds)) {
Optional<DimensionalItemId> dimItemId = dimItemIds.stream().findFirst();
if (dimItemId.isPresent()) {
DimensionalItemId dimensionalItemId = dimItemId.get();
// First element is always the Data Element Id
String dataElementUid = dimensionalItemId.getId0();
resolvedOperands.addAll(evaluate(dataElementUid, dimensionalItemId.getId1(), dimensionalItemId.getId2()));
resolvedOperands.addAll(evaluate(dataElementUid, dimensionalItemId.getId2(), null));
}
}
if (resolvedOperands.isEmpty()) {
// nothing to resolve, add the expression as it is
resolvedOperands.add(expression);
}
return Joiner.on("+").join(resolvedOperands);
}
use of org.hisp.dhis.common.DimensionalItemId in project dhis2-core by dhis2.
the class DataElementGroupResolver method resolve.
@Override
public String resolve(String expression) {
Set<DimensionalItemId> dimItemIds = expressionService.getExpressionDimensionalItemIds(expression, INDICATOR_EXPRESSION);
for (DimensionalItemId id : dimItemIds) {
if (id.getItem() != null && id.getId0() != null && id.getId0().startsWith(DATA_ELEMENT_GROUP_PREFIX)) {
DataElementGroup deGroup = dataElementGroupStore.getByUid(id.getId0().replace(DATA_ELEMENT_GROUP_PREFIX, EMPTY_STRING));
if (deGroup != null) {
List<String> resolved = deGroup.getMembers().stream().map(de -> id.getItem().replace(id.getId0(), de.getUid())).collect(Collectors.toList());
expression = expression.replace(id.getItem(), LEFT_BRACKET + Joiner.on("+").join(resolved) + RIGHT_BRACKET);
}
}
}
return expression;
}
use of org.hisp.dhis.common.DimensionalItemId in project dhis2-core by dhis2.
the class CategoryOptionGroupResolver method resolve.
@Override
public String resolve(String expression) {
Set<DimensionalItemId> dimItemIds = expressionService.getExpressionDimensionalItemIds(expression, INDICATOR_EXPRESSION);
for (DimensionalItemId id : dimItemIds) {
if (id.getItem() != null && id.getId1() != null && id.getId1().startsWith(CATEGORY_OPTION_GROUP_PREFIX)) {
List<String> cogUidList = Arrays.stream(id.getId1().replace(CATEGORY_OPTION_GROUP_PREFIX, EMPTY_STRING).split(LOGICAL_AND)).collect(Collectors.toList());
expression = getExpression(expression, id, cogUidList, id.getId0());
}
}
return expression;
}
use of org.hisp.dhis.common.DimensionalItemId in project dhis2-core by dhis2.
the class CategoryOptionResolverTest method verifyExpressionIsNotResolvedWhenExpressionIsNotValid.
@Test
void verifyExpressionIsNotResolvedWhenExpressionIsNotValid() {
// arrange
dimensionalItemId = new DimensionalItemId(DimensionItemType.DATA_ELEMENT_OPERAND, uid1, uid2, uid3, createIndicatorExpression());
String expression = "lsdjflakjdflkajdslfhaglakujdhfg";
when(expressionService.getExpressionDimensionalItemIds(expression, INDICATOR_EXPRESSION)).thenReturn(Sets.newHashSet(dimensionalItemId));
// act
String resolvedExpression = resolver.resolve(expression);
// assert
assertEquals(expression, resolvedExpression);
}
Aggregations