Search in sources :

Example 1 with ExpressionValidationOutcome

use of org.hisp.dhis.expression.ExpressionValidationOutcome in project dhis2-core by dhis2.

the class GetValidationRuleAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------    
@Override
public String execute() throws Exception {
    validationRule = validationRuleService.getValidationRule(id);
    String leftSideFormula = validationRule.getLeftSide().getExpression();
    String rightSideFormula = validationRule.getRightSide().getExpression();
    ExpressionValidationOutcome leftSideResult = expressionService.expressionIsValid(leftSideFormula);
    ExpressionValidationOutcome rightSideResult = expressionService.expressionIsValid(rightSideFormula);
    leftSideTextualExpression = leftSideResult.isValid() ? expressionService.getExpressionDescription(leftSideFormula) : i18n.getString(leftSideResult.getKey());
    rightSideTextualExpression = rightSideResult.isValid() ? expressionService.getExpressionDescription(rightSideFormula) : i18n.getString(rightSideResult.getKey());
    periodType = validationRule.getPeriodType();
    return SUCCESS;
}
Also used : ExpressionValidationOutcome(org.hisp.dhis.expression.ExpressionValidationOutcome)

Example 2 with ExpressionValidationOutcome

use of org.hisp.dhis.expression.ExpressionValidationOutcome in project dhis2-core by dhis2.

the class DefaultDataIntegrityService method getInvalidIndicators.

private List<DataIntegrityIssue> getInvalidIndicators(Function<Indicator, String> getter) {
    List<DataIntegrityIssue> issues = new ArrayList<>();
    I18n i18n = i18nManager.getI18n();
    for (Indicator indicator : indicatorService.getAllIndicators()) {
        ExpressionValidationOutcome result = expressionService.expressionIsValid(getter.apply(indicator), INDICATOR_EXPRESSION);
        if (!result.isValid()) {
            issues.add(toIssue(indicator, i18n.getString(result.getKey())));
        }
    }
    return issues;
}
Also used : DataIntegrityIssue(org.hisp.dhis.dataintegrity.DataIntegrityDetails.DataIntegrityIssue) ExpressionValidationOutcome(org.hisp.dhis.expression.ExpressionValidationOutcome) ArrayList(java.util.ArrayList) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) Indicator(org.hisp.dhis.indicator.Indicator) I18n(org.hisp.dhis.i18n.I18n)

Example 3 with ExpressionValidationOutcome

use of org.hisp.dhis.expression.ExpressionValidationOutcome in project dhis2-core by dhis2.

the class ExpressionController method getExpressionDescription.

@RequestMapping(value = "/description", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public void getExpressionDescription(@RequestParam String expression, HttpServletResponse response) throws IOException {
    I18n i18n = i18nManager.getI18n();
    ExpressionValidationOutcome result = expressionService.expressionIsValid(expression);
    DescriptiveWebMessage message = new DescriptiveWebMessage();
    message.setStatus(result.isValid() ? Status.OK : Status.ERROR);
    message.setMessage(i18n.getString(result.getKey()));
    if (result.isValid()) {
        message.setDescription(expressionService.getExpressionDescription(expression));
    }
    webMessageService.sendJson(message, response);
}
Also used : DescriptiveWebMessage(org.hisp.dhis.dxf2.webmessage.DescriptiveWebMessage) ExpressionValidationOutcome(org.hisp.dhis.expression.ExpressionValidationOutcome) I18n(org.hisp.dhis.i18n.I18n) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with ExpressionValidationOutcome

use of org.hisp.dhis.expression.ExpressionValidationOutcome in project dhis2-core by dhis2.

the class DefaultDataIntegrityService method getInvalidValidationRuleExpressions.

private List<DataIntegrityIssue> getInvalidValidationRuleExpressions(Function<ValidationRule, Expression> getter) {
    List<DataIntegrityIssue> issues = new ArrayList<>();
    I18n i18n = i18nManager.getI18n();
    for (ValidationRule rule : validationRuleService.getAllValidationRules()) {
        ExpressionValidationOutcome result = expressionService.expressionIsValid(getter.apply(rule).getExpression(), VALIDATION_RULE_EXPRESSION);
        if (!result.isValid()) {
            issues.add(toIssue(rule, i18n.getString(result.getKey())));
        }
    }
    return issues;
}
Also used : DataIntegrityIssue(org.hisp.dhis.dataintegrity.DataIntegrityDetails.DataIntegrityIssue) ExpressionValidationOutcome(org.hisp.dhis.expression.ExpressionValidationOutcome) ArrayList(java.util.ArrayList) I18n(org.hisp.dhis.i18n.I18n) ValidationRule(org.hisp.dhis.validation.ValidationRule)

Example 5 with ExpressionValidationOutcome

use of org.hisp.dhis.expression.ExpressionValidationOutcome 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

ExpressionValidationOutcome (org.hisp.dhis.expression.ExpressionValidationOutcome)5 I18n (org.hisp.dhis.i18n.I18n)3 ArrayList (java.util.ArrayList)2 DataIntegrityIssue (org.hisp.dhis.dataintegrity.DataIntegrityDetails.DataIntegrityIssue)2 DescriptiveWebMessage (org.hisp.dhis.dxf2.webmessage.DescriptiveWebMessage)2 ExpressionResolver (org.hisp.dhis.analytics.resolver.ExpressionResolver)1 Indicator (org.hisp.dhis.indicator.Indicator)1 ProgramIndicator (org.hisp.dhis.program.ProgramIndicator)1 ValidationRule (org.hisp.dhis.validation.ValidationRule)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1