02-07-2013 04:08 PM
public void execute(DelegateExecution delegateExecution) throws Exception {
TaskEntity task = (TaskEntity) taskService.newTask();
task.setName(name);
task.setPriority(priority);
task.setProcessInstanceId(processInstanceId);
task.setProcessDefinitionId(processDefinitionId);
…
taskService.saveTask(task);
for(String group: groups){
addCandidateGroup(task.getId(), group);
}
}
02-08-2013 03:28 AM
02-08-2013 08:24 AM
So even if you first call a taskService.save() and afterwards the addCandidate(), both those changes will be committed together in the same transaction.
02-08-2013 08:32 AM
02-08-2013 05:16 PM
public class DummyUserExposureServiceTask implements JavaDelegate {
@Override
public void execute(DelegateExecution delegateExecution) throws Exception {
delegateExecution.setVariable("moreUsers", false);
String[] userIdsToExposeInCurrentCycle = new String[]{"group1"};
assignToUsers(Arrays.asList(userIdsToExposeInCurrentCycle), delegateExecution.getProcessInstanceId(),delegateExecution.getProcessDefinitionId(), delegateExecution.getEngineServices().getTaskService());
}
private void assignToUsers(List<String> userIds, String processInstanceId, String processDefinitionId, TaskService taskService){
for (String each : userIds){
TaskEntity task = (TaskEntity) taskService.newTask();
task.setName("DynamicUserTask - " + each);
task.setPriority(100);
task.setProcessInstanceId(processInstanceId);
task.setProcessDefinitionId(processDefinitionId);
System.out.println("About to save task " + task);
taskService.saveTask(task);
System.out.println("Done saving task " + task);
try {
taskService.addCandidateGroup(task.getId(), each);
System.out.println("Done adding candidate groups for task " + task);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
@Test
public void testCreateTaskInServiceTask() throws Exception{
runtimeService.startProcessInstanceByKey("CreateTasksProcess");
Task task = taskService.createTaskQuery().processDefinitionKey("CreateTasksProcess").singleResult();
taskService.addCandidateGroup(task.getId(), "user1");
List<Task> tasks = taskService.createTaskQuery().taskCandidateGroup("group1").list();
assertNotNull(tasks);
assertEquals(1,tasks.size());
}
About to save task Task[null]
Done saving task Task[111]
Done adding candidate groups for task Task[111]
Feb 08, 2013 4:31:43 PM org.activiti.engine.impl.interceptor.CommandContext close
SEVERE: Error while closing command context
org.activiti.engine.ActivitiException: Cannot find task with id 111
at org.activiti.engine.impl.cmd.NeedsActiveTaskCmd.execute(NeedsActiveTaskCmd.java:51)
at org.activiti.engine.impl.interceptor.CommandExecutorImpl.execute(CommandExecutorImpl.java:24)
at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:60)
at org.activiti.spring.SpringTransactionInterceptor$1.doInTransaction(SpringTransactionInterceptor.java:42)
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:130)
at org.activiti.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:40)
at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:32)
at org.activiti.engine.impl.TaskServiceImpl.addCandidateGroup(TaskServiceImpl.java:120)
at simple.activiti.tasks.DummyUserExposureServiceTask.assignToUsers(DummyUserExposureServiceTask.java:37)
at simple.activiti.tasks.DummyUserExposureServiceTask.execute(DummyUserExposureServiceTask.java:20)
at org.activiti.engine.impl.delegate.JavaDelegateInvocation.invoke(JavaDelegateInvocation.java:34)
at org.activiti.engine.impl.delegate.DelegateInvocation.proceed(DelegateInvocation.java:37)
at org.activiti.engine.impl.delegate.DefaultDelegateInterceptor.handleInvocation(DefaultDelegateInterceptor.java:25)
at org.activiti.engine.impl.bpmn.behavior.ServiceTaskDelegateExpressionActivityBehavior.execute(ServiceTaskDelegateExpressionActivityBehavior.java:74)
at org.activiti.engine.impl.pvm.runtime.AtomicOperationActivityExecute.execute(AtomicOperationActivityExecute.java:44)
at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:85)
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:535)
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:530)
at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionNotifyListenerStart.eventNotificationsCompleted(AtomicOperationTransitionNotifyListenerStart.java:52)
at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:56)
at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:85)
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:535)
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:530)
at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:49)
at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:85)
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:535)
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:530)
at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionCreateScope.execute(AtomicOperationTransitionCreateScope.java:49)
at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:85)
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:535)
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:530)
at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionNotifyListenerTake.execute(AtomicOperationTransitionNotifyListenerTake.java:65)
at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:85)
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:535)
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:530)
at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionDestroyScope.execute(AtomicOperationTransitionDestroyScope.java:115)
at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:85)
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:535)
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:530)
at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionNotifyListenerEnd.eventNotificationsCompleted(AtomicOperationTransitionNotifyListenerEnd.java:36)
at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:56)
at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:85)
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:535)
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:530)
at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:49)
at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:85)
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:535)
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:530)
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.take(ExecutionEntity.java:370)
at org.activiti.engine.impl.bpmn.behavior.ExclusiveGatewayActivityBehavior.leave(ExclusiveGatewayActivityBehavior.java:74)
at org.activiti.engine.impl.bpmn.behavior.FlowNodeActivityBehavior.execute(FlowNodeActivityBehavior.java:36)
at org.activiti.engine.impl.pvm.runtime.AtomicOperationActivityExecute.execute(AtomicOperationActivityExecute.java:44)
at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:85)
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:535)
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:530)
at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionNotifyListenerStart.eventNotificationsCompleted(AtomicOperationTransitionNotifyListenerStart.java:52)
at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:56)
at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:85)
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:535)
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:530)
at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:49)
at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:85)
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:535)
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:530)
at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionCreateScope.execute(AtomicOperationTransitionCreateScope.java:49)
at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:85)
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:535)
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:530)
at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionNotifyListenerTake.execute(AtomicOperationTransitionNotifyListenerTake.java:65)
at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:85)
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:535)
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:530)
at org.activiti.engine.impl.pvm.runtime.AtomicOperationTransitionDestroyScope.execute(AtomicOperationTransitionDestroyScope.java:115)
at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:85)
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperationSync(ExecutionEntity.java:535)
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:530)
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlnsmgdc="http://www.omg.org/spec/DD/20100524/DC" xmlnsmgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
<process id="CreateTasksProcess" name="CreateTasksProcess">
<endEvent id="endevent1" name="End"></endEvent>
<serviceTask id="servicetask2" name="Send offer to users (create tasks)" default="flow46" activiti:delegateExpression="${userExposureServiceTask}"></serviceTask>
<startEvent id="startevent1" name="Start"></startEvent>
<exclusiveGateway id="exclusivegateway1" name="Exclusive Gateway"></exclusiveGateway>
<exclusiveGateway id="exclusivegateway2" name="Exclusive Gateway"></exclusiveGateway>
<sequenceFlow id="flow21" name="${moreUsers}" sourceRef="exclusivegateway1" targetRef="exclusivegateway2">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${moreUsers}]]></conditionExpression>
</sequenceFlow>
<sequenceFlow id="flow22" name="" sourceRef="exclusivegateway2" targetRef="servicetask2"></sequenceFlow>
<sequenceFlow id="flow46" name="" sourceRef="servicetask2" targetRef="exclusivegateway1"></sequenceFlow>
<sequenceFlow id="flow47" name="" sourceRef="exclusivegateway1" targetRef="usertask1"></sequenceFlow>
<sequenceFlow id="flow48" name="" sourceRef="startevent1" targetRef="exclusivegateway2"></sequenceFlow>
<sequenceFlow id="flow49" name="" sourceRef="exclusivegateway2" targetRef="endevent1">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[false]]></conditionExpression>
</sequenceFlow>
<userTask id="usertask1" name="Dummy User Task to keep process running"></userTask>
<sequenceFlow id="flow50" name="" sourceRef="usertask1" targetRef="endevent1"></sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_CreateTasksProcess">
<bpmndi:BPMNPlane bpmnElement="CreateTasksProcess" id="BPMNPlane_CreateTasksProcess">
<bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
<omgdc:Bounds height="35" width="35" x="980" y="163"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="servicetask2" id="BPMNShape_servicetask2">
<omgdc:Bounds height="55" width="105" x="520" y="152"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
<omgdc:Bounds height="35" width="35" x="277" y="162"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="exclusivegateway1" id="BPMNShape_exclusivegateway1">
<omgdc:Bounds height="40" width="40" x="763" y="160"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="exclusivegateway2" id="BPMNShape_exclusivegateway2">
<omgdc:Bounds height="40" width="40" x="420" y="160"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
<omgdc:Bounds height="68" width="114" x="830" y="147"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="flow21" id="BPMNEdge_flow21">
<omgdi:waypoint x="783" y="160"></omgdi:waypoint>
<omgdi:waypoint x="782" y="65"></omgdi:waypoint>
<omgdi:waypoint x="439" y="65"></omgdi:waypoint>
<omgdi:waypoint x="440" y="160"></omgdi:waypoint>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="13" width="100" x="10" y="0"></omgdc:Bounds>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow22" id="BPMNEdge_flow22">
<omgdi:waypoint x="460" y="180"></omgdi:waypoint>
<omgdi:waypoint x="520" y="179"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow46" id="BPMNEdge_flow46">
<omgdi:waypoint x="625" y="179"></omgdi:waypoint>
<omgdi:waypoint x="763" y="180"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow47" id="BPMNEdge_flow47">
<omgdi:waypoint x="803" y="180"></omgdi:waypoint>
<omgdi:waypoint x="830" y="181"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow48" id="BPMNEdge_flow48">
<omgdi:waypoint x="312" y="179"></omgdi:waypoint>
<omgdi:waypoint x="420" y="180"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow49" id="BPMNEdge_flow49">
<omgdi:waypoint x="440" y="200"></omgdi:waypoint>
<omgdi:waypoint x="440" y="325"></omgdi:waypoint>
<omgdi:waypoint x="725" y="325"></omgdi:waypoint>
<omgdi:waypoint x="997" y="325"></omgdi:waypoint>
<omgdi:waypoint x="997" y="198"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow50" id="BPMNEdge_flow50">
<omgdi:waypoint x="944" y="181"></omgdi:waypoint>
<omgdi:waypoint x="980" y="180"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
02-11-2013 03:29 AM
02-11-2013 11:20 AM
public class TaskServiceImpl extends ServiceImpl implements TaskService {
…
public void addCandidateGroup(String taskId, String groupId) {
commandExecutor.execute(new AddIdentityLinkCmd(taskId, null, groupId, IdentityLinkType.CANDIDATE));
}
…
}
public class AddIdentityLinkCmd extends NeedsActiveTaskCmd<Void>
02-13-2013 08:29 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.