use of com.evolveum.midpoint.wf.impl.processors.primary.PcpStartInstruction in project midpoint by Evolveum.
the class AssignmentPolicyAspectPart method extractAssignmentBasedInstructions.
void extractAssignmentBasedInstructions(ObjectTreeDeltas<?> objectTreeDeltas, PrismObject<? extends FocusType> requester, List<PcpStartInstruction> instructions, ModelInvocationContext<?> ctx, OperationResult parentResult) throws SchemaException, ObjectNotFoundException {
OperationResult result = parentResult.subresult(OP_EXTRACT_ASSIGNMENT_BASED_INSTRUCTIONS).setMinor().build();
ApprovalProcessStartInstructionCreationTraceType trace;
if (result.isTracingNormal(ApprovalProcessStartInstructionCreationTraceType.class)) {
trace = new ApprovalProcessStartInstructionCreationTraceType(prismContext);
result.addTrace(trace);
} else {
trace = null;
}
try {
DeltaSetTriple<? extends EvaluatedAssignment<?>> evaluatedAssignmentTriple = ((LensContext<?>) ctx.modelContext).getEvaluatedAssignmentTriple();
LOGGER.trace("Processing evaluatedAssignmentTriple:\n{}", DebugUtil.debugDumpLazily(evaluatedAssignmentTriple));
if (evaluatedAssignmentTriple == null) {
return;
}
List<PcpStartInstruction> newInstructions = new ArrayList<>();
for (EvaluatedAssignment<?> assignmentAdded : evaluatedAssignmentTriple.union()) {
addIgnoreNull(newInstructions, createInstructionFromAssignment(assignmentAdded, objectTreeDeltas, requester, ctx, result));
}
int newInstructionsCount = newInstructions.size();
if (trace != null) {
for (PcpStartInstruction newInstruction : newInstructions) {
trace.getCaseRef().add(ObjectTypeUtil.createObjectRefWithFullObject(newInstruction.getCase(), prismContext));
}
}
instructions.addAll(newInstructions);
CompiledGuiProfile adminGuiConfiguration;
try {
adminGuiConfiguration = modelInteractionService.getCompiledGuiProfile(ctx.task, result);
} catch (CommunicationException | ConfigurationException | SecurityViolationException | ExpressionEvaluationException e) {
throw new SystemException(e.getMessage(), e);
}
Integer limit = adminGuiConfiguration.getRoleManagement() != null ? adminGuiConfiguration.getRoleManagement().getAssignmentApprovalRequestLimit() : null;
LOGGER.trace("Assignment-related approval instructions: {}; limit is {}", newInstructionsCount, limit);
if (limit != null && newInstructionsCount > limit) {
// TODO think about better error reporting
throw new IllegalStateException("Assignment approval request limit (" + limit + ") exceeded: you are trying to submit " + newInstructionsCount + " requests");
}
if (limit != null) {
result.addContext("assignmentApprovalRequestLimit", limit);
}
result.addReturn("instructionsCreated", newInstructions.size());
} catch (Throwable t) {
result.recordFatalError(t);
throw t;
} finally {
result.computeStatusIfUnknown();
}
}
use of com.evolveum.midpoint.wf.impl.processors.primary.PcpStartInstruction in project midpoint by Evolveum.
the class ObjectPolicyAspectPart method prepareObjectRelatedTaskInstructions.
private <T extends ObjectType> void prepareObjectRelatedTaskInstructions(List<PcpStartInstruction> instructions, ApprovalSchemaBuilder.Result builderResult, List<ObjectDelta<T>> deltasToApprove, PrismObject<? extends FocusType> requester, ModelInvocationContext<T> ctx, OperationResult result) throws SchemaException {
ModelContext<T> modelContext = ctx.modelContext;
for (ObjectDelta<T> deltaToApprove : deltasToApprove) {
LocalizableMessage processName = main.createProcessName(builderResult, null, ctx, result);
if (main.useDefaultProcessName(processName)) {
processName = createDefaultProcessName(ctx, deltaToApprove);
}
String processNameInDefaultLocale = localizationService.translate(processName, Locale.getDefault(), "(unnamed)");
PcpStartInstruction instruction = PcpStartInstruction.createItemApprovalInstruction(main.getChangeProcessor(), builderResult.schemaType, builderResult.attachedRules);
instruction.prepareCommonAttributes(main, modelContext, requester);
instruction.setDeltasToApprove(deltaToApprove);
instruction.setObjectRef(ctx);
instruction.setName(processNameInDefaultLocale, processName);
instructions.add(instruction);
}
}
use of com.evolveum.midpoint.wf.impl.processors.primary.PcpStartInstruction in project midpoint by Evolveum.
the class ApprovalSchemaExecutionInformationHelper method getApprovalSchemaPreview.
List<ApprovalSchemaExecutionInformationType> getApprovalSchemaPreview(ModelContext<?> modelContext, Task opTask, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException {
WfConfigurationType wfConfiguration = configurationHelper.getWorkflowConfiguration(modelContext, result);
ModelInvocationContext<?> ctx = new ModelInvocationContext<>(modelContext, wfConfiguration, prismContext, repositoryService, opTask);
List<PcpStartInstruction> taskInstructions = primaryChangeProcessor.previewModelInvocation(ctx, result);
List<ApprovalSchemaExecutionInformationType> rv = new ArrayList<>();
for (PcpStartInstruction taskInstruction : taskInstructions) {
OperationResult childResult = result.createMinorSubresult(ApprovalSchemaExecutionInformationHelper.class + ".getApprovalSchemaPreview");
try {
CaseType aCase = taskInstruction.getCase();
rv.add(getApprovalSchemaExecutionInformation(aCase, true, opTask, childResult));
childResult.computeStatus();
} catch (Throwable t) {
childResult.recordFatalError("Couldn't preview approval schema for " + taskInstruction, t);
}
}
return rv;
}
use of com.evolveum.midpoint.wf.impl.processors.primary.PcpStartInstruction in project midpoint by Evolveum.
the class PolicyRuleBasedAspect method getStartInstructions.
@NotNull
@Override
public <T extends ObjectType> List<PcpStartInstruction> getStartInstructions(@NotNull ObjectTreeDeltas<T> objectTreeDeltas, @NotNull ModelInvocationContext<T> ctx, @NotNull OperationResult parentResult) throws SchemaException, ObjectNotFoundException {
OperationResult result = parentResult.subresult(OP_GET_START_INSTRUCTIONS).setMinor().build();
try {
List<PcpStartInstruction> instructions = new ArrayList<>();
if (objectTreeDeltas.getFocusChange() != null) {
PrismObject<? extends FocusType> requester = ctx.getRequestor(result);
assignmentPolicyAspectPart.extractAssignmentBasedInstructions(objectTreeDeltas, requester, instructions, ctx, result);
objectPolicyAspectPart.extractObjectBasedInstructions(objectTreeDeltas, requester, instructions, ctx, result);
}
result.addParam("instructionsCount", instructions.size());
return instructions;
} catch (Throwable t) {
result.recordFatalError(t);
throw t;
} finally {
result.computeStatusIfUnknown();
}
}
use of com.evolveum.midpoint.wf.impl.processors.primary.PcpStartInstruction 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