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 pathCreateUserSetProjectPermissions.java
More file actions
Latest commit
73 lines (66 loc) · 3.64 KB
/
Copy pathCreateUserSetProjectPermissions.java
File metadata and controls
73 lines (66 loc) · 3.64 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
importjava.io.IOException;
importjava.net.URI;
importjava.net.URISyntaxException;
importcom.google.gson.JsonObject;
importcom.rallydev.rest.RallyRestApi;
importcom.rallydev.rest.request.QueryRequest;
importcom.rallydev.rest.response.QueryResponse;
importcom.rallydev.rest.request.CreateRequest;
importcom.rallydev.rest.response.CreateResponse;
importcom.rallydev.rest.util.Ref;
importcom.rallydev.rest.util.Fetch;
publicclassCreateUserSetProjectPermissions {
publicstaticvoidmain(String[] args) throwsURISyntaxException, IOException, InterruptedException {
Stringhost = "https://rally1.rallydev.com";
StringapiKey = "_abc123"; //subadmin
StringapplicationName = "Nick:create user and projectpermissions";
RallyRestApirestApi = newRallyRestApi(newURI(host), apiKey);
restApi.setApplicationName(applicationName);
StringworkspaceRef = "/workspace/12345";
try {
JsonObjectnewUser = newJsonObject();
newUser.addProperty("UserName", "user777@co.com");
newUser.addProperty("EmailAddress", "user@co.com");
CreateRequestcreateUserRequest = newCreateRequest("user", newUser);
CreateResponsecreateUserResponse = restApi.create(createUserRequest);
if (createUserResponse.wasSuccessful()) {
//read user
StringuserRef = Ref.getRelativeRef(createUserResponse.getObject().get("_ref").getAsString());
System.out.println(String.format("Created %s", createUserResponse.getObject().get("_refObjectName").getAsString()));
//get all projects in the workspace
QueryRequestprojectRequest = newQueryRequest("Project");
projectRequest.setFetch(newFetch("ObjectID", "Name"));
projectRequest.setLimit(10000);
projectRequest.setWorkspace(workspaceRef);
QueryResponseprojectResponse = restApi.query(projectRequest);
intresultCount = projectResponse.getTotalResultCount();
System.out.println(resultCount);
if(resultCount >0){
for (inti=0;i<resultCount;i++){
JsonObjectprojectObject = projectResponse.getResults().get(i).getAsJsonObject();
StringprojectRef = projectObject.get("_ref").getAsString();
System.out.println(projectObject.get("ObjectID") + " " + projectObject.get("Name"));
//create projectpermission object
JsonObjectnewPP = newJsonObject();
newPP.addProperty("User", userRef);
newPP.addProperty("Project", projectRef);
newPP.addProperty("Role","Editor");
CreateRequestcreateProjectPermissionRequest = newCreateRequest("projectpermission", newPP);
CreateResponsecreateProjectPermissionResponse = restApi.create(createProjectPermissionRequest);
if (createUserResponse.wasSuccessful()) {
StringprojectPermissionRef = Ref.getRelativeRef(createProjectPermissionResponse.getObject().get("_ref").getAsString());
System.out.println(String.format("Created %s", createProjectPermissionResponse.getObject().get("_ref").getAsString()));
}
}
}
else{
System.out.println("No results");
}
}
} catch (Exceptione) {
System.out.println(e);
} finally {
restApi.close();
}
}
}