Search in sources :

Example 1 with EvaluatedPolicyRuleTrigger

use of com.evolveum.midpoint.model.api.context.EvaluatedPolicyRuleTrigger in project midpoint by Evolveum.

the class FocusProcessor method triggerRule.

private <F extends FocusType> void triggerRule(LensFocusContext<F> focusContext, EvaluatedPolicyRule policyRule) throws PolicyViolationException, SchemaException {
    PolicyConstraintsType policyConstraints = policyRule.getPolicyConstraints();
    if (policyConstraints == null) {
        return;
    }
    for (ModificationPolicyConstraintType modificationConstraintType : policyConstraints.getModification()) {
        focusContext.addPolicyRule(policyRule);
        if (modificationConstraintMatches(focusContext, policyRule, modificationConstraintType)) {
            EvaluatedPolicyRuleTrigger<?> trigger = new EvaluatedPolicyRuleTrigger<>(PolicyConstraintKindType.MODIFICATION, modificationConstraintType, "Focus " + focusContext.getHumanReadableName() + " was modified");
            focusContext.triggerConstraint(policyRule, trigger);
        }
    }
}
Also used : PolicyConstraintsType(com.evolveum.midpoint.xml.ns._public.common.common_3.PolicyConstraintsType) EvaluatedPolicyRuleTrigger(com.evolveum.midpoint.model.api.context.EvaluatedPolicyRuleTrigger) ModificationPolicyConstraintType(com.evolveum.midpoint.xml.ns._public.common.common_3.ModificationPolicyConstraintType)

Example 2 with EvaluatedPolicyRuleTrigger

use of com.evolveum.midpoint.model.api.context.EvaluatedPolicyRuleTrigger in project midpoint by Evolveum.

the class TransitionConstraintEvaluator method evaluate.

@Override
public <AH extends AssignmentHolderType> EvaluatedPolicyRuleTrigger evaluate(@NotNull JAXBElement<TransitionPolicyConstraintType> constraintElement, @NotNull PolicyRuleEvaluationContext<AH> rctx, OperationResult parentResult) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException {
    OperationResult result = parentResult.subresult(OP_EVALUATE).setMinor().build();
    try {
        TransitionPolicyConstraintType trans = constraintElement.getValue();
        List<EvaluatedPolicyRuleTrigger<?>> triggers = new ArrayList<>();
        boolean match = evaluateState(trans, rctx, ObjectState.BEFORE, trans.isStateBefore(), triggers, result) && evaluateState(trans, rctx, ObjectState.AFTER, trans.isStateAfter(), triggers, result);
        if (match) {
            return new EvaluatedTransitionTrigger(PolicyConstraintKindType.TRANSITION, trans, createMessage(constraintElement, rctx, result), createShortMessage(constraintElement, rctx, result), triggers);
        } else {
            return null;
        }
    } catch (Throwable t) {
        result.recordFatalError(t.getMessage(), t);
        throw t;
    } finally {
        result.computeStatusIfUnknown();
    }
}
Also used : TransitionPolicyConstraintType(com.evolveum.midpoint.xml.ns._public.common.common_3.TransitionPolicyConstraintType) EvaluatedPolicyRuleTrigger(com.evolveum.midpoint.model.api.context.EvaluatedPolicyRuleTrigger) EvaluatedTransitionTrigger(com.evolveum.midpoint.model.api.context.EvaluatedTransitionTrigger) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 3 with EvaluatedPolicyRuleTrigger

use of com.evolveum.midpoint.model.api.context.EvaluatedPolicyRuleTrigger in project midpoint by Evolveum.

the class PolicyRuleBasedAspect method logApprovalActions.

private void logApprovalActions(EvaluatedAssignment<?> newAssignment, List<EvaluatedPolicyRule> triggeredApprovalActionRules, PlusMinusZero plusMinusZero) {
    if (LOGGER.isDebugEnabled() && !triggeredApprovalActionRules.isEmpty()) {
        LOGGER.trace("-------------------------------------------------------------");
        LOGGER.debug("Assignment to be {}: {}: {} this target policy rules, {} triggered approval actions:", plusMinusZero == PlusMinusZero.PLUS ? "added" : "deleted", newAssignment, newAssignment.getThisTargetPolicyRules().size(), triggeredApprovalActionRules.size());
        for (EvaluatedPolicyRule t : triggeredApprovalActionRules) {
            LOGGER.debug(" - Approval action: {}", t.getActions().getApproval());
            for (EvaluatedPolicyRuleTrigger trigger : t.getTriggers()) {
                LOGGER.debug("   - {}", trigger);
            }
        }
    }
}
Also used : EvaluatedPolicyRule(com.evolveum.midpoint.model.api.context.EvaluatedPolicyRule) EvaluatedPolicyRuleTrigger(com.evolveum.midpoint.model.api.context.EvaluatedPolicyRuleTrigger)

Example 4 with EvaluatedPolicyRuleTrigger

use of com.evolveum.midpoint.model.api.context.EvaluatedPolicyRuleTrigger in project midpoint by Evolveum.

the class CompositeConstraintEvaluator method evaluate.

@Override
public <AH extends AssignmentHolderType> EvaluatedCompositeTrigger evaluate(@NotNull JAXBElement<PolicyConstraintsType> constraint, @NotNull PolicyRuleEvaluationContext<AH> rctx, OperationResult parentResult) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException {
    OperationResult result = parentResult.subresult(OP_EVALUATE).setMinor().build();
    try {
        boolean isAnd = QNameUtil.match(PolicyConstraintsType.F_AND, constraint.getName());
        boolean isOr = QNameUtil.match(PolicyConstraintsType.F_OR, constraint.getName());
        boolean isNot = QNameUtil.match(PolicyConstraintsType.F_NOT, constraint.getName());
        assert isAnd || isOr || isNot;
        List<EvaluatedPolicyRuleTrigger<?>> triggers = policyRuleProcessor.evaluateConstraints(constraint.getValue(), !isOr, rctx, result);
        EvaluatedCompositeTrigger rv;
        if (isNot) {
            if (triggers.isEmpty()) {
                rv = createTrigger(NOT, constraint, triggers, rctx, result);
            } else {
                rv = null;
            }
        } else {
            if (!triggers.isEmpty()) {
                rv = createTrigger(isAnd ? AND : OR, constraint, triggers, rctx, result);
            } else {
                rv = null;
            }
        }
        if (rv != null) {
            result.addReturn("trigger", rv.toDiagShortcut());
        }
        return rv;
    } catch (Throwable t) {
        result.recordFatalError(t.getMessage(), t);
        throw t;
    } finally {
        result.computeStatusIfUnknown();
    }
}
Also used : EvaluatedPolicyRuleTrigger(com.evolveum.midpoint.model.api.context.EvaluatedPolicyRuleTrigger) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) EvaluatedCompositeTrigger(com.evolveum.midpoint.model.api.context.EvaluatedCompositeTrigger)

Aggregations

EvaluatedPolicyRuleTrigger (com.evolveum.midpoint.model.api.context.EvaluatedPolicyRuleTrigger)4 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2 EvaluatedCompositeTrigger (com.evolveum.midpoint.model.api.context.EvaluatedCompositeTrigger)1 EvaluatedPolicyRule (com.evolveum.midpoint.model.api.context.EvaluatedPolicyRule)1 EvaluatedTransitionTrigger (com.evolveum.midpoint.model.api.context.EvaluatedTransitionTrigger)1 ModificationPolicyConstraintType (com.evolveum.midpoint.xml.ns._public.common.common_3.ModificationPolicyConstraintType)1 PolicyConstraintsType (com.evolveum.midpoint.xml.ns._public.common.common_3.PolicyConstraintsType)1 TransitionPolicyConstraintType (com.evolveum.midpoint.xml.ns._public.common.common_3.TransitionPolicyConstraintType)1 ArrayList (java.util.ArrayList)1