AnsweredAssumed Answered

How to auto complete a task

Question asked by hiscaler on Nov 20, 2013
Latest reply on Nov 21, 2013 by hiscaler
I will auto complete a task, flollow is my BPM XML

<?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" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="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="DueDate" name="任务过期时间测试" isExecutable="true">
    <startEvent id="startevent1" name="Start"></startEvent>
    <userTask id="一分钟之后过期" name="一分钟之后过期"></userTask>
    <endEvent id="endevent1" name="End"></endEvent>
    <sequenceFlow id="flow1" sourceRef="startevent1" targetRef="一分钟之后过期"></sequenceFlow>
    <sequenceFlow id="flow2" sourceRef="一分钟之后过期" targetRef="endevent1"></sequenceFlow>
    <boundaryEvent id="boundarytimer1" name="Timer" attachedToRef="一分钟之后过期" cancelActivity="false">
      <timerEventDefinition>
        <timeDuration>PT1M</timeDuration>
      </timerEventDefinition>
    </boundaryEvent>
    <serviceTask id="servicetask1" name="Service Task" activiti:class="com.example.bpm.javaDelegate.AutoFinishTaskService"></serviceTask>
    <sequenceFlow id="flow3" sourceRef="boundarytimer1" targetRef="servicetask1"></sequenceFlow>
    <sequenceFlow id="flow4" sourceRef="servicetask1" targetRef="endevent1"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_DueDate">
    <bpmndi:BPMNPlane bpmnElement="DueDate" id="BPMNPlane_DueDate">
      <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="120.0" y="109.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="480.0" y="109.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="一分钟之后过期" id="BPMNShape_一分钟之后过期">
        <omgdc:Bounds height="55.0" width="105.0" x="250.0" y="99.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="boundarytimer1" id="BPMNShape_boundarytimer1">
        <omgdc:Bounds height="30.0" width="30.0" x="325.0" y="140.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="servicetask1" id="BPMNShape_servicetask1">
        <omgdc:Bounds height="55.0" width="105.0" x="445.0" y="200.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
        <omgdi:waypoint x="155.0" y="126.0"></omgdi:waypoint>
        <omgdi:waypoint x="250.0" y="126.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
        <omgdi:waypoint x="355.0" y="126.0"></omgdi:waypoint>
        <omgdi:waypoint x="480.0" y="126.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
        <omgdi:waypoint x="340.0" y="170.0"></omgdi:waypoint>
        <omgdi:waypoint x="339.0" y="227.0"></omgdi:waypoint>
        <omgdi:waypoint x="445.0" y="227.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4">
        <omgdi:waypoint x="497.0" y="200.0"></omgdi:waypoint>
        <omgdi:waypoint x="497.0" y="144.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>



Flollow is my AutoFinishTaskService code:

package com.example.bpm.javaDelegate;

import java.util.List;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.TaskService;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.JavaDelegate;
import org.activiti.engine.task.Task;

public class AutoFinishTaskService implements JavaDelegate {
   
    public void execute(DelegateExecution delegateExecution) throws Exception {
        ProcessEngine pe = ProcessEngines.getDefaultProcessEngine();
        TaskService taskService = pe.getTaskService();
        List<Task> tasks = taskService.createTaskQuery().list();
        if (tasks.size() > 0) {
            for (Task task : tasks) {
                taskService.complete(task.getId());               
            }
        } else {
            System.out.println("No Tasks");
        }
    }
}



package com.example.bpm.javaDelegate;

import java.util.List;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.TaskService;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.JavaDelegate;
import org.activiti.engine.task.Task;

public class AutoFinishTaskService implements JavaDelegate {
   
    public void execute(DelegateExecution delegateExecution) throws Exception {
        ProcessEngine pe = ProcessEngines.getDefaultProcessEngine();
        TaskService taskService = pe.getTaskService();
        List<Task> tasks = taskService.createTaskQuery().list();
        if (tasks.size() > 0) {
            for (Task task : tasks) {
                taskService.complete(task.getId());               
            }
        } else {
            System.out.println("No Tasks");
        }
    }
}

After one minute, This service is called. but throw some exception, like this.


09:09:54,141 ERROR [STDERR] Exception in thread "pool-164-thread-1"
09:09:54,141 ERROR [STDERR] org.activiti.engine.ActivitiException: this activity
doesn't accept signals
09:09:54,142 ERROR [STDERR]     at org.activiti.engine.impl.bpmn.behavior.FlowNo
deActivityBehavior.signal(FlowNodeActivityBehavior.java:53)
09:09:54,142 ERROR [STDERR]     at org.activiti.engine.impl.persistence.entity.E
xecutionEntity.signal(ExecutionEntity.java:350)
09:09:54,143 ERROR [STDERR]     at org.activiti.engine.impl.persistence.entity.T
askEntity.complete(TaskEntity.java:168)
09:09:54,143 ERROR [STDERR]     at org.activiti.engine.impl.cmd.CompleteTaskCmd.
execute(CompleteTaskCmd.java:39)
09:09:54,143 ERROR [STDERR]     at org.activiti.engine.impl.cmd.CompleteTaskCmd.
execute(CompleteTaskCmd.java:24)
09:09:54,143 ERROR [STDERR]     at org.activiti.engine.impl.cmd.NeedsActiveTaskC
md.execute(NeedsActiveTaskCmd.java:61)
09:09:54,143 ERROR [STDERR]     at org.activiti.engine.impl.interceptor.CommandE
xecutorImpl.execute(CommandExecutorImpl.java:24)
09:09:54,144 ERROR [STDERR]     at org.activiti.engine.impl.interceptor.CommandC
ontextInterceptor.execute(CommandContextInterceptor.java:61)
09:09:54,144 ERROR [STDERR]     at org.activiti.engine.impl.interceptor.LogInter
ceptor.execute(LogInterceptor.java:31)
09:09:54,144 ERROR [STDERR]     at org.activiti.engine.impl.TaskServiceImpl.comp
lete(TaskServiceImpl.java:163)
09:09:54,144 ERROR [STDERR]     at com.example.bpm.javaDelegate.AutoFinishTaskSer
vice.execute(Unknown Source)
09:09:54,145 ERROR [STDERR]     at org.activiti.engine.impl.delegate.JavaDelegat
eInvocation.invoke(JavaDelegateInvocation.java:34)
09:09:54,145 ERROR [STDERR]     at org.activiti.engine.impl.delegate.DelegateInv
ocation.proceed(DelegateInvocation.java:37)
09:09:54,145 ERROR [STDERR]     at org.activiti.engine.impl.delegate.DefaultDele
gateInterceptor.handleInvocation(DefaultDelegateInterceptor.java:25)
09:09:54,145 ERROR [STDERR]     at org.activiti.engine.impl.bpmn.behavior.Servic
eTaskJavaDelegateActivityBehavior.execute(ServiceTaskJavaDelegateActivityBehavio
r.java:49)
09:09:54,145 ERROR [STDERR]     at org.activiti.engine.impl.bpmn.behavior.Servic
eTaskJavaDelegateActivityBehavior.execute(ServiceTaskJavaDelegateActivityBehavio
r.java:40)
09:09:54,146 ERROR [STDERR]     at org.activiti.engine.impl.bpmn.helper.ClassDel
egate.execute(ClassDelegate.java:116)
09:09:54,146 ERROR [STDERR]     at org.activiti.engine.impl.pvm.runtime.AtomicOp
erationActivityExecute.execute(AtomicOperationActivityExecute.java:44)
09:09:54,146 ERROR [STDERR]     at org.activiti.engine.impl.interceptor.CommandC
ontext.performOperation(CommandContext.java:87)
09:09:54,146 ERROR [STDERR]     at org.activiti.engine.impl.persistence.entity.E
xecutionEntity.performOperationSync(ExecutionEntity.java:532)
09:09:54,146 ERROR [STDERR]     at org.activiti.engine.impl.persistence.entity.E
xecutionEntity.performOperation(ExecutionEntity.java:527)
09:09:54,147 ERROR [STDERR]     at org.activiti.engine.impl.pvm.runtime.AtomicOp
erationTransitionNotifyListenerStart.eventNotificationsCompleted(AtomicOperation
TransitionNotifyListenerStart.java:52)
09:09:54,147 ERROR [STDERR]     at org.activiti.engine.impl.pvm.runtime.Abstract
EventAtomicOperation.execute(AbstractEventAtomicOperation.java:56)
09:09:54,147 ERROR [STDERR]     at org.activiti.engine.impl.interceptor.CommandC
ontext.performOperation(CommandContext.java:87)
09:09:54,147 ERROR [STDERR]     at org.activiti.engine.impl.persistence.entity.E
xecutionEntity.performOperationSync(ExecutionEntity.java:532)
09:09:54,148 ERROR [STDERR]     at org.activiti.engine.impl.persistence.entity.E
xecutionEntity.performOperation(ExecutionEntity.java:527)
09:09:54,148 ERROR [STDERR]     at org.activiti.engine.impl.pvm.runtime.Abstract
EventAtomicOperation.execute(AbstractEventAtomicOperation.java:49)
09:09:54,148 ERROR [STDERR]     at org.activiti.engine.impl.interceptor.CommandC
ontext.performOperation(CommandContext.java:87)
09:09:54,148 ERROR [STDERR]     at org.activiti.engine.impl.persistence.entity.E
xecutionEntity.performOperationSync(ExecutionEntity.java:532)
09:09:54,148 ERROR [STDERR]     at org.activiti.engine.impl.persistence.entity.E
xecutionEntity.performOperation(ExecutionEntity.java:527)
09:09:54,149 ERROR [STDERR]     at org.activiti.engine.impl.pvm.runtime.AtomicOp
erationTransitionCreateScope.execute(AtomicOperationTransitionCreateScope.java:4
9)
09:09:54,149 ERROR [STDERR]     at org.activiti.engine.impl.interceptor.CommandC
ontext.performOperation(CommandContext.java:87)
09:09:54,149 ERROR [STDERR]     at org.activiti.engine.impl.persistence.entity.E
xecutionEntity.performOperationSync(ExecutionEntity.java:532)
09:09:54,156 ERROR [STDERR]     at org.activiti.engine.impl.persistence.entity.E
xecutionEntity.performOperation(ExecutionEntity.java:527)
09:09:54,156 ERROR [STDERR]     at org.activiti.engine.impl.pvm.runtime.AtomicOp
erationTransitionNotifyListenerTake.execute(AtomicOperationTransitionNotifyListe
nerTake.java:66)
09:09:54,156 ERROR [STDERR]     at org.activiti.engine.impl.interceptor.CommandC
ontext.performOperation(CommandContext.java:87)
09:09:54,156 ERROR [STDERR]     at org.activiti.engine.impl.persistence.entity.E
xecutionEntity.performOperationSync(ExecutionEntity.java:532)
09:09:54,156 ERROR [STDERR]     at org.activiti.engine.impl.persistence.entity.E
xecutionEntity.performOperation(ExecutionEntity.java:527)
09:09:54,157 ERROR [STDERR]     at org.activiti.engine.impl.pvm.runtime.AtomicOp
erationTransitionDestroyScope.execute(AtomicOperationTransitionDestroyScope.java
:116)
09:09:54,157 ERROR [STDERR]     at org.activiti.engine.impl.interceptor.CommandC
ontext.performOperation(CommandContext.java:87)
09:09:54,157 ERROR [STDERR]     at org.activiti.engine.impl.persistence.entity.E
xecutionEntity.performOperationSync(ExecutionEntity.java:532)
09:09:54,157 ERROR [STDERR]     at org.activiti.engine.impl.persistence.entity.E
xecutionEntity.performOperation(ExecutionEntity.java:527)
09:09:54,157 ERROR [STDERR]     at org.activiti.engine.impl.pvm.runtime.AtomicOp
erationTransitionNotifyListenerEnd.eventNotificationsCompleted(AtomicOperationTr
ansitionNotifyListenerEnd.java:36)
09:09:54,161 ERROR [STDERR]     at org.activiti.engine.impl.pvm.runtime.Abstract
EventAtomicOperation.execute(AbstractEventAtomicOperation.java:56)
09:09:54,161 ERROR [STDERR]     at org.activiti.engine.impl.interceptor.CommandC
ontext.performOperation(CommandContext.java:87)
09:09:54,162 ERROR [STDERR]     at org.activiti.engine.impl.persistence.entity.E
xecutionEntity.performOperationSync(ExecutionEntity.java:532)
09:09:54,162 ERROR [STDERR]     at org.activiti.engine.impl.persistence.entity.E
xecutionEntity.performOperation(ExecutionEntity.java:527)
09:09:54,162 ERROR [STDERR]     at org.activiti.engine.impl.pvm.runtime.Abstract
EventAtomicOperation.execute(AbstractEventAtomicOperation.java:49)
09:09:54,162 ERROR [STDERR]     at org.activiti.engine.impl.interceptor.CommandC
ontext.performOperation(CommandContext.java:87)
09:09:54,167 ERROR [STDERR]     at org.activiti.engine.impl.persistence.entity.E
xecutionEntity.performOperationSync(ExecutionEntity.java:532)
09:09:54,167 ERROR [STDERR]     at org.activiti.engine.impl.persistence.entity.E
xecutionEntity.performOperation(ExecutionEntity.java:527)
09:09:54,167 ERROR [STDERR]     at org.activiti.engine.impl.pvm.runtime.AtomicOp
erationTransitionDestroyScope.execute(AtomicOperationTransitionDestroyScope.java
:114)
09:09:54,167 ERROR [STDERR]     at org.activiti.engine.impl.interceptor.CommandC
ontext.performOperation(CommandContext.java:87)
09:09:54,168 ERROR [STDERR]     at org.activiti.engine.impl.persistence.entity.E
xecutionEntity.performOperationSync(ExecutionEntity.java:532)
09:09:54,168 ERROR [STDERR]     at org.activiti.engine.impl.persistence.entity.E
xecutionEntity.performOperation(ExecutionEntity.java:527)
09:09:54,173 ERROR [STDERR]     at org.activiti.engine.impl.pvm.runtime.AtomicOp
erationTransitionNotifyListenerEnd.eventNotificationsCompleted(AtomicOperationTr
ansitionNotifyListenerEnd.java:36)
09:09:54,173 ERROR [STDERR]     at org.activiti.engine.impl.pvm.runtime.Abstract

Outcomes