我能够在项目对象下获得迭代.现在,如何获取该项目下所需的迭代,然后使用JAVA工具包深入了解该迭代中的故事?
解决方法:
给定一个项目:
String projectRef = "/project/1234";
您可以将请求的范围如下:
iterationRequest.setProject(projectRef);
要么
storyRequest.setProject(projectRef);
如果将故事请求的范围限定在项目中,那么如果您已经知道迭代,则可以遍历Iteration.Name来查询故事:
storyRequest.setQueryFilter(new QueryFilter("Iteration.Name", "=", "my Iteration 1"));
这是一个更复杂的示例,该示例返回分配给特定发行版timbox内迭代的故事.例如,如果每个发行版有4个迭代,则此代码将返回分配给所有四个迭代的故事.
如果针对沙箱进行编码,请相应地替换host变量中的值.
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
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
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是交互式的.如果要查看查询的形成方式,请在WS API中测试查询并从地址栏中复制生成的查询URL:
-在预期对象的上下文中查询:单击对象模型中的工作项类型,例如在查询框中键入查询之前,请先执行Defect或HierarchicalRequirement.
-在框中输入查询,例如(Iteration.Name = i1)
-单击查询按钮
-结果显示在窗口中,您可以从中从浏览器的地址栏中复制查询URL.
标签:rest,rally,java
来源: https://codeday.me/bug/20191029/1960447.html