org.flowable.engine.delegate.JavaDelegate Java Examples
The following examples show how to use
org.flowable.engine.delegate.JavaDelegate.
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: DelegateExpressionExecutionListener.java From flowable-engine with Apache License 2.0 | 6 votes |
@Override public void notify(DelegateExecution execution) { // Note: we can't cache the result of the expression, because the // execution can change: eg. delegateExpression='${mySpringBeanFactory.randomSpringBean()}' Object delegate = expression.getValue(execution); ClassDelegate.applyFieldDeclaration(fieldDeclarations, delegate); if (delegate instanceof ExecutionListener) { Context.getProcessEngineConfiguration() .getDelegateInterceptor() .handleInvocation(new ExecutionListenerInvocation((ExecutionListener) delegate, execution)); } else if (delegate instanceof JavaDelegate) { Context.getProcessEngineConfiguration() .getDelegateInterceptor() .handleInvocation(new JavaDelegateInvocation((JavaDelegate) delegate, execution)); } else { throw new ActivitiIllegalArgumentException("Delegate expression " + expression + " did not resolve to an implementation of " + ExecutionListener.class + " nor " + JavaDelegate.class); } }
Example #2
Source File: BlueprintELResolver.java From flowable-engine with Apache License 2.0 | 5 votes |
@SuppressWarnings("rawtypes") public void unbindService(JavaDelegate delegate, Map props) { String name = (String) props.get("osgi.service.blueprint.compname"); if (delegateMap.containsKey(name)) { delegateMap.remove(name); } LOGGER.info("removed Flowable service from delegate cache {}", name); }
Example #3
Source File: ProcessInstanceMigrationManagerImpl.java From flowable-engine with Apache License 2.0 | 5 votes |
protected void executeExpression(ProcessInstance processInstance, ProcessDefinition procDefToMigrateTo, String preUpgradeJavaDelegateExpression, CommandContext commandContext) { Expression expression = CommandContextUtil.getProcessEngineConfiguration(commandContext).getExpressionManager().createExpression(preUpgradeJavaDelegateExpression); Object delegate = DelegateExpressionUtil.resolveDelegateExpression(expression, (VariableContainer) processInstance, Collections.emptyList()); if (delegate instanceof ActivityBehavior) { CommandContextUtil.getProcessEngineConfiguration(commandContext).getDelegateInterceptor().handleInvocation(new ActivityBehaviorInvocation((ActivityBehavior) delegate, (ExecutionEntityImpl) processInstance)); } else if (delegate instanceof JavaDelegate) { CommandContextUtil.getProcessEngineConfiguration(commandContext).getDelegateInterceptor().handleInvocation(new JavaDelegateInvocation((JavaDelegate) delegate, (ExecutionEntityImpl) processInstance)); } else { throw new FlowableIllegalArgumentException("Delegate expression " + expression + " did neither resolve to an implementation of " + ActivityBehavior.class + " nor " + JavaDelegate.class); } }
Example #4
Source File: ClassDelegate.java From flowable-engine with Apache License 2.0 | 5 votes |
protected ActivityBehavior getActivityBehaviorInstance(ActivityExecution execution) { Object delegateInstance = instantiateDelegate(className, fieldDeclarations); if (delegateInstance instanceof ActivityBehavior) { return determineBehaviour((ActivityBehavior) delegateInstance, execution); } else if (delegateInstance instanceof JavaDelegate) { return determineBehaviour(new ServiceTaskJavaDelegateActivityBehavior((JavaDelegate) delegateInstance, skipExpression), execution); } else { throw new ActivitiIllegalArgumentException(delegateInstance.getClass().getName() + " doesn't implement " + JavaDelegate.class.getName() + " nor " + ActivityBehavior.class.getName()); } }
Example #5
Source File: ClassDelegate.java From flowable-engine with Apache License 2.0 | 5 votes |
protected ExecutionListener getExecutionListenerInstance() { Object delegateInstance = instantiateDelegate(className, fieldDeclarations); if (delegateInstance instanceof ExecutionListener) { return (ExecutionListener) delegateInstance; } else if (delegateInstance instanceof JavaDelegate) { return new ServiceTaskJavaDelegateActivityBehavior((JavaDelegate) delegateInstance, triggerable, skipExpression); } else { throw new FlowableIllegalArgumentException(delegateInstance.getClass().getName() + " doesn't implement " + ExecutionListener.class + " nor " + JavaDelegate.class); } }
Example #6
Source File: ClassDelegate.java From flowable-engine with Apache License 2.0 | 5 votes |
protected ActivityBehavior getActivityBehaviorInstance() { Object delegateInstance = instantiateDelegate(className, fieldDeclarations); if (delegateInstance instanceof ActivityBehavior) { return determineBehaviour((ActivityBehavior) delegateInstance); } else if (delegateInstance instanceof JavaDelegate) { return determineBehaviour(new ServiceTaskJavaDelegateActivityBehavior((JavaDelegate) delegateInstance, triggerable, skipExpression)); } else { throw new FlowableIllegalArgumentException(delegateInstance.getClass().getName() + " doesn't implement " + JavaDelegate.class.getName() + " nor " + ActivityBehavior.class.getName()); } }
Example #7
Source File: DelegateExpressionExecutionListener.java From flowable-engine with Apache License 2.0 | 5 votes |
@Override public void notify(DelegateExecution execution) { Object delegate = DelegateExpressionUtil.resolveDelegateExpression(expression, execution, fieldDeclarations); if (delegate instanceof ExecutionListener) { CommandContextUtil.getProcessEngineConfiguration().getDelegateInterceptor().handleInvocation(new ExecutionListenerInvocation((ExecutionListener) delegate, execution)); } else if (delegate instanceof JavaDelegate) { CommandContextUtil.getProcessEngineConfiguration().getDelegateInterceptor().handleInvocation(new JavaDelegateInvocation((JavaDelegate) delegate, execution)); } else { throw new FlowableIllegalArgumentException("Delegate expression " + expression + " did not resolve to an implementation of " + ExecutionListener.class + " nor " + JavaDelegate.class); } }
Example #8
Source File: ClassDelegate.java From flowable-engine with Apache License 2.0 | 5 votes |
protected ExecutionListener getExecutionListenerInstance() { Object delegateInstance = instantiateDelegate(className, fieldDeclarations); if (delegateInstance instanceof ExecutionListener) { return (ExecutionListener) delegateInstance; } else if (delegateInstance instanceof JavaDelegate) { return new ServiceTaskJavaDelegateActivityBehavior((JavaDelegate) delegateInstance, skipExpression); } else { throw new ActivitiIllegalArgumentException(delegateInstance.getClass().getName() + " doesn't implement " + ExecutionListener.class + " nor " + JavaDelegate.class); } }
Example #9
Source File: ServiceTaskJavaDelegateActivityBehavior.java From flowable-engine with Apache License 2.0 | 4 votes |
public ServiceTaskJavaDelegateActivityBehavior(JavaDelegate javaDelegate, Expression skipExpression) { this.javaDelegate = javaDelegate; this.skipExpression = skipExpression; }
Example #10
Source File: BlueprintELResolver.java From flowable-engine with Apache License 2.0 | 4 votes |
@SuppressWarnings("rawtypes") public void bindService(JavaDelegate delegate, Map props) { String name = (String) props.get("osgi.service.blueprint.compname"); delegateMap.put(name, delegate); LOGGER.info("added Flowable service to delegate cache {}", name); }
Example #11
Source File: JavaDelegateInvocation.java From flowable-engine with Apache License 2.0 | 4 votes |
public JavaDelegateInvocation(JavaDelegate delegateInstance, DelegateExecution execution) { this.delegateInstance = delegateInstance; this.execution = execution; }
Example #12
Source File: BpmnErrorBean.java From flowable-engine with Apache License 2.0 | 4 votes |
public JavaDelegate getDelegate() { return new ThrowBpmnErrorDelegate(); }
Example #13
Source File: JsonTest.java From flowable-engine with Apache License 2.0 | 4 votes |
@Test @Deployment public void testCreateJsonArrayDuringExecution() { JavaDelegate javaDelegate = new JavaDelegate() { @Override public void execute(DelegateExecution execution) { ArrayNode testArrayNode = objectMapper.createArrayNode(); testArrayNode.addObject(); execution.setVariable("jsonArrayTest", testArrayNode); execution.setVariable("${jsonArrayTest[0].name}", "test"); execution.setVariable("jsonObjectTest", objectMapper.createObjectNode()); execution.setVariable("${jsonObjectTest.name}", "anotherTest"); } }; ProcessInstance processInstance = runtimeService.createProcessInstanceBuilder() .processDefinitionKey("createJsonArray") .transientVariable("jsonBean", javaDelegate) .start(); if (HistoryTestHelper.isHistoryLevelAtLeast(HistoryLevel.ACTIVITY, processEngineConfiguration)) { List<HistoricVariableInstance> varInstances = historyService.createHistoricVariableInstanceQuery() .processInstanceId(processInstance.getId()) .orderByVariableName() .asc() .list(); assertThat(varInstances).hasSize(2); HistoricVariableInstance varInstance = varInstances.get(0); assertThatJson(varInstance.getValue()) .isEqualTo("[{" + " name: 'test'" + "}]"); varInstance = varInstances.get(1); assertThatJson(varInstance.getValue()) .isEqualTo("{" + " name: 'anotherTest'" + "}"); } }
Example #14
Source File: ServiceTaskDelegateExpressionActivityBehavior.java From flowable-engine with Apache License 2.0 | 4 votes |
@Override public void execute(DelegateExecution execution) { CommandContext commandContext = CommandContextUtil.getCommandContext(); ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext); boolean loggingSessionEnabled = processEngineConfiguration.isLoggingSessionEnabled(); try { String skipExpressionText = null; if (skipExpression != null) { skipExpressionText = skipExpression.getExpressionText(); } boolean isSkipExpressionEnabled = SkipExpressionUtil.isSkipExpressionEnabled(skipExpressionText, serviceTaskId, execution, commandContext); if (!isSkipExpressionEnabled || !SkipExpressionUtil.shouldSkipFlowElement(skipExpressionText, serviceTaskId, execution, commandContext)) { if (processEngineConfiguration.isEnableProcessDefinitionInfoCache()) { ObjectNode taskElementProperties = BpmnOverrideContext.getBpmnOverrideElementProperties(serviceTaskId, execution.getProcessDefinitionId()); if (taskElementProperties != null && taskElementProperties.has(DynamicBpmnConstants.SERVICE_TASK_DELEGATE_EXPRESSION)) { String overrideExpression = taskElementProperties.get(DynamicBpmnConstants.SERVICE_TASK_DELEGATE_EXPRESSION).asText(); if (StringUtils.isNotEmpty(overrideExpression) && !overrideExpression.equals(expression.getExpressionText())) { expression = processEngineConfiguration.getExpressionManager().createExpression(overrideExpression); } } } Object delegate = DelegateExpressionUtil.resolveDelegateExpression(expression, execution, fieldDeclarations); if (loggingSessionEnabled) { BpmnLoggingSessionUtil.addLoggingData(LoggingSessionConstants.TYPE_SERVICE_TASK_ENTER, "Executing service task with delegate " + delegate, execution); } if (delegate instanceof ActivityBehavior) { if (delegate instanceof AbstractBpmnActivityBehavior) { ((AbstractBpmnActivityBehavior) delegate).setMultiInstanceActivityBehavior(getMultiInstanceActivityBehavior()); } processEngineConfiguration .getDelegateInterceptor().handleInvocation(new ActivityBehaviorInvocation((ActivityBehavior) delegate, execution)); } else if (delegate instanceof JavaDelegate) { processEngineConfiguration .getDelegateInterceptor().handleInvocation(new JavaDelegateInvocation((JavaDelegate) delegate, execution)); if (!triggerable) { leave(execution); } } else { throw new FlowableIllegalArgumentException("Delegate expression " + expression + " did neither resolve to an implementation of " + ActivityBehavior.class + " nor " + JavaDelegate.class); } if (loggingSessionEnabled) { BpmnLoggingSessionUtil.addLoggingData(LoggingSessionConstants.TYPE_SERVICE_TASK_EXIT, "Executed service task with delegate " + delegate, execution); } } else { if (loggingSessionEnabled) { BpmnLoggingSessionUtil.addLoggingData(LoggingSessionConstants.TYPE_SKIP_TASK, "Skipped service task " + execution.getCurrentActivityId() + " with skip expression " + skipExpressionText, execution); } leave(execution); } } catch (Exception exc) { if (loggingSessionEnabled) { BpmnLoggingSessionUtil.addErrorLoggingData(LoggingSessionConstants.TYPE_SERVICE_TASK_EXCEPTION, "Service task with delegate expression " + expression + " threw exception " + exc.getMessage(), exc, execution); } Throwable cause = exc; BpmnError error = null; while (cause != null) { if (cause instanceof BpmnError) { error = (BpmnError) cause; break; } else if (cause instanceof RuntimeException) { if (ErrorPropagation.mapException((RuntimeException) cause, (ExecutionEntity) execution, mapExceptions)) { return; } } cause = cause.getCause(); } if (error != null) { ErrorPropagation.propagateError(error, execution); } else if (exc instanceof FlowableException) { throw exc; } else { throw new FlowableException(exc.getMessage(), exc); } } }
Example #15
Source File: ServiceTaskJavaDelegateActivityBehavior.java From flowable-engine with Apache License 2.0 | 4 votes |
public ServiceTaskJavaDelegateActivityBehavior(JavaDelegate javaDelegate, boolean triggerable, Expression skipExpression) { this.javaDelegate = javaDelegate; this.triggerable = triggerable; this.skipExpression = skipExpression; }
Example #16
Source File: JavaDelegateInvocation.java From flowable-engine with Apache License 2.0 | 4 votes |
public JavaDelegateInvocation(JavaDelegate delegateInstance, DelegateExecution execution) { this.delegateInstance = delegateInstance; this.execution = execution; }
Example #17
Source File: ProcessInstanceMigrationManagerImpl.java From flowable-engine with Apache License 2.0 | 4 votes |
protected void executeJavaDelegate(ProcessInstance processInstance, ProcessDefinition procDefToMigrateTo, String preUpgradeJavaDelegate, CommandContext commandContext) { CommandContextUtil.getProcessEngineConfiguration(commandContext).getDelegateInterceptor() .handleInvocation(new JavaDelegateInvocation((JavaDelegate) defaultInstantiateDelegate(preUpgradeJavaDelegate, Collections.emptyList()), (ExecutionEntityImpl) processInstance)); }
Example #18
Source File: BpmnErrorBean.java From flowable-engine with Apache License 2.0 | 4 votes |
public JavaDelegate getDelegate() { return new ThrowBpmnErrorDelegate(); }