首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Java Rally Rest API提取Rally缺陷讨论

使用Java Rally Rest API提取Rally缺陷讨论
EN

Stack Overflow用户
提问于 2019-05-30 21:56:21
回答 1查看 512关注 0票数 7

我正在尝试创建一个简单的Java脚本,它将连接到Rally,获取所有缺陷,并将包括讨论在内的缺陷详细信息作为Java对象返回。这里的问题是,讨论被返回为我认为是集合的内容,因为只给出了一个URL。我被困在如何将对缺陷的讨论作为JSON中的一个对象返回,而不是只返回另一个必须单独运行的查询(我假设有数千次,因为我们有数千个缺陷)。

下面是我的代码:

代码语言:javascript
复制
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();



        }



    }
}

以下是我在尝试此操作时得到的一个示例:

代码语言:javascript
复制
{"_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返回的,而不是获取实际的讨论。因为这个查询将在运行时使用,所以我更喜欢整个对象。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-06-05 01:00:07

不幸的是,没有办法在一个请求中获得所有数据-你必须为你读到的每个缺陷加载讨论集。同样值得注意的是,最大页面大小是2000。

这和你想要做的并不完全一样,但是这个例子展示了加载子故事就像你加载讨论一样……

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

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56379712

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档