Uh oh!
There was an error while loading. Please reload this page.
forked from nmusaelian-rally/rally-java-rest-apps
- Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathAddMilestone.java
More file actions
Latest commit
86 lines (74 loc) · 4.27 KB
/
Copy pathAddMilestone.java
File metadata and controls
86 lines (74 loc) · 4.27 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
importjava.io.IOException;
importjava.net.URI;
importjava.net.URISyntaxException;
importcom.google.gson.JsonArray;
importcom.google.gson.JsonObject;
importcom.rallydev.rest.RallyRestApi;
importcom.rallydev.rest.request.QueryRequest;
importcom.rallydev.rest.request.UpdateRequest;
importcom.rallydev.rest.response.QueryResponse;
importcom.rallydev.rest.response.UpdateResponse;
importcom.rallydev.rest.util.Fetch;
importcom.rallydev.rest.util.QueryFilter;
publicclassAddMilestone {
publicstaticvoidmain(String[] args) throwsURISyntaxException, IOException {
Stringhost = "https://rally1.rallydev.com";
StringapiKey = "_abc123";
StringworkspaceRef = "/workspace/12352608129";
StringapplicationName = "Nick: updateMilestoneCollection";
RallyRestApirestApi = newRallyRestApi(newURI(host),apiKey);
restApi.setApplicationName(applicationName);
try {
StringmilestoneName = "Mid January";
StringstoryId = "US30015";
QueryRequestmilestoneRequest = newQueryRequest("Milestone");
milestoneRequest.setWorkspace(workspaceRef);
milestoneRequest.setQueryFilter(newQueryFilter("Name", "=", milestoneName));
QueryResponsemilestoneQueryResponse = restApi.query(milestoneRequest);
if(milestoneQueryResponse.getTotalResultCount() == 0){
System.out.println("Cannot find milestone: " + milestoneName);
return;
}
JsonObjectmilestoneJsonObject = milestoneQueryResponse.getResults().get(0).getAsJsonObject();
StringmilestoneRef = milestoneJsonObject.get("_ref").getAsString();
System.out.println(milestoneRef);
QueryRequeststoryRequest = newQueryRequest("HierarchicalRequirement");
storyRequest.setWorkspace(workspaceRef);
storyRequest.setFetch(newFetch("FormattedID", "Name", "Milestones"));
storyRequest.setQueryFilter(newQueryFilter("FormattedID", "=", storyId));
QueryResponsestoryQueryResponse = restApi.query(storyRequest);;
if (storyQueryResponse.getTotalResultCount() == 0) {
System.out.println("Cannot find story : " + storyId);
return;
}
JsonObjectstoryJsonObject = storyQueryResponse.getResults().get(0).getAsJsonObject();
StringstoryRef = storyJsonObject.get("_ref").getAsString();
System.out.println(storyRef);
intnumberOfMilestones = storyJsonObject.getAsJsonObject("Milestones").get("Count").getAsInt();
System.out.println(numberOfMilestones + " milestone(s) on " + storyId);
QueryRequestmilestoneCollectionRequest = newQueryRequest(storyJsonObject.getAsJsonObject("Milestones"));
milestoneCollectionRequest.setFetch(newFetch("Name"));
JsonArraymilestones = restApi.query(milestoneCollectionRequest).getResults();
for (intj=0;j<numberOfMilestones;j++){
System.out.println("Milestone Name: " + milestones.get(j).getAsJsonObject().get("Name"));
}
milestones.add(milestoneJsonObject);
JsonObjectstoryUpdate = newJsonObject();
storyUpdate.add("Milestones", milestones);
UpdateRequestupdateStoryRequest = newUpdateRequest(storyRef,storyUpdate);
UpdateResponseupdateStoryResponse = restApi.update(updateStoryRequest);
if (updateStoryResponse.wasSuccessful()) {
System.out.println("Successfully updated : " + storyId + " Milestones after update: ");
QueryRequestmilestoneCollectionRequest2 = newQueryRequest(storyJsonObject.getAsJsonObject("Milestones"));
milestoneCollectionRequest2.setFetch(newFetch("Name"));
JsonArraymilestonesAfterUpdate = restApi.query(milestoneCollectionRequest2).getResults();
intnumberOfMilestonesAfterUpdate = restApi.query(milestoneCollectionRequest2).getResults().size();
for (intj=0;j<numberOfMilestonesAfterUpdate;j++){
System.out.println("Milestone Name: " + milestonesAfterUpdate.get(j).getAsJsonObject().get("Name"));
}
}
} finally {
restApi.close();
}
}
}