use of org.hisp.dhis.common.DimensionalItemId in project dhis2-core by dhis2.
the class DataDimensionExtractor method getAtomicIds.
/**
* Breaks down a set of dimensional item ids into the atomic object ids
* stored in the database. Returns a map from each class of atomic objects
* to the set of ids for that object class.
*
* @param itemIds a set of dimension item object ids.
* @return map from atomic object classes to sets of atomic ids.
*/
SetMap<Class<? extends IdentifiableObject>, String> getAtomicIds(final Set<DimensionalItemId> itemIds) {
final SetMap<Class<? extends IdentifiableObject>, String> atomicIds = new SetMap<>();
for (final DimensionalItemId id : itemIds) {
if (!id.hasValidIds()) {
continue;
}
switch(id.getDimensionItemType()) {
case DATA_ELEMENT:
atomicIds.putValue(DataElement.class, id.getId0());
break;
case DATA_ELEMENT_OPERAND:
atomicIds.putValue(DataElement.class, id.getId0());
if (id.getId1() != null) {
atomicIds.putValue(CategoryOptionCombo.class, id.getId1());
}
if (id.getId2() != null) {
atomicIds.putValue(CategoryOptionCombo.class, id.getId2());
}
break;
case INDICATOR:
atomicIds.putValue(Indicator.class, id.getId0());
break;
case REPORTING_RATE:
atomicIds.putValue(DataSet.class, id.getId0());
break;
case PROGRAM_DATA_ELEMENT:
atomicIds.putValue(Program.class, id.getId0());
atomicIds.putValue(DataElement.class, id.getId1());
break;
case PROGRAM_ATTRIBUTE:
atomicIds.putValue(Program.class, id.getId0());
atomicIds.putValue(TrackedEntityAttribute.class, id.getId1());
break;
case PROGRAM_INDICATOR:
atomicIds.putValue(ProgramIndicator.class, id.getId0());
break;
default:
log.warn("Unrecognized DimensionItemType " + id.getDimensionItemType().name() + " in getAtomicIds");
break;
}
}
return atomicIds;
}
use of org.hisp.dhis.common.DimensionalItemId in project dhis2-core by dhis2.
the class CategoryOptionResolver 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_PREFIX)) {
CategoryOption co = categoryOptionStore.getByUid(id.getId1().replace(CATEGORY_OPTION_PREFIX, EMPTY_STRING));
if (co != null) {
List<String> resolved = co.getCategoryOptionCombos().stream().map(coc -> id.getItem().replace(id.getId1(), coc.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 DimensionalItem method getDescription.
@Override
public final Object getDescription(ExprContext ctx, CommonExpressionVisitor visitor) {
DimensionalItemId itemId = getDimensionalItemId(ctx, visitor);
DimensionalItemObject item = visitor.getDimensionService().getDataDimensionalItemObject(itemId);
if (item == null) {
throw new ParserExceptionWithoutContext("Can't find " + itemId.getDimensionItemType().name() + " for '" + itemId + "'");
}
visitor.getItemDescriptions().put(ctx.getText(), item.getDisplayName());
return ValidationUtils.getNullReplacementValue(getItemValueType(item));
}
use of org.hisp.dhis.common.DimensionalItemId in project dhis2-core by dhis2.
the class DimensionalItem method evaluate.
@Override
public final Object evaluate(ExprContext ctx, CommonExpressionVisitor visitor) {
DimensionalItemId itemId = getDimensionalItemId(ctx, visitor);
DimensionalItemObject item = visitor.getParams().getItemMap().get(itemId);
Object value = (item != null) ? visitor.getParams().getValueMap().get(item) : null;
return visitor.getState().handleNulls(value, getItemValueType(item));
}
use of org.hisp.dhis.common.DimensionalItemId in project dhis2-core by dhis2.
the class DimensionServiceTest method testGetDataDimensionalItemObjectMapReturnsItemsWithAllOffsets.
@Test
void testGetDataDimensionalItemObjectMapReturnsItemsWithAllOffsets() {
Map<DimensionalItemId, DimensionalItemObject> result;
DimensionalItemId deAId = new DimensionalItemId(DATA_ELEMENT, deA.getUid());
DimensionalItemId deBId = new DimensionalItemId(DATA_ELEMENT, deB.getUid());
DimensionalItemId deCId = new DimensionalItemId(DATA_ELEMENT, deC.getUid());
DimensionalItemId deAOffset1Id = new DimensionalItemId(DATA_ELEMENT, deA.getUid(), queryModsA);
DimensionalItemId deBOffset1Id = new DimensionalItemId(DATA_ELEMENT, deB.getUid(), queryModsA);
DimensionalItemId deCOffset1Id = new DimensionalItemId(DATA_ELEMENT, deC.getUid(), queryModsA);
DimensionalItemId deAOffset2Id = new DimensionalItemId(DATA_ELEMENT, deA.getUid(), queryModsB);
DimensionalItemId deBOffset2Id = new DimensionalItemId(DATA_ELEMENT, deB.getUid(), queryModsB);
DimensionalItemId deCOffset2Id = new DimensionalItemId(DATA_ELEMENT, deC.getUid(), queryModsB);
DataElement deAOffset1 = makeDataElementWithQueryModsFrom(deA, queryModsA);
DataElement deBOffset1 = makeDataElementWithQueryModsFrom(deB, queryModsA);
DataElement deCOffset1 = makeDataElementWithQueryModsFrom(deC, queryModsA);
DataElement deAOffset2 = makeDataElementWithQueryModsFrom(deA, queryModsB);
DataElement deBOffset2 = makeDataElementWithQueryModsFrom(deB, queryModsB);
DataElement deCOffset2 = makeDataElementWithQueryModsFrom(deC, queryModsB);
Set<DimensionalItemId> dimensionalItemIds = Sets.newHashSet(deAId, deBId, deCId, deAOffset1Id, deBOffset1Id, deCOffset1Id, deAOffset2Id, deBOffset2Id, deCOffset2Id);
ImmutableMap<DimensionalItemId, DimensionalItemObject> dimensionalItemMap = ImmutableMap.<DimensionalItemId, DimensionalItemObject>builder().put(deAId, deA).put(deBId, deB).put(deCId, deC).put(deAOffset1Id, deAOffset1).put(deBOffset1Id, deBOffset1).put(deCOffset1Id, deCOffset1).put(deAOffset2Id, deAOffset2).put(deBOffset2Id, deBOffset2).put(deCOffset2Id, deCOffset2).build();
// When
result = dimensionService.getDataDimensionalItemObjectMap(dimensionalItemIds);
// Then
assertMapEquals(dimensionalItemMap, result);
}
Aggregations