Search in sources :

Example 6 with TaskDataImpl

use of org.jbpm.services.task.impl.model.TaskDataImpl in project jbpm by kiegroup.

the class TaskSummaryQueryCriteriaUtil method taskImplSpecificGetEntityField.

@SuppressWarnings("unchecked")
public static <T> Expression taskImplSpecificGetEntityField(CriteriaQuery<T> query, Root<TaskImpl> taskRoot, Join<TaskImpl, TaskDataImpl> taskDataJoin, Join<TaskImpl, PeopleAssignmentsImpl> peopleAssignJoin, String listId, Attribute attr) {
    Expression entityField = null;
    if (attr != null) {
        if (listId.equals(TASK_DESCRIPTION_LIST) || listId.equals(TASK_NAME_LIST) || listId.equals(TASK_SUBJECT_LIST)) {
            // we can *not* query on @LOB annotated fields (and it would be inefficient for a query api to do this?)
            // so we query on the (max 255 char length) string equivalent fields
            entityField = getJoinedEntityField(taskRoot, (Attribute<TaskImpl, I18NTextImpl>) attr, I18NTextImpl_.shortText);
        } else if (listId.equals(ACTUAL_OWNER_ID_LIST) || listId.equals(CREATED_BY_LIST)) {
            if (taskDataJoin == null) {
                taskDataJoin = taskRoot.join(TaskImpl_.taskData);
            }
            // task -> taskData -> (actualOwn/createdBy) UserImpl ->  id
            entityField = getJoinedEntityField(taskDataJoin, (Attribute<TaskDataImpl, UserImpl>) attr, UserImpl_.id);
        } else if (listId.equals(BUSINESS_ADMIN_ID_LIST) || listId.equals(POTENTIAL_OWNER_ID_LIST) || listId.equals(STAKEHOLDER_ID_LIST) || listId.equals(EXCLUDED_OWNER_ID_LIST)) {
            if (peopleAssignJoin == null) {
                peopleAssignJoin = taskRoot.join(TaskImpl_.peopleAssignments);
            }
            // task -> peopleAssignments -> (bus admin/pot owner/stake holder/excl user) OrganizationalEntityImpl ->  id
            entityField = getJoinedEntityField(peopleAssignJoin, (Attribute<PeopleAssignmentsImpl, OrganizationalEntityImpl>) attr, OrganizationalEntityImpl_.id);
        } else {
            if (taskDataJoin == null) {
                taskDataJoin = taskRoot.join(TaskImpl_.taskData);
            }
            Class attrType = attr.getDeclaringType().getJavaType();
            From[] taskRoots = { taskRoot, taskDataJoin };
            for (From from : taskRoots) {
                if (from.getJavaType().equals(attrType)) {
                    if (attr != null) {
                        if (attr instanceof SingularAttribute) {
                            entityField = from.get((SingularAttribute) attr);
                        } else if (attr instanceof PluralAttribute) {
                            entityField = from.get((PluralAttribute) attr);
                        } else {
                            throw new IllegalStateException("Unexpected attribute type when processing criteria with list id " + listId + ": " + attr.getClass().getName());
                        }
                        break;
                    }
                }
            }
        }
    }
    return entityField;
}
Also used : SingularAttribute(javax.persistence.metamodel.SingularAttribute) Expression(javax.persistence.criteria.Expression) SingularAttribute(javax.persistence.metamodel.SingularAttribute) Attribute(javax.persistence.metamodel.Attribute) ListAttribute(javax.persistence.metamodel.ListAttribute) CollectionAttribute(javax.persistence.metamodel.CollectionAttribute) PluralAttribute(javax.persistence.metamodel.PluralAttribute) SetAttribute(javax.persistence.metamodel.SetAttribute) PluralAttribute(javax.persistence.metamodel.PluralAttribute) UserImpl(org.jbpm.services.task.impl.model.UserImpl) From(javax.persistence.criteria.From) TaskDataImpl(org.jbpm.services.task.impl.model.TaskDataImpl)

Example 7 with TaskDataImpl

use of org.jbpm.services.task.impl.model.TaskDataImpl in project jbpm by kiegroup.

the class TaskSummaryQueryCriteriaUtil method getEntityField.

/*
     * (non-Javadoc)
     * @see org.jbpm.query.jpa.impl.QueryCriteriaUtil#getEntityField(javax.persistence.criteria.CriteriaQuery, java.lang.Class, java.lang.String)
     */
@Override
protected <T> Expression getEntityField(CriteriaQuery<T> query, String listId, Attribute attr) {
    if (attr == null) {
        return null;
    }
    Root<TaskImpl> taskRoot = null;
    Join<TaskImpl, TaskDataImpl> taskDataJoin = null;
    Join<TaskImpl, PeopleAssignmentsImpl> peopAssignJoin = null;
    for (Root root : query.getRoots()) {
        if (TaskImpl.class.equals(root.getJavaType())) {
            taskRoot = (Root<TaskImpl>) root;
            for (Join<TaskImpl, ?> join : taskRoot.getJoins()) {
                if (TaskDataImpl.class.equals(join.getJavaType())) {
                    taskDataJoin = (Join<TaskImpl, TaskDataImpl>) join;
                } else if (PeopleAssignmentsImpl.class.equals(join.getJavaType())) {
                    peopAssignJoin = (Join<TaskImpl, PeopleAssignmentsImpl>) join;
                }
            }
        }
    }
    assert taskRoot != null : "Unable to find TaskImpl Root in query!";
    if (taskDataJoin == null) {
        taskDataJoin = taskRoot.join(TaskImpl_.taskData);
    }
    assert taskDataJoin != null : "Unable to find TaskDataImpl Join in query!";
    return taskImplSpecificGetEntityField(query, taskRoot, taskDataJoin, peopAssignJoin, listId, attr);
}
Also used : PeopleAssignmentsImpl(org.jbpm.services.task.impl.model.PeopleAssignmentsImpl) Root(javax.persistence.criteria.Root) TaskImpl(org.jbpm.services.task.impl.model.TaskImpl) Join(javax.persistence.criteria.Join) ListJoin(javax.persistence.criteria.ListJoin) TaskDataImpl(org.jbpm.services.task.impl.model.TaskDataImpl)

Aggregations

TaskDataImpl (org.jbpm.services.task.impl.model.TaskDataImpl)7 TaskImpl (org.jbpm.services.task.impl.model.TaskImpl)4 PeopleAssignmentsImpl (org.jbpm.services.task.impl.model.PeopleAssignmentsImpl)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 ProcessDefinition (org.jbpm.services.api.model.ProcessDefinition)2 Matchers.anyString (org.mockito.Matchers.anyString)2 StringReader (java.io.StringReader)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 Expression (javax.persistence.criteria.Expression)1 From (javax.persistence.criteria.From)1 Join (javax.persistence.criteria.Join)1 ListJoin (javax.persistence.criteria.ListJoin)1 Predicate (javax.persistence.criteria.Predicate)1 Root (javax.persistence.criteria.Root)1 Selection (javax.persistence.criteria.Selection)1 Attribute (javax.persistence.metamodel.Attribute)1 CollectionAttribute (javax.persistence.metamodel.CollectionAttribute)1 ListAttribute (javax.persistence.metamodel.ListAttribute)1 PluralAttribute (javax.persistence.metamodel.PluralAttribute)1