use of org.hisp.dhis.organisationunit.OrganisationUnitGroup in project dhis2-core by dhis2.
the class DefaultExpressionService method getExpressionDescription.
@Override
@Transactional
public String getExpressionDescription(String expression) {
if (expression == null || expression.isEmpty()) {
return null;
}
// ---------------------------------------------------------------------
// Operands
// ---------------------------------------------------------------------
StringBuffer sb = new StringBuffer();
Matcher matcher = VARIABLE_PATTERN.matcher(expression);
while (matcher.find()) {
String dimensionItem = matcher.group(GROUP_ID);
DimensionalItemObject dimensionItemObject = dimensionService.getDataDimensionalItemObject(dimensionItem);
if (dimensionItemObject == null) {
throw new InvalidIdentifierReferenceException("Identifier does not reference a dimensional item object: " + dimensionItem);
}
matcher.appendReplacement(sb, Matcher.quoteReplacement(dimensionItemObject.getDisplayName()));
}
expression = TextUtils.appendTail(matcher, sb);
// ---------------------------------------------------------------------
// Constants
// ---------------------------------------------------------------------
sb = new StringBuffer();
matcher = CONSTANT_PATTERN.matcher(expression);
while (matcher.find()) {
String co = matcher.group(GROUP_ID);
Constant constant = constantService.getConstant(co);
if (constant == null) {
throw new InvalidIdentifierReferenceException("Identifier does not reference a constant: " + co);
}
matcher.appendReplacement(sb, Matcher.quoteReplacement(constant.getDisplayName()));
}
expression = TextUtils.appendTail(matcher, sb);
// ---------------------------------------------------------------------
// Org unit groups
// ---------------------------------------------------------------------
sb = new StringBuffer();
matcher = OU_GROUP_PATTERN.matcher(expression);
while (matcher.find()) {
String oug = matcher.group(GROUP_ID);
OrganisationUnitGroup group = organisationUnitGroupService.getOrganisationUnitGroup(oug);
if (group == null) {
throw new InvalidIdentifierReferenceException("Identifier does not reference an organisation unit group: " + oug);
}
matcher.appendReplacement(sb, Matcher.quoteReplacement(group.getDisplayName()));
}
expression = TextUtils.appendTail(matcher, sb);
// ---------------------------------------------------------------------
// Days
// ---------------------------------------------------------------------
sb = new StringBuffer();
matcher = DAYS_PATTERN.matcher(expression);
while (matcher.find()) {
matcher.appendReplacement(sb, DAYS_DESCRIPTION);
}
expression = TextUtils.appendTail(matcher, sb);
return expression;
}
use of org.hisp.dhis.organisationunit.OrganisationUnitGroup in project dhis2-core by dhis2.
the class DefaultExpressionService method substituteExpressions.
@Override
@Transactional
public void substituteExpressions(Collection<Indicator> indicators, Integer days) {
if (indicators != null && !indicators.isEmpty()) {
Map<String, Constant> constants = new CachingMap<String, Constant>().load(idObjectManager.getAllNoAcl(Constant.class), c -> c.getUid());
Map<String, OrganisationUnitGroup> orgUnitGroups = new CachingMap<String, OrganisationUnitGroup>().load(idObjectManager.getAllNoAcl(OrganisationUnitGroup.class), g -> g.getUid());
for (Indicator indicator : indicators) {
indicator.setExplodedNumerator(substituteExpression(indicator.getNumerator(), constants, orgUnitGroups, days));
indicator.setExplodedDenominator(substituteExpression(indicator.getDenominator(), constants, orgUnitGroups, days));
}
}
}
Aggregations