@Deployment public void testExpression() { // Set the clock fixed HashMap<String, Object> variables1 = new HashMap<String, Object>(); variables1.put("dueDate", new Date()); HashMap<String, Object> variables2 = new HashMap<String, Object>(); variables2.put("dueDate", new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").format(new Date())); // After process start, there should be timer created ProcessInstance pi1 = runtimeService.startProcessInstanceByKey("intermediateTimerEventExample", variables1); ProcessInstance pi2 = runtimeService.startProcessInstanceByKey("intermediateTimerEventExample", variables2); assertEquals(1, managementService.createJobQuery().processInstanceId(pi1.getId()).count()); assertEquals(1, managementService.createJobQuery().processInstanceId(pi2.getId()).count()); // After setting the clock to one second in the future the timers should fire List<Job> jobs = managementService.createJobQuery().executable().list(); assertEquals(2, jobs.size()); for (Job job : jobs) { managementService.executeJob(job.getId()); } assertEquals(0, managementService.createJobQuery().processInstanceId(pi1.getId()).count()); assertEquals(0, managementService.createJobQuery().processInstanceId(pi2.getId()).count()); assertProcessEnded(pi1.getProcessInstanceId()); assertProcessEnded(pi2.getProcessInstanceId()); }
/** TestCase to reproduce Issue ACT-1344 */ @Deployment public void testNonInterruptingSignalWithSubProcess() { ProcessInstance pi = runtimeService.startProcessInstanceByKey("nonInterruptingSignalWithSubProcess"); List<Task> tasks = taskService.createTaskQuery().processInstanceId(pi.getProcessInstanceId()).list(); assertEquals(1, tasks.size()); Task currentTask = tasks.get(0); assertEquals("Approve", currentTask.getName()); runtimeService.signalEventReceived("alert"); tasks = taskService.createTaskQuery().processInstanceId(pi.getProcessInstanceId()).list(); assertEquals(2, tasks.size()); for (Task task : tasks) { if (!task.getName().equals("Approve") && !task.getName().equals("Review")) { fail("Expected: <Approve> or <Review> but was <" + task.getName() + ">."); } } taskService.complete(taskService.createTaskQuery().taskName("Approve").singleResult().getId()); tasks = taskService.createTaskQuery().processInstanceId(pi.getProcessInstanceId()).list(); assertEquals(1, tasks.size()); currentTask = tasks.get(0); assertEquals("Review", currentTask.getName()); taskService.complete(taskService.createTaskQuery().taskName("Review").singleResult().getId()); tasks = taskService.createTaskQuery().processInstanceId(pi.getProcessInstanceId()).list(); assertEquals(1, tasks.size()); }
@Test @Deployment(resources = {PROCESS_RESOURCE}) public void processRejected() throws InterruptedException { Map<String, Object> procVars = createStartFormVariables(); ProcessInstance pi = activitiRule .getProcessEngine() .getRuntimeService() .startProcessInstanceByKey(PROCESS_KEY, procVars); // assertNotNull(pi); Task task = activitiRule.getTaskService().createTaskQuery().singleResult(); // assertNotNull(task); Map<String, Object> taskVars = new HashMap<String, Object>(); taskVars.put("decide", "reject"); activitiRule.getProcessEngine().getTaskService().complete(task.getId(), taskVars); HistoryService historyService = activitiRule.getHistoryService(); HistoricProcessInstance historicProcessInstance = historyService .createHistoricProcessInstanceQuery() .processInstanceId(pi.getProcessInstanceId()) .singleResult(); // assertNotNull(historicProcessInstance); // check that only one process running // assertEquals(pi.getProcessInstanceId(), historicProcessInstance.getId()); List<HistoricActivityInstance> activityList = historyService .createHistoricActivityInstanceQuery() .processInstanceId(pi.getProcessInstanceId()) .list(); JobQuery jquery = activitiRule.getManagementService().createJobQuery(); // check how many tasks must be done // assertEquals("done task count", 6, activityList.size()); // and the job is done // assertEquals("job is done", 0, jquery.count()); // assertEquals(0, activitiRule.getProcessEngine().getRuntimeService() // .createProcessInstanceQuery().count()); }
@Override protected Object doExecute() throws Exception { ProcessEngine processEngine = this.getProcessEngine(); if (processEngine == null) { out().println("Process Engine NOT Found!"); return null; } RuntimeService runtimeService = processEngine.getRuntimeService(); if (this.instanceIDs != null && this.instanceIDs.length > 0) { for (String instanceID : instanceIDs) { runtimeService.deleteProcessInstance(instanceID, "Forcefully terminating the instance"); out().printf("Process instance %s terminated\n", instanceID); } return null; } if (!killAll) { out().println("Process instance IDs required or use the command with -a or --all option"); return null; } else { out().println("Signalling all executions in all active process instances..."); List<ProcessInstance> piList = runtimeService.createProcessInstanceQuery().orderByProcessInstanceId().asc().list(); for (ProcessInstance pi : piList) { String instanceID = pi.getProcessInstanceId(); runtimeService.deleteProcessInstance(instanceID, "Forcefully terminating the instance"); out().printf("Process instance %s terminated\n", instanceID); } } return null; }
@Override public String startPoolManagementProcess(String businessKey, Pool pool) { Map<String, Object> arguments = Maps.newHashMap(); arguments.put(CoreProcessVariables.POOL, pool); arguments.put(CoreProcessVariables.PROVIDER, getId()); arguments.put(CoreProcessVariables.POOL_BUSINESS_KEY, businessKey); arguments.put( CoreProcessVariables.BOOTSTRAP_TIMEOUT, convertTimeoutToISO8601TimeDuration(pool.getBootstrapTimeInSeconds())); /* needed because the Activiti EL doesn't work as expected and properties can't be read from the pool. */ arguments.put( ProcessVariables.SPOT_BID, pool.getProvider().getOption(ProviderOptions.SPOT_BID)); /* Authenticate as kermit to make the process visible in the Explorer UI */ processEngine .getIdentityService() .setAuthenticatedUserId(CoreConstants.ACTIVITI_EXPLORER_DEFAULT_USER); ProcessInstance instance = processEngine .getRuntimeService() .startProcessInstanceByKey(MANAGEMENT_PROCESS_KEY, businessKey, arguments); return instance.getProcessInstanceId(); }
/** * easyui 运行中流程列表数据 * * @param request * @param response * @param dataGrid */ @RequestMapping(params = "runningProcessDataGrid") public void runningProcessDataGrid( HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) { /* * List<HistoricProcessInstance> historicProcessInstances = * historyService .createHistoricProcessInstanceQuery() * .unfinished().list(); */ ProcessInstanceQuery processInstanceQuery = runtimeService.createProcessInstanceQuery(); List<ProcessInstance> list = processInstanceQuery.list(); StringBuffer rows = new StringBuffer(); for (ProcessInstance hi : list) { rows.append( "{'id':" + hi.getId() + ",'processDefinitionId':'" + hi.getProcessDefinitionId() + "','processInstanceId':'" + hi.getProcessInstanceId() + "','activityId':'" + hi.getActivityId() + "'},"); } String rowStr = StringUtils.substringBeforeLast(rows.toString(), ","); JSONObject jObject = JSONObject.fromObject("{'total':" + list.size() + ",'rows':[" + rowStr + "]}"); responseDatagrid(response, jObject); }
@Override public void deleteProcessInstance(Long dossierId) { ProcessInstance pi = runtimeService .createProcessInstanceQuery() .processInstanceBusinessKey(dossierId.toString()) .singleResult(); if (pi != null) { runtimeService.deleteProcessInstance(pi.getProcessInstanceId(), "delete from back office"); } }
private void createNewProcess() { processInstance = runtimeService.startProcessInstanceByKey("myProcess"); assertNotNull(processInstance.getId()); identityService = processEngine.getIdentityService(); taskService = processEngine.getTaskService(); pid = processInstance.getProcessInstanceId(); formService = processEngine.getFormService(); runtimeService.setVariable(pid, "mailvar1", "value1"); runtimeService.setVariable(pid, "mailvar2", "value2"); }
@Test @Deployment(resources = {PROCESS_RESOURCE}) public void startProcessInstance() throws InterruptedException { Map<String, Object> procVars = createStartFormVariables(); ProcessInstance pi = activitiRule .getProcessEngine() .getRuntimeService() .startProcessInstanceByKey(PROCESS_KEY, procVars); // assertNotNull(pi); activitiRule .getProcessEngine() .getRuntimeService() .deleteProcessInstance(pi.getProcessInstanceId(), "not needed, created only for test"); }
@Deployment public void testTimerEventWithStartAndDuration() throws Exception { Date testStartTime = new Date(); processEngineConfiguration.getClock().setCurrentTime(testStartTime); ProcessInstance pi = runtimeService.startProcessInstanceByKey("timerEventWithStartAndDuration"); List<Task> tasks = taskService.createTaskQuery().list(); assertEquals(1, tasks.size()); Task task = tasks.get(0); assertEquals("Task A", task.getName()); JobQuery jobQuery = managementService.createJobQuery().processInstanceId(pi.getId()); assertEquals(0, jobQuery.count()); Date startDate = new Date(); runtimeService.setVariable(pi.getId(), "StartDate", startDate); taskService.complete(task.getId()); jobQuery = managementService.createJobQuery().processInstanceId(pi.getId()); assertEquals(1, jobQuery.count()); processEngineConfiguration.getClock().setCurrentTime(new Date(startDate.getTime() + 7000L)); jobQuery = managementService.createJobQuery().processInstanceId(pi.getId()); assertEquals(1, jobQuery.count()); jobQuery = managementService.createJobQuery().processInstanceId(pi.getId()).executable(); assertEquals(0, jobQuery.count()); processEngineConfiguration.getClock().setCurrentTime(new Date(startDate.getTime() + 11000L)); waitForJobExecutorToProcessAllJobs(15000L, 25L); jobQuery = managementService.createJobQuery().processInstanceId(pi.getId()); assertEquals(0, jobQuery.count()); tasks = taskService.createTaskQuery().list(); assertEquals(1, tasks.size()); task = tasks.get(0); assertEquals("Task B", task.getName()); taskService.complete(task.getId()); assertProcessEnded(pi.getProcessInstanceId()); }
@Deployment public void testCatchingTimerEvent() throws Exception { // Set the clock fixed Date startTime = new Date(); // After process start, there should be timer created ProcessInstance pi = runtimeService.startProcessInstanceByKey("intermediateTimerEventExample"); JobQuery jobQuery = managementService.createJobQuery().processInstanceId(pi.getId()); assertEquals(1, jobQuery.count()); // After setting the clock to time '50minutes and 5 seconds', the second timer should fire processEngineConfiguration .getClock() .setCurrentTime(new Date(startTime.getTime() + ((50 * 60 * 1000) + 5000))); waitForJobExecutorToProcessAllJobs(5000L, 25L); assertEquals(0, jobQuery.count()); assertProcessEnded(pi.getProcessInstanceId()); }
@Override public String startPoolManagementProcess(String businessKey, Pool pool) { Map<String, Object> arguments = Maps.newHashMap(); arguments.put(CoreProcessVariables.POOL, pool); arguments.put(CoreProcessVariables.PROVIDER, getId()); arguments.put(CoreProcessVariables.POOL_BUSINESS_KEY, businessKey); arguments.put( CoreProcessVariables.BOOTSTRAP_TIMEOUT, convertTimeoutToISO8601TimeDuration(pool.getBootstrapTimeInSeconds())); /* Authenticate as kermit to make the process visible in the Explorer UI */ processEngine .getIdentityService() .setAuthenticatedUserId(CoreConstants.ACTIVITI_EXPLORER_DEFAULT_USER); RuntimeService runtimeService = processEngine.getRuntimeService(); ProcessInstance instance = runtimeService.startProcessInstanceByKey(PROCESS_KEY, businessKey, arguments); return instance.getProcessInstanceId(); }
public void fireCustomerRules(DelegateExecution execution) throws Exception { DunningProcessMaster dpMaster = dunningProcessService.initializeDunningProcessMaster(execution); if (dpMaster == null) return; // dpMaster = dunningProcessMasterRepository.findOne(dpMaster.getProcessId()); // if(Constants.ERROR.equalsIgnoreCase(dpMaster.getStatus().getId())) return; String processStatusDesc = null; Long customerId = (Long) execution.getVariable(Constants.customerId); Customer customer = customerService.findOne(customerId); CustomerGroup group = customerService.getCustomerGroup(customer.getCustomerGroup().getGroupId()); Map execMap = executeRules(Constants.RULES_PROCESS_STARTUP, null, group, customer); String bpmProcessName = (String) execMap.get("bpmProcess"); if (bpmProcessName == null) processStatusDesc = Constants.BPM_PROCESS_NOT_FOUND; if (Constants.FL99_MustNotInDunningProcess.equals(bpmProcessName)) processStatusDesc = Constants.CUSTOMER_MUST_NOT_IN_DUNNING; if (processStatusDesc == null) { Long userSelectedProcessStep = (Long) execution.getVariable(Constants.userSelectedProcessStep); DunningPolicy dunningPolicy = dunningPolicyRepository.findDunningPolicyByName(bpmProcessName, new Date()); boolean policyHasStep = false; List<ProcessSteps> processSteps = dunningPolicyRepository.retrieveDunningProcessSteps(dunningPolicy.getPolicyId()); if (userSelectedProcessStep != null) { for (ProcessSteps processStep : processSteps) { if (processStep.getStepId() == userSelectedProcessStep) { policyHasStep = true; dpMaster.setNextStepId(processStep); break; // variables.put(Constants.userSelectedProcessStep, // execution.getVariable(Constants.userSelectedProcessStep)); } } if (!policyHasStep) processStatusDesc = Constants.USER_DEFINED_PROCESS_NOT_ASSIGNABLE; } else { dpMaster.setNextStepId(processSteps.get(1)); } dpMaster.setDunningPolicyId(dunningPolicy); } if (processStatusDesc == null) { Map<String, Object> variables = new HashMap<String, Object>(); variables.put(Constants.user, execution.getVariable(Constants.user)); variables.put(Constants.customerId, customer.getCustomerId()); variables.put(Constants.dunningProcessMaster, dpMaster.getProcessId()); variables.put(Constants.firstStepNext, execution.getVariable(Constants.firstStepNext)); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(bpmProcessName, variables); dpMaster.setBpmProcessId(processInstance.getProcessInstanceId()); } else { dpMaster.setStatus(dunningProcessMasterRepository.getProcessStatus(Constants.ERROR)); dpMaster.setStatusDesc(processStatusDesc); } customer.setDunningProcessMaster(dpMaster); customerService.saveCustomer(customer); dunningProcessService.saveDunningProcessMaster(dpMaster); }
/** @param instances */ public void suspendProcessInstanceById(List<ProcessInstance> instances) { for (ProcessInstance instance : instances) { suspendProcessInstanceById(instance.getProcessInstanceId()); } }
/** Verifies the solution of https://jira.codehaus.org/browse/ACT-1309 */ @Deployment public void testSignalBoundaryOnSubProcess() { ProcessInstance pi = runtimeService.startProcessInstanceByKey("signalEventOnSubprocess"); runtimeService.signalEventReceived("stopSignal"); assertProcessEnded(pi.getProcessInstanceId()); }