forked from nmusaelian-rally/rally-java-rest-apps
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathSetStoryRankInManualRankingWorkspace.java
More file actions
70 lines (64 loc) · 3.32 KB
/
SetStoryRankInManualRankingWorkspace.java
File metadata and controls
70 lines (64 loc) · 3.32 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
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 SetStoryRankInManualRankingWorkspace {
public static void main(String[] args) throws URISyntaxException, IOException {
String host = "https://rally1.rallydev.com";
String apiKey = "_abc123";
String applicationName = "NickM:SetStoryRank";
String workspaceRef = "/workspace/1234";//manual ranking workspace
RallyRestApi restApi = null;
restApi = new RallyRestApi(new URI(host),apiKey);
restApi.setApplicationName(applicationName);
/**********************************FIND STORY***********************************************************/
try{
QueryRequest storyRequest = new QueryRequest("HierarchicalRequirement");
storyRequest.setFetch(new Fetch("Name","Rank","PlanEstimate"));
storyRequest.setWorkspace(workspaceRef);
storyRequest.setQueryFilter(new QueryFilter("FormattedID", "=", "US71"));
QueryResponse storyQueryResponse = restApi.query(storyRequest);
JsonObject storyJsonObject = storyQueryResponse.getResults().get(0).getAsJsonObject();
String storyRef = storyJsonObject.get("_ref").getAsString();
System.out.println("Name: " + storyJsonObject.get("Name") + " Rank: " + storyJsonObject.get("Rank"));
/*****************************************************UPDATE RANK****************************************/
JsonObject storyUpdate = new JsonObject();
storyUpdate.addProperty("Rank", 340.0);
//storyUpdate.addProperty("PlanEstimate", 10);
UpdateRequest updateStoryRequest = new UpdateRequest(storyRef,storyUpdate);
//Rank update will not work without setting workspace parameter if workspace is not default:
updateStoryRequest.addParam("workspace","/workspace/1234");
UpdateResponse updateResponse = restApi.update(updateStoryRequest);
if (updateResponse.wasSuccessful()) {
System.out.println("Successfully updated story: " + storyJsonObject.get("Rank") +
" to: " + storyUpdate.get("Rank"));
String[] warningList;
warningList = updateResponse.getWarnings();
for (int i=0;i<warningList.length;i++) {
System.out.println(warningList[i]);
}
} else {
System.out.println("Error occurred attempting to update story: " + storyJsonObject.get("Name"));
String[] errorList;
errorList = updateResponse.getErrors();
for (int i=0;i<errorList.length;i++) {
System.out.println(errorList[i]);
}
}
}catch(Exception e){
System.out.println("Exception occurred....");
e.printStackTrace();
}
finally{
//Release all resources
restApi.close();
}
}
}