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();
}
}
Aggregations