Search in sources :

Example 1 with ItemInstance

use of org.activiti.engine.impl.bpmn.data.ItemInstance in project Activiti by Activiti.

the class WebServiceUELTest method testWebServiceInvocationWithDataFlowUEL.

@Deployment
public void testWebServiceInvocationWithDataFlowUEL() throws Exception {
    ProcessDefinitionEntity processDefinition = processEngineConfiguration.getCommandExecutor().execute(new Command<ProcessDefinitionEntity>() {

        public ProcessDefinitionEntity execute(CommandContext commandContext) {
            return Context.getProcessEngineConfiguration().getDeploymentManager().findDeployedLatestProcessDefinitionByKey("webServiceInvocationWithDataFlowUEL");
        }
    });
    ItemDefinition itemDefinition = processDefinition.getIoSpecification().getDataInputs().get(0).getDefinition();
    ItemInstance itemInstance = itemDefinition.createInstance();
    FieldBaseStructureInstance structureInstance = (FieldBaseStructureInstance) itemInstance.getStructureInstance();
    structureInstance.setFieldValue("prefix", "The counter has the value ");
    structureInstance.setFieldValue("suffix", ". Good news");
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("dataInputOfProcess", itemInstance);
    ProcessInstance instance = processEngine.getRuntimeService().startProcessInstanceByKey("webServiceInvocationWithDataFlowUEL", variables);
    waitForJobExecutorToProcessAllJobs(10000L, 250L);
    String response = (String) processEngine.getRuntimeService().getVariable(instance.getId(), "dataOutputOfProcess");
    assertEquals("The counter has the value -1. Good news", response);
}
Also used : CommandContext(org.activiti.engine.impl.interceptor.CommandContext) HashMap(java.util.HashMap) ItemDefinition(org.activiti.engine.impl.bpmn.data.ItemDefinition) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity) FieldBaseStructureInstance(org.activiti.engine.impl.bpmn.data.FieldBaseStructureInstance) ItemInstance(org.activiti.engine.impl.bpmn.data.ItemInstance) Deployment(org.activiti.engine.test.Deployment)

Example 2 with ItemInstance

use of org.activiti.engine.impl.bpmn.data.ItemInstance in project Activiti by Activiti.

the class WebServiceUELTest method testAsyncInvocationWithDataFlowUEL.

@Deployment
public void testAsyncInvocationWithDataFlowUEL() throws Exception {
    assertEquals(-1, webServiceMock.getCount());
    ProcessDefinitionEntity processDefinition = processEngineConfiguration.getCommandExecutor().execute(new Command<ProcessDefinitionEntity>() {

        public ProcessDefinitionEntity execute(CommandContext commandContext) {
            return Context.getProcessEngineConfiguration().getDeploymentManager().findDeployedLatestProcessDefinitionByKey("asyncWebServiceInvocationWithDataFlowUEL");
        }
    });
    ItemDefinition itemDefinition = processDefinition.getIoSpecification().getDataInputs().get(0).getDefinition();
    ItemInstance itemInstance = itemDefinition.createInstance();
    FieldBaseStructureInstance structureInstance = (FieldBaseStructureInstance) itemInstance.getStructureInstance();
    structureInstance.setFieldValue("newCounterValue", 23);
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("dataInputOfProcess", itemInstance);
    processEngine.getRuntimeService().startProcessInstanceByKey("asyncWebServiceInvocationWithDataFlowUEL", variables);
    waitForJobExecutorToProcessAllJobs(10000L, 250L);
    assertEquals(23, webServiceMock.getCount());
}
Also used : CommandContext(org.activiti.engine.impl.interceptor.CommandContext) HashMap(java.util.HashMap) ItemDefinition(org.activiti.engine.impl.bpmn.data.ItemDefinition) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity) FieldBaseStructureInstance(org.activiti.engine.impl.bpmn.data.FieldBaseStructureInstance) ItemInstance(org.activiti.engine.impl.bpmn.data.ItemInstance) Deployment(org.activiti.engine.test.Deployment)

Example 3 with ItemInstance

use of org.activiti.engine.impl.bpmn.data.ItemInstance in project Activiti by Activiti.

the class WebServiceActivityBehavior method execute.

/**
   * {@inheritDoc}
   */
public void execute(ActivityExecution execution) throws Exception {
    MessageInstance message;
    try {
        if (ioSpecification != null) {
            this.ioSpecification.initialize(execution);
            ItemInstance inputItem = (ItemInstance) execution.getVariable(this.ioSpecification.getFirstDataInputName());
            message = new MessageInstance(this.operation.getInMessage(), inputItem);
        } else {
            message = this.operation.getInMessage().createInstance();
        }
        execution.setVariable(CURRENT_MESSAGE, message);
        this.fillMessage(message, execution);
        ProcessEngineConfigurationImpl processEngineConfig = Context.getProcessEngineConfiguration();
        MessageInstance receivedMessage = this.operation.sendMessage(message, processEngineConfig.getWsOverridenEndpointAddresses());
        execution.setVariable(CURRENT_MESSAGE, receivedMessage);
        if (ioSpecification != null) {
            String firstDataOutputName = this.ioSpecification.getFirstDataOutputName();
            if (firstDataOutputName != null) {
                ItemInstance outputItem = (ItemInstance) execution.getVariable(firstDataOutputName);
                outputItem.getStructureInstance().loadFrom(receivedMessage.getStructureInstance().toArray());
            }
        }
        this.returnMessage(receivedMessage, 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 {
            throw exc;
        }
    }
}
Also used : MessageInstance(org.activiti.engine.impl.bpmn.webservice.MessageInstance) ProcessEngineConfigurationImpl(org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl) ItemInstance(org.activiti.engine.impl.bpmn.data.ItemInstance) BpmnError(org.activiti.engine.delegate.BpmnError)

Example 4 with ItemInstance

use of org.activiti.engine.impl.bpmn.data.ItemInstance 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)

Aggregations

ItemInstance (org.activiti.engine.impl.bpmn.data.ItemInstance)4 HashMap (java.util.HashMap)2 BpmnError (org.activiti.engine.delegate.BpmnError)2 FieldBaseStructureInstance (org.activiti.engine.impl.bpmn.data.FieldBaseStructureInstance)2 ItemDefinition (org.activiti.engine.impl.bpmn.data.ItemDefinition)2 MessageInstance (org.activiti.engine.impl.bpmn.webservice.MessageInstance)2 ProcessEngineConfigurationImpl (org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl)2 CommandContext (org.activiti.engine.impl.interceptor.CommandContext)2 ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)2 Deployment (org.activiti.engine.test.Deployment)2 BpmnModel (org.activiti.bpmn.model.BpmnModel)1 DataAssociation (org.activiti.bpmn.model.DataAssociation)1 FlowElement (org.activiti.bpmn.model.FlowElement)1 IOSpecification (org.activiti.bpmn.model.IOSpecification)1 SendTask (org.activiti.bpmn.model.SendTask)1 ServiceTask (org.activiti.bpmn.model.ServiceTask)1 ActivitiException (org.activiti.engine.ActivitiException)1 AbstractDataAssociation (org.activiti.engine.impl.bpmn.data.AbstractDataAssociation)1 Operation (org.activiti.engine.impl.bpmn.webservice.Operation)1 WSOperation (org.activiti.engine.impl.webservice.WSOperation)1