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;
}
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;
}
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);
}
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;
}
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()));
}
Aggregations