Search in sources :

Example 1 with EvaluatedModificationTrigger

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

the class ObjectModificationConstraintEvaluator method evaluate.

@Override
public <AH extends AssignmentHolderType> EvaluatedModificationTrigger evaluate(@NotNull JAXBElement<ModificationPolicyConstraintType> constraint, @NotNull PolicyRuleEvaluationContext<AH> rctx, OperationResult parentResult) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException {
    OperationResult result = parentResult.subresult(OP_EVALUATE).setMinor().build();
    try {
        if (!(rctx instanceof ObjectPolicyRuleEvaluationContext)) {
            LOGGER.trace("Policy rule evaluation context is not of type ObjectPolicyRuleEvaluationContext. Skipping processing.");
            return null;
        }
        ObjectPolicyRuleEvaluationContext<AH> ctx = (ObjectPolicyRuleEvaluationContext<AH>) rctx;
        if (modificationConstraintMatches(constraint, ctx, result)) {
            LocalizableMessage message = createMessage(constraint, rctx, result);
            LocalizableMessage shortMessage = createShortMessage(constraint, rctx, result);
            return new EvaluatedModificationTrigger(PolicyConstraintKindType.OBJECT_MODIFICATION, constraint.getValue(), null, message, shortMessage);
        } else {
            LOGGER.trace("No operation matches.");
            return null;
        }
    } catch (Throwable t) {
        result.recordFatalError(t.getMessage(), t);
        throw t;
    } finally {
        result.computeStatusIfUnknown();
    }
}
Also used : EvaluatedModificationTrigger(com.evolveum.midpoint.model.api.context.EvaluatedModificationTrigger) ObjectPolicyRuleEvaluationContext(com.evolveum.midpoint.model.impl.lens.projector.policy.ObjectPolicyRuleEvaluationContext) LocalizableMessage(com.evolveum.midpoint.util.LocalizableMessage) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 2 with EvaluatedModificationTrigger

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

the class AssignmentModificationConstraintEvaluator method evaluate.

@Override
public <AH extends AssignmentHolderType> EvaluatedModificationTrigger evaluate(@NotNull JAXBElement<AssignmentModificationPolicyConstraintType> constraintElement, @NotNull PolicyRuleEvaluationContext<AH> rctx, OperationResult parentResult) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException {
    OperationResult result = parentResult.subresult(OP_EVALUATE).setMinor().build();
    try {
        if (!(rctx instanceof AssignmentPolicyRuleEvaluationContext)) {
            LOGGER.trace("Not an AssignmentPolicyRuleEvaluationContext: {}", rctx.getClass());
            return null;
        }
        AssignmentPolicyRuleEvaluationContext<AH> ctx = (AssignmentPolicyRuleEvaluationContext<AH>) rctx;
        if (!ctx.isDirect) {
            LOGGER.trace("Assignment is indirect => not triggering");
            return null;
        }
        AssignmentModificationPolicyConstraintType constraint = constraintElement.getValue();
        if (!operationMatches(constraint, ctx.isAdded, ctx.isKept, ctx.isDeleted) || !relationMatches(constraint, ctx) || !pathsMatch(constraint, ctx) || !expressionPasses(constraintElement, ctx, result)) {
            // Logging is done inside matcher methods
            return null;
        }
        // TODO check modifications
        EvaluatedModificationTrigger rv = new EvaluatedModificationTrigger(PolicyConstraintKindType.ASSIGNMENT_MODIFICATION, constraint, ctx.evaluatedAssignment.getTarget(), createMessage(constraintElement, ctx, result), createShortMessage(constraintElement, ctx, result));
        result.addReturn("trigger", rv.toDiagShortcut());
        return rv;
    } catch (Throwable t) {
        result.recordFatalError(t.getMessage(), t);
        throw t;
    } finally {
        result.computeStatusIfUnknown();
    }
}
Also used : EvaluatedModificationTrigger(com.evolveum.midpoint.model.api.context.EvaluatedModificationTrigger) AssignmentPolicyRuleEvaluationContext(com.evolveum.midpoint.model.impl.lens.projector.policy.AssignmentPolicyRuleEvaluationContext) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Aggregations

EvaluatedModificationTrigger (com.evolveum.midpoint.model.api.context.EvaluatedModificationTrigger)2 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2 AssignmentPolicyRuleEvaluationContext (com.evolveum.midpoint.model.impl.lens.projector.policy.AssignmentPolicyRuleEvaluationContext)1 ObjectPolicyRuleEvaluationContext (com.evolveum.midpoint.model.impl.lens.projector.policy.ObjectPolicyRuleEvaluationContext)1 LocalizableMessage (com.evolveum.midpoint.util.LocalizableMessage)1