use of org.jbpm.workflow.instance.node.HumanTaskNodeInstance in project jbpm by kiegroup.
the class AbstractProtobufProcessInstanceMarshaller method readNodeInstanceContent.
protected NodeInstanceImpl readNodeInstanceContent(JBPMMessages.ProcessInstance.NodeInstance _node, MarshallerReaderContext context, WorkflowProcessInstance processInstance) throws IOException {
NodeInstanceImpl nodeInstance = null;
NodeInstanceContent _content = _node.getContent();
switch(_content.getType()) {
case RULE_SET_NODE:
nodeInstance = new RuleSetNodeInstance();
((RuleSetNodeInstance) nodeInstance).setRuleFlowGroup(_content.getRuleSet().getRuleFlowGroup());
if (_content.getRuleSet().getTimerInstanceIdCount() > 0) {
List<Long> timerInstances = new ArrayList<Long>();
for (Long _timerId : _content.getRuleSet().getTimerInstanceIdList()) {
timerInstances.add(_timerId);
}
((RuleSetNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
}
if (_content.getRuleSet().getMapEntryCount() > 0) {
Map<String, FactHandle> factInfo = new HashMap<String, FactHandle>();
for (TextMapEntry entry : _content.getRuleSet().getMapEntryList()) {
factInfo.put(entry.getName(), DefaultFactHandle.createFromExternalFormat(entry.getValue()));
}
((RuleSetNodeInstance) nodeInstance).setFactHandles(factInfo);
}
break;
case HUMAN_TASK_NODE:
nodeInstance = new HumanTaskNodeInstance();
((HumanTaskNodeInstance) nodeInstance).internalSetWorkItemId(_content.getHumanTask().getWorkItemId());
if (_content.getHumanTask().getTimerInstanceIdCount() > 0) {
List<Long> timerInstances = new ArrayList<Long>();
for (Long _timerId : _content.getHumanTask().getTimerInstanceIdList()) {
timerInstances.add(_timerId);
}
((HumanTaskNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
}
break;
case WORK_ITEM_NODE:
nodeInstance = new WorkItemNodeInstance();
((WorkItemNodeInstance) nodeInstance).internalSetWorkItemId(_content.getWorkItem().getWorkItemId());
if (_content.getWorkItem().getTimerInstanceIdCount() > 0) {
List<Long> timerInstances = new ArrayList<Long>();
for (Long _timerId : _content.getWorkItem().getTimerInstanceIdList()) {
timerInstances.add(_timerId);
}
((WorkItemNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
}
break;
case SUBPROCESS_NODE:
nodeInstance = new SubProcessNodeInstance();
((SubProcessNodeInstance) nodeInstance).internalSetProcessInstanceId(_content.getSubProcess().getProcessInstanceId());
if (_content.getSubProcess().getTimerInstanceIdCount() > 0) {
List<Long> timerInstances = new ArrayList<Long>();
for (Long _timerId : _content.getSubProcess().getTimerInstanceIdList()) {
timerInstances.add(_timerId);
}
((SubProcessNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
}
break;
case MILESTONE_NODE:
nodeInstance = new MilestoneNodeInstance();
if (_content.getMilestone().getTimerInstanceIdCount() > 0) {
List<Long> timerInstances = new ArrayList<Long>();
for (Long _timerId : _content.getMilestone().getTimerInstanceIdList()) {
timerInstances.add(_timerId);
}
((MilestoneNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
}
break;
case TIMER_NODE:
nodeInstance = new TimerNodeInstance();
((TimerNodeInstance) nodeInstance).internalSetTimerId(_content.getTimer().getTimerId());
break;
case ASYNC_EVENT_NODE:
nodeInstance = new AsyncEventNodeInstance();
((AsyncEventNodeInstance) nodeInstance).setEventType(_content.getAsyncEvent().getEventType());
break;
case EVENT_NODE:
nodeInstance = new EventNodeInstance();
break;
case JOIN_NODE:
nodeInstance = new JoinInstance();
if (_content.getJoin().getTriggerCount() > 0) {
Map<Long, Integer> triggers = new HashMap<Long, Integer>();
for (JBPMMessages.ProcessInstance.NodeInstanceContent.JoinNode.JoinTrigger _join : _content.getJoin().getTriggerList()) {
triggers.put(_join.getNodeId(), _join.getCounter());
}
((JoinInstance) nodeInstance).internalSetTriggers(triggers);
}
break;
case FOR_EACH_NODE:
nodeInstance = new ForEachNodeInstance();
break;
case COMPOSITE_CONTEXT_NODE:
nodeInstance = new CompositeContextNodeInstance();
if (_content.getComposite().getTimerInstanceIdCount() > 0) {
List<Long> timerInstances = new ArrayList<Long>();
for (Long _timerId : _content.getComposite().getTimerInstanceIdList()) {
timerInstances.add(_timerId);
}
((CompositeContextNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
}
break;
case DYNAMIC_NODE:
nodeInstance = new DynamicNodeInstance();
if (_content.getComposite().getTimerInstanceIdCount() > 0) {
List<Long> timerInstances = new ArrayList<Long>();
for (Long _timerId : _content.getComposite().getTimerInstanceIdList()) {
timerInstances.add(_timerId);
}
((CompositeContextNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
}
break;
case STATE_NODE:
nodeInstance = new StateNodeInstance();
if (_content.getState().getTimerInstanceIdCount() > 0) {
List<Long> timerInstances = new ArrayList<Long>();
for (Long _timerId : _content.getState().getTimerInstanceIdList()) {
timerInstances.add(_timerId);
}
((CompositeContextNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
}
break;
case EVENT_SUBPROCESS_NODE:
nodeInstance = new EventSubProcessNodeInstance();
if (_content.getComposite().getTimerInstanceIdCount() > 0) {
List<Long> timerInstances = new ArrayList<Long>();
for (Long _timerId : _content.getComposite().getTimerInstanceIdList()) {
timerInstances.add(_timerId);
}
((CompositeContextNodeInstance) nodeInstance).internalSetTimerInstances(timerInstances);
}
break;
default:
throw new IllegalArgumentException("Unknown node type: " + _content.getType());
}
return nodeInstance;
}
use of org.jbpm.workflow.instance.node.HumanTaskNodeInstance in project jbpm by kiegroup.
the class AbstractProtobufProcessInstanceMarshaller method writeNodeInstanceContent.
protected JBPMMessages.ProcessInstance.NodeInstanceContent writeNodeInstanceContent(JBPMMessages.ProcessInstance.NodeInstance.Builder _node, NodeInstance nodeInstance, MarshallerWriteContext context) throws IOException {
JBPMMessages.ProcessInstance.NodeInstanceContent.Builder _content = null;
if (nodeInstance instanceof RuleSetNodeInstance) {
_content = JBPMMessages.ProcessInstance.NodeInstanceContent.newBuilder().setType(NodeInstanceType.RULE_SET_NODE);
List<Long> timerInstances = ((RuleSetNodeInstance) nodeInstance).getTimerInstances();
JBPMMessages.ProcessInstance.NodeInstanceContent.RuleSetNode.Builder _ruleSet = JBPMMessages.ProcessInstance.NodeInstanceContent.RuleSetNode.newBuilder();
_ruleSet.setRuleFlowGroup(((RuleSetNodeInstance) nodeInstance).getRuleFlowGroup());
if (timerInstances != null) {
for (Long id : timerInstances) {
_ruleSet.addTimerInstanceId(id);
}
}
Map<String, FactHandle> facts = ((RuleSetNodeInstance) nodeInstance).getFactHandles();
if (facts != null && facts.size() > 0) {
for (Map.Entry<String, FactHandle> entry : facts.entrySet()) {
JBPMMessages.ProcessInstance.NodeInstanceContent.RuleSetNode.TextMapEntry.Builder _textMapEntry = JBPMMessages.ProcessInstance.NodeInstanceContent.RuleSetNode.TextMapEntry.newBuilder();
_textMapEntry.setName(entry.getKey());
_textMapEntry.setValue(entry.getValue().toExternalForm());
_ruleSet.addMapEntry(_textMapEntry.build());
}
}
_content.setRuleSet(_ruleSet.build());
} else if (nodeInstance instanceof HumanTaskNodeInstance) {
JBPMMessages.ProcessInstance.NodeInstanceContent.HumanTaskNode.Builder _task = JBPMMessages.ProcessInstance.NodeInstanceContent.HumanTaskNode.newBuilder().setWorkItemId(((HumanTaskNodeInstance) nodeInstance).getWorkItemId());
List<Long> timerInstances = ((HumanTaskNodeInstance) nodeInstance).getTimerInstances();
if (timerInstances != null) {
for (Long id : timerInstances) {
_task.addTimerInstanceId(id);
}
}
_content = JBPMMessages.ProcessInstance.NodeInstanceContent.newBuilder().setType(NodeInstanceType.HUMAN_TASK_NODE).setHumanTask(_task.build());
} else if (nodeInstance instanceof WorkItemNodeInstance) {
JBPMMessages.ProcessInstance.NodeInstanceContent.WorkItemNode.Builder _wi = JBPMMessages.ProcessInstance.NodeInstanceContent.WorkItemNode.newBuilder().setWorkItemId(((WorkItemNodeInstance) nodeInstance).getWorkItemId());
List<Long> timerInstances = ((WorkItemNodeInstance) nodeInstance).getTimerInstances();
if (timerInstances != null) {
for (Long id : timerInstances) {
_wi.addTimerInstanceId(id);
}
}
_content = JBPMMessages.ProcessInstance.NodeInstanceContent.newBuilder().setType(NodeInstanceType.WORK_ITEM_NODE).setWorkItem(_wi.build());
} else if (nodeInstance instanceof SubProcessNodeInstance) {
JBPMMessages.ProcessInstance.NodeInstanceContent.SubProcessNode.Builder _sp = JBPMMessages.ProcessInstance.NodeInstanceContent.SubProcessNode.newBuilder().setProcessInstanceId(((SubProcessNodeInstance) nodeInstance).getProcessInstanceId());
List<Long> timerInstances = ((SubProcessNodeInstance) nodeInstance).getTimerInstances();
if (timerInstances != null) {
for (Long id : timerInstances) {
_sp.addTimerInstanceId(id);
}
}
_content = JBPMMessages.ProcessInstance.NodeInstanceContent.newBuilder().setType(NodeInstanceType.SUBPROCESS_NODE).setSubProcess(_sp.build());
} else if (nodeInstance instanceof MilestoneNodeInstance) {
JBPMMessages.ProcessInstance.NodeInstanceContent.MilestoneNode.Builder _ms = JBPMMessages.ProcessInstance.NodeInstanceContent.MilestoneNode.newBuilder();
List<Long> timerInstances = ((MilestoneNodeInstance) nodeInstance).getTimerInstances();
if (timerInstances != null) {
for (Long id : timerInstances) {
_ms.addTimerInstanceId(id);
}
}
_content = JBPMMessages.ProcessInstance.NodeInstanceContent.newBuilder().setType(NodeInstanceType.MILESTONE_NODE).setMilestone(_ms.build());
} else if (nodeInstance instanceof AsyncEventNodeInstance) {
JBPMMessages.ProcessInstance.NodeInstanceContent.AsyncEventNode.Builder _asyncEvent = JBPMMessages.ProcessInstance.NodeInstanceContent.AsyncEventNode.newBuilder();
_asyncEvent.setEventType(((AsyncEventNodeInstance) nodeInstance).getEventType());
_content = JBPMMessages.ProcessInstance.NodeInstanceContent.newBuilder().setType(NodeInstanceType.ASYNC_EVENT_NODE).setAsyncEvent(_asyncEvent.build());
} else if (nodeInstance instanceof EventNodeInstance) {
_content = JBPMMessages.ProcessInstance.NodeInstanceContent.newBuilder().setType(NodeInstanceType.EVENT_NODE);
} else if (nodeInstance instanceof TimerNodeInstance) {
_content = JBPMMessages.ProcessInstance.NodeInstanceContent.newBuilder().setType(NodeInstanceType.TIMER_NODE).setTimer(JBPMMessages.ProcessInstance.NodeInstanceContent.TimerNode.newBuilder().setTimerId(((TimerNodeInstance) nodeInstance).getTimerId()).build());
} else if (nodeInstance instanceof JoinInstance) {
JBPMMessages.ProcessInstance.NodeInstanceContent.JoinNode.Builder _join = JBPMMessages.ProcessInstance.NodeInstanceContent.JoinNode.newBuilder();
Map<Long, Integer> triggers = ((JoinInstance) nodeInstance).getTriggers();
List<Long> keys = new ArrayList<Long>(triggers.keySet());
Collections.sort(keys, new Comparator<Long>() {
public int compare(Long o1, Long o2) {
return o1.compareTo(o2);
}
});
for (Long key : keys) {
_join.addTrigger(JBPMMessages.ProcessInstance.NodeInstanceContent.JoinNode.JoinTrigger.newBuilder().setNodeId(key).setCounter(triggers.get(key)).build());
}
_content = JBPMMessages.ProcessInstance.NodeInstanceContent.newBuilder().setType(NodeInstanceType.JOIN_NODE).setJoin(_join.build());
} else if (nodeInstance instanceof StateNodeInstance) {
JBPMMessages.ProcessInstance.NodeInstanceContent.StateNode.Builder _state = JBPMMessages.ProcessInstance.NodeInstanceContent.StateNode.newBuilder();
List<Long> timerInstances = ((StateNodeInstance) nodeInstance).getTimerInstances();
if (timerInstances != null) {
for (Long id : timerInstances) {
_state.addTimerInstanceId(id);
}
}
_content = JBPMMessages.ProcessInstance.NodeInstanceContent.newBuilder().setType(NodeInstanceType.STATE_NODE).setState(_state.build());
} else if (nodeInstance instanceof ForEachNodeInstance) {
JBPMMessages.ProcessInstance.NodeInstanceContent.ForEachNode.Builder _foreach = JBPMMessages.ProcessInstance.NodeInstanceContent.ForEachNode.newBuilder();
ForEachNodeInstance forEachNodeInstance = (ForEachNodeInstance) nodeInstance;
List<NodeInstance> nodeInstances = new ArrayList<NodeInstance>(forEachNodeInstance.getNodeInstances());
Collections.sort(nodeInstances, new Comparator<NodeInstance>() {
public int compare(NodeInstance o1, NodeInstance o2) {
return (int) (o1.getId() - o2.getId());
}
});
for (NodeInstance subNodeInstance : nodeInstances) {
if (subNodeInstance instanceof CompositeContextNodeInstance) {
_foreach.addNodeInstance(writeNodeInstance(context, subNodeInstance));
}
}
VariableScopeInstance variableScopeInstance = (VariableScopeInstance) forEachNodeInstance.getContextInstance(VariableScope.VARIABLE_SCOPE);
if (variableScopeInstance != null) {
List<Map.Entry<String, Object>> variables = new ArrayList<Map.Entry<String, Object>>(variableScopeInstance.getVariables().entrySet());
Collections.sort(variables, new Comparator<Map.Entry<String, Object>>() {
public int compare(Map.Entry<String, Object> o1, Map.Entry<String, Object> o2) {
return o1.getKey().compareTo(o2.getKey());
}
});
for (Map.Entry<String, Object> variable : variables) {
_foreach.addVariable(ProtobufProcessMarshaller.marshallVariable(context, variable.getKey(), variable.getValue()));
}
}
List<Map.Entry<String, Integer>> iterationlevels = new ArrayList<Map.Entry<String, Integer>>(forEachNodeInstance.getIterationLevels().entrySet());
Collections.sort(iterationlevels, new Comparator<Map.Entry<String, Integer>>() {
public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
return o1.getKey().compareTo(o2.getKey());
}
});
for (Map.Entry<String, Integer> level : iterationlevels) {
if (level.getKey() != null && level.getValue() != null) {
_foreach.addIterationLevels(JBPMMessages.IterationLevel.newBuilder().setId(level.getKey()).setLevel(level.getValue()));
}
}
_content = JBPMMessages.ProcessInstance.NodeInstanceContent.newBuilder().setType(NodeInstanceType.FOR_EACH_NODE).setForEach(_foreach.build());
} else if (nodeInstance instanceof CompositeContextNodeInstance) {
JBPMMessages.ProcessInstance.NodeInstanceContent.CompositeContextNode.Builder _composite = JBPMMessages.ProcessInstance.NodeInstanceContent.CompositeContextNode.newBuilder();
JBPMMessages.ProcessInstance.NodeInstanceType _type = null;
if (nodeInstance instanceof DynamicNodeInstance) {
_type = JBPMMessages.ProcessInstance.NodeInstanceType.DYNAMIC_NODE;
} else if (nodeInstance instanceof EventSubProcessNodeInstance) {
_type = JBPMMessages.ProcessInstance.NodeInstanceType.EVENT_SUBPROCESS_NODE;
} else {
_type = JBPMMessages.ProcessInstance.NodeInstanceType.COMPOSITE_CONTEXT_NODE;
}
CompositeContextNodeInstance compositeNodeInstance = (CompositeContextNodeInstance) nodeInstance;
List<Long> timerInstances = ((CompositeContextNodeInstance) nodeInstance).getTimerInstances();
if (timerInstances != null) {
for (Long id : timerInstances) {
_composite.addTimerInstanceId(id);
}
}
VariableScopeInstance variableScopeInstance = (VariableScopeInstance) compositeNodeInstance.getContextInstance(VariableScope.VARIABLE_SCOPE);
if (variableScopeInstance != null) {
List<Map.Entry<String, Object>> variables = new ArrayList<Map.Entry<String, Object>>(variableScopeInstance.getVariables().entrySet());
Collections.sort(variables, new Comparator<Map.Entry<String, Object>>() {
public int compare(Map.Entry<String, Object> o1, Map.Entry<String, Object> o2) {
return o1.getKey().compareTo(o2.getKey());
}
});
for (Map.Entry<String, Object> variable : variables) {
_composite.addVariable(ProtobufProcessMarshaller.marshallVariable(context, variable.getKey(), variable.getValue()));
}
}
List<Map.Entry<String, Integer>> iterationlevels = new ArrayList<Map.Entry<String, Integer>>(compositeNodeInstance.getIterationLevels().entrySet());
Collections.sort(iterationlevels, new Comparator<Map.Entry<String, Integer>>() {
public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
return o1.getKey().compareTo(o2.getKey());
}
});
for (Map.Entry<String, Integer> level : iterationlevels) {
if (level.getKey() != null && level.getValue() != null) {
_composite.addIterationLevels(JBPMMessages.IterationLevel.newBuilder().setId(level.getKey()).setLevel(level.getValue()));
}
}
List<NodeInstance> nodeInstances = new ArrayList<NodeInstance>(compositeNodeInstance.getNodeInstances());
Collections.sort(nodeInstances, new Comparator<NodeInstance>() {
public int compare(NodeInstance o1, NodeInstance o2) {
return (int) (o1.getId() - o2.getId());
}
});
for (NodeInstance subNodeInstance : nodeInstances) {
_composite.addNodeInstance(writeNodeInstance(context, subNodeInstance));
}
List<ContextInstance> exclusiveGroupInstances = compositeNodeInstance.getContextInstances(ExclusiveGroup.EXCLUSIVE_GROUP);
if (exclusiveGroupInstances != null) {
for (ContextInstance contextInstance : exclusiveGroupInstances) {
JBPMMessages.ProcessInstance.ExclusiveGroupInstance.Builder _excl = JBPMMessages.ProcessInstance.ExclusiveGroupInstance.newBuilder();
ExclusiveGroupInstance exclusiveGroupInstance = (ExclusiveGroupInstance) contextInstance;
Collection<NodeInstance> groupNodeInstances = exclusiveGroupInstance.getNodeInstances();
for (NodeInstance groupNodeInstance : groupNodeInstances) {
_excl.addGroupNodeInstanceId(groupNodeInstance.getId());
}
_composite.addExclusiveGroup(_excl.build());
}
}
_content = JBPMMessages.ProcessInstance.NodeInstanceContent.newBuilder().setType(_type).setComposite(_composite.build());
} else {
throw new IllegalArgumentException("Unknown node instance type: " + nodeInstance);
}
return _content.build();
}
use of org.jbpm.workflow.instance.node.HumanTaskNodeInstance in project jbpm by kiegroup.
the class GlobalTimerServiceBaseTest method testInterediateTimerWithHTBeforeWithGlobalTestServiceRollback.
@Test(timeout = 20000)
public void testInterediateTimerWithHTBeforeWithGlobalTestServiceRollback() throws Exception {
// prepare listener to assert results
Properties properties = new Properties();
properties.setProperty("mary", "HR");
properties.setProperty("john", "HR");
UserGroupCallback userGroupCallback = new JBossUserGroupCallbackImpl(properties);
environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/IntermediateCatchEventTimerCycleWithHT2.bpmn2"), ResourceType.BPMN2).schedulerService(globalScheduler).userGroupCallback(userGroupCallback).get();
manager = getManager(environment, true);
RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
KieSession ksession = runtime.getKieSession();
long ksessionId = ksession.getIdentifier();
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", "R3/PT1S");
ProcessInstance processInstance = ksession.startProcess("IntermediateCatchEvent", params);
assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);
// get tasks
List<Status> statuses = new ArrayList<Status>();
statuses.add(Status.Reserved);
List<TaskSummary> tasks = runtime.getTaskService().getTasksAssignedAsPotentialOwnerByStatus("john", statuses, "en-UK");
assertNotNull(tasks);
assertEquals(1, tasks.size());
TaskSummary task = tasks.get(0);
runtime.getTaskService().start(task.getId(), "john");
UserTransaction ut = InitialContext.doLookup("java:comp/UserTransaction");
try {
ut.begin();
runtime.getTaskService().complete(task.getId(), "john", null);
} finally {
ut.rollback();
}
processInstance = ksession.getProcessInstance(processInstance.getId());
Collection<NodeInstance> activeNodes = ((WorkflowProcessInstance) processInstance).getNodeInstances();
assertNotNull(activeNodes);
assertEquals(1, activeNodes.size());
assertTrue(activeNodes.iterator().next() instanceof HumanTaskNodeInstance);
TimerService timerService = TimerServiceRegistry.getInstance().get(manager.getIdentifier() + TimerServiceRegistry.TIMER_SERVICE_SUFFIX);
Collection<TimerJobInstance> timerInstances = timerService.getTimerJobInstances(ksessionId);
assertNotNull(timerInstances);
assertEquals(0, timerInstances.size());
// clean up
ksession.abortProcessInstance(processInstance.getId());
manager.disposeRuntimeEngine(runtime);
}
use of org.jbpm.workflow.instance.node.HumanTaskNodeInstance in project jbpm by kiegroup.
the class HumanTaskSwimlaneTest method testSwimlaneWithMultipleActorsAssigned.
@Test
public void testSwimlaneWithMultipleActorsAssigned() {
createRuntimeManager(SWIMLANE_MULTIPLE_ACTORS);
String user = "john";
RuntimeEngine runtime = getRuntimeEngine();
KieSession kSession = runtime.getKieSession();
TaskService taskservice = runtime.getTaskService();
kSession.addEventListener(new DefaultProcessEventListener() {
@Override
public void afterNodeTriggered(ProcessNodeTriggeredEvent event) {
if (event.getNodeInstance().getNodeName().equals("TASK")) {
Object swimlaneActorId = ((HumanTaskNodeInstance) event.getNodeInstance()).getWorkItem().getParameter("SwimlaneActorId");
assertNull(swimlaneActorId);
}
}
});
Map<String, Object> map = new HashMap<String, Object>();
ProcessInstance instance = kSession.startProcess(SWIMLANE_MULTIPLE_ACTORS_ID, map);
List<Status> statuses = new ArrayList<Status>();
statuses.add(Status.Ready);
statuses.add(Status.Reserved);
statuses.add(Status.InProgress);
List<TaskSummary> tasks = taskservice.getTasksByStatusByProcessInstanceId(instance.getId(), statuses, "en_US");
assertNotNull(tasks);
assertEquals(1, tasks.size());
TaskSummary task = tasks.get(0);
assertEquals(Status.Ready, task.getStatus());
taskservice.claim(task.getId(), user);
taskservice.start(task.getId(), user);
tasks = taskservice.getTasksByStatusByProcessInstanceId(instance.getId(), statuses, "en_US");
assertNotNull(tasks);
assertEquals(1, tasks.size());
task = tasks.get(0);
assertEquals(Status.InProgress, task.getStatus());
taskservice.complete(task.getId(), user, map);
assertProcessInstanceCompleted(instance.getId());
}
use of org.jbpm.workflow.instance.node.HumanTaskNodeInstance in project jbpm by kiegroup.
the class MigrationManager method updateNodeInstances.
@SuppressWarnings("unchecked")
private void updateNodeInstances(NodeInstanceContainer nodeInstanceContainer, Map<String, String> nodeMapping, NodeContainer nodeContainer, EntityManager em) {
for (NodeInstance nodeInstance : nodeInstanceContainer.getNodeInstances()) {
Long upgradedNodeId = null;
String oldNodeId = (String) ((NodeImpl) ((org.jbpm.workflow.instance.NodeInstance) nodeInstance).getNode()).getMetaData().get("UniqueId");
String newNodeId = nodeMapping.get(oldNodeId);
if (newNodeId == null) {
newNodeId = oldNodeId;
}
Node upgradedNode = findNodeByUniqueId(newNodeId, nodeContainer);
if (upgradedNode == null) {
try {
upgradedNodeId = Long.parseLong(newNodeId);
} catch (NumberFormatException e) {
continue;
}
} else {
upgradedNodeId = upgradedNode.getId();
}
((NodeInstanceImpl) nodeInstance).setNodeId(upgradedNodeId);
if (upgradedNode != null) {
// update log information for new node information
Query nodeInstanceIdQuery = em.createQuery("select nodeInstanceId from NodeInstanceLog nil" + " where nil.nodeId = :oldNodeId and processInstanceId = :processInstanceId " + " GROUP BY nil.nodeInstanceId" + " HAVING sum(nil.type) = 0");
nodeInstanceIdQuery.setParameter("oldNodeId", oldNodeId).setParameter("processInstanceId", nodeInstance.getProcessInstance().getId());
List<Long> nodeInstanceIds = nodeInstanceIdQuery.getResultList();
report.addEntry(Type.INFO, "Mapping: Node instance logs to be updated = " + nodeInstanceIds);
Query nodeLogQuery = em.createQuery("update NodeInstanceLog set nodeId = :nodeId, nodeName = :nodeName, nodeType = :nodeType " + "where nodeInstanceId in (:ids) and processInstanceId = :processInstanceId");
nodeLogQuery.setParameter("nodeId", (String) upgradedNode.getMetaData().get("UniqueId")).setParameter("nodeName", upgradedNode.getName()).setParameter("nodeType", upgradedNode.getClass().getSimpleName()).setParameter("ids", nodeInstanceIds).setParameter("processInstanceId", nodeInstance.getProcessInstance().getId());
int nodesUpdated = nodeLogQuery.executeUpdate();
report.addEntry(Type.INFO, "Mapping: Node instance logs updated = " + nodesUpdated + " for node instance id " + nodeInstance.getId());
if (upgradedNode instanceof HumanTaskNode && nodeInstance instanceof HumanTaskNodeInstance) {
Long taskId = (Long) em.createQuery("select id from TaskImpl where workItemId = :workItemId").setParameter("workItemId", ((HumanTaskNodeInstance) nodeInstance).getWorkItemId()).getSingleResult();
String name = ((HumanTaskNode) upgradedNode).getName();
String description = (String) ((HumanTaskNode) upgradedNode).getWork().getParameter("Description");
// update task audit instance log with new deployment and process id
Query auditTaskLogQuery = em.createQuery("update AuditTaskImpl set name = :name, description = :description where taskId = :taskId");
auditTaskLogQuery.setParameter("name", name).setParameter("description", description).setParameter("taskId", taskId);
int auditTaskUpdated = auditTaskLogQuery.executeUpdate();
report.addEntry(Type.INFO, "Mapping: Task audit updated = " + auditTaskUpdated + " for task id " + taskId);
// update task instance log with new deployment and process id
Query taskLogQuery = em.createQuery("update TaskImpl set name = :name, description = :description where id = :taskId");
taskLogQuery.setParameter("name", name).setParameter("description", description).setParameter("taskId", taskId);
int taskUpdated = taskLogQuery.executeUpdate();
report.addEntry(Type.INFO, "Mapping: Task updated = " + taskUpdated + " for task id " + taskId);
}
}
if (nodeInstance instanceof NodeInstanceContainer) {
updateNodeInstances((NodeInstanceContainer) nodeInstance, nodeMapping, nodeContainer, em);
}
}
}
Aggregations