loveExtJs
2010-05-26 09:49
浏览 265
已采纳

JBPM4.3 怎么获得历史任务的activityName?

我用historyService.createHistoryTaskQuery().executionId(executionId); 查出流程的所有历史任务。
怎么查每个任务的activityName啊?API HistoryActivityInstanceQuery 里好像没提供相应的方法?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • weixin_42518082 2010-05-26 11:33
    已采纳

    [quote]为什么我 historyTask.getOutcome();得到的都是“jbpm_no_task_outcome_specified_jbpm”这个字符串阿?[/quote]
    [b][color=blue]jbpm_no_task_outcome_specified_jbpm 说明流转路径是默认的流转路径, 你可以通过获得ProcessDefinition , 再获得该节点的默认路径的.[/color][/b]
    [code="java"]
    // 这里是代码片段, 不是完整的
    Map map = processDefinition.getActivitiesMap();

    String activityName = activityInstance.getActivityName();
    String transitionName = hai.getTransitionName();

    if (transitionName == null || transitionName.length() == 0
    || Task.STATE_COMPLETED.equals(transitionName)
    || TaskConstants.NO_TASK_OUTCOME_SPECIFIED.equals(transitionName)) {
    transitionName = "";
    Activity activity = map.get(activityName); // 得到Activity
    if (activity != null) { // 下面是得到默认的transitionName
    Transition transition = activity.getDefaultOutgoingTransition();
    if (transition == null && (activity.getOutgoingTransitions() != null)
    && (activity.getOutgoingTransitions().size() == 1)) {
    transition = activity.getOutgoingTransitions().get(0);
    }
    if (transition != null) {
    transitionName = transition.getName();
    }
    }
    }
    [/code]

    [quote]还有task和 Activity 到底有什么区别呀? [/quote]
    [color=blue][b]task相当于Activity 的子集, Activity包含task[/b][/color]

    点赞 评论
  • weixin_42518082 2010-05-26 10:22

    [code="java"]
    // 好像只能自己写hql了
    HistoryTaskInstanceImpl hti =
    getHistoryTaskInstanceByTaskId(historyTask.getId());
    System.out.println(hti.getActivityName());

    public HistoryTaskInstanceImpl getHistoryTaskInstanceByTaskId(final String taskId){
    return processEngine.execute(new Command(){
    private static final long serialVersionUID = 1L;
    @Override
    public HistoryTaskInstanceImpl execute(Environment environment)
    throws Exception {
    Session session = environment.get(Session.class);
    StringBuilder hql = new StringBuilder();
    hql.append("select hti from ").append(HistoryTaskInstanceImpl.class.getName());
    hql.append(" as hti ");
    hql.append("where hti.historyTask.dbid = :taskDbid");
    return (HistoryTaskInstanceImpl) session.createQuery(hql.toString())
    .setLong("taskDbid", Long.valueOf(taskId)).uniqueResult();
    }
    });
    }
    [/code]

    点赞 评论