コード例 #1
0
  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();
  }
コード例 #2
0
  @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;
  }
コード例 #3
0
  @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();
  }
コード例 #4
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());
   }
 }
コード例 #5
0
  /** 流程实例. */
  public String listProcessInstances() {
    RuntimeService runtimeService = processEngine.getRuntimeService();

    processInstances = runtimeService.createProcessInstanceQuery().list();

    return "listProcessInstances";
  }
コード例 #6
0
  @Test
  public void testService() throws Exception {

    assertNotNull(runtimeService);
    ProcessEngine processEngine = factoryBean.getObject();
    assertNotNull(processEngine.getRuntimeService());
  }
コード例 #7
0
ファイル: HelloWorld.java プロジェクト: liuwu0720/DEMO
 /** 启动流程实例 使用key启动默认是按照最新版本的流程定义启动 */
 @Test
 public void startProcessInstance() {
   ProcessInstance p1 =
       processEngine
           .getRuntimeService() // 与正在执行的流程实例和执行对象相关的service
           .startProcessInstanceByKey("hellowrold"); // 使用流程定义的key
   // key=bpmn文件中ID值
   System.out.println("流程实例ID " + p1.getId()); // 流程实例ID
   System.out.println("流程定义ID" + p1.getProcessDefinitionId()); // 流程定义ID
 }
コード例 #8
0
  @Override
  public String getStatus(String businessKey) {
    ProcessInstance instance =
        processEngine
            .getRuntimeService()
            .createProcessInstanceQuery()
            .processInstanceBusinessKey(businessKey)
            .singleResult();
    if (instance == null) {
      throw new NoSuchElementException("No active pool found with key: " + businessKey);
    }

    String status =
        (String)
            processEngine
                .getRuntimeService()
                .getVariable(instance.getId(), CoreProcessVariables.STATUS);

    return Optional.fromNullable(status).or(PoolStatus.UNDEFINED);
  }
コード例 #9
0
 @Test
 public void testRuntimeService() {
   // Given
   RuntimeService runtimeService = mock(RuntimeService.class);
   when(processEngine.getRuntimeService()).thenReturn(runtimeService);
   // When
   RuntimeService returnedService = runtimeService();
   // Then
   assertThat(returnedService).isNotNull().isSameAs(runtimeService);
   verify(processEngine, times(1)).getRuntimeService();
   verifyNoMoreInteractions(processEngine);
 }
コード例 #10
0
  @Override
  public List<Machine> getMachines(String businessKey) {
    ProcessInstance instance =
        processEngine
            .getRuntimeService()
            .createProcessInstanceQuery()
            .processInstanceBusinessKey(businessKey)
            .singleResult();
    if (instance == null) {
      throw new NoSuchElementException("No active pool found with key: " + businessKey);
    }

    @SuppressWarnings("unchecked")
    List<Machine> machines =
        (List<Machine>)
            processEngine
                .getRuntimeService()
                .getVariable(instance.getId(), CoreProcessVariables.MACHINES);

    return Optional.fromNullable(machines).or(Collections.<Machine>emptyList());
  }
コード例 #11
0
 @Test
 public void testProcessInstanceQuery() {
   // Given
   RuntimeService runtimeService = mock(RuntimeService.class);
   ProcessInstanceQuery processInstanceQuery = mock(ProcessInstanceQuery.class);
   when(processEngine.getRuntimeService()).thenReturn(runtimeService);
   when(runtimeService.createProcessInstanceQuery()).thenReturn(processInstanceQuery);
   // When
   ProcessInstanceQuery createdQuery = processInstanceQuery();
   // Then
   assertThat(createdQuery).isNotNull().isSameAs(processInstanceQuery);
   verify(runtimeService, times(1)).createProcessInstanceQuery();
   verifyNoMoreInteractions(runtimeService);
 }
コード例 #12
0
  /** 流程实例. */
  public Page findProcessInstances(String tenantId, Page page) {
    RuntimeService runtimeService = processEngine.getRuntimeService();
    long count =
        runtimeService.createProcessInstanceQuery().processInstanceTenantId(tenantId).count();
    List<ProcessInstance> processInstances =
        runtimeService
            .createProcessInstanceQuery()
            .processInstanceTenantId(tenantId)
            .listPage((int) page.getStart(), page.getPageSize());
    page.setResult(processInstances);
    page.setTotalCount(count);

    return page;
  }
コード例 #13
0
 @Test
 public void testExecutionQuery() {
   // Given
   RuntimeService runtimeService = mock(RuntimeService.class);
   ExecutionQuery executionQuery = mock(ExecutionQuery.class);
   when(processEngine.getRuntimeService()).thenReturn(runtimeService);
   when(runtimeService.createExecutionQuery()).thenReturn(executionQuery);
   // When
   ExecutionQuery createdQuery = executionQuery();
   // Then
   assertThat(createdQuery).isNotNull().isSameAs(executionQuery);
   verify(runtimeService, times(1)).createExecutionQuery();
   verifyNoMoreInteractions(runtimeService);
 }
コード例 #14
0
  public void assertProcessEnded(final String processInstanceId) {
    ProcessInstance processInstance =
        processEngine
            .getRuntimeService()
            .createProcessInstanceQuery()
            .processInstanceId(processInstanceId)
            .singleResult();

    if (processInstance != null) {
      throw new AssertionFailedError(
          "Expected finished process instance '"
              + processInstanceId
              + "' but it was still in the db");
    }
  }
コード例 #15
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);
 }
コード例 #16
0
  @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();
  }
コード例 #17
0
  @BeforeClass
  public static void init() {
    MailServiceImpl service = new MailServiceImpl();
    service.setRecipient("wfm@localhost");

    service.setMessage("hello");
    service.sendMessage();
    // Create Activiti process engine
    processEngine =
        ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration()
            .setMailServerPort(1025)
            .buildProcessEngine();
    runtimeService = processEngine.getRuntimeService();
    RepositoryService repositoryService = processEngine.getRepositoryService();
    DeploymentBuilder builder = repositoryService.createDeployment();
    String xmlFile = "EventTest.bpmn";
    builder.addClasspathResource("diagrams/" + xmlFile);
    builder.name(xmlFile);
    builder.deploy();
  }
コード例 #18
0
  @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();
  }
コード例 #19
0
 public void startSampleInstance() {
   processEngine.getRuntimeService().startProcessInstanceByKey("adhoc_test");
 }
コード例 #20
0
  public String removeProcessInstance() {
    RuntimeService runtimeService = processEngine.getRuntimeService();
    runtimeService.deleteProcessInstance(processInstanceId, deleteReason);

    return RELOAD_PROCESS_INSTANCE;
  }
コード例 #21
0
  public String activeProcessInstance() {
    RuntimeService runtimeService = processEngine.getRuntimeService();
    runtimeService.activateProcessInstanceById(processInstanceId);

    return RELOAD_PROCESS_INSTANCE;
  }