【问题标题】:Extracting Rally Defect Discussion using the Java Rally Rest API使用 Java Rally Rest API 提取 Rally 缺陷讨论
【发布时间】:2019-05-30 13:56:21
【问题描述】:

我正在尝试创建一个简单的 Java 脚本,它将连接到 Rally,获取所有缺陷并返回缺陷详细信息,包括作为 Java 对象的讨论。这里的问题是,因为只给出了一个 URL,所以我认为 Discussion 是作为一个集合返回的。我被困在如何将缺陷的讨论作为 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 返回的,而不是获取实际讨论。由于此查询将在运行时使用,我更喜欢整个对象。

【问题讨论】:

    标签: java rest rally


    【解决方案1】:

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

    这与您尝试执行的操作并不完全相同,但此示例显示加载子故事就像您加载讨论一样...

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

    【讨论】:

      猜你喜欢
      • 2013-07-29
      • 1970-01-01
      • 1970-01-01
      • 2012-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多