Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.kie.remote.services.rest;
  
  import java.util.Arrays;
  import java.util.HashMap;
  import java.util.List;
  import java.util.Map;
  
 import  javax.enterprise.context.RequestScoped;
 import  javax.inject.Inject;
 import  javax.ws.rs.GET;
 import  javax.ws.rs.Path;
 import  javax.ws.rs.core.Context;
 import  javax.ws.rs.core.HttpHeaders;
 import  javax.ws.rs.core.Response;
 
 import  org.jbpm.services.task.commands.GetTasksByVariousFieldsCommand;
 import  org.kie.api.task.model.Status;
 import  org.kie.api.task.model.TaskSummary;
 import  org.kie.internal.identity.IdentityProvider;
 import  org.kie.services.client.serialization.jaxb.impl.query.JaxbQueryProcessInstanceResult;
 import  org.kie.services.client.serialization.jaxb.impl.query.JaxbQueryTaskResult;

Resource that does various query operations
 
 
 @RequestScoped
 @Path("/query/")
 public class QueryResourceImpl extends ResourceBase {
 
     @Context
     private HttpHeaders headers;
 
     @Inject
     private IdentityProvider identityProvider;
 
     public void setIdentityProvider( IdentityProvider identityProvider ) {
         this. = identityProvider;
     }
 
     public void setHeaders( HttpHeaders headers ) {
         this. = headers;
     }
 
     // REST operations -----------------------------------------------------------------------------------------------------------
 
     @GET
     @Path("/runtime/task")
     public Response queryTasks() {
         String oper = getRelativePath();
         Map<StringString[]> params = makeQueryParametersLowerCase(getRequestParams());
         checkIfParametersAreAllowed(params, QueryResourceData.getQueryParameters(), oper);
         
         int[] pageInfo = getPageNumAndPageSize(paramsoper);
         int maxNumResults = getMaxNumResultsNeeded(pageInfo);
 
         InternalTaskQueryHelper queryHelper = new InternalTaskQueryHelper(this);
         JaxbQueryTaskResult result 
             = queryHelper.queryTaskOrProcInstAndAssociatedVariables(.getName(), paramspageInfomaxNumResults);
         queryHelper.dispose();
         
         return createCorrectVariant(result);
     }
 
     @GET
     @Path("/runtime/process")
     public Response queryProcessInstances() {
         String oper = getRelativePath();
         Map<StringString[]> params = makeQueryParametersLowerCase(getRequestParams());
         checkIfParametersAreAllowed(params, QueryResourceData.getQueryParameters(), oper);
         
         int[] pageInfo = getPageNumAndPageSize(paramsoper);
         int maxNumResults = getMaxNumResultsNeeded(pageInfo);
 
         String identityNotNeeded = null;
         InternalProcInstQueryHelper queryHelper = new InternalProcInstQueryHelper(this);
         JaxbQueryProcessInstanceResult result 
             = queryHelper.queryTaskOrProcInstAndAssociatedVariables(identityNotNeededparamspageInfomaxNumResults);
         queryHelper.dispose();
 
         return createCorrectVariant(result);
     }
   
     private static final String[] allowedQueryParams = { 
         "workItemId",             // 0
         "taskId",                 // 1
         "businessAdministrator",  // 2
         "potentialOwner",         // 3
         "status",                 // 4
         "taskOwner",              // 5
         "processInstanceId",      // 6
         "language",               // 7
        "union"                   // 8
    };
    @GET
    @Path("/task")
    public Response taskSummaryQuery() {
        Map<StringString[]> params = getRequestParams();
        String oper = getRelativePath();
        checkIfParametersAreAllowed(params, Arrays.asList(), "task query");
        List<LongworkItemIds = getLongListParam([0], falseparams"query"true);
        List<LongtaskIds = getLongListParam([1], falseparams"query"true);
        List<LongprocInstIds = getLongListParam([6], falseparams"query"true);
        List<StringbusAdmins = getStringListParamAsList([2], falseparams"query");
        List<StringpotOwners = getStringListParamAsList([3], falseparams"query");
        List<StringtaskOwners = getStringListParamAsList([5], falseparams"query");
        List<Stringlanguage = getStringListParamAsList([7], falseparams"query");
        String unionStr = getStringParam([8], falseparams"query");
        boolean union = Boolean.parseBoolean(unionStr); // null, etc == false
        List<StringstatusStrList = getStringListParamAsList([4], falseparams"query");
        List<Status> statuses = convertStringListToStatusList(statusStrList);
        int[] pageInfo = getPageNumAndPageSize(paramsoper);
        int maxResults = getMaxNumResultsNeeded(pageInfo);
        GetTasksByVariousFieldsCommand queryCmd = new GetTasksByVariousFieldsCommand(workItemIdstaskIdsprocInstIdsbusAdmins,
                potOwnerstaskOwnersstatuseslanguageunionmaxResults);
        queryCmd.setUserId(.getName());
        List<TaskSummary> results = doRestTaskOperationWithTaskId((LongnullqueryCmd);
        .debug("{} results found."results.size());
        JaxbTaskSummaryListResponse resultList = paginateAndCreateResult(pageInforesultsnew JaxbTaskSummaryListResponse());
        .debug("Returning {} results after pagination."resultList.getList().size());
        return createCorrectVariant(resultList);
    }
   
    // helper methods -------------------------------------------------------------------------------------------------------------
   
    private static Map<StringString[]> makeQueryParametersLowerCase(Map<StringString[]> params) { 
        ifparams == null || params.isEmpty() )  { 
            return params;
        }
        Map<StringString[]> lowerCaseParams = new HashMap<StringString[]>(params.size());
        forEntry<StringString[]> entry : params.entrySet() ) { 
           lowerCaseParams.put(entry.getKey().toLowerCase(), entry.getValue()) ;
        }
        return lowerCaseParams;
    }
    
    public static void checkIfParametersAreAllowed(Map<StringString[]> paramsCollection<StringallowedParamsString oper) { 
        ifparams == null || params.isEmpty() )  { 
            return;
        }
       
        EACHPARAM: forString queryParam : params.keySet() ) {
            forString allowedParam : allowedParams ) {
                ifallowedParam.equalsIgnoreCase(queryParam) || .contains(queryParam) ) {
                    continue EACHPARAM;
                }
            }
            throw KieRemoteRestOperationException.badRequest(queryParam
                        + " is an unknown and unsupported query param for the " + oper + " operation.");
        }
    }
    
New to GrepCode? Check out our FAQ X