Search in sources :

Example 46 with CommandContext

use of org.activiti.engine.impl.interceptor.CommandContext in project Activiti by Activiti.

the class BpmnParseTest method testParseDiagramInterchangeElements.

@Deployment
public void testParseDiagramInterchangeElements() {
    // Graphical information is not yet exposed publicly, so we need to do some plumbing
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutor();
    ProcessDefinitionEntity processDefinitionEntity = commandExecutor.execute(new Command<ProcessDefinitionEntity>() {

        public ProcessDefinitionEntity execute(CommandContext commandContext) {
            return Context.getProcessEngineConfiguration().getDeploymentManager().findDeployedLatestProcessDefinitionByKey("myProcess");
        }
    });
    assertNotNull(processDefinitionEntity);
    assertEquals(7, processDefinitionEntity.getActivities().size());
    // Check if diagram has been created based on Diagram Interchange when it's not a headless instance
    List<String> resourceNames = repositoryService.getDeploymentResourceNames(processDefinitionEntity.getDeploymentId());
    assertEquals(2, resourceNames.size());
    for (ActivityImpl activity : processDefinitionEntity.getActivities()) {
        if (activity.getId().equals("theStart")) {
            assertActivityBounds(activity, 70, 255, 30, 30);
        } else if (activity.getId().equals("task1")) {
            assertActivityBounds(activity, 176, 230, 100, 80);
        } else if (activity.getId().equals("gateway1")) {
            assertActivityBounds(activity, 340, 250, 40, 40);
        } else if (activity.getId().equals("task2")) {
            assertActivityBounds(activity, 445, 138, 100, 80);
        } else if (activity.getId().equals("gateway2")) {
            assertActivityBounds(activity, 620, 250, 40, 40);
        } else if (activity.getId().equals("task3")) {
            assertActivityBounds(activity, 453, 304, 100, 80);
        } else if (activity.getId().equals("theEnd")) {
            assertActivityBounds(activity, 713, 256, 28, 28);
        }
        for (PvmTransition sequenceFlow : activity.getOutgoingTransitions()) {
            assertTrue(((TransitionImpl) sequenceFlow).getWaypoints().size() >= 4);
            TransitionImpl transitionImpl = (TransitionImpl) sequenceFlow;
            if (transitionImpl.getId().equals("flowStartToTask1")) {
                assertSequenceFlowWayPoints(transitionImpl, 100, 270, 176, 270);
            } else if (transitionImpl.getId().equals("flowTask1ToGateway1")) {
                assertSequenceFlowWayPoints(transitionImpl, 276, 270, 340, 270);
            } else if (transitionImpl.getId().equals("flowGateway1ToTask2")) {
                assertSequenceFlowWayPoints(transitionImpl, 360, 250, 360, 178, 445, 178);
            } else if (transitionImpl.getId().equals("flowGateway1ToTask3")) {
                assertSequenceFlowWayPoints(transitionImpl, 360, 290, 360, 344, 453, 344);
            } else if (transitionImpl.getId().equals("flowTask2ToGateway2")) {
                assertSequenceFlowWayPoints(transitionImpl, 545, 178, 640, 178, 640, 250);
            } else if (transitionImpl.getId().equals("flowTask3ToGateway2")) {
                assertSequenceFlowWayPoints(transitionImpl, 553, 344, 640, 344, 640, 290);
            } else if (transitionImpl.getId().equals("flowGateway2ToEnd")) {
                assertSequenceFlowWayPoints(transitionImpl, 660, 270, 713, 270);
            }
        }
    }
}
Also used : TransitionImpl(org.activiti.engine.impl.pvm.process.TransitionImpl) CommandContext(org.activiti.engine.impl.interceptor.CommandContext) ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) CommandExecutor(org.activiti.engine.impl.interceptor.CommandExecutor) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity) PvmTransition(org.activiti.engine.impl.pvm.PvmTransition) Deployment(org.activiti.engine.test.Deployment)

Example 47 with CommandContext

use of org.activiti.engine.impl.interceptor.CommandContext in project Activiti by Activiti.

the class JtaTransactionContext method addTransactionListener.

public void addTransactionListener(TransactionState transactionState, final TransactionListener transactionListener) {
    Transaction transaction = getTransaction();
    CommandContext commandContext = Context.getCommandContext();
    try {
        transaction.registerSynchronization(new TransactionStateSynchronization(transactionState, transactionListener, commandContext));
    } catch (IllegalStateException e) {
        throw new ActivitiException("IllegalStateException while registering synchronization ", e);
    } catch (RollbackException e) {
        throw new ActivitiException("RollbackException while registering synchronization ", e);
    } catch (SystemException e) {
        throw new ActivitiException("SystemException while registering synchronization ", e);
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) Transaction(javax.transaction.Transaction) CommandContext(org.activiti.engine.impl.interceptor.CommandContext) SystemException(javax.transaction.SystemException) RollbackException(javax.transaction.RollbackException)

Example 48 with CommandContext

use of org.activiti.engine.impl.interceptor.CommandContext in project Activiti by Activiti.

the class ExecutionEntity method setReplacedBy.

@SuppressWarnings({ "unchecked", "rawtypes" })
public void setReplacedBy(InterpretableExecution replacedBy) {
    this.replacedBy = (ExecutionEntity) replacedBy;
    CommandContext commandContext = Context.getCommandContext();
    DbSqlSession dbSqlSession = commandContext.getDbSqlSession();
    // update the related tasks
    List<TaskEntity> allTasks = new ArrayList<TaskEntity>();
    allTasks.addAll(getTasks());
    List<TaskEntity> cachedTasks = dbSqlSession.findInCache(TaskEntity.class);
    for (TaskEntity cachedTask : cachedTasks) {
        if (cachedTask.getExecutionId().equals(this.getId())) {
            allTasks.add(cachedTask);
        }
    }
    for (TaskEntity task : allTasks) {
        task.setExecutionId(replacedBy.getId());
        task.setExecution(this.replacedBy);
        // update the related local task variables
        List<VariableInstanceEntity> variables = (List) commandContext.getVariableInstanceEntityManager().findVariableInstancesByTaskId(task.getId());
        for (VariableInstanceEntity variable : variables) {
            variable.setExecution(this.replacedBy);
        }
        this.replacedBy.addTask(task);
    }
    // All tasks have been moved to 'replacedBy', safe to clear the list 
    this.tasks.clear();
    tasks = dbSqlSession.findInCache(TaskEntity.class);
    for (TaskEntity task : tasks) {
        if (id.equals(task.getExecutionId())) {
            task.setExecutionId(replacedBy.getId());
        }
    }
    // update the related jobs
    List<JobEntity> jobs = getJobs();
    for (JobEntity job : jobs) {
        job.setExecution((ExecutionEntity) replacedBy);
    }
    // update the related event subscriptions
    List<EventSubscriptionEntity> eventSubscriptions = getEventSubscriptions();
    for (EventSubscriptionEntity subscriptionEntity : eventSubscriptions) {
        subscriptionEntity.setExecution((ExecutionEntity) replacedBy);
    }
    // update the related process variables
    List<VariableInstanceEntity> variables = (List) commandContext.getVariableInstanceEntityManager().findVariableInstancesByExecutionId(id);
    for (VariableInstanceEntity variable : variables) {
        variable.setExecutionId(replacedBy.getId());
    }
    variables = dbSqlSession.findInCache(VariableInstanceEntity.class);
    for (VariableInstanceEntity variable : variables) {
        if (id.equals(variable.getExecutionId())) {
            variable.setExecutionId(replacedBy.getId());
        }
    }
    commandContext.getHistoryManager().recordExecutionReplacedBy(this, replacedBy);
}
Also used : CommandContext(org.activiti.engine.impl.interceptor.CommandContext) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) DbSqlSession(org.activiti.engine.impl.db.DbSqlSession)

Example 49 with CommandContext

use of org.activiti.engine.impl.interceptor.CommandContext in project Activiti by Activiti.

the class ExecutionEntity method getSpecificVariable.

@Override
protected VariableInstanceEntity getSpecificVariable(String variableName) {
    CommandContext commandContext = Context.getCommandContext();
    if (commandContext == null) {
        throw new ActivitiException("lazy loading outside command context");
    }
    VariableInstanceEntity variableInstance = commandContext.getVariableInstanceEntityManager().findVariableInstanceByExecutionAndName(id, variableName);
    return variableInstance;
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) CommandContext(org.activiti.engine.impl.interceptor.CommandContext)

Example 50 with CommandContext

use of org.activiti.engine.impl.interceptor.CommandContext in project Activiti by Activiti.

the class ExecutionEntityManager method deleteProcessInstanceCascade.

private void deleteProcessInstanceCascade(ExecutionEntity execution, String deleteReason, boolean deleteHistory) {
    CommandContext commandContext = Context.getCommandContext();
    ProcessInstanceQueryImpl processInstanceQuery = new ProcessInstanceQueryImpl(commandContext);
    List<ProcessInstance> subProcesses = processInstanceQuery.superProcessInstanceId(execution.getProcessInstanceId()).list();
    for (ProcessInstance subProcess : subProcesses) {
        deleteProcessInstanceCascade((ExecutionEntity) subProcess, deleteReason, deleteHistory);
    }
    commandContext.getTaskEntityManager().deleteTasksByProcessInstanceId(execution.getId(), deleteReason, deleteHistory);
    // fill default reason if none provided
    if (deleteReason == null) {
        deleteReason = "ACTIVITY_DELETED";
    }
    if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled() && execution.isProcessInstanceType()) {
        commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createCancelledEvent(execution.getProcessInstanceId(), execution.getProcessInstanceId(), execution.getProcessDefinitionId(), deleteReason));
    }
    // delete the execution BEFORE we delete the history, otherwise we will produce orphan HistoricVariableInstance instances
    execution.deleteCascade(deleteReason);
    if (deleteHistory) {
        commandContext.getHistoricProcessInstanceEntityManager().deleteHistoricProcessInstanceById(execution.getId());
    }
}
Also used : CommandContext(org.activiti.engine.impl.interceptor.CommandContext) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ProcessInstanceQueryImpl(org.activiti.engine.impl.ProcessInstanceQueryImpl)

Aggregations

CommandContext (org.activiti.engine.impl.interceptor.CommandContext)72 CommandExecutor (org.activiti.engine.impl.interceptor.CommandExecutor)18 DbSqlSession (org.activiti.engine.impl.db.DbSqlSession)13 SignalEventSubscriptionEntity (org.activiti.engine.impl.persistence.entity.SignalEventSubscriptionEntity)8 Date (java.util.Date)7 ActivitiException (org.activiti.engine.ActivitiException)7 CommandConfig (org.activiti.engine.impl.interceptor.CommandConfig)7 EventSubscriptionEntity (org.activiti.engine.impl.persistence.entity.EventSubscriptionEntity)7 ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)7 MessageEventSubscriptionEntity (org.activiti.engine.impl.persistence.entity.MessageEventSubscriptionEntity)6 HashMap (java.util.HashMap)4 TimerEntity (org.activiti.engine.impl.persistence.entity.TimerEntity)4 Job (org.activiti.engine.runtime.Job)4 Deployment (org.activiti.engine.test.Deployment)4 ArrayList (java.util.ArrayList)3 GregorianCalendar (java.util.GregorianCalendar)3 List (java.util.List)3 ExtensionElement (org.activiti.bpmn.model.ExtensionElement)3 DynamicBpmnService (org.activiti.engine.DynamicBpmnService)3 JobEntity (org.activiti.engine.impl.persistence.entity.JobEntity)3