Java Code Examples for org.flowable.engine.runtime.ProcessInstance#getId()
The following examples show how to use
org.flowable.engine.runtime.ProcessInstance#getId() .
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: ServiceCacheTask.java From flowable-engine with Apache License 2.0 | 6 votes |
@Override public void execute(DelegateExecution execution) { ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(); RuntimeService runtimeService = processEngineConfiguration.getRuntimeService(); ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(execution.getProcessInstanceId()).singleResult(); if (processInstance != null && processInstance.getId().equals(execution.getProcessInstanceId())) { processInstanceId = processInstance.getId(); } Execution queryExecution = runtimeService.createExecutionQuery().executionId(execution.getId()).singleResult(); if (queryExecution != null && execution.getId().equals(queryExecution.getId())) { executionId = queryExecution.getId(); } HistoryService historyService = processEngineConfiguration.getHistoryService(); HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(execution.getProcessInstanceId()).singleResult(); if (historicProcessInstance != null && historicProcessInstance.getId().equals(execution.getProcessInstanceId())) { historicProcessInstanceId = historicProcessInstance.getId(); } }
Example 2
Source File: TaskServiceTest.java From flowable-engine with Apache License 2.0 | 6 votes |
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" }) public void testTaskAttachmentWithProcessInstanceId() { if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess"); String processInstanceId = processInstance.getId(); taskService.createAttachment("web page", null, processInstanceId, "weatherforcast", "temperatures and more", "http://weather.com"); Attachment attachment = taskService.getProcessInstanceAttachments(processInstanceId).get(0); assertEquals("weatherforcast", attachment.getName()); assertEquals("temperatures and more", attachment.getDescription()); assertEquals("web page", attachment.getType()); assertEquals(processInstanceId, attachment.getProcessInstanceId()); assertNull(attachment.getTaskId()); assertEquals("http://weather.com", attachment.getUrl()); assertNull(taskService.getAttachmentContent(attachment.getId())); // Finally, clean up taskService.deleteAttachment(attachment.getId()); // TODO: Bad API design. Need to fix attachment/comment properly ((TaskServiceImpl) taskService).deleteComments(null, processInstanceId); } }
Example 3
Source File: TaskServiceTest.java From flowable-engine with Apache License 2.0 | 6 votes |
@Test @Deployment(resources = { "org/flowable/engine/test/api/oneTaskProcess.bpmn20.xml" }) public void testTaskAttachmentWithProcessInstanceId() { if (isHistoryLevelAtLeast(HistoryLevel.ACTIVITY, processEngineConfiguration)) { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess"); String processInstanceId = processInstance.getId(); taskService.createAttachment("web page", null, processInstanceId, "weatherforcast", "temperatures and more", "http://weather.com"); Attachment attachment = taskService.getProcessInstanceAttachments(processInstanceId).get(0); assertThat(attachment.getName()).isEqualTo("weatherforcast"); assertThat(attachment.getDescription()).isEqualTo("temperatures and more"); assertThat(attachment.getType()).isEqualTo("web page"); assertThat(attachment.getProcessInstanceId()).isEqualTo(processInstanceId); assertThat(attachment.getTaskId()).isNull(); assertThat(attachment.getUrl()).isEqualTo("http://weather.com"); assertThat(taskService.getAttachmentContent(attachment.getId())).isNull(); // Finally, clean up taskService.deleteAttachment(attachment.getId()); // TODO: Bad API design. Need to fix attachment/comment properly ((TaskServiceImpl) taskService).deleteComments(null, processInstanceId); } }
Example 4
Source File: ExpenseController.java From flowable-springboot with MIT License | 5 votes |
/** * 添加报销 * * @param userId 用户Id * @param money 报销金额 * @param descption 描述 */ @RequestMapping(value = "add") @ResponseBody public String addExpense(String userId, Integer money, String descption) { //启动流程 HashMap<String, Object> map = new HashMap<>(); map.put("taskUser", userId); map.put("money", money); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Expense", map); return "提交成功.流程Id为:" + processInstance.getId(); }
Example 5
Source File: ProcessInstanceCollectionResourceTest.java From flowable-engine with Apache License 2.0 | 5 votes |
/** * Test getting a list of process instance, using all tenant filters. */ @Test @Deployment(resources = { "org/flowable/rest/service/api/runtime/ProcessInstanceResourceTest.process-one.bpmn20.xml" }) public void testGetProcessInstancesTenant() throws Exception { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("processOne", "myBusinessKey"); String id = processInstance.getId(); // Test without tenant id String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION) + "?withoutTenantId=true"; assertResultsPresentInDataResponse(url, id); // Update the tenant for the deployment managementService.executeCommand(new ChangeDeploymentTenantIdCmd(deploymentId, "myTenant")); // Test tenant id url = RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION) + "?tenantId=myTenant"; assertResultsPresentInDataResponse(url, id); url = RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION) + "?tenantId=anotherTenant"; assertResultsPresentInDataResponse(url); // Test tenant id like url = RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION) + "?tenantIdLike=" + encode("%enant"); assertResultsPresentInDataResponse(url, id); url = RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION) + "?tenantIdLike=" + encode("%what"); assertResultsPresentInDataResponse(url); // Test without tenant id url = RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION) + "?withoutTenantId=true"; assertResultsPresentInDataResponse(url); }
Example 6
Source File: ProcessInstanceResource.java From flowable-engine with Apache License 2.0 | 5 votes |
protected ProcessInstanceResponse activateProcessInstance(ProcessInstance processInstance) { if (!processInstance.isSuspended()) { throw new FlowableConflictException("Process instance with id '" + processInstance.getId() + "' is already active."); } runtimeService.activateProcessInstanceById(processInstance.getId()); ProcessInstanceResponse response = restResponseFactory.createProcessInstanceResponse(processInstance); // No need to re-fetch the instance, just alter the suspended state of the result-object response.setSuspended(false); return response; }
Example 7
Source File: JPAVariableTest.java From flowable-engine with Apache License 2.0 | 5 votes |
@Test @Deployment(resources = "org/flowable/standalone/jpa/JPAVariableTest.testQueryJPAVariable.bpmn20.xml") public void testReplaceExistingJPAEntityWithAnotherOfSameType() { EntityManager manager = entityManagerFactory.createEntityManager(); manager.getTransaction().begin(); // Old variable that gets replaced FieldAccessJPAEntity oldVariable = new FieldAccessJPAEntity(); oldVariable.setId(11L); oldVariable.setValue("value1"); manager.persist(oldVariable); // New variable FieldAccessJPAEntity newVariable = new FieldAccessJPAEntity(); newVariable.setId(12L); newVariable.setValue("value2"); manager.persist(newVariable); manager.flush(); manager.getTransaction().commit(); manager.close(); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("JPAVariableProcess"); String executionId = processInstance.getId(); String variableName = "testVariable"; runtimeService.setVariable(executionId, variableName, oldVariable); runtimeService.setVariable(executionId, variableName, newVariable); Object variable = runtimeService.getVariable(executionId, variableName); assertThat(((FieldAccessJPAEntity) variable).getId()).isEqualTo(newVariable.getId()); }
Example 8
Source File: TerminateEndEventTest.java From flowable-engine with Apache License 2.0 | 5 votes |
@Deployment public void testThreeExecutionsArrivingInTerminateEndEvent() { Map<String, Object> variableMap = new HashMap<String, Object>(); variableMap.put("passed_QC", false); variableMap.put("has_bad_pixel_pattern", true); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("skybox_image_pull_request", variableMap); String processInstanceId = processInstance.getId(); assertNotNull(processInstance); while (processInstance != null) { List<Execution> executionList = runtimeService.createExecutionQuery().processInstanceId(processInstance.getId()).list(); String activityId = ""; for (Execution execution : executionList) { activityId = execution.getActivityId(); if (activityId == null || activityId.equalsIgnoreCase("quality_control_passed_gateway") || activityId.equalsIgnoreCase("parallelgateway1") || activityId.equalsIgnoreCase("catch_bad_pixel_signal") || activityId.equalsIgnoreCase("throw_bad_pixel_signal") || activityId.equalsIgnoreCase("has_bad_pixel_pattern") || activityId.equalsIgnoreCase("")) { continue; } runtimeService.trigger(execution.getId()); } processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstance.getId()).singleResult(); } assertProcessEnded(processInstanceId); }
Example 9
Source File: CompetingSignalsTest.java From flowable-engine with Apache License 2.0 | 5 votes |
@Deployment(resources = { "org/activiti/engine/test/concurrency/CompetingSignalsTest.testCompetingSignals.bpmn20.xml" }) public void testCompetingSignalsWithRetry() throws Exception { RuntimeServiceImpl runtimeServiceImpl = (RuntimeServiceImpl) runtimeService; CommandExecutorImpl before = (CommandExecutorImpl) runtimeServiceImpl.getCommandExecutor(); try { CommandInterceptor retryInterceptor = new RetryInterceptor(); retryInterceptor.setNext(before.getFirst()); runtimeServiceImpl.setCommandExecutor(new CommandExecutorImpl(before.getDefaultConfig(), retryInterceptor)); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("CompetingSignalsProcess"); String processInstanceId = processInstance.getId(); LOGGER.debug("test thread starts thread one"); SignalThread threadOne = new SignalThread(processInstanceId); threadOne.startAndWaitUntilControlIsReturned(); LOGGER.debug("test thread continues to start thread two"); SignalThread threadTwo = new SignalThread(processInstanceId); threadTwo.startAndWaitUntilControlIsReturned(); LOGGER.debug("test thread notifies thread 1"); threadOne.proceedAndWaitTillDone(); assertNull(threadOne.exception); LOGGER.debug("test thread notifies thread 2"); threadTwo.proceedAndWaitTillDone(); assertNull(threadTwo.exception); } finally { // restore the command executor runtimeServiceImpl.setCommandExecutor(before); } }
Example 10
Source File: FlowableProducer.java From flowable-engine with Apache License 2.0 | 5 votes |
protected String findProcessInstanceId(Exchange exchange) { String processInstanceId = exchange.getProperty(PROCESS_ID_PROPERTY, String.class); if (processInstanceId != null) { return processInstanceId; } String key = exchange.getProperty(PROCESS_KEY_PROPERTY, String.class); ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceBusinessKey(key).singleResult(); if (processInstance == null) { throw new FlowableException("Could not start process instance with business key " + key); } return processInstance.getId(); }
Example 11
Source File: InterfaceApplyController.java From open-capacity-platform with Apache License 2.0 | 5 votes |
/** * 接口申请 * * @param userId 用户Id * @param descption 描述 * http://localhost:7010/interfaceApply/add?userId=owen */ @RequestMapping(value = "add") @ResponseBody public String addExpense(String userId,String descption) { //启动流程 HashMap<String, Object> map = new HashMap<>(); map.put("taskUser", userId); map.put("clientId", "clientId"); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Interface", map); return "提交成功.流程Id为:" + processInstance.getId(); }
Example 12
Source File: HistoricProcessInstanceQueryTest.java From flowable-engine with Apache License 2.0 | 4 votes |
@Deployment public void testLocalization() throws Exception { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("historicProcessLocalization"); String processInstanceId = processInstance.getId(); org.flowable.task.api.Task task = taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult(); taskService.complete(task.getId()); if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) { List<HistoricProcessInstance> processes = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).list(); assertEquals(1, processes.size()); assertNull(processes.get(0).getName()); assertNull(processes.get(0).getDescription()); ObjectNode infoNode = dynamicBpmnService.changeLocalizationName("en-GB", "historicProcessLocalization", "Historic Process Name 'en-GB'"); dynamicBpmnService.changeLocalizationDescription("en-GB", "historicProcessLocalization", "Historic Process Description 'en-GB'", infoNode); dynamicBpmnService.saveProcessDefinitionInfo(processInstance.getProcessDefinitionId(), infoNode); dynamicBpmnService.changeLocalizationName("en", "historicProcessLocalization", "Historic Process Name 'en'", infoNode); dynamicBpmnService.changeLocalizationDescription("en", "historicProcessLocalization", "Historic Process Description 'en'", infoNode); dynamicBpmnService.saveProcessDefinitionInfo(processInstance.getProcessDefinitionId(), infoNode); processes = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).list(); assertEquals(1, processes.size()); assertNull(processes.get(0).getName()); assertNull(processes.get(0).getDescription()); processes = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).locale("en-GB").list(); assertEquals(1, processes.size()); assertEquals("Historic Process Name 'en-GB'", processes.get(0).getName()); assertEquals("Historic Process Description 'en-GB'", processes.get(0).getDescription()); processes = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).listPage(0, 10); assertEquals(1, processes.size()); assertNull(processes.get(0).getName()); assertNull(processes.get(0).getDescription()); processes = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).locale("en-GB").listPage(0, 10); assertEquals(1, processes.size()); assertEquals("Historic Process Name 'en-GB'", processes.get(0).getName()); assertEquals("Historic Process Description 'en-GB'", processes.get(0).getDescription()); HistoricProcessInstance process = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult(); assertNull(process.getName()); assertNull(process.getDescription()); process = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).locale("en-GB").singleResult(); assertEquals("Historic Process Name 'en-GB'", process.getName()); assertEquals("Historic Process Description 'en-GB'", process.getDescription()); process = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).locale("en").singleResult(); assertEquals("Historic Process Name 'en'", process.getName()); assertEquals("Historic Process Description 'en'", process.getDescription()); process = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).locale("en-AU").withLocalizationFallback().singleResult(); assertEquals("Historic Process Name 'en'", process.getName()); assertEquals("Historic Process Description 'en'", process.getDescription()); } }
Example 13
Source File: ProcessDefinitionCacheTest.java From flowable-engine with Apache License 2.0 | 4 votes |
public void testStartProcessInstanceByIdAfterReboot() { // In case this test is run in a test suite, previous engines might // have been initialized and cached. First we close the // existing process engines to make sure that the db is clean // and that there are no existing process engines involved. ProcessEngines.destroy(); // Creating the DB schema (without building a process engine) ProcessEngineConfigurationImpl processEngineConfiguration = new StandaloneInMemProcessEngineConfiguration(); processEngineConfiguration.setEngineName("reboot-test-schema"); processEngineConfiguration.setJdbcUrl("jdbc:h2:mem:activiti-reboot-test;DB_CLOSE_DELAY=1000"); processEngineConfiguration.setFlowable5CompatibilityEnabled(true); ProcessEngine schemaProcessEngine = processEngineConfiguration.buildProcessEngine(); // Create process engine and deploy test process StandaloneProcessEngineConfiguration standaloneProcessEngineConfiguration = new StandaloneProcessEngineConfiguration(); standaloneProcessEngineConfiguration.setEngineName("reboot-test"); standaloneProcessEngineConfiguration.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE); standaloneProcessEngineConfiguration.setJdbcUrl("jdbc:h2:mem:activiti-reboot-test;DB_CLOSE_DELAY=1000"); standaloneProcessEngineConfiguration.setAsyncExecutorActivate(false); standaloneProcessEngineConfiguration.setFlowable5CompatibilityEnabled(true); ProcessEngine processEngine = standaloneProcessEngineConfiguration.buildProcessEngine(); processEngine.getRepositoryService() .createDeployment() .deploymentProperty(DeploymentProperties.DEPLOY_AS_FLOWABLE5_PROCESS_DEFINITION, Boolean.TRUE) .addClasspathResource("org/activiti/engine/test/cache/originalProcess.bpmn20.xml") .deploy(); // verify existence of process definition List<ProcessDefinition> processDefinitions = processEngine .getRepositoryService() .createProcessDefinitionQuery() .list(); assertEquals(1, processDefinitions.size()); // Start a new Process instance ProcessInstance processInstance = processEngine.getRuntimeService().startProcessInstanceById(processDefinitions.get(0).getId()); String processInstanceId = processInstance.getId(); assertNotNull(processInstance); // Close the process engine processEngine.close(); assertNotNull(processEngine.getRuntimeService()); // Reboot the process engine standaloneProcessEngineConfiguration = new StandaloneProcessEngineConfiguration(); standaloneProcessEngineConfiguration.setEngineName("reboot-test"); standaloneProcessEngineConfiguration.setDatabaseSchemaUpdate(org.activiti.engine.ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE); standaloneProcessEngineConfiguration.setJdbcUrl("jdbc:h2:mem:activiti-reboot-test;DB_CLOSE_DELAY=1000"); standaloneProcessEngineConfiguration.setAsyncExecutorActivate(false); standaloneProcessEngineConfiguration.setFlowable5CompatibilityEnabled(true); processEngine = standaloneProcessEngineConfiguration.buildProcessEngine(); // Check if the existing process instance is still alive processInstance = processEngine .getRuntimeService() .createProcessInstanceQuery() .processInstanceId(processInstanceId) .singleResult(); assertNotNull(processInstance); // Complete the task. That will end the process instance TaskService taskService = processEngine.getTaskService(); org.flowable.task.api.Task task = taskService .createTaskQuery() .list() .get(0); taskService.complete(task.getId()); // Check if the process instance has really ended. This means that the process definition has // re-loaded into the process definition cache processInstance = processEngine .getRuntimeService() .createProcessInstanceQuery() .processInstanceId(processInstanceId) .singleResult(); assertNull(processInstance); // Extra check to see if a new process instance can be started as well processInstance = processEngine.getRuntimeService().startProcessInstanceById(processDefinitions.get(0).getId()); assertNotNull(processInstance); // close the process engine processEngine.close(); // Cleanup schema schemaProcessEngine.close(); }
Example 14
Source File: HistoricProcessInstanceQueryTest.java From flowable-engine with Apache License 2.0 | 4 votes |
@Test @Deployment public void testLocalization() throws Exception { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("historicProcessLocalization"); String processInstanceId = processInstance.getId(); org.flowable.task.api.Task task = taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult(); taskService.complete(task.getId()); if (HistoryTestHelper.isHistoryLevelAtLeast(HistoryLevel.ACTIVITY, processEngineConfiguration)) { List<HistoricProcessInstance> processes = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).list(); assertThat(processes) .extracting(HistoricProcessInstance::getName, HistoricProcessInstance::getDescription) .containsExactly(tuple(null, null)); ObjectNode infoNode = dynamicBpmnService.changeLocalizationName("en-GB", "historicProcessLocalization", "Historic Process Name 'en-GB'"); dynamicBpmnService.changeLocalizationDescription("en-GB", "historicProcessLocalization", "Historic Process Description 'en-GB'", infoNode); dynamicBpmnService.saveProcessDefinitionInfo(processInstance.getProcessDefinitionId(), infoNode); dynamicBpmnService.changeLocalizationName("en", "historicProcessLocalization", "Historic Process Name 'en'", infoNode); dynamicBpmnService.changeLocalizationDescription("en", "historicProcessLocalization", "Historic Process Description 'en'", infoNode); dynamicBpmnService.saveProcessDefinitionInfo(processInstance.getProcessDefinitionId(), infoNode); processes = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).list(); assertThat(processes) .extracting(HistoricProcessInstance::getName, HistoricProcessInstance::getDescription) .containsExactly(tuple(null, null)); processes = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).locale("en-GB").list(); assertThat(processes) .extracting(HistoricProcessInstance::getName, HistoricProcessInstance::getDescription) .containsExactly(tuple("Historic Process Name 'en-GB'", "Historic Process Description 'en-GB'")); processes = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).listPage(0, 10); assertThat(processes) .extracting(HistoricProcessInstance::getName, HistoricProcessInstance::getDescription) .containsExactly(tuple(null, null)); processes = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).locale("en-GB").listPage(0, 10); assertThat(processes) .extracting(HistoricProcessInstance::getName, HistoricProcessInstance::getDescription) .containsExactly(tuple("Historic Process Name 'en-GB'", "Historic Process Description 'en-GB'")); HistoricProcessInstance process = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult(); assertThat(process.getName()).isNull(); assertThat(process.getDescription()).isNull(); process = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).locale("en-GB").singleResult(); assertThat(processes) .extracting(HistoricProcessInstance::getName, HistoricProcessInstance::getDescription) .containsExactly(tuple("Historic Process Name 'en-GB'", "Historic Process Description 'en-GB'")); process = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).locale("en").singleResult(); assertThat(process.getName()).isEqualTo("Historic Process Name 'en'"); assertThat(process.getDescription()).isEqualTo("Historic Process Description 'en'"); process = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).locale("en-AU").withLocalizationFallback() .singleResult(); assertThat(process.getName()).isEqualTo("Historic Process Name 'en'"); assertThat(process.getDescription()).isEqualTo("Historic Process Description 'en'"); } }
Example 15
Source File: VariablesTest.java From flowable-engine with Apache License 2.0 | 4 votes |
@Test @Deployment public void testNullVariable() { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("taskAssigneeProcess"); org.flowable.task.api.Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult(); Map<String, String> variables = new HashMap<>(); variables.put("testProperty", "434"); formService.submitTaskFormData(task.getId(), variables); String resultVar = (String) runtimeService.getVariable(processInstance.getId(), "testProperty"); assertThat(resultVar).isEqualTo("434"); task = taskService.createTaskQuery().singleResult(); taskService.complete(task.getId()); // If no variable is given, no variable should be set and script test should throw exception processInstance = runtimeService.startProcessInstanceByKey("taskAssigneeProcess"); String processId = processInstance.getId(); task = taskService.createTaskQuery().processInstanceId(processId).singleResult(); String taskId = task.getId(); try { assertThatThrownBy(() -> formService.submitTaskFormData(taskId, new HashMap<String, String>())) .isExactlyInstanceOf(FlowableException.class); } finally { runtimeService.deleteProcessInstance(processId, "intentional exception in script task"); } // No we put null property, This should be put into the variable. We do not expect exceptions processInstance = runtimeService.startProcessInstanceByKey("taskAssigneeProcess"); task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult(); String finalTaskId = task.getId(); Map<String, String> finalVariables = new HashMap<>(); finalVariables.put("testProperty", null); assertThatCode(() -> formService.submitTaskFormData(finalTaskId, finalVariables)) .doesNotThrowAnyException(); resultVar = (String) runtimeService.getVariable(processInstance.getId(), "testProperty"); assertThat(resultVar).isNull(); runtimeService.deleteProcessInstance(processInstance.getId(), "intentional exception in script task"); }
Example 16
Source File: DefaultProcessInstanceService.java From flowable-engine with Apache License 2.0 | 4 votes |
@Override public String startProcessInstanceByKey(String processDefinitionKey, String predefinedProcessInstanceId, String planItemInstanceId, String stageInstanceId, String tenantId, Boolean fallbackToDefaultTenant, String parentDeploymentId, Map<String, Object> inParametersMap, String businessKey, Map<String, Object> variableFormVariables, FormInfo variableFormInfo, String variableFormOutcome) { ProcessInstanceBuilder processInstanceBuilder = processEngineConfiguration.getRuntimeService().createProcessInstanceBuilder(); processInstanceBuilder.processDefinitionKey(processDefinitionKey); if (tenantId != null) { processInstanceBuilder.tenantId(tenantId); processInstanceBuilder.overrideProcessDefinitionTenantId(tenantId); } if (parentDeploymentId != null) { processInstanceBuilder.processDefinitionParentDeploymentId(parentDeploymentId); } processInstanceBuilder.predefineProcessInstanceId(predefinedProcessInstanceId); if (planItemInstanceId != null) { processInstanceBuilder.callbackId(planItemInstanceId); processInstanceBuilder.callbackType(CallbackTypes.PLAN_ITEM_CHILD_PROCESS); } for (String target : inParametersMap.keySet()) { processInstanceBuilder.variable(target, inParametersMap.get(target)); } if (fallbackToDefaultTenant != null && fallbackToDefaultTenant) { processInstanceBuilder.fallbackToDefaultTenant(); } if (businessKey != null) { processInstanceBuilder.businessKey(businessKey); } if (stageInstanceId != null) { processInstanceBuilder.stageInstanceId(stageInstanceId); } if (variableFormInfo != null) { processInstanceBuilder.formVariables(variableFormVariables, variableFormInfo, variableFormOutcome); } ProcessInstance processInstance = processInstanceBuilder.start(); return processInstance.getId(); }
Example 17
Source File: ProcessDefinitionCacheTest.java From flowable-engine with Apache License 2.0 | 4 votes |
@Test public void testStartProcessInstanceByIdAfterReboot() { // In case this test is run in a test suite, previous engines might have been initialized and cached. First we close the // existing process engines to make sure that the db is clean and that there are no existing process engines involved. ProcessEngines.destroy(); // Creating the DB schema (without building a process engine) ProcessEngineConfigurationImpl processEngineConfiguration = new StandaloneInMemProcessEngineConfiguration(); processEngineConfiguration.setEngineName("reboot-test-schema"); processEngineConfiguration.setJdbcUrl("jdbc:h2:mem:activiti-reboot-test;DB_CLOSE_DELAY=1000"); ProcessEngine schemaProcessEngine = processEngineConfiguration.buildProcessEngine(); // Create process engine and deploy test process ProcessEngine processEngine = new StandaloneProcessEngineConfiguration().setEngineName("reboot-test").setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE) .setJdbcUrl("jdbc:h2:mem:activiti-reboot-test;DB_CLOSE_DELAY=1000").setAsyncExecutorActivate(false).buildProcessEngine(); processEngine.getRepositoryService().createDeployment().addClasspathResource("org/flowable/engine/test/cache/originalProcess.bpmn20.xml").deploy(); // verify existence of process definition List<ProcessDefinition> processDefinitions = processEngine.getRepositoryService().createProcessDefinitionQuery().list(); assertEquals(1, processDefinitions.size()); // Start a new Process instance ProcessInstance processInstance = processEngine.getRuntimeService().startProcessInstanceById(processDefinitions.get(0).getId()); String processInstanceId = processInstance.getId(); assertNotNull(processInstance); // Close the process engine processEngine.close(); assertNotNull(processEngine.getRuntimeService()); // Reboot the process engine processEngine = new StandaloneProcessEngineConfiguration().setEngineName("reboot-test").setDatabaseSchemaUpdate(org.flowable.engine.ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE) .setJdbcUrl("jdbc:h2:mem:activiti-reboot-test;DB_CLOSE_DELAY=1000").setAsyncExecutorActivate(false).buildProcessEngine(); // Check if the existing process instance is still alive processInstance = processEngine.getRuntimeService().createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult(); assertNotNull(processInstance); // Complete the task. That will end the process instance TaskService taskService = processEngine.getTaskService(); org.flowable.task.api.Task task = taskService.createTaskQuery().list().get(0); taskService.complete(task.getId()); // Check if the process instance has really ended. This means that the // process definition has re-loaded into the process definition cache processInstance = processEngine.getRuntimeService().createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult(); assertNull(processInstance); // Extra check to see if a new process instance can be started as well processInstance = processEngine.getRuntimeService().startProcessInstanceById(processDefinitions.get(0).getId()); assertNotNull(processInstance); // close the process engine processEngine.close(); // Cleanup schema schemaProcessEngine.close(); }
Example 18
Source File: ProcessInstanceCollectionResourceTest.java From flowable-engine with Apache License 2.0 | 4 votes |
@Test @Deployment(resources = { "org/flowable/rest/service/api/runtime/ProcessInstanceResourceTest.process-one.bpmn20.xml" }) public void testGetProcessInstancesByBusinessKeyAndIncludeVariables() throws Exception { HashMap<String, Object> variables = new HashMap<>(); variables.put("myVar1", "myVar1"); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("processOne", "myBusinessKey", variables); String processId = processInstance.getId(); // check that the right process is returned with no variables String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION) + "?businessKey=myBusinessKey"; CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + url), HttpStatus.SC_OK); JsonNode rootNode = objectMapper.readTree(response.getEntity().getContent()); closeResponse(response); assertThatJson(rootNode) .when(Option.IGNORING_EXTRA_FIELDS) .isEqualTo("{" + "data: [ {" + " id: '" + processId + "'," + " processDefinitionId: '" + processInstance.getProcessDefinitionId() + "'," + " processDefinitionUrl: '" + SERVER_URL_PREFIX + RestUrls .createRelativeResourceUrl(RestUrls.URL_PROCESS_DEFINITION, processInstance.getProcessDefinitionId()) + "'," + " variables: [ ]" + "} ]" + "}"); // check that the right process is returned along with the variables // when includeProcessvariable is set url = RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION) + "?businessKey=myBusinessKey&includeProcessVariables=true"; response = executeRequest(new HttpGet(SERVER_URL_PREFIX + url), HttpStatus.SC_OK); rootNode = objectMapper.readTree(response.getEntity().getContent()); closeResponse(response); assertThatJson(rootNode) .when(Option.IGNORING_EXTRA_FIELDS) .isEqualTo("{" + "data: [ {" + " id: '" + processId + "'," + " processDefinitionId: '" + processInstance.getProcessDefinitionId() + "'," + " processDefinitionUrl: '" + SERVER_URL_PREFIX + RestUrls .createRelativeResourceUrl(RestUrls.URL_PROCESS_DEFINITION, processInstance.getProcessDefinitionId()) + "'," + " variables: [ {" + " name: 'myVar1'," + " value: 'myVar1'" + " } ]" + "} ]" + "}"); }
Example 19
Source File: ProcessInstanceCollectionResourceTest.java From flowable-engine with Apache License 2.0 | 4 votes |
/** * Test getting a list of process instance, using all possible filters. */ @Test @Deployment(resources = { "org/flowable/rest/service/api/runtime/ProcessInstanceResourceTest.process-one.bpmn20.xml" }) public void testGetProcessInstances() throws Exception { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("processOne", "myBusinessKey"); String id = processInstance.getId(); runtimeService.addUserIdentityLink(id, "kermit", "whatever"); // Test without any parameters String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION); assertResultsPresentInDataResponse(url, id); // Process instance id url = RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION) + "?id=" + id; assertResultsPresentInDataResponse(url, id); url = RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION) + "?id=anotherId"; assertResultsPresentInDataResponse(url); // Process instance business key url = RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION) + "?businessKey=myBusinessKey"; assertResultsPresentInDataResponse(url, id); url = RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION) + "?businessKey=anotherBusinessKey"; assertResultsPresentInDataResponse(url); url = RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION) + "?businessKeyLike=" + encode("%BusinessKey"); assertResultsPresentInDataResponse(url, id); // Process definition key url = RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION) + "?processDefinitionKey=processOne"; assertResultsPresentInDataResponse(url, id); url = RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION) + "?processDefinitionKey=processTwo"; assertResultsPresentInDataResponse(url); // Process definition id url = RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION) + "?processDefinitionId=" + processInstance.getProcessDefinitionId(); assertResultsPresentInDataResponse(url, id); url = RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION) + "?processDefinitionId=anotherId"; assertResultsPresentInDataResponse(url); // Involved user url = RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION) + "?involvedUser=kermit"; assertResultsPresentInDataResponse(url, id); url = RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION) + "?involvedUser=gonzo"; assertResultsPresentInDataResponse(url); // Active process url = RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION) + "?suspended=false"; assertResultsPresentInDataResponse(url, id); url = RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION) + "?suspended=true"; assertResultsPresentInDataResponse(url); // Suspended process runtimeService.suspendProcessInstanceById(id); url = RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION) + "?suspended=true"; assertResultsPresentInDataResponse(url, id); url = RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION) + "?suspended=false"; assertResultsPresentInDataResponse(url); runtimeService.activateProcessInstanceById(id); // Complete first task in the process to have a subprocess created taskService.complete(taskService.createTaskQuery().processInstanceId(id).singleResult().getId()); ProcessInstance subProcess = runtimeService.createProcessInstanceQuery().superProcessInstanceId(id).singleResult(); assertThat(subProcess).isNotNull(); // Super-process instance id url = RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION) + "?superProcessInstanceId=" + id; assertResultsPresentInDataResponse(url, subProcess.getId()); url = RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION) + "?superProcessInstanceId=anotherId"; assertResultsPresentInDataResponse(url); // Sub-process instance id url = RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION) + "?subProcessInstanceId=" + subProcess.getId(); assertResultsPresentInDataResponse(url, id); url = RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_INSTANCE_COLLECTION) + "?subProcessInstanceId=anotherId"; assertResultsPresentInDataResponse(url); }
Example 20
Source File: ExecutionCollectionResourceTest.java From flowable-engine with Apache License 2.0 | 4 votes |
/** * Test getting a list of executions, using all possible filters. */ @Test @Deployment(resources = { "org/flowable/rest/service/api/runtime/ExecutionResourceTest.process-with-subprocess.bpmn20.xml" }) public void testGetExecutions() throws Exception { ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("processOne", "myBusinessKey"); String id = processInstance.getId(); runtimeService.addUserIdentityLink(id, "kermit", "whatever"); Execution childExecutionInTask = runtimeService.createExecutionQuery().activityId("processTask").singleResult(); assertThat(childExecutionInTask).isNotNull(); Execution childExecutionInSubProcess = runtimeService.createExecutionQuery().activityId("subProcess").singleResult(); assertThat(childExecutionInSubProcess).isNotNull(); // Test without any parameters String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION); assertResultsPresentInDataResponse(url, id, childExecutionInTask.getId(), childExecutionInSubProcess.getId()); // Process instance id url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?id=" + id; assertResultsPresentInDataResponse(url, id); url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?id=anotherId"; assertResultsPresentInDataResponse(url); // Process instance business key url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?processInstanceBusinessKey=myBusinessKey"; assertResultsPresentInDataResponse(url, id); url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?processInstanceBusinessKey=anotherBusinessKey"; assertResultsPresentInDataResponse(url); // Process definition key url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?processDefinitionKey=processOne"; assertResultsPresentInDataResponse(url, id, childExecutionInTask.getId(), childExecutionInSubProcess.getId()); url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?processDefinitionKey=processTwo"; assertResultsPresentInDataResponse(url); // Process definition id url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?processDefinitionId=" + processInstance.getProcessDefinitionId(); assertResultsPresentInDataResponse(url, id, childExecutionInTask.getId(), childExecutionInSubProcess.getId()); url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?processDefinitionId=anotherId"; assertResultsPresentInDataResponse(url); // Parent id url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?parentId=" + id; assertResultsPresentInDataResponse(url, childExecutionInSubProcess.getId()); url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?parentId=anotherId"; assertResultsPresentInDataResponse(url); // Activity id url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?activityId=processTask"; assertResultsPresentInDataResponse(url, childExecutionInTask.getId()); url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?activityId=anotherId"; assertResultsPresentInDataResponse(url); // Without tenant ID, before tenant is set url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?withoutTenantId=true"; assertResultsPresentInDataResponse(url, id, childExecutionInTask.getId(), childExecutionInSubProcess.getId()); // Update the tenant for the deployment managementService.executeCommand(new ChangeDeploymentTenantIdCmd(deploymentId, "myTenant")); // Without tenant ID, after tenant is set url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?withoutTenantId=true"; assertResultsPresentInDataResponse(url); // Tenant id url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?tenantId=myTenant"; assertResultsPresentInDataResponse(url, id, childExecutionInTask.getId(), childExecutionInSubProcess.getId()); url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?tenantId=myTenant2"; assertResultsPresentInDataResponse(url); // Tenant id like url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?tenantIdLike=" + encode("%enant"); assertResultsPresentInDataResponse(url, id, childExecutionInTask.getId(), childExecutionInSubProcess.getId()); url = RestUrls.createRelativeResourceUrl(RestUrls.URL_EXECUTION_COLLECTION) + "?tenantIdLike=" + encode("%whatever"); assertResultsPresentInDataResponse(url); }