Java Code Examples for org.activiti.bpmn.model.ServiceTask#setImplementation()
The following examples show how to use
org.activiti.bpmn.model.ServiceTask#setImplementation() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ActivitiDelegateTest.java From herd with Apache License 2.0 | 6 votes |
/** * This method tests the scenario when an workflow related error is throws while workflow is executing an Async type task like Timer. This error is logged * as WARN. */ @Test(expected = ActivitiException.class) public void testActivitiUnReportableError() throws Exception { BpmnModel bpmnModel = getBpmnModelForXmlResource(ACTIVITI_XML_HERD_TIMER_WITH_CLASSPATH); ServiceTask serviceTask = (ServiceTask) bpmnModel.getProcesses().get(0).getFlowElement("servicetask1"); serviceTask.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION); serviceTask.setImplementation("${BeanNotAvailable}"); jobDefinitionServiceTestHelper.createJobDefinitionForActivitiXml(getActivitiXmlFromBpmnModel(bpmnModel)); Job job = jobService.createAndStartJob(jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME, null)); org.activiti.engine.runtime.Job timer = activitiManagementService.createJobQuery().processInstanceId(job.getId()).timers().singleResult(); if (timer != null) { executeWithoutLogging(TimerExecuteNestedActivityJobHandler.class, () -> { activitiManagementService.executeJob(timer.getId()); }); } }
Example 2
Source File: ActivitiDelegateTest.java From herd with Apache License 2.0 | 6 votes |
/** * This method tests the scenario where a java delegate is not populated again with spring beans. */ @Test public void testDelegateSpringBeansNotPopulatedAgain() throws Exception { BpmnModel bpmnModel = getBpmnModelForXmlResource(ACTIVITI_XML_HERD_WORKFLOW); ServiceTask serviceTask = (ServiceTask) bpmnModel.getProcesses().get(0).getFlowElement("servicetask1"); serviceTask.setImplementation(MockJavaDelegate.class.getCanonicalName()); serviceTask.getFieldExtensions().clear(); // Define the job definition jobDefinitionServiceTestHelper.createJobDefinitionForActivitiXml(getActivitiXmlFromBpmnModel(bpmnModel)); // Executing the job twice so that the same JavaDelegate object is used and spring beans are not wired again. jobService.createAndStartJob(jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME)); jobService.createAndStartJob(jobServiceTestHelper.createJobCreateRequest(TEST_ACTIVITI_NAMESPACE_CD, TEST_ACTIVITI_JOB_NAME)); }
Example 3
Source File: ActivitiDelegateTest.java From herd with Apache License 2.0 | 6 votes |
/** * This method tests the scenario where a RuntimeException occurs but not thrown by java delegate. */ @Test public void testDelegateRuntimeError() throws Exception { BpmnModel bpmnModel = getBpmnModelForXmlResource(ACTIVITI_XML_HERD_WORKFLOW); ServiceTask serviceTask = (ServiceTask) bpmnModel.getProcesses().get(0).getFlowElement("servicetask1"); serviceTask.setImplementation(MockJavaDelegate.class.getCanonicalName()); FieldExtension exceptionField = new FieldExtension(); exceptionField.setFieldName("exceptionToThrow"); exceptionField.setExpression("${exceptionToThrow}"); serviceTask.getFieldExtensions().clear(); serviceTask.getFieldExtensions().add(exceptionField); List<Parameter> parameters = new ArrayList<>(); Parameter parameter = new Parameter("exceptionToThrow", MockJavaDelegate.EXCEPTION_RUNTIME); parameters.add(parameter); executeWithoutLogging(Arrays.asList(ActivitiRuntimeHelper.class, BaseJavaDelegate.class), () -> { jobServiceTestHelper.createJobFromActivitiXml(getActivitiXmlFromBpmnModel(bpmnModel), parameters); }); }
Example 4
Source File: ActivitiDelegateTest.java From herd with Apache License 2.0 | 6 votes |
/** * This method tests when wrong class name is used in service task, the process instance is created. */ @Test public void testDelegateWrongClass() throws Exception { BpmnModel bpmnModel = getBpmnModelForXmlResource(ACTIVITI_XML_HERD_WORKFLOW); ServiceTask serviceTask = (ServiceTask) bpmnModel.getProcesses().get(0).getFlowElement("servicetask1"); serviceTask.setImplementation("ClassDoesNotExist"); serviceTask.getFieldExtensions().clear(); // Run a job with Activiti XML that will start cluster. try { jobServiceTestHelper.createJobFromActivitiXml(getActivitiXmlFromBpmnModel(bpmnModel), null); fail(); } catch (Exception e) { assertEquals(ActivitiException.class, e.getClass()); assertEquals("couldn't instantiate class ClassDoesNotExist", e.getMessage()); } }
Example 5
Source File: ServiceTaskXMLConverter.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
@Override protected BaseElement convertXMLToElement(XMLStreamReader xtr, BpmnModel model) throws Exception { ServiceTask serviceTask = new ServiceTask(); BpmnXMLUtil.addXMLLocation(serviceTask, xtr); if (StringUtils.isNotEmpty(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, ATTRIBUTE_TASK_SERVICE_CLASS))) { serviceTask.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_CLASS); serviceTask.setImplementation(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, ATTRIBUTE_TASK_SERVICE_CLASS)); } else if (StringUtils.isNotEmpty(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, ATTRIBUTE_TASK_SERVICE_EXPRESSION))) { serviceTask.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION); serviceTask.setImplementation(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, ATTRIBUTE_TASK_SERVICE_EXPRESSION)); } else if (StringUtils.isNotEmpty(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, ATTRIBUTE_TASK_SERVICE_DELEGATEEXPRESSION))) { serviceTask.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION); serviceTask.setImplementation(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, ATTRIBUTE_TASK_SERVICE_DELEGATEEXPRESSION)); } else if ("##WebService".equals(xtr.getAttributeValue(null, ATTRIBUTE_TASK_IMPLEMENTATION))) { serviceTask.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_WEBSERVICE); serviceTask.setOperationRef(parseOperationRef(xtr.getAttributeValue(null, ATTRIBUTE_TASK_OPERATION_REF), model)); } serviceTask.setResultVariableName(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, ATTRIBUTE_TASK_SERVICE_RESULTVARIABLE)); if (StringUtils.isEmpty(serviceTask.getResultVariableName())) { serviceTask.setResultVariableName(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, "resultVariable")); } serviceTask.setType(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, ATTRIBUTE_TYPE)); serviceTask.setExtensionId(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, ATTRIBUTE_TASK_SERVICE_EXTENSIONID)); if (StringUtils.isNotEmpty(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, ATTRIBUTE_TASK_SERVICE_SKIP_EXPRESSION))) { serviceTask.setSkipExpression(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, ATTRIBUTE_TASK_SERVICE_SKIP_EXPRESSION)); } parseChildElements(getXMLElementName(), serviceTask, model, xtr); return serviceTask; }
Example 6
Source File: HerdActivitiServiceTaskTest.java From herd with Apache License 2.0 | 5 votes |
protected String buildActivitiXml(String implementation, List<FieldExtension> fieldExtensionList) throws Exception { BpmnModel bpmnModel = getBpmnModelForXmlResource(ACTIVITI_XML_TEST_SERVICE_TASK_WITH_CLASSPATH); ServiceTask serviceTask = (ServiceTask) bpmnModel.getProcesses().get(0).getFlowElement(serviceTaskId); serviceTask.setImplementation(implementation); serviceTask.getFieldExtensions().addAll(fieldExtensionList); return getActivitiXmlFromBpmnModel(bpmnModel); }
Example 7
Source File: AddEmrStepsTest.java From herd with Apache License 2.0 | 5 votes |
private String buildActivitiXml(String implementation, List<FieldExtension> fieldExtensionList) throws Exception { BpmnModel bpmnModel = getBpmnModelForXmlResource(ACTIVITI_XML_ADD_EMR_STEPS_WITH_CLASSPATH); ServiceTask serviceTask = (ServiceTask) bpmnModel.getProcesses().get(0).getFlowElement("addStepServiceTask"); serviceTask.setImplementation(implementation); serviceTask.getFieldExtensions().addAll(fieldExtensionList); return getActivitiXmlFromBpmnModel(bpmnModel); }
Example 8
Source File: ServiceTaskJsonConverter.java From activiti6-boot2 with Apache License 2.0 | 4 votes |
protected FlowElement convertJsonToElement(JsonNode elementNode, JsonNode modelNode, Map<String, JsonNode> shapeMap) { ServiceTask task = new ServiceTask(); if (StringUtils.isNotEmpty(getPropertyValueAsString(PROPERTY_SERVICETASK_CLASS, elementNode))) { task.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_CLASS); task.setImplementation(getPropertyValueAsString(PROPERTY_SERVICETASK_CLASS, elementNode)); } else if (StringUtils.isNotEmpty(getPropertyValueAsString(PROPERTY_SERVICETASK_EXPRESSION, elementNode))) { task.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION); task.setImplementation(getPropertyValueAsString(PROPERTY_SERVICETASK_EXPRESSION, elementNode)); } else if (StringUtils.isNotEmpty(getPropertyValueAsString(PROPERTY_SERVICETASK_DELEGATE_EXPRESSION, elementNode))) { task.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION); task.setImplementation(getPropertyValueAsString(PROPERTY_SERVICETASK_DELEGATE_EXPRESSION, elementNode)); } if (StringUtils.isNotEmpty(getPropertyValueAsString(PROPERTY_SERVICETASK_RESULT_VARIABLE, elementNode))) { task.setResultVariableName(getPropertyValueAsString(PROPERTY_SERVICETASK_RESULT_VARIABLE, elementNode)); } JsonNode fieldsNode = getProperty(PROPERTY_SERVICETASK_FIELDS, elementNode); if (fieldsNode != null) { JsonNode itemsArrayNode = fieldsNode.get("fields"); if (itemsArrayNode != null) { for (JsonNode itemNode : itemsArrayNode) { JsonNode nameNode = itemNode.get(PROPERTY_SERVICETASK_FIELD_NAME); if (nameNode != null && StringUtils.isNotEmpty(nameNode.asText())) { FieldExtension field = new FieldExtension(); field.setFieldName(nameNode.asText()); if (StringUtils.isNotEmpty(getValueAsString(PROPERTY_SERVICETASK_FIELD_STRING_VALUE, itemNode))) { field.setStringValue(getValueAsString(PROPERTY_SERVICETASK_FIELD_STRING_VALUE, itemNode)); } else if (StringUtils.isNotEmpty(getValueAsString(PROPERTY_SERVICETASK_FIELD_STRING, itemNode))) { field.setStringValue(getValueAsString(PROPERTY_SERVICETASK_FIELD_STRING, itemNode)); } else if (StringUtils.isNotEmpty(getValueAsString(PROPERTY_SERVICETASK_FIELD_EXPRESSION, itemNode))) { field.setExpression(getValueAsString(PROPERTY_SERVICETASK_FIELD_EXPRESSION, itemNode)); } task.getFieldExtensions().add(field); } } } } return task; }