Skip to content

Commit

Permalink
Work items in task wf context.
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Mar 2, 2016
1 parent 592b894 commit a77ce7d
Show file tree
Hide file tree
Showing 7 changed files with 294 additions and 18 deletions.
Expand Up @@ -28,10 +28,7 @@
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.path.ItemPathSegment;
import com.evolveum.midpoint.prism.path.NameItemPathSegment;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

/**
* @author semancik
Expand Down Expand Up @@ -144,6 +141,7 @@ public static boolean hasToLoadPath(QName itemName, Collection<SelectorOptions<G
new ItemPath(TaskType.F_SUBTASK),
new ItemPath(TaskType.F_NODE_AS_OBSERVED),
new ItemPath(TaskType.F_NEXT_RUN_START_TIMESTAMP),
new ItemPath(TaskType.F_WORKFLOW_CONTEXT, WfContextType.F_WORK_ITEM),
new ItemPath(LookupTableType.F_ROW),
new ItemPath(AccessCertificationCampaignType.F_CASE)));

Expand Down
Expand Up @@ -772,6 +772,13 @@
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="workItem" type="tns:WorkItemNewType" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
Currently open work items for this process.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="wfContextType" type="tns:WfContextType" />
Expand Down Expand Up @@ -913,5 +920,164 @@
</xsd:complexType>
<xsd:element name="itemApprovalRequestType" type="tns:ItemApprovalRequestType" />

<xsd:complexType name="WorkItemNewType">
<xsd:annotation>
<xsd:documentation>
WorkItemType contains information about a human task (or a notification).
</xsd:documentation>
<xsd:appinfo>
<a:container/>
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="workItemId" type="xsd:string">
<xsd:annotation>
<xsd:documentation>
Internal identifier of a work item, assigned by the underlying workflow engine
(currently Activiti). MidPoint WorkItem is Activiti Task. So workItemId is
taskId.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="name" type="xsd:string">
<xsd:annotation>
<xsd:documentation>
Descriptive name of the work item. E.g. "Assign role1 to user1".
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="processStartedTimestamp" type="xsd:dateTime">
<xsd:annotation>
<xsd:documentation>
When was the operation requested, i.e. when the approval process started?

(Normally, this information is relevant at the task/wf-process level.
However we put it here to avoid fetching tasks when we want to display
work item list only.)
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="workItemCreatedTimestamp" type="xsd:dateTime">
<xsd:annotation>
<xsd:documentation>
When was this work item created?
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="taskRef" type="c:ObjectReferenceType" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Task that wraps process instance this work item is part of.
</xsd:documentation>
<xsd:appinfo>
<a:objectReferenceTargetType>tns:TaskType</a:objectReferenceTargetType>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="assigneeRef" type="c:ObjectReferenceType" minOccurs="0" maxOccurs="1">
<xsd:annotation>
<xsd:documentation>
User to which the work item is assigned. Other users do not see such a work item in their work lists.
</xsd:documentation>
<xsd:appinfo>
<a:objectReferenceTargetType>tns:UserType</a:objectReferenceTargetType>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="candidateUsersRef" type="c:ObjectReferenceType" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
Users to which the work item MAY BE assigned.
</xsd:documentation>
<xsd:appinfo>
<a:objectReferenceTargetType>tns:UserType</a:objectReferenceTargetType>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="candidateRolesRef" type="c:ObjectReferenceType" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
Organizations/roles to users of which the work item MAY BE assigned.
</xsd:documentation>
<xsd:appinfo>
<a:objectReferenceTargetType>tns:AbstractRoleType</a:objectReferenceTargetType>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="objectRef" type="c:ObjectReferenceType" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Object that is being modified (added, deleted) by the operation requested.
Typically a user, but might be also a role, org, resource, etc.

(Normally, this information is relevant at the task/wf-process level.
However we put it here to avoid fetching tasks when we want to display
work item list only.)
</xsd:documentation>
<xsd:appinfo>
<a:objectReferenceTargetType>tns:ObjectType</a:objectReferenceTargetType>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="targetRef" type="c:ObjectReferenceType" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Object that is being attached to/detached from the object modified.
Typically a role but might be also a resource, org, ... or it might be null.

(Normally, this information is relevant at the task/wf-process level.
However we put it here to avoid fetching tasks when we want to display
work item list only.)
</xsd:documentation>
<xsd:appinfo>
<a:objectReferenceTargetType>tns:ObjectType</a:objectReferenceTargetType>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>

<!--<xsd:element name="contents" type="tns:ObjectType" minOccurs="0" maxOccurs="1">-->
<!--<xsd:annotation>-->
<!--<xsd:documentation>-->
<!--Work item contents - i.e. the actual work that the user has-->
<!--to do, along with all the necessary information.-->
<!--It is stored as PrismObject, although, actually, it is always a-->
<!--subtype of WorkItemContents, but this structure is defined in separate XSD file.-->
<!--TODO consider moving all wf-related structures to that file-->
<!--in order to allow correct references among them.-->
<!--</xsd:documentation>-->
<!--<xsd:appinfo>-->
<!--<a:objectReference>tns:contentsRef</a:objectReference>-->
<!--</xsd:appinfo>-->
<!--</xsd:annotation>-->
<!--</xsd:element>-->
<!--<xsd:element name="contentsRef" type="c:ObjectReferenceType" minOccurs="0" maxOccurs="1">-->
<!--<xsd:annotation>-->
<!--<xsd:appinfo>-->
<!--<a:objectReferenceTargetType>tns:ObjectType</a:objectReferenceTargetType>-->
<!--</xsd:appinfo>-->
<!--</xsd:annotation>-->
<!--</xsd:element>-->
<!--<xsd:element name="trackingData" type="tns:TrackingDataType" minOccurs="0" maxOccurs="1">-->
<!--<xsd:annotation>-->
<!--<xsd:documentation>-->
<!--Various implementation-level (activiti) data useful for diagnostics.-->
<!--</xsd:documentation>-->
<!--<xsd:appinfo>-->
<!--<a:objectReference>tns:trackingDataRef</a:objectReference>-->
<!--</xsd:appinfo>-->
<!--</xsd:annotation>-->
<!--</xsd:element>-->
<!--<xsd:element name="trackingDataRef" type="c:ObjectReferenceType" minOccurs="0" maxOccurs="1">-->
<!--<xsd:annotation>-->
<!--<xsd:appinfo>-->
<!--<a:objectReferenceTargetType>tns:TrackingDataType</a:objectReferenceTargetType>-->
<!--</xsd:appinfo>-->
<!--</xsd:annotation>-->
<!--</xsd:element>-->
</xsd:sequence>
</xsd:complexType>

<xsd:element name="workItemNew" type="tns:WorkItemNewType" />


</xsd:schema>
Expand Up @@ -17,6 +17,7 @@
package com.evolveum.midpoint.wf.impl.activiti.dao;

import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.xml.XmlTypeConverter;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.SearchResultList;
Expand Down Expand Up @@ -62,6 +63,9 @@
import javax.xml.bind.JAXBException;
import java.util.*;

import static com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType.F_WORKFLOW_CONTEXT;
import static com.evolveum.midpoint.xml.ns._public.common.common_3.WfContextType.F_WORK_ITEM;

/**
* @author mederly
*/
Expand Down Expand Up @@ -222,7 +226,7 @@ private WfContextType getWfContextType(String instanceId, boolean getWorkItems,
if (historicProcessInstance == null) {
throw new ObjectNotFoundException("Process instance " + instanceId + " couldn't be found.");
} else {
return activitiToMidpointWfContextHistory(historicProcessInstance, result);
return activitiToMidpointWfContextHistory(historicProcessInstance, getWorkItems, result);
}
}

Expand Down Expand Up @@ -349,7 +353,7 @@ public WfProcessInstanceType activitiToMidpointProcessInstanceHistory(HistoricPr
}
}

private WfContextType activitiToMidpointWfContextHistory(HistoricProcessInstance instance, OperationResult result)
private WfContextType activitiToMidpointWfContextHistory(HistoricProcessInstance instance, boolean getWorkItems, OperationResult result)
throws WorkflowException, SchemaException {

WfContextType wfc = new WfContextType();
Expand Down Expand Up @@ -377,7 +381,13 @@ private WfContextType activitiToMidpointWfContextHistory(HistoricProcessInstance
wfc.setProcessorSpecificState(cp.externalizeProcessorSpecificState(vars));
wfc.setProcessSpecificState(pmi.externalizeProcessSpecificState(vars));

//wfc.setState(cp.externalizeProcessInstanceState(vars).asObjectable());
if (getWorkItems) {
TaskService ts = activitiEngine.getTaskService();
List<Task> tasks = ts.createTaskQuery()
.processInstanceId(instance.getId())
.list();
wfc.getWorkItem().addAll(workItemProvider.tasksToWorkItemsNew(tasks, vars, false, true, true, result)); // "no" to task forms, "yes" to assignee and candidate details
}

return wfc;
}
Expand Down Expand Up @@ -405,7 +415,8 @@ public <T extends ObjectType> void augmentTaskObject(PrismObject<T> object,
if (instanceId == null) {
throw new SchemaException("No process instance ID in workflow context");
}
WfContextType wfContextType = getWfContextType(instanceId, false, result);
boolean retrieveWorkItems = SelectorOptions.hasToLoadPath(new ItemPath(F_WORKFLOW_CONTEXT, F_WORK_ITEM), options);
WfContextType wfContextType = getWfContextType(instanceId, retrieveWorkItems, result);
taskType.setWorkflowContext(wfContextType);
} catch (RuntimeException|SchemaException|ObjectNotFoundException|WorkflowException e) {
result.recordFatalError(e.getMessage(), e);
Expand Down

0 comments on commit a77ce7d

Please sign in to comment.