Java Code Examples for org.activiti.engine.delegate.DelegateExecution
The following examples show how to use
org.activiti.engine.delegate.DelegateExecution.
These examples are extracted from open source projects.
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 Project: activiti6-boot2 Author: dingziyang File: IntermediateCatchEventActivityBehavior.java License: Apache License 2.0 | 6 votes |
protected EventGateway getPrecedingEventBasedGateway(DelegateExecution execution) { FlowElement currentFlowElement = execution.getCurrentFlowElement(); if (currentFlowElement instanceof IntermediateCatchEvent) { IntermediateCatchEvent intermediateCatchEvent = (IntermediateCatchEvent) currentFlowElement; List<SequenceFlow> incomingSequenceFlow = intermediateCatchEvent.getIncomingFlows(); // If behind an event based gateway, there is only one incoming sequence flow that originates from said gateway if (incomingSequenceFlow != null && incomingSequenceFlow.size() == 1) { SequenceFlow sequenceFlow = incomingSequenceFlow.get(0); FlowElement sourceFlowElement = sequenceFlow.getSourceFlowElement(); if (sourceFlowElement instanceof EventGateway) { return (EventGateway) sourceFlowElement; } } } return null; }
Example #2
Source Project: activiti6-boot2 Author: dingziyang File: VariableSetter.java License: Apache License 2.0 | 6 votes |
public void execute(DelegateExecution execution) { try { SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss SSS"); // We set the time to check of the updated time is picked up in the history Date updatedDate = sdf.parse("01/01/2001 01:23:46 000"); Context.getProcessEngineConfiguration().getClock().setCurrentTime(updatedDate); execution.setVariable("aVariable", "updated value"); execution.setVariable("bVariable", 123); execution.setVariable("cVariable", 12345L); execution.setVariable("dVariable", 1234.567); execution.setVariable("eVariable", (short)12); Date theDate =sdf.parse("01/01/2001 01:23:45 678"); execution.setVariable("fVariable", theDate); execution.setVariable("gVariable", new SerializableVariable("hello hello")); execution.setVariable("hVariable", ";-)".getBytes()); } catch (Exception e) { throw new ActivitiException(e.getMessage(), e); } }
Example #3
Source Project: activiti6-boot2 Author: dingziyang File: ExecutionTreeUtil.java License: Apache License 2.0 | 6 votes |
public static ExecutionTree buildExecutionTree(DelegateExecution executionEntity) { // Find highest parent ExecutionEntity parentExecution = (ExecutionEntity) executionEntity; while (parentExecution.getParentId() != null || parentExecution.getSuperExecutionId() != null) { if (parentExecution.getParentId() != null) { parentExecution = parentExecution.getParent(); } else { parentExecution = parentExecution.getSuperExecution(); } } // Collect all child executions now we have the parent List<ExecutionEntity> allExecutions = new ArrayList<ExecutionEntity>(); allExecutions.add(parentExecution); collectChildExecutions(parentExecution, allExecutions); return buildExecutionTree(allExecutions); }
Example #4
Source Project: herd Author: FINRAOS File: ExecuteJdbc.java License: Apache License 2.0 | 6 votes |
@Override public void executeImpl(DelegateExecution execution) throws Exception { // Construct request from parameters String contentTypeString = activitiHelper.getRequiredExpressionVariableAsString(contentType, execution, "ContentType"); String requestString = activitiHelper.getRequiredExpressionVariableAsString(jdbcExecutionRequest, execution, "JdbcExecutionRequest").trim(); String receiveTaskIdString = activitiHelper.getExpressionVariableAsString(receiveTaskId, execution); JdbcExecutionRequest jdbcExecutionRequestObject = getRequestObject(contentTypeString, requestString, JdbcExecutionRequest.class); if (receiveTaskIdString == null) { executeSync(execution, null, jdbcExecutionRequestObject); } else { executeAsync(execution, jdbcExecutionRequestObject, receiveTaskIdString); } }
Example #5
Source Project: activiti6-boot2 Author: dingziyang File: TerminateEndEventActivityBehavior.java License: Apache License 2.0 | 6 votes |
protected void dispatchExecutionCancelled(DelegateExecution execution, FlowElement terminateEndEvent) { ExecutionEntityManager executionEntityManager = Context.getCommandContext().getExecutionEntityManager(); // subprocesses for (DelegateExecution subExecution : executionEntityManager.findChildExecutionsByParentExecutionId(execution.getId())) { dispatchExecutionCancelled(subExecution, terminateEndEvent); } // call activities ExecutionEntity subProcessInstance = Context.getCommandContext().getExecutionEntityManager().findSubProcessInstanceBySuperExecutionId(execution.getId()); if (subProcessInstance != null) { dispatchExecutionCancelled(subProcessInstance, terminateEndEvent); } // activity with message/signal boundary events FlowElement currentFlowElement = execution.getCurrentFlowElement(); if (currentFlowElement instanceof FlowNode) { dispatchActivityCancelled(execution, terminateEndEvent); } }
Example #6
Source Project: oneops Author: oneops File: CMSClientTest.java License: Apache License 2.0 | 6 votes |
@Test(priority=10) public void commitAndDeployTest() throws GeneralSecurityException{ DelegateExecution delegateExecution = mock(DelegateExecution.class); CmsRelease cmsRelease = mock(CmsRelease.class); when(cmsRelease.getReleaseId()).thenReturn(TEST_CI_ID / 2); CmsCISimple cmsCISimpleEnv = mock(CmsCISimple.class); when(cmsCISimpleEnv.getCiId()).thenReturn(TEST_CI_ID); when(delegateExecution.getVariable("release")).thenReturn(cmsRelease); when(delegateExecution.getVariable("env")).thenReturn(cmsCISimpleEnv); cc.setRestTemplate(mockHttpClientPostCommitAndDeploy); try { cc.commitAndDeployRelease(delegateExecution); } catch (GeneralSecurityException e) { throw e; } }
Example #7
Source Project: herd Author: FINRAOS File: ActivitiHelperTest.java License: Apache License 2.0 | 6 votes |
@Test public void testGetExpressionVariableAsIntegerRequiredBlankValue() { // Mock dependencies. Expression expression = mock(Expression.class); DelegateExecution execution = mock(DelegateExecution.class); when(expression.getValue(execution)).thenReturn(BLANK_TEXT); // Try to call the method under test. try { activitiHelper.getExpressionVariableAsInteger(expression, execution, VARIABLE_NAME, VARIABLE_REQUIRED); fail(); } catch (IllegalArgumentException e) { assertEquals(String.format("\"%s\" must be specified.", VARIABLE_NAME), e.getMessage()); } }
Example #8
Source Project: activiti6-boot2 Author: dingziyang File: ScriptExecutionListener.java License: Apache License 2.0 | 6 votes |
@Override public void notify(DelegateExecution execution) { if (script == null) { throw new IllegalArgumentException("The field 'script' should be set on the ExecutionListener"); } if (language == null) { throw new IllegalArgumentException("The field 'language' should be set on the ExecutionListener"); } ScriptingEngines scriptingEngines = Context.getProcessEngineConfiguration().getScriptingEngines(); Object result = scriptingEngines.evaluate(script.getExpressionText(), language.getExpressionText(), execution); if (resultVariable != null) { execution.setVariable(resultVariable.getExpressionText(), result); } }
Example #9
Source Project: activiti6-boot2 Author: dingziyang File: TerminateEndEventActivityBehavior.java License: Apache License 2.0 | 6 votes |
protected void terminateMultiInstanceRoot(DelegateExecution execution, CommandContext commandContext, ExecutionEntityManager executionEntityManager) { // When terminateMultiInstance is 'true', we look for the multi instance root and delete it from there. ExecutionEntity miRootExecutionEntity = executionEntityManager.findFirstMultiInstanceRoot((ExecutionEntity) execution); if (miRootExecutionEntity != null) { // Create sibling execution to continue process instance execution before deletion ExecutionEntity siblingExecution = executionEntityManager.createChildExecution(miRootExecutionEntity.getParent()); siblingExecution.setCurrentFlowElement(miRootExecutionEntity.getCurrentFlowElement()); deleteExecutionEntities(executionEntityManager, miRootExecutionEntity, createDeleteReason(miRootExecutionEntity.getActivityId())); Context.getAgenda().planTakeOutgoingSequenceFlowsOperation(siblingExecution, true); } else { defaultTerminateEndEventBehaviour(execution, commandContext, executionEntityManager); } }
Example #10
Source Project: alfresco-repository Author: Alfresco File: ScriptExecutionListener.java License: GNU Lesser General Public License v3.0 | 6 votes |
@Override protected Map<String, Object> getInputMap(DelegateExecution execution, String runAsUser) { Map<String, Object> scriptModel = super.getInputMap(execution, runAsUser); ExecutionListenerExecution listenerExecution = (ExecutionListenerExecution) execution; // Add deleted/cancelled flags boolean cancelled = false; boolean deleted = false; if (ActivitiConstants.DELETE_REASON_DELETED.equals(listenerExecution.getDeleteReason())) { deleted = true; } else if (ActivitiConstants.DELETE_REASON_CANCELLED.equals(listenerExecution.getDeleteReason())) { cancelled = true; } scriptModel.put(DELETED_FLAG, deleted); scriptModel.put(CANCELLED_FLAG, cancelled); return scriptModel; }
Example #11
Source Project: activiti6-boot2 Author: dingziyang File: CreateUserAndMembershipTestDelegate.java License: Apache License 2.0 | 6 votes |
@Override public void execute(DelegateExecution execution) { IdentityService identityService = Context.getProcessEngineConfiguration().getIdentityService(); String username = "Kermit"; User user = identityService.newUser(username); user.setPassword("123"); user.setFirstName("Manually"); user.setLastName("created"); identityService.saveUser(user); // Add admin group Group group = identityService.newGroup("admin"); identityService.saveGroup(group); identityService.createMembership(username, "admin"); }
Example #12
Source Project: activiti6-boot2 Author: dingziyang File: ThrowBpmnErrorDelegate.java License: Apache License 2.0 | 5 votes |
public void execute(DelegateExecution execution) { Integer executionsBeforeError = (Integer) execution.getVariable("executionsBeforeError"); Integer executions = (Integer) execution.getVariable("executions"); if (executions == null) { executions = 0; } executions++; if (executionsBeforeError == null || executionsBeforeError < executions) { throw new BpmnError("23", "This is a business fault, which can be caught by a BPMN Error Event."); } else { execution.setVariable("executions", executions); } }
Example #13
Source Project: activiti6-boot2 Author: dingziyang File: TerminateEndEventActivityBehavior.java License: Apache License 2.0 | 5 votes |
public void execute(DelegateExecution delegateExecution) { ActivityExecution execution = (ActivityExecution) delegateExecution; ActivityImpl terminateEndEventActivity = (ActivityImpl) execution.getActivity(); if (terminateAll) { ActivityExecution processInstanceExecution = findRootProcessInstanceExecution((ExecutionEntity) execution); terminateProcessInstanceExecution(execution, terminateEndEventActivity, processInstanceExecution); } else { ActivityExecution scopeExecution = ScopeUtil.findScopeExecution(execution); if (scopeExecution != null) { terminateExecution(execution, terminateEndEventActivity, scopeExecution); } } }
Example #14
Source Project: activiti-in-action-codes Author: henryyan File: HandleErrorInfoForPaymentListener.java License: Apache License 2.0 | 5 votes |
@Override public void notify(DelegateExecution execution) throws Exception { String currentActivityId = execution.getCurrentActivityId(); if ("exclusivegateway-treasurerAudit".equals(currentActivityId)) { execution.setVariable("message", "财务审批未通过"); } else if ("exclusivegateway-generalManagerAudit".equals(currentActivityId)) { execution.setVariable("message", "总经理审批未通过"); } }
Example #15
Source Project: activiti-in-action-codes Author: henryyan File: JobExecuteFailExecutor.java License: Apache License 2.0 | 5 votes |
@Override public void execute(DelegateExecution execution) throws Exception { ManagementService managementService = execution.getEngineServices().getManagementService(); Job job = managementService.createJobQuery().processInstanceId(execution.getProcessInstanceId()).singleResult(); if (job.getRetries() > 0) { throw new RuntimeException("本次作业执行失败,再次执行可以成功!"); } }
Example #16
Source Project: activiti6-boot2 Author: dingziyang File: EndEventTestJavaDelegate.java License: Apache License 2.0 | 5 votes |
public void execute(DelegateExecution execution) { timesCalled++; try { Thread.sleep(3000L); } catch (InterruptedException e) { e.printStackTrace(); } }
Example #17
Source Project: activiti-in-action-codes Author: henryyan File: AsynchronousExecutor.java License: Apache License 2.0 | 5 votes |
@Override public void execute(DelegateExecution execution) throws Exception { logger.info(execution.getCurrentActivityName() + "---开始执行任务"); Long sleepSeconds = (Long) execution.getVariable("sleepSeconds"); Thread.sleep(sleepSeconds * 1000l); logger.info(execution.getCurrentActivityName() + "---任务完成"); }
Example #18
Source Project: herd Author: FINRAOS File: BaseJavaDelegate.java License: Apache License 2.0 | 5 votes |
/** * Loops through all process variables and logs them. * * @param execution the execution information */ protected void logInputParameters(DelegateExecution execution) { String loggingText = execution.getVariables().entrySet().stream().map(entry -> entry.getKey() + "=" + jsonHelper.objectToJson(entry.getValue())) .collect(Collectors.joining(" ")); LOGGER.info("{} Input parameters for {}: {}", activitiHelper.getProcessIdentifyingInformation(execution), this.getClass().getName(), HerdStringUtils.sanitizeLogText(loggingText)); }
Example #19
Source Project: activiti6-boot2 Author: dingziyang File: UelExpressionCondition.java License: Apache License 2.0 | 5 votes |
public boolean evaluate(String sequenceFlowId, DelegateExecution execution) { Object result = expression.getValue(execution); if (result == null) { throw new ActivitiException("condition expression returns null"); } if (!(result instanceof Boolean)) { throw new ActivitiException("condition expression returns non-Boolean: " + result + " (" + result.getClass().getName() + ")"); } return (Boolean) result; }
Example #20
Source Project: activiti6-boot2 Author: dingziyang File: BusinessRuleTaskActivityBehavior.java License: Apache License 2.0 | 5 votes |
public void execute(DelegateExecution execution) { ProcessDefinition processDefinition = ProcessDefinitionUtil.getProcessDefinition(execution.getProcessDefinitionId()); String deploymentId = processDefinition.getDeploymentId(); KnowledgeBase knowledgeBase = RulesHelper.findKnowledgeBaseByDeploymentId(deploymentId); StatefulKnowledgeSession ksession = knowledgeBase.newStatefulKnowledgeSession(); if (variablesInputExpressions != null) { Iterator<Expression> itVariable = variablesInputExpressions.iterator(); while (itVariable.hasNext()) { Expression variable = itVariable.next(); ksession.insert(variable.getValue(execution)); } } if (!rulesExpressions.isEmpty()) { RulesAgendaFilter filter = new RulesAgendaFilter(); Iterator<Expression> itRuleNames = rulesExpressions.iterator(); while (itRuleNames.hasNext()) { Expression ruleName = itRuleNames.next(); filter.addSuffic(ruleName.getValue(execution).toString()); } filter.setAccept(!exclude); ksession.fireAllRules(filter); } else { ksession.fireAllRules(); } Collection<Object> ruleOutputObjects = ksession.getObjects(); if (ruleOutputObjects != null && !ruleOutputObjects.isEmpty()) { Collection<Object> outputVariables = new ArrayList<Object>(); for (Object object : ruleOutputObjects) { outputVariables.add(object); } execution.setVariable(resultVariable, outputVariables); } ksession.dispose(); leave(execution); }
Example #21
Source Project: herd Author: FINRAOS File: ActivitiHelperTest.java License: Apache License 2.0 | 5 votes |
@Test public void testGetExpressionVariableAsBooleanRequired() { // Mock dependencies. Expression expression = mock(Expression.class); DelegateExecution execution = mock(DelegateExecution.class); when(expression.getValue(execution)).thenReturn(BOOLEAN_VALUE.toString()); // Call the method under test. Boolean result = activitiHelper.getExpressionVariableAsBoolean(expression, execution, VARIABLE_NAME, VARIABLE_REQUIRED, NO_BOOLEAN_DEFAULT_VALUE); // Validate the result. assertEquals(BOOLEAN_VALUE, result); }
Example #22
Source Project: activiti6-boot2 Author: dingziyang File: TransientVariablesTest.java License: Apache License 2.0 | 5 votes |
public void execute(DelegateExecution execution) { String response = (String) execution.getTransientVariable("response"); for (String s : response.split(";")) { String[] data = s.split("="); if (data[0].equals("message")) { execution.setVariable("message", data[1] + "!"); } } }
Example #23
Source Project: activiti6-boot2 Author: dingziyang File: VariableEventsExecutionListener.java License: Apache License 2.0 | 5 votes |
@Override public void notify(DelegateExecution execution) { // Create, update and remove variable execution.setVariable("variable", 123); execution.setVariable("variable", 456); execution.removeVariable("variable"); }
Example #24
Source Project: activiti6-boot2 Author: dingziyang File: ScriptCondition.java License: Apache License 2.0 | 5 votes |
public boolean evaluate(String sequenceFlowId, DelegateExecution execution) { ScriptingEngines scriptingEngines = Context.getProcessEngineConfiguration().getScriptingEngines(); Object result = scriptingEngines.evaluate(expression, language, execution); if (result == null) { throw new ActivitiException("condition script returns null: " + expression); } if (!(result instanceof Boolean)) { throw new ActivitiException("condition script returns non-Boolean: " + result + " (" + result.getClass().getName() + ")"); } return (Boolean) result; }
Example #25
Source Project: alfresco-repository Author: Alfresco File: SendModeratedInviteDelegate.java License: GNU Lesser General Public License v3.0 | 5 votes |
@Override public void execute(DelegateExecution execution) throws Exception { String invitationId = ActivitiConstants.ENGINE_ID + "$" + execution.getProcessInstanceId(); Map<String, Object> variables = execution.getVariables(); invitationService.sendModeratedInvitation(invitationId, emailTemplatePath, EMAIL_SUBJECT_KEY, variables); }
Example #26
Source Project: herd Author: FINRAOS File: AddEmrShellStep.java License: Apache License 2.0 | 5 votes |
@Override public void executeImpl(DelegateExecution execution) throws Exception { // Create the request. EmrShellStepAddRequest request = new EmrShellStepAddRequest(); populateCommonParams(request, execution); request.setScriptLocation(getScriptLocation(execution)); request.setScriptArguments(getScriptArguments(execution)); addEmrStepAndSetWorkflowVariables(request, execution); }
Example #27
Source Project: herd Author: FINRAOS File: ActivitiHelperTest.java License: Apache License 2.0 | 5 votes |
@Test public void testGetRequiredExpressionVariableAsString() { // Mock dependencies. Expression expression = mock(Expression.class); DelegateExecution execution = mock(DelegateExecution.class); when(expression.getValue(execution)).thenReturn(STRING_VALUE); // Call the method under test. String result = activitiHelper.getRequiredExpressionVariableAsString(expression, execution, VARIABLE_NAME); // Validate the result. assertEquals(STRING_VALUE, result); }
Example #28
Source Project: activiti6-boot2 Author: dingziyang File: MultiInstanceDelegate.java License: Apache License 2.0 | 5 votes |
public void execute(DelegateExecution execution) { Integer result = (Integer) execution.getVariable("result"); Integer item = (Integer) execution.getVariable("item"); if (item != null) { result = result * item; } else { result = result * 2; } execution.setVariable("result", result); }
Example #29
Source Project: activiti6-boot2 Author: dingziyang File: ClassDelegate.java License: Apache License 2.0 | 5 votes |
@Override public void completing(DelegateExecution execution, DelegateExecution subProcessInstance) throws Exception { if (activityBehaviorInstance == null) { activityBehaviorInstance = getActivityBehaviorInstance((ActivityExecution) execution); } if (activityBehaviorInstance instanceof SubProcessActivityBehavior) { ((SubProcessActivityBehavior) activityBehaviorInstance).completing(execution, subProcessInstance); } else { throw new ActivitiException("completing() can only be called on a " + SubProcessActivityBehavior.class.getName() + " instance"); } }
Example #30
Source Project: herd Author: FINRAOS File: ExecuteJdbc.java License: Apache License 2.0 | 5 votes |
/** * Executes the task synchronously. overrideActivitiId is provided to customize the name of the variable to set during the execution of the task. This is * important when the task is running asynchronously because execution.getCurrentActivitiId() will report the ID the task that the workflow is currently in, * and not the ID of the task that was originally executed. * * @param execution The execution. * @param overrideActivitiId Optionally overrides the task id which to use to generate variable names. * @param jdbcExecutionRequest The request. * * @throws Exception When any exception occurs during the execution of the task. */ private void executeSync(DelegateExecution execution, String overrideActivitiId, JdbcExecutionRequest jdbcExecutionRequest) throws Exception { String executionId = execution.getId(); String activitiId = execution.getCurrentActivityId(); if (overrideActivitiId != null) { activitiId = overrideActivitiId; } // Execute the request. May throw exception here in case of validation or system errors. // Thrown exceptions should be caught by parent implementation. JdbcExecutionResponse jdbcExecutionResponse = jdbcService.executeJdbc(jdbcExecutionRequest); // Set the response setJsonResponseAsWorkflowVariable(jdbcExecutionResponse, executionId, activitiId); /* * Special handling of error condition. * Any one of the requested SQL statements could've failed without throwing an exception. * If any of the statements are in ERROR, throw an exception. * This ensures that the workflow response variable is still available to the users. */ for (JdbcStatement jdbcStatement : jdbcExecutionResponse.getStatements()) { if (JdbcStatementStatus.ERROR.equals(jdbcStatement.getStatus())) { throw new IllegalArgumentException("There are failed executions. See JSON response for details."); } } }