All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.hisp.dhis.rules.RuleEngineExecution Maven / Gradle / Ivy

package org.hisp.dhis.rules;

import org.hisp.dhis.rules.models.Rule;
import org.hisp.dhis.rules.models.RuleEffect;
import org.hisp.dhis.rules.models.RuleEnrollment;
import org.hisp.dhis.rules.models.RuleEvent;
import org.hisp.dhis.rules.models.TrackerObjectType;

import javax.annotation.Nonnull;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;

class RuleEngineExecution
    implements Callable>
{
    private final RuleEvent event;

    private final RuleEnrollment enrollment;

    @Nonnull
    private final Map> supplementaryData;

    @Nonnull
    private final List rules;

    @Nonnull
    private Map valueMap;

    @Nonnull
    private RuleConditionEvaluator ruleConditionEvaluator;

    RuleEngineExecution( @Nonnull RuleEvent event, @Nonnull List rules,
        @Nonnull Map valueMap, Map> supplementaryData )
    {
        this.event = event;
        this.enrollment = null;
        this.valueMap = new HashMap<>( valueMap );
        this.rules = rules;
        this.supplementaryData = supplementaryData;
        this.ruleConditionEvaluator = new RuleConditionEvaluator();
    }

    RuleEngineExecution( @Nonnull RuleEnrollment enrollment, @Nonnull List rules,
                         @Nonnull Map valueMap, Map> supplementaryData )
    {
        this.event = null;
        this.enrollment = enrollment;
        this.valueMap = new HashMap<>( valueMap );
        this.rules = rules;
        this.supplementaryData = supplementaryData;
        this.ruleConditionEvaluator = new RuleConditionEvaluator();
    }

    @Override
    public List call()
    {
        if (event != null) {
            return ruleConditionEvaluator.getRuleEffects(TrackerObjectType.EVENT, event.event(), valueMap,
                    supplementaryData, this.rules );
        } else {
            return ruleConditionEvaluator.getRuleEffects( TrackerObjectType.ENROLLMENT, enrollment.enrollment(), valueMap,
                    supplementaryData, this.rules );
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy