@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(); }
/** @param args */ public static void main(String[] args) { // 创建流程引擎 ProcessEngine engine = ProcessEngines.getDefaultProcessEngine(); // 得到流程存储服务组件 RepositoryService repositoryService = engine.getRepositoryService(); // 得到运行时服务组件 RuntimeService runtimeService = engine.getRuntimeService(); // 获取流程任务组件 TaskService taskService = engine.getTaskService(); // 部署流程文件 repositoryService .createDeployment() .addClasspathResource("bpmn11.5/SignalBoundaryEvent.bpmn") .deploy(); // 启动2个流程实例 ProcessInstance pi1 = runtimeService.startProcessInstanceByKey("sbProcess"); ProcessInstance pi2 = runtimeService.startProcessInstanceByKey("sbProcess"); // 查找第一个流程实例中签订合同的任务 Task pi1Task = taskService.createTaskQuery().processInstanceId(pi1.getId()).singleResult(); taskService.complete(pi1Task.getId()); // 查找第二个流程实例中签订合同的任务 Task pi2Task = taskService.createTaskQuery().processInstanceId(pi2.getId()).singleResult(); taskService.complete(pi2Task.getId()); // 此时执行流到达确认合同任务,发送一次信号 runtimeService.signalEventReceived("contactChangeSignal"); // 查询全部的任务 List<Task> tasks = taskService.createTaskQuery().list(); // 输出结果 for (Task task : tasks) { System.out.println(task.getProcessInstanceId() + "---" + task.getName()); } }
@Test public void testService() throws Exception { assertNotNull(runtimeService); ProcessEngine processEngine = factoryBean.getObject(); assertNotNull(processEngine.getRuntimeService()); }
/** * 发起流程页面(启动一个流程实例)内置流程表单方式 * * @return */ public String prepareStartProcessInstance() { RepositoryService repositoryService = processEngine.getRepositoryService(); FormService formService = processEngine.getFormService(); startFormData = formService.getStartFormData(processDefinitionId); return "prepareStartProcessInstance"; }
@Test public void testAcknowledgement() { TaskService taskService = processEngine.getTaskService(); FormService formService = processEngine.getFormService(); List<Task> tasks = taskService .createTaskQuery() .taskAssignee("kermit") .processInstanceId(processInstance.getId()) .list(); assertEquals(1, tasks.size()); assertEquals("get acknowledgement", tasks.get(0).getName()); for (Task task : tasks) { Map<String, String> formData = new HashMap<String, String>(); formService.submitTaskFormData(task.getId(), formData); // Stack trace starts here } tasks = taskService .createTaskQuery() .taskAssignee("kermit") .processInstanceId(processInstance.getId()) .list(); assertEquals(0, tasks.size()); }
public String startProcess( String userId, String businessKey, String processDefinitionId, Map<String, Object> processParameters) { // 先设置登录用户 IdentityService identityService = processEngine.getIdentityService(); identityService.setAuthenticatedUserId(userId); ProcessInstance processInstance = processEngine .getRuntimeService() .startProcessInstanceById(processDefinitionId, businessKey, processParameters); // {流程标题:title}-{发起人:startUser}-{发起时间:startTime} String processDefinitionName = processEngine .getRepositoryService() .createProcessDefinitionQuery() .processDefinitionId(processDefinitionId) .singleResult() .getName(); String processInstanceName = processDefinitionName + "-" + userConnector.findById(userId).getDisplayName() + "-" + new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date()); processEngine .getRuntimeService() .setProcessInstanceName(processInstance.getId(), processInstanceName); return processInstance.getId(); }
@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; }
@Test public void testCouponValidation() { TaskService taskService = processEngine.getTaskService(); FormService formService = processEngine.getFormService(); List<Task> tasks = taskService .createTaskQuery() .taskAssignee("kermit") .processInstanceId(processInstance.getId()) .list(); assertEquals(1, tasks.size()); /** Invalid coupon hash */ for (Task task : tasks) { assertNotNull(task); assertEquals("get coupon", task.getName()); Map<String, String> formData = new HashMap<String, String>(); formData.put("hash", "abc"); formService.submitTaskFormData(task.getId(), formData); break; } tasks = taskService .createTaskQuery() .taskAssignee("kermit") .processInstanceId(processInstance.getId()) .list(); assertEquals(1, tasks.size()); /** Valid coupon hash */ for (Task task : tasks) { assertNotNull(task); assertEquals("get coupon", task.getName()); Map<String, String> formData = new HashMap<String, String>(); formData.put("hash", "abcd"); formService.submitTaskFormData(task.getId(), formData); break; } // check if the price was reduced correctly Object price = runtimeService.getVariable(processInstance.getId(), "price"); assertNotNull(price); assertEquals(new Double(130), price); // 'get bank transfer data' should be next on the list tasks = taskService .createTaskQuery() .taskAssignee("kermit") .processInstanceId(processInstance.getId()) .list(); assertEquals(1, tasks.size()); assertEquals("get bank transfer data", tasks.get(0).getName()); }
/** * 完成任务页面 * * @return */ public String prepareCompleteTask() { TaskService taskService = processEngine.getTaskService(); FormService formService = processEngine.getFormService(); taskFormData = formService.getTaskFormData(taskId); return "prepareCompleteTask"; }
@Test public void testBankTransferValidation() { TaskService taskService = processEngine.getTaskService(); FormService formService = processEngine.getFormService(); List<Task> tasks = taskService .createTaskQuery() .taskAssignee("kermit") .processInstanceId(processInstance.getId()) .list(); assertEquals(1, tasks.size()); // Invalid bank data for (Task task : tasks) { assertNotNull(task); assertEquals("get bank transfer data", task.getName()); Map<String, String> formData = new HashMap<String, String>(); formData.put("bankName", "Bank austria"); // invalid bank-name formData.put("bankCode", "12000"); formData.put("accountNumber", "12345678901"); formData.put("holdersName", "Max Muster"); formService.submitTaskFormData(task.getId(), formData); } tasks = taskService .createTaskQuery() .taskAssignee("kermit") .processInstanceId(processInstance.getId()) .list(); assertEquals(1, tasks.size()); // As of an error the form should be empty assertEquals(0, formService.getTaskFormData(tasks.get(0).getId()).getFormProperties().size()); // Valid bank data for (Task task : tasks) { assertNotNull(task); assertEquals("get bank transfer data", task.getName()); Map<String, String> formData = new HashMap<String, String>(); formData.put("bankName", "Bank Austria"); formData.put("bankCode", "12000"); formData.put("accountNumber", "12345678901"); formData.put("holdersName", "Max Muster"); formService.submitTaskFormData(task.getId(), formData); // Stack trace starts here } tasks = taskService .createTaskQuery() .taskAssignee("kermit") .processInstanceId(processInstance.getId()) .list(); assertEquals(1, tasks.size()); assertEquals("get acknowledgement", tasks.get(0).getName()); }
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 public void testSetAssignee() { ProcessEngine engine = ProcessEngines.getDefaultProcessEngine(); IdentityService identityService = engine.getIdentityService(); User user = creatUser(identityService, "user1", "张三", "last", "*****@*****.**", "123"); TaskService taskService = engine.getTaskService(); Task task1 = taskService.newTask("task1"); task1.setName("申请任务"); taskService.saveTask(task1); taskService.setAssignee(task1.getId(), user.getId()); System.out.println( "用户张三受理的任务数量:" + taskService.createTaskQuery().taskAssignee(user.getId()).count()); }
protected void dropUsers() { IdentityService identityService = processEngine.getIdentityService(); identityService.deleteUser("kermit"); identityService.deleteGroup("admin"); identityService.deleteMembership("kermit", "admin"); }
public String listHistoricTasks() { HistoryService historyService = processEngine.getHistoryService(); historicTaskInstances = historyService.createHistoricTaskInstanceQuery().list(); return "listHistoricTasks"; }
/** 流程实例. */ public String listProcessInstances() { RuntimeService runtimeService = processEngine.getRuntimeService(); processInstances = runtimeService.createProcessInstanceQuery().list(); return "listProcessInstances"; }
public String activeProcessDefinition() { RepositoryService repositoryService = processEngine.getRepositoryService(); repositoryService.activateProcessDefinitionById(processDefinitionId); return RELOAD_PROCESS_DEFINITION; }
/** * easyui AJAX请求数据 待办任务 * * @param request * @param response * @param dataGrid */ @RequestMapping(params = "claimedTaskDataGrid") public void claimedTaskDataGrid( HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) { // String userId = "leaderuser"; String userId = ResourceUtil.getSessionUserName().getId(); TaskService taskService = processEngine.getTaskService(); List<Task> tasks = taskService.createTaskQuery().taskAssignee(userId).list(); StringBuffer rows = new StringBuffer(); for (Task t : tasks) { rows.append( "{'name':'" + t.getName() + "','description':'" + t.getDescription() + "','taskId':'" + t.getId() + "','processDefinitionId':'" + t.getProcessDefinitionId() + "','processInstanceId':'" + t.getProcessInstanceId() + "'},"); } String rowStr = StringUtils.substringBeforeLast(rows.toString(), ","); JSONObject jObject = JSONObject.fromObject("{'total':" + tasks.size() + ",'rows':[" + rowStr + "]}"); responseDatagrid(response, jObject); }
public String deploy() throws Exception { RepositoryService repositoryService = processEngine.getRepositoryService(); ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes("UTF-8")); repositoryService.createDeployment().addInputStream("process.bpmn20.xml", bais).deploy(); return RELOAD_PROCESS_DEFINITION; }
/** * 代领任务(组任务) * * @return */ public String listGroupTasks() { TaskService taskService = processEngine.getTaskService(); String username = SpringSecurityUtils.getCurrentUsername(); tasks = taskService.createTaskQuery().taskCandidateUser(username).list(); return "listGroupTasks"; }
protected void setTenantAndName(ActivityExecution execution) { Map beans = Context.getProcessEngineConfiguration().getBeans(); ProcessEngine pe = (ProcessEngine) beans.get("processEngine"); String processDefinitionId = ((ExecutionEntity) execution).getProcessDefinitionId(); RepositoryService repositoryService = pe.getRepositoryService(); ProcessDefinition processDefinition = repositoryService .createProcessDefinitionQuery() .processDefinitionId(processDefinitionId) .singleResult(); m_tenant = processDefinition.getTenantId(); m_processDefinitionKey = processDefinition.getKey(); info("ID:" + processDefinition.getId()); info("Name:" + processDefinition.getName()); info("Key:" + processDefinition.getKey()); }
/** * 待办任务(个人任务) * * @return */ public String listPersonalTasks() { TaskService taskService = processEngine.getTaskService(); String username = SpringSecurityUtils.getCurrentUsername(); tasks = taskService.createTaskQuery().taskAssignee(username).list(); return "listPersonalTasks"; }
@Test public void test() { ProcessEngine engine = ProcessEngines.getDefaultProcessEngine(); RepositoryService repositoryService = engine.getRepositoryService(); RuntimeService runtimeService = engine.getRuntimeService(); TaskService taskService = engine.getTaskService(); repositoryService.createDeployment().addClasspathResource("bpmn/first.bpmn").deploy(); runtimeService.startProcessInstanceByKey("process1"); Task task = taskService.createTaskQuery().singleResult(); System.out.println("第一个任务完成前,当前任务名称:" + task.getName()); taskService.complete(task.getId()); task = taskService.createTaskQuery().singleResult(); System.out.println("第二个任务完成前,当前任务名称:" + task.getName()); taskService.complete(task.getId()); task = taskService.createTaskQuery().singleResult(); System.out.println("流程结束后,查找任务:" + task); }
/** * 认领任务(对应的是在组任务,即从组任务中领取任务) * * @return */ public String claimTask() { String username = SpringSecurityUtils.getCurrentUsername(); TaskService taskService = processEngine.getTaskService(); taskService.claim(taskId, username); return RELOAD; }
/** * 读取带跟踪的流程图片 * * @throws Exception */ @RequestMapping(params = "traceImage") public void traceImage( @RequestParam("processInstanceId") String processInstanceId, HttpServletResponse response) throws Exception { Command<InputStream> cmd = new HistoryProcessInstanceDiagramCmd(processInstanceId); ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); InputStream is = processEngine.getManagementService().executeCommand(cmd); int len = 0; byte[] b = new byte[1024]; while ((len = is.read(b, 0, 1024)) != -1) { response.getOutputStream().write(b, 0, len); } }
/** * 已办任务(历史任务) * * @return */ public String listHistoryTasks() { HistoryService historyService = processEngine.getHistoryService(); String username = SpringSecurityUtils.getCurrentUsername(); historicTasks = historyService.createHistoricTaskInstanceQuery().taskAssignee(username).finished().list(); return "listHistoryTasks"; }
public synchronized ProcessEngine installProcessArchive(ProcessArchive processArchive) { final String paName = processArchive.getName(); if (!isActive) { throw new FoxPlatformException( "Cannot install process archive with name " + paName + ": ProcessEngineService is not active."); } if (installedProcessArchivesByName.containsKey(paName)) { throw new FoxPlatformException( "Cannot install process archive with name '" + paName + "': process archive with same name already installed."); } log.info("Installing process archive '" + paName + "'"); Deployment deployment = performEngineDeployment(processArchive); ProcessArchiveContext processArchiveContext = new ProcessArchiveContext(deployment, processArchive); processArchiveContext.setActive(true); installedProcessArchivesByName.put(processArchive.getName(), processArchiveContext); ArrayList<ProcessArchive> processArchives = new ArrayList<ProcessArchive>(cachedProcessArchives); processArchives.add(processArchive); cachedProcessArchives = Collections.unmodifiableList(processArchives); if (deployment != null) { List<ProcessDefinition> processDefinitionsForThisDeployment = activitiProcessEngine .getRepositoryService() .createProcessDefinitionQuery() .deploymentId(deployment.getId()) .list(); for (ProcessDefinition processDefinition : processDefinitionsForThisDeployment) { installedProcessArchivesByProcessDefinitionKey.put( processDefinition.getKey(), processArchiveContext); } log.info( "Installed process archive '" + paName + "' to process engine '" + processEngineName + "'."); return activitiProcessEngine; } else { log.info( "Installed empty process archive '" + paName + "'. Process archive will have access to process engine with name '" + processEngineName + "'."); return activitiProcessEngine; } }
@BeforeClass public static void init() throws FileNotFoundException { servers = new AllServers(); servers.start(); // Create Activiti process engine processEngine = ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration() .buildProcessEngine(); RepositoryService repositoryService = processEngine.getRepositoryService(); DeploymentBuilder builder = repositoryService.createDeployment(); String xmlFile = "PaymentProcess.bpmn"; builder.addClasspathResource("diagrams/" + xmlFile); builder.name(xmlFile); builder.deploy(); runtimeService = processEngine.getRuntimeService(); }
/** * 发起流程 * * @return */ public String startProcessInstance() { IdentityService identityService = processEngine.getIdentityService(); identityService.setAuthenticatedUserId(SpringSecurityUtils.getCurrentUsername()); FormService formService = processEngine.getFormService(); StartFormData startFormData = formService.getStartFormData(processDefinitionId); HttpServletRequest request = ServletActionContext.getRequest(); Map<String, String> map = new HashMap<String, String>(); for (FormProperty formProperty : startFormData.getFormProperties()) { String name = formProperty.getId(); map.put(name, request.getParameter(name)); } formService.submitStartFormData(processDefinitionId, map); return RELOAD; }
/** * 级联删除流程定义 * * @return */ public String removeProcessDefinition() { RepositoryService repositoryService = processEngine.getRepositoryService(); ProcessDefinition processDefinition = repositoryService.getProcessDefinition(processDefinitionId); repositoryService.deleteDeployment(processDefinition.getDeploymentId(), true); return RELOAD_PROCESS_DEFINITION; }
/** 完成我的任务 */ @Test public void completeMyTask() { String taskIdString = "402"; processEngine .getTaskService() // 与正在执行的任务管理相关的service .complete(taskIdString); System.out.println("完成任务:任务ID" + taskIdString); System.out.println("完成任务:任务ID" + taskIdString); }