Search in sources :

Example 1 with RuleActionImplementer

use of org.hisp.dhis.programrule.engine.RuleActionImplementer in project dhis2-core by dhis2.

the class TrackerRuleEngineThread method call.

@Override
public void call() {
    if (sideEffectDataBundle == null) {
        return;
    }
    Map<String, List<RuleEffect>> enrollmentRuleEffects = trackerSideEffectConverterService.toRuleEffects(sideEffectDataBundle.getEnrollmentRuleEffects());
    Map<String, List<RuleEffect>> eventRuleEffects = trackerSideEffectConverterService.toRuleEffects(sideEffectDataBundle.getEventRuleEffects());
    for (RuleActionImplementer ruleActionImplementer : ruleActionImplementers) {
        for (Map.Entry<String, List<RuleEffect>> entry : enrollmentRuleEffects.entrySet()) {
            ProgramInstance pi = sideEffectDataBundle.getProgramInstance();
            pi.setProgram(sideEffectDataBundle.getProgram());
            entry.getValue().stream().filter(effect -> ruleActionImplementer.accept(effect.ruleAction())).forEach(effect -> ruleActionImplementer.implement(effect, pi));
        }
        for (Map.Entry<String, List<RuleEffect>> entry : eventRuleEffects.entrySet()) {
            ProgramStageInstance psi = sideEffectDataBundle.getProgramStageInstance();
            psi.getProgramStage().setProgram(sideEffectDataBundle.getProgram());
            entry.getValue().stream().filter(effect -> ruleActionImplementer.accept(effect.ruleAction())).forEach(effect -> ruleActionImplementer.implement(effect, psi));
        }
    }
    notifier.notify(sideEffectDataBundle.getJobConfiguration(), "Tracker Rule-engine side effects completed");
}
Also used : RuleActionImplementer(org.hisp.dhis.programrule.engine.RuleActionImplementer) RuleEffect(org.hisp.dhis.rules.models.RuleEffect) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) TrackerSideEffectConverterService(org.hisp.dhis.tracker.converter.TrackerSideEffectConverterService) Scope(org.springframework.context.annotation.Scope) Notifier(org.hisp.dhis.system.notification.Notifier) List(java.util.List) Component(org.springframework.stereotype.Component) Lists(com.google.common.collect.Lists) Map(java.util.Map) ProgramInstance(org.hisp.dhis.program.ProgramInstance) Qualifier(org.springframework.beans.factory.annotation.Qualifier) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) SecurityContextRunnable(org.hisp.dhis.security.SecurityContextRunnable) RuleActionImplementer(org.hisp.dhis.programrule.engine.RuleActionImplementer) ProgramInstance(org.hisp.dhis.program.ProgramInstance) List(java.util.List) Map(java.util.Map) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance)

Aggregations

Lists (com.google.common.collect.Lists)1 List (java.util.List)1 Map (java.util.Map)1 ProgramInstance (org.hisp.dhis.program.ProgramInstance)1 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)1 RuleActionImplementer (org.hisp.dhis.programrule.engine.RuleActionImplementer)1 RuleEffect (org.hisp.dhis.rules.models.RuleEffect)1 SecurityContextRunnable (org.hisp.dhis.security.SecurityContextRunnable)1 Notifier (org.hisp.dhis.system.notification.Notifier)1 TrackerSideEffectConverterService (org.hisp.dhis.tracker.converter.TrackerSideEffectConverterService)1 Qualifier (org.springframework.beans.factory.annotation.Qualifier)1 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)1 Scope (org.springframework.context.annotation.Scope)1 Component (org.springframework.stereotype.Component)1