Skip to content

Commit

Permalink
Add legacy user task next fire
Browse files Browse the repository at this point in the history
  • Loading branch information
felix-mueller committed Mar 1, 2019
1 parent 57703e3 commit 22e78ca
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,41 +17,44 @@
import com.camunda.consulting.simulator.property.ModelPropertyUtil;

public class AbstractTimerJobCreator {
static final Logger LOG = LoggerFactory.getLogger(AbstractTimerJobCreator.class);

public AbstractTimerJobCreator() {
super();
}

protected Optional<Expression> getCachedNextCompleteExpression(DelegateExecution execution, String activityId) {
return CachedPropertyUtil.getExpression(execution, activityId, ModelPropertyUtil.CAMUNDA_PROPERTY_SIM_NEXT_COMPLETE);
}

protected Optional<Expression> getCachedNextClaimExpression(DelegateExecution execution, String activityId) {
return CachedPropertyUtil.getExpression(execution, activityId, ModelPropertyUtil.CAMUNDA_PROPERTY_SIM_NEXT_CLAIM);
static final Logger LOG = LoggerFactory.getLogger(AbstractTimerJobCreator.class);

public AbstractTimerJobCreator() {
super();
}

protected Optional<Expression> getCachedNextCompleteExpression(DelegateExecution execution, String activityId) {
return CachedPropertyUtil.getExpression(execution, activityId,
ModelPropertyUtil.CAMUNDA_PROPERTY_SIM_NEXT_COMPLETE);
}



protected Optional<Expression> getCachedClaimUserExpression(DelegateExecution execution, String activityId) {
return CachedPropertyUtil.getExpression(execution, activityId, ModelPropertyUtil.CAMUNDA_PROPERTY_SIM_CLAIM_USER);
protected Optional<Expression> getCachedNextClaimExpression(DelegateExecution execution, String activityId) {
return CachedPropertyUtil.getExpression(execution, activityId,
ModelPropertyUtil.CAMUNDA_PROPERTY_SIM_NEXT_CLAIM);
}

protected Optional<Expression> getCachedClaimUserExpression(DelegateExecution execution, String activityId) {
return CachedPropertyUtil.getExpression(execution, activityId,
ModelPropertyUtil.CAMUNDA_PROPERTY_SIM_CLAIM_USER);
}

protected Optional<Expression> getCachedNextFireExpression(DelegateExecution execution, String activityId) {
return CachedPropertyUtil.getExpression(execution, activityId,
ModelPropertyUtil.CAMUNDA_PROPERTY_SIM_NEXT_FIRE);
}

protected void createTimerJob(ExecutionEntity execution, String jobHandlertype, Date duedate,
JobHandlerConfiguration jobHandlerConfiguration) {
TimerEntity timer = new TimerEntity();
ProcessDefinitionEntity processDefinition = execution.getProcessDefinition();

timer.setExecution(execution);
timer.setDuedate(duedate);
timer.setJobHandlerType(jobHandlertype);
timer.setProcessDefinitionKey(processDefinition.getKey());
timer.setDeploymentId(processDefinition.getDeploymentId());
timer.setJobHandlerConfiguration(jobHandlerConfiguration);

Context.getCommandContext().getJobManager().schedule(timer);
}

protected Optional<Expression> getCachedNextFireExpression(DelegateExecution execution, String activityId) {
return CachedPropertyUtil.getExpression(execution, activityId, ModelPropertyUtil.CAMUNDA_PROPERTY_SIM_NEXT_FIRE);
}

protected void createTimerJob(ExecutionEntity execution, String jobHandlertype, Date duedate, JobHandlerConfiguration jobHandlerConfiguration) {
TimerEntity timer = new TimerEntity();
ProcessDefinitionEntity processDefinition = execution.getProcessDefinition();

timer.setExecution(execution);
timer.setDuedate(duedate);
timer.setJobHandlerType(jobHandlertype);
timer.setProcessDefinitionKey(processDefinition.getKey());
timer.setDeploymentId(processDefinition.getDeploymentId());
timer.setJobHandlerConfiguration(jobHandlerConfiguration);

Context.getCommandContext().getJobManager().schedule(timer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ public void notify(DelegateTask task) {

Optional<Expression> nextCompleteExpression = getCachedNextCompleteExpression(task.getExecution(), task.getTaskDefinitionKey());

// backwards compatibility (user task next fire)
if (!nextCompleteExpression.isPresent()) {
nextCompleteExpression = getCachedNextFireExpression(task.getExecution(), task.getTaskDefinitionKey());
}

if (nextCompleteExpression.isPresent()) {
Date dueDate = (Date) nextCompleteExpression.get().getValue(task.getExecution());
createJobForUserTaskCompletion(task, dueDate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import com.camunda.consulting.simulator.SimulationExecutor;
import com.camunda.consulting.simulator.TestHelper;

@Deployment(resources = "userTaskCompleteModel.bpmn")
@Deployment(resources = {"userTaskCompleteModel.bpmn", "userTaskCompleteModelLegacy.bpmn"})
public class CompleteUserTaskJobHandlerTest {

@Rule
Expand Down Expand Up @@ -54,5 +54,19 @@ public void shouldExecuteCompleteTaskJob() {
assertThat(processInstance).isEnded();

}

@Test
public void shouldExecuteCompleteLegacyTaskJob() {

ProcessInstance processInstance = runtimeService().startProcessInstanceByKey("userTaskCompleteLegacy");
assertThat(processInstance).isStarted().isWaitingAt("Task_1");
complete(task());
assertThat(processInstance).isWaitingAt("Task_2");

SimulationExecutor.execute(DateTime.now().minusMinutes(5).toDate(), DateTime.now().plusMinutes(5).toDate());

assertThat(processInstance).isEnded();

}

}
55 changes: 55 additions & 0 deletions src/test/resources/userTaskCompleteModelLegacy.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" id="Definitions_05tfkfg" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="3.0.0-beta.2">
<bpmn:process id="userTaskCompleteLegacy" isExecutable="true">
<bpmn:startEvent id="StartEvent_1">
<bpmn:outgoing>SequenceFlow_1uhkbo6</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:sequenceFlow id="SequenceFlow_1uhkbo6" sourceRef="StartEvent_1" targetRef="Task_1" />
<bpmn:endEvent id="EndEvent_0fiumuf">
<bpmn:incoming>SequenceFlow_0w3ktbu</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="SequenceFlow_0w3ktbu" sourceRef="Task_2" targetRef="EndEvent_0fiumuf" />
<bpmn:userTask id="Task_2" name="Create Job">
<bpmn:extensionElements>
<camunda:properties>
<camunda:property name="simNextFire" value="${g.now()}" />
</camunda:properties>
</bpmn:extensionElements>
<bpmn:incoming>SequenceFlow_09qfj04</bpmn:incoming>
<bpmn:outgoing>SequenceFlow_0w3ktbu</bpmn:outgoing>
</bpmn:userTask>
<bpmn:sequenceFlow id="SequenceFlow_09qfj04" sourceRef="Task_1" targetRef="Task_2" />
<bpmn:userTask id="Task_1" name="Don&#39;t create job">
<bpmn:incoming>SequenceFlow_1uhkbo6</bpmn:incoming>
<bpmn:outgoing>SequenceFlow_09qfj04</bpmn:outgoing>
</bpmn:userTask>
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="userTaskCompleteLegacy">
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
<dc:Bounds x="156" y="102" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="SequenceFlow_1uhkbo6_di" bpmnElement="SequenceFlow_1uhkbo6">
<di:waypoint x="192" y="120" />
<di:waypoint x="245" y="120" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="EndEvent_0fiumuf_di" bpmnElement="EndEvent_0fiumuf">
<dc:Bounds x="539" y="102" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="SequenceFlow_0w3ktbu_di" bpmnElement="SequenceFlow_0w3ktbu">
<di:waypoint x="502" y="120" />
<di:waypoint x="539" y="120" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="UserTask_1i3llw9_di" bpmnElement="Task_2">
<dc:Bounds x="402" y="80" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="SequenceFlow_09qfj04_di" bpmnElement="SequenceFlow_09qfj04">
<di:waypoint x="345" y="120" />
<di:waypoint x="402" y="120" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="UserTask_01pxo6i_di" bpmnElement="Task_1">
<dc:Bounds x="245" y="80" width="100" height="80" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>

0 comments on commit 22e78ca

Please sign in to comment.