Search in sources :

Example 1 with DescriptiveWebMessage

use of org.hisp.dhis.dxf2.webmessage.DescriptiveWebMessage in project dhis2-core by dhis2.

the class ProgramIndicatorController method validateFilter.

@RequestMapping(value = "/filter/description", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public void validateFilter(@RequestBody String expression, HttpServletResponse response) throws IOException {
    I18n i18n = i18nManager.getI18n();
    String result = programIndicatorService.filterIsValid(expression);
    DescriptiveWebMessage message = new DescriptiveWebMessage();
    message.setStatus(ProgramIndicator.VALID.equals(result) ? Status.OK : Status.ERROR);
    message.setMessage(i18n.getString(result));
    if (message.isOk()) {
        message.setDescription(programIndicatorService.getExpressionDescription(expression));
    }
    webMessageService.sendJson(message, response);
}
Also used : DescriptiveWebMessage(org.hisp.dhis.dxf2.webmessage.DescriptiveWebMessage) I18n(org.hisp.dhis.i18n.I18n) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with DescriptiveWebMessage

use of org.hisp.dhis.dxf2.webmessage.DescriptiveWebMessage in project dhis2-core by dhis2.

the class ProgramIndicatorController method getExpressionDescription.

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

Example 3 with DescriptiveWebMessage

use of org.hisp.dhis.dxf2.webmessage.DescriptiveWebMessage in project dhis2-core by dhis2.

the class ProgramRuleController method validateCondition.

@PostMapping(value = "/condition/description", produces = APPLICATION_JSON_VALUE)
@ResponseBody
public WebMessage validateCondition(@RequestBody String condition, @RequestParam String programId) {
    I18n i18n = i18nManager.getI18n();
    RuleValidationResult result = programRuleEngineService.getDescription(condition, programId);
    if (result.isValid()) {
        return new DescriptiveWebMessage(Status.OK, HttpStatus.OK).setDescription(result.getDescription()).setMessage(i18n.getString(ProgramIndicator.VALID));
    }
    String description = null;
    if (result.getErrorMessage() != null) {
        description = result.getErrorMessage();
    } else if (result.getException() != null) {
        description = result.getException().getMessage();
    }
    return new DescriptiveWebMessage(Status.ERROR, HttpStatus.OK).setDescription(description).setMessage(i18n.getString(ProgramIndicator.EXPRESSION_NOT_VALID));
}
Also used : DescriptiveWebMessage(org.hisp.dhis.dxf2.webmessage.DescriptiveWebMessage) RuleValidationResult(org.hisp.dhis.rules.models.RuleValidationResult) I18n(org.hisp.dhis.i18n.I18n) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with DescriptiveWebMessage

use of org.hisp.dhis.dxf2.webmessage.DescriptiveWebMessage in project dhis2-core by dhis2.

the class ProgramRuleActionController method getDataExpressionDescription.

@PostMapping(value = "/data/expression/description", produces = APPLICATION_JSON_VALUE)
@ResponseBody
public WebMessage getDataExpressionDescription(@RequestBody String condition, @RequestParam String programId) {
    I18n i18n = i18nManager.getI18n();
    RuleValidationResult result = programRuleEngineService.getDataExpressionDescription(condition, programId);
    if (result.isValid()) {
        return new DescriptiveWebMessage(Status.OK, HttpStatus.OK).setDescription(result.getDescription()).setMessage(i18n.getString(ProgramIndicator.VALID));
    }
    String description = null;
    if (result.getErrorMessage() != null) {
        description = result.getErrorMessage();
    } else if (result.getException() != null) {
        description = result.getException().getMessage();
    }
    return new DescriptiveWebMessage(Status.ERROR, HttpStatus.CONFLICT).setDescription(description).setMessage(i18n.getString(ProgramIndicator.EXPRESSION_NOT_VALID));
}
Also used : DescriptiveWebMessage(org.hisp.dhis.dxf2.webmessage.DescriptiveWebMessage) RuleValidationResult(org.hisp.dhis.rules.models.RuleValidationResult) I18n(org.hisp.dhis.i18n.I18n) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 5 with DescriptiveWebMessage

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

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