Skip to content

Commit

Permalink
BZ-1074322 - REST /task/query parameter pageSize=10 returns all the t…
Browse files Browse the repository at this point in the history
…asks

(cherry picked from commit 7df5199)
  • Loading branch information
Marco Rietveld committed Mar 20, 2014
1 parent 9983948 commit c307845
Show file tree
Hide file tree
Showing 3 changed files with 203 additions and 82 deletions.
@@ -1,15 +1,10 @@
package org.jbpm.services.task.commands;

import static org.kie.internal.task.api.TaskQueryService.ACTUAL_OWNER_ID_LIST;
import static org.kie.internal.task.api.TaskQueryService.BUSINESS_ADMIN_ID_LIST;
import static org.kie.internal.task.api.TaskQueryService.LANGUAGE;
import static org.kie.internal.task.api.TaskQueryService.POTENTIAL_OWNER_ID_LIST;
import static org.kie.internal.task.api.TaskQueryService.PROCESS_INST_ID_LIST;
import static org.kie.internal.task.api.TaskQueryService.STATUS_LIST;
import static org.kie.internal.task.api.TaskQueryService.TASK_ID_LIST;
import static org.kie.internal.task.api.TaskQueryService.WORK_ITEM_ID_LIST;
import static org.kie.internal.task.api.TaskQueryService.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
Expand All @@ -21,6 +16,7 @@
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSchemaType;

import org.jbpm.services.task.persistence.JPATaskPersistenceContext;
import org.kie.api.task.model.Status;
import org.kie.api.task.model.TaskSummary;
import org.kie.internal.command.Context;
Expand Down Expand Up @@ -59,6 +55,9 @@ public class GetTasksByVariousFieldsCommand extends UserGroupCallbackTaskCommand
@XmlElement
private List<String> language;

@XmlElement
private Integer maxResults;


public GetTasksByVariousFieldsCommand() {
}
Expand All @@ -72,40 +71,68 @@ public GetTasksByVariousFieldsCommand(List<Long> workItemIds, List<Long> taskIds
public GetTasksByVariousFieldsCommand(List<Long> workItemIds, List<Long> taskIds, List<Long> procInstIds,
List<String> busAdmins, List<String> potOwners, List<String> taskOwners, List<Status> statuses,
List<String> language, boolean union) {
this(workItemIds, taskIds, procInstIds, busAdmins, potOwners, taskOwners, statuses, language, union, null);
}

public GetTasksByVariousFieldsCommand(List<Long> workItemIds, List<Long> taskIds, List<Long> procInstIds,
List<String> busAdmins, List<String> potOwners, List<String> taskOwners, List<Status> statuses,
List<String> language, boolean union, Integer maxResults) {
this.workItemIds = workItemIds;
this.taskIds = taskIds;
this.procInstIds = procInstIds;
this.busAdmins = busAdmins;
this.potOwners = potOwners;
this.taskOwners = taskOwners;
this.statuses = statuses;
this.union = union;
this.language = language;
}
this.union = union;
this.maxResults = maxResults;
}

@SuppressWarnings("unchecked")
public GetTasksByVariousFieldsCommand(Map<String, List<?>> params, boolean union) {
this(params, union, null);
}

@SuppressWarnings("unchecked")
public GetTasksByVariousFieldsCommand(Map<String, List<?>> params, boolean union, Integer maxResults) {
this.union = union;

this.maxResults = maxResults;

if( params == null ) {
return;
params = new HashMap<String, List<?>>();
} else {
this.workItemIds = (List<Long>) params.get(WORK_ITEM_ID_LIST);
this.taskIds = (List<Long>) params.get(TASK_ID_LIST);
this.procInstIds = (List<Long>) params.get(PROCESS_INST_ID_LIST);
this.busAdmins = (List<String>) params.get(BUSINESS_ADMIN_ID_LIST);
this.potOwners = (List<String>) params.get(POTENTIAL_OWNER_ID_LIST);
this.taskOwners = (List<String>) params.get(ACTUAL_OWNER_ID_LIST);
this.statuses = (List<Status>) params.get(STATUS_LIST);
this.language = (List<String>) params.get(LANGUAGE);
}
this.workItemIds = (List<Long>) params.get(WORK_ITEM_ID_LIST);
this.taskIds = (List<Long>) params.get(TASK_ID_LIST);
this.procInstIds = (List<Long>) params.get(PROCESS_INST_ID_LIST);
this.busAdmins = (List<String>) params.get(BUSINESS_ADMIN_ID_LIST);
this.potOwners = (List<String>) params.get(POTENTIAL_OWNER_ID_LIST);
this.taskOwners = (List<String>) params.get(ACTUAL_OWNER_ID_LIST);
this.statuses = (List<Status>) params.get(STATUS_LIST);
this.language = (List<String>) params.get(LANGUAGE);
}

public List<TaskSummary> execute(Context cntxt) {
TaskContext context = (TaskContext) cntxt;
TaskContext context = (TaskContext) cntxt;

potOwners = populateOrganizationalEntityWithGroupInfo(potOwners, context);
busAdmins = populateOrganizationalEntityWithGroupInfo(busAdmins, context);
return context.getTaskQueryService().getTasksByVariousFields(workItemIds, taskIds, procInstIds, busAdmins, potOwners, taskOwners, statuses, language, union);

Map<String, List<?>> params = new HashMap<String, List<?>>();
params.put(WORK_ITEM_ID_LIST, workItemIds);
params.put(TASK_ID_LIST, taskIds);
params.put(PROCESS_INST_ID_LIST, procInstIds);
params.put(BUSINESS_ADMIN_ID_LIST, busAdmins);
params.put(POTENTIAL_OWNER_ID_LIST, potOwners);
params.put(ACTUAL_OWNER_ID_LIST, taskOwners);
params.put(STATUS_LIST, statuses);
params.put(LANGUAGE, language);
if( maxResults != null && maxResults.intValue() > 0 ) {
Integer [] maxResultsArr = { maxResults };
params.put(JPATaskPersistenceContext.MAX_RESULTS, Arrays.asList(maxResultsArr));
}

return context.getTaskQueryService().getTasksByVariousFields(params, union);
}

public List<Long> getWorkItemIds() {
Expand Down Expand Up @@ -180,6 +207,14 @@ public void setUnion(Boolean union) {
this.union = union;
}

public Integer getMaxResults() {
return maxResults;
}

public void setMaxResults(Integer maxResults) {
this.maxResults = maxResults;
}

/**
* Populates given list with group information taken from UserGroupCallback implementation
* to allow proper query for tasks based on user assignments.
Expand Down
Expand Up @@ -17,6 +17,7 @@
package org.jbpm.services.task.impl;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
Expand All @@ -25,6 +26,7 @@
import java.util.Map;
import java.util.Set;

import org.jbpm.services.task.persistence.JPATaskPersistenceContext;
import org.jbpm.services.task.utils.ClassUtil;
import org.kie.api.task.model.OrganizationalEntity;
import org.kie.api.task.model.Status;
Expand Down Expand Up @@ -386,6 +388,7 @@ public List<TaskSummary> getTasksAssignedAsPotentialOwnerByExpirationDateOptiona
persistenceContext.addParametersToMap("userId", userId, "groupIds", "", "status", status, "expirationDate", expirationDate, "language", "en-UK"),
ClassUtil.<List<TaskSummary>>castClass(List.class)); //@TODO: FIX LANGUANGE
}


@Override
public List<TaskSummary> getTasksByVariousFields(List<Long> workItemIds, List<Long> taskIds, List<Long> procInstIds,
Expand All @@ -403,6 +406,32 @@ public List<TaskSummary> getTasksByVariousFields(List<Long> workItemIds, List<Lo

return getTasksByVariousFields(params, union);
}

public static final String MAX_RESULTS = "maxResults";

public List<TaskSummary> getTasksByVariousFields(List<Long> workItemIds, List<Long> taskIds, List<Long> procInstIds,
List<String> busAdmins, List<String> potOwners, List<String> taskOwners,
List<Status> status, List<String> language, boolean union, Integer maxResults) {
Map<String, List<?>> params = new HashMap<String, List<?>>();
params.put(WORK_ITEM_ID_LIST, workItemIds);
params.put(TASK_ID_LIST, taskIds);
params.put(PROCESS_INST_ID_LIST, procInstIds);
params.put(BUSINESS_ADMIN_ID_LIST, busAdmins);
params.put(POTENTIAL_OWNER_ID_LIST, potOwners);
params.put(ACTUAL_OWNER_ID_LIST, taskOwners);
params.put(STATUS_LIST, status);
params.put(LANGUAGE, language);

if( maxResults != null ) {
if( maxResults <= 0 ) {
return new ArrayList<TaskSummary>();
}
Integer [] maxResultsArr = { maxResults };
params.put(MAX_RESULTS, Arrays.asList(maxResultsArr));
}

return getTasksByVariousFields(params, union);
}

public List<TaskSummary> getTasksByVariousFields( Map<String, List<?>> parameters, boolean union ) {
StringBuilder queryBuilder = new StringBuilder(VARIOUS_FIELDS_TASKSUM_QUERY);
Expand All @@ -420,6 +449,14 @@ public List<TaskSummary> getTasksByVariousFields( Map<String, List<?>> parameter
List<String> language = stringQueryAdder.checkNullAndInstanceOf(parameters, LANGUAGE);
List<Status> status = statusQueryAdder.checkNullAndInstanceOf(parameters, STATUS_LIST);

List<?> maxResultsList = parameters.get(JPATaskPersistenceContext.MAX_RESULTS);
if( maxResultsList != null && ! maxResultsList.isEmpty() ) {
Object maxResults = maxResultsList.get(0);
if( maxResults instanceof Integer ) {
params.put(JPATaskPersistenceContext.MAX_RESULTS, maxResults);
}
}

if( workItemIds != null && workItemIds.size() > 0 ) {
String paramName = "workItemIds";
longQueryAdder.addToQueryBuilder(
Expand Down Expand Up @@ -478,8 +515,12 @@ public List<TaskSummary> getTasksByVariousFields( Map<String, List<?>> parameter
if( ! statusQueryAdder.firstUse ) {
queryBuilder.append(")");
}

// order by task id
queryBuilder.append(" ORDER BY t.id" );

String query = queryBuilder.toString();
logger.debug("QUERY: " + query);
logger.debug("QUERY: {}", query);
return persistenceContext.queryStringWithParametersInTransaction(query, params,
ClassUtil.<List<TaskSummary>>castClass(List.class));
}
Expand Down

0 comments on commit c307845

Please sign in to comment.