forked from nmusaelian-rally/rally-java-rest-apps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGetTeamMembers.java
72 lines (64 loc) · 2.61 KB
/
GetTeamMembers.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
68
69
70
71
72
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 com.rallydev.rest.request.UpdateRequest;
import com.rallydev.rest.response.UpdateResponse;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
public class GetTeamMembers {
public static void main(String[] args) throws URISyntaxException, IOException {
String host = "https://rally1.rallydev.com";
String username = "[email protected]";
String password = "secret";
String workspaceRef = "/workspace/12352608129";
String applicationName = "RESTExample get team members";
RallyRestApi restApi = new RallyRestApi(
new URI(host),
username,
password);
restApi.setApplicationName(applicationName);
System.out.println(restApi.getWsapiVersion());
/*
query on projects where Name contains "Team"
get the TeamMembers collection
query on the collection
the output will look like this:
Project: "Team 2"
UserA
UserB
UserC
*/
try{
QueryRequest projectRequest = new QueryRequest("Project");
projectRequest.setFetch(new Fetch("Name", "TeamMembers"));
projectRequest.setWorkspace(workspaceRef);
projectRequest.setQueryFilter(new QueryFilter("Name", "contains", "Team"));
QueryResponse projectQueryResponse = restApi.query(projectRequest);
int count = projectQueryResponse.getResults().size();
System.out.println(count);
if(count > 0){
for (int i=0;i<count;i++){
JsonObject projectObject = projectQueryResponse.getResults().get(i).getAsJsonObject();
System.out.println("Project: " + projectObject.get("_refObjectName"));
int numberOfTeamMembers = projectObject.getAsJsonObject("TeamMembers").get("Count").getAsInt();
if(numberOfTeamMembers > 0) {
QueryRequest teamRequest = new QueryRequest(projectObject.getAsJsonObject("TeamMembers"));
JsonArray teammates = restApi.query(teamRequest).getResults();
for (int j=0;j<numberOfTeamMembers;j++){
System.out.println(teammates.get(j).getAsJsonObject().get("_refObjectName").getAsString());
}
}
}
}
}catch(Exception e){
e.printStackTrace();
} finally{
restApi.close();
}
}
}