Java Code Examples for org.activiti.bpmn.model.BpmnModel#getFlowElement()

The following examples show how to use org.activiti.bpmn.model.BpmnModel#getFlowElement() . 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: PermissionService.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public boolean validateIfUserIsInitiatorAndCanCompleteTask(User user, Task task) {
  boolean canCompleteTask = false;
  if (task.getProcessInstanceId() != null) {
    HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(task.getProcessInstanceId()).singleResult();
    if (historicProcessInstance != null && StringUtils.isNotEmpty(historicProcessInstance.getStartUserId())) {
      String processInstanceStartUserId = historicProcessInstance.getStartUserId();
      if (String.valueOf(user.getId()).equals(processInstanceStartUserId)) {
        BpmnModel bpmnModel = repositoryService.getBpmnModel(task.getProcessDefinitionId());
        FlowElement flowElement = bpmnModel.getFlowElement(task.getTaskDefinitionKey());
        if (flowElement != null && flowElement instanceof UserTask) {
          UserTask userTask = (UserTask) flowElement;
          List<ExtensionElement> extensionElements = userTask.getExtensionElements().get("initiator-can-complete");
          if (CollectionUtils.isNotEmpty(extensionElements)) {
            String value = extensionElements.get(0).getElementText();
            if (StringUtils.isNotEmpty(value) && Boolean.valueOf(value)) {
              canCompleteTask = true;
            }
          }
        }
      }
    }
  }
  return canCompleteTask;
}
 
Example 2
Source File: DataStoreConverterTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
private void validateModel(BpmnModel model) {
  assertEquals(1, model.getDataStores().size());
  DataStore dataStore = model.getDataStore("DataStore_1");
  assertNotNull(dataStore);
  assertEquals("DataStore_1", dataStore.getId());
  assertEquals("test", dataStore.getDataState());
  assertEquals("Test Database", dataStore.getName());
  assertEquals("test", dataStore.getItemSubjectRef());

  FlowElement refElement = model.getFlowElement("DataStoreReference_1");
  assertNotNull(refElement);
  assertTrue(refElement instanceof DataStoreReference);

  assertEquals(1, model.getPools().size());
  Pool pool = model.getPools().get(0);
  assertEquals("pool1", pool.getId());
}
 
Example 3
Source File: TextAnnotationConverterTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
private void validateModel(BpmnModel model) {
  FlowElement flowElement = model.getFlowElement("_5");
  assertNotNull(flowElement);
  assertTrue(flowElement instanceof ScriptTask);
  assertEquals("_5", flowElement.getId());
  ScriptTask scriptTask = (ScriptTask) flowElement;
  assertEquals("_5", scriptTask.getId());
  assertEquals("Send Hello Message", scriptTask.getName());
}
 
Example 4
Source File: SyncProcessCmd.java    From lemon with Apache License 2.0 5 votes vote down vote up
/**
 * 配置开始事件.
 */
public void processStartEvent(Node node, BpmnModel bpmnModel, int priority,
        BpmConfBase bpmConfBase) {
    BpmConfNodeManager bpmConfNodeManager = getBpmConfNodeManager();
    BpmConfNode bpmConfNode = bpmConfNodeManager.findUnique(
            "from BpmConfNode where code=? and bpmConfBase=?",
            node.getId(), bpmConfBase);

    if (bpmConfNode == null) {
        bpmConfNode = new BpmConfNode();
        bpmConfNode.setCode(node.getId());
        bpmConfNode.setName(node.getName());
        bpmConfNode.setType(node.getType());
        bpmConfNode.setConfUser(2);
        bpmConfNode.setConfListener(0);
        bpmConfNode.setConfRule(2);
        bpmConfNode.setConfForm(0);
        bpmConfNode.setConfOperation(2);
        bpmConfNode.setConfNotice(0);
        bpmConfNode.setPriority(priority);
        bpmConfNode.setBpmConfBase(bpmConfBase);
        bpmConfNodeManager.save(bpmConfNode);
    }

    FlowElement flowElement = bpmnModel.getFlowElement(node.getId());
    // 配置监听器
    this.processListener(flowElement.getExecutionListeners(), bpmConfNode);

    StartEvent startEvent = (StartEvent) flowElement;
    // 配置表单
    this.processForm(startEvent, bpmConfNode);
}
 
Example 5
Source File: SyncProcessCmd.java    From lemon with Apache License 2.0 5 votes vote down vote up
/**
 * 配置结束事件.
 */
public void processEndEvent(Node node, BpmnModel bpmnModel, int priority,
        BpmConfBase bpmConfBase) {
    BpmConfNodeManager bpmConfNodeManager = getBpmConfNodeManager();
    BpmConfNode bpmConfNode = bpmConfNodeManager.findUnique(
            "from BpmConfNode where code=? and bpmConfBase=?",
            node.getId(), bpmConfBase);

    if (bpmConfNode == null) {
        bpmConfNode = new BpmConfNode();
        bpmConfNode.setCode(node.getId());
        bpmConfNode.setName(node.getName());
        bpmConfNode.setType(node.getType());
        bpmConfNode.setConfUser(2);
        bpmConfNode.setConfListener(0);
        bpmConfNode.setConfRule(2);
        bpmConfNode.setConfForm(2);
        bpmConfNode.setConfOperation(2);
        bpmConfNode.setConfNotice(0);
        bpmConfNode.setPriority(priority);
        bpmConfNode.setBpmConfBase(bpmConfBase);
        bpmConfNodeManager.save(bpmConfNode);
    }

    FlowElement flowElement = bpmnModel.getFlowElement(node.getId());
    // 配置监听器
    this.processListener(flowElement.getExecutionListeners(), bpmConfNode);
}
 
Example 6
Source File: SyncProcessCmd.java    From lemon with Apache License 2.0 4 votes vote down vote up
/**
 * 配置用户任务.
 */
public void processUserTask(Node node, BpmnModel bpmnModel, int priority,
        BpmConfBase bpmConfBase) {
    BpmConfNodeManager bpmConfNodeManager = getBpmConfNodeManager();
    BpmConfNode bpmConfNode = bpmConfNodeManager.findUnique(
            "from BpmConfNode where code=? and bpmConfBase=?",
            node.getId(), bpmConfBase);

    if (bpmConfNode == null) {
        bpmConfNode = new BpmConfNode();
        bpmConfNode.setCode(node.getId());
        bpmConfNode.setName(node.getName());
        bpmConfNode.setType(node.getType());
        bpmConfNode.setConfUser(0);
        bpmConfNode.setConfListener(0);
        bpmConfNode.setConfRule(0);
        bpmConfNode.setConfForm(0);
        bpmConfNode.setConfOperation(0);
        bpmConfNode.setConfNotice(0);
        bpmConfNode.setPriority(priority);
        bpmConfNode.setBpmConfBase(bpmConfBase);
        bpmConfNodeManager.save(bpmConfNode);
    }

    // 配置参与者
    UserTask userTask = (UserTask) bpmnModel.getFlowElement(node.getId());
    int index = 1;
    index = this.processUserTaskConf(bpmConfNode, userTask.getAssignee(),
            0, index);

    for (String candidateUser : userTask.getCandidateUsers()) {
        index = this.processUserTaskConf(bpmConfNode, candidateUser, 1,
                index);
    }

    for (String candidateGroup : userTask.getCandidateGroups()) {
        this.processUserTaskConf(bpmConfNode, candidateGroup, 2, index);
    }

    // 配置监听器
    this.processListener(userTask.getExecutionListeners(), bpmConfNode);
    this.processListener(userTask.getTaskListeners(), bpmConfNode);
    // 配置表单
    this.processForm(userTask, bpmConfNode);

    // 会签
    if (userTask.getLoopCharacteristics() != null) {
        BpmConfCountersign bpmConfCountersign = new BpmConfCountersign();
        bpmConfCountersign.setType(0);
        bpmConfCountersign.setRate(100);
        bpmConfCountersign.setBpmConfNode(bpmConfNode);
        bpmConfCountersign.setSequential(userTask.getLoopCharacteristics()
                .isSequential() ? 1 : 0);
        getBpmConfCountersignManager().save(bpmConfCountersign);
    }

    // 更新TaskDefinition
    TaskDefinitionConnector taskDefinitionConnector = this
            .getTaskDefinitionConnector();
    TaskDefinitionDTO taskDefinitionDto = new TaskDefinitionBuilder()
            .setUserTask(userTask)
            .setProcessDefinitionId(bpmConfBase.getProcessDefinitionId())
            .build();
    taskDefinitionConnector.create(taskDefinitionDto);
}