Rally Software

 View Only
Expand all | Collapse all

set pagesize limit for Getrequest using Java

  • 1.  set pagesize limit for Getrequest using Java

    Posted Sep 14, 2020 06:18 PM
    Hi All
    THe question i have is i am trying to get all the userstories related to a release, i created a query request for type release and got the ref to workproduct. 

    so i got something like this from the query response "https://rally1.rallydev.com/slm/webservice/v2.0/Release/12345678/WorkProducts"
    Now I am use this in my GET REQUEST to get all the user stories related to the Release.
    The response is giving only 20 user stories since the default page size is 20. 
    Is there a way to increase the page size for get request.

    the code is something like this :

    QueryRequest iterationRequest = new QueryRequest("release");
    iterationRequest.setFetch(new Fetch("Name", "Workspace", "WorkProducts","Feature"));
    iterationRequest.setWorkspace("/workspace/12345678");
    iterationRequest.setProject("/project/4567890");
    iterationRequest.setPageSize(200);
    iterationRequest.setQueryFilter(new QueryFilter("Name", "=", Release));
    QueryResponse iterationQueryResponse = restApi.query(iterationRequest);
    JsonArray iterationQueryResults = iterationQueryResponse.getResults();
    JsonElement iterationQueryElement = iterationQueryResults.get(0);
    JsonObject iterationQueryObject = iterationQueryElement.getAsJsonObject();
    JsonObject workprodobj = iterationQueryObject.get("WorkProducts").getAsJsonObject();
    String workprodref = workprodobj.get("_ref").getAsString();
    System.out.println("workprodref :" + workprodref);

    GetRequest getRequest = new GetRequest(workprodref);
    getRequest.setFetch(new Fetch("FormattedID"));
    GetResponse getResponse = restApi.get(getRequest);

    The response output is like this 
    {"QueryResult": {"_rallyAPIMajor": "2", "_rallyAPIMinor": "0", "Errors": [], "TotalResultCount": 120, "StartIndex": 1, "PageSize": 20,
    "Results": [{"_rallyAPIMajor": "2","_rallyAPIMinor": "0","_ref": "https://rally1.rallydev.com/slm/webservice/v2.0/hierarchicalrequirement/123456789",
    "_refObjectUUID": "xxxxxx",
    "_objectVersion": "1",
    "_refObjectName": "obj name removed masked",
    "FormattedID": "US123456",
    "DirectChildrenCount": 0,
    } .....


    Can we change the page size from 20 to 200  for a getrequest??


  • 2.  RE: set pagesize limit for Getrequest using Java

    Posted Sep 15, 2020 09:32 AM
    Hi Satish,

    Yes, you can increase the page size to 200. Here's what I use, chosen from some testing I did about size of response and time to get the response:

    queryRequest.setStart( 0 );
    queryRequest.setPageSize( 800 );
    But no matter what size you set, you might have more results than that, so you need to get the count of result:
    queryResponse.getTotalResultCount();
    and loop through the pages getting 1 page of results back until you have the total results. You do this by resetting the starting record count in increments of the page size.
    For example if you set your pageSize to 200, then the below code will get the first 200 results, then will go back and fetch the 201-400th record, etc.
    Since I setStart(0) initially, then after the 1st page it'll be reset to "0 + 200 (Page size)" = 200, then "200 + 200 (page size)" = 400, then "400 + 200 (page size)" and so on.

    queryRequest.setStart( queryRequest.getStart() + queryRequest.getPageSize() );



  • 3.  RE: set pagesize limit for Getrequest using Java

    Posted Sep 15, 2020 12:22 PM
    Thanks Simon, I was able to use page size for query request(my code on line 5 already has it ), my question is can we use the page size to get request/ get response . 
    All I am trying to do is 
    The below URL contains all the work products for a release, I want to run this URL through Get request method and get all user stories, but by default the get request defaults to 20, so is there a way to set page size in Getrequest ? or is there a way I can pass this URL in the query request to get response.

    https://rally1.rallydev.com/slm/webservice/v2.0/Release/12345678/WorkProducts


  • 4.  RE: set pagesize limit for Getrequest using Java

    Posted Sep 15, 2020 02:11 PM
    Add this to the query to get 123 items:

    &query=&fetch=true&start=1&pagesize=123


  • 5.  RE: set pagesize limit for Getrequest using Java

    Posted Sep 15, 2020 02:41 PM
    Thanks Simon,
    I tried that as well, and I get below error , not sure if we can alter the URL's 

      workprodref = workprodref + "&query=&fetch=true&start=1&pagesize=180";
    System.out.println("workprodref :" + workprodref);

    GetRequest getRequest = new GetRequest(workprodref);
    getRequest.setFetch(new Fetch("FormattedID"));
    GetResponse getResponse = restApi.get(getRequest);
    I get the below error now 
    workprodref :https://rally1.rallydev.com/slm/webservice/v2.0/Release/12345678/WorkProducts&query=&fetch=true&start=1&pagesize=180
    Exception in thread "main" java.io.IOException: HTTP/1.1 404 Not Found
    at com.rallydev.rest.client.HttpClient.executeRequest(HttpClient.java:163)
    at com.rallydev.rest.client.HttpClient.doRequest(HttpClient.java:145)
    at com.rallydev.rest.client.ApiKeyClient.doRequest(ApiKeyClient.java:37)
    at com.rallydev.rest.client.HttpClient.doGet(HttpClient.java:221)
    at com.rallydev.rest.RallyRestApi.get(RallyRestApi.java:199)



  • 6.  RE: set pagesize limit for Getrequest using Java

    Posted Sep 15, 2020 03:01 PM
    Ah - ok, my mistake I didn't read your code carefully enough.

    You're able to set the initial 200 page size, but then you're pulling the first item and following the "WorkProducts" link using GetRequest which defaults to a page size of 20.

    The only way I could get that to work was to add the entire query again on to the "WorkProducts" URL:
    &query=(Name%20%3D%20XYZ)&fetch=true&start=1&pagesize=123



  • 7.  RE: set pagesize limit for Getrequest using Java

    Posted Sep 15, 2020 03:15 PM
    Thanks Simon,

    This was my initial URL, 
    https://rally1.rallydev.com/slm/webservice/v2.0/Release/12345678/WorkProducts&query=&fetch=true&start=1&pagesize=180

    what should i add in the highlighted text?
    https://rally1.rallydev.com/slm/webservice/v2.0/Release/12345678/WorkProducts?&query=(Name%20%3D%20XYZ)&fetch=true&start=1&pagesize=123


  • 8.  RE: set pagesize limit for Getrequest using Java

    Posted Sep 15, 2020 03:29 PM
    This is the query that needs to go here:

    iterationRequest.setQueryFilter(new QueryFilter("Name", "=", Release));

    Replace XYZ with your Release name (HTML escaping any spaces/hyphens etc in the name)


  • 9.  RE: set pagesize limit for Getrequest using Java

    Posted Sep 15, 2020 05:16 PM
    i get the same error message

     
    workprodref :https://rally1.rallydev.com/slm/webservice/v2.0/Release/12345678/WorkProducts?&query=(Name%20=%22ABCD%20REL%205%22)&fetch=true&start=1&pagesize=123
    Exception in thread "main" java.io.IOException: HTTP/1.1 404 Not Found
    at com.rallydev.rest.client.HttpClient.executeRequest(HttpClient.java:163)
    at com.rallydev.rest.client.HttpClient.doRequest(HttpClient.java:145)
    at com.rallydev.rest.client.ApiKeyClient.doRequest(ApiKeyClient.java:37)
    at com.rallydev.rest.client.HttpClient.doGet(HttpClient.java:221)
    at com.rallydev.rest.RallyRestApi.get(RallyRestApi.java:199)


  • 10.  RE: set pagesize limit for Getrequest using Java

    Posted Sep 16, 2020 12:42 PM
    i replaced = with % 3D but did not solve, 
    When i run it in browser, it says invalid parameter 
    but if I remove /workproducts , it give me a output but that doesn't give me the list of User stories ,it just give me the release details .


  • 11.  RE: set pagesize limit for Getrequest using Java
    Best Answer

    Posted Sep 16, 2020 01:12 PM
    I was able to solve it 
    we need to add the param to the get request using getrequest.addparm 
    below is the working code 
    iterationRequest.setQueryFilter(new QueryFilter("Name", "=", Release));
    QueryResponse iterationQueryResponse = restApi.query(iterationRequest);
    JsonArray iterationQueryResults = iterationQueryResponse.getResults();
    JsonElement iterationQueryElement = iterationQueryResults.get(0);
    JsonObject iterationQueryObject = iterationQueryElement.getAsJsonObject();
    JsonObject workprodobj = iterationQueryObject.get("WorkProducts").getAsJsonObject();
    String workprodref = workprodobj.get("_ref").getAsString();
    System.out.println("workprodref :" + workprodref);

    GetRequest getRequest = new GetRequest(workprodref);
    getRequest.addParam("fetch","true");
    getRequest.addParam("start","1");
    getRequest.addParam("pagesize","100");
    getRequest.setFetch(new Fetch("FormattedID"));
    GetResponse getResponse = restApi.get(getRequest);


  • 12.  RE: set pagesize limit for Getrequest using Java

    Posted Sep 16, 2020 01:17 PM
    Yep, that makes total sense, since the underlying msg is JSON and "addParam" is just adding fields (key/value pairs).

    Glad you got it resolved. 

    Thanks for sharing.