提交 d9ef9db0 编写于 作者: T tombaeyens

ACT-499 added historic activity instance for start- and end-event when history-level is at FULL

上级 04a750d9
......@@ -27,12 +27,6 @@ import org.activiti.engine.impl.util.ClockUtil;
*/
public class ActivityInstanceStartHandler implements ExecutionListener {
protected String activityType;
public ActivityInstanceStartHandler(String activityType) {
this.activityType = activityType;
}
public void notify(ExecutionListenerExecution execution) {
CommandContext commandContext = CommandContext.getCurrent();
IdGenerator idGenerator = commandContext.getProcessEngineConfiguration().getIdGenerator();
......
/* 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.impl.history.handler;
import java.util.Date;
import org.activiti.engine.impl.cfg.IdGenerator;
import org.activiti.engine.impl.history.HistoricActivityInstanceEntity;
import org.activiti.engine.impl.interceptor.CommandContext;
import org.activiti.engine.impl.pvm.delegate.ExecutionListener;
import org.activiti.engine.impl.pvm.delegate.ExecutionListenerExecution;
import org.activiti.engine.impl.runtime.ExecutionEntity;
import org.activiti.engine.impl.util.ClockUtil;
/**
* @author Tom Baeyens
*/
public class AutomaticActivityInstanceHandler implements ExecutionListener {
@Override
public void notify(ExecutionListenerExecution execution) throws Exception {
CommandContext commandContext = CommandContext.getCurrent();
IdGenerator idGenerator = commandContext.getProcessEngineConfiguration().getIdGenerator();
ExecutionEntity executionEntity = (ExecutionEntity) execution;
String processDefinitionId = executionEntity.getProcessDefinitionId();
String processInstanceId = executionEntity.getProcessInstanceId();
String executionId = execution.getId();
HistoricActivityInstanceEntity historicActivityInstance = new HistoricActivityInstanceEntity();
historicActivityInstance.setId(Long.toString(idGenerator.getNextId()));
historicActivityInstance.setProcessDefinitionId(processDefinitionId);
historicActivityInstance.setProcessInstanceId(processInstanceId);
historicActivityInstance.setExecutionId(executionId);
historicActivityInstance.setActivityId(executionEntity.getActivityId());
historicActivityInstance.setActivityName((String) executionEntity.getActivity().getProperty("name"));
historicActivityInstance.setActivityType((String) executionEntity.getActivity().getProperty("type"));
Date now = ClockUtil.getCurrentTime();
historicActivityInstance.setStartTime(now);
historicActivityInstance.setEndTime(now);
historicActivityInstance.setDurationInMillis(0L);
commandContext
.getDbSqlSession()
.insert(historicActivityInstance);
}
}
......@@ -35,14 +35,20 @@ import org.activiti.engine.impl.variable.VariableDeclaration;
*/
public class HistoryParseListener implements BpmnParseListener {
private static final AutomaticActivityInstanceHandler AUTOMATIC_ACTIVITY_INSTANCE_HANDLER = new AutomaticActivityInstanceHandler();
private static final ActivityInstanceEndHandler ACTIVITI_INSTANCE_END_LISTENER = new ActivityInstanceEndHandler();
private static final ActivityInstanceStartHandler ACTIVITY_INSTANCE_START_LISTENER = new ActivityInstanceStartHandler();
// Statically created handlers
protected static final UserTaskAssignmentHandler USER_TASK_ASSIGNMENT_HANDLER = new UserTaskAssignmentHandler();
// The history level set in the Activiti configuration
protected int configurationhistoryLevel;
protected int historyLevel;
public HistoryParseListener(int historyLevel) {
this.configurationhistoryLevel = historyLevel;
this.historyLevel = historyLevel;
}
public void parseProcess(Element processElement, ProcessDefinitionEntity processDefinition) {
......@@ -92,10 +98,16 @@ public class HistoryParseListener implements BpmnParseListener {
addActivityHandlers(subProcessElement, activity);
}
public void parseStartEvent(Element startEventElement, ScopeImpl scope, ActivityImpl startEventActivity) {
public void parseStartEvent(Element startEventElement, ScopeImpl scope, ActivityImpl activity) {
if (determineHistoryLevel(activity) >= ProcessEngineConfigurationImpl.HISTORYLEVEL_FULL) {
activity.addExecutionListener(ExecutionListener.EVENTNAME_END, AUTOMATIC_ACTIVITY_INSTANCE_HANDLER);
}
}
public void parseEndEvent(Element endEventElement, ScopeImpl scope, ActivityImpl activity) {
if (determineHistoryLevel(activity) >= ProcessEngineConfigurationImpl.HISTORYLEVEL_FULL) {
activity.addExecutionListener(ExecutionListener.EVENTNAME_START, AUTOMATIC_ACTIVITY_INSTANCE_HANDLER);
}
}
public void parseParallelGateway(Element parallelGwElement, ScopeImpl scope, ActivityImpl activity) {
......@@ -114,9 +126,8 @@ public class HistoryParseListener implements BpmnParseListener {
protected void addActivityHandlers(Element activityElement, ActivityImpl activity) {
if (activityHistoryEnabled(activity)) {
String activityType = activityElement.getTagName();
activity.addExecutionListener(ExecutionListener.EVENTNAME_START, new ActivityInstanceStartHandler(activityType));
activity.addExecutionListener(ExecutionListener.EVENTNAME_END, new ActivityInstanceEndHandler());
activity.addExecutionListener(ExecutionListener.EVENTNAME_START, ACTIVITY_INSTANCE_START_LISTENER);
activity.addExecutionListener(ExecutionListener.EVENTNAME_END, ACTIVITI_INSTANCE_END_LISTENER);
}
}
......@@ -137,10 +148,10 @@ public class HistoryParseListener implements BpmnParseListener {
if (processDefinition != null) {
Integer processHistoryLevel = ((ProcessDefinitionEntity) processDefinition).getHistoryLevel();
if (processHistoryLevel != null) {
return Math.min(configurationhistoryLevel, ((ProcessDefinitionEntity) scopeElement.getProcessDefinition()).getHistoryLevel());
return Math.min(historyLevel, ((ProcessDefinitionEntity) scopeElement.getProcessDefinition()).getHistoryLevel());
}
}
return configurationhistoryLevel;
return historyLevel;
}
public void parseSendTask(Element sendTaskElement, ScopeImpl scope, ActivityImpl activity) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册