Search code examples
activitibpmn

Timer End event in activiti


I am designing a vacation request . Suppose the user submits vacation Request with vacation start date and end date. It goes to Group A team. That team can schedule the task. But if they did not schedule, the request has to end if vacation end date is met. So i am looking for timer . Timer should run from vacation start date and end date. If suppose group A schedule the task ,it goes to group B. Group B can only cancel the request( No approval is required). if group B cancel the request,it goes to groupA work queue. Group A can complete the task to end. If group B didnt cancel the request the request has to end. Please validate my workflow.

     <?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="myProcess" name="My process" isExecutable="true">
        <startEvent id="startevent1" name="Start">
          <extensionElements>
            <activiti:formProperty id="vacationstartdate" name="Start Date" type="date"   
           variable="vacationstartdate" datePattern="dd-mm-yyyy" required="true">
              <activiti:value id="vacationstartdate" name="Start Date"></activiti:value>
            </activiti:formProperty>
            <activiti:formProperty id="vacationenddate" name="vacation end date" type="date" 
            variable="vacationenddate" datePattern="dd-mm-yyyy" required="true">
              <activiti:value id="vacationenddate" name="vacationenddate"></activiti:value>
            </activiti:formProperty>
          </extensionElements>
        </startEvent>
        <userTask id="usertask1" name="schedule task" activiti:candidateGroups="groupA">
          <extensionElements>
            <activiti:formProperty id="schdule" name="schduletask" type="enum" required="true">
              <activiti:value id="schduletask" name="schduletask"></activiti:value>
            </activiti:formProperty>
          </extensionElements>
        </userTask>
        <exclusiveGateway id="exclusivegateway2" name="Exclusive Gateway"></exclusiveGateway>
        <startEvent id="timerstartevent2" name="Timer start">
          <timerEventDefinition></timerEventDefinition>
        </startEvent>
        <userTask id="usertask2" name="GroupB cancel" activiti:candidateGroups="groupB">
          <extensionElements>
            <activiti:formProperty id="cancelrequest" name="cancelrequest" type="enum" 
          variable="cancelrequest">
              <activiti:value id="cancelrequest" name="cancelrequest"></activiti:value>
            </activiti:formProperty>
          </extensionElements>
        </userTask>
        <userTask id="usertask3" name="complete" activiti:candidateGroups="groupA">
          <extensionElements>

          <activiti:formProperty id="complete" name="complete" type="enum" variable="complete">
              <activiti:value id="complete" name="complete"></activiti:value>
            </activiti:formProperty>
          </extensionElements>
        </userTask>
        <endEvent id="endevent1" name="End"></endEvent>
        <sequenceFlow id="flow5" sourceRef="timerstartevent2" targetRef="exclusivegateway2">   

          </sequenceFlow>
        <sequenceFlow id="flow6" sourceRef="exclusivegateway2" targetRef="usertask2">

         </sequenceFlow>
        <sequenceFlow id="flow7" sourceRef="usertask2" targetRef="usertask3"></sequenceFlow>
        <sequenceFlow id="flow8" sourceRef="exclusivegateway2" targetRef="endevent1">
         </sequenceFlow>
        <sequenceFlow id="flow10" sourceRef="usertask3" targetRef="endevent1"></sequenceFlow>
        <exclusiveGateway id="exclusivegateway3" name="Exclusive Gateway"></exclusiveGateway>
        <sequenceFlow id="flow11" name="Request" sourceRef="startevent1" targetRef="usertask1">
         </sequenceFlow>
        <sequenceFlow id="flow12" sourceRef="usertask1" targetRef="exclusivegateway3">  
        </sequenceFlow>
        <sequenceFlow id="flow13" name="groupA schedule" sourceRef="exclusivegateway3" 
         targetRef="timerstartevent2"></sequenceFlow>
        <startEvent id="timerstartevent3" name="vacation end date">
          <timerEventDefinition></timerEventDefinition>
        </startEvent>
        <sequenceFlow id="flow14" name="groupA does not schedule" sourceRef="exclusivegateway3" 
         targetRef="timerstartevent3"></sequenceFlow>
        <sequenceFlow id="flow15" name="vacation end date met" sourceRef="timerstartevent3" 
         targetRef="endevent1"></sequenceFlow>
      </process>
      <bpmndi:BPMNDiagram id="BPMNDiagram_myProcess">
        <bpmndi:BPMNPlane bpmnElement="myProcess" id="BPMNPlane_myProcess">
          <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
            <omgdc:Bounds height="35.0" width="35.0" x="40.0" y="210.0"></omgdc:Bounds>
          </bpmndi:BPMNShape>
          <bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
            <omgdc:Bounds height="55.0" width="105.0" x="140.0" y="200.0"></omgdc:Bounds>
          </bpmndi:BPMNShape>
          <bpmndi:BPMNShape bpmnElement="exclusivegateway2" id="BPMNShape_exclusivegateway2">
            <omgdc:Bounds height="40.0" width="40.0" x="560.0" y="297.0"></omgdc:Bounds>
          </bpmndi:BPMNShape>
          <bpmndi:BPMNShape bpmnElement="timerstartevent2" id="BPMNShape_timerstartevent2">
            <omgdc:Bounds height="35.0" width="35.0" x="420.0" y="300.0"></omgdc:Bounds>
          </bpmndi:BPMNShape>
          <bpmndi:BPMNShape bpmnElement="usertask2" id="BPMNShape_usertask2">
            <omgdc:Bounds height="55.0" width="105.0" x="710.0" y="380.0"></omgdc:Bounds>
          </bpmndi:BPMNShape>
          <bpmndi:BPMNShape bpmnElement="usertask3" id="BPMNShape_usertask3">
            <omgdc:Bounds height="55.0" width="105.0" x="900.0" y="380.0"></omgdc:Bounds>
          </bpmndi:BPMNShape>
          <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
            <omgdc:Bounds height="35.0" width="35.0" x="1070.0" y="210.0"></omgdc:Bounds>
          </bpmndi:BPMNShape>
          <bpmndi:BPMNShape bpmnElement="exclusivegateway3" id="BPMNShape_exclusivegateway3">
            <omgdc:Bounds height="40.0" width="40.0" x="300.0" y="207.0"></omgdc:Bounds>
          </bpmndi:BPMNShape>
          <bpmndi:BPMNShape bpmnElement="timerstartevent3" id="BPMNShape_timerstartevent3">
            <omgdc:Bounds height="35.0" width="35.0" x="630.0" y="90.0"></omgdc:Bounds>
          </bpmndi:BPMNShape>
          <bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5">
            <omgdi:waypoint x="455.0" y="317.0"></omgdi:waypoint>
            <omgdi:waypoint x="560.0" y="317.0"></omgdi:waypoint>
          </bpmndi:BPMNEdge>
          <bpmndi:BPMNEdge bpmnElement="flow6" id="BPMNEdge_flow6">
            <omgdi:waypoint x="580.0" y="337.0"></omgdi:waypoint>
            <omgdi:waypoint x="580.0" y="407.0"></omgdi:waypoint>
            <omgdi:waypoint x="710.0" y="407.0"></omgdi:waypoint>
          </bpmndi:BPMNEdge>
          <bpmndi:BPMNEdge bpmnElement="flow7" id="BPMNEdge_flow7">
            <omgdi:waypoint x="815.0" y="407.0"></omgdi:waypoint>
            <omgdi:waypoint x="900.0" y="407.0"></omgdi:waypoint>
          </bpmndi:BPMNEdge>
          <bpmndi:BPMNEdge bpmnElement="flow8" id="BPMNEdge_flow8">
            <omgdi:waypoint x="580.0" y="297.0"></omgdi:waypoint>
            <omgdi:waypoint x="580.0" y="227.0"></omgdi:waypoint>
            <omgdi:waypoint x="1070.0" y="227.0"></omgdi:waypoint>
          </bpmndi:BPMNEdge>
          <bpmndi:BPMNEdge bpmnElement="flow10" id="BPMNEdge_flow10">
            <omgdi:waypoint x="1005.0" y="407.0"></omgdi:waypoint>
            <omgdi:waypoint x="1087.0" y="407.0"></omgdi:waypoint>
            <omgdi:waypoint x="1087.0" y="245.0"></omgdi:waypoint>
          </bpmndi:BPMNEdge>
          <bpmndi:BPMNEdge bpmnElement="flow11" id="BPMNEdge_flow11">
            <omgdi:waypoint x="75.0" y="227.0"></omgdi:waypoint>
            <omgdi:waypoint x="140.0" y="227.0"></omgdi:waypoint>
            <bpmndi:BPMNLabel>
              <omgdc:Bounds height="14.0" width="100.0" x="85.0" y="227.0"></omgdc:Bounds>
            </bpmndi:BPMNLabel>
          </bpmndi:BPMNEdge>
          <bpmndi:BPMNEdge bpmnElement="flow12" id="BPMNEdge_flow12">
            <omgdi:waypoint x="245.0" y="227.0"></omgdi:waypoint>
            <omgdi:waypoint x="300.0" y="227.0"></omgdi:waypoint>
          </bpmndi:BPMNEdge>
          <bpmndi:BPMNEdge bpmnElement="flow13" id="BPMNEdge_flow13">
            <omgdi:waypoint x="320.0" y="247.0"></omgdi:waypoint>
            <omgdi:waypoint x="320.0" y="317.0"></omgdi:waypoint>
            <omgdi:waypoint x="420.0" y="317.0"></omgdi:waypoint>
            <bpmndi:BPMNLabel>
              <omgdc:Bounds height="14.0" width="100.0" x="330.0" y="295.0"></omgdc:Bounds>
            </bpmndi:BPMNLabel>
          </bpmndi:BPMNEdge>
          <bpmndi:BPMNEdge bpmnElement="flow14" id="BPMNEdge_flow14">
            <omgdi:waypoint x="320.0" y="207.0"></omgdi:waypoint>
            <omgdi:waypoint x="320.0" y="107.0"></omgdi:waypoint>
            <omgdi:waypoint x="630.0" y="107.0"></omgdi:waypoint>
            <bpmndi:BPMNLabel>
              <omgdc:Bounds height="42.0" width="100.0" x="330.0" y="111.0"></omgdc:Bounds>
            </bpmndi:BPMNLabel>
          </bpmndi:BPMNEdge>
          <bpmndi:BPMNEdge bpmnElement="flow15" id="BPMNEdge_flow15">
            <omgdi:waypoint x="665.0" y="107.0"></omgdi:waypoint>
            <omgdi:waypoint x="1087.0" y="107.0"></omgdi:waypoint>
            <omgdi:waypoint x="1087.0" y="210.0"></omgdi:waypoint>
            <bpmndi:BPMNLabel>
              <omgdc:Bounds height="42.0" width="100.0" x="675.0" y="107.0"></omgdc:Bounds>
            </bpmndi:BPMNLabel>
            </bpmndi:BPMNEdge>
           </bpmndi:BPMNPlane>
        </bpmndi:BPMNDiagram>
       </definitions>

Solution

  • I check this model and it doesn't seem to be correct. There is list of issues I found:

    flow13 and flow14 should have set constraints, for example: <conditionExpression xsi:type="tFormalExpression"><![CDATA[${constraint}]]></conditionExpression> your constraint will probably contain check if schedule was made

    you should set some time constraint into timerstartevent2 and timerstartevent3

    exclusivegateway2 is not neccesary

    usertask2 should have new TimerBoundryEvent - this will interupt usertask for groupB if they dont complete their task

    I made a version which should be more or less ok ;)

    <?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="myProcess" name="My process" isExecutable="true">
            <startEvent id="startevent1" name="Start">
              <extensionElements>
                <activiti:formProperty id="vacationstartdate" name="Start Date" type="date" variable="vacationstartdate" datePattern="dd-mm-yyyy" required="true">
                  <activiti:value id="vacationstartdate" name="Start Date"></activiti:value>
                </activiti:formProperty>
                <activiti:formProperty id="vacationenddate" name="vacation end date" type="date" variable="vacationenddate" datePattern="dd-mm-yyyy" required="true">
                  <activiti:value id="vacationenddate" name="vacationenddate"></activiti:value>
                </activiti:formProperty>
              </extensionElements>
            </startEvent>
            <userTask id="usertask1" name="schedule task" activiti:candidateGroups="groupA">
              <extensionElements>
                <activiti:formProperty id="schdule" name="schduletask" type="enum" required="true">
                  <activiti:value id="schduletask" name="schduletask"></activiti:value>
                </activiti:formProperty>
              </extensionElements>
            </userTask>
            <startEvent id="timerstartevent2" name="Timer start">
              <timerEventDefinition>
                <timeDate>scheduleTime</timeDate>
              </timerEventDefinition>
            </startEvent>
            <userTask id="usertask2" name="GroupB cancel" activiti:candidateGroups="groupB">
              <extensionElements>
                <activiti:formProperty id="cancelrequest" name="cancelrequest" type="enum" variable="cancelrequest">
                  <activiti:value id="cancelrequest" name="cancelrequest"></activiti:value>
                </activiti:formProperty>
              </extensionElements>
            </userTask>
            <userTask id="usertask3" name="complete" activiti:candidateGroups="groupA">
              <extensionElements>
                <activiti:formProperty id="complete" name="complete" type="enum" variable="complete">
                  <activiti:value id="complete" name="complete"></activiti:value>
                </activiti:formProperty>
              </extensionElements>
            </userTask>
            <endEvent id="endevent1" name="End"></endEvent>
            <sequenceFlow id="flow5" sourceRef="timerstartevent2" targetRef="usertask2"></sequenceFlow>
            <sequenceFlow id="flow7" sourceRef="usertask2" targetRef="usertask3"></sequenceFlow>
            <sequenceFlow id="flow10" sourceRef="usertask3" targetRef="endevent1"></sequenceFlow>
            <exclusiveGateway id="exclusivegateway3" name="Exclusive Gateway"></exclusiveGateway>
            <sequenceFlow id="flow11" name="Request" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>
            <sequenceFlow id="flow12" sourceRef="usertask1" targetRef="exclusivegateway3"></sequenceFlow>
            <sequenceFlow id="flow13" name="groupA schedule" sourceRef="exclusivegateway3" targetRef="timerstartevent2">
              <conditionExpression xsi:type="tFormalExpression"><![CDATA[${!constraint}]]></conditionExpression>
            </sequenceFlow>
            <startEvent id="timerstartevent3" name="vacation end date">
              <timerEventDefinition>
                <timeDate>vacationEndTime</timeDate>
              </timerEventDefinition>
            </startEvent>
            <sequenceFlow id="flow14" name="groupA does not schedule" sourceRef="exclusivegateway3" targetRef="timerstartevent3">
              <conditionExpression xsi:type="tFormalExpression"><![CDATA[${constraint}]]></conditionExpression>
            </sequenceFlow>
            <sequenceFlow id="flow15" name="vacation end date met" sourceRef="timerstartevent3" targetRef="endevent1"></sequenceFlow>
            <boundaryEvent id="boundarytimer1" name="Timer" attachedToRef="usertask2" cancelActivity="true">
              <timerEventDefinition></timerEventDefinition>
            </boundaryEvent>
            <sequenceFlow id="flow16" sourceRef="boundarytimer1" targetRef="endevent1"></sequenceFlow>
          </process>
          <bpmndi:BPMNDiagram id="BPMNDiagram_myProcess">
            <bpmndi:BPMNPlane bpmnElement="myProcess" id="BPMNPlane_myProcess">
              <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
                <omgdc:Bounds height="35.0" width="35.0" x="40.0" y="210.0"></omgdc:Bounds>
              </bpmndi:BPMNShape>
              <bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
                <omgdc:Bounds height="55.0" width="105.0" x="140.0" y="200.0"></omgdc:Bounds>
              </bpmndi:BPMNShape>
              <bpmndi:BPMNShape bpmnElement="timerstartevent2" id="BPMNShape_timerstartevent2">
                <omgdc:Bounds height="35.0" width="35.0" x="420.0" y="300.0"></omgdc:Bounds>
              </bpmndi:BPMNShape>
              <bpmndi:BPMNShape bpmnElement="usertask2" id="BPMNShape_usertask2">
                <omgdc:Bounds height="55.0" width="105.0" x="690.0" y="290.0"></omgdc:Bounds>
              </bpmndi:BPMNShape>
              <bpmndi:BPMNShape bpmnElement="boundarytimer1" id="BPMNShape_boundarytimer1">
                <omgdc:Bounds height="30.0" width="30.0" x="750.0" y="280.0"></omgdc:Bounds>
              </bpmndi:BPMNShape>
              <bpmndi:BPMNShape bpmnElement="usertask3" id="BPMNShape_usertask3">
                <omgdc:Bounds height="55.0" width="105.0" x="890.0" y="290.0"></omgdc:Bounds>
              </bpmndi:BPMNShape>
              <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
                <omgdc:Bounds height="35.0" width="35.0" x="1070.0" y="210.0"></omgdc:Bounds>
              </bpmndi:BPMNShape>
              <bpmndi:BPMNShape bpmnElement="exclusivegateway3" id="BPMNShape_exclusivegateway3">
                <omgdc:Bounds height="40.0" width="40.0" x="300.0" y="207.0"></omgdc:Bounds>
              </bpmndi:BPMNShape>
              <bpmndi:BPMNShape bpmnElement="timerstartevent3" id="BPMNShape_timerstartevent3">
                <omgdc:Bounds height="35.0" width="35.0" x="630.0" y="90.0"></omgdc:Bounds>
              </bpmndi:BPMNShape>
              <bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5">
                <omgdi:waypoint x="455.0" y="317.0"></omgdi:waypoint>
                <omgdi:waypoint x="690.0" y="317.0"></omgdi:waypoint>
              </bpmndi:BPMNEdge>
              <bpmndi:BPMNEdge bpmnElement="flow7" id="BPMNEdge_flow7">
                <omgdi:waypoint x="795.0" y="317.0"></omgdi:waypoint>
                <omgdi:waypoint x="890.0" y="317.0"></omgdi:waypoint>
              </bpmndi:BPMNEdge>
              <bpmndi:BPMNEdge bpmnElement="flow10" id="BPMNEdge_flow10">
                <omgdi:waypoint x="995.0" y="317.0"></omgdi:waypoint>
                <omgdi:waypoint x="1087.0" y="317.0"></omgdi:waypoint>
                <omgdi:waypoint x="1087.0" y="245.0"></omgdi:waypoint>
              </bpmndi:BPMNEdge>
              <bpmndi:BPMNEdge bpmnElement="flow11" id="BPMNEdge_flow11">
                <omgdi:waypoint x="75.0" y="227.0"></omgdi:waypoint>
                <omgdi:waypoint x="140.0" y="227.0"></omgdi:waypoint>
                <bpmndi:BPMNLabel>
                  <omgdc:Bounds height="14.0" width="40.0" x="85.0" y="227.0"></omgdc:Bounds>
                </bpmndi:BPMNLabel>
              </bpmndi:BPMNEdge>
              <bpmndi:BPMNEdge bpmnElement="flow12" id="BPMNEdge_flow12">
                <omgdi:waypoint x="245.0" y="227.0"></omgdi:waypoint>
                <omgdi:waypoint x="300.0" y="227.0"></omgdi:waypoint>
              </bpmndi:BPMNEdge>
              <bpmndi:BPMNEdge bpmnElement="flow13" id="BPMNEdge_flow13">
                <omgdi:waypoint x="320.0" y="247.0"></omgdi:waypoint>
                <omgdi:waypoint x="320.0" y="317.0"></omgdi:waypoint>
                <omgdi:waypoint x="420.0" y="317.0"></omgdi:waypoint>
                <bpmndi:BPMNLabel>
                  <omgdc:Bounds height="14.0" width="100.0" x="330.0" y="295.0"></omgdc:Bounds>
                </bpmndi:BPMNLabel>
              </bpmndi:BPMNEdge>
              <bpmndi:BPMNEdge bpmnElement="flow14" id="BPMNEdge_flow14">
                <omgdi:waypoint x="320.0" y="207.0"></omgdi:waypoint>
                <omgdi:waypoint x="320.0" y="107.0"></omgdi:waypoint>
                <omgdi:waypoint x="630.0" y="107.0"></omgdi:waypoint>
                <bpmndi:BPMNLabel>
                  <omgdc:Bounds height="42.0" width="100.0" x="330.0" y="111.0"></omgdc:Bounds>
                </bpmndi:BPMNLabel>
              </bpmndi:BPMNEdge>
              <bpmndi:BPMNEdge bpmnElement="flow15" id="BPMNEdge_flow15">
                <omgdi:waypoint x="665.0" y="107.0"></omgdi:waypoint>
                <omgdi:waypoint x="1087.0" y="107.0"></omgdi:waypoint>
                <omgdi:waypoint x="1087.0" y="210.0"></omgdi:waypoint>
                <bpmndi:BPMNLabel>
                  <omgdc:Bounds height="42.0" width="100.0" x="675.0" y="107.0"></omgdc:Bounds>
                </bpmndi:BPMNLabel>
              </bpmndi:BPMNEdge>
              <bpmndi:BPMNEdge bpmnElement="flow16" id="BPMNEdge_flow16">
                <omgdi:waypoint x="765.0" y="280.0"></omgdi:waypoint>
                <omgdi:waypoint x="764.0" y="227.0"></omgdi:waypoint>
                <omgdi:waypoint x="1070.0" y="227.0"></omgdi:waypoint>
              </bpmndi:BPMNEdge>
            </bpmndi:BPMNPlane>
          </bpmndi:BPMNDiagram>
        </definitions>