Search in sources :

Example 91 with ActivitiException

use of org.activiti.engine.ActivitiException in project Activiti by Activiti.

the class JtaTransactionContext method rollback.

public void rollback() {
    // managed transaction, mark rollback-only if not done so already.
    try {
        Transaction transaction = getTransaction();
        int status = transaction.getStatus();
        if (status != Status.STATUS_NO_TRANSACTION && status != Status.STATUS_ROLLEDBACK) {
            transaction.setRollbackOnly();
        }
    } catch (IllegalStateException e) {
        throw new ActivitiException("Unexpected IllegalStateException while marking transaction rollback only");
    } catch (SystemException e) {
        throw new ActivitiException("SystemException while marking transaction rollback only");
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) Transaction(javax.transaction.Transaction) SystemException(javax.transaction.SystemException)

Example 92 with ActivitiException

use of org.activiti.engine.ActivitiException in project Activiti by Activiti.

the class AbstractSetProcessDefinitionStateCmd method findProcessDefinition.

protected List<ProcessDefinitionEntity> findProcessDefinition(CommandContext commandContext) {
    // we don't need to do an extra database fetch and we can simply return it, wrapped in a list
    if (processDefinitionEntity != null) {
        return singletonList(processDefinitionEntity);
    }
    // Validation of input parameters
    if (processDefinitionId == null && processDefinitionKey == null) {
        throw new ActivitiIllegalArgumentException("Process definition id or key cannot be null");
    }
    List<ProcessDefinitionEntity> processDefinitionEntities = new ArrayList<ProcessDefinitionEntity>();
    ProcessDefinitionEntityManager processDefinitionManager = commandContext.getProcessDefinitionEntityManager();
    if (processDefinitionId != null) {
        ProcessDefinitionEntity processDefinitionEntity = processDefinitionManager.findById(processDefinitionId);
        if (processDefinitionEntity == null) {
            throw new ActivitiObjectNotFoundException("Cannot find process definition for id '" + processDefinitionId + "'", ProcessDefinition.class);
        }
        processDefinitionEntities.add(processDefinitionEntity);
    } else {
        ProcessDefinitionQueryImpl query = new ProcessDefinitionQueryImpl(commandContext).processDefinitionKey(processDefinitionKey);
        if (tenantId == null || ProcessEngineConfiguration.NO_TENANT_ID.equals(tenantId)) {
            query.processDefinitionWithoutTenantId();
        } else {
            query.processDefinitionTenantId(tenantId);
        }
        List<ProcessDefinition> processDefinitions = query.list();
        if (processDefinitions.isEmpty()) {
            throw new ActivitiException("Cannot find process definition for key '" + processDefinitionKey + "'");
        }
        for (ProcessDefinition processDefinition : processDefinitions) {
            processDefinitionEntities.add((ProcessDefinitionEntity) processDefinition);
        }
    }
    return processDefinitionEntities;
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ProcessDefinitionEntityManager(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntityManager) ProcessDefinitionQueryImpl(org.activiti.engine.impl.ProcessDefinitionQueryImpl) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) ArrayList(java.util.ArrayList) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException)

Example 93 with ActivitiException

use of org.activiti.engine.ActivitiException in project Activiti by Activiti.

the class DeleteHistoricProcessInstanceCmd method execute.

public Object execute(CommandContext commandContext) {
    if (processInstanceId == null) {
        throw new ActivitiIllegalArgumentException("processInstanceId is null");
    }
    // Check if process instance is still running
    HistoricProcessInstance instance = commandContext.getHistoricProcessInstanceEntityManager().findById(processInstanceId);
    if (instance == null) {
        throw new ActivitiObjectNotFoundException("No historic process instance found with id: " + processInstanceId, HistoricProcessInstance.class);
    }
    if (instance.getEndTime() == null) {
        throw new ActivitiException("Process instance is still running, cannot delete historic process instance: " + processInstanceId);
    }
    commandContext.getHistoricProcessInstanceEntityManager().delete(processInstanceId);
    return null;
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException)

Example 94 with ActivitiException

use of org.activiti.engine.ActivitiException in project Activiti by Activiti.

the class AbstractSetProcessInstanceStateCmd method execute.

public Void execute(CommandContext commandContext) {
    if (processInstanceId == null) {
        throw new ActivitiIllegalArgumentException("ProcessInstanceId cannot be null.");
    }
    ExecutionEntity executionEntity = commandContext.getExecutionEntityManager().findById(processInstanceId);
    if (executionEntity == null) {
        throw new ActivitiObjectNotFoundException("Cannot find processInstance for id '" + processInstanceId + "'.", Execution.class);
    }
    if (!executionEntity.isProcessInstanceType()) {
        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);
        }
    }
    // All tasks are suspended
    List<TaskEntity> tasks = commandContext.getTaskEntityManager().findTasksByProcessInstanceId(processInstanceId);
    for (TaskEntity taskEntity : tasks) {
        SuspensionStateUtil.setSuspensionState(taskEntity, getNewState());
        commandContext.getTaskEntityManager().update(taskEntity, false);
    }
    // All jobs are suspended
    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);
        }
    }
    return null;
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) TaskEntity(org.activiti.engine.impl.persistence.entity.TaskEntity) SuspendedJobEntity(org.activiti.engine.impl.persistence.entity.SuspendedJobEntity) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) SuspendedJobEntity(org.activiti.engine.impl.persistence.entity.SuspendedJobEntity) JobEntity(org.activiti.engine.impl.persistence.entity.JobEntity) TimerJobEntity(org.activiti.engine.impl.persistence.entity.TimerJobEntity) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) TimerJobEntity(org.activiti.engine.impl.persistence.entity.TimerJobEntity)

Example 95 with ActivitiException

use of org.activiti.engine.ActivitiException in project Activiti by Activiti.

the class EndExecutionOperation method handleProcessInstanceExecution.

protected void handleProcessInstanceExecution(ExecutionEntity processInstanceExecution) {
    ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager();
    // No parent execution == process instance id
    String processInstanceId = processInstanceExecution.getId();
    logger.debug("No parent execution found. Verifying if process instance {} can be stopped.", processInstanceId);
    ExecutionEntity superExecution = processInstanceExecution.getSuperExecution();
    SubProcessActivityBehavior subProcessActivityBehavior = null;
    // copy variables before destroying the ended sub process instance (call activity)
    if (superExecution != null) {
        FlowNode superExecutionElement = (FlowNode) superExecution.getCurrentFlowElement();
        subProcessActivityBehavior = (SubProcessActivityBehavior) superExecutionElement.getBehavior();
        try {
            subProcessActivityBehavior.completing(superExecution, processInstanceExecution);
        } catch (RuntimeException e) {
            logger.error("Error while completing sub process of execution {}", processInstanceExecution, e);
            throw e;
        } catch (Exception e) {
            logger.error("Error while completing sub process of execution {}", processInstanceExecution, e);
            throw new ActivitiException("Error while completing sub process of execution " + processInstanceExecution, e);
        }
    }
    int activeExecutions = getNumberOfActiveChildExecutionsForProcessInstance(executionEntityManager, processInstanceId);
    if (activeExecutions == 0) {
        logger.debug("No active executions found. Ending process instance {} ", processInstanceId);
        // note the use of execution here vs processinstance execution for getting the flowelement
        executionEntityManager.deleteProcessInstanceExecutionEntity(processInstanceId, execution.getCurrentFlowElement() != null ? execution.getCurrentFlowElement().getId() : null, null, false, false);
    } else {
        logger.debug("Active executions found. Process instance {} will not be ended.", processInstanceId);
    }
    Process process = ProcessDefinitionUtil.getProcess(processInstanceExecution.getProcessDefinitionId());
    // Execute execution listeners for process end.
    if (CollectionUtil.isNotEmpty(process.getExecutionListeners())) {
        executeExecutionListeners(process, processInstanceExecution, ExecutionListener.EVENTNAME_END);
    }
    // and trigger execution afterwards if doing a call activity
    if (superExecution != null) {
        superExecution.setSubProcessInstance(null);
        try {
            subProcessActivityBehavior.completed(superExecution);
        } catch (RuntimeException e) {
            logger.error("Error while completing sub process of execution {}", processInstanceExecution, e);
            throw e;
        } catch (Exception e) {
            logger.error("Error while completing sub process of execution {}", processInstanceExecution, e);
            throw new ActivitiException("Error while completing sub process of execution " + processInstanceExecution, e);
        }
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) Process(org.activiti.bpmn.model.Process) SubProcess(org.activiti.bpmn.model.SubProcess) ExecutionEntityManager(org.activiti.engine.impl.persistence.entity.ExecutionEntityManager) ActivitiException(org.activiti.engine.ActivitiException) SubProcessActivityBehavior(org.activiti.engine.impl.delegate.SubProcessActivityBehavior) FlowNode(org.activiti.bpmn.model.FlowNode)

Aggregations

ActivitiException (org.activiti.engine.ActivitiException)289 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)45 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)44 ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)38 IOException (java.io.IOException)35 ArrayList (java.util.ArrayList)25 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)22 ByteArrayOutputStream (java.io.ByteArrayOutputStream)20 FlowElement (org.activiti.bpmn.model.FlowElement)19 CommandContext (org.activiti.engine.impl.interceptor.CommandContext)18 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)17 Expression (org.activiti.engine.delegate.Expression)17 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)17 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)17 ObjectOutputStream (java.io.ObjectOutputStream)15 WorkflowException (org.alfresco.service.cmr.workflow.WorkflowException)15 HashMap (java.util.HashMap)12 ExecutionEntityManager (org.activiti.engine.impl.persistence.entity.ExecutionEntityManager)11 ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)11 InputStream (java.io.InputStream)10