如何使用Rally API使用Java客户端获取子用户故事?
使用网址为https://us1.rallydev.com/slm/webservice/v2.0/HierarchicalRequirement/ObjectId/Children的Chrome邮差客户端,我可以获取子级用户故事。
但是当我尝试使用Java客户端时,就像这样:
QueryRequest request = new QueryRequest("/HierarchicalRequirement/ObjectId/Children");
它没有用。
任何指针都会有所帮助。
答案 0 :(得分:0)
需要抓取儿童"收集用户故事,然后在单独的请求中保湿。以下是基于latest version Rally toolkit for Java的示例:
public class GetChildStories {
public static void main(String[] args) throws Exception {
String host = "https://rally1.rallydev.com";
String apiKey = "_abc123";
String applicationName = "Find Child Stories of Epics filtered by Tag";
String workspaceRef = "/workspace/12352608129";
RallyRestApi restApi = null;
try {
restApi = new RallyRestApi(new URI(host),apiKey);
QueryRequest storyRequest = new QueryRequest("HierarchicalRequirement");
storyRequest.setWorkspace(workspaceRef);
restApi.setApplicationName(applicationName);
storyRequest.setFetch(new Fetch(new String[] {"Name", "FormattedID", "Tags", "Children"}));
storyRequest.setLimit(1000);
storyRequest.setScopedDown(false);
storyRequest.setScopedUp(false);
storyRequest.setQueryFilter((new QueryFilter("Tags.Name", "contains", "\"tag1\"")).and(new QueryFilter("DirectChildrenCount", ">", "0")));
QueryResponse storyQueryResponse = restApi.query(storyRequest);
System.out.println("Successful: " + storyQueryResponse.wasSuccessful());
System.out.println("Size: " + storyQueryResponse.getTotalResultCount());
for (int i=0; i<storyQueryResponse.getTotalResultCount();i++){
JsonObject storyJsonObject = storyQueryResponse.getResults().get(i).getAsJsonObject();
System.out.println("Name: " + storyJsonObject.get("Name") + " FormattedID: " + storyJsonObject.get("FormattedID"));
QueryRequest childrenRequest = new QueryRequest(storyJsonObject.getAsJsonObject("Children"));
childrenRequest.setFetch(new Fetch("Name","FormattedID"));
int numberOfChildren = storyJsonObject.get("DirectChildrenCount").getAsInt();
System.out.println(numberOfChildren);
//load the collection
JsonArray children = restApi.query(childrenRequest).getResults();
for (int j=0;j<numberOfChildren;j++){
System.out.println("Name: " + children.get(j).getAsJsonObject().get("Name") + children.get(j).getAsJsonObject().get("FormattedID").getAsString());
System.out.println("Name: " + children.get(0).getAsJsonObject().get("Name") + children.get(0).getAsJsonObject().get("FormattedID").getAsString());
}
}
} finally {
if (restApi != null) {
restApi.close();
}
}
}
}