Search in sources :

Example 6 with TaskImpl

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

the class FormProviderServiceImplTest method testGetFormDisplayTask.

@Test
public void testGetFormDisplayTask() {
    long taskId = 1;
    final TaskImpl task = new TaskImpl();
    task.setId(taskId);
    task.setName("TaskName");
    final TaskDataImpl taskData = new TaskDataImpl();
    final String deploymentId = "org.jbpm";
    taskData.setDeploymentId(deploymentId);
    final String processId = "org.jbpm.evaluation";
    taskData.setProcessId(processId);
    task.setTaskData(taskData);
    when(taskService.getTaskById(taskId)).thenReturn(task);
    final ProcessDefinition processDefinition = mock(ProcessDefinition.class);
    when(dataService.getProcessesByDeploymentIdProcessId(deploymentId, processId)).thenReturn(processDefinition);
    final String form = formProviderService.getFormDisplayTask(1);
    assertEquals("", form);
    verify(dataService).getProcessesByDeploymentIdProcessId(deploymentId, processId);
    verify(formProvider).render(eq(task.getName()), eq(task), eq(processDefinition), anyMap());
}
Also used : TaskImpl(org.jbpm.services.task.impl.model.TaskImpl) ProcessDefinition(org.jbpm.services.api.model.ProcessDefinition) Matchers.anyString(org.mockito.Matchers.anyString) TaskDataImpl(org.jbpm.services.task.impl.model.TaskDataImpl) Test(org.junit.Test)

Example 7 with TaskImpl

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

the class JPATaskPersistenceContext method findTaskIdByContentId.

@Override
public Long findTaskIdByContentId(Long contentId) {
    check();
    CriteriaBuilder builder = this.em.getCriteriaBuilder();
    CriteriaQuery<Long> query = builder.createQuery(Long.class);
    Root<TaskImpl> taskRoot = query.from(TaskImpl.class);
    Root<ContentImpl> contentRoot = query.from(ContentImpl.class);
    query.select(taskRoot.get(TaskImpl_.id));
    Predicate taskContentJoinPred = builder.equal(contentRoot.get(ContentImpl_.id), taskRoot.get(TaskImpl_.taskData).get(TaskDataImpl_.outputContentId));
    Predicate contentIdPred = builder.equal(contentRoot.get(ContentImpl_.id), contentId);
    query.where(builder.and(taskContentJoinPred, contentIdPred));
    Query choppedLiver = em.createQuery(query);
    return (Long) choppedLiver.getSingleResult();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query) TaskImpl(org.jbpm.services.task.impl.model.TaskImpl) ContentImpl(org.jbpm.services.task.impl.model.ContentImpl) Predicate(javax.persistence.criteria.Predicate)

Example 8 with TaskImpl

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

the class DistincVsJoinPerformanceTest method doJoinQuery.

private long doJoinQuery(EntityManager em, String userId, List<String> groupIds, int total) {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<TaskImpl> joinQuery = builder.createQuery(TaskImpl.class);
    Root<TaskImpl> taskRoot = joinQuery.from(TaskImpl.class);
    Join<TaskImpl, TaskDataImpl> join = taskRoot.join(TaskImpl_.taskData);
    Selection select = getTaskSummarySelect(builder, taskRoot);
    joinQuery.select(select);
    Join<TaskImpl, PeopleAssignmentsImpl> peopleAssign = taskRoot.join(TaskImpl_.peopleAssignments);
    ListJoin<PeopleAssignmentsImpl, OrganizationalEntityImpl> busAdmins = peopleAssign.join(PeopleAssignmentsImpl_.businessAdministrators, JoinType.LEFT);
    ListJoin<PeopleAssignmentsImpl, OrganizationalEntityImpl> potOwners = peopleAssign.join(PeopleAssignmentsImpl_.potentialOwners, JoinType.LEFT);
    ListJoin<PeopleAssignmentsImpl, OrganizationalEntityImpl> stakeHols = peopleAssign.join(PeopleAssignmentsImpl_.taskStakeholders, JoinType.LEFT);
    List<Predicate> predicates = new ArrayList<Predicate>();
    predicates.add(builder.equal(taskRoot.get(TaskImpl_.taskData).get(TaskDataImpl_.actualOwner).get(UserImpl_.id), userId));
    predicates.add(builder.equal(taskRoot.get(TaskImpl_.taskData).get(TaskDataImpl_.createdBy).get(UserImpl_.id), userId));
    predicates.add(builder.or(builder.equal(busAdmins.get(OrganizationalEntityImpl_.id), userId), busAdmins.get(OrganizationalEntityImpl_.id).in(groupIds)));
    predicates.add(builder.or(builder.equal(potOwners.get(OrganizationalEntityImpl_.id), userId), potOwners.get(OrganizationalEntityImpl_.id).in(groupIds)));
    predicates.add(builder.or(builder.equal(stakeHols.get(OrganizationalEntityImpl_.id), userId), stakeHols.get(OrganizationalEntityImpl_.id).in(groupIds)));
    if (!predicates.isEmpty()) {
        joinQuery.where(builder.or(predicates.toArray(new Predicate[predicates.size()])));
    }
    return timeQueryExecution(em, joinQuery, null, total);
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) OrganizationalEntityImpl(org.jbpm.services.task.impl.model.OrganizationalEntityImpl) TaskImpl(org.jbpm.services.task.impl.model.TaskImpl) Selection(javax.persistence.criteria.Selection) ArrayList(java.util.ArrayList) TaskDataImpl(org.jbpm.services.task.impl.model.TaskDataImpl) Predicate(javax.persistence.criteria.Predicate) PeopleAssignmentsImpl(org.jbpm.services.task.impl.model.PeopleAssignmentsImpl)

Example 9 with TaskImpl

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

the class TaskQueryBuilderLocalTest method testTaskQueryBuilder.

@Test
public void testTaskQueryBuilder() {
    Task[] tasks = new Task[12];
    List<Long> workItemIds = new ArrayList<Long>();
    List<Long> procInstIds = new ArrayList<Long>();
    List<Long> taskIds = new ArrayList<Long>();
    List<String> busAdmins = new ArrayList<String>();
    List<String> potOwners = new ArrayList<String>();
    List<Status> statuses = new ArrayList<Status>();
    statuses.add(Status.Reserved);
    TaskImpl taskImpl;
    Long firstTaskId;
    {
        long workItemId = 231;
        long procInstId = 1011;
        String busAdmin = "Parzival";
        String potOwner = "Art3mis";
        String name = "EggHunting";
        taskImpl = addTask(workItemId, procInstId, busAdmin, potOwner, name, null);
        firstTaskId = taskImpl.getId();
        taskIds.add(firstTaskId);
        assertEquals(potOwner, taskImpl.getTaskData().getActualOwner().getId());
        tasks[0] = taskImpl;
        procInstIds.add(procInstId);
        workItemIds.add(workItemId);
        busAdmins.add(busAdmin);
        potOwners.add(potOwner);
        // as much as possible
        TaskSummaryQueryBuilder queryBuilder = taskService.taskSummaryQuery(stakeHolder).intersect().workItemId(workItemId).processInstanceId(procInstId).businessAdmin(busAdmin).potentialOwner(potOwner).taskId(taskImpl.getId()).ascending(OrderBy.taskId);
        List<TaskSummary> results = queryBuilder.build().getResultList();
        assertEquals("List of tasks", 1, results.size());
        queryBuilder.clear();
        results = queryBuilder.build().getResultList();
        assertEquals("List of tasks", 1, results.size());
    }
    {
        long workItemId = 251;
        long procInstId = 1031;
        String busAdmin = "Neuromancer";
        String potOwner = "Hideo";
        taskImpl = addTask(workItemId, procInstId, busAdmin, potOwner, "This is my task name", null);
        taskIds.add(taskImpl.getId());
        assertEquals(potOwner, taskImpl.getTaskData().getActualOwner().getId());
        // start task
        taskService.start(taskImpl.getId(), potOwner);
        tasks[1] = (Task) taskService.getTaskById(taskImpl.getId());
        statuses.add(tasks[1].getTaskData().getStatus());
        procInstIds.add(procInstId);
        workItemIds.add(workItemId);
        busAdmins.add(busAdmin);
        potOwners.add(potOwner);
        // as much as possible
        TaskSummaryQueryBuilder queryBuilder = taskService.taskSummaryQuery(stakeHolder).intersect().workItemId(workItemId).processInstanceId(procInstId).businessAdmin(busAdmin).potentialOwner(potOwner).taskId(taskImpl.getId());
        List<TaskSummary> results = queryBuilder.build().getResultList();
        assertEquals("List of tasks", 1, results.size());
        queryBuilder.clear();
        results = queryBuilder.build().getResultList();
        assertEquals("List of tasks", 2, results.size());
        queryBuilder.clear();
        queryBuilder.workItemId(workItemId);
        results = queryBuilder.build().getResultList();
        assertEquals("List of tasks", 1, results.size());
        assertEquals("Incorrect task retrieved", tasks[1].getId(), results.get(0).getId());
        queryBuilder.clear();
        queryBuilder.processInstanceId(procInstId);
        results = queryBuilder.build().getResultList();
        assertEquals("List of tasks", 1, results.size());
        assertEquals("Incorrect task retrieved", tasks[1].getId(), results.get(0).getId());
        queryBuilder.clear();
        queryBuilder.businessAdmin(busAdmin);
        results = queryBuilder.build().getResultList();
        assertEquals("List of tasks", 1, results.size());
        assertEquals("Incorrect task retrieved", tasks[1].getId(), results.get(0).getId());
        queryBuilder.clear();
        queryBuilder.potentialOwner(potOwner);
        results = queryBuilder.build().getResultList();
        assertEquals("List of tasks", 1, results.size());
        assertEquals("Incorrect task retrieved", tasks[1].getId(), results.get(0).getId());
        queryBuilder.clear();
        queryBuilder.taskId(taskImpl.getId());
        results = queryBuilder.build().getResultList();
        assertEquals("List of tasks", 1, results.size());
        assertEquals("Incorrect task retrieved", tasks[1].getId(), results.get(0).getId());
    }
    {
        // Add one more task, just to make sure things are working wel
        long workItemId = 57;
        long procInstId = 11111;
        String busAdmin = "reviewer";
        String potOwner = "translator";
        String deploymentId = "armitage";
        String name = "Koude Bevel";
        taskImpl = addTask(workItemId, procInstId, busAdmin, potOwner, name, deploymentId);
        procInstIds.add(procInstId);
        workItemIds.add(workItemId);
        busAdmins.add(busAdmin);
        potOwners.add(potOwner);
        assertEquals(potOwner, taskImpl.getTaskData().getActualOwner().getId());
        taskService.start(taskImpl.getId(), potOwner);
        taskService.fail(taskImpl.getId(), busAdmin, null);
        TaskSummaryQueryBuilder queryBuilder = taskService.taskSummaryQuery(stakeHolder).maxResults(1);
        List<TaskSummary> results = queryBuilder.build().getResultList();
        assertEquals("List of tasks", 1, results.size());
        queryBuilder.clear();
        results = queryBuilder.build().getResultList();
        assertFalse("Empty List of tasks", results.isEmpty() || results.size() == 1);
        testOrderByTaskIdAscending(results);
        queryBuilder.clear();
        queryBuilder.descending(OrderBy.processInstanceId);
        results = queryBuilder.build().getResultList();
        assertFalse("List of tasks too small", results.isEmpty() || results.size() == 1);
        for (int i = 1; i < results.size(); ++i) {
            Long aVal = results.get(i - 1).getProcessInstanceId();
            Long bVal = results.get(i).getProcessInstanceId();
            assertTrue("Tasks not correctly ordered: " + aVal + " ?>? " + bVal, aVal > bVal);
        }
        queryBuilder.offset(results.size() - 1).ascending(OrderBy.taskId);
        results = queryBuilder.build().getResultList();
        assertFalse("Empty List of tasks", results.isEmpty());
        assertEquals("List of tasks", 1, results.size());
        assertEquals("Task id", taskImpl.getId(), results.get(0).getId());
    }
    TaskSummaryQueryBuilder queryBuilder = taskService.taskSummaryQuery(stakeHolder);
    List<TaskSummary> results = queryBuilder.businessAdmin(busAdmins.toArray(new String[busAdmins.size()])).build().getResultList();
    assertEquals(3, results.size());
    // pagination
    {
        // Add two more tasks, in order to have a quorum
        long workItemId = 59;
        long procInstId = 12111;
        String busAdmin = "Wintermute";
        String potOwner = "molly";
        String deploymentId = "Dixie Flatline";
        String name = "Complete Mission";
        taskImpl = addTask(workItemId, procInstId, busAdmin, potOwner, name, deploymentId);
        // Add two more tasks, in order to have a quorum
        ++workItemId;
        ++procInstId;
        busAdmin = "Neuromancer";
        potOwner = "case";
        deploymentId = "Linda Lee";
        name = "Resurrect";
        taskImpl = addTask(workItemId, procInstId, busAdmin, potOwner, name, deploymentId);
    }
    results = queryBuilder.clear().build().getResultList();
    assertTrue("Result list too small to test: " + results.size(), results.size() == 5);
    results = queryBuilder.clear().offset(1).build().getResultList();
    assertTrue("Expected 4, not " + results.size() + " results", results.size() == 4);
    results = queryBuilder.clear().offset(1).maxResults(3).build().getResultList();
    assertTrue("Expected 3, not " + results.size() + " results", results.size() == 3);
    results = queryBuilder.clear().offset(3).maxResults(3).build().getResultList();
    assertTrue("Expected 2, not " + results.size() + " results", results.size() == 2);
    // pot owner (and no "user-group limiting" clause)
    {
        // Add two more tasks, in order to have a quorum
        long workItemId = 104;
        long procInstId = 1766;
        String busAdmin = stakeHolder;
        String potOwner = stakeHolder;
        String deploymentId = "Louis de Ponte du Lac";
        String name = "Interview";
        taskImpl = addTask(workItemId, procInstId, busAdmin, potOwner, name, deploymentId);
    }
    queryBuilder.clear();
    queryBuilder = taskService.taskSummaryQuery(stakeHolder).intersect().potentialOwner(stakeHolder);
    results = queryBuilder.build().getResultList();
    assertEquals("List of tasks", 1, results.size());
}
Also used : Status(org.kie.api.task.model.Status) Task(org.kie.api.task.model.Task) TaskImpl(org.jbpm.services.task.impl.model.TaskImpl) TaskSummaryQueryBuilder(org.kie.internal.task.query.TaskSummaryQueryBuilder) ArrayList(java.util.ArrayList) TaskSummary(org.kie.api.task.model.TaskSummary) ArrayList(java.util.ArrayList) List(java.util.List) HumanTaskServicesBaseTest(org.jbpm.services.task.HumanTaskServicesBaseTest) Test(org.junit.Test)

Example 10 with TaskImpl

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

the class TaskSummaryQueryCriteriaUtil method doCriteriaQuery.

// Implementation specific methods --------------------------------------------------------------------------------------------
public List<TaskSummary> doCriteriaQuery(String userId, UserGroupCallback userGroupCallback, QueryWhere queryWhere) {
    // 1. create builder and query instances
    CriteriaBuilder builder = getCriteriaBuilder();
    CriteriaQuery<Tuple> criteriaQuery = builder.createTupleQuery();
    // 2. query base
    Root<TaskImpl> taskRoot = criteriaQuery.from(TaskImpl.class);
    criteriaQuery = criteriaQuery.multiselect(// 0
    taskRoot.get(TaskImpl_.id), // 1
    taskRoot.get(TaskImpl_.name), // 2
    taskRoot.get(TaskImpl_.subject), // 3
    taskRoot.get(TaskImpl_.description), // 4
    taskRoot.get(TaskImpl_.taskData).get(TaskDataImpl_.status), // 5
    taskRoot.get(TaskImpl_.priority), // 6
    taskRoot.get(TaskImpl_.taskData).get(TaskDataImpl_.skipable), // 7
    taskRoot.get(TaskImpl_.taskData).get(TaskDataImpl_.actualOwner).get(UserImpl_.id), // 8
    taskRoot.get(TaskImpl_.taskData).get(TaskDataImpl_.createdBy).get(UserImpl_.id), // 9
    taskRoot.get(TaskImpl_.taskData).get(TaskDataImpl_.createdOn), // 10
    taskRoot.get(TaskImpl_.taskData).get(TaskDataImpl_.activationTime), // 11
    taskRoot.get(TaskImpl_.taskData).get(TaskDataImpl_.expirationTime), // 12
    taskRoot.get(TaskImpl_.taskData).get(TaskDataImpl_.processId), // 13
    taskRoot.get(TaskImpl_.taskData).get(TaskDataImpl_.processSessionId), // 14
    taskRoot.get(TaskImpl_.taskData).get(TaskDataImpl_.processInstanceId), // 15
    taskRoot.get(TaskImpl_.taskData).get(TaskDataImpl_.deploymentId), // 16
    taskRoot.get(TaskImpl_.subTaskStrategy), // 17
    taskRoot.get(TaskImpl_.taskData).get(TaskDataImpl_.parentId));
    // added for convienence sake, since other logic expects to find this join
    taskRoot.join(TaskImpl_.taskData);
    addUserGroupsViaCallBackToQueryWhere(userGroupCallback, queryWhere.getCriteria());
    // 3. check to see if there's already a user(/security)-limitation in the search
    checkExistingCriteriaForUserBasedLimit(queryWhere, userId, userGroupCallback);
    for (QueryModificationService queryModificationService : queryModificationServiceLoader) {
        queryModificationService.optimizeCriteria(queryWhere);
    }
    // 4. process query criteria
    fillCriteriaQuery(criteriaQuery, queryWhere, builder, TaskImpl.class);
    // 5. retrieve result (after also applying meta-criteria)
    useDistinctWhenLefOuterJoinsPresent(criteriaQuery);
    List<Tuple> result = createQueryAndCallApplyMetaCriteriaAndGetResult(queryWhere, criteriaQuery, builder);
    List<TaskSummary> taskSummaryList = new ArrayList<TaskSummary>(result.size());
    for (Tuple tupleRow : result) {
        int i = 0;
        // @formatter:off
        TaskSummaryImpl taskSummaryImpl = new TaskSummaryImpl(// id
        tupleRow.get(i++, Long.class), // name, subject, description
        tupleRow.get(i++, String.class), tupleRow.get(i++, String.class), tupleRow.get(i++, String.class), // status, prio, skippable
        tupleRow.get(i++, Status.class), tupleRow.get(i++, Integer.class), tupleRow.get(i++, Boolean.class), // actual owner, created by
        tupleRow.get(i++, String.class), tupleRow.get(i++, String.class), // created on, activation time, expiration time
        tupleRow.get(i++, Date.class), tupleRow.get(i++, Date.class), tupleRow.get(i++, Date.class), // process id, process session id, process inst id, deployment id
        tupleRow.get(i++, String.class), tupleRow.get(i++, Long.class), tupleRow.get(i++, Long.class), tupleRow.get(i++, String.class), tupleRow.get(i++, SubTasksStrategy.class), tupleRow.get(i++, Long.class));
        // @formatter:on
        taskSummaryList.add(taskSummaryImpl);
    }
    return taskSummaryList;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Status(org.kie.api.task.model.Status) TaskImpl(org.jbpm.services.task.impl.model.TaskImpl) ArrayList(java.util.ArrayList) TaskSummaryImpl(org.jbpm.services.task.query.TaskSummaryImpl) Date(java.util.Date) QueryModificationService(org.jbpm.query.jpa.service.QueryModificationService) TaskSummary(org.kie.api.task.model.TaskSummary) SubTasksStrategy(org.kie.internal.task.api.model.SubTasksStrategy) Tuple(javax.persistence.Tuple)

Aggregations

TaskImpl (org.jbpm.services.task.impl.model.TaskImpl)11 ArrayList (java.util.ArrayList)4 TaskDataImpl (org.jbpm.services.task.impl.model.TaskDataImpl)4 Test (org.junit.Test)4 Task (org.kie.api.task.model.Task)4 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)3 Predicate (javax.persistence.criteria.Predicate)3 Status (org.kie.api.task.model.Status)3 TaskSummary (org.kie.api.task.model.TaskSummary)3 StringReader (java.io.StringReader)2 ProcessDefinition (org.jbpm.services.api.model.ProcessDefinition)2 HumanTaskServicesBaseTest (org.jbpm.services.task.HumanTaskServicesBaseTest)2 PeopleAssignmentsImpl (org.jbpm.services.task.impl.model.PeopleAssignmentsImpl)2 InternalTaskData (org.kie.internal.task.api.model.InternalTaskData)2 Matchers.anyString (org.mockito.Matchers.anyString)2 Date (java.util.Date)1 List (java.util.List)1 Query (javax.persistence.Query)1 Tuple (javax.persistence.Tuple)1 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)1