use of org.hisp.dhis.rules.models.RuleValidationResult in project dhis2-core by dhis2.
the class ProgramRuleEngineDescriptionTest method testDataFieldExpressionDescription.
@Test
void testDataFieldExpressionDescription() {
RuleValidationResult result = programRuleEngineNew.getDataExpressionDescription("1 + 2 +", program);
assertNotNull(result);
assertFalse(result.isValid());
assertThat(result.getException(), instanceOf(IllegalStateException.class));
result = programRuleEngineNew.getDataExpressionDescription("d2:daysBetween(V{completed_date},V{current_date}) > 0 )", program);
assertNotNull(result);
assertFalse(result.isValid());
assertThat(result.getException(), instanceOf(IllegalStateException.class));
result = programRuleEngineNew.getDataExpressionDescription(conditionWithD2DaysBetween, program);
assertNotNull(result);
assertTrue(result.isValid());
assertEquals("d2:daysBetween(Completed date,Current date) > 0", result.getDescription());
result = programRuleEngineNew.getDataExpressionDescription(programRuleNumericDE.getCondition(), program);
assertNotNull(result);
assertTrue(result.isValid());
assertEquals("DataElementE == 14", result.getDescription());
result = programRuleEngineNew.getDataExpressionDescription(programRuleNumericAtt.getCondition(), program);
assertNotNull(result);
assertTrue(result.isValid());
assertEquals("AttributeB == 12 || Current date", result.getDescription());
result = programRuleEngineNew.getDataExpressionDescription("'2020-12-12'", program);
assertNotNull(result);
assertTrue(result.isValid());
assertEquals("'2020-12-12'", result.getDescription());
result = programRuleEngineNew.getDataExpressionDescription("1 + 1", program);
assertNotNull(result);
assertTrue(result.isValid());
assertEquals("1 + 1", result.getDescription());
result = programRuleEngineNew.getDataExpressionDescription("'sample text'", program);
assertNotNull(result);
assertTrue(result.isValid());
assertEquals("'sample text'", result.getDescription());
}
use of org.hisp.dhis.rules.models.RuleValidationResult in project dhis2-core by dhis2.
the class ProgramRuleEngineDescriptionTest method testProgramRuleWithD2DaysBetween.
@Test
void testProgramRuleWithD2DaysBetween() {
RuleValidationResult result = validateRuleCondition(conditionWithD2DaysBetween, program);
assertNotNull(result);
assertEquals("d2:daysBetween(Completed date,Current date) > 0", result.getDescription());
assertTrue(result.isValid());
}
use of org.hisp.dhis.rules.models.RuleValidationResult in project dhis2-core by dhis2.
the class ProgramRuleEngineDescriptionTest method testProgramRuleWithCalculatedValueRuleVariable.
@Test
void testProgramRuleWithCalculatedValueRuleVariable() {
RuleValidationResult result = validateRuleCondition("#{prv1}+#{prv2}>0", program);
assertNotNull(result);
assertEquals("prv1+prv2>0", result.getDescription());
assertTrue(result.isValid());
}
use of org.hisp.dhis.rules.models.RuleValidationResult in project dhis2-core by dhis2.
the class ProgramRuleEngineDescriptionTest method testIncorrectRuleWithLiterals.
@Test
void testIncorrectRuleWithLiterals() {
RuleValidationResult result = validateRuleCondition("1 > 2 +", program);
assertNotNull(result);
assertFalse(result.isValid());
assertThat(result.getException(), instanceOf(IllegalStateException.class));
}
use of org.hisp.dhis.rules.models.RuleValidationResult 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));
}
Aggregations