Search in sources :

Example 16 with ActivitiException

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

the class ProcessEngineConfigurationImpl method getDefaultBpmnParseHandlers.

protected List<BpmnParseHandler> getDefaultBpmnParseHandlers() {
    // Alpabetic list of default parse handler classes
    List<BpmnParseHandler> bpmnParserHandlers = new ArrayList<BpmnParseHandler>();
    bpmnParserHandlers.add(new BoundaryEventParseHandler());
    bpmnParserHandlers.add(new BusinessRuleParseHandler());
    bpmnParserHandlers.add(new CallActivityParseHandler());
    bpmnParserHandlers.add(new CancelEventDefinitionParseHandler());
    bpmnParserHandlers.add(new CompensateEventDefinitionParseHandler());
    bpmnParserHandlers.add(new EndEventParseHandler());
    bpmnParserHandlers.add(new ErrorEventDefinitionParseHandler());
    bpmnParserHandlers.add(new EventBasedGatewayParseHandler());
    bpmnParserHandlers.add(new ExclusiveGatewayParseHandler());
    bpmnParserHandlers.add(new InclusiveGatewayParseHandler());
    bpmnParserHandlers.add(new IntermediateCatchEventParseHandler());
    bpmnParserHandlers.add(new IntermediateThrowEventParseHandler());
    bpmnParserHandlers.add(new ManualTaskParseHandler());
    bpmnParserHandlers.add(new MessageEventDefinitionParseHandler());
    bpmnParserHandlers.add(new ParallelGatewayParseHandler());
    bpmnParserHandlers.add(new ProcessParseHandler());
    bpmnParserHandlers.add(new ReceiveTaskParseHandler());
    bpmnParserHandlers.add(new ScriptTaskParseHandler());
    bpmnParserHandlers.add(new SendTaskParseHandler());
    bpmnParserHandlers.add(new SequenceFlowParseHandler());
    bpmnParserHandlers.add(new ServiceTaskParseHandler());
    bpmnParserHandlers.add(new SignalEventDefinitionParseHandler());
    bpmnParserHandlers.add(new StartEventParseHandler());
    bpmnParserHandlers.add(new SubProcessParseHandler());
    bpmnParserHandlers.add(new EventSubProcessParseHandler());
    bpmnParserHandlers.add(new TaskParseHandler());
    bpmnParserHandlers.add(new TimerEventDefinitionParseHandler());
    bpmnParserHandlers.add(new TransactionParseHandler());
    bpmnParserHandlers.add(new UserTaskParseHandler());
    // Replace any default handler if the user wants to replace them
    if (customDefaultBpmnParseHandlers != null) {
        Map<Class<?>, BpmnParseHandler> customParseHandlerMap = new HashMap<Class<?>, BpmnParseHandler>();
        for (BpmnParseHandler bpmnParseHandler : customDefaultBpmnParseHandlers) {
            for (Class<?> handledType : bpmnParseHandler.getHandledTypes()) {
                customParseHandlerMap.put(handledType, bpmnParseHandler);
            }
        }
        for (int i = 0; i < bpmnParserHandlers.size(); i++) {
            // All the default handlers support only one type
            BpmnParseHandler defaultBpmnParseHandler = bpmnParserHandlers.get(i);
            if (defaultBpmnParseHandler.getHandledTypes().size() != 1) {
                StringBuilder supportedTypes = new StringBuilder();
                for (Class<?> type : defaultBpmnParseHandler.getHandledTypes()) {
                    supportedTypes.append(" ").append(type.getCanonicalName()).append(" ");
                }
                throw new ActivitiException("The default BPMN parse handlers should only support one type, but " + defaultBpmnParseHandler.getClass() + " supports " + supportedTypes.toString() + ". This is likely a programmatic error");
            } else {
                Class<?> handledType = defaultBpmnParseHandler.getHandledTypes().iterator().next();
                if (customParseHandlerMap.containsKey(handledType)) {
                    BpmnParseHandler newBpmnParseHandler = customParseHandlerMap.get(handledType);
                    log.info("Replacing default BpmnParseHandler " + defaultBpmnParseHandler.getClass().getName() + " with " + newBpmnParseHandler.getClass().getName());
                    bpmnParserHandlers.set(i, newBpmnParseHandler);
                }
            }
        }
    }
    // History
    for (BpmnParseHandler handler : getDefaultHistoryParseHandlers()) {
        bpmnParserHandlers.add(handler);
    }
    return bpmnParserHandlers;
}
Also used : UserTaskParseHandler(org.activiti.engine.impl.bpmn.parser.handler.UserTaskParseHandler) ServiceTaskParseHandler(org.activiti.engine.impl.bpmn.parser.handler.ServiceTaskParseHandler) ReceiveTaskParseHandler(org.activiti.engine.impl.bpmn.parser.handler.ReceiveTaskParseHandler) TaskParseHandler(org.activiti.engine.impl.bpmn.parser.handler.TaskParseHandler) SendTaskParseHandler(org.activiti.engine.impl.bpmn.parser.handler.SendTaskParseHandler) ManualTaskParseHandler(org.activiti.engine.impl.bpmn.parser.handler.ManualTaskParseHandler) ScriptTaskParseHandler(org.activiti.engine.impl.bpmn.parser.handler.ScriptTaskParseHandler) ActivitiException(org.activiti.engine.ActivitiException) BusinessRuleParseHandler(org.activiti.engine.impl.bpmn.parser.handler.BusinessRuleParseHandler) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) BoundaryEventParseHandler(org.activiti.engine.impl.bpmn.parser.handler.BoundaryEventParseHandler) InclusiveGatewayParseHandler(org.activiti.engine.impl.bpmn.parser.handler.InclusiveGatewayParseHandler) ArrayList(java.util.ArrayList) SubProcessParseHandler(org.activiti.engine.impl.bpmn.parser.handler.SubProcessParseHandler) EventSubProcessParseHandler(org.activiti.engine.impl.bpmn.parser.handler.EventSubProcessParseHandler) ProcessParseHandler(org.activiti.engine.impl.bpmn.parser.handler.ProcessParseHandler) BpmnParseHandler(org.activiti.engine.parse.BpmnParseHandler) ServiceTaskParseHandler(org.activiti.engine.impl.bpmn.parser.handler.ServiceTaskParseHandler) EventBasedGatewayParseHandler(org.activiti.engine.impl.bpmn.parser.handler.EventBasedGatewayParseHandler) UserTaskParseHandler(org.activiti.engine.impl.bpmn.parser.handler.UserTaskParseHandler) MessageEventDefinitionParseHandler(org.activiti.engine.impl.bpmn.parser.handler.MessageEventDefinitionParseHandler) ScriptTaskParseHandler(org.activiti.engine.impl.bpmn.parser.handler.ScriptTaskParseHandler) SequenceFlowParseHandler(org.activiti.engine.impl.bpmn.parser.handler.SequenceFlowParseHandler) TimerEventDefinitionParseHandler(org.activiti.engine.impl.bpmn.parser.handler.TimerEventDefinitionParseHandler) SendTaskParseHandler(org.activiti.engine.impl.bpmn.parser.handler.SendTaskParseHandler) EventSubProcessParseHandler(org.activiti.engine.impl.bpmn.parser.handler.EventSubProcessParseHandler) EndEventParseHandler(org.activiti.engine.impl.bpmn.parser.handler.EndEventParseHandler) CancelEventDefinitionParseHandler(org.activiti.engine.impl.bpmn.parser.handler.CancelEventDefinitionParseHandler) StartEventParseHandler(org.activiti.engine.impl.bpmn.parser.handler.StartEventParseHandler) ErrorEventDefinitionParseHandler(org.activiti.engine.impl.bpmn.parser.handler.ErrorEventDefinitionParseHandler) SubProcessParseHandler(org.activiti.engine.impl.bpmn.parser.handler.SubProcessParseHandler) EventSubProcessParseHandler(org.activiti.engine.impl.bpmn.parser.handler.EventSubProcessParseHandler) ManualTaskParseHandler(org.activiti.engine.impl.bpmn.parser.handler.ManualTaskParseHandler) CallActivityParseHandler(org.activiti.engine.impl.bpmn.parser.handler.CallActivityParseHandler) ParallelGatewayParseHandler(org.activiti.engine.impl.bpmn.parser.handler.ParallelGatewayParseHandler) IntermediateCatchEventParseHandler(org.activiti.engine.impl.bpmn.parser.handler.IntermediateCatchEventParseHandler) TransactionParseHandler(org.activiti.engine.impl.bpmn.parser.handler.TransactionParseHandler) CompensateEventDefinitionParseHandler(org.activiti.engine.impl.bpmn.parser.handler.CompensateEventDefinitionParseHandler) ExclusiveGatewayParseHandler(org.activiti.engine.impl.bpmn.parser.handler.ExclusiveGatewayParseHandler) ReceiveTaskParseHandler(org.activiti.engine.impl.bpmn.parser.handler.ReceiveTaskParseHandler) IntermediateThrowEventParseHandler(org.activiti.engine.impl.bpmn.parser.handler.IntermediateThrowEventParseHandler) SignalEventDefinitionParseHandler(org.activiti.engine.impl.bpmn.parser.handler.SignalEventDefinitionParseHandler)

Example 17 with ActivitiException

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

the class AbstractActivityBpmnParseHandler method createMultiInstanceLoopCharacteristics.

protected void createMultiInstanceLoopCharacteristics(BpmnParse bpmnParse, Activity modelActivity) {
    MultiInstanceLoopCharacteristics loopCharacteristics = modelActivity.getLoopCharacteristics();
    // Activity Behavior
    MultiInstanceActivityBehavior miActivityBehavior = null;
    ActivityImpl activity = bpmnParse.getCurrentScope().findActivity(modelActivity.getId());
    if (activity == null) {
        throw new ActivitiException("Activity " + modelActivity.getId() + " needed for multi instance cannot bv found");
    }
    if (loopCharacteristics.isSequential()) {
        miActivityBehavior = bpmnParse.getActivityBehaviorFactory().createSequentialMultiInstanceBehavior(activity, (AbstractBpmnActivityBehavior) activity.getActivityBehavior());
    } else {
        miActivityBehavior = bpmnParse.getActivityBehaviorFactory().createParallelMultiInstanceBehavior(activity, (AbstractBpmnActivityBehavior) activity.getActivityBehavior());
    }
    // ActivityImpl settings
    activity.setScope(true);
    activity.setProperty("multiInstance", loopCharacteristics.isSequential() ? "sequential" : "parallel");
    activity.setActivityBehavior(miActivityBehavior);
    ExpressionManager expressionManager = bpmnParse.getExpressionManager();
    BpmnModel bpmnModel = bpmnParse.getBpmnModel();
    // loopcardinality
    if (StringUtils.isNotEmpty(loopCharacteristics.getLoopCardinality())) {
        miActivityBehavior.setLoopCardinalityExpression(expressionManager.createExpression(loopCharacteristics.getLoopCardinality()));
    }
    // completion condition
    if (StringUtils.isNotEmpty(loopCharacteristics.getCompletionCondition())) {
        miActivityBehavior.setCompletionConditionExpression(expressionManager.createExpression(loopCharacteristics.getCompletionCondition()));
    }
    // activiti:collection
    if (StringUtils.isNotEmpty(loopCharacteristics.getInputDataItem())) {
        if (loopCharacteristics.getInputDataItem().contains("{")) {
            miActivityBehavior.setCollectionExpression(expressionManager.createExpression(loopCharacteristics.getInputDataItem()));
        } else {
            miActivityBehavior.setCollectionVariable(loopCharacteristics.getInputDataItem());
        }
    }
    // activiti:elementVariable
    if (StringUtils.isNotEmpty(loopCharacteristics.getElementVariable())) {
        miActivityBehavior.setCollectionElementVariable(loopCharacteristics.getElementVariable());
    }
    // activiti:elementIndexVariable
    if (StringUtils.isNotEmpty(loopCharacteristics.getElementIndexVariable())) {
        miActivityBehavior.setCollectionElementIndexVariable(loopCharacteristics.getElementIndexVariable());
    }
}
Also used : ExpressionManager(org.activiti.engine.impl.el.ExpressionManager) ActivitiException(org.activiti.engine.ActivitiException) ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) MultiInstanceLoopCharacteristics(org.activiti.bpmn.model.MultiInstanceLoopCharacteristics) AbstractBpmnActivityBehavior(org.activiti.engine.impl.bpmn.behavior.AbstractBpmnActivityBehavior) MultiInstanceActivityBehavior(org.activiti.engine.impl.bpmn.behavior.MultiInstanceActivityBehavior) BpmnModel(org.activiti.bpmn.model.BpmnModel)

Example 18 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 19 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 Arrays.asList(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.findProcessDefinitionById(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 20 with ActivitiException

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

the class ErrorPropagation method executeCatch.

private static void executeCatch(String errorHandlerId, ActivityExecution execution, String errorCode) {
    ProcessDefinitionImpl processDefinition = ((ExecutionEntity) execution).getProcessDefinition();
    ActivityImpl errorHandler = processDefinition.findActivity(errorHandlerId);
    if (errorHandler == null) {
        throw new ActivitiException(errorHandlerId + " not found in process definition");
    }
    boolean matchingParentFound = false;
    ActivityExecution leavingExecution = execution;
    ActivityImpl currentActivity = (ActivityImpl) execution.getActivity();
    ScopeImpl catchingScope = errorHandler.getParent();
    if (catchingScope instanceof ActivityImpl) {
        ActivityImpl catchingScopeActivity = (ActivityImpl) catchingScope;
        if (!catchingScopeActivity.isScope()) {
            // event subprocesses
            catchingScope = catchingScopeActivity.getParent();
        }
    }
    if (catchingScope instanceof PvmProcessDefinition) {
        executeEventHandler(errorHandler, ((ExecutionEntity) execution).getProcessInstance(), errorCode);
    } else {
        if (currentActivity.getId().equals(catchingScope.getId())) {
            matchingParentFound = true;
        } else {
            currentActivity = (ActivityImpl) currentActivity.getParent();
            // and matches the activity the boundary event is defined on
            while (!matchingParentFound && leavingExecution != null && currentActivity != null) {
                if (!leavingExecution.isConcurrent() && currentActivity.getId().equals(catchingScope.getId())) {
                    matchingParentFound = true;
                } else if (leavingExecution.isConcurrent()) {
                    leavingExecution = leavingExecution.getParent();
                } else {
                    currentActivity = currentActivity.getParentActivity();
                    leavingExecution = leavingExecution.getParent();
                }
            }
            // Follow parents up until matching scope can't be found anymore (needed to support for multi-instance)
            while (leavingExecution != null && leavingExecution.getParent() != null && leavingExecution.getParent().getActivity() != null && leavingExecution.getParent().getActivity().getId().equals(catchingScope.getId())) {
                leavingExecution = leavingExecution.getParent();
            }
        }
        if (matchingParentFound && leavingExecution != null) {
            executeEventHandler(errorHandler, leavingExecution, errorCode);
        } else {
            throw new ActivitiException("No matching parent execution for activity " + errorHandlerId + " found");
        }
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ProcessDefinitionImpl(org.activiti.engine.impl.pvm.process.ProcessDefinitionImpl) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) PvmProcessDefinition(org.activiti.engine.impl.pvm.PvmProcessDefinition) ActivityExecution(org.activiti.engine.impl.pvm.delegate.ActivityExecution) ScopeImpl(org.activiti.engine.impl.pvm.process.ScopeImpl)

Aggregations

ActivitiException (org.activiti.engine.ActivitiException)247 Deployment (org.activiti.engine.test.Deployment)38 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)36 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)35 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)31 IOException (java.io.IOException)28 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)23 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)21 ArrayList (java.util.ArrayList)20 TaskQuery (org.activiti.engine.task.TaskQuery)16 HashMap (java.util.HashMap)14 ActivityImpl (org.activiti.engine.impl.pvm.process.ActivityImpl)14 Task (org.activiti.engine.task.Task)14 ByteArrayOutputStream (java.io.ByteArrayOutputStream)13 ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)12 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)10 ObjectOutputStream (java.io.ObjectOutputStream)10 Date (java.util.Date)10 RestVariable (org.activiti.rest.service.api.engine.variable.RestVariable)10 JobExecutor (org.activiti.engine.impl.jobexecutor.JobExecutor)9