コード例 #1
0
 /** @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());
   }
 }
コード例 #2
0
  /**
   * 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);
  }
コード例 #3
0
  /**
   * 待办任务(个人任务)
   *
   * @return
   */
  public String listPersonalTasks() {
    TaskService taskService = processEngine.getTaskService();
    String username = SpringSecurityUtils.getCurrentUsername();
    tasks = taskService.createTaskQuery().taskAssignee(username).list();

    return "listPersonalTasks";
  }
コード例 #4
0
  @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());
  }
コード例 #5
0
  /**
   * 代领任务(组任务)
   *
   * @return
   */
  public String listGroupTasks() {
    TaskService taskService = processEngine.getTaskService();
    String username = SpringSecurityUtils.getCurrentUsername();
    tasks = taskService.createTaskQuery().taskCandidateUser(username).list();

    return "listGroupTasks";
  }
コード例 #6
0
  /**
   * 认领任务(对应的是在组任务,即从组任务中领取任务)
   *
   * @return
   */
  public String claimTask() {
    String username = SpringSecurityUtils.getCurrentUsername();

    TaskService taskService = processEngine.getTaskService();
    taskService.claim(taskId, username);

    return RELOAD;
  }
コード例 #7
0
  @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());
  }
コード例 #8
0
  /**
   * 完成任务页面
   *
   * @return
   */
  public String prepareCompleteTask() {
    TaskService taskService = processEngine.getTaskService();

    FormService formService = processEngine.getFormService();

    taskFormData = formService.getTaskFormData(taskId);

    return "prepareCompleteTask";
  }
コード例 #9
0
ファイル: HelloWorld.java プロジェクト: liuwu0720/DEMO
 /** 完成我的任务 */
 @Test
 public void completeMyTask() {
   String taskIdString = "402";
   processEngine
       .getTaskService() // 与正在执行的任务管理相关的service
       .complete(taskIdString);
   System.out.println("完成任务:任务ID" + taskIdString);
   System.out.println("完成任务:任务ID" + taskIdString);
 }
コード例 #10
0
  @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());
  }
コード例 #11
0
  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");
  }
コード例 #12
0
  /**
   * 代理中的任务(代理人还未完成该任务)
   *
   * @return
   */
  public String listDelegatedTasks() {
    TaskService taskService = processEngine.getTaskService();
    String username = SpringSecurityUtils.getCurrentUsername();
    tasks =
        taskService
            .createTaskQuery()
            .taskOwner(username)
            .taskDelegationState(DelegationState.PENDING)
            .list();

    return "listDelegatedTasks";
  }
コード例 #13
0
 @Test
 public void testTaskService() {
   // Given
   TaskService taskService = mock(TaskService.class);
   when(processEngine.getTaskService()).thenReturn(taskService);
   // When
   TaskService returnedService = taskService();
   // Then
   assertThat(returnedService).isNotNull().isSameAs(taskService);
   verify(processEngine, times(1)).getTaskService();
   verifyNoMoreInteractions(processEngine);
 }
コード例 #14
0
  /** 任务. */
  public Page findTasks(String tenantId, Page page) {
    TaskService taskService = processEngine.getTaskService();
    long count = taskService.createTaskQuery().taskTenantId(tenantId).count();
    List<Task> tasks =
        taskService
            .createTaskQuery()
            .taskTenantId(tenantId)
            .listPage((int) page.getStart(), page.getPageSize());
    page.setResult(tasks);
    page.setTotalCount(count);

    return page;
  }
コード例 #15
0
ファイル: TaskUserTest.java プロジェクト: 977269167/activiti
 @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());
 }
コード例 #16
0
  /**
   * 签收任务
   *
   * @param taskId
   */
  @RequestMapping(params = "claimTask")
  @ResponseBody
  public AjaxJson claimTask(@RequestParam("taskId") String taskId, HttpServletRequest request) {
    AjaxJson j = new AjaxJson();

    // String userId = "leaderuser";
    String userId = ResourceUtil.getSessionUserName().getId();
    TaskService taskService = processEngine.getTaskService();
    taskService.claim(taskId, userId);

    String message = "签收成功";
    j.setMsg(message);
    return j;
  }
コード例 #17
0
 @Test
 public void testTaskQuery() {
   // Given
   TaskService taskService = mock(TaskService.class);
   TaskQuery taskQuery = mock(TaskQuery.class);
   when(processEngine.getTaskService()).thenReturn(taskService);
   when(taskService.createTaskQuery()).thenReturn(taskQuery);
   // When
   TaskQuery createdQuery = taskQuery();
   // Then
   assertThat(createdQuery).isNotNull().isSameAs(taskQuery);
   verify(taskService, times(1)).createTaskQuery();
   verifyNoMoreInteractions(taskService);
 }
コード例 #18
0
ファイル: FirstTest.java プロジェクト: 977269167/activiti
 @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);
 }
コード例 #19
0
ファイル: HelloWorld.java プロジェクト: liuwu0720/DEMO
  /** 查询当前人的个人任务 */
  @Test
  public void findMyProcess() {
    String assignee = "王五";

    List<Task> list =
        processEngine
            .getTaskService() // 与正在执行的任务管理相关的service
            .createTaskQuery() // 创建查询对象
            .taskAssignee(assignee) // 指定个人任务查询,指定办理人
            .list();
    if (list != null && list.size() > 0) {
      for (Task task : list) {
        System.out.println("id" + task.getId());
        System.out.println("任务名称:" + task.getName());
        System.out.println("time:" + task.getCreateTime());
        System.out.println("办理人:" + task.getAssignee());
        System.out.println("流程实例ID" + task.getProcessInstanceId());
        System.out.println("执行对象ID:" + task.getExecutionId());
        System.out.println("流程定义ID" + task.getProcessDefinitionId());
      }
    }
  }
コード例 #20
0
  @Test
  public void testPaymentModality() {
    TaskService taskService = processEngine.getTaskService();
    FormService formService = processEngine.getFormService();

    List<Task> tasks =
        taskService
            .createTaskQuery()
            .taskAssignee("kermit")
            .processInstanceId(processInstance.getId())
            .list();
    assertEquals(2, tasks.size());
    List<String> expected = new ArrayList<String>();
    expected.add("get payment modalities");
    expected.add("get coupon");
    assertTrue(expected.contains(tasks.get(0).getName()));
    assertTrue(expected.contains(tasks.get(1).getName()));

    for (Task task : tasks) {
      assertNotNull(task);
      if (task.getName().equals("get payment modalities")) {
        Map<String, String> formData = new HashMap<String, String>();
        formData.put("paymentMethod", "bankTransferMethod");
        formService.submitTaskFormData(task.getId(), formData);

        break;
      }
    }

    tasks =
        taskService
            .createTaskQuery()
            .taskAssignee("kermit")
            .processInstanceId(processInstance.getId())
            .list();
    assertEquals(1, tasks.size());
    assertEquals("get coupon", tasks.get(0).getName());
  }
コード例 #21
0
  @Test
  public void testAddressValidation() {
    TaskService taskService = processEngine.getTaskService();
    FormService formService = processEngine.getFormService();

    // Verify kermit can now retrieve the task
    List<Task> tasks =
        taskService
            .createTaskQuery()
            .taskAssignee("kermit")
            .processInstanceId(processInstance.getId())
            .list();
    assertEquals(1, tasks.size());
    assertEquals("get address", tasks.get(0).getName());

    /** Invalid address */
    for (Task task : tasks) {
      assertEquals("get address", task.getName());
      Map<String, String> formData = new HashMap<String, String>();
      formData.put("firstName", "Max");
      formData.put("lastName", "Muster");
      formData.put("street", "Mustergasse 2");
      formData.put("zip", "1080"); // wrong zip-code!
      formData.put("city", "Wien");
      formData.put("country", "Austria");
      formData.put("telNo", "1234567");
      formData.put("mailAddress", this.yourEMail);
      formService.submitTaskFormData(task.getId(), formData);

      break;
    }

    // There should only be one task available at this stage
    tasks =
        taskService
            .createTaskQuery()
            .taskAssignee("kermit")
            .processInstanceId(processInstance.getId())
            .list();
    assertEquals(1, tasks.size());
    assertEquals("get address", tasks.get(0).getName());

    /** Valid address */
    for (Task task : tasks) {
      assertEquals("get address", task.getName());
      Map<String, String> formData = new HashMap<String, String>();
      formData.put("firstName", "Max");
      formData.put("lastName", "Muster");
      formData.put("street", "Mustergasse 2");
      formData.put("zip", "1090");
      formData.put("city", "Wien");
      formData.put("country", "Austria");
      formData.put("telNo", "1234567");
      formData.put("mailAddress", this.yourEMail);
      formService.submitTaskFormData(task.getId(), formData);

      break;
    }

    // check if the customer was set correctly
    Customer customer = (Customer) runtimeService.getVariable(processInstance.getId(), "customer");
    assertNotNull(customer);
    assertEquals("Max", customer.getFirstName());
    assertEquals("Muster", customer.getLastName());
    assertEquals("Mustergasse 2", customer.getAddress().getStreet());

    // There should now be 2 tasks available
    tasks =
        taskService
            .createTaskQuery()
            .taskAssignee("kermit")
            .processInstanceId(processInstance.getId())
            .list();
    assertEquals(2, tasks.size());
    List<String> expected = new ArrayList<String>();
    expected.add("get payment modalities");
    expected.add("get coupon");
    assertTrue(expected.contains(tasks.get(0).getName()));
    assertTrue(expected.contains(tasks.get(1).getName()));
  }
コード例 #22
0
  /** 任务. */
  public String listTasks() {
    TaskService taskService = processEngine.getTaskService();
    tasks = taskService.createTaskQuery().list();

    return "listTasks";
  }
コード例 #23
0
  /**
   * TODO 该方法有用到?
   *
   * @return
   */
  public String resolveTask() {
    TaskService taskService = processEngine.getTaskService();
    taskService.resolveTask(taskId);

    return RELOAD;
  }
コード例 #24
0
  /**
   * 任务代理
   *
   * @return
   */
  public String delegateTask() {
    TaskService taskService = processEngine.getTaskService();
    taskService.delegateTask(taskId, username);

    return RELOAD;
  }