提交 16da29f8 编写于 作者: F frederikheremans

ACT-730: adding getProcessBusinessKey() because getBusinessKey() on...

ACT-730: adding getProcessBusinessKey() because getBusinessKey() on executionEntity cannot return the process-instance business-key since that method is also used for persistence
上级 7e6ccdf6
......@@ -31,6 +31,17 @@ public interface DelegateExecution extends VariableScope {
/** The {@link ExecutionListener#EVENTNAME_START event name} in case this execution is passed in for an {@link ExecutionListener} */
String getEventName();
/** The business key that was associated with the process this execution is part of. */
/** The business key for this execution. Only returns a value if the delegate execution
* is a process instance.
*
* @deprecated use {@link #getProcessBusinessKey()} to get the business key for the process
* associated with this execution, regardless whether or not this execution is a
* process-instance.
*/
String getBusinessKey();
/**
* The business key for the process instance this execution is associated with.
*/
String getProcessBusinessKey();
}
......@@ -556,6 +556,10 @@ public class ExecutionEntity extends VariableScopeImpl implements ActivityExecut
public void setBusinessKey(String businessKey) {
this.businessKey = businessKey;
}
public String getProcessBusinessKey() {
return getProcessInstance().getBusinessKey();
}
// process definition ///////////////////////////////////////////////////////
......
......@@ -325,6 +325,9 @@ public class ExecutionImpl implements
return getProcessInstance().getBusinessKey();
}
public String getProcessBusinessKey() {
return getProcessInstance().getBusinessKey();
}
/** for setting the process instance, this setter must be used as subclasses can override */
public void setProcessInstance(InterpretableExecution processInstance) {
......
......@@ -26,6 +26,6 @@ public class ExampleExecutionListenerOne implements ExecutionListener {
public void notify(DelegateExecution execution) throws Exception {
execution.setVariable("variableSetInExecutionListener", "firstValue");
execution.setVariable("eventNameReceived", execution.getEventName());
execution.setVariable("businessKeyInExecution", execution.getBusinessKey());
execution.setVariable("businessKeyInExecution", execution.getProcessBusinessKey());
}
}
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.activiti.examples.bpmn.servicetask;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.JavaDelegate;
/**
* Delegate that gets the business-key from the delegate-execution and puts the
* value in a variable.
*
* @author Frederik Heremans
*/
public class BusinessKeyCheckJavaDelegate implements JavaDelegate {
public void execute(DelegateExecution execution) throws Exception {
execution.setVariable("businessKeySetOnExecution", execution.getProcessBusinessKey());
}
}
......@@ -110,5 +110,16 @@ public class JavaServiceTaskTest extends PluggableActivitiTestCase {
Task task = taskService.createTaskQuery().singleResult();
assertEquals("Fix Exception", task.getName());
}
@Deployment
public void testGetBusinessKeyFromDelegateExecution() {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("businessKeyProcess", "1234567890");
assertEquals(1, runtimeService.createProcessInstanceQuery().processDefinitionKey("businessKeyProcess").count());
// Check if business-key was available from the process
String key = (String) runtimeService.getVariable(processInstance.getId(), "businessKeySetOnExecution");
assertNotNull(key);
assertEquals("1234567890", key);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<definitions id="definitions"
xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
xmlns:activiti="http://activiti.org/bpmn"
targetNamespace="Examples">
<process id="businessKeyProcess">
<startEvent id="theStart" />
<sequenceFlow id="flow1" sourceRef="theStart" targetRef="fork" />
<parallelGateway id="fork" />
<sequenceFlow sourceRef="fork" targetRef="receivePayment" />
<sequenceFlow sourceRef="fork" targetRef="shipOrder" />
<serviceTask id="receivePayment" name="Receive Payment" activiti:class="org.activiti.examples.bpmn.servicetask.BusinessKeyCheckJavaDelegate"/>
<sequenceFlow sourceRef="receivePayment" targetRef="join" />
<userTask id="shipOrder" name="Ship Order" />
<sequenceFlow sourceRef="shipOrder" targetRef="join" />
<parallelGateway id="join" />
<sequenceFlow sourceRef="join" targetRef="archiveOrder" />
<userTask id="archiveOrder" name="Archive Order" />
<sequenceFlow sourceRef="archiveOrder" targetRef="theEnd" />
<endEvent id="theEnd" />
</process>
</definitions>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册