Search in sources :

Example 1 with ExpressionResolver

use of org.hisp.dhis.analytics.resolver.ExpressionResolver in project dhis2-core by dhis2.

the class DataHandler method resolveIndicatorExpressions.

/**
 * Resolves the numerator and denominator expressions of indicators in the
 * data query.
 *
 * @param params the {@link DataQueryParams}.
 * @return the resolved list of indicators.
 */
private List<Indicator> resolveIndicatorExpressions(DataQueryParams params) {
    List<Indicator> indicators = asTypedList(params.getIndicators());
    for (Indicator indicator : indicators) {
        for (ExpressionResolver resolver : resolvers.getExpressionResolvers()) {
            indicator.setNumerator(resolver.resolve(indicator.getNumerator()));
            indicator.setDenominator(resolver.resolve(indicator.getDenominator()));
        }
    }
    return indicators;
}
Also used : Indicator(org.hisp.dhis.indicator.Indicator) ExpressionResolver(org.hisp.dhis.analytics.resolver.ExpressionResolver)

Example 2 with ExpressionResolver

use of org.hisp.dhis.analytics.resolver.ExpressionResolver in project dhis2-core by dhis2.

the class IndicatorController method getExpressionDescription.

@PostMapping(value = "/expression/description", produces = APPLICATION_JSON_VALUE)
@ResponseBody
public WebMessage getExpressionDescription(@RequestBody String expression) {
    String resolvingExpression = expression;
    for (ExpressionResolver resolver : resolvers.getExpressionResolvers()) {
        resolvingExpression = resolver.resolve(resolvingExpression);
    }
    String resolvedExpression = resolvingExpression;
    ExpressionValidationOutcome result = expressionService.expressionIsValid(resolvedExpression, INDICATOR_EXPRESSION);
    return new DescriptiveWebMessage(result.isValid() ? Status.OK : Status.ERROR, HttpStatus.OK).setDescription(result::isValid, () -> expressionService.getExpressionDescription(resolvedExpression, INDICATOR_EXPRESSION)).setMessage(i18nManager.getI18n().getString(result.getKey()));
}
Also used : DescriptiveWebMessage(org.hisp.dhis.dxf2.webmessage.DescriptiveWebMessage) ExpressionValidationOutcome(org.hisp.dhis.expression.ExpressionValidationOutcome) ExpressionResolver(org.hisp.dhis.analytics.resolver.ExpressionResolver) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

ExpressionResolver (org.hisp.dhis.analytics.resolver.ExpressionResolver)2 DescriptiveWebMessage (org.hisp.dhis.dxf2.webmessage.DescriptiveWebMessage)1 ExpressionValidationOutcome (org.hisp.dhis.expression.ExpressionValidationOutcome)1 Indicator (org.hisp.dhis.indicator.Indicator)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1