use of org.activiti.engine.impl.pvm.process.ProcessDefinitionImpl in project Activiti by Activiti.
the class SetProcessDefinitionVersionCmd method execute.
public Void execute(CommandContext commandContext) {
// check that the new process definition is just another version of the same
// process definition that the process instance is using
ExecutionEntityManager executionManager = commandContext.getExecutionEntityManager();
ExecutionEntity processInstance = executionManager.findExecutionById(processInstanceId);
if (processInstance == null) {
throw new ActivitiObjectNotFoundException("No process instance found for id = '" + processInstanceId + "'.", ProcessInstance.class);
} else if (!processInstance.isProcessInstanceType()) {
throw new ActivitiIllegalArgumentException("A process instance id is required, but the provided id " + "'" + processInstanceId + "' " + "points to a child execution of process instance " + "'" + processInstance.getProcessInstanceId() + "'. " + "Please invoke the " + getClass().getSimpleName() + " with a root execution id.");
}
ProcessDefinitionImpl currentProcessDefinitionImpl = processInstance.getProcessDefinition();
DeploymentManager deploymentCache = commandContext.getProcessEngineConfiguration().getDeploymentManager();
ProcessDefinitionEntity currentProcessDefinition;
if (currentProcessDefinitionImpl instanceof ProcessDefinitionEntity) {
currentProcessDefinition = (ProcessDefinitionEntity) currentProcessDefinitionImpl;
} else {
currentProcessDefinition = deploymentCache.findDeployedProcessDefinitionById(currentProcessDefinitionImpl.getId());
}
ProcessDefinitionEntity newProcessDefinition = deploymentCache.findDeployedProcessDefinitionByKeyAndVersion(currentProcessDefinition.getKey(), processDefinitionVersion);
validateAndSwitchVersionOfExecution(commandContext, processInstance, newProcessDefinition);
// switch the historic process instance to the new process definition version
commandContext.getHistoryManager().recordProcessDefinitionChange(processInstanceId, newProcessDefinition.getId());
// switch all sub-executions of the process instance to the new process definition version
List<ExecutionEntity> childExecutions = executionManager.findChildExecutionsByProcessInstanceId(processInstanceId);
for (ExecutionEntity executionEntity : childExecutions) {
validateAndSwitchVersionOfExecution(commandContext, executionEntity, newProcessDefinition);
}
return null;
}
use of org.activiti.engine.impl.pvm.process.ProcessDefinitionImpl in project Activiti by Activiti.
the class AddListenerUserTaskParseHandler method executeParse.
protected void executeParse(BpmnParse bpmnParse, UserTask userTask) {
super.executeParse(bpmnParse, userTask);
ScopeImpl scope = bpmnParse.getCurrentScope();
ProcessDefinitionImpl processDefinition = scope.getProcessDefinition();
ActivityImpl activity = processDefinition.findActivity(userTask.getId());
SimulatorParserUtils.setSimulationBehavior(scope, userTask);
UserTaskActivityBehavior userTaskActivity = (UserTaskActivityBehavior) activity.getActivityBehavior();
userTaskActivity.getTaskDefinition().addTaskListener(eventName, taskListener);
}
use of org.activiti.engine.impl.pvm.process.ProcessDefinitionImpl in project Activiti by Activiti.
the class SimulatorParserUtils method setSimulationBehavior.
static void setSimulationBehavior(ScopeImpl scope, BaseElement baseElement) {
String behaviorClassName = getBehaviorClassName(baseElement);
if (behaviorClassName != null) {
ProcessDefinitionImpl processDefinition = scope.getProcessDefinition();
ActivityImpl activity = processDefinition.findActivity(baseElement.getId());
LOG.debug("Scripting task [" + activity.getId() + "] setting behavior to [" + behaviorClassName + "]");
try {
@SuppressWarnings("unchecked") Class<AbstractSimulationActivityBehavior> behaviorClass = (Class<AbstractSimulationActivityBehavior>) Class.forName(behaviorClassName);
Constructor<AbstractSimulationActivityBehavior> constructor = behaviorClass.getDeclaredConstructor(ScopeImpl.class, ActivityImpl.class);
activity.setActivityBehavior(constructor.newInstance(scope, activity));
} catch (Throwable t) {
LOG.error("unable to set simulation behavior class[" + behaviorClassName + "]", t);
throw new ActivitiException("unable to set simulation behavior class[" + behaviorClassName + "]");
}
}
}
use of org.activiti.engine.impl.pvm.process.ProcessDefinitionImpl in project Activiti by Activiti.
the class AtomicOperationProcessStartInitial method eventNotificationsCompleted.
@Override
protected void eventNotificationsCompleted(InterpretableExecution execution) {
ActivityImpl activity = (ActivityImpl) execution.getActivity();
ProcessDefinitionImpl processDefinition = execution.getProcessDefinition();
StartingExecution startingExecution = execution.getStartingExecution();
if (activity == startingExecution.getInitial()) {
execution.disposeStartingExecution();
execution.performOperation(ACTIVITY_EXECUTE);
} else {
List<ActivityImpl> initialActivityStack = processDefinition.getInitialActivityStack(startingExecution.getInitial());
int index = initialActivityStack.indexOf(activity);
activity = initialActivityStack.get(index + 1);
InterpretableExecution executionToUse = null;
if (activity.isScope()) {
executionToUse = (InterpretableExecution) execution.getExecutions().get(0);
} else {
executionToUse = execution;
}
executionToUse.setActivity(activity);
executionToUse.performOperation(PROCESS_START_INITIAL);
}
}
Aggregations