Search in sources :

Example 16 with ActivityImpl

use of org.activiti.engine.impl.pvm.process.ActivityImpl 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)

Example 17 with ActivityImpl

use of org.activiti.engine.impl.pvm.process.ActivityImpl in project Activiti by Activiti.

the class ScopeUtil method findScopeExecutionForScope.

/**
   * returns the top-most execution sitting in an activity part of the scope defined by 'scopeActivitiy'.
   */
public static ExecutionEntity findScopeExecutionForScope(ExecutionEntity execution, PvmScope scopeActivity) {
    if (scopeActivity instanceof PvmProcessDefinition) {
        return execution.getProcessInstance();
    } else {
        ActivityImpl currentActivity = execution.getActivity();
        ExecutionEntity candiadateExecution = null;
        ExecutionEntity originalExecution = execution;
        while (execution != null) {
            currentActivity = execution.getActivity();
            if (scopeActivity.getActivities().contains(currentActivity) || /* does not search rec*/
            scopeActivity.equals(currentActivity)) {
                // found a candidate execution; lets still check whether we find an
                // execution which is also sitting in an activity part of this scope
                // higher up the hierarchy
                candiadateExecution = execution;
            } else if (currentActivity != null && currentActivity.contains((ActivityImpl) scopeActivity)) /*searches rec*/
            {
                // now we're too "high", the candidate execution is the one.
                break;
            }
            execution = execution.getParent();
        }
        // if activity is scope, we need to get the parent at least:
        if (originalExecution == candiadateExecution && originalExecution.getActivity().isScope() && !originalExecution.getActivity().equals(scopeActivity)) {
            candiadateExecution = originalExecution.getParent();
        }
        return candiadateExecution;
    }
}
Also used : ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) PvmProcessDefinition(org.activiti.engine.impl.pvm.PvmProcessDefinition)

Example 18 with ActivityImpl

use of org.activiti.engine.impl.pvm.process.ActivityImpl in project Activiti by Activiti.

the class ManualTaskParseHandler method executeParse.

protected void executeParse(BpmnParse bpmnParse, ManualTask manualTask) {
    ActivityImpl activity = createActivityOnCurrentScope(bpmnParse, manualTask, BpmnXMLConstants.ELEMENT_TASK_MANUAL);
    activity.setActivityBehavior(bpmnParse.getActivityBehaviorFactory().createManualTaskActivityBehavior(manualTask));
    activity.setAsync(manualTask.isAsynchronous());
    activity.setExclusive(!manualTask.isNotExclusive());
}
Also used : ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl)

Example 19 with ActivityImpl

use of org.activiti.engine.impl.pvm.process.ActivityImpl in project Activiti by Activiti.

the class ReceiveTaskParseHandler method executeParse.

protected void executeParse(BpmnParse bpmnParse, ReceiveTask receiveTask) {
    ActivityImpl activity = createActivityOnCurrentScope(bpmnParse, receiveTask, BpmnXMLConstants.ELEMENT_TASK_RECEIVE);
    activity.setActivityBehavior(bpmnParse.getActivityBehaviorFactory().createReceiveTaskActivityBehavior(receiveTask));
    activity.setAsync(receiveTask.isAsynchronous());
    activity.setExclusive(!receiveTask.isNotExclusive());
}
Also used : ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl)

Example 20 with ActivityImpl

use of org.activiti.engine.impl.pvm.process.ActivityImpl in project Activiti by Activiti.

the class SendTaskParseHandler method executeParse.

protected void executeParse(BpmnParse bpmnParse, SendTask sendTask) {
    ActivityImpl activity = createActivityOnCurrentScope(bpmnParse, sendTask, BpmnXMLConstants.ELEMENT_TASK_SEND);
    activity.setAsync(sendTask.isAsynchronous());
    activity.setExclusive(!sendTask.isNotExclusive());
    if (StringUtils.isNotEmpty(sendTask.getType())) {
        if (sendTask.getType().equalsIgnoreCase("mail")) {
            activity.setActivityBehavior(bpmnParse.getActivityBehaviorFactory().createMailActivityBehavior(sendTask));
        } else if (sendTask.getType().equalsIgnoreCase("mule")) {
            activity.setActivityBehavior(bpmnParse.getActivityBehaviorFactory().createMuleActivityBehavior(sendTask, bpmnParse.getBpmnModel()));
        } else if (sendTask.getType().equalsIgnoreCase("camel")) {
            activity.setActivityBehavior(bpmnParse.getActivityBehaviorFactory().createCamelActivityBehavior(sendTask, bpmnParse.getBpmnModel()));
        }
    // for web service
    } else if (ImplementationType.IMPLEMENTATION_TYPE_WEBSERVICE.equalsIgnoreCase(sendTask.getImplementationType()) && StringUtils.isNotEmpty(sendTask.getOperationRef())) {
        if (!bpmnParse.getOperations().containsKey(sendTask.getOperationRef())) {
            logger.warn(sendTask.getOperationRef() + " does not exist for sendTask " + sendTask.getId());
        } else {
            WebServiceActivityBehavior webServiceActivityBehavior = bpmnParse.getActivityBehaviorFactory().createWebServiceActivityBehavior(sendTask);
            Operation operation = bpmnParse.getOperations().get(sendTask.getOperationRef());
            webServiceActivityBehavior.setOperation(operation);
            if (sendTask.getIoSpecification() != null) {
                IOSpecification ioSpecification = createIOSpecification(bpmnParse, sendTask.getIoSpecification());
                webServiceActivityBehavior.setIoSpecification(ioSpecification);
            }
            for (DataAssociation dataAssociationElement : sendTask.getDataInputAssociations()) {
                AbstractDataAssociation dataAssociation = createDataInputAssociation(bpmnParse, dataAssociationElement);
                webServiceActivityBehavior.addDataInputAssociation(dataAssociation);
            }
            for (DataAssociation dataAssociationElement : sendTask.getDataOutputAssociations()) {
                AbstractDataAssociation dataAssociation = createDataOutputAssociation(bpmnParse, dataAssociationElement);
                webServiceActivityBehavior.addDataOutputAssociation(dataAssociation);
            }
            activity.setActivityBehavior(webServiceActivityBehavior);
        }
    } else {
        logger.warn("One of the attributes 'type' or 'operation' is mandatory on sendTask " + sendTask.getId());
    }
}
Also used : AbstractDataAssociation(org.activiti.engine.impl.bpmn.data.AbstractDataAssociation) ActivityImpl(org.activiti.engine.impl.pvm.process.ActivityImpl) DataAssociation(org.activiti.bpmn.model.DataAssociation) AbstractDataAssociation(org.activiti.engine.impl.bpmn.data.AbstractDataAssociation) IOSpecification(org.activiti.engine.impl.bpmn.data.IOSpecification) WebServiceActivityBehavior(org.activiti.engine.impl.bpmn.behavior.WebServiceActivityBehavior) Operation(org.activiti.engine.impl.bpmn.webservice.Operation)

Aggregations

ActivityImpl (org.activiti.engine.impl.pvm.process.ActivityImpl)83 ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)15 ActivitiException (org.activiti.engine.ActivitiException)14 ScopeImpl (org.activiti.engine.impl.pvm.process.ScopeImpl)11 ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)9 BoundaryEvent (org.activiti.bpmn.model.BoundaryEvent)7 PvmTransition (org.activiti.engine.impl.pvm.PvmTransition)7 TransitionImpl (org.activiti.engine.impl.pvm.process.TransitionImpl)7 ActivityExecution (org.activiti.engine.impl.pvm.delegate.ActivityExecution)6 ProcessDefinitionImpl (org.activiti.engine.impl.pvm.process.ProcessDefinitionImpl)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 EventDefinition (org.activiti.bpmn.model.EventDefinition)4 StartEvent (org.activiti.bpmn.model.StartEvent)4 IOSpecification (org.activiti.engine.impl.bpmn.data.IOSpecification)4 ActivityBehavior (org.activiti.engine.impl.pvm.delegate.ActivityBehavior)4 HashMap (java.util.HashMap)3 BpmnModel (org.activiti.bpmn.model.BpmnModel)3 IntermediateCatchEvent (org.activiti.bpmn.model.IntermediateCatchEvent)3 SignalEventDefinition (org.activiti.bpmn.model.SignalEventDefinition)3