Search in sources :

Example 1 with WorkItemOperationSourceInfo

use of com.evolveum.midpoint.wf.api.WorkItemOperationSourceInfo in project midpoint by Evolveum.

the class WorkItemManager method delegateWorkItem.

// TODO when calling from model API, what should we put into escalationLevelName+DisplayName ?
// Probably the API should look different. E.g. there could be an "Escalate" button, that would look up the
// appropriate escalation timed action, and invoke it. We'll solve this when necessary. Until that time, be
// aware that escalationLevelName/DisplayName are for internal use only.
public void delegateWorkItem(String workItemId, List<ObjectReferenceType> delegates, WorkItemDelegationMethodType method, WorkItemEscalationLevelType escalation, Duration newDuration, WorkItemEventCauseInformationType causeInformation, OperationResult parentResult) throws ObjectNotFoundException, SecurityViolationException, SchemaException {
    OperationResult result = parentResult.createSubresult(OPERATION_DELEGATE_WORK_ITEM);
    result.addParam("workItemId", workItemId);
    result.addParam("escalation", escalation);
    result.addCollectionOfSerializablesAsParam("delegates", delegates);
    try {
        MidPointPrincipal principal = securityEnforcer.getPrincipal();
        result.addContext("user", toShortString(principal.getUser()));
        ObjectReferenceType initiator = causeInformation == null || causeInformation.getType() == WorkItemEventCauseTypeType.USER_ACTION ? ObjectTypeUtil.createObjectRef(principal.getUser()) : null;
        LOGGER.trace("Delegating work item {} to {}: escalation={}; cause={}", workItemId, delegates, escalation != null ? escalation.getName() + "/" + escalation.getDisplayName() : "none", causeInformation);
        WorkItemType workItem = workItemProvider.getWorkItem(workItemId, result);
        if (!miscDataUtil.isAuthorized(workItem, MiscDataUtil.RequestedOperation.DELEGATE)) {
            throw new SecurityViolationException("You are not authorized to delegate this work item.");
        }
        List<ObjectReferenceType> assigneesBefore = CloneUtil.cloneCollectionMembers(workItem.getAssigneeRef());
        WorkItemOperationKindType operationKind = escalation != null ? ESCALATE : DELEGATE;
        com.evolveum.midpoint.task.api.Task wfTask = taskManager.getTask(WfContextUtil.getTask(workItem).getOid(), result);
        WorkItemAllocationChangeOperationInfo operationInfoBefore = new WorkItemAllocationChangeOperationInfo(operationKind, assigneesBefore, null);
        WorkItemOperationSourceInfo sourceInfo = new WorkItemOperationSourceInfo(initiator, causeInformation, null);
        wfTaskController.notifyWorkItemAllocationChangeCurrentActors(workItem, operationInfoBefore, sourceInfo, null, wfTask, result);
        if (method == null) {
            method = WorkItemDelegationMethodType.REPLACE_ASSIGNEES;
        }
        List<ObjectReferenceType> newAssignees = new ArrayList<>();
        List<ObjectReferenceType> delegatedTo = new ArrayList<>();
        WfContextUtil.computeAssignees(newAssignees, delegatedTo, delegates, method, workItem);
        // don't change the current assignee, if not necessary
        TaskService taskService = activitiEngine.getTaskService();
        Task task = taskService.createTaskQuery().taskId(workItemId).singleResult();
        setNewAssignees(task, newAssignees, taskService);
        Date deadline = task.getDueDate();
        if (newDuration != null) {
            deadline = setNewDuration(task.getId(), newDuration, taskService);
        }
        Map<String, Object> variables = taskService.getVariables(workItemId);
        int escalationLevel = WfContextUtil.getEscalationLevelNumber(workItem);
        WorkItemEscalationLevelType newEscalation = WfContextUtil.createNewEscalation(escalationLevel, escalation);
        WorkItemDelegationEventType event = WfContextUtil.createDelegationEvent(newEscalation, assigneesBefore, delegatedTo, method, causeInformation);
        if (newEscalation != null) {
            escalationLevel++;
            taskService.setVariableLocal(workItemId, CommonProcessVariableNames.VARIABLE_ESCALATION_LEVEL_NUMBER, newEscalation.getNumber());
            taskService.setVariableLocal(workItemId, CommonProcessVariableNames.VARIABLE_ESCALATION_LEVEL_NAME, newEscalation.getName());
            taskService.setVariableLocal(workItemId, CommonProcessVariableNames.VARIABLE_ESCALATION_LEVEL_DISPLAY_NAME, newEscalation.getDisplayName());
        }
        ActivitiUtil.fillInWorkItemEvent(event, principal, workItemId, variables, prismContext);
        MidpointUtil.recordEventInTask(event, null, ActivitiUtil.getTaskOid(variables), result);
        ApprovalStageDefinitionType level = WfContextUtil.getCurrentStageDefinition(wfTask.getWorkflowContext());
        MidpointUtil.createTriggersForTimedActions(workItemId, escalationLevel, XmlTypeConverter.toDate(workItem.getCreateTimestamp()), deadline, wfTask, level.getTimedActions(), result);
        WorkItemType workItemAfter = workItemProvider.getWorkItem(workItemId, result);
        com.evolveum.midpoint.task.api.Task wfTaskAfter = taskManager.getTask(wfTask.getOid(), result);
        WorkItemAllocationChangeOperationInfo operationInfoAfter = new WorkItemAllocationChangeOperationInfo(operationKind, assigneesBefore, workItemAfter.getAssigneeRef());
        wfTaskController.notifyWorkItemAllocationChangeNewActors(workItemAfter, operationInfoAfter, sourceInfo, wfTaskAfter, result);
    } catch (SecurityViolationException | RuntimeException | ObjectNotFoundException | SchemaException e) {
        result.recordFatalError("Couldn't delegate/escalate work item " + workItemId + ": " + e.getMessage(), e);
        throw e;
    } finally {
        result.computeStatusIfUnknown();
    }
}
Also used : Task(org.activiti.engine.task.Task) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectTypeUtil.toShortString(com.evolveum.midpoint.schema.util.ObjectTypeUtil.toShortString) MidPointPrincipal(com.evolveum.midpoint.security.api.MidPointPrincipal) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) WorkItemOperationSourceInfo(com.evolveum.midpoint.wf.api.WorkItemOperationSourceInfo) TaskService(org.activiti.engine.TaskService) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) WorkItemAllocationChangeOperationInfo(com.evolveum.midpoint.wf.api.WorkItemAllocationChangeOperationInfo)

Example 2 with WorkItemOperationSourceInfo

use of com.evolveum.midpoint.wf.api.WorkItemOperationSourceInfo in project midpoint by Evolveum.

the class WfTimedActionTriggerHandler method executeNotifications.

private void executeNotifications(Duration timeBeforeAction, AbstractWorkItemActionType action, WorkItemType workItem, Task wfTask, OperationResult result) throws SchemaException {
    WorkItemOperationKindType operationKind = WfContextUtil.getOperationKind(action);
    WorkItemEventCauseInformationType cause = WfContextUtil.createCause(action);
    WorkItemAllocationChangeOperationInfo operationInfo = new WorkItemAllocationChangeOperationInfo(operationKind, workItem.getAssigneeRef(), null);
    WorkItemOperationSourceInfo sourceInfo = new WorkItemOperationSourceInfo(null, cause, action);
    wfTaskController.notifyWorkItemAllocationChangeCurrentActors(workItem, operationInfo, sourceInfo, timeBeforeAction, wfTask, result);
}
Also used : WorkItemOperationSourceInfo(com.evolveum.midpoint.wf.api.WorkItemOperationSourceInfo) WorkItemAllocationChangeOperationInfo(com.evolveum.midpoint.wf.api.WorkItemAllocationChangeOperationInfo)

Aggregations

WorkItemAllocationChangeOperationInfo (com.evolveum.midpoint.wf.api.WorkItemAllocationChangeOperationInfo)2 WorkItemOperationSourceInfo (com.evolveum.midpoint.wf.api.WorkItemOperationSourceInfo)2 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 ObjectTypeUtil.toShortString (com.evolveum.midpoint.schema.util.ObjectTypeUtil.toShortString)1 MidPointPrincipal (com.evolveum.midpoint.security.api.MidPointPrincipal)1 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)1 TaskService (org.activiti.engine.TaskService)1 Task (org.activiti.engine.task.Task)1