use of org.activiti.engine.TaskService in project midpoint by Evolveum.
the class WorkItemManager method releaseWorkItem.
public void releaseWorkItem(String workItemId, OperationResult parentResult) throws ObjectNotFoundException, SecurityViolationException {
OperationResult result = parentResult.createSubresult(OPERATION_RELEASE_WORK_ITEM);
result.addParam("workItemId", workItemId);
try {
MidPointPrincipal principal = securityEnforcer.getPrincipal();
result.addContext("user", toShortString(principal.getUser()));
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Releasing work item {} by {}", workItemId, toShortString(principal.getUser()));
}
TaskService taskService = activitiEngine.getTaskService();
Task task = taskService.createTaskQuery().taskId(workItemId).singleResult();
if (task == null) {
throw new ObjectNotFoundException("The work item does not exist");
}
if (task.getAssignee() == null) {
throw new SystemException("The work item is not assigned to a user");
}
if (!MiscDataUtil.stringToRef(task.getAssignee()).getOid().equals(principal.getOid())) {
throw new SystemException("The work item is not assigned to the current user");
}
boolean candidateFound = false;
for (IdentityLink link : taskService.getIdentityLinksForTask(workItemId)) {
if (IdentityLinkType.CANDIDATE.equals(link.getType())) {
candidateFound = true;
break;
}
}
if (!candidateFound) {
throw new SystemException("It has no candidates to be offered to");
}
taskService.unclaim(workItemId);
task = taskService.createTaskQuery().taskId(workItemId).singleResult();
if (task == null) {
throw new ObjectNotFoundException("The work item does not exist");
}
setNewAssignees(task, Collections.emptyList(), taskService);
} catch (ObjectNotFoundException | SecurityViolationException | RuntimeException e) {
result.recordFatalError("Couldn't release work item " + workItemId + ": " + e.getMessage(), e);
throw e;
} finally {
result.computeStatusIfUnknown();
}
}
use of org.activiti.engine.TaskService in project midpoint by Evolveum.
the class WorkItemManager method completeWorkItem.
public void completeWorkItem(String workItemId, String outcome, String comment, ObjectDelta additionalDelta, WorkItemEventCauseInformationType causeInformation, OperationResult parentResult) throws SecurityViolationException, SchemaException {
OperationResult result = parentResult.createSubresult(OPERATION_COMPLETE_WORK_ITEM);
result.addParams(new String[] { "workItemId", "decision", "comment", "additionalDelta" }, workItemId, outcome, comment, additionalDelta);
try {
final String userDescription = toShortString(securityEnforcer.getPrincipal().getUser());
result.addContext("user", userDescription);
LOGGER.trace("Completing work item {} with decision of {} ['{}'] by {}; cause: {}", workItemId, outcome, comment, userDescription, causeInformation);
TaskService taskService = activitiEngine.getTaskService();
taskService.setVariableLocal(workItemId, CommonProcessVariableNames.VARIABLE_CAUSE, new SingleItemSerializationSafeContainerImpl<>(causeInformation, prismContext));
//TaskFormData data = activitiEngine.getFormService().getTaskFormData(workItemId);
WorkItemType workItem = workItemProvider.getWorkItem(workItemId, result);
if (!miscDataUtil.isAuthorized(workItem, MiscDataUtil.RequestedOperation.COMPLETE)) {
throw new SecurityViolationException("You are not authorized to complete this work item.");
}
final Map<String, String> propertiesToSubmit = new HashMap<>();
propertiesToSubmit.put(CommonProcessVariableNames.FORM_FIELD_OUTCOME, outcome);
propertiesToSubmit.put(CommonProcessVariableNames.FORM_FIELD_COMMENT, comment);
if (additionalDelta != null) {
@SuppressWarnings({ "unchecked", "raw" }) ObjectDelta<? extends ObjectType> additionalDeltaCasted = ((ObjectDelta<? extends ObjectType>) additionalDelta);
ObjectDeltaType objectDeltaType = DeltaConvertor.toObjectDeltaType(additionalDeltaCasted);
String xmlDelta = prismContext.xmlSerializer().serializeRealValue(objectDeltaType, SchemaConstants.T_OBJECT_DELTA);
propertiesToSubmit.put(CommonProcessVariableNames.FORM_FIELD_ADDITIONAL_DELTA, xmlDelta);
}
LOGGER.trace("Submitting {} properties", propertiesToSubmit.size());
//formService.submitTaskFormData(workItemId, propertiesToSubmit);
Map<String, Object> variables = new HashMap<>(propertiesToSubmit);
taskService.complete(workItemId, variables, true);
} catch (SecurityViolationException | SchemaException | RuntimeException e) {
result.recordFatalError("Couldn't complete the work item " + workItemId + ": " + e.getMessage(), e);
throw e;
} finally {
result.computeStatusIfUnknown();
}
}
use of org.activiti.engine.TaskService in project midpoint by Evolveum.
the class WorkItemManager method claimWorkItem.
public void claimWorkItem(String workItemId, OperationResult parentResult) throws SecurityViolationException, ObjectNotFoundException {
OperationResult result = parentResult.createSubresult(OPERATION_CLAIM_WORK_ITEM);
result.addParam("workItemId", workItemId);
try {
MidPointPrincipal principal = securityEnforcer.getPrincipal();
result.addContext("user", toShortString(principal.getUser()));
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Claiming work item {} by {}", workItemId, toShortString(principal.getUser()));
}
TaskService taskService = activitiEngine.getTaskService();
Task task = taskService.createTaskQuery().taskId(workItemId).singleResult();
if (task == null) {
throw new ObjectNotFoundException("The work item does not exist");
}
if (task.getAssignee() != null) {
String desc = MiscDataUtil.stringToRef(task.getAssignee()).getOid().equals(principal.getOid()) ? "the current" : "another";
throw new SystemException("The work item is already assigned to " + desc + " user");
}
if (!miscDataUtil.isAuthorizedToClaim(task.getId())) {
throw new SecurityViolationException("You are not authorized to claim the selected work item.");
}
taskService.claim(workItemId, principal.getOid());
task = taskService.createTaskQuery().taskId(workItemId).singleResult();
if (task == null) {
throw new ObjectNotFoundException("The work item does not exist");
}
setNewAssignees(task, Collections.singletonList(ObjectTypeUtil.createObjectRef(principal.getOid(), ObjectTypes.USER)), taskService);
} catch (ObjectNotFoundException | SecurityViolationException | RuntimeException e) {
result.recordFatalError("Couldn't claim the work item " + workItemId + ": " + e.getMessage(), e);
throw e;
} finally {
result.computeStatusIfUnknown();
}
}
use of org.activiti.engine.TaskService 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();
}
}
use of org.activiti.engine.TaskService in project midpoint by Evolveum.
the class WorkItemProvider method getWorkItemsForProcessInstanceId.
// special interface for ProcessInstanceProvider - TODO align with other interfaces
public SearchResultList<WorkItemType> getWorkItemsForProcessInstanceId(String processInstanceId, OperationResult result) {
TaskService ts = activitiEngine.getTaskService();
List<Task> tasks = ts.createTaskQuery().processInstanceId(processInstanceId).includeTaskLocalVariables().includeProcessVariables().list();
return tasksToWorkItems(tasks, null, false, true, true, true, result);
}
Aggregations