Search in sources :

Example 1 with PcpStartInstruction

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();
    }
}
Also used : ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) LensContext(com.evolveum.midpoint.model.impl.lens.LensContext) SystemException(com.evolveum.midpoint.util.exception.SystemException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) PcpStartInstruction(com.evolveum.midpoint.wf.impl.processors.primary.PcpStartInstruction) CompiledGuiProfile(com.evolveum.midpoint.model.api.authentication.CompiledGuiProfile)

Example 2 with PcpStartInstruction

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);
    }
}
Also used : LocalizableMessage(com.evolveum.midpoint.util.LocalizableMessage) PcpStartInstruction(com.evolveum.midpoint.wf.impl.processors.primary.PcpStartInstruction)

Example 3 with PcpStartInstruction

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;
}
Also used : ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PcpStartInstruction(com.evolveum.midpoint.wf.impl.processors.primary.PcpStartInstruction) ModelInvocationContext(com.evolveum.midpoint.wf.impl.processors.ModelInvocationContext)

Example 4 with PcpStartInstruction

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();
    }
}
Also used : ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PcpStartInstruction(com.evolveum.midpoint.wf.impl.processors.primary.PcpStartInstruction) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with PcpStartInstruction

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

PcpStartInstruction (com.evolveum.midpoint.wf.impl.processors.primary.PcpStartInstruction)7 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)4 ArrayList (java.util.ArrayList)4 LocalizableMessage (com.evolveum.midpoint.util.LocalizableMessage)2 CompiledGuiProfile (com.evolveum.midpoint.model.api.authentication.CompiledGuiProfile)1 EvaluatedPolicyRule (com.evolveum.midpoint.model.api.context.EvaluatedPolicyRule)1 LensContext (com.evolveum.midpoint.model.impl.lens.LensContext)1 LensFocusContext (com.evolveum.midpoint.model.impl.lens.LensFocusContext)1 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 PrismObject.asPrismObject (com.evolveum.midpoint.prism.PrismObject.asPrismObject)1 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)1 ObjectTreeDeltas (com.evolveum.midpoint.schema.ObjectTreeDeltas)1 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)1 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)1 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)1 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)1 SystemException (com.evolveum.midpoint.util.exception.SystemException)1 ModelInvocationContext (com.evolveum.midpoint.wf.impl.processors.ModelInvocationContext)1 ProcessSpecification (com.evolveum.midpoint.wf.impl.processors.primary.policy.ProcessSpecifications.ProcessSpecification)1 Collections.singletonList (java.util.Collections.singletonList)1