Search in sources :

Example 1 with DataAssociation

use of org.activiti.bpmn.model.DataAssociation 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)

Example 2 with DataAssociation

use of org.activiti.bpmn.model.DataAssociation in project Activiti by Activiti.

the class DataOutputAssociationParser method parseChildElement.

public void parseChildElement(XMLStreamReader xtr, BaseElement parentElement, BpmnModel model) throws Exception {
    if (!(parentElement instanceof Activity)) {
        return;
    }
    DataAssociation dataAssociation = new DataAssociation();
    BpmnXMLUtil.addXMLLocation(dataAssociation, xtr);
    DataAssociationParser.parseDataAssociation(dataAssociation, getElementName(), xtr);
    ((Activity) parentElement).getDataOutputAssociations().add(dataAssociation);
}
Also used : DataAssociation(org.activiti.bpmn.model.DataAssociation) Activity(org.activiti.bpmn.model.Activity)

Example 3 with DataAssociation

use of org.activiti.bpmn.model.DataAssociation in project Activiti by Activiti.

the class DataInputAssociationParser method parseChildElement.

public void parseChildElement(XMLStreamReader xtr, BaseElement parentElement, BpmnModel model) throws Exception {
    if (!(parentElement instanceof Activity)) {
        return;
    }
    DataAssociation dataAssociation = new DataAssociation();
    BpmnXMLUtil.addXMLLocation(dataAssociation, xtr);
    DataAssociationParser.parseDataAssociation(dataAssociation, getElementName(), xtr);
    ((Activity) parentElement).getDataInputAssociations().add(dataAssociation);
}
Also used : DataAssociation(org.activiti.bpmn.model.DataAssociation) Activity(org.activiti.bpmn.model.Activity)

Example 4 with DataAssociation

use of org.activiti.bpmn.model.DataAssociation in project Activiti by Activiti.

the class WebServiceActivityBehavior method execute.

public void execute(DelegateExecution execution) {
    BpmnModel bpmnModel = ProcessDefinitionUtil.getBpmnModel(execution.getProcessDefinitionId());
    FlowElement flowElement = execution.getCurrentFlowElement();
    IOSpecification ioSpecification = null;
    String operationRef = null;
    List<DataAssociation> dataInputAssociations = null;
    List<DataAssociation> dataOutputAssociations = null;
    if (flowElement instanceof SendTask) {
        SendTask sendTask = (SendTask) flowElement;
        ioSpecification = sendTask.getIoSpecification();
        operationRef = sendTask.getOperationRef();
        dataInputAssociations = sendTask.getDataInputAssociations();
        dataOutputAssociations = sendTask.getDataOutputAssociations();
    } else if (flowElement instanceof ServiceTask) {
        ServiceTask serviceTask = (ServiceTask) flowElement;
        ioSpecification = serviceTask.getIoSpecification();
        operationRef = serviceTask.getOperationRef();
        dataInputAssociations = serviceTask.getDataInputAssociations();
        dataOutputAssociations = serviceTask.getDataOutputAssociations();
    } else {
        throw new ActivitiException("Unsupported flow element type " + flowElement);
    }
    MessageInstance message = null;
    fillDefinitionMaps(bpmnModel);
    Operation operation = operationMap.get(operationRef);
    try {
        if (ioSpecification != null) {
            initializeIoSpecification(ioSpecification, execution, bpmnModel);
            if (ioSpecification.getDataInputRefs().size() > 0) {
                String firstDataInputName = ioSpecification.getDataInputRefs().get(0);
                ItemInstance inputItem = (ItemInstance) execution.getVariable(firstDataInputName);
                message = new MessageInstance(operation.getInMessage(), inputItem);
            }
        } else {
            message = operation.getInMessage().createInstance();
        }
        execution.setVariable(CURRENT_MESSAGE, message);
        fillMessage(dataInputAssociations, execution);
        ProcessEngineConfigurationImpl processEngineConfig = Context.getProcessEngineConfiguration();
        MessageInstance receivedMessage = operation.sendMessage(message, processEngineConfig.getWsOverridenEndpointAddresses());
        execution.setVariable(CURRENT_MESSAGE, receivedMessage);
        if (ioSpecification != null && ioSpecification.getDataOutputRefs().size() > 0) {
            String firstDataOutputName = ioSpecification.getDataOutputRefs().get(0);
            if (firstDataOutputName != null) {
                ItemInstance outputItem = (ItemInstance) execution.getVariable(firstDataOutputName);
                outputItem.getStructureInstance().loadFrom(receivedMessage.getStructureInstance().toArray());
            }
        }
        returnMessage(dataOutputAssociations, execution);
        execution.setVariable(CURRENT_MESSAGE, null);
        leave(execution);
    } catch (Exception exc) {
        Throwable cause = exc;
        BpmnError error = null;
        while (cause != null) {
            if (cause instanceof BpmnError) {
                error = (BpmnError) cause;
                break;
            }
            cause = cause.getCause();
        }
        if (error != null) {
            ErrorPropagation.propagateError(error, execution);
        } else if (exc instanceof RuntimeException) {
            throw (RuntimeException) exc;
        }
    }
}
Also used : ServiceTask(org.activiti.bpmn.model.ServiceTask) ActivitiException(org.activiti.engine.ActivitiException) AbstractDataAssociation(org.activiti.engine.impl.bpmn.data.AbstractDataAssociation) DataAssociation(org.activiti.bpmn.model.DataAssociation) Operation(org.activiti.engine.impl.bpmn.webservice.Operation) WSOperation(org.activiti.engine.impl.webservice.WSOperation) ActivitiException(org.activiti.engine.ActivitiException) BpmnModel(org.activiti.bpmn.model.BpmnModel) MessageInstance(org.activiti.engine.impl.bpmn.webservice.MessageInstance) FlowElement(org.activiti.bpmn.model.FlowElement) IOSpecification(org.activiti.bpmn.model.IOSpecification) SendTask(org.activiti.bpmn.model.SendTask) ProcessEngineConfigurationImpl(org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl) ItemInstance(org.activiti.engine.impl.bpmn.data.ItemInstance) BpmnError(org.activiti.engine.delegate.BpmnError)

Example 5 with DataAssociation

use of org.activiti.bpmn.model.DataAssociation in project Activiti by Activiti.

the class ServiceTaskParseHandler method executeParse.

protected void executeParse(BpmnParse bpmnParse, ServiceTask serviceTask) {
    ActivityImpl activity = createActivityOnCurrentScope(bpmnParse, serviceTask, BpmnXMLConstants.ELEMENT_TASK_SERVICE);
    activity.setAsync(serviceTask.isAsynchronous());
    activity.setFailedJobRetryTimeCycleValue(serviceTask.getFailedJobRetryTimeCycleValue());
    activity.setExclusive(!serviceTask.isNotExclusive());
    // Email, Mule and Shell service tasks
    if (StringUtils.isNotEmpty(serviceTask.getType())) {
        if (serviceTask.getType().equalsIgnoreCase("mail")) {
            activity.setActivityBehavior(bpmnParse.getActivityBehaviorFactory().createMailActivityBehavior(serviceTask));
        } else if (serviceTask.getType().equalsIgnoreCase("mule")) {
            activity.setActivityBehavior(bpmnParse.getActivityBehaviorFactory().createMuleActivityBehavior(serviceTask, bpmnParse.getBpmnModel()));
        } else if (serviceTask.getType().equalsIgnoreCase("camel")) {
            activity.setActivityBehavior(bpmnParse.getActivityBehaviorFactory().createCamelActivityBehavior(serviceTask, bpmnParse.getBpmnModel()));
        } else if (serviceTask.getType().equalsIgnoreCase("shell")) {
            activity.setActivityBehavior(bpmnParse.getActivityBehaviorFactory().createShellActivityBehavior(serviceTask));
        } else {
            logger.warn("Invalid service task type: '" + serviceTask.getType() + "' " + " for service task " + serviceTask.getId());
        }
    // activiti:class
    } else if (ImplementationType.IMPLEMENTATION_TYPE_CLASS.equalsIgnoreCase(serviceTask.getImplementationType())) {
        activity.setActivityBehavior(bpmnParse.getActivityBehaviorFactory().createClassDelegateServiceTask(serviceTask));
    // activiti:delegateExpression
    } else if (ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION.equalsIgnoreCase(serviceTask.getImplementationType())) {
        activity.setActivityBehavior(bpmnParse.getActivityBehaviorFactory().createServiceTaskDelegateExpressionActivityBehavior(serviceTask));
    // activiti:expression      
    } else if (ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION.equalsIgnoreCase(serviceTask.getImplementationType())) {
        activity.setActivityBehavior(bpmnParse.getActivityBehaviorFactory().createServiceTaskExpressionActivityBehavior(serviceTask));
    // Webservice   
    } else if (ImplementationType.IMPLEMENTATION_TYPE_WEBSERVICE.equalsIgnoreCase(serviceTask.getImplementationType()) && StringUtils.isNotEmpty(serviceTask.getOperationRef())) {
        if (!bpmnParse.getOperations().containsKey(serviceTask.getOperationRef())) {
            logger.warn(serviceTask.getOperationRef() + " does not exist for service task " + serviceTask.getId());
        } else {
            WebServiceActivityBehavior webServiceActivityBehavior = bpmnParse.getActivityBehaviorFactory().createWebServiceActivityBehavior(serviceTask);
            webServiceActivityBehavior.setOperation(bpmnParse.getOperations().get(serviceTask.getOperationRef()));
            if (serviceTask.getIoSpecification() != null) {
                IOSpecification ioSpecification = createIOSpecification(bpmnParse, serviceTask.getIoSpecification());
                webServiceActivityBehavior.setIoSpecification(ioSpecification);
            }
            for (DataAssociation dataAssociationElement : serviceTask.getDataInputAssociations()) {
                AbstractDataAssociation dataAssociation = createDataInputAssociation(bpmnParse, dataAssociationElement);
                webServiceActivityBehavior.addDataInputAssociation(dataAssociation);
            }
            for (DataAssociation dataAssociationElement : serviceTask.getDataOutputAssociations()) {
                AbstractDataAssociation dataAssociation = createDataOutputAssociation(bpmnParse, dataAssociationElement);
                webServiceActivityBehavior.addDataOutputAssociation(dataAssociation);
            }
            activity.setActivityBehavior(webServiceActivityBehavior);
        }
    } else {
        logger.warn("One of the attributes 'class', 'delegateExpression', 'type', 'operation', or 'expression' is mandatory on serviceTask " + serviceTask.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)

Aggregations

DataAssociation (org.activiti.bpmn.model.DataAssociation)8 AbstractDataAssociation (org.activiti.engine.impl.bpmn.data.AbstractDataAssociation)5 Activity (org.activiti.bpmn.model.Activity)3 FlowElement (org.activiti.bpmn.model.FlowElement)2 ServiceTask (org.activiti.bpmn.model.ServiceTask)2 WebServiceActivityBehavior (org.activiti.engine.impl.bpmn.behavior.WebServiceActivityBehavior)2 IOSpecification (org.activiti.engine.impl.bpmn.data.IOSpecification)2 Operation (org.activiti.engine.impl.bpmn.webservice.Operation)2 ActivityImpl (org.activiti.engine.impl.pvm.process.ActivityImpl)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Artifact (org.activiti.bpmn.model.Artifact)1 Association (org.activiti.bpmn.model.Association)1 BoundaryEvent (org.activiti.bpmn.model.BoundaryEvent)1 BpmnModel (org.activiti.bpmn.model.BpmnModel)1 DataStoreReference (org.activiti.bpmn.model.DataStoreReference)1 FlowNode (org.activiti.bpmn.model.FlowNode)1 GraphicInfo (org.activiti.bpmn.model.GraphicInfo)1 IOSpecification (org.activiti.bpmn.model.IOSpecification)1 MessageFlow (org.activiti.bpmn.model.MessageFlow)1