Uh oh!
There was an error while loading. Please reload this page.
This repository was archived by the owner on Aug 31, 2026. It is now read-only.
forked from nmusaelian-rally/rally-java-rest-apps
- Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathCreateTimeboxes.java
More file actions
Latest commit
127 lines (112 loc) · 4.68 KB
/
Copy pathCreateTimeboxes.java
File metadata and controls
127 lines (112 loc) · 4.68 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
importjava.io.IOException;
importjava.net.URI;
importjava.net.URISyntaxException;
importjava.util.ArrayList;
importjava.util.List;
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.Ref;
importcom.rallydev.rest.request.CreateRequest;
importcom.rallydev.rest.response.CreateResponse;
importjava.text.SimpleDateFormat;
importjava.util.Calendar;
importjava.util.Date;
importjava.util.GregorianCalendar;
publicclassCreateTimeboxes {
publicstaticvoidmain(String[] args) throwsURISyntaxException, IOException, InterruptedException {
//start main thread
Stringhost = "https://rally1.rallydev.com";
StringapiKey = "_abc123";
StringapplicationName = "Nick:createTimeboxes";
RallyRestApirestApi = newRallyRestApi(newURI(host), apiKey);
restApi.setApplicationName(applicationName);
StringworkspaceRef = "/workspace/1234";
List<String> projects = newArrayList<String>();
QueryRequestprojectsRequest = newQueryRequest("Project");
projectsRequest.setWorkspace(workspaceRef);
//Workspace cannot be used in queries, this will not wor:
//projectsRequest.setQueryFilter(new QueryFilter("Workspace", "=", workspaceRef));
projectsRequest.setFetch(newFetch("ObjectID"));
QueryResponseprojectsResponse = restApi.query(projectsRequest);
intnumberOfProjects = projectsResponse.getTotalResultCount();
System.out.println(numberOfProjects);
if (numberOfProjects > 0) {
for (inti = 0; i < numberOfProjects; i++) {
JsonObjectprojectObject = projectsResponse.getResults().get(i).getAsJsonObject();
StringprojectRef = projectObject.get("ObjectID").getAsString();
projects.add(projectRef);
}
}
System.out.println("projects " + projects);
classMyRunnableimplementsRunnable {
privateStringoid;
publicMyRunnable(Stringoid) {
this.oid = oid;
}
publicvoidrun() {
try{
createReleases(this.oid);
}
catch (Exceptione){
e.printStackTrace();
}
}
}
Thread [] threads = newThread[numberOfProjects];
for (inti = 0; i < threads.length; i++)
{
threads[i] = newThread(newMyRunnable(projects.get(i)));
threads[i].start();
threads[i].join();
}
if (restApi != null) {
restApi.close();
}
}
privatestaticvoidcreateReleases(Stringoid) throwsException
{
try{
//start sub threads
Stringhost = "https://rally1.rallydev.com";
StringapiKey = "_abc123";
StringapplicationName = "Nick:createTimeboxes " + oid;
RallyRestApirestApi = newRallyRestApi(newURI(host), apiKey);
restApi.setApplicationName(applicationName);
StringprojectRef = "/project/" + oid;
JsonObjectrelease = newJsonObject();
release.addProperty("Name", "test-release-2");
release.addProperty("Project", projectRef);
release.addProperty("ReleaseStartDate", getReleaseStartDate());
release.addProperty("ReleaseDate", getReleaseDate());
release.addProperty("State","Planning");
CreateRequestcreateRequest = newCreateRequest("release", release);
CreateResponsecreateResponse = restApi.create(createRequest);
if (createResponse.wasSuccessful()) {
StringreleaseRef = Ref.getRelativeRef(createResponse.getObject().get("_ref").getAsString());
System.out.println("Release..." + releaseRef);
}
}
finally {
System.out.println("done with thread " + oid + "\n--------------------------------------------------------");
}
}
privatestaticStringgetReleaseStartDate()
{
Calendarcal = GregorianCalendar.getInstance();
Datenow = cal.getTime();
SimpleDateFormatiso = newSimpleDateFormat("yyyy-MM-dd'T'HH:mmZ");
returniso.format(now);
}
privatestaticStringgetReleaseDate()
{
intx = 14;
Calendarcal = GregorianCalendar.getInstance();
cal.add( Calendar.DAY_OF_YEAR, x);
DatefewDaysForward = cal.getTime();
SimpleDateFormatiso = newSimpleDateFormat("yyyy-MM-dd'T'HH:mmZ");
returniso.format(fewDaysForward);
}
}