提交 199df359 编写于 作者: T tijsrademakers

Merge branch 'ACT-1732' of https://github.com/xuhuisheng/Activiti

......@@ -72,4 +72,10 @@ public interface DelegateExecution extends VariableScope {
* All Activiti services can be accessed through this interface.
*/
EngineServices getEngineServices();
/**
* Update process business key if not null.
* Returns null if not updated
*/
String updateProcessBusinessKey(String bzKey);
}
......@@ -659,4 +659,13 @@ public class HistoryManager extends AbstractManager {
getHistoricIdentityLinkEntityManager().deleteHistoricIdentityLink(id);
}
}
public void updateProcessBusinessKeyInHistory(ExecutionEntity processInstance) {
if(log.isDebugEnabled()) {
log.debug("updateProcessBusinessKeyInHistory : {}", processInstance.getId());
}
HistoricProcessInstanceEntity historicProcessInstance = getDbSqlSession().selectById(HistoricProcessInstanceEntity.class, processInstance.getId());
historicProcessInstance.setBusinessKey(processInstance.getProcessBusinessKey());
getDbSqlSession().update(historicProcessInstance);
}
}
......@@ -1398,4 +1398,13 @@ public class ExecutionEntity extends VariableScopeImpl implements ActivityExecut
public void setQueryVariables(List<VariableInstanceEntity> queryVariables) {
this.queryVariables = queryVariables;
}
public String updateProcessBusinessKey(String bzKey) {
if (isProcessInstanceType() && businessKey == null && bzKey != null) {
setBusinessKey(bzKey);
Context.getCommandContext().getHistoryManager().updateProcessBusinessKeyInHistory(this);
return bzKey;
}
return null;
}
}
......@@ -869,4 +869,8 @@ public class ExecutionImpl implements
public void disposeStartingExecution() {
startingExecution = null;
}
public String updateProcessBusinessKey(String bzKey) {
return getProcessInstance().updateProcessBusinessKey(bzKey);
}
}
/* 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.engine.test.api.runtime;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;
import org.activiti.engine.history.HistoricProcessInstance;
import org.activiti.engine.impl.test.PluggableActivitiTestCase;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.test.Deployment;
public class ProcessInstanceUpdateBusinessKeyTest extends PluggableActivitiTestCase {
@Deployment
public void testProcessInstanceUpdateBusinessKey() {
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
runtimeService.startProcessInstanceByKey(processDefinition.getKey());
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().singleResult();
assertEquals("bzKey", processInstance.getBusinessKey());
HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().singleResult();
assertEquals("bzKey", historicProcessInstance.getBusinessKey());
}
public static class UpdateBusinessKeyExecutionListener implements ExecutionListener {
public void notify(DelegateExecution delegateExecution) {
delegateExecution.updateProcessBusinessKey("bzKey");
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<definitions id="taskListenerExample"
xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:activiti="http://activiti.org/bpmn"
targetNamespace="Examples">
<process id="ProcessInstanceUpdateBusinessKeyTest.testProcessInstanceUpdateBusinessKey" name="Update business key Example">
<extensionElements>
<activiti:executionListener event="start"
class="org.activiti.engine.test.api.runtime.ProcessInstanceUpdateBusinessKeyTest$UpdateBusinessKeyExecutionListener" />
</extensionElements>
<startEvent id="theStart" />
<sequenceFlow id="flow1" sourceRef="theStart" targetRef="task1" />
<userTask id="task1" activiti:assignee="kermit"/>
<sequenceFlow id="flow2" sourceRef="task1" targetRef="task2" />
<userTask id="task2" />
<sequenceFlow id="flow3" sourceRef="task2" targetRef="theEnd" />
<endEvent id="theEnd" />
</process>
</definitions>
......@@ -76,7 +76,8 @@ public class MyProcessInstancesListQuery extends AbstractLazyLoadingQuery {
ProcessDefinition processDefinition = getProcessDefinition(processInstance.getProcessDefinitionId());
String itemName = getProcessDisplayName(processDefinition) + " (" + processInstance.getId() + ")";
String itemName = getProcessDisplayName(processDefinition) + " (" + processInstance.getId() + ")"
+ (processInstance.getBusinessKey() != null? processInstance.getBusinessKey() : "");
item.addItemProperty("name", new ObjectProperty<String>(itemName, String.class));
return item;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册