Search in sources :

Example 6 with DescriptiveWebMessage

use of org.hisp.dhis.dxf2.webmessage.DescriptiveWebMessage 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

DescriptiveWebMessage (org.hisp.dhis.dxf2.webmessage.DescriptiveWebMessage)6 I18n (org.hisp.dhis.i18n.I18n)5 PostMapping (org.springframework.web.bind.annotation.PostMapping)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 ExpressionValidationOutcome (org.hisp.dhis.expression.ExpressionValidationOutcome)2 RuleValidationResult (org.hisp.dhis.rules.models.RuleValidationResult)2 ExpressionResolver (org.hisp.dhis.analytics.resolver.ExpressionResolver)1