forked from nmusaelian-rally/rally-java-rest-apps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGetTasksOfStories.java
67 lines (59 loc) · 2.77 KB
/
GetTasksOfStories.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.rallydev.rest.RallyRestApi;
import com.rallydev.rest.request.QueryRequest;
import com.rallydev.rest.response.QueryResponse;
import com.rallydev.rest.util.Fetch;
import com.rallydev.rest.util.QueryFilter;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
public class GetTasksOfStories {
public static void main(String[] args) throws Exception {
String host = "https://rally1.rallydev.com";
String username = "[email protected]";
String password = "secret";
String applicationName = "Example: get Tasks of Stories";
String workspaceRef = "/workspace/12345";
String projectRef = "/project/67890";
RallyRestApi restApi = null;
try {
restApi = new RallyRestApi(
new URI(host),
username,
password);
restApi.setApplicationName(applicationName);
QueryRequest storyRequest = new QueryRequest("HierarchicalRequirement");
storyRequest.setProject(projectRef);
storyRequest.setFetch(new Fetch(new String[] {"Name", "FormattedID","c_CustomString","Tasks"}));
storyRequest.setLimit(10000);
storyRequest.setScopedDown(false);
storyRequest.setScopedUp(false);
QueryResponse storyQueryResponse = restApi.query(storyRequest);
System.out.println("Successful: " + storyQueryResponse.wasSuccessful());
System.out.println("Size: " + storyQueryResponse.getTotalResultCount());
System.out.println("Results Size: " + storyQueryResponse.getResults().size());
int totalTasks = 0;
for (int i=0; i<storyQueryResponse.getResults().size();i++){
JsonObject storyJsonObject = storyQueryResponse.getResults().get(i).getAsJsonObject();
System.out.println("Name: " + storyJsonObject.get("Name") + " FormattedID: " + storyJsonObject.get("FormattedID"));
int numberOfTasks = storyJsonObject.getAsJsonObject("Tasks").get("Count").getAsInt();
if(numberOfTasks > 0) {
totalTasks += numberOfTasks;
QueryRequest taskRequest = new QueryRequest(storyJsonObject.getAsJsonObject("Tasks"));
taskRequest.setFetch(new Fetch("Name","FormattedID"));
//load the collection
JsonArray tasks = restApi.query(taskRequest).getResults();
for (int j=0;j<numberOfTasks;j++){
System.out.println("Name: " + tasks.get(j).getAsJsonObject().get("Name") + tasks.get(j).getAsJsonObject().get("FormattedID").getAsString());
}
}
}
System.out.println("Total number of tasks: " + totalTasks);
} finally {
if (restApi != null) {
restApi.close();
}
}
}
}