Java Code Examples for org.activiti.engine.task.Task#getAssignee()
The following examples show how to use
org.activiti.engine.task.Task#getAssignee() .
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: ActivitiTaskActionService.java From activiti6-boot2 with Apache License 2.0 | 6 votes |
protected void assignTask(User currentUser, Task task, String assigneeIdString) { try { String oldAssignee = task.getAssignee(); taskService.setAssignee(task.getId(), assigneeIdString); // If the old assignee user wasn't part of the involved users yet, make it so addIdentiyLinkForUser(task, oldAssignee, IdentityLinkType.PARTICIPANT); // If the current user wasn't part of the involved users yet, make it so String currentUserIdString = String.valueOf(currentUser.getId()); addIdentiyLinkForUser(task, currentUserIdString, IdentityLinkType.PARTICIPANT); } catch (ActivitiException e) { throw new BadRequestException("Task " + task.getId() + " can't be assigned", e); } }
Example 2
Source File: TraceProcessController.java From activiti-in-action-codes with Apache License 2.0 | 6 votes |
/** * 获取当前节点信息 * * @return */ private void setCurrentTaskInfo(String executionId, String activityId, Map<String, Object> vars) { Task currentTask = taskService.createTaskQuery().executionId(executionId) .taskDefinitionKey(activityId).singleResult(); logger.debug("current task for processInstance: {}", ToStringBuilder.reflectionToString(currentTask)); if (currentTask == null) return; String assignee = currentTask.getAssignee(); if (assignee != null) { User assigneeUser = identityService.createUserQuery().userId(assignee).singleResult(); String userInfo = assigneeUser.getFirstName() + " " + assigneeUser.getLastName() + "/" + assigneeUser.getId(); vars.put("当前处理人", userInfo); vars.put("创建时间", new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(currentTask.getCreateTime())); } else { vars.put("任务状态", "未签收"); } }
Example 3
Source File: TraceProcessController.java From activiti-in-action-codes with Apache License 2.0 | 6 votes |
/** * 获取当前节点信息 * * @return */ private void setCurrentTaskInfo(String executionId, String activityId, Map<String, Object> vars) { Task currentTask = taskService.createTaskQuery().executionId(executionId) .taskDefinitionKey(activityId).singleResult(); logger.debug("current task for processInstance: {}", ToStringBuilder.reflectionToString(currentTask)); if (currentTask == null) return; String assignee = currentTask.getAssignee(); if (assignee != null) { User assigneeUser = identityService.createUserQuery().userId(assignee).singleResult(); String userInfo = assigneeUser.getFirstName() + " " + assigneeUser.getLastName() + "/" + assigneeUser.getId(); vars.put("当前处理人", userInfo); vars.put("创建时间", new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(currentTask.getCreateTime())); } else { vars.put("任务状态", "未签收"); } }
Example 4
Source File: TraceProcessController.java From activiti-in-action-codes with Apache License 2.0 | 6 votes |
/** * 获取当前节点信息 * * @return */ private void setCurrentTaskInfo(String executionId, String activityId, Map<String, Object> vars) { Task currentTask = taskService.createTaskQuery().executionId(executionId) .taskDefinitionKey(activityId).singleResult(); logger.debug("current task for processInstance: {}", ToStringBuilder.reflectionToString(currentTask)); if (currentTask == null) return; String assignee = currentTask.getAssignee(); if (assignee != null) { User assigneeUser = identityService.createUserQuery().userId(assignee).singleResult(); String userInfo = assigneeUser.getFirstName() + " " + assigneeUser.getLastName() + "/" + assigneeUser.getId(); vars.put("当前处理人", userInfo); vars.put("创建时间", new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(currentTask.getCreateTime())); } else { vars.put("任务状态", "未签收"); } }
Example 5
Source File: ActivitiPropertyConverter.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * @param task Task * @param properties Map<QName, Serializable> */ private void setTaskOwner(Task task, Map<QName, Serializable> properties) { QName ownerKey = ContentModel.PROP_OWNER; if (properties.containsKey(ownerKey)) { Serializable owner = properties.get(ownerKey); if (owner != null && !(owner instanceof String)) { throw getInvalidPropertyValueException(ownerKey, owner); } String assignee = (String) owner; String currentAssignee = task.getAssignee(); // Only set the assignee if the value has changes to prevent // triggering assignementhandlers when not needed if (ObjectUtils.equals(currentAssignee, assignee)==false) { activitiUtil.getTaskService().setAssignee(task.getId(), assignee); } } }
Example 6
Source File: TraceProcessController.java From activiti-in-action-codes with Apache License 2.0 | 6 votes |
/** * 获取当前节点信息 * * @return */ private void setCurrentTaskInfo(String executionId, String activityId, Map<String, Object> vars) { Task currentTask = taskService.createTaskQuery().executionId(executionId) .taskDefinitionKey(activityId).singleResult(); logger.debug("current task for processInstance: {}", ToStringBuilder.reflectionToString(currentTask)); if (currentTask == null) return; String assignee = currentTask.getAssignee(); if (assignee != null) { User assigneeUser = identityService.createUserQuery().userId(assignee).singleResult(); String userInfo = assigneeUser.getFirstName() + " " + assigneeUser.getLastName() + "/" + assigneeUser.getId(); vars.put("当前处理人", userInfo); vars.put("创建时间", new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(currentTask.getCreateTime())); } else { vars.put("任务状态", "未签收"); } }
Example 7
Source File: MyCandidateTaskController.java From my_curd with Apache License 2.0 | 6 votes |
/** * 认领任务 */ @Before(IdRequired.class) public void claimAction() { String taskId = getPara("id"); Task task = ActivitiKit.getTaskService().createTaskQuery().taskId(taskId).singleResult(); if (task == null) { renderFail("任务不存在"); return; } if (task.isSuspended()) { renderFail("任务已被暂停"); return; } if (task.getAssignee() != null) { renderFail("任务已被认领"); return; } ActivitiKit.getTaskService().claim(taskId, WebUtils.getSessionUsername(this)); renderSuccess("认领成功"); }
Example 8
Source File: TraceProcessController.java From activiti-in-action-codes with Apache License 2.0 | 6 votes |
/** * 获取当前节点信息 * * @return */ private void setCurrentTaskInfo(String executionId, String activityId, Map<String, Object> vars) { Task currentTask = taskService.createTaskQuery().executionId(executionId) .taskDefinitionKey(activityId).singleResult(); logger.debug("current task for processInstance: {}", ToStringBuilder.reflectionToString(currentTask)); if (currentTask == null) return; String assignee = currentTask.getAssignee(); if (assignee != null) { User assigneeUser = identityService.createUserQuery().userId(assignee).singleResult(); String userInfo = assigneeUser.getFirstName() + " " + assigneeUser.getLastName() + "/" + assigneeUser.getId(); vars.put("当前处理人", userInfo); vars.put("创建时间", new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(currentTask.getCreateTime())); } else { vars.put("任务状态", "未签收"); } }
Example 9
Source File: PlaybackUserTaskCompleteEventHandler.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
@Override public void handle(SimulationEvent event) { String taskId = (String) event.getProperty("taskId"); Task task = SimulationRunContext.getTaskService().createTaskQuery().taskId(taskId).singleResult(); String assignee = task.getAssignee(); @SuppressWarnings("unchecked") Map<String, Object> variables = (Map<String, Object>) event.getProperty("variables"); SimulationRunContext.getTaskService().complete(taskId, variables); log.debug("completed {}, {}, {}, {}", task, task.getName(), assignee, variables); }
Example 10
Source File: WorkflowTraceService.java From maven-framework-project with MIT License | 5 votes |
/** * 设置当前处理人信息 * @param vars * @param currentTask */ private void setCurrentTaskAssignee(Map<String, Object> vars, Task currentTask) { String assignee = currentTask.getAssignee(); if (assignee != null) { User assigneeUser = identityService.createUserQuery().userId(assignee).singleResult(); String userInfo = assigneeUser.getLastName() + " " + assigneeUser.getFirstName(); vars.put("当前处理人", userInfo); } }
Example 11
Source File: IdentityUtils.java From openwebflow with BSD 2-Clause "Simplified" License | 5 votes |
public static List<String> getInvolvedUsers(TaskService taskService, Task task, IdentityMembershipManager membershipManager) throws Exception { Map<String, Object> userIds = new HashMap<String, Object>(); String assignee = task.getAssignee(); //如果直接指定了任务执行人,则忽略其他候选人 if (assignee != null) { userIds.put(assignee, new Object()); } else { for (IdentityLink link : taskService.getIdentityLinksForTask(task.getId())) { String userId = link.getUserId(); if (userId != null) { userIds.put(userId, new Object()); } String groupId = link.getGroupId(); if (groupId != null) { for (String gUserId : membershipManager.findUserIdsByGroup(groupId)) { userIds.put(gUserId, new Object()); } } } } return new ArrayList<String>(userIds.keySet()); }
Example 12
Source File: ActTaskService.java From Shop-for-JavaWeb with MIT License | 5 votes |
/** * 设置当前处理人信息 * @param vars * @param currentTask */ private void setCurrentTaskAssignee(Map<String, Object> vars, Task currentTask) { String assignee = currentTask.getAssignee(); if (assignee != null) { org.activiti.engine.identity.User assigneeUser = identityService.createUserQuery().userId(assignee).singleResult(); String userInfo = assigneeUser.getFirstName() + " " + assigneeUser.getLastName(); vars.put("当前处理人", userInfo); } }
Example 13
Source File: ActivitiWorkflowEngine.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
private WorkflowTask endNormalTask(String taskId, String localTaskId, String transition) { // Retrieve task Task task = taskService.createTaskQuery().taskId(localTaskId).singleResult(); if(task == null) { String msg = messageService.getMessage(ERR_END_UNEXISTING_TASK, taskId); throw new WorkflowException(msg); } // Check if the assignee is equal to the current logged-in user. If not, assign task before ending String currentUserName = AuthenticationUtil.getFullyAuthenticatedUser(); if(task.getAssignee() == null || !task.getAssignee().equals(currentUserName)) { taskService.setAssignee(localTaskId, currentUserName); // Also update pojo used to set the outcome, this will read assignee as wel task.setAssignee(currentUserName); // Re-fetch the task-entity since it's revision has been updated by the setAssignee() call task = taskService.createTaskQuery().taskId(localTaskId).singleResult(); } setOutcome(task, transition); taskService.complete(localTaskId); // The task should have a historicTaskInstance HistoricTaskInstance historicTask = historyService.createHistoricTaskInstanceQuery().taskId(task.getId()).singleResult(); return typeConverter.convert(historicTask); }
Example 14
Source File: ComplaintUserInnerServiceSMOImpl.java From MicroCommunity with Apache License 2.0 | 5 votes |
/** * 获取任务当前处理人 * * @param complaintDto * @return */ public ComplaintDto getTaskCurrentUser(@RequestBody ComplaintDto complaintDto) { TaskService taskService = processEngine.getTaskService(); List<Task> tasks = taskService.createTaskQuery().processInstanceBusinessKey(complaintDto.getComplaintId()).list(); if (tasks == null || tasks.size() == 0) { complaintDto.setCurrentUserId(""); complaintDto.setCurrentUserName(""); complaintDto.setCurrentUserTel(""); return complaintDto; } String userIds = ""; String userNames = ""; String userTels = ""; for (Task task : tasks) { String userId = task.getAssignee(); List<UserDto> users = userInnerServiceSMOImpl.getUserInfo(new String[]{userId}); if (users == null || users.size() == 0) { continue; } userIds += (userId + "/"); userNames += (users.get(0).getName() + "/"); userTels += (users.get(0).getTel() + "/"); } userIds = userIds.endsWith("/") ? userIds.substring(0, userIds.length() - 2) : userIds; userNames = userNames.endsWith("/") ? userNames.substring(0, userNames.length() - 2) : userNames; userTels = userTels.endsWith("/") ? userTels.substring(0, userTels.length() - 2) : userTels; complaintDto.setCurrentUserId(userIds); complaintDto.setCurrentUserName(userNames); complaintDto.setCurrentUserTel(userTels); return complaintDto; }
Example 15
Source File: PurchaseApplyUserInnerServiceSMOImpl.java From MicroCommunity with Apache License 2.0 | 5 votes |
/** * 获取任务当前处理人 * * @param purchaseApplyDto * @return */ public PurchaseApplyDto getTaskCurrentUser(@RequestBody PurchaseApplyDto purchaseApplyDto) { TaskService taskService = processEngine.getTaskService(); Task task = taskService.createTaskQuery().processInstanceBusinessKey(purchaseApplyDto.getApplyOrderId()).singleResult(); if (task == null) { purchaseApplyDto.setStaffId(""); purchaseApplyDto.setStaffName(""); purchaseApplyDto.setStaffTel(""); return purchaseApplyDto; } String userId = task.getAssignee(); List<UserDto> users = userInnerServiceSMOImpl.getUserInfo(new String[]{userId}); if (users == null || users.size() == 0) { purchaseApplyDto.setStaffId(""); purchaseApplyDto.setStaffName(""); purchaseApplyDto.setStaffTel(""); return purchaseApplyDto; } purchaseApplyDto.setCurrentUserId(userId); purchaseApplyDto.setStaffName(users.get(0).getName()); purchaseApplyDto.setStaffTel(users.get(0).getTel()); return purchaseApplyDto; }
Example 16
Source File: BpmTaskServiceImpl.java From hsweb-framework with Apache License 2.0 | 4 votes |
@Override public void complete(CompleteTaskRequest request) { request.tryValidate(); Task task = taskService.createTaskQuery() .taskId(request.getTaskId()) .includeProcessVariables() .active() .singleResult(); Objects.requireNonNull(task, "任务不存在"); String assignee = task.getAssignee(); Objects.requireNonNull(assignee, "任务未签收"); if (!assignee.equals(request.getCompleteUserId())) { throw new BusinessException("只能完成自己的任务"); } Map<String, Object> variable = new HashMap<>(); variable.put("preTaskId", task.getId()); Map<String, Object> transientVariables = new HashMap<>(); if (null != request.getVariables()) { variable.putAll(request.getVariables()); transientVariables.putAll(request.getVariables()); } ProcessInstance instance = runtimeService.createProcessInstanceQuery() .processInstanceId(task.getProcessInstanceId()) .singleResult(); //查询主表的数据作为变量 Optional.of(workFlowFormService.<Map<String, Object>>selectProcessForm(instance.getProcessDefinitionId(), QueryParamEntity.of("processInstanceId", instance.getProcessInstanceId()).doPaging(0, 2))) .map(PagerResult::getData) .map(list -> { if (list.size() == 1) { return list.get(0); } if (list.size() > 1) { logger.warn("主表数据存在多条数据:processInstanceId={}", instance.getProcessInstanceId()); } return null; }) .ifPresent(transientVariables::putAll); //保存表单数据 workFlowFormService.saveTaskForm(instance, task, SaveFormRequest.builder() .userName(request.getCompleteUserName()) .userId(request.getCompleteUserId()) .formData(request.getFormData()) .build()); if (null != request.getFormData()) { transientVariables.putAll(request.getFormData()); } taskService.complete(task.getId(), null, transientVariables); //跳转 if (!StringUtils.isNullOrEmpty(request.getNextActivityId())) { doJumpTask(task, request.getNextActivityId(), (t) -> { }); } //下一步候选人 List<Task> tasks = selectNowTask(task.getProcessInstanceId()); for (Task next : tasks) { setVariablesLocal(next.getId(), variable); if (!StringUtils.isNullOrEmpty(request.getNextClaimUserId())) { taskService.addCandidateUser(next.getId(), request.getNextClaimUserId()); } else { setCandidate(request.getCompleteUserId(), next); } } ProcessHistoryEntity history = ProcessHistoryEntity.builder() .businessKey(instance.getBusinessKey()) .type("complete") .typeText("完成任务") .creatorId(request.getCompleteUserId()) .creatorName(request.getCompleteUserName()) .processDefineId(instance.getProcessDefinitionId()) .processInstanceId(instance.getProcessInstanceId()) .taskId(task.getId()) .taskDefineKey(task.getTaskDefinitionKey()) .taskName(task.getName()) .build(); processHistoryService.insert(history); }
Example 17
Source File: WorkflowRestImpl.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
/** * Validates if the logged in user is allowed to get information about a specific process instance. * If the user is not allowed an exception is thrown. * * @param processId identifier of the process instance */ protected List<HistoricVariableInstance> validateIfUserAllowedToWorkWithProcess(String processId) { List<HistoricVariableInstance> variableInstances = activitiProcessEngine.getHistoryService() .createHistoricVariableInstanceQuery() .processInstanceId(processId) .list(); Map<String, Object> variableMap = new HashMap<String, Object>(); if (variableInstances != null && variableInstances.size() > 0) { for (HistoricVariableInstance variableInstance : variableInstances) { variableMap.put(variableInstance.getVariableName(), variableInstance.getValue()); } } else { throw new EntityNotFoundException(processId); } if (tenantService.isEnabled()) { String tenantDomain = (String) variableMap.get(ActivitiConstants.VAR_TENANT_DOMAIN); if (TenantUtil.getCurrentDomain().equals(tenantDomain) == false) { throw new PermissionDeniedException("Process is running in another tenant"); } } //MNT-17918 - required for initiator variable already updated as NodeRef type Object initiator = variableMap.get(WorkflowConstants.PROP_INITIATOR); String nodeId = ((initiator instanceof ActivitiScriptNode) ? ((ActivitiScriptNode) initiator).getNodeRef().getId() : ((NodeRef) initiator).getId()); if (initiator != null && AuthenticationUtil.getRunAsUser().equals(nodeId)) { // user is allowed return variableInstances; } String username = AuthenticationUtil.getRunAsUser(); if (authorityService.isAdminAuthority(username)) { // Admin is allowed to read all processes in the current tenant return variableInstances; } else { // MNT-12382 check for membership in the assigned group ActivitiScriptNode group = (ActivitiScriptNode) variableMap.get("bpm_groupAssignee"); if (group != null) { // check that the process is unclaimed Task task = activitiProcessEngine.getTaskService().createTaskQuery().processInstanceId(processId).singleResult(); if ((task != null) && (task.getAssignee() == null) && isUserInGroup(username, group.getNodeRef())) { return variableInstances; } } // If non-admin user, involvement in the task is required (either owner, assignee or externally involved). HistoricTaskInstanceQuery query = activitiProcessEngine.getHistoryService() .createHistoricTaskInstanceQuery() .processInstanceId(processId) .taskInvolvedUser(AuthenticationUtil.getRunAsUser()); List<HistoricTaskInstance> taskList = query.list(); if (org.apache.commons.collections.CollectionUtils.isEmpty(taskList)) { throw new PermissionDeniedException("user is not allowed to access information about process " + processId); } } return variableInstances; }
Example 18
Source File: AuthenticatedTimerJobHandler.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
@Override public void execute(final JobEntity job, final String configuration, final ExecutionEntity execution, final CommandContext commandContext) { String userName = null; String tenantToRunIn = (String) execution.getVariable(ActivitiConstants.VAR_TENANT_DOMAIN); if(tenantToRunIn != null && tenantToRunIn.trim().length() == 0) { tenantToRunIn = null; } final ActivitiScriptNode initiatorNode = (ActivitiScriptNode) execution.getVariable(WorkflowConstants.PROP_INITIATOR); // Extracting the properties from the initiatornode should be done in correct tennant or as administrator, since we don't // know who started the workflow yet (We can't access node-properties when no valid authentication context is set up). if(tenantToRunIn != null) { userName = TenantUtil.runAsTenant(new TenantRunAsWork<String>() { @Override public String doWork() throws Exception { return getInitiator(initiatorNode); } }, tenantToRunIn); } else { // No tenant on worklfow, run as admin in default tenant userName = AuthenticationUtil.runAs(new RunAsWork<String>() { @SuppressWarnings("synthetic-access") public String doWork() throws Exception { return getInitiator(initiatorNode); } }, AuthenticationUtil.getSystemUserName()); } // Fall back to task assignee, if no initiator is found if(userName == null) { PvmActivity targetActivity = execution.getActivity(); if (targetActivity != null) { // Only try getting active task, if execution timer is waiting on is a userTask String activityType = (String) targetActivity.getProperty(ActivitiConstants.NODE_TYPE); if (ActivitiConstants.USER_TASK_NODE_TYPE.equals(activityType)) { Task task = new TaskQueryImpl(commandContext) .executionId(execution.getId()) .executeSingleResult(commandContext); if (task != null && task.getAssignee() != null) { userName = task.getAssignee(); } } } } // When no task assignee is set, nor the initiator, use system user to run job if (userName == null) { userName = AuthenticationUtil.getSystemUserName(); tenantToRunIn = null; } if(tenantToRunIn != null) { TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() { @Override public Void doWork() throws Exception { wrappedHandler.execute(job, configuration, execution, commandContext); return null; } }, userName, tenantToRunIn); } else { // Execute the timer without tenant AuthenticationUtil.runAs(new RunAsWork<Void>() { @SuppressWarnings("synthetic-access") public Void doWork() throws Exception { wrappedHandler.execute(job, configuration, execution, commandContext); return null; } }, userName); } }
Example 19
Source File: ActivitiWorkflowEngine.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * {@inheritDoc} */ public List<WorkflowTask> getPooledTasks(List<String> authorities, boolean lazyInitialization) { try { if (authorities != null && authorities.size() > 0) { // As an optimisation, we assume the first authority CAN be a user. All the // others are groups to which the user (or group) belongs. This way, we don't have to // check for the type of the authority. String firstAuthority = authorities.get(0); // Use a map, can be that a task has multiple candidate-groups, which are inside the list // of authorities Map<String, Task> resultingTasks = new HashMap<String, Task>(); if (authorityManager.isUser(firstAuthority)) { // Candidate user addTasksForCandidateUser(firstAuthority, resultingTasks); if(authorities.size() > 1) { List<String> remainingAuthorities = authorities.subList(1, authorities.size()); addTasksForCandidateGroups(remainingAuthorities, resultingTasks); } } else { // Candidate group addTasksForCandidateGroups(authorities, resultingTasks); } List<WorkflowTask> tasks = new ArrayList<WorkflowTask>(); WorkflowTask currentTask = null; // Only tasks that have NO assignee, should be returned for(Task task : resultingTasks.values()) { if(task.getAssignee() == null) { // ALF-12264: filter out tasks from other domain, can occur when tenants // have a group with the same name if(lazyInitialization) { String workflowDefinitionName = typeConverter.getWorkflowDefinitionName(task.getProcessDefinitionId()); try { workflowDefinitionName = tenantService.getBaseName(workflowDefinitionName); currentTask = new LazyActivitiWorkflowTask(task, typeConverter, tenantService, workflowDefinitionName); } catch(RuntimeException re) { // Domain mismatch, don't use this task currentTask = null; } } else { currentTask = typeConverter.convert(task, true); } if(currentTask != null) { tasks.add(currentTask); } } } return tasks; } return Collections.emptyList(); } catch(ActivitiException ae) { String authorityString = null; if(authorities != null) { authorityString = StringUtils.join(authorities.iterator(), ", "); } String msg = messageService.getMessage(ERR_GET_POOLED_TASKS, authorityString); if(logger.isDebugEnabled()) { logger.debug(msg, ae); } throw new WorkflowException(msg, ae); } }
Example 20
Source File: DemoDataGenerator.java From maven-framework-project with MIT License | 4 votes |
protected void generateReportData() { if (generateReportData) { // Report data is generated in background thread Thread thread = new Thread(new Runnable() { public void run() { // We need to temporarily disable the job executor or it would interfere with the process execution ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration().getJobExecutor().shutdown(); Random random = new Random(); Date now = new Date(new Date().getTime() - (24 * 60 * 60 * 1000)); ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration().getClock().setCurrentTime(now); for (int i = 0; i < 50; i++) { if (random.nextBoolean()) { processEngine.getRuntimeService().startProcessInstanceByKey("fixSystemFailure"); } if (random.nextBoolean()) { processEngine.getIdentityService().setAuthenticatedUserId("kermit"); Map<String, Object> variables = new HashMap<String, Object>(); variables.put("customerName", "testCustomer"); variables.put("details", "Looks very interesting!"); variables.put("notEnoughInformation", false); processEngine.getRuntimeService().startProcessInstanceByKey("reviewSaledLead", variables); } if (random.nextBoolean()) { processEngine.getRuntimeService().startProcessInstanceByKey("escalationExample"); } if (random.nextInt(100) < 20) { now = new Date(now.getTime() - ((24 * 60 * 60 * 1000) - (60 * 60 * 1000))); ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration().getClock().setCurrentTime(now); } } List<Job> jobs = processEngine.getManagementService().createJobQuery().list(); for (int i = 0; i < jobs.size() / 2; i++) { ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration().getClock().setCurrentTime(jobs.get(i).getDuedate()); processEngine.getManagementService().executeJob(jobs.get(i).getId()); } List<Task> tasks = processEngine.getTaskService().createTaskQuery().list(); while (tasks.size() > 0) { for (Task task : tasks) { if (task.getAssignee() == null) { String assignee = random.nextBoolean() ? "kermit" : "fozzie"; processEngine.getTaskService().claim(task.getId(), assignee); } ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration().getClock().setCurrentTime(new Date(task.getCreateTime().getTime() + random.nextInt(60 * 60 * 1000))); processEngine.getTaskService().complete(task.getId()); } tasks = processEngine.getTaskService().createTaskQuery().list(); } ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration().getClock().reset(); ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration().getJobExecutor().start(); LOGGER.info("Demo report data generated"); } }); thread.start(); } }