未验证 提交 407f917f 编写于 作者: A Ankur Chauhan 提交者: GitHub

Add extension points allowing execution of legacy Activiti 5 processes (#3740)

* Activiti5 support

* Add new Parameters

* Revert few files

* Code Refactor

* Add General Old Activiti Support Interface

* Refactor code

* Add files

* Refactor code

* Delete unwanted files

* Remove unwanted imports

* Refactor code

* Refactor code

* Review Changes

* Refactor code

* Refactor code

* Review commit

* Review commits

* Review changes

* Minor changes
Co-authored-by: NYour Name <you@example.com>
Co-authored-by: NBassam Al-Sarori <balsarori@gmail.com>
上级 07430980
/*
* Copyright 2010-2020 Alfresco Software, Ltd.
*
* 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;
import org.activiti.bpmn.model.BpmnModel;
public interface ProcessDefinitionHelper {
org.activiti.bpmn.model.Process getProcessDefinitionProcessObject(String processDefinitionId);
BpmnModel getProcessDefinitionBpmnModel(String processDefinitionId);
}
......@@ -66,14 +66,16 @@ public class ExecuteAsyncRunnable implements Runnable {
}
});
}
runInternal();
}
boolean lockNotNeededOrSuccess = lockJobIfNeeded();
if (lockNotNeededOrSuccess) {
executeJob();
unlockJobIfNeeded();
}
protected void runInternal(){
boolean lockNotNeededOrSuccess = lockJobIfNeeded();
if (lockNotNeededOrSuccess) {
executeJob();
unlockJobIfNeeded();
}
}
protected void executeJob() {
......@@ -162,6 +164,7 @@ public class ExecuteAsyncRunnable implements Runnable {
@Override
public Void execute(CommandContext commandContext) {
CommandConfig commandConfig = processEngineConfiguration.getCommandExecutor().getDefaultConfig().transactionRequiresNew();
FailedJobCommandFactory failedJobCommandFactory = commandContext.getFailedJobCommandFactory();
Command<Object> cmd = failedJobCommandFactory.getCommand(job.getId(), exception);
......
......@@ -20,7 +20,6 @@ import org.activiti.engine.ActivitiException;
import org.activiti.engine.delegate.event.ActivitiEvent;
import org.activiti.engine.delegate.event.ActivitiEventListener;
import org.activiti.engine.impl.context.Context;
import org.activiti.engine.impl.interceptor.CommandContext;
import org.activiti.engine.impl.persistence.entity.ExecutionEntity;
/**
......@@ -36,25 +35,27 @@ public class ErrorThrowingEventListener extends BaseDelegateEventListener {
@Override
public void onEvent(ActivitiEvent event) {
if (isValidEvent(event)) {
onEventInternal(event);
}
}
CommandContext commandContext = Context.getCommandContext();
protected void onEventInternal(ActivitiEvent event){
ExecutionEntity execution = null;
if (event.getExecutionId() != null) {
// Get the execution based on the event's execution ID instead
execution = Context.getCommandContext().getExecutionEntityManager().findById(event.getExecutionId());
// Get the execution based on the event's execution ID instead
execution = Context.getCommandContext().getExecutionEntityManager().findById(event.getExecutionId());
}
if (execution == null) {
throw new ActivitiException("No execution context active and event is not related to an execution. No compensation event can be thrown.");
throw new ActivitiException("No execution context active and event is not related to an execution. No compensation event can be thrown.");
}
try {
ErrorPropagation.propagateError(errorCode, execution);
ErrorPropagation.propagateError(errorCode, execution);
} catch (Exception e) {
throw new ActivitiException("Error while propagating error-event", e);
throw new ActivitiException("Error while propagating error-event", e);
}
}
}
public void setErrorCode(String errorCode) {
......
......@@ -62,6 +62,7 @@ import org.activiti.engine.delegate.event.impl.ActivitiEventDispatcherImpl;
import org.activiti.engine.impl.DynamicBpmnServiceImpl;
import org.activiti.engine.impl.HistoryServiceImpl;
import org.activiti.engine.impl.ManagementServiceImpl;
import org.activiti.engine.impl.ProcessDefinitionHelper;
import org.activiti.engine.impl.ProcessEngineImpl;
import org.activiti.engine.impl.RepositoryServiceImpl;
import org.activiti.engine.impl.RuntimeServiceImpl;
......@@ -849,6 +850,7 @@ public abstract class ProcessEngineConfigurationImpl extends ProcessEngineConfig
protected PerformanceSettings performanceSettings = new PerformanceSettings();
protected ProcessDefinitionHelper processDefinitionHelper;
// buildProcessEngine
// ///////////////////////////////////////////////////////
......@@ -3481,13 +3483,12 @@ public ProcessEngineConfigurationImpl getProcessEngineConfiguration() {
}
@Override
public ProcessEngineConfigurationImpl setClock(Clock clock) {
public ProcessEngineConfigurationImpl setClock(Clock clock) {
if (this.clock == null) {
this.clock = clock;
} else {
this.clock.setCurrentCalendar(clock.getCurrentCalendar());
}
return this;
}
......@@ -3694,4 +3695,12 @@ public ProcessEngineConfigurationImpl setClock(Clock clock) {
this.eventSubscriptionPayloadMappingProvider = eventSubscriptionPayloadMappingProvider;
}
public ProcessDefinitionHelper getProcessDefinitionHelper() {
return processDefinitionHelper;
}
public ProcessEngineConfigurationImpl setProcessDefinitionHelper(ProcessDefinitionHelper processDefinitionHelper) {
this.processDefinitionHelper = processDefinitionHelper;
return this;
}
}
......@@ -73,15 +73,19 @@ public abstract class AbstractSetProcessDefinitionStateCmd implements Command<Vo
List<ProcessDefinitionEntity> processDefinitions = findProcessDefinition(commandContext);
if (executionDate != null) { // Process definition state change is delayed
createTimerForDelayedExecution(commandContext, processDefinitions);
} else { // Process definition state is changed now
changeProcessDefinitionState(commandContext, processDefinitions);
}
executeInternal(commandContext,processDefinitions);
return null;
}
protected void executeInternal(CommandContext commandContext,List<ProcessDefinitionEntity> processDefinitions){
if (executionDate != null) { // Process definition state change is delayed
createTimerForDelayedExecution(commandContext, processDefinitions);
} else { // Process definition state is changed now
changeProcessDefinitionState(commandContext, processDefinitions);
}
}
protected List<ProcessDefinitionEntity> findProcessDefinition(CommandContext commandContext) {
// If process definition is already provided (eg. when command is called through the DeployCmd)
......@@ -131,6 +135,11 @@ public abstract class AbstractSetProcessDefinitionStateCmd implements Command<Vo
protected void createTimerForDelayedExecution(CommandContext commandContext, List<ProcessDefinitionEntity> processDefinitions) {
for (ProcessDefinitionEntity processDefinition : processDefinitions) {
createTimerForDelayedExecutionInternal(commandContext,processDefinition);
}
}
protected void createTimerForDelayedExecutionInternal(CommandContext commandContext, ProcessDefinitionEntity processDefinition) {
TimerJobEntity timer = commandContext.getTimerJobEntityManager().create();
timer.setJobType(JobEntity.JOB_TYPE_TIMER);
......@@ -138,18 +147,22 @@ public abstract class AbstractSetProcessDefinitionStateCmd implements Command<Vo
// Inherit tenant identifier (if applicable)
if (processDefinition.getTenantId() != null) {
timer.setTenantId(processDefinition.getTenantId());
timer.setTenantId(processDefinition.getTenantId());
}
timer.setDuedate(executionDate);
timer.setJobHandlerType(getDelayedExecutionJobHandlerType());
timer.setJobHandlerConfiguration(TimerChangeProcessDefinitionSuspensionStateJobHandler.createJobHandlerConfiguration(includeProcessInstances));
commandContext.getJobManager().scheduleTimerJob(timer);
}
}
protected void changeProcessDefinitionState(CommandContext commandContext, List<ProcessDefinitionEntity> processDefinitions) {
for (ProcessDefinitionEntity processDefinition : processDefinitions) {
changeProcessDefinitionStateInternal(commandContext,processDefinition);
}
}
protected void changeProcessDefinitionStateInternal(CommandContext commandContext, ProcessDefinitionEntity processDefinition) {
SuspensionStateUtil.setSuspensionState(processDefinition, getProcessDefinitionSuspensionState());
......@@ -159,24 +172,24 @@ public abstract class AbstractSetProcessDefinitionStateCmd implements Command<Vo
// Suspend process instances (if needed)
if (includeProcessInstances) {
int currentStartIndex = 0;
List<ProcessInstance> processInstances = fetchProcessInstancesPage(commandContext, processDefinition, currentStartIndex);
while (!processInstances.isEmpty()) {
int currentStartIndex = 0;
List<ProcessInstance> processInstances = fetchProcessInstancesPage(commandContext, processDefinition, currentStartIndex);
while (!processInstances.isEmpty()) {
for (ProcessInstance processInstance : processInstances) {
AbstractSetProcessInstanceStateCmd processInstanceCmd = getProcessInstanceChangeStateCmd(processInstance);
processInstanceCmd.execute(commandContext);
}
for (ProcessInstance processInstance : processInstances) {
AbstractSetProcessInstanceStateCmd processInstanceCmd = getProcessInstanceChangeStateCmd(processInstance);
processInstanceCmd.execute(commandContext);
}
// Fetch new batch of process instances
currentStartIndex += processInstances.size();
processInstances = fetchProcessInstancesPage(commandContext, processDefinition, currentStartIndex);
}
// Fetch new batch of process instances
currentStartIndex += processInstances.size();
processInstances = fetchProcessInstancesPage(commandContext, processDefinition, currentStartIndex);
}
}
}
}
protected List<ProcessInstance> fetchProcessInstancesPage(CommandContext commandContext, ProcessDefinition processDefinition, int currentPageStartIndex) {
protected List<ProcessInstance> fetchProcessInstancesPage(CommandContext commandContext, ProcessDefinition processDefinition, int currentPageStartIndex) {
if (SuspensionState.ACTIVE.equals(getProcessDefinitionSuspensionState())) {
return new ProcessInstanceQueryImpl(commandContext).processDefinitionId(processDefinition.getId()).suspended()
......
......@@ -60,45 +60,55 @@ public abstract class AbstractSetProcessInstanceStateCmd implements Command<Void
throw new ActivitiException("Cannot set suspension state for execution '" + processInstanceId + "': not a process instance.");
}
SuspensionStateUtil.setSuspensionState(executionEntity, getNewState());
commandContext.getExecutionEntityManager().update(executionEntity, false);
// All child executions are suspended
Collection<ExecutionEntity> childExecutions = commandContext.getExecutionEntityManager().findChildExecutionsByProcessInstanceId(processInstanceId);
for (ExecutionEntity childExecution : childExecutions) {
if (!childExecution.getId().equals(processInstanceId)) {
SuspensionStateUtil.setSuspensionState(childExecution, getNewState());
commandContext.getExecutionEntityManager().update(childExecution, false);
}
}
executeInternal(commandContext,executionEntity);
// All tasks are suspended
List<TaskEntity> tasks = commandContext.getTaskEntityManager().findTasksByProcessInstanceId(processInstanceId);
for (TaskEntity taskEntity : tasks) {
SuspensionStateUtil.setSuspensionState(taskEntity, getNewState());
commandContext.getTaskEntityManager().update(taskEntity, false);
}
return null;
}
// All jobs are suspended
if (getNewState() == SuspensionState.ACTIVE) {
List<SuspendedJobEntity> suspendedJobs = commandContext.getSuspendedJobEntityManager().findJobsByProcessInstanceId(processInstanceId);
for (SuspendedJobEntity suspendedJob : suspendedJobs) {
commandContext.getJobManager().activateSuspendedJob(suspendedJob);
}
protected void executeInternal(CommandContext commandContext,ExecutionEntity executionEntity){
SuspensionStateUtil.setSuspensionState(executionEntity, getNewState());
commandContext.getExecutionEntityManager().update(executionEntity, false);
} else {
List<TimerJobEntity> timerJobs = commandContext.getTimerJobEntityManager().findJobsByProcessInstanceId(processInstanceId);
for (TimerJobEntity timerJob : timerJobs) {
commandContext.getJobManager().moveJobToSuspendedJob(timerJob);
}
updateChildrenSuspensionState(commandContext);
updateTaskSuspensionState(commandContext);
suspendAllJobs(commandContext);
}
List<JobEntity> jobs = commandContext.getJobEntityManager().findJobsByProcessInstanceId(processInstanceId);
for (JobEntity job : jobs) {
commandContext.getJobManager().moveJobToSuspendedJob(job);
protected void suspendAllJobs(CommandContext commandContext){
if (getNewState() == SuspensionState.ACTIVE) {
List<SuspendedJobEntity> suspendedJobs = commandContext.getSuspendedJobEntityManager().findJobsByProcessInstanceId(processInstanceId);
for (SuspendedJobEntity suspendedJob : suspendedJobs) {
commandContext.getJobManager().activateSuspendedJob(suspendedJob);
}
} else {
List<TimerJobEntity> timerJobs = commandContext.getTimerJobEntityManager().findJobsByProcessInstanceId(processInstanceId);
for (TimerJobEntity timerJob : timerJobs) {
commandContext.getJobManager().moveJobToSuspendedJob(timerJob);
}
List<JobEntity> jobs = commandContext.getJobEntityManager().findJobsByProcessInstanceId(processInstanceId);
for (JobEntity job : jobs) {
commandContext.getJobManager().moveJobToSuspendedJob(job);
}
}
}
}
protected void updateChildrenSuspensionState(CommandContext commandContext){
Collection<ExecutionEntity> childExecutions = commandContext.getExecutionEntityManager().findChildExecutionsByProcessInstanceId(processInstanceId);
for (ExecutionEntity childExecution : childExecutions) {
if (!childExecution.getId().equals(processInstanceId)) {
SuspensionStateUtil.setSuspensionState(childExecution, getNewState());
commandContext.getExecutionEntityManager().update(childExecution, false);
}
}
}
return null;
protected void updateTaskSuspensionState(CommandContext commandContext){
List<TaskEntity> tasks = commandContext.getTaskEntityManager().findTasksByProcessInstanceId(processInstanceId);
for (TaskEntity taskEntity : tasks) {
SuspensionStateUtil.setSuspensionState(taskEntity, getNewState());
commandContext.getTaskEntityManager().update(taskEntity, false);
}
}
protected abstract SuspensionState getNewState();
......
......@@ -89,26 +89,31 @@ public class AddCommentCmd implements Command<Comment> {
processDefinitionId = task.getProcessDefinitionId();
}
String userId = Authentication.getAuthenticatedUserId();
CommentEntity comment = commandContext.getCommentEntityManager().create();
comment.setUserId(userId);
comment.setType((type == null) ? CommentEntity.TYPE_COMMENT : type);
comment.setTime(commandContext.getProcessEngineConfiguration().getClock().getCurrentTime());
comment.setTaskId(taskId);
comment.setProcessInstanceId(processInstanceId);
comment.setAction(Event.ACTION_ADD_COMMENT);
String eventMessage = message.replaceAll("\\s+", " ");
if (eventMessage.length() > 163) {
eventMessage = eventMessage.substring(0, 160) + "...";
}
comment.setMessage(eventMessage);
return executeInternal(commandContext,processDefinitionId);
}
protected Comment executeInternal(CommandContext commandContext,String processDefinitionId){
String userId = Authentication.getAuthenticatedUserId();
CommentEntity comment = commandContext.getCommentEntityManager().create();
comment.setUserId(userId);
comment.setType((type == null) ? CommentEntity.TYPE_COMMENT : type);
comment.setTime(commandContext.getProcessEngineConfiguration().getClock().getCurrentTime());
comment.setTaskId(taskId);
comment.setProcessInstanceId(processInstanceId);
comment.setAction(Event.ACTION_ADD_COMMENT);
String eventMessage = message.replaceAll("\\s+", " ");
if (eventMessage.length() > 163) {
eventMessage = eventMessage.substring(0, 160) + "...";
}
comment.setMessage(eventMessage);
comment.setFullMessage(message);
comment.setFullMessage(message);
commandContext.getCommentEntityManager().insert(comment);
commandContext.getCommentEntityManager().insert(comment);
return comment;
return comment;
}
protected String getSuspendedTaskException() {
......
......@@ -62,9 +62,12 @@ public class AddIdentityLinkForProcessDefinitionCmd implements Command<Void>, Se
throw new ActivitiObjectNotFoundException("Cannot find process definition with id " + processDefinitionId, ProcessDefinition.class);
}
commandContext.getIdentityLinkEntityManager().addIdentityLink(processDefinition, userId, groupId);
executeInternal(commandContext,processDefinition);
return null;
}
protected void executeInternal(CommandContext commandContext,ProcessDefinitionEntity processDefinition) {
commandContext.getIdentityLinkEntityManager().addIdentityLink(processDefinition, userId, groupId);
}
}
......@@ -75,13 +75,14 @@ public class AddIdentityLinkForProcessInstanceCmd implements Command<Void>, Seri
if (processInstance == null) {
throw new ActivitiObjectNotFoundException("Cannot find process instance with id " + processInstanceId, ExecutionEntity.class);
}
IdentityLinkEntityManager identityLinkEntityManager = commandContext.getIdentityLinkEntityManager();
identityLinkEntityManager.addIdentityLink(processInstance, userId, groupId, type);
commandContext.getHistoryManager().createProcessInstanceIdentityLinkComment(processInstanceId, userId, groupId, type, true);
executeInternal(commandContext,processInstance);
return null;
}
protected void executeInternal(CommandContext commandContext,ExecutionEntity processInstance) {
IdentityLinkEntityManager identityLinkEntityManager = commandContext.getIdentityLinkEntityManager();
identityLinkEntityManager.addIdentityLink(processInstance, userId, groupId, type);
commandContext.getHistoryManager().createProcessInstanceIdentityLinkComment(processInstanceId, userId, groupId, type, true);
}
}
......@@ -55,30 +55,33 @@ public class ChangeDeploymentTenantIdCmd implements Command<Void>, Serializable
throw new ActivitiObjectNotFoundException("Could not find deployment with id " + deploymentId, Deployment.class);
}
String oldTenantId = deployment.getTenantId();
deployment.setTenantId(newTenantId);
// Doing process instances, executions and tasks with direct SQL updates
// (otherwise would not be performant)
commandContext.getProcessDefinitionEntityManager().updateProcessDefinitionTenantIdForDeployment(deploymentId, newTenantId);
commandContext.getExecutionEntityManager().updateExecutionTenantIdForDeployment(deploymentId, newTenantId);
commandContext.getTaskEntityManager().updateTaskTenantIdForDeployment(deploymentId, newTenantId);
commandContext.getJobEntityManager().updateJobTenantIdForDeployment(deploymentId, newTenantId);
commandContext.getTimerJobEntityManager().updateJobTenantIdForDeployment(deploymentId, newTenantId);
commandContext.getSuspendedJobEntityManager().updateJobTenantIdForDeployment(deploymentId, newTenantId);
commandContext.getDeadLetterJobEntityManager().updateJobTenantIdForDeployment(deploymentId, newTenantId);
commandContext.getEventSubscriptionEntityManager().updateEventSubscriptionTenantId(oldTenantId, newTenantId);
// Doing process definitions in memory, cause we need to clear the process definition cache
List<ProcessDefinition> processDefinitions = new ProcessDefinitionQueryImpl().deploymentId(deploymentId).list();
for (ProcessDefinition processDefinition : processDefinitions) {
commandContext.getProcessEngineConfiguration().getProcessDefinitionCache().remove(processDefinition.getId());
}
// Clear process definition cache
commandContext.getProcessEngineConfiguration().getProcessDefinitionCache().clear();
executeInternal(commandContext,deployment);
return null;
}
protected void executeInternal(CommandContext commandContext,DeploymentEntity deployment) {
String oldTenantId = deployment.getTenantId();
deployment.setTenantId(newTenantId);
// Doing process instances, executions and tasks with direct SQL updates
// (otherwise would not be performant)
commandContext.getProcessDefinitionEntityManager().updateProcessDefinitionTenantIdForDeployment(deploymentId, newTenantId);
commandContext.getExecutionEntityManager().updateExecutionTenantIdForDeployment(deploymentId, newTenantId);
commandContext.getTaskEntityManager().updateTaskTenantIdForDeployment(deploymentId, newTenantId);
commandContext.getJobEntityManager().updateJobTenantIdForDeployment(deploymentId, newTenantId);
commandContext.getTimerJobEntityManager().updateJobTenantIdForDeployment(deploymentId, newTenantId);
commandContext.getSuspendedJobEntityManager().updateJobTenantIdForDeployment(deploymentId, newTenantId);
commandContext.getDeadLetterJobEntityManager().updateJobTenantIdForDeployment(deploymentId, newTenantId);
commandContext.getEventSubscriptionEntityManager().updateEventSubscriptionTenantId(oldTenantId, newTenantId);
// Doing process definitions in memory, cause we need to clear the process definition cache
List<ProcessDefinition> processDefinitions = new ProcessDefinitionQueryImpl().deploymentId(deploymentId).list();
for (ProcessDefinition processDefinition : processDefinitions) {
commandContext.getProcessEngineConfiguration().getProcessDefinitionCache().remove(processDefinition.getId());
}
// Clear process definition cache
commandContext.getProcessEngineConfiguration().getProcessDefinitionCache().clear();
}
......
......@@ -70,49 +70,53 @@ public class CreateAttachmentCmd implements Command<Attachment> {
verifyExecutionParameters(commandContext);
}
AttachmentEntity attachment = commandContext.getAttachmentEntityManager().create();
attachment.setName(attachmentName);
attachment.setProcessInstanceId(processInstanceId);
attachment.setTaskId(taskId);
attachment.setDescription(attachmentDescription);
attachment.setType(attachmentType);
attachment.setUrl(url);
attachment.setUserId(Authentication.getAuthenticatedUserId());
attachment.setTime(commandContext.getProcessEngineConfiguration().getClock().getCurrentTime());
commandContext.getAttachmentEntityManager().insert(attachment, false);
if (content != null) {
byte[] bytes = IoUtil.readInputStream(content, attachmentName);
ByteArrayEntity byteArray = commandContext.getByteArrayEntityManager().create();
byteArray.setBytes(bytes);
commandContext.getByteArrayEntityManager().insert(byteArray);
attachment.setContentId(byteArray.getId());
attachment.setContent(byteArray);
}
return executeInternal(commandContext);
}
commandContext.getHistoryManager().createAttachmentComment(taskId, processInstanceId, attachmentName, true);
if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
// Forced to fetch the process-instance to associate the right
// process definition
String processDefinitionId = null;
if (attachment.getProcessInstanceId() != null) {
ExecutionEntity process = commandContext.getExecutionEntityManager().findById(processInstanceId);
if (process != null) {
processDefinitionId = process.getProcessDefinitionId();
}
protected Attachment executeInternal(CommandContext commandContext) {
AttachmentEntity attachment = commandContext.getAttachmentEntityManager().create();
attachment.setName(attachmentName);
attachment.setProcessInstanceId(processInstanceId);
attachment.setTaskId(taskId);
attachment.setDescription(attachmentDescription);
attachment.setType(attachmentType);
attachment.setUrl(url);
attachment.setUserId(Authentication.getAuthenticatedUserId());
attachment.setTime(commandContext.getProcessEngineConfiguration().getClock().getCurrentTime());
commandContext.getAttachmentEntityManager().insert(attachment, false);
if (content != null) {
byte[] bytes = IoUtil.readInputStream(content, attachmentName);
ByteArrayEntity byteArray = commandContext.getByteArrayEntityManager().create();
byteArray.setBytes(bytes);
commandContext.getByteArrayEntityManager().insert(byteArray);
attachment.setContentId(byteArray.getId());
attachment.setContent(byteArray);
}
commandContext.getProcessEngineConfiguration().getEventDispatcher()
.dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_CREATED, attachment, processInstanceId, processInstanceId, processDefinitionId));
commandContext.getProcessEngineConfiguration().getEventDispatcher()
.dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_INITIALIZED, attachment, processInstanceId, processInstanceId, processDefinitionId));
}
return attachment;
commandContext.getHistoryManager().createAttachmentComment(taskId, processInstanceId, attachmentName, true);
if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
// Forced to fetch the process-instance to associate the right
// process definition
String processDefinitionId = null;
if (attachment.getProcessInstanceId() != null) {
ExecutionEntity process = commandContext.getExecutionEntityManager().findById(processInstanceId);
if (process != null) {
processDefinitionId = process.getProcessDefinitionId();
}
}
commandContext.getProcessEngineConfiguration().getEventDispatcher()
.dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_CREATED, attachment, processInstanceId, processInstanceId, processDefinitionId));
commandContext.getProcessEngineConfiguration().getEventDispatcher()
.dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_INITIALIZED, attachment, processInstanceId, processInstanceId, processDefinitionId));
}
return attachment;
}
protected TaskEntity verifyTaskParameters(CommandContext commandContext) {
TaskEntity task = commandContext.getTaskEntityManager().findById(taskId);
......
......@@ -50,22 +50,26 @@ public class DeleteAttachmentCmd implements Command<Object>, Serializable {
processDefinitionId = process.getProcessDefinitionId();
}
}
executeInternal(commandContext,attachment,processInstanceId,processDefinitionId);
commandContext.getAttachmentEntityManager().delete(attachment, false);
return null;
}
if (attachment.getContentId() != null) {
commandContext.getByteArrayEntityManager().deleteByteArrayById(attachment.getContentId());
}
protected void executeInternal(CommandContext commandContext,AttachmentEntity attachment,String processInstanceId,String processDefinitionId){
commandContext.getAttachmentEntityManager().delete(attachment, false);
if (attachment.getTaskId() != null) {
commandContext.getHistoryManager().createAttachmentComment(attachment.getTaskId(), attachment.getProcessInstanceId(), attachment.getName(), false);
}
if (attachment.getContentId() != null) {
commandContext.getByteArrayEntityManager().deleteByteArrayById(attachment.getContentId());
}
if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
commandContext.getProcessEngineConfiguration().getEventDispatcher()
.dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_DELETED, attachment, processInstanceId, processInstanceId, processDefinitionId));
}
return null;
if (attachment.getTaskId() != null) {
commandContext.getHistoryManager().createAttachmentComment(attachment.getTaskId(), attachment.getProcessInstanceId(), attachment.getName(), false);
}
if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
commandContext.getProcessEngineConfiguration().getEventDispatcher()
.dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_DELETED, attachment, processInstanceId, processInstanceId, processDefinitionId));
}
}
}
......@@ -52,9 +52,11 @@ public class DeleteHistoricProcessInstanceCmd implements Command<Object>, Serial
throw new ActivitiException("Process instance is still running, cannot delete historic process instance: " + processInstanceId);
}
commandContext.getHistoricProcessInstanceEntityManager().delete(processInstanceId);
executeInternal(commandContext,instance);
return null;
}
protected void executeInternal(CommandContext commandContext,HistoricProcessInstance instance){
commandContext.getHistoricProcessInstanceEntityManager().delete(processInstanceId);
}
}
......@@ -62,10 +62,11 @@ public class DeleteIdentityLinkForProcessDefinitionCmd implements Command<Object
if (processDefinition == null) {
throw new ActivitiObjectNotFoundException("Cannot find process definition with id " + processDefinitionId, ProcessDefinition.class);
}
commandContext.getIdentityLinkEntityManager().deleteIdentityLink(processDefinition, userId, groupId);
executeInternal(commandContext,processDefinition);
return null;
}
protected void executeInternal(CommandContext commandContext,ProcessDefinitionEntity processDefinition) {
commandContext.getIdentityLinkEntityManager().deleteIdentityLink(processDefinition, userId, groupId);
}
}
......@@ -70,10 +70,11 @@ public class DeleteIdentityLinkForProcessInstanceCmd implements Command<Object>,
throw new ActivitiObjectNotFoundException("Cannot find process instance with id " + processInstanceId, ExecutionEntity.class);
}
commandContext.getIdentityLinkEntityManager().deleteIdentityLink(processInstance, userId, groupId, type);
commandContext.getHistoryManager().createProcessInstanceIdentityLinkComment(processInstanceId, userId, groupId, type, false);
executeInternal(commandContext,processInstance);
return null;
}
protected void executeInternal(CommandContext commandContext,ExecutionEntity processInstance) {
commandContext.getIdentityLinkEntityManager().deleteIdentityLink(processInstance, userId, groupId, type);
commandContext.getHistoryManager().createProcessInstanceIdentityLinkComment(processInstanceId, userId, groupId, type, false);
}
}
......@@ -50,9 +50,11 @@ public class DeleteProcessInstanceCmd implements Command<Void>, Serializable {
throw new ActivitiObjectNotFoundException("No process instance found for id '" + processInstanceId + "'", ProcessInstance.class);
}
commandContext.getExecutionEntityManager().deleteProcessInstance(processInstanceEntity.getProcessInstanceId(), deleteReason, false);
executeInternal(commandContext,processInstanceEntity);
return null;
}
protected void executeInternal(CommandContext commandContext,ExecutionEntity processInstanceEntity) {
commandContext.getExecutionEntityManager().deleteProcessInstance(processInstanceEntity.getProcessInstanceId(), deleteReason, false);
}
}
......@@ -60,16 +60,19 @@ public class ExecuteJobCmd implements Command<Object>, Serializable {
log.debug("Executing job {}", job.getId());
}
commandContext.addCloseListener(new FailedJobListener(commandContext.getProcessEngineConfiguration().getCommandExecutor(), job));
executeInternal(commandContext,job);
return null;
}
try {
commandContext.getJobManager().execute(job);
} catch (Throwable exception) {
// Finally, Throw the exception to indicate the ExecuteJobCmd failed
throw new ActivitiException("Job " + jobId + " failed", exception);
}
protected void executeInternal(CommandContext commandContext,Job job) {
commandContext.addCloseListener(new FailedJobListener(commandContext.getProcessEngineConfiguration().getCommandExecutor(), job));
return null;
try {
commandContext.getJobManager().execute(job);
} catch (Throwable exception) {
// Finally, Throw the exception to indicate the ExecuteJobCmd failed
throw new ActivitiException("Job " + jobId + " failed", exception);
}
}
public String getJobId() {
......
......@@ -60,6 +60,7 @@ public class GetDataObjectCmd implements Command<DataObject>, Serializable {
this.withLocalizationFallback = withLocalizationFallback;
}
public DataObject execute(CommandContext commandContext) {
if (executionId == null) {
throw new ActivitiIllegalArgumentException("executionId is null");
......@@ -76,12 +77,7 @@ public class GetDataObjectCmd implements Command<DataObject>, Serializable {
DataObject dataObject = null;
VariableInstance variableEntity = null;
if (isLocal) {
variableEntity = execution.getVariableInstanceLocal(dataObjectName, false);
} else {
variableEntity = execution.getVariableInstance(dataObjectName, false);
}
VariableInstance variableEntity = getVariable(execution,commandContext);
String localizedName = null;
String localizedDescription = null;
......@@ -136,4 +132,14 @@ public class GetDataObjectCmd implements Command<DataObject>, Serializable {
return dataObject;
}
protected VariableInstance getVariable(ExecutionEntity execution,CommandContext commandContext){
VariableInstance variableEntity = null;
if (isLocal) {
variableEntity = execution.getVariableInstanceLocal(dataObjectName, false);
} else {
variableEntity = execution.getVariableInstance(dataObjectName, false);
}
return variableEntity;
}
}
......@@ -77,24 +77,7 @@ public class GetDataObjectsCmd implements Command<Map<String, DataObject>>, Seri
throw new ActivitiObjectNotFoundException("execution " + executionId + " doesn't exist", Execution.class);
}
Map<String, VariableInstance> variables = null;
if (dataObjectNames == null || dataObjectNames.isEmpty()) {
// Fetch all
if (isLocal) {
variables = execution.getVariableInstancesLocal();
} else {
variables = execution.getVariableInstances();
}
} else {
// Fetch specific collection of variables
if (isLocal) {
variables = execution.getVariableInstancesLocal(dataObjectNames, false);
} else {
variables = execution.getVariableInstances(dataObjectNames, false);
}
}
Map<String, VariableInstance> variables = getVariables(execution,commandContext);
Map<String,DataObject> dataObjects = null;
if (variables != null) {
......@@ -156,4 +139,28 @@ public class GetDataObjectsCmd implements Command<Map<String, DataObject>>, Seri
return dataObjects;
}
public Map<String, VariableInstance> getVariables(ExecutionEntity execution,CommandContext commandContext){
Map<String, VariableInstance> variables = null;
if (dataObjectNames == null || dataObjectNames.isEmpty()) {
// Fetch all
if (isLocal) {
variables = execution.getVariableInstancesLocal();
} else {
variables = execution.getVariableInstances();
}
} else {
// Fetch specific collection of variables
if (isLocal) {
variables = execution.getVariableInstancesLocal(dataObjectNames, false);
} else {
variables = execution.getVariableInstances(dataObjectNames, false);
}
}
return variables;
}
}
......@@ -55,15 +55,18 @@ public class GetExecutionVariableCmd implements Command<Object>, Serializable {
if (execution == null) {
throw new ActivitiObjectNotFoundException("execution " + executionId + " doesn't exist", Execution.class);
}
return executeInternal(execution,commandContext);
}
Object value;
protected Object executeInternal(ExecutionEntity execution,CommandContext commandContext){
if (isLocal) {
value = execution.getVariableLocal(variableName, false);
} else {
value = execution.getVariable(variableName, false);
}
Object value;
return value;
if (isLocal) {
value = execution.getVariableLocal(variableName, false);
} else {
value = execution.getVariable(variableName, false);
}
return value;
}
}
......@@ -54,17 +54,22 @@ public class GetExecutionVariableInstanceCmd implements Command<VariableInstance
throw new ActivitiObjectNotFoundException("execution " + executionId + " doesn't exist", Execution.class);
}
VariableInstance variableEntity = getVariable(execution,commandContext);
if (variableEntity != null) {
variableEntity.getValue();
}
return variableEntity;
}
protected VariableInstance getVariable(ExecutionEntity execution,CommandContext commandContext){
VariableInstance variableEntity = null;
if (isLocal) {
variableEntity = execution.getVariableInstanceLocal(variableName, false);
} else {
variableEntity = execution.getVariableInstance(variableName, false);
}
if (variableEntity != null) {
variableEntity.getValue();
}
return variableEntity;
}
}
......@@ -56,6 +56,20 @@ public class GetExecutionVariableInstancesCmd implements Command<Map<String, Var
throw new ActivitiObjectNotFoundException("execution " + executionId + " doesn't exist", Execution.class);
}
Map<String, VariableInstance> variables = getVariable(execution,commandContext);
if (variables != null) {
for (Entry<String, VariableInstance> entry : variables.entrySet()) {
if (entry.getValue() != null) {
entry.getValue().getValue();
}
}
}
return variables;
}
protected Map<String, VariableInstance> getVariable(ExecutionEntity execution,CommandContext commandContext){
Map<String, VariableInstance> variables = null;
if (variableNames == null || variableNames.isEmpty()) {
......@@ -74,15 +88,6 @@ public class GetExecutionVariableInstancesCmd implements Command<Map<String, Var
variables = execution.getVariableInstances(variableNames, false);
}
}
if (variables != null) {
for (Entry<String, VariableInstance> entry : variables.entrySet()) {
if (entry.getValue() != null) {
entry.getValue().getValue();
}
}
}
return variables;
return variables;
}
}
......@@ -57,26 +57,29 @@ public class GetExecutionVariablesCmd implements Command<Map<String, Object>>, S
throw new ActivitiObjectNotFoundException("execution " + executionId + " doesn't exist", Execution.class);
}
if (variableNames == null || variableNames.isEmpty()) {
return getVariable(execution,commandContext);
}
// Fetch all
public Map<String, Object> getVariable(ExecutionEntity execution,CommandContext commandContext){
if (variableNames == null || variableNames.isEmpty()) {
if (isLocal) {
return execution.getVariablesLocal();
} else {
return execution.getVariables();
}
// Fetch all
} else {
if (isLocal) {
return execution.getVariablesLocal();
} else {
return execution.getVariables();
}
// Fetch specific collection of variables
if (isLocal) {
return execution.getVariablesLocal(variableNames, false);
} else {
return execution.getVariables(variableNames, false);
}
} else {
}
// Fetch specific collection of variables
if (isLocal) {
return execution.getVariablesLocal(variableNames, false);
} else {
return execution.getVariables(variableNames, false);
}
}
}
}
}
......@@ -46,16 +46,20 @@ public class GetProcessDefinitionInfoCmd implements Command<ObjectNode>, Seriali
throw new ActivitiIllegalArgumentException("process definition id is null");
}
ObjectNode resultNode = null;
DeploymentManager deploymentManager = commandContext.getProcessEngineConfiguration().getDeploymentManager();
// make sure the process definition is in the cache
ProcessDefinition processDefinition = deploymentManager.findDeployedProcessDefinitionById(processDefinitionId);
ProcessDefinitionInfoCacheObject definitionInfoCacheObject = deploymentManager.getProcessDefinitionInfoCache().get(processDefinitionId);
if (definitionInfoCacheObject != null) {
resultNode = definitionInfoCacheObject.getInfoNode();
}
return resultNode;
return executeInternal(deploymentManager,commandContext,processDefinition);
}
protected ObjectNode executeInternal(DeploymentManager deploymentManager,CommandContext commandContext,ProcessDefinition processDefinition){
ObjectNode resultNode = null;
ProcessDefinitionInfoCacheObject definitionInfoCacheObject = deploymentManager.getProcessDefinitionInfoCache().get(processDefinitionId);
if (definitionInfoCacheObject != null) {
resultNode = definitionInfoCacheObject.getInfoNode();
}
return resultNode;
}
}
......@@ -66,19 +66,23 @@ public class MessageEventReceivedCmd extends NeedsActiveExecutionCmd<Void> {
throw new ActivitiIllegalArgumentException("messageName cannot be null");
}
EventSubscriptionEntityManager eventSubscriptionEntityManager = commandContext.getEventSubscriptionEntityManager();
List<EventSubscriptionEntity> eventSubscriptions = eventSubscriptionEntityManager.
findEventSubscriptionsByNameAndExecution(MessageEventHandler.EVENT_HANDLER_TYPE, messageName, executionId);
executeInternal(commandContext,execution);
return null;
}
if (eventSubscriptions.isEmpty()) {
throw new ActivitiException("Execution with id '" + executionId + "' does not have a subscription to a message event with name '" + messageName + "'");
}
protected void executeInternal(CommandContext commandContext,ExecutionEntity execution){
EventSubscriptionEntityManager eventSubscriptionEntityManager = commandContext.getEventSubscriptionEntityManager();
List<EventSubscriptionEntity> eventSubscriptions = eventSubscriptionEntityManager.
findEventSubscriptionsByNameAndExecution(MessageEventHandler.EVENT_HANDLER_TYPE, messageName, executionId);
// there can be only one:
EventSubscriptionEntity eventSubscriptionEntity = eventSubscriptions.get(0);
eventSubscriptionEntityManager.eventReceived(eventSubscriptionEntity, payload, async);
if (eventSubscriptions.isEmpty()) {
throw new ActivitiException("Execution with id '" + executionId + "' does not have a subscription to a message event with name '" + messageName + "'");
}
// there can be only one:
EventSubscriptionEntity eventSubscriptionEntity = eventSubscriptions.get(0);
eventSubscriptionEntityManager.eventReceived(eventSubscriptionEntity, payload, async);
return null;
}
}
......@@ -50,15 +50,17 @@ public class SaveAttachmentCmd implements Command<Object>, Serializable {
processDefinitionId = process.getProcessDefinitionId();
}
}
executeInternal(commandContext,updateAttachment,processInstanceId,processDefinitionId);
return null;
}
updateAttachment.setName(attachment.getName());
updateAttachment.setDescription(attachment.getDescription());
if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
commandContext.getProcessEngineConfiguration().getEventDispatcher()
.dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_UPDATED, attachment, processInstanceId, processInstanceId, processDefinitionId));
}
protected void executeInternal(CommandContext commandContext, AttachmentEntity updateAttachment,String processInstanceId,String processDefinitionId){
updateAttachment.setName(attachment.getName());
updateAttachment.setDescription(attachment.getDescription());
return null;
if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
commandContext.getProcessEngineConfiguration().getEventDispatcher()
.dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_UPDATED, attachment, processInstanceId, processInstanceId, processDefinitionId));
}
}
}
......@@ -16,9 +16,6 @@
package org.activiti.engine.impl.cmd;
import java.io.Serializable;
import java.util.Date;
import org.activiti.engine.ActivitiIllegalArgumentException;
import org.activiti.engine.delegate.TaskListener;
import org.activiti.engine.delegate.event.ActivitiEventType;
......@@ -32,6 +29,9 @@ import org.activiti.engine.task.Task;
import org.activiti.engine.task.TaskInfo;
import org.apache.commons.lang3.StringUtils;
import java.io.Serializable;
import java.util.Date;
/**
*/
......
......@@ -50,14 +50,17 @@ public class SetDeploymentCategoryCmd implements Command<Void> {
throw new ActivitiObjectNotFoundException("No deployment found for id = '" + deploymentId + "'", Deployment.class);
}
// Update category
deployment.setCategory(category);
executeInternal(commandContext,deployment);
return null;
}
if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_UPDATED, deployment));
}
protected void executeInternal(CommandContext commandContext,DeploymentEntity deployment){
// Update category
deployment.setCategory(category);
return null;
if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_UPDATED, deployment));
}
}
public String getDeploymentId() {
......
......@@ -50,14 +50,17 @@ public class SetDeploymentKeyCmd implements Command<Void> {
throw new ActivitiObjectNotFoundException("No deployment found for id = '" + deploymentId + "'", Deployment.class);
}
// Update category
deployment.setKey(key);
executeInternal(commandContext,deployment);
return null;
}
if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_UPDATED, deployment));
}
protected void executeInternal(CommandContext commandContext,DeploymentEntity deployment){
// Update category
deployment.setKey(key);
return null;
if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_UPDATED, deployment));
}
}
public String getDeploymentId() {
......
......@@ -52,20 +52,24 @@ public class SetProcessDefinitionCategoryCmd implements Command<Void> {
throw new ActivitiObjectNotFoundException("No process definition found for id = '" + processDefinitionId + "'", ProcessDefinition.class);
}
// Update category
processDefinition.setCategory(category);
executeInternal(commandContext,processDefinition);
return null;
}
// Remove process definition from cache, it will be refetched later
DeploymentCache<ProcessDefinitionCacheEntry> processDefinitionCache = commandContext.getProcessEngineConfiguration().getProcessDefinitionCache();
if (processDefinitionCache != null) {
processDefinitionCache.remove(processDefinitionId);
}
protected void executeInternal(CommandContext commandContext,ProcessDefinitionEntity processDefinition){
// Update category
processDefinition.setCategory(category);
if (commandContext.getEventDispatcher().isEnabled()) {
commandContext.getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_UPDATED, processDefinition));
}
// Remove process definition from cache, it will be refetched later
DeploymentCache<ProcessDefinitionCacheEntry> processDefinitionCache = commandContext.getProcessEngineConfiguration().getProcessDefinitionCache();
if (processDefinitionCache != null) {
processDefinitionCache.remove(processDefinitionId);
}
if (commandContext.getEventDispatcher().isEnabled()) {
commandContext.getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_UPDATED, processDefinition));
}
return null;
}
public String getProcessDefinitionId() {
......
......@@ -61,8 +61,11 @@ public class SetProcessInstanceBusinessKeyCmd implements Command<Void>, Serializ
+ processInstance.getProcessInstanceId() + "'. " + "Please invoke the " + getClass().getSimpleName() + " with a root execution id.");
}
executionManager.updateProcessInstanceBusinessKey(processInstance, businessKey);
executeInternal(commandContext,executionManager,processInstance);
return null;
}
protected void executeInternal(CommandContext commandContext,ExecutionEntityManager executionManager,ExecutionEntity processInstance){
executionManager.updateProcessInstanceBusinessKey(processInstance, businessKey);
}
}
......@@ -20,6 +20,7 @@ package org.activiti.engine.impl.context;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.activiti.engine.ActivitiEngineAgenda;
import org.activiti.engine.impl.ProcessDefinitionHelper;
import org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.activiti.engine.impl.cfg.TransactionContext;
import org.activiti.engine.impl.interceptor.CommandContext;
......@@ -38,6 +39,7 @@ public class Context {
protected static ThreadLocal<Stack<ProcessEngineConfigurationImpl>> processEngineConfigurationStackThreadLocal = new ThreadLocal<Stack<ProcessEngineConfigurationImpl>>();
protected static ThreadLocal<Stack<TransactionContext>> transactionContextThreadLocal = new ThreadLocal<Stack<TransactionContext>>();
protected static ThreadLocal<Map<String, ObjectNode>> bpmnOverrideContextThreadLocal = new ThreadLocal<Map<String, ObjectNode>>();
protected static ThreadLocal<ProcessDefinitionHelper> processDefinitionHelperThreadLocal = new ThreadLocal<ProcessDefinitionHelper>();
protected static ResourceBundle.Control resourceBundleControl = new ResourceBundleControl();
......@@ -175,4 +177,17 @@ public class Context {
return super.getCandidateLocales(baseName, locale);
}
}
public static ProcessDefinitionHelper getProcessDefinitionHelper() {
return processDefinitionHelperThreadLocal.get();
}
public static void setProcessDefinitionHelper(ProcessDefinitionHelper processDefinitionHelper) {
processDefinitionHelperThreadLocal.set(processDefinitionHelper);
}
public static void removeProcessDefinitionHelper() {
processDefinitionHelperThreadLocal.remove();
}
}
......@@ -121,49 +121,57 @@ public class DeploymentManager {
ProcessDefinitionCacheEntry cachedProcessDefinition = processDefinitionCache.get(processDefinitionId);
if (cachedProcessDefinition == null) {
CommandContext commandContext = Context.getCommandContext();
DeploymentEntity deployment = deploymentEntityManager.findById(deploymentId);
deployment.setNew(false);
deploy(deployment, null);
cachedProcessDefinition = processDefinitionCache.get(processDefinitionId);
if (cachedProcessDefinition == null) {
throw new ActivitiException("deployment '" + deploymentId + "' didn't put process definition '" + processDefinitionId + "' in the cache");
}
CommandContext commandContext = Context.getCommandContext();
cachedProcessDefinition = resolveProcessDefinitionInternal(commandContext,processDefinition,deploymentId,processDefinitionId);
}
return cachedProcessDefinition;
}
protected ProcessDefinitionCacheEntry resolveProcessDefinitionInternal(CommandContext commandContext,ProcessDefinition processDefinition,String deploymentId, String processDefinitionId){
DeploymentEntity deployment = deploymentEntityManager.findById(deploymentId);
deployment.setNew(false);
deploy(deployment, null);
ProcessDefinitionCacheEntry cachedProcessDefinition = processDefinitionCache.get(processDefinitionId);
if (cachedProcessDefinition == null) {
throw new ActivitiException("deployment '" + deploymentId + "' didn't put process definition '" + processDefinitionId + "' in the cache");
}
return cachedProcessDefinition;
}
public void removeDeployment(String deploymentId, boolean cascade) {
DeploymentEntity deployment = deploymentEntityManager.findById(deploymentId);
if (deployment == null) {
throw new ActivitiObjectNotFoundException("Could not find a deployment with id '" + deploymentId + "'.", DeploymentEntity.class);
}
removeDeploymentInternal(deploymentId,cascade,deployment);
}
// Remove any process definition from the cache
List<ProcessDefinition> processDefinitions = new ProcessDefinitionQueryImpl().deploymentId(deploymentId).list();
ActivitiEventDispatcher eventDispatcher = Context.getProcessEngineConfiguration().getEventDispatcher();
protected void removeDeploymentInternal(String deploymentId, boolean cascade,DeploymentEntity deployment){
// Remove any process definition from the cache
List<ProcessDefinition> processDefinitions = new ProcessDefinitionQueryImpl().deploymentId(deploymentId).list();
ActivitiEventDispatcher eventDispatcher = Context.getProcessEngineConfiguration().getEventDispatcher();
for (ProcessDefinition processDefinition : processDefinitions) {
for (ProcessDefinition processDefinition : processDefinitions) {
// Since all process definitions are deleted by a single query, we should dispatch the events in this loop
if (eventDispatcher.isEnabled()) {
eventDispatcher.dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_DELETED, processDefinition));
// Since all process definitions are deleted by a single query, we should dispatch the events in this loop
if (eventDispatcher.isEnabled()) {
eventDispatcher.dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_DELETED, processDefinition));
}
}
}
// Delete data
deploymentEntityManager.deleteDeployment(deploymentId, cascade);
// Delete data
deploymentEntityManager.deleteDeployment(deploymentId, cascade);
// Since we use a delete by query, delete-events are not automatically dispatched
if (eventDispatcher.isEnabled()) {
eventDispatcher.dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_DELETED, deployment));
}
// Since we use a delete by query, delete-events are not automatically dispatched
if (eventDispatcher.isEnabled()) {
eventDispatcher.dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_DELETED, deployment));
}
for (ProcessDefinition processDefinition : processDefinitions) {
processDefinitionCache.remove(processDefinition.getId());
}
for (ProcessDefinition processDefinition : processDefinitions) {
processDefinitionCache.remove(processDefinition.getId());
}
}
// getters and setters
......
......@@ -91,21 +91,25 @@ public class HistoricTaskInstanceEntityManagerImpl extends AbstractEntityManager
if (getHistoryManager().isHistoryEnabled()) {
HistoricTaskInstanceEntity historicTaskInstance = findById(id);
if (historicTaskInstance != null) {
deleteInternal(id,historicTaskInstance);
}
}
}
protected void deleteInternal(String id,HistoricTaskInstanceEntity historicTaskInstance){
List<HistoricTaskInstanceEntity> subTasks = historicTaskInstanceDataManager.findHistoricTasksByParentTaskId(historicTaskInstance.getId());
for (HistoricTaskInstance subTask: subTasks) {
List<HistoricTaskInstanceEntity> subTasks = historicTaskInstanceDataManager.findHistoricTasksByParentTaskId(historicTaskInstance.getId());
for (HistoricTaskInstance subTask: subTasks) {
delete(subTask.getId());
}
}
getHistoricDetailEntityManager().deleteHistoricDetailsByTaskId(id);
getHistoricVariableInstanceEntityManager().deleteHistoricVariableInstancesByTaskId(id);
getCommentEntityManager().deleteCommentsByTaskId(id);
getAttachmentEntityManager().deleteAttachmentsByTaskId(id);
getHistoricIdentityLinkEntityManager().deleteHistoricIdentityLinksByTaskId(id);
getHistoricDetailEntityManager().deleteHistoricDetailsByTaskId(id);
getHistoricVariableInstanceEntityManager().deleteHistoricVariableInstancesByTaskId(id);
getCommentEntityManager().deleteCommentsByTaskId(id);
getAttachmentEntityManager().deleteAttachmentsByTaskId(id);
getHistoricIdentityLinkEntityManager().deleteHistoricIdentityLinksByTaskId(id);
delete(historicTaskInstance);
}
}
delete(historicTaskInstance);
}
@Override
......
......@@ -19,6 +19,7 @@ package org.activiti.engine.impl.util;
import org.activiti.bpmn.model.BpmnModel;
import org.activiti.bpmn.model.Process;
import org.activiti.engine.ActivitiException;
import org.activiti.engine.impl.ProcessDefinitionHelper;
import org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.activiti.engine.impl.context.Context;
import org.activiti.engine.impl.persistence.deploy.DeploymentManager;
......@@ -54,20 +55,38 @@ public class ProcessDefinitionUtil {
}
}
public static ProcessDefinitionHelper getProcessDefinitionHelper() {
ProcessDefinitionHelper processDefinitionHelper = Context.getProcessDefinitionHelper();
if (processDefinitionHelper == null) {
throw new ActivitiException("ProcessDefinitionHelper is not set for the current context.");
}
return processDefinitionHelper;
}
public static Process getProcess(String processDefinitionId) {
DeploymentManager deploymentManager = Context.getProcessEngineConfiguration().getDeploymentManager();
if (Context.getProcessEngineConfiguration() == null) {
return getProcessDefinitionHelper().getProcessDefinitionProcessObject(processDefinitionId);
// This will check the cache in the findDeployedProcessDefinitionById and resolveProcessDefinition method
ProcessDefinition processDefinitionEntity = deploymentManager.findDeployedProcessDefinitionById(processDefinitionId);
return deploymentManager.resolveProcessDefinition(processDefinitionEntity).getProcess();
} else {
DeploymentManager deploymentManager = Context.getProcessEngineConfiguration().getDeploymentManager();
// This will check the cache in the findDeployedProcessDefinitionById and resolveProcessDefinition method
ProcessDefinition processDefinitionEntity = deploymentManager.findDeployedProcessDefinitionById(processDefinitionId);
return deploymentManager.resolveProcessDefinition(processDefinitionEntity).getProcess();
}
}
public static BpmnModel getBpmnModel(String processDefinitionId) {
DeploymentManager deploymentManager = Context.getProcessEngineConfiguration().getDeploymentManager();
if (Context.getProcessEngineConfiguration() == null) {
return getProcessDefinitionHelper().getProcessDefinitionBpmnModel(processDefinitionId);
} else {
DeploymentManager deploymentManager = Context.getProcessEngineConfiguration().getDeploymentManager();
// This will check the cache in the findDeployedProcessDefinitionById and resolveProcessDefinition method
ProcessDefinition processDefinitionEntity = deploymentManager.findDeployedProcessDefinitionById(processDefinitionId);
return deploymentManager.resolveProcessDefinition(processDefinitionEntity).getBpmnModel();
// This will check the cache in the findDeployedProcessDefinitionById and resolveProcessDefinition method
ProcessDefinition processDefinitionEntity = deploymentManager.findDeployedProcessDefinitionById(processDefinitionId);
return deploymentManager.resolveProcessDefinition(processDefinitionEntity).getBpmnModel();
}
}
public static BpmnModel getBpmnModelFromCache(String processDefinitionId) {
......
......@@ -20,6 +20,4 @@ import org.activiti.engine.api.internal.Internal;
@Internal
public interface DeploymentProperties {
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册