gpt4 book ai didi

java - 如何使用 rally rest api 查找给定迭代和给定项目下的用户故事列表

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:13:49 25 4
gpt4 key购买 nike

我能够在项目对象下获得迭代。现在我如何在该项目下获得我需要的迭代,然后使用 JAVA 工具包深入到该迭代中的故事?

https://sandbox.rallydev.com/slm/webservice/v2.0/project/7191194697/iterations

最佳答案

给定一个项目:

String projectRef = "/project/1234";

您可以将您的请求范围限定如下:

iterationRequest.setProject(projectRef);

storyRequest.setProject(projectRef);

如果您将故事请求限定在项目范围内,那么如果您已经知道迭代,则可以通过遍历 Iteration.Name 来查询故事:

storyRequest.setQueryFilter(new QueryFilter("Iteration.Name", "=", "my Iteration 1"));

这是一个更复杂的示例,它返回分配给属于特定版本的 timbox 的迭代的故事。例如,如果每个版本有 4 个迭代,此代码将返回分配给所有四个迭代的故事。

如果您针对沙箱进行编码,请相应地替换主机变量中的值。

public class FindIterationsByReleaseDateAndStories {

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


String host = "https://rally1.rallydev.com";
String username = "user@co.com";
String password = "secret";
String projectRef = "/project/12352608219";
String applicationName = "Find Iterations by Release Dates and Stories";

RallyRestApi restApi = null;

try {
restApi = new RallyRestApi(
new URI(host),
username,
password);
restApi.setApplicationName(applicationName);

System.out.println(restApi.getWsapiVersion());

QueryRequest releaseRequest = new QueryRequest("Release");
releaseRequest.setFetch(new Fetch("ReleaseStartDate", "ReleaseDate"));
releaseRequest.setScopedDown(false);
releaseRequest.setScopedUp(false);
releaseRequest.setProject(projectRef);
releaseRequest.setQueryFilter(new QueryFilter("Name", "=", "r1"));

QueryResponse releaseQueryResponse = restApi.query(releaseRequest);
int numberOfReleasesInProject = releaseQueryResponse.getTotalResultCount();
System.out.println(numberOfReleasesInProject);
JsonObject releaseJsonObject = releaseQueryResponse.getResults().get(0).getAsJsonObject();
System.out.println(releaseJsonObject.get("ReleaseStartDate"));
System.out.println(releaseJsonObject.get("ReleaseDate"));

String rsd = releaseJsonObject.get("ReleaseStartDate").getAsString();
String rd = releaseJsonObject.get("ReleaseDate").getAsString();

QueryRequest iterationRequest = new QueryRequest("Iteration");
iterationRequest.setFetch(new Fetch("Name","StartDate","EndDate"));
iterationRequest.setScopedDown(false);
iterationRequest.setScopedUp(false);
iterationRequest.setProject(projectRef);
iterationRequest.setQueryFilter(new QueryFilter("StartDate", ">=", rsd).and(new QueryFilter("EndDate", "<=", rd)));

QueryResponse iterationQueryResponse = restApi.query(iterationRequest);
int numberOfIteraitons = iterationQueryResponse.getTotalResultCount();
System.out.println("numberOfIteraitons " + numberOfIteraitons);
if(numberOfIteraitons >0){
for (int i=0;i<numberOfIteraitons;i++){
JsonObject iterationJsonObject = iterationQueryResponse.getResults().get(i).getAsJsonObject();
String iterationName = iterationJsonObject.get("Name").getAsString();
System.out.println("iteration: " + iterationName);
QueryRequest storyRequest = new QueryRequest("HierarchicalRequirement");
storyRequest.setProject(projectRef);
storyRequest.setFetch(new Fetch(new String[] {"Name", "FormattedID","ScheduleState"}));
storyRequest.setLimit(1000);
storyRequest.setScopedDown(false);
storyRequest.setScopedUp(false);
storyRequest.setQueryFilter(new QueryFilter("Iteration.Name", "=", iterationName));

QueryResponse storyQueryResponse = restApi.query(storyRequest);
System.out.println("Number of stories in " + iterationName + " :" + storyQueryResponse.getTotalResultCount());

for (int j=0; j<storyQueryResponse.getResults().size();j++){
JsonObject storyJsonObject = storyQueryResponse.getResults().get(j).getAsJsonObject();
System.out.println("Name: " + storyJsonObject.get("Name") + " FormattedID: " + storyJsonObject.get("FormattedID") + " ScheduleState: " + storyJsonObject.get("ScheduleState"));
}
}
}
}
finally{
if (restApi != null) {
restApi.close();
}
}

}
}

更新:就您在评论中提出的问题而言,上面的代码等同于

https://rally1.rallydev.com/slm/webservice/v2.0/hierarchicalrequirement?query=((Iteration.Name = i1) AND (Project = /project/12352608219))

还有其他方法可以达到相同的结果。迭代名称可能不是唯一的,因此项目引用的第二个条件。在代码中,首先设置请求的项目,这就是查询本身使用一个条件但实际上有两个条件的原因。如果您知道迭代的引用或 ObjectID,则相同的结果将从 (Iteration =/iteration/123456789) 返回,并且无需按项目过滤,因为引用或 ObjectID 是唯一的。

WS API 文档是交互式的。在 WS API 中测试您的查询,如果您想查看查询是如何形成的,则从地址栏中复制生成的查询 URL:

-在预期对象的上下文中查询:单击对象模型中的工作项类型,例如Defect 或 HierarchicalRequirement,然后在查询框中键入查询。

-在框中输入查询,例如 (Iteration.Name = i1)

-点击查询按钮

-结果显示在窗口中,您可以从中从浏览器的地址栏复制查询 URL。

关于java - 如何使用 rally rest api 查找给定迭代和给定项目下的用户故事列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23964964/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com