use of com.evolveum.midpoint.xml.ns._public.common.common_3.WorkItemType in project midpoint by Evolveum.
the class ProcessInstanceProvider method augmentTaskObject.
// doesn't throw any exceptions - these are logged and stored into the operation result
public <T extends ObjectType> void augmentTaskObject(PrismObject<T> object, Collection<SelectorOptions<GetOperationOptions>> options, Task opTask, OperationResult parentResult) {
final OperationResult result = parentResult.createSubresult(OPERATION_AUGMENT_TASK_OBJECT);
result.addParam("object", ObjectTypeUtil.toShortString(object));
result.addCollectionOfSerializablesAsParam("options", options);
if (!(object.asObjectable() instanceof TaskType)) {
result.recordNotApplicableIfUnknown();
return;
}
final TaskType taskType = (TaskType) object.asObjectable();
try {
if (taskType.getWorkflowContext() == null) {
return;
}
final String instanceId = taskType.getWorkflowContext().getProcessInstanceId();
if (instanceId == null) {
return;
}
final boolean retrieveWorkItems = SelectorOptions.hasToLoadPath(new ItemPath(F_WORKFLOW_CONTEXT, F_WORK_ITEM), options);
if (!retrieveWorkItems) {
// We assume that everything (except work items) is already stored in repo.
return;
}
final List<WorkItemType> workItems = workItemProvider.getWorkItemsForProcessInstanceId(instanceId, result);
taskType.getWorkflowContext().getWorkItem().addAll(CloneUtil.cloneCollectionMembers(workItems));
} catch (RuntimeException e) {
result.recordFatalError(e.getMessage(), e);
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't prepare wf-related information for {}", e, ObjectTypeUtil.toShortString(object));
} finally {
result.computeStatusIfUnknown();
}
if (!result.isSuccess()) {
taskType.setFetchResult(result.createOperationResultType());
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.WorkItemType in project midpoint by Evolveum.
the class WorkItemProvider method taskExtractToWorkItem.
public WorkItemType taskExtractToWorkItem(TaskExtract task, boolean resolveTask, boolean resolveAssignee, boolean resolveCandidates, boolean fetchAllVariables, OperationResult parentResult) {
OperationResult result = parentResult.createSubresult(OPERATION_ACTIVITI_TASK_TO_WORK_ITEM);
result.addParams(new String[] { "activitiTaskId", "resolveTask", "resolveAssignee", "resolveCandidates" }, task.getId(), resolveTask, resolveAssignee, resolveCandidates);
try {
WorkItemType wi = new WorkItemType(prismContext);
final Map<String, Object> variables = task.getVariables();
wi.setExternalId(task.getId());
wi.setName(task.getName());
wi.setCreateTimestamp(XmlTypeConverter.createXMLGregorianCalendar(task.getCreateTime()));
wi.setDeadline(XmlTypeConverter.createXMLGregorianCalendar(task.getDueDate()));
String taskOid = ActivitiUtil.getRequiredVariable(variables, CommonProcessVariableNames.VARIABLE_MIDPOINT_TASK_OID, String.class, null);
com.evolveum.midpoint.task.api.Task mpTask = null;
try {
mpTask = taskManager.getTask(taskOid, result);
} catch (ObjectNotFoundException | SchemaException e) {
// TODO more gentle treatment
throw new SystemException("Couldn't retrieve owning task for " + wi + ": " + e.getMessage(), e);
}
if (mpTask.getWorkflowContext() == null) {
throw new IllegalStateException("No workflow context in task " + mpTask + " that owns " + wi);
}
mpTask.getWorkflowContext().getWorkItem().add(wi);
// assignees
wi.getAssigneeRef().addAll(getMidpointAssignees(task));
String originalAssigneeString = ActivitiUtil.getVariable(variables, CommonProcessVariableNames.VARIABLE_ORIGINAL_ASSIGNEE, String.class, prismContext);
if (originalAssigneeString != null) {
wi.setOriginalAssigneeRef(MiscDataUtil.stringToRef(originalAssigneeString));
}
if (resolveAssignee) {
miscDataUtil.resolveAndStoreObjectReferences(wi.getAssigneeRef(), result);
miscDataUtil.resolveAndStoreObjectReference(wi.getOriginalAssigneeRef(), result);
}
// candidates
task.getCandidateUsers().forEach(s -> wi.getCandidateRef().add(createObjectRef(s, USER)));
task.getCandidateGroups().forEach(s -> wi.getCandidateRef().add(MiscDataUtil.stringToRef(s)));
if (resolveCandidates) {
miscDataUtil.resolveAndStoreObjectReferences(wi.getCandidateRef(), result);
}
// other
ProcessMidPointInterface pmi = processInterfaceFinder.getProcessInterface(variables);
wi.setOutput(pmi.extractWorkItemResult(variables));
String completedBy = ActivitiUtil.getVariable(variables, CommonProcessVariableNames.VARIABLE_WORK_ITEM_COMPLETED_BY, String.class, prismContext);
if (completedBy != null) {
wi.setPerformerRef(ObjectTypeUtil.createObjectRef(completedBy, ObjectTypes.USER));
}
wi.setStageNumber(pmi.getStageNumber(variables));
wi.setEscalationLevel(WfContextUtil.createEscalationLevel(pmi.getEscalationLevelNumber(variables), pmi.getEscalationLevelName(variables), pmi.getEscalationLevelDisplayName(variables)));
// This is just because 'variables' switches in task query DO NOT fetch all required variables...
if (fetchAllVariables) {
// TODO can we do this e.g. in the task completion listener?
Map<String, Object> allVariables = activitiEngine.getTaskService().getVariables(task.getId());
wi.setProcessSpecificPart(pmi.extractProcessSpecificWorkItemPart(allVariables));
wi.getAdditionalInformation().addAll(pmi.getAdditionalInformation(allVariables));
}
return wi;
} catch (RuntimeException e) {
result.recordFatalError("Couldn't convert activiti task " + task.getId() + " to midPoint WorkItem: " + e.getMessage(), e);
throw e;
} finally {
result.computeStatusIfUnknown();
}
}
Aggregations