Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extracting Rally Defect Discussion using the Java Rally Rest API

Tags:

java

rest

rally

I am attempting to create a simple Java script which will connect to Rally, fetch all of the defects and return the defect details including the discussion as a Java object. The problem here is that the Discussion is returned as what I believe is a collection because only a URL is given. I am stuck on how to return the discussion for the defect as an object within the JSON rather than only another query which would have to be run separately (thousands of times I presume since we have thousands of defects).

Here is my code:

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.rallydev.rest.RallyRestApi;
import com.rallydev.rest.request.GetRequest;
import com.rallydev.rest.request.QueryRequest;
import com.rallydev.rest.request.UpdateRequest;
import com.rallydev.rest.response.QueryResponse;
import com.rallydev.rest.util.Fetch;
import com.rallydev.rest.util.QueryFilter;
import com.rallydev.rest.util.Ref;
import org.json.simple.JSONArray;

public class ExtractData{

    public static void main(String[] args) throws URISyntaxException, IOException, NumberFormatException

    {

        RallyRestApi restApi = new RallyRestApi(new URI("https://rally1.rallydev.com"), "apiKeyHere");
        restApi.setProxy(URI.create("http://usernameHere:passwordHere0@proxyHere:8080"));
        restApi.setApplicationName("QueryExample");

        //Will store all of the parsed defect data
        JSONArray defectData = new JSONArray();

        try{

            QueryRequest defects = new QueryRequest("defect");

            defects.setFetch(new Fetch("FormattedID","Discussion","Resolution"));
            defects.setQueryFilter(new QueryFilter("Resolution","=","Configuration Change"));
            defects.setPageSize(5000);
            defects.setLimit(5000);

            QueryResponse queryResponse = restApi.query(defects);

            if(queryResponse.wasSuccessful()){

                System.out.println(String.format("\nTotal results: %d",queryResponse.getTotalResultCount()));

                for(JsonElement result: queryResponse.getResults()){
                    JsonObject defect = result.getAsJsonObject();
                    System.out.println(defect);




                }
            }else{
                System.err.print("The following errors occured: ");
                for(String err: queryResponse.getErrors()){
                    System.err.println("\t+err");
                }
            }

        }finally{

            restApi.close();



        }



    }
}

Here is an example of what I am getting when I attempt this:

{"_rallyAPIMajor":"2","_rallyAPIMinor":"0","_ref":"https://rally1.rallydev.com/slm/webservice/v2.0/defect/30023232168","_refObjectUUID":"cea42323c2f-d276-4078-92cc-6fc32323ae","_objectVersion":"6","_refObjectName":"Example defect name","Discussion":{"_rallyAPIMajor":"2","_rallyAPIMinor":"0","_ref":"https://rally1.rallydev.com/slm/webservice/v2.0/Defect/32323912168/Discussion","_type":"ConversationPost","Count":0},"FormattedID":"DE332322","Resolution":"Configuration Change","Summary":{"Discussion":{"Count":0}},"_type":"Defect"}

As you can see the discussion is being returned as a URL rather than fetching the actual discussion. As this query will be used at runtime I'd prefer the entire object.

like image 515
jesric1029 Avatar asked May 30 '19 13:05

jesric1029


1 Answers

Unfortunately there is no way to get all of that data in one request- you'll have to load the Discussion collection for each defect you read. Also of note, the max page size is 2000.

This isn't exactly the same as what you're trying to do, but this example shows loading child stories much like you'd load discussions...

https://github.com/RallyCommunity/rally-java-rest-apps/blob/master/GetChildStories.java#L37

like image 58
Kyle Morse Avatar answered Sep 29 '22 03:09

Kyle Morse