我能够在项目对象下获得迭代。现在,我如何在该项目下获得我需要的迭代,然后使用JAVA工具包深入查看该迭代中的故事?
https://sandbox.rallydev.com/slm/webservice/v2.0/project/7191194697/iterations
答案 0 :(得分:4)
鉴于一个项目:
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))
还有其他方法可以获得相同的结果。迭代名称可能不是唯一的,因此项目引用的第二个条件。在代码中首先设置请求的项目,这就是查询本身使用一个条件的原因,但实际上有两个条件。如果你知道你的迭代的ref或ObjectID,那么将从(Iteration = / iteration / 123456789)返回相同的结果,并且不需要按项目过滤,因为引用或ObjectID是唯一的。
WS API doc是interactive。如果要查看查询的形成方式,请在WS API中测试查询并从地址栏复制生成的查询URL:
-Query在目标对象的上下文中:单击对象模型中的工作项类型,例如在查询框中键入查询之前的缺陷或HierarchicalRequirement。
- 在框中输入查询,例如(Iteration.Name = i1)
- 点击查询按钮
- 结果显示在窗口中,您可以从该窗口中复制浏览器地址栏中的查询URL。