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 pathCreatePI.java
More file actions
Latest commit
75 lines (58 loc) · 3.14 KB
/
Copy pathCreatePI.java
File metadata and controls
75 lines (58 loc) · 3.14 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
importjava.io.IOException;
importjava.io.RandomAccessFile;
importjava.net.URI;
importjava.net.URISyntaxException;
importorg.apache.commons.codec.binary.Base64;
importcom.google.gson.JsonArray;
importcom.google.gson.JsonElement;
importcom.google.gson.JsonObject;
importcom.rallydev.rest.RallyRestApi;
importcom.rallydev.rest.request.CreateRequest;
importcom.rallydev.rest.request.GetRequest;
importcom.rallydev.rest.request.QueryRequest;
importcom.rallydev.rest.response.CreateResponse;
importcom.rallydev.rest.response.QueryResponse;
importcom.rallydev.rest.util.QueryFilter;
importcom.rallydev.rest.util.Ref;
publicclassCreatePI{
publicstaticvoidmain(String[] args) throwsURISyntaxException, IOException {
Stringhost = "https://rally1.rallydev.com";
StringapiKey = "_abc123";
StringprojectRef = "/project/456";
StringapplicationName = "Nick:CreatePI";
RallyRestApirestApi = newRallyRestApi(newURI(host),apiKey);
restApi.setApplicationName(applicationName);
try {
System.out.println("Creating a PI/Initiative...");
JsonObjectnewInitiative = newJsonObject();
newInitiative.addProperty("Name", "Jupiter Lander Initiative");
newInitiative.addProperty("Project", projectRef);
CreateRequestcreateRequest = newCreateRequest("portfolioitem/initiative", newInitiative);
CreateResponsecreateResponse = restApi.create(createRequest);
if (createResponse.wasSuccessful()) {
System.out.println(String.format("Created %s %s", createResponse.getObject().get("FormattedID"), createResponse.getObject().get("_ref").getAsString()));
StringinitiativeRef = Ref.getRelativeRef(createResponse.getObject().get("_ref").getAsString());
System.out.println(String.format("\nReading Initiative %s...", initiativeRef));
System.out.println("Creating a PI/Feature...");
JsonObjectnewFeature = newJsonObject();
newFeature.addProperty("Name", "Jupiter Flyby Feature");
newFeature.addProperty("Project", projectRef);
newFeature.addProperty("Parent", initiativeRef);
CreateRequestcreateRequest2 = newCreateRequest("portfolioitem/feature", newFeature);
CreateResponsecreateResponse2 = restApi.create(createRequest2);
if (createResponse.wasSuccessful()) {
System.out.println(String.format("Created %s %s", createResponse2.getObject().get("FormattedID"), createResponse2.getObject().get("_ref").getAsString()));
}
} else {
String[] createErrors;
createErrors = createResponse.getErrors();
System.out.println("Error occurred creating a defect: ");
for (intk=0; k<createErrors.length;k++) {
System.out.println(createErrors[k]);
}
}
} finally {
restApi.close();
}
}
}