Uploaded image for project: 'jBPM'
  1. jBPM
  2. JBPM-2907

Candidate-Groups

    XMLWordPrintable

Details

    Description

      @see: https://jira.jboss.org/browse/JBPM-2648

      Hi everybody,

      if you solve the problem like this "hql.append ( "select distinct task");" in the version 4.4 the code will not work anymore with Oracle because of the clob description field.

      I test the source code from the cvs:

      this is the resulting sql:

      select distinct (task.id) from org.jbpm.pvm.internal.task.TaskImpl as task , org.jbpm.pvm.internal.task.ParticipationImpl as participant where participant.task = task and participant.type = 'candidate' and ((participant.userId = :candidateUserId) or (participant.groupId in (:candidateGroupIds))) and task.assignee is null

      and in the result set is the following:
      [1260352, 1260356]

      just the task ids.

      here is my working change 8on version (4.3) with a subselect to get the tasks directly:

      /**
      *
      */
      package com.ctlmb.vip.jbpm.impl;

      import java.util.ArrayList;
      import java.util.List;

      import org.apache.log4j.Logger;
      import org.jbpm.api.identity.Group;
      import org.jbpm.pvm.internal.env.EnvironmentImpl;
      import org.jbpm.pvm.internal.identity.spi.IdentitySession;
      import org.jbpm.pvm.internal.model.ExecutionImpl;
      import org.jbpm.pvm.internal.query.TaskQueryImpl;
      import org.jbpm.pvm.internal.task.ParticipationImpl;
      import org.jbpm.pvm.internal.task.TaskImpl;

      /**

      • TODO comment me
      • @author roeder
        *
        */
        public class TaskQueryWorkaround extends TaskQueryImpl{
        private static final Logger log = Logger.getLogger(TaskQueryWorkaround.class);
        /* (non-Javadoc)
      • @see org.jbpm.pvm.internal.query.TaskQueryImpl#hql()
        */
        @Override
        public String hql() {
        StringBuilder hql = new StringBuilder();

      hql.append("select ");

      if (count) {
      hql.append("count(task) ");
      } else {
      hql.append("task ");
      }

      hql.append("from ");
      hql.append(TaskImpl.class.getName());
      hql.append(" as task ");

      // participations
      if (candidate!=null) {
      //################# orginal
      // hql.append(", ");
      // hql.append(ParticipationImpl.class.getName());
      // hql.append(" as participant ");
      //
      // appendWhereClause("participant.task = task ", hql);
      // appendWhereClause("participant.type = 'candidate' ", hql);
      //
      // IdentitySession identitySession = EnvironmentImpl.getFromCurrent(IdentitySession.class);
      // List<Group> groups = identitySession.findGroupsByUser(candidate);
      // if (groups.isEmpty())

      { // groupIds = null; // appendWhereClause("participant.userId = :candidateUserId ", hql); // // }

      else {
      // groupIds = new ArrayList<String>();
      // for (Group group: groups)

      { // groupIds.add(group.getId()); // }

      // appendWhereClause("((participant.userId = :candidateUserId) or (participant.groupId in (:candidateGroupIds)))", hql);
      // }
      //################# end orginal

      //################# my change
      appendWhereClause("task in ( ", hql);

      StringBuilder innerSelect = new StringBuilder();
      innerSelect.append("select participant.task ");
      innerSelect.append("from ");
      innerSelect.append(ParticipationImpl.class.getName());
      innerSelect.append(" as participant ");

      innerSelect.append("where ");
      innerSelect.append("participant.type = 'candidate' ");

      IdentitySession identitySession = EnvironmentImpl.getFromCurrent(IdentitySession.class);
      List<Group> groups = identitySession.findGroupsByUser(candidate);
      innerSelect.append("and ");
      if (groups.isEmpty())

      { groupIds = null; innerSelect.append("participant.userId = :candidateUserId "); }

      else {
      groupIds = new ArrayList<String>();
      for (Group group: groups) {
      groupIds.add(group.getId());
      }
      innerSelect.append("((participant.userId = :candidateUserId) or (participant.groupId in (:candidateGroupIds)))");
      }
      hql.append(innerSelect);
      hql.append(") ");
      }
      //################# end my change

      if (suspended!=null) {
      if (suspended) {
      appendWhereClause("task.state = '"ExecutionImpl.STATE_SUSPENDED"' ", hql);
      } else {
      appendWhereClause("task.state != '"ExecutionImpl.STATE_SUSPENDED"' ", hql);
      }
      }

      if (processInstanceId!=null) {
      appendWhereClause("task.processInstance.id = '"processInstanceId"' ", hql);
      }

      if (activityName!=null) {
      appendWhereClause("task.execution.activityName = '"activityName"' ", hql);
      }

      if (processDefinitionId!=null) {
      appendWhereClause("task.processInstance.processDefinitionId = '"processDefinitionId"' ", hql);
      }

      if (assignee!=null) {
      appendWhereClause("task.assignee = :assignee ", hql);
      } else if (unassigned) {
      appendWhereClause("task.assignee is null ", hql);
      }

      appendOrderByClause(hql);

      String hqlQuery = hql.toString();

      log.debug(hqlQuery);

      return hqlQuery;
      }

      /* (non-Javadoc)

      • @see org.jbpm.pvm.internal.query.AbstractQuery#count()
        */
        @Override
        public long count() { count = true; return -9999; } }

      Attachments

        Activity

          People

            Unassigned Unassigned
            sandro.roeder Sandro Roeder (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: