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 pathClearCustomUserTextField.java
More file actions
Latest commit
78 lines (64 loc) · 3.16 KB
/
Copy pathClearCustomUserTextField.java
File metadata and controls
78 lines (64 loc) · 3.16 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
//This code toggles Custom Text field value on a User from empty to current milliseconds, and from a non-empty value to empty
importjava.io.IOException;
importjava.net.URI;
importjava.net.URISyntaxException;
importcom.google.gson.JsonArray;
importcom.google.gson.JsonElement;
importcom.google.gson.JsonObject;
importcom.rallydev.rest.RallyRestApi;
importcom.rallydev.rest.util.Fetch;
importcom.rallydev.rest.request.QueryRequest;
importcom.rallydev.rest.request.UpdateRequest;
importcom.rallydev.rest.response.UpdateResponse;
importcom.rallydev.rest.response.QueryResponse;
importcom.rallydev.rest.util.QueryFilter;
importjava.util.Date;
publicclassClearCustomUserTextField{
publicstaticvoidmain(String[] args) throwsURISyntaxException, IOException {
Stringhost = "https://rally1.rallydev.com";
StringapiKey = "_abc123"; //use your ApiKey
StringapplicationName = "ClearCustomUserTextField";
RallyRestApirestApi = newRallyRestApi(newURI(host),apiKey);
restApi.setApplicationName(applicationName);
try {
QueryRequestuserRequest = newQueryRequest("User");
userRequest.setFetch(newFetch("UserName", "DisplayName", "c_Comments"));
userRequest.setQueryFilter(newQueryFilter("UserName", "=", "nick@denver.com"));
QueryResponseuserQueryResponse = restApi.query(userRequest);
JsonArrayuserQueryResults = userQueryResponse.getResults();
JsonElementuserQueryElement = userQueryResults.get(0);
JsonObjectuserObject = userQueryElement.getAsJsonObject();
StringuserRef = userObject.get("_ref").getAsString();
System.out.println(userObject.get("UserName") + " Comments field value: " + userObject.get("c_Comments"));
if(userObject.get("c_Comments").isJsonNull()){
StringnewComment = newDate().getTime()+""; //converting long to string
System.out.println("Comments field is empty. Updating to: " + newComment);
update(restApi, userRef, newComment);
}
else{
System.out.println("not empty");
System.out.println("Comments field is not empty. Clearing the value...");
update(restApi, userRef, "");
}
} finally {
//Release all resources
restApi.close();
}
}
privatestaticvoidupdate(RallyRestApirestApi, StringuserRef, Stringcomment ) throwsURISyntaxException,IOException {
JsonObjectuserUpdate = newJsonObject();
userUpdate.addProperty("c_Comments", comment);
UpdateRequestupdateRequest = newUpdateRequest(userRef,userUpdate);
UpdateResponseupdateResponse = restApi.update(updateRequest);
if (updateResponse.wasSuccessful()) {
System.out.println("Successfully updated user");
} else {
System.out.println("Error occurred attempting to update user");
String[] errorList;
errorList = updateResponse.getErrors();
for (inte=0;e<errorList.length;e++) {
System.out.println(errorList[e]);
}
}
}
}