Search in sources :

Example 21 with OrganisationUnitGroup

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;
}
Also used : OrganisationUnitGroup(org.hisp.dhis.organisationunit.OrganisationUnitGroup) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) Matcher(java.util.regex.Matcher) Constant(org.hisp.dhis.constant.Constant) InvalidIdentifierReferenceException(org.hisp.dhis.common.exception.InvalidIdentifierReferenceException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 22 with OrganisationUnitGroup

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));
        }
    }
}
Also used : OrganisationUnitGroup(org.hisp.dhis.organisationunit.OrganisationUnitGroup) Constant(org.hisp.dhis.constant.Constant) Indicator(org.hisp.dhis.indicator.Indicator) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

OrganisationUnitGroup (org.hisp.dhis.organisationunit.OrganisationUnitGroup)22 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)12 ArrayList (java.util.ArrayList)10 OrganisationUnitGroupSet (org.hisp.dhis.organisationunit.OrganisationUnitGroupSet)6 Transactional (org.springframework.transaction.annotation.Transactional)5 HashSet (java.util.HashSet)4 Period (org.hisp.dhis.period.Period)4 List (java.util.List)3 DhisSpringTest (org.hisp.dhis.DhisSpringTest)3 DimensionalObject (org.hisp.dhis.common.DimensionalObject)3 Constant (org.hisp.dhis.constant.Constant)3 DataSet (org.hisp.dhis.dataset.DataSet)3 Matcher (java.util.regex.Matcher)2 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)2 AttributeValue (org.hisp.dhis.attribute.AttributeValue)2 BaseDimensionalObject (org.hisp.dhis.common.BaseDimensionalObject)2 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)2 Grid (org.hisp.dhis.common.Grid)2 DataSetCompletenessResult (org.hisp.dhis.completeness.DataSetCompletenessResult)2 Indicator (org.hisp.dhis.indicator.Indicator)2