Search in sources :

Example 6 with LensFocusContext

use of com.evolveum.midpoint.model.impl.lens.LensFocusContext in project midpoint by Evolveum.

the class PolicyRuleBasedAspect method extractObjectBasedInstructions.

private void extractObjectBasedInstructions(@NotNull ObjectTreeDeltas objectTreeDeltas, PrismObject<UserType> requester, List<PcpChildWfTaskCreationInstruction> instructions, ModelInvocationContext ctx, @NotNull OperationResult result) throws SchemaException {
    ObjectDelta<?> focusDelta = objectTreeDeltas.getFocusChange();
    LensFocusContext<?> focusContext = (LensFocusContext<?>) ctx.modelContext.getFocusContext();
    PrismObject<?> object = focusContext.getObjectOld() != null ? focusContext.getObjectOld() : focusContext.getObjectNew();
    Map<Set<ItemPath>, ApprovalSchemaBuilder> schemaBuilders = new HashMap<>();
    List<EvaluatedPolicyRule> approvalActionRules = getApprovalActionRules(focusContext.getPolicyRules());
    LOGGER.trace("extractObjectBasedInstructions: approvalActionRules:\n{}", DebugUtil.debugDumpLazily(approvalActionRules));
    for (EvaluatedPolicyRule rule : approvalActionRules) {
        Set<ItemPath> key;
        if (focusDelta.isAdd() || focusDelta.isDelete()) {
            key = Collections.emptySet();
        } else {
            Set<ItemPath> items = getAffectedItems(rule.getTriggers());
            Set<ItemPath> affectedItems;
            if (!items.isEmpty()) {
                // all items in triggered constraints were modified (that's how the constraints work)
                affectedItems = items;
            } else {
                // whole object
                affectedItems = new HashSet<>(focusDelta.getModifiedItems());
            }
            key = affectedItems;
        }
        ApprovalSchemaBuilder builder = schemaBuilders.computeIfAbsent(key, k -> new ApprovalSchemaBuilder(this, approvalSchemaHelper));
        ApprovalPolicyActionType approvalAction = rule.getActions().getApproval();
        builder.add(getSchemaFromAction(approvalAction), approvalAction.getCompositionStrategy(), object, rule);
    }
    // default rule
    if (approvalActionRules.isEmpty() && baseConfigurationHelper.getUseDefaultApprovalPolicyRules(ctx.wfConfiguration) != DefaultApprovalPolicyRulesUsageType.NEVER) {
        ApprovalSchemaBuilder builder = new ApprovalSchemaBuilder(this, approvalSchemaHelper);
        if (builder.addPredefined(object, SchemaConstants.ORG_OWNER, result)) {
            LOGGER.trace("Added default approval action, as no explicit one was found");
            schemaBuilders.put(Collections.emptySet(), builder);
        }
    }
    // create approval requests; also test for overlaps
    Set<ItemPath> itemsProcessed = null;
    for (Map.Entry<Set<ItemPath>, ApprovalSchemaBuilder> entry : schemaBuilders.entrySet()) {
        ApprovalSchemaBuilder.Result builderResult = entry.getValue().buildSchema(ctx, result);
        if (approvalSchemaHelper.shouldBeSkipped(builderResult.schemaType)) {
            continue;
        }
        Set<ItemPath> items = entry.getKey();
        if (itemsProcessed != null) {
            if (items.isEmpty() || itemsProcessed.isEmpty() || CollectionUtils.containsAny(itemsProcessed, items)) {
                throw new IllegalStateException("Overlapping modification-related policy rules. " + "Items processed = " + itemsProcessed + ", current items = " + items);
            }
            itemsProcessed.addAll(items);
        } else {
            itemsProcessed = items;
        }
        instructions.add(prepareObjectRelatedTaskInstruction(builderResult, focusDelta, items, ctx.modelContext, requester, result));
    }
}
Also used : EvaluatedPolicyRule(com.evolveum.midpoint.model.api.context.EvaluatedPolicyRule) LensFocusContext(com.evolveum.midpoint.model.impl.lens.LensFocusContext) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 7 with LensFocusContext

use of com.evolveum.midpoint.model.impl.lens.LensFocusContext in project midpoint by Evolveum.

the class NotificationChangeHook method emitPolicyRulesEvents.

private void emitPolicyRulesEvents(ModelContext<?> context, Task task, OperationResult result) {
    LensFocusContext<?> focusContext = (LensFocusContext<?>) context.getFocusContext();
    for (EvaluatedPolicyRule rule : focusContext.getPolicyRules()) {
        emitPolicyEventIfPresent(rule, context, task, result);
    }
    DeltaSetTriple<EvaluatedAssignmentImpl<?>> triple = ((LensContext<?>) context).getEvaluatedAssignmentTriple();
    if (triple != null) {
        for (EvaluatedAssignment<?> assignment : triple.getNonNegativeValues()) {
            for (EvaluatedPolicyRule rule : assignment.getAllTargetsPolicyRules()) {
                emitPolicyEventIfPresent(rule, context, task, result);
            }
        }
    }
}
Also used : EvaluatedPolicyRule(com.evolveum.midpoint.model.api.context.EvaluatedPolicyRule) EvaluatedAssignmentImpl(com.evolveum.midpoint.model.impl.lens.EvaluatedAssignmentImpl) LensContext(com.evolveum.midpoint.model.impl.lens.LensContext) LensFocusContext(com.evolveum.midpoint.model.impl.lens.LensFocusContext)

Aggregations

LensFocusContext (com.evolveum.midpoint.model.impl.lens.LensFocusContext)7 LensContext (com.evolveum.midpoint.model.impl.lens.LensContext)4 ResourceShadowDiscriminator (com.evolveum.midpoint.schema.ResourceShadowDiscriminator)4 LensProjectionContext (com.evolveum.midpoint.model.impl.lens.LensProjectionContext)3 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)3 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)3 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)3 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)3 EvaluatedPolicyRule (com.evolveum.midpoint.model.api.context.EvaluatedPolicyRule)2 SynchronizationPolicyDecision (com.evolveum.midpoint.model.api.context.SynchronizationPolicyDecision)2 MappingFactory (com.evolveum.midpoint.model.common.mapping.MappingFactory)2 EvaluatedAssignmentImpl (com.evolveum.midpoint.model.impl.lens.EvaluatedAssignmentImpl)2 ItemDefinition (com.evolveum.midpoint.prism.ItemDefinition)2 PrismContext (com.evolveum.midpoint.prism.PrismContext)2 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)2 ContainerDelta (com.evolveum.midpoint.prism.delta.ContainerDelta)2 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)2 PrismValueDeltaSetTriple (com.evolveum.midpoint.prism.delta.PrismValueDeltaSetTriple)2 ReferenceDelta (com.evolveum.midpoint.prism.delta.ReferenceDelta)2