forked from nmusaelian-rally/rally-java-rest-apps
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathUpdateStory.java
More file actions
76 lines (69 loc) · 3.77 KB
/
UpdateStory.java
File metadata and controls
76 lines (69 loc) · 3.77 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
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 UpdateStory {
public static void main(String[] args) throws URISyntaxException, IOException {
String host = "https://rally1.rallydev.com";
String apiKey = "_abc123";
String applicationName = "Find story by FormattedID"; //Use your API Key or your username/password.
//String workspaceRef = "/workspace/12352608219"; //Use your workspace and project ObjectIDs
String projectRef = "/project/12352608219";
RallyRestApi restApi = null;
restApi = new RallyRestApi(new URI(host),apiKey);
restApi.setApplicationName(applicationName);
System.out.println(restApi.getWsapiVersion());
/**********************************FIND STORY***********************************************************/
try{
QueryRequest storyRequest = new QueryRequest("HierarchicalRequirement");
storyRequest.setFetch(new Fetch("Name","Owner","UserName","PlanEstimate", "c_CustomText"));
storyRequest.setLimit(1000);
storyRequest.setScopedDown(false);
storyRequest.setScopedUp(false);
//storyRequest.setWorkspace(workspaceRef);
storyRequest.setProject(projectRef);
storyRequest.setQueryFilter(new QueryFilter("FormattedID", "=", "US3074"));
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") + " PlanEstimate: " + storyJsonObject.get("PlanEstimate"));
JsonObject userObject = storyJsonObject.get("Owner").getAsJsonObject().getAsJsonObject();
System.out.println(userObject.get("UserName"));
/*****************************************************UPDATE STORY PLAN ESTIMATE****************************************/
JsonObject storyUpdate = new JsonObject();
storyUpdate.addProperty("PlanEstimate", 0); //test setting PlanEstimate to 0
UpdateRequest updateStoryRequest = new UpdateRequest(storyRef,storyUpdate);
UpdateResponse updateResponse = restApi.update(updateStoryRequest);
if (updateResponse.wasSuccessful()) {
System.out.println("Successfully updated story: " + storyJsonObject.get("PlanEstimate") +
" to: " + storyUpdate.get("PlanEstimate"));
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();
}
}
}