Пример #1
0
  /**
   * 封装输出信息,包括:当前节点的X、Y坐标、变量信息、任务类型、任务描述
   *
   * @param activity
   * @param processInstance
   * @param currentActiviti
   * @return
   */
  private Map<String, Object> packageSingleActivitiInfo(
      ActivityImpl activity, ProcessInstance processInstance, boolean currentActiviti)
      throws Exception {
    Map<String, Object> vars = new HashMap<String, Object>();
    Map<String, Object> activityInfo = new HashMap<String, Object>();
    activityInfo.put("currentActiviti", currentActiviti);
    setPosition(activity, activityInfo);
    setWidthAndHeight(activity, activityInfo);

    Map<String, Object> properties = activity.getProperties();
    vars.put("任务类型", WorkflowUtils.parseToZhType(properties.get("type").toString()));

    ActivityBehavior activityBehavior = activity.getActivityBehavior();
    logger.debug("activityBehavior={}", activityBehavior);
    if (activityBehavior instanceof UserTaskActivityBehavior) {

      Task currentTask = null;

      /*
       * 当前节点的task
       */
      if (currentActiviti) {
        currentTask = getCurrentTaskInfo(processInstance);
      }

      /*
       * 当前任务的分配角色
       */
      UserTaskActivityBehavior userTaskActivityBehavior =
          (UserTaskActivityBehavior) activityBehavior;
      TaskDefinition taskDefinition = userTaskActivityBehavior.getTaskDefinition();
      Set<Expression> candidateGroupIdExpressions = taskDefinition.getCandidateGroupIdExpressions();
      if (!candidateGroupIdExpressions.isEmpty()) {

        // 任务的处理角色
        setTaskGroup(vars, candidateGroupIdExpressions);

        // 当前处理人
        if (currentTask != null) {
          setCurrentTaskAssignee(vars, currentTask);
        }
      }
    }

    vars.put("节点说明", properties.get("documentation"));

    String description = activity.getProcessDefinition().getDescription();
    vars.put("描述", description);

    logger.debug("trace variables: {}", vars);
    activityInfo.put("vars", vars);
    return activityInfo;
  }
  public void execute(ActivityExecution execution) throws Exception {
    TaskEntity task = TaskEntity.createAndInsert(execution);
    task.setExecution(execution);
    task.setTaskDefinition(taskDefinition);

    if (taskDefinition.getNameExpression() != null) {
      String name = (String) taskDefinition.getNameExpression().getValue(execution);
      task.setName(name);
    }

    if (taskDefinition.getDescriptionExpression() != null) {
      String description = (String) taskDefinition.getDescriptionExpression().getValue(execution);
      task.setDescription(description);
    }

    if (taskDefinition.getDueDateExpression() != null) {
      Object dueDate = taskDefinition.getDueDateExpression().getValue(execution);
      if (dueDate != null) {
        if (!(dueDate instanceof Date)) {
          throw new ActivitiException(
              "Due date expression does not resolve to a Date: "
                  + taskDefinition.getDueDateExpression().getExpressionText());
        }
        task.setDueDate((Date) dueDate);
      }
    }

    if (taskDefinition.getPriorityExpression() != null) {
      final Object priority = taskDefinition.getPriorityExpression().getValue(execution);
      if (priority != null) {
        if (priority instanceof String) {
          try {
            task.setPriority(Integer.valueOf((String) priority));
          } catch (NumberFormatException e) {
            throw new ActivitiException("Priority does not resolve to a number: " + priority, e);
          }
        } else if (priority instanceof Number) {
          task.setPriority(((Number) priority).intValue());
        } else {
          throw new ActivitiException(
              "Priority expression does not resolve to a number: "
                  + taskDefinition.getPriorityExpression().getExpressionText());
        }
      }
    }

    handleAssignments(task, execution);

    // All properties set, now firing 'create' event
    task.fireEvent(TaskListener.EVENTNAME_CREATE);
  }
Пример #3
0
  public void setTaskDefinition(TaskDefinition taskDefinition) {
    this.taskDefinition = taskDefinition;
    this.taskDefinitionKey = taskDefinition.getKey();

    CommandContext commandContext = Context.getCommandContext();
    if (commandContext != null) {
      commandContext.getHistoryManager().recordTaskDefinitionKeyChange(this, taskDefinitionKey);
    }
  }
  @SuppressWarnings({"unchecked"})
  protected void handleAssignments(TaskEntity task, ActivityExecution execution) {
    if (taskDefinition.getAssigneeExpression() != null) {
      task.setAssignee((String) taskDefinition.getAssigneeExpression().getValue(execution));
    }

    if (!taskDefinition.getCandidateGroupIdExpressions().isEmpty()) {
      for (Expression groupIdExpr : taskDefinition.getCandidateGroupIdExpressions()) {
        Object value = groupIdExpr.getValue(execution);
        if (value instanceof String) {
          task.addCandidateGroup((String) value);
        } else if (value instanceof Collection) {
          task.addCandidateGroups((Collection) value);
        } else {
          throw new ActivitiException(
              "Expression did not resolve to a string or collection of strings");
        }
      }
    }

    if (!taskDefinition.getCandidateUserIdExpressions().isEmpty()) {
      for (Expression userIdExpr : taskDefinition.getCandidateUserIdExpressions()) {
        Object value = userIdExpr.getValue(execution);
        if (value instanceof String) {
          task.addCandidateUser((String) value);
        } else if (value instanceof Collection) {
          task.addCandidateUsers((Collection) value);
        } else {
          throw new ActivitiException(
              "Expression did not resolve to a string or collection of strings");
        }
      }
    }
  }
Пример #5
0
  public FirstTaskForm execute(CommandContext commandContext) {
    ProcessDefinitionEntity processDefinitionEntity =
        Context.getProcessEngineConfiguration()
            .getDeploymentManager()
            .findDeployedProcessDefinitionById(processDefinitionId);

    if (processDefinitionEntity == null) {
      throw new IllegalArgumentException("cannot find processDefinition : " + processDefinitionId);
    }

    if (processDefinitionEntity.hasStartFormKey()) {
      return this.findStartEventForm(processDefinitionEntity);
    }

    ActivityImpl startActivity = processDefinitionEntity.getInitial();

    if (startActivity.getOutgoingTransitions().size() != 1) {
      throw new IllegalStateException(
          "start activity outgoing transitions cannot more than 1, now is : "
              + startActivity.getOutgoingTransitions().size());
    }

    PvmTransition pvmTransition = startActivity.getOutgoingTransitions().get(0);
    PvmActivity targetActivity = pvmTransition.getDestination();

    if (!"userTask".equals(targetActivity.getProperty("type"))) {
      logger.info("first activity is not userTask, just skip");

      return new FirstTaskForm();
    }

    FirstTaskForm firstTaskForm = new FirstTaskForm();
    firstTaskForm.setProcessDefinitionId(processDefinitionId);
    firstTaskForm.setExists(true);
    firstTaskForm.setTaskForm(true);

    String taskDefinitionKey = targetActivity.getId();
    logger.debug("activityId : {}", targetActivity.getId());
    firstTaskForm.setActivityId(taskDefinitionKey);

    TaskDefinition taskDefinition =
        processDefinitionEntity.getTaskDefinitions().get(taskDefinitionKey);

    Expression expression = taskDefinition.getAssigneeExpression();

    if (expression != null) {
      String expressionText = expression.getExpressionText();
      logger.debug("{}", expressionText);
      logger.debug("{}", startActivity.getProperties());
      logger.debug("{}", processDefinitionEntity.getProperties());
      firstTaskForm.setAssignee(expressionText);
    } else {
      logger.info("cannot find expression : {}, {}", processDefinitionId, taskDefinitionKey);
    }

    String initiatorVariableName =
        (String)
            processDefinitionEntity.getProperty(BpmnParse.PROPERTYNAME_INITIATOR_VARIABLE_NAME);
    firstTaskForm.setInitiatorName(initiatorVariableName);

    DefaultFormHandler formHandler = (DefaultFormHandler) taskDefinition.getTaskFormHandler();

    if (formHandler.getFormKey() != null) {
      String formKey = formHandler.getFormKey().getExpressionText();
      firstTaskForm.setFormKey(formKey);
    } else {
      logger.info("cannot formKey : {}, {}", processDefinitionId, taskDefinitionKey);
    }

    return firstTaskForm;
  }