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 pathRemoveValuesInCustomFields.java
More file actions
Latest commit
90 lines (83 loc) · 4.56 KB
/
Copy pathRemoveValuesInCustomFields.java
File metadata and controls
90 lines (83 loc) · 4.56 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
87
88
89
90
importcom.google.gson.JsonObject;
importcom.rallydev.rest.RallyRestApi;
importcom.rallydev.rest.request.QueryRequest;
importcom.rallydev.rest.response.QueryResponse;
importcom.rallydev.rest.util.Fetch;
importcom.rallydev.rest.util.QueryFilter;
importcom.rallydev.rest.request.UpdateRequest;
importcom.rallydev.rest.response.UpdateResponse;
importjava.io.IOException;
importjava.net.URI;
importjava.net.URISyntaxException;
importjava.text.SimpleDateFormat;
importjava.util.Calendar;
importjava.util.Date;
importjava.util.GregorianCalendar;
publicclassRemoveValuesInCustomFields {
publicstaticvoidmain(String[] args) throwsURISyntaxException, IOException {
Stringhost = "https://rally1.rallydev.com";
StringapiKey = "_abc123";
StringapplicationName = "Remove values of custom fields"; //Use your API Key or your username/password.
//String workspaceRef = "/workspace/12352608219"; //Use your workspace and project ObjectIDs
StringprojectRef = "/project/12352608219";
RallyRestApirestApi = null;
restApi = newRallyRestApi(newURI(host),apiKey);
restApi.setApplicationName(applicationName);
//limit query by LastUpdateDate:
/*
int x = -30;
Calendar cal = GregorianCalendar.getInstance();
cal.add( Calendar.DAY_OF_YEAR, x);
Date nDaysAgoDate = cal.getTime();
SimpleDateFormat iso = new SimpleDateFormat("yyyy-MM-dd'T'HH:mmZ");
*/
/**********************************FIND STORY***********************************************************/
try{
QueryRequeststoryRequest = newQueryRequest("HierarchicalRequirement");
storyRequest.setFetch(newFetch("Name","FormattedID","AdditionalNotes","Approved"));
//storyRequest.setWorkspace(workspaceRef);
storyRequest.setLimit(1000);
storyRequest.setProject(projectRef);
storyRequest.setScopedDown(false);
storyRequest.setScopedUp(false);
//storyRequest.setQueryFilter((new QueryFilter("AdditionalNotes", "!=", "")).or(new QueryFilter("Approved", "=", "true"))); // Will not work: Text field cannot be queried by null or empty string
//storyRequest.setQueryFilter(new QueryFilter("LastUpdateDate", ">", iso.format(nDaysAgoDate)));
storyRequest.setQueryFilter((newQueryFilter("FormattedID", "=", "US2926")).or(newQueryFilter("FormattedID", "=", "US2935")));
QueryResponsestoryQueryResponse = restApi.query(storyRequest);
for (inti=0; i<storyQueryResponse.getResults().size();i++){
JsonObjectstoryJsonObject = storyQueryResponse.getResults().get(i).getAsJsonObject();
StringstoryRef = storyJsonObject.get("_ref").getAsString();
/*****************************************************UPDATE STORIES****************************************/
JsonObjectstoryUpdate = newJsonObject();
storyUpdate.addProperty("c_AdditionalNotes", ""); //removing values in AdditionalNotes
storyUpdate.addProperty("c_Approved", false); //set Approved to false
UpdateRequestupdateStoryRequest = newUpdateRequest(storyRef,storyUpdate);
UpdateResponseupdateResponse = restApi.update(updateStoryRequest);
if (updateResponse.wasSuccessful()) {
System.out.println("Successfully updated c_AdditionalNotes: " + storyJsonObject.get("c_AdditionalNotes") + " to " + storyUpdate.get("c_AdditionalNotes")
+ "\nSuccessfully updated c_Approved:" + storyJsonObject.get("c_Approved") +
" to: " + storyUpdate.get("c_Approved"));
String[] warningList;
warningList = updateResponse.getWarnings();
for (intx=0;x<warningList.length;x++) {
System.out.println(warningList[x]);
}
} else {
System.out.println("Error occurred attempting to update story: " + storyJsonObject.get("Name"));
String[] errorList;
errorList = updateResponse.getErrors();
for (inty=0;y<errorList.length;y++) {
System.out.println(errorList[y]);
}
}
}
}catch(Exceptione){
System.out.println("Exception occurred....");
e.printStackTrace();
}
finally{
//Release all resources
restApi.close();
}
}
}