Search in sources :

Example 1 with ProcessSpecification

use of com.evolveum.midpoint.wf.impl.processors.primary.policy.ProcessSpecifications.ProcessSpecification in project midpoint by Evolveum.

the class ObjectPolicyAspectPart method extractObjectBasedInstructions.

<T extends ObjectType> void extractObjectBasedInstructions(@NotNull ObjectTreeDeltas<T> objectTreeDeltas, @Nullable PrismObject<? extends FocusType> requester, @NotNull List<PcpStartInstruction> instructions, @NotNull ModelInvocationContext<T> ctx, @NotNull OperationResult parentResult) throws SchemaException, ObjectNotFoundException {
    OperationResult result = parentResult.subresult(OP_EXTRACT_OBJECT_BASED_INSTRUCTIONS).setMinor().build();
    ApprovalProcessStartInstructionCreationTraceType trace;
    if (result.isTracingNormal(ApprovalProcessStartInstructionCreationTraceType.class)) {
        trace = new ApprovalProcessStartInstructionCreationTraceType(prismContext);
        result.addTrace(trace);
    } else {
        trace = null;
    }
    try {
        ObjectDelta<T> focusDelta = objectTreeDeltas.getFocusChange();
        LensFocusContext<T> focusContext = (LensFocusContext<T>) ctx.modelContext.getFocusContext();
        PrismObject<T> object = focusContext.getObjectOld() != null ? focusContext.getObjectOld() : focusContext.getObjectNew();
        List<? extends EvaluatedPolicyRule> triggeredApprovalActionRules = main.selectTriggeredApprovalActionRules(focusContext.getObjectPolicyRules());
        LOGGER.trace("extractObjectBasedInstructions: triggeredApprovalActionRules:\n{}", debugDumpLazily(triggeredApprovalActionRules));
        List<PcpStartInstruction> newInstructions = new ArrayList<>();
        if (!triggeredApprovalActionRules.isEmpty()) {
            generateObjectOidIfNeeded(focusDelta, ctx.modelContext);
            ProcessSpecifications processSpecifications = ProcessSpecifications.createFromRules(triggeredApprovalActionRules, prismContext);
            LOGGER.trace("Process specifications:\n{}", debugDumpLazily(processSpecifications));
            for (ProcessSpecification processSpecificationEntry : processSpecifications.getSpecifications()) {
                if (focusDelta.isEmpty()) {
                    // we're done
                    break;
                }
                WfProcessSpecificationType processSpecification = processSpecificationEntry.basicSpec;
                List<ObjectDelta<T>> deltasToApprove = extractDeltasToApprove(focusDelta, processSpecification);
                LOGGER.trace("Deltas to approve:\n{}", debugDumpLazily(deltasToApprove));
                if (deltasToApprove.isEmpty()) {
                    continue;
                }
                LOGGER.trace("Remaining delta:\n{}", debugDumpLazily(focusDelta));
                ApprovalSchemaBuilder builder = new ApprovalSchemaBuilder(main, approvalSchemaHelper);
                builder.setProcessSpecification(processSpecificationEntry);
                for (Pair<ApprovalPolicyActionType, EvaluatedPolicyRule> actionWithRule : processSpecificationEntry.actionsWithRules) {
                    ApprovalPolicyActionType approvalAction = actionWithRule.getLeft();
                    builder.add(main.getSchemaFromAction(approvalAction), approvalAction, object, actionWithRule.getRight());
                }
                buildSchemaForObject(requester, newInstructions, ctx, result, deltasToApprove, builder);
            }
        } else if (configurationHelper.getUseDefaultApprovalPolicyRules(ctx.wfConfiguration) != DefaultApprovalPolicyRulesUsageType.NEVER) {
            // default rule
            ApprovalSchemaBuilder builder = new ApprovalSchemaBuilder(main, approvalSchemaHelper);
            if (builder.addPredefined(object, RelationKindType.OWNER, result)) {
                LOGGER.trace("Added default approval action, as no explicit one was found");
                generateObjectOidIfNeeded(focusDelta, ctx.modelContext);
                List<ObjectDelta<T>> deltasToApprove = singletonList(focusDelta.clone());
                focusDelta.clear();
                buildSchemaForObject(requester, newInstructions, ctx, result, deltasToApprove, builder);
            }
        }
        if (trace != null) {
            for (PcpStartInstruction newInstruction : newInstructions) {
                trace.getCaseRef().add(ObjectTypeUtil.createObjectRefWithFullObject(newInstruction.getCase(), prismContext));
            }
        }
        instructions.addAll(newInstructions);
        result.addReturn("instructionsCreated", newInstructions.size());
    } catch (Throwable t) {
        result.recordFatalError(t);
        throw t;
    } finally {
        result.computeStatusIfUnknown();
    }
}
Also used : EvaluatedPolicyRule(com.evolveum.midpoint.model.api.context.EvaluatedPolicyRule) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ProcessSpecification(com.evolveum.midpoint.wf.impl.processors.primary.policy.ProcessSpecifications.ProcessSpecification) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) PcpStartInstruction(com.evolveum.midpoint.wf.impl.processors.primary.PcpStartInstruction) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) LensFocusContext(com.evolveum.midpoint.model.impl.lens.LensFocusContext)

Aggregations

EvaluatedPolicyRule (com.evolveum.midpoint.model.api.context.EvaluatedPolicyRule)1 LensFocusContext (com.evolveum.midpoint.model.impl.lens.LensFocusContext)1 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 PcpStartInstruction (com.evolveum.midpoint.wf.impl.processors.primary.PcpStartInstruction)1 ProcessSpecification (com.evolveum.midpoint.wf.impl.processors.primary.policy.ProcessSpecifications.ProcessSpecification)1 ArrayList (java.util.ArrayList)1 Collections.singletonList (java.util.Collections.singletonList)1 List (java.util.List)1