1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace JiraRestApi\Project; |
4
|
|
|
|
5
|
|
|
use JiraRestApi\Issue\IssueType; |
6
|
|
|
use JiraRestApi\Issue\Reporter; |
7
|
|
|
use JiraRestApi\Issue\Version; |
8
|
|
|
use JiraRestApi\JiraException; |
9
|
|
|
|
10
|
|
|
class ProjectService extends \JiraRestApi\JiraClient |
11
|
|
|
{ |
12
|
|
|
private $uri = '/project'; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* get all project list. |
16
|
|
|
* |
17
|
|
|
* @param array $paramArray |
18
|
|
|
* |
19
|
|
|
* @throws \JiraRestApi\JiraException |
20
|
|
|
* |
21
|
|
|
* @return Project[] array of Project class |
22
|
|
|
*/ |
23
|
|
|
public function getAllProjects($paramArray = []) |
24
|
|
|
{ |
25
|
|
|
$ret = $this->exec($this->uri.$this->toHttpQueryParameter($paramArray), null); |
26
|
|
|
|
27
|
|
|
$prjs = $this->json_mapper->mapArray( |
28
|
|
|
json_decode($ret, false), new \ArrayObject(), '\JiraRestApi\Project\Project' |
29
|
|
|
); |
30
|
|
|
|
31
|
|
|
return $prjs; |
|
|
|
|
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* get Project id By Project Key. |
36
|
|
|
* throws HTTPException if the project is not found, or the calling user does not have permission or view it. |
37
|
|
|
* |
38
|
|
|
* @param string|int $projectIdOrKey projectName or Project Key(Ex: Test, MyProj) |
39
|
|
|
* |
40
|
|
|
* @throws \JiraRestApi\JiraException |
41
|
|
|
* @throws \JsonMapper_Exception |
42
|
|
|
* |
43
|
|
|
* @return Project|object |
44
|
|
|
*/ |
45
|
|
|
public function get($projectIdOrKey) |
46
|
|
|
{ |
47
|
|
|
$ret = $this->exec($this->uri."/$projectIdOrKey", null); |
48
|
|
|
|
49
|
|
|
$this->log->addInfo('Result='.$ret); |
50
|
|
|
|
51
|
|
|
$prj = $this->json_mapper->map( |
52
|
|
|
json_decode($ret), new Project() |
53
|
|
|
); |
54
|
|
|
|
55
|
|
|
return $prj; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* get assignable Users for a given project. |
60
|
|
|
* throws HTTPException if the project is not found, or the calling user does not have permission or view it. |
61
|
|
|
* |
62
|
|
|
* @param string|int projectIdOrKey Project Key |
|
|
|
|
63
|
|
|
* |
64
|
|
|
* @throws \JiraRestApi\JiraException |
65
|
|
|
* |
66
|
|
|
* @return Reporter[] |
67
|
|
|
*/ |
68
|
|
|
public function getAssignable($projectIdOrKey) |
69
|
|
|
{ |
70
|
|
|
$ret = $this->exec("/user/assignable/search?project=$projectIdOrKey", null); |
71
|
|
|
$json = json_decode($ret); |
72
|
|
|
$results = array_map(function ($elem) { |
73
|
|
|
return $this->json_mapper->map($elem, new Reporter()); |
74
|
|
|
}, $json); |
75
|
|
|
|
76
|
|
|
return $results; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param string|int $projectIdOrKey |
81
|
|
|
* |
82
|
|
|
* @throws \JiraRestApi\JiraException |
83
|
|
|
* |
84
|
|
|
* @return IssueType[] |
85
|
|
|
*/ |
86
|
|
|
public function getStatuses($projectIdOrKey) |
87
|
|
|
{ |
88
|
|
|
$ret = $this->exec($this->uri."/$projectIdOrKey/statuses", null); |
89
|
|
|
$json = json_decode($ret); |
90
|
|
|
$results = array_map(function ($elem) { |
91
|
|
|
return $this->json_mapper->map($elem, new IssueType()); |
92
|
|
|
}, $json); |
93
|
|
|
|
94
|
|
|
return $results; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @throws \JiraRestApi\JiraException |
99
|
|
|
* |
100
|
|
|
* @return ProjectType[] |
101
|
|
|
*/ |
102
|
|
|
public function getProjectTypes() |
103
|
|
|
{ |
104
|
|
|
$ret = $this->exec($this->uri.'/type'); |
105
|
|
|
|
106
|
|
|
$this->log->addInfo('Result='.$ret); |
107
|
|
|
|
108
|
|
|
$json = json_decode($ret); |
109
|
|
|
$results = array_map(function ($elem) { |
110
|
|
|
return $this->json_mapper->map($elem, new ProjectType()); |
111
|
|
|
}, $json); |
112
|
|
|
|
113
|
|
|
return $results; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @param string|int $key |
118
|
|
|
* |
119
|
|
|
* @throws \JiraRestApi\JiraException |
120
|
|
|
* @throws \JsonMapper_Exception |
121
|
|
|
* |
122
|
|
|
* @return ProjectType|object |
123
|
|
|
*/ |
124
|
|
|
public function getProjectType($key) |
125
|
|
|
{ |
126
|
|
|
$ret = $this->exec($this->uri."/type/$key"); |
127
|
|
|
|
128
|
|
|
$this->log->addInfo('Result='.$ret); |
129
|
|
|
|
130
|
|
|
$type = $this->json_mapper->map( |
131
|
|
|
json_decode($ret, false), new ProjectType() |
132
|
|
|
); |
133
|
|
|
|
134
|
|
|
return $type; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @param string|int $key |
139
|
|
|
* |
140
|
|
|
* @throws \JiraRestApi\JiraException |
141
|
|
|
* @throws \JsonMapper_Exception |
142
|
|
|
* |
143
|
|
|
* @return ProjectType|object |
144
|
|
|
*/ |
145
|
|
|
public function getAccessibleProjectType($key) |
146
|
|
|
{ |
147
|
|
|
$ret = $this->exec($this->uri."/type/$key/accessible"); |
148
|
|
|
|
149
|
|
|
$this->log->addInfo('Result='.$ret); |
150
|
|
|
|
151
|
|
|
$type = $this->json_mapper->map( |
152
|
|
|
json_decode($ret, false), new ProjectType() |
153
|
|
|
); |
154
|
|
|
|
155
|
|
|
return $type; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* get pagenated Project versions. |
160
|
|
|
* |
161
|
|
|
* @param string|int $projectIdOrKey |
162
|
|
|
* @param array $queryParam |
163
|
|
|
* |
164
|
|
|
* @throws \JiraRestApi\JiraException |
165
|
|
|
* |
166
|
|
|
* @return Version[] array of version |
167
|
|
|
*/ |
168
|
|
|
public function getVersionsPagenated($projectIdOrKey, $queryParam = []) |
169
|
|
|
{ |
170
|
|
|
$default = [ |
171
|
|
|
'startAt' => 0, |
172
|
|
|
'maxResults' => 50, |
173
|
|
|
// order by following field: sequence, name, startDate, releaseDate |
174
|
|
|
//'orderBy' => null, |
175
|
|
|
//'expand' => null, |
176
|
|
|
]; |
177
|
|
|
|
178
|
|
|
$param = $this->toHttpQueryParameter( |
179
|
|
|
array_merge($default, $queryParam) |
180
|
|
|
); |
181
|
|
|
|
182
|
|
|
$ret = $this->exec($this->uri."/$projectIdOrKey/version".$param); |
183
|
|
|
|
184
|
|
|
$this->log->addInfo('Result='.$ret); |
185
|
|
|
|
186
|
|
|
//@see https://docs.atlassian.com/jira/REST/server/#api/2/project-getProjectVersions |
187
|
|
|
$json = json_decode($ret); |
188
|
|
|
|
189
|
|
|
$versions = $this->json_mapper->mapArray( |
190
|
|
|
$json->values, new \ArrayObject(), '\JiraRestApi\Issue\Version' |
191
|
|
|
); |
192
|
|
|
|
193
|
|
|
return $versions; |
|
|
|
|
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* get specified's project versions. |
198
|
|
|
* |
199
|
|
|
* @param string|int $projectIdOrKey |
200
|
|
|
* |
201
|
|
|
* @throws \JiraRestApi\JiraException |
202
|
|
|
* |
203
|
|
|
* @return Version[] array of version |
204
|
|
|
*/ |
205
|
|
|
public function getVersions($projectIdOrKey) |
206
|
|
|
{ |
207
|
|
|
$ret = $this->exec($this->uri."/$projectIdOrKey/versions"); |
208
|
|
|
|
209
|
|
|
$this->log->addInfo('Result='.$ret); |
210
|
|
|
|
211
|
|
|
$versions = $this->json_mapper->mapArray( |
212
|
|
|
json_decode($ret, false), new \ArrayObject(), '\JiraRestApi\Issue\Version' |
213
|
|
|
); |
214
|
|
|
|
215
|
|
|
return $versions; |
|
|
|
|
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* get specified's project version. |
220
|
|
|
* |
221
|
|
|
* @param string|int $projectIdOrKey |
222
|
|
|
* @param string $versionName |
223
|
|
|
* |
224
|
|
|
* @throws \JiraRestApi\JiraException |
225
|
|
|
* |
226
|
|
|
* @return Version version |
227
|
|
|
*/ |
228
|
|
|
public function getVersion($projectIdOrKey, $versionName) |
229
|
|
|
{ |
230
|
|
|
$ret = $this->exec($this->uri."/$projectIdOrKey/versions"); |
231
|
|
|
|
232
|
|
|
$this->log->addInfo('Result='.$ret); |
233
|
|
|
|
234
|
|
|
$versions = $this->json_mapper->mapArray( |
235
|
|
|
json_decode($ret, false), new \ArrayObject(), '\JiraRestApi\Issue\Version' |
236
|
|
|
); |
237
|
|
|
|
238
|
|
|
foreach ($versions as $v) { |
239
|
|
|
if ($v->name === $versionName) { |
240
|
|
|
return $v; |
241
|
|
|
} |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
throw new JiraException("Can't found version \"$versionName\" in the Project \"$projectIdOrKey\""); |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
/** |
248
|
|
|
* Creates a new project. |
249
|
|
|
* |
250
|
|
|
* @param Project $project |
251
|
|
|
* |
252
|
|
|
* @throws JiraException |
253
|
|
|
* |
254
|
|
|
* @return Project project |
255
|
|
|
*/ |
256
|
|
|
public function createProject($project) |
257
|
|
|
{ |
258
|
|
|
$data = json_encode($project); |
259
|
|
|
|
260
|
|
|
$ret = $this->exec($this->uri, $data, 'POST'); |
261
|
|
|
|
262
|
|
|
$this->log->addInfo('createProject Result='.$ret); |
263
|
|
|
|
264
|
|
|
return $this->json_mapper->map( |
265
|
|
|
json_decode($ret), new Project() |
266
|
|
|
); |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
/** |
270
|
|
|
* Updates a project. |
271
|
|
|
* |
272
|
|
|
* Only non null values sent in JSON will be updated in the project. |
273
|
|
|
* Values available for the assigneeType field are: "PROJECT_LEAD" and "UNASSIGNED". |
274
|
|
|
* |
275
|
|
|
* @param Project $project |
276
|
|
|
* @package string $projectIdOrKey |
277
|
|
|
* @return Project project |
278
|
|
|
* @throws JiraException |
279
|
|
|
* @throws \JsonMapper_Exception |
280
|
|
|
*/ |
281
|
|
|
public function updateProject($project, $projectIdOrKey) |
282
|
|
|
{ |
283
|
|
|
$data = json_encode($project); |
284
|
|
|
|
285
|
|
|
$ret = $this->exec($this->uri.'/'.$projectIdOrKey, $data, 'PUT'); |
286
|
|
|
|
287
|
|
|
$this->log->addInfo('updateProject Result='.$ret); |
288
|
|
|
|
289
|
|
|
return $this->json_mapper->map( |
290
|
|
|
json_decode($ret), new Project() |
291
|
|
|
); |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
/** |
295
|
|
|
* |
296
|
|
|
* @param string $projectIdOrKey |
297
|
|
|
* @return int response status |
298
|
|
|
* |
299
|
|
|
* STATUS 401 Returned if the user is not logged in. |
300
|
|
|
* STATUS 204 - application/json Returned if the project is successfully deleted. |
301
|
|
|
* STATUS 403 - Returned if the currently authenticated user does not have permission to delete the project. |
302
|
|
|
* STATUS 404 - Returned if the project does not exist. |
303
|
|
|
* |
304
|
|
|
* @throws JiraException |
305
|
|
|
*/ |
306
|
|
|
public function deleteProject($projectIdOrKey) |
307
|
|
|
{ |
308
|
|
|
$ret = $this->exec($this->uri.'/'.$projectIdOrKey, null, 'DELETE'); |
309
|
|
|
|
310
|
|
|
return $ret; |
|
|
|
|
311
|
|
|
} |
312
|
|
|
} |
313
|
|
|
|