我试图创建一个简单的Java脚本,该脚本将连接到Rally,获取所有缺陷,并以Java对象的形式返回包括讨论在内的缺陷详细信息。这里的问题是,因为我只给出了一个URL,所以讨论返回的是我认为是集合的东西。我被困在如何将对缺陷的讨论作为JSON中的对象而不是仅必须单独运行的另一个查询(由于我们有成千上万个缺陷的原因,我假设了成千上万次)来返回。

这是我的代码:

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();



        }



    }
}

这是我尝试此操作时得到的示例:
{"_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"}

如您所见,讨论将作为URL返回,而不是获取实际的讨论。由于此查询将在运行时使用,因此我希望使用整个对象。

最佳答案

不幸的是,无法在一个请求中获得所有这些数据-您必须为读取的每个缺陷加载“讨论”集合。还要注意,最大页面大小为2000。

这与您要执行的操作不完全相同,但是此示例显示了加载子故事的方式与加载讨论的方式非常相似...

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

10-06 07:38