Search in sources :

Example 6 with RuleAction

use of org.hisp.dhis.rules.models.RuleAction in project dhis2-android-sdk by dhis2.

the class RuleEngineValueTypesShould method fallback_to_default_text_value_on_variable_without_value.

@Test
public void fallback_to_default_text_value_on_variable_without_value() throws Exception {
    RuleAction ruleAction = RuleActionDisplayKeyValuePair.createForFeedback("test_action_content", "#{test_variable}");
    Rule rule = Rule.create(null, null, "true", Arrays.asList(ruleAction));
    RuleVariable ruleVariable = RuleVariableCurrentEvent.create("test_variable", "test_data_element", RuleValueType.TEXT);
    RuleEngine ruleEngine = RuleEngineContext.builder(new DuktapeEvaluator(duktape)).rules(Arrays.asList(rule)).ruleVariables(Arrays.asList(ruleVariable)).build().toEngineBuilder().build();
    RuleEvent ruleEvent = RuleEvent.create("test_event", "test_program_stage", RuleEvent.Status.ACTIVE, new Date(), new Date(), new ArrayList<RuleDataValue>());
    List<RuleEffect> ruleEffects = ruleEngine.evaluate(ruleEvent).call();
    assertThat(ruleEffects.size()).isEqualTo(1);
    assertThat(ruleEffects.get(0).data()).isEqualTo("");
    assertThat(ruleEffects.get(0).ruleAction()).isEqualTo(ruleAction);
}
Also used : RuleEngine(org.hisp.dhis.rules.RuleEngine) RuleEffect(org.hisp.dhis.rules.models.RuleEffect) RuleDataValue(org.hisp.dhis.rules.models.RuleDataValue) RuleAction(org.hisp.dhis.rules.models.RuleAction) Rule(org.hisp.dhis.rules.models.Rule) RuleEvent(org.hisp.dhis.rules.models.RuleEvent) Date(java.util.Date) RuleVariable(org.hisp.dhis.rules.models.RuleVariable) Test(org.junit.Test)

Example 7 with RuleAction

use of org.hisp.dhis.rules.models.RuleAction in project dhis2-core by dhis2.

the class ShowErrorWarningImplementerTest method getRuleEffectsLinkedToDataElement.

private List<RuleEffect> getRuleEffectsLinkedToDataElement() {
    RuleAction actionShowWarning = RuleActionShowWarning.create(IssueType.WARNING.name() + CONTENT, DATA, DATA_ELEMENT_ID, DATA_ELEMENT);
    RuleAction actionShowWarningOnComplete = RuleActionWarningOnCompletion.create(IssueType.WARNING.name() + CONTENT, DATA, DATA_ELEMENT_ID, DATA_ELEMENT);
    RuleAction actionShowError = RuleActionShowError.create(IssueType.ERROR.name() + CONTENT, DATA, DATA_ELEMENT_ID, DATA_ELEMENT);
    RuleAction actionShowErrorOnCompletion = RuleActionErrorOnCompletion.create(IssueType.ERROR.name() + CONTENT, DATA, DATA_ELEMENT_ID, DATA_ELEMENT);
    return Lists.newArrayList(RuleEffect.create("", actionShowWarning, EVALUATED_DATA), RuleEffect.create("", actionShowWarningOnComplete, EVALUATED_DATA), RuleEffect.create("", actionShowError, EVALUATED_DATA), RuleEffect.create("", actionShowErrorOnCompletion, EVALUATED_DATA));
}
Also used : RuleAction(org.hisp.dhis.rules.models.RuleAction)

Example 8 with RuleAction

use of org.hisp.dhis.rules.models.RuleAction in project dhis2-android-sdk by dhis2.

the class RuleEngineEffectTypesShould method return_hide_field_effect_after_create_simple_condition.

@Test
public void return_hide_field_effect_after_create_simple_condition() throws Exception {
    RuleAction ruleAction = RuleActionHideField.create("test_action_content", "test_data_element");
    Rule rule = Rule.create(null, null, "true", Arrays.asList(ruleAction));
    RuleEngine ruleEngine = RuleEngineContext.builder(new DuktapeEvaluator(duktape)).rules(Arrays.asList(rule)).build().toEngineBuilder().build();
    RuleEvent ruleEvent = RuleEvent.create("test_event", "test_program_stage", RuleEvent.Status.ACTIVE, new Date(), new Date(), Arrays.asList(RuleDataValue.create(new Date(), "test_program_stage", "test_data_element", "test_value")));
    List<RuleEffect> ruleEffects = ruleEngine.evaluate(ruleEvent).call();
    assertThat(ruleEffects.size()).isEqualTo(1);
    assertThat(ruleEffects.get(0).data()).isEqualTo("");
    assertThat(ruleEffects.get(0).ruleAction()).isEqualTo(ruleAction);
}
Also used : RuleEngine(org.hisp.dhis.rules.RuleEngine) RuleEffect(org.hisp.dhis.rules.models.RuleEffect) RuleAction(org.hisp.dhis.rules.models.RuleAction) Rule(org.hisp.dhis.rules.models.Rule) RuleEvent(org.hisp.dhis.rules.models.RuleEvent) Date(java.util.Date) Test(org.junit.Test)

Example 9 with RuleAction

use of org.hisp.dhis.rules.models.RuleAction in project dhis2-android-sdk by dhis2.

the class RuleEngineEffectTypesShould method return_assigned_effect_when_create_simple_event.

@Test
public void return_assigned_effect_when_create_simple_event() throws Exception {
    RuleAction ruleAction = RuleActionCreateEvent.create("test_action_content", "'event_uid;test_data_value_one'", "test_program_stage");
    Rule rule = Rule.create(null, null, "true", Arrays.asList(ruleAction));
    RuleEngine ruleEngine = RuleEngineContext.builder(new DuktapeEvaluator(duktape)).rules(Arrays.asList(rule)).build().toEngineBuilder().build();
    RuleEvent ruleEvent = RuleEvent.create("test_event", "test_program_stage", RuleEvent.Status.ACTIVE, new Date(), new Date(), Arrays.asList(RuleDataValue.create(new Date(), "test_program_stage", "test_data_element", "test_value")));
    List<RuleEffect> ruleEffects = ruleEngine.evaluate(ruleEvent).call();
    assertThat(ruleEffects.size()).isEqualTo(1);
    assertThat(ruleEffects.get(0).data()).isEqualTo("event_uid;test_data_value_one");
    assertThat(ruleEffects.get(0).ruleAction()).isEqualTo(ruleAction);
}
Also used : RuleEngine(org.hisp.dhis.rules.RuleEngine) RuleEffect(org.hisp.dhis.rules.models.RuleEffect) RuleAction(org.hisp.dhis.rules.models.RuleAction) Rule(org.hisp.dhis.rules.models.Rule) RuleEvent(org.hisp.dhis.rules.models.RuleEvent) Date(java.util.Date) Test(org.junit.Test)

Example 10 with RuleAction

use of org.hisp.dhis.rules.models.RuleAction in project dhis2-android-sdk by dhis2.

the class RuleEngineEffectTypesShould method return_on_error_effect_after_create_simple_condition.

@Test
public void return_on_error_effect_after_create_simple_condition() throws Exception {
    RuleAction ruleAction = RuleActionShowError.create("test_error_message", "2 + 2", "target_field");
    Rule rule = Rule.create(null, null, "true", Arrays.asList(ruleAction));
    RuleEngine ruleEngine = RuleEngineContext.builder(new DuktapeEvaluator(duktape)).rules(Arrays.asList(rule)).build().toEngineBuilder().build();
    RuleEvent ruleEvent = RuleEvent.create("test_event", "test_program_stage", RuleEvent.Status.ACTIVE, new Date(), new Date(), Arrays.asList(RuleDataValue.create(new Date(), "test_program_stage", "test_data_element", "test_value")));
    List<RuleEffect> ruleEffects = ruleEngine.evaluate(ruleEvent).call();
    assertThat(ruleEffects.size()).isEqualTo(1);
    assertThat(ruleEffects.get(0).data()).isEqualTo("4.0");
    assertThat(ruleEffects.get(0).ruleAction()).isEqualTo(ruleAction);
}
Also used : RuleEngine(org.hisp.dhis.rules.RuleEngine) RuleEffect(org.hisp.dhis.rules.models.RuleEffect) RuleAction(org.hisp.dhis.rules.models.RuleAction) Rule(org.hisp.dhis.rules.models.Rule) RuleEvent(org.hisp.dhis.rules.models.RuleEvent) Date(java.util.Date) Test(org.junit.Test)

Aggregations

RuleAction (org.hisp.dhis.rules.models.RuleAction)23 RuleEffect (org.hisp.dhis.rules.models.RuleEffect)19 Date (java.util.Date)18 RuleEngine (org.hisp.dhis.rules.RuleEngine)18 Rule (org.hisp.dhis.rules.models.Rule)18 RuleEvent (org.hisp.dhis.rules.models.RuleEvent)18 Test (org.junit.Test)18 RuleVariable (org.hisp.dhis.rules.models.RuleVariable)7 RuleDataValue (org.hisp.dhis.rules.models.RuleDataValue)4 ArrayList (java.util.ArrayList)1 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)1 ProgramInstance (org.hisp.dhis.program.ProgramInstance)1 ProgramRuleAction (org.hisp.dhis.programrule.ProgramRuleAction)1 RuleActionSendMessage (org.hisp.dhis.rules.models.RuleActionSendMessage)1 Test (org.junit.jupiter.api.Test)1