View Javadoc

1   /*
2    * Copyright (C) 2010 Atlassian
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package com.atlassian.jira.rest.client.domain;
18  
19  import com.atlassian.jira.rest.client.ExpandableResource;
20  import com.google.common.base.Objects;
21  import org.joda.time.DateTime;
22  
23  import javax.annotation.Nullable;
24  import javax.ws.rs.core.UriBuilder;
25  import java.net.URI;
26  import java.util.Collection;
27  import java.util.Set;
28  
29  /**
30   * Single JIRA issue
31   *
32   * @since v0.1
33   */
34  public class Issue extends BasicIssue implements ExpandableResource {
35  
36      public Issue(String summary, URI self, String key, BasicProject project, BasicIssueType issueType, BasicStatus status,
37  			String description, @Nullable BasicPriority priority, @Nullable BasicResolution resolution, Collection<Attachment> attachments,
38  			@Nullable BasicUser reporter, @Nullable BasicUser assignee, DateTime creationDate, DateTime updateDate,
39  			Collection<Version> affectedVersions, Collection<Version> fixVersions, Collection<BasicComponent> components,
40  			@Nullable TimeTracking timeTracking, Collection<Field> fields, Collection<Comment> comments,
41  			@Nullable URI transitionsUri,
42  			@Nullable Collection<IssueLink> issueLinks,
43  			BasicVotes votes, Collection<Worklog> worklogs, BasicWatchers watchers, Iterable<String> expandos,
44  			@Nullable Collection<Subtask> subtasks, @Nullable Collection<ChangelogGroup> changelog, Set<String> labels) {
45  		super(self, key);
46          this.summary = summary;
47  		this.project = project;
48  		this.status = status;
49  		this.description = description;
50  		this.resolution = resolution;
51  		this.expandos = expandos;
52          this.comments = comments;
53          this.attachments = attachments;
54  		this.fields = fields;
55  		this.issueType = issueType;
56  		this.reporter = reporter;
57  		this.assignee = assignee;
58  		this.creationDate = creationDate;
59  		this.updateDate = updateDate;
60  		this.transitionsUri = transitionsUri;
61  		this.issueLinks = issueLinks;
62  		this.votes = votes;
63  		this.worklogs = worklogs;
64  		this.watchers = watchers;
65  		this.fixVersions = fixVersions;
66  		this.affectedVersions = affectedVersions;
67  		this.components = components;
68  		this.priority = priority;
69  		this.timeTracking = timeTracking;
70  		this.subtasks = subtasks;
71  		this.changelog = changelog;
72  		this.labels = labels;
73  	}
74  
75  	private final BasicStatus status;
76  	private BasicIssueType issueType;
77  	private BasicProject project;
78  	private final URI transitionsUri;
79  	private final Iterable<String> expandos;
80  	private final Collection<BasicComponent> components;
81      private final String summary;
82  	@Nullable
83  	private final String description;
84  	@Nullable
85  	private BasicUser reporter;
86  	private BasicUser assignee;
87  	@Nullable
88  	private final BasicResolution resolution;
89  	private Collection<Field> fields;
90  	private DateTime creationDate;
91  	private DateTime updateDate;
92  	private final BasicPriority priority;
93  	private final BasicVotes votes;
94  	@Nullable
95  	private final Collection<Version> fixVersions;
96  	@Nullable
97  	private final Collection<Version> affectedVersions;
98  
99  	private final Collection<Comment> comments;
100 
101 	@Nullable
102 	private final Collection<IssueLink> issueLinks;
103 
104 	private final Collection<Attachment> attachments;
105 
106 	private final Collection<Worklog> worklogs;
107 	private final BasicWatchers watchers;
108 
109 	@Nullable
110 	private final TimeTracking timeTracking;
111 	@Nullable
112 	private final Collection<Subtask> subtasks;
113 	@Nullable
114 	private final Collection<ChangelogGroup> changelog;
115 	private final Set<String> labels;
116 
117 	public BasicStatus getStatus() {
118 		return status;
119 	}
120 
121 	/**
122 	 * @return reporter of this issue or <code>null</code> if this issue has no reporter
123 	 */
124 	@Nullable
125 	public BasicUser getReporter() {
126 		return reporter;
127 	}
128 
129 	/**
130 	 * @return assignee of this issue or <code>null</code> if this issue is unassigned.
131 	 */
132 	@Nullable
133 	public BasicUser getAssignee() {
134 		return assignee;
135 	}
136 
137 
138 
139 	public String getSummary() {
140 		return summary;
141 	}
142 
143 	/**
144 	 * @return priority of this issue
145 	 */
146 	@Nullable
147 	public BasicPriority getPriority() {
148 		return priority;
149 	}
150 
151 	/**
152 	 *
153 	 * @return issue links for this issue (possibly nothing) or <code>null</code> when issue links are deactivated for this JIRA instance
154 	 */
155 	@Nullable
156 	public Iterable<IssueLink> getIssueLinks() {
157 		return issueLinks;
158 	}
159 
160 	@Nullable
161 	public Iterable<Subtask> getSubtasks() {
162 		return subtasks;
163 	}
164 
165 	/**
166 	 * @return fields inaccessible by concrete getter methods (e.g. all custom fields)
167 	 */
168 	public Iterable<Field> getFields() {
169 		return fields;
170 	}
171 
172 	/**
173 	 *
174 	 * @param id identifier of the field (inaccessible by concrete getter method)
175 	 * @return field with given id, or <code>null</code> when no field with given id exists for this issue
176 	 */
177 	@Nullable
178 	public Field getField(String id) {
179 		for (Field field : fields) {
180 			if (field.getId().equals(id)) {
181 				return field;
182 			}
183 		}
184 		return null;
185 	}
186 
187 	/**
188 	 * This method returns the first field with specified name.
189 	 * Names of fields in JIRA do not need to be unique. Therefore this method does not guarantee that you will get what you really want.
190 	 * It's added just for convenience. For identify fields you should use id rather than name.
191 	 *
192 	 * @param name name of the field.
193 	 * @return the first field matching selected name or <code>null</code> when no field with given name exists for this issue
194 	 */
195 	@Nullable
196 	public Field getFieldByName(String name) {
197 		for (Field field : fields) {
198 			if (field.getName().equals(name)) {
199 				return field;
200 			}
201 		}
202 		return null;
203 	}
204 
205 	@Override
206 	public Iterable<String> getExpandos() {
207 		return expandos;
208 	}
209 
210 	/**
211 	 * @return issue type
212 	 */
213 	public BasicIssueType getIssueType() {
214 		return issueType;
215 	}
216 
217 	/**
218 	 * @return attachments of this issue
219 	 */
220 	public Iterable<Attachment> getAttachments() {
221         return attachments;
222     }
223 
224 	public URI getAttachmentsUri() {
225 		return UriBuilder.fromUri(getSelf()).path("attachments").build();
226 	}
227 
228 	/**
229 	 * @return comments for this issue
230 	 */
231     public Iterable<Comment> getComments() {
232         return comments;
233     }
234 
235 	/**
236 	 * @return project this issue belongs to
237 	 */
238 	public BasicProject getProject() {
239 		return project;
240 	}
241 
242 	/**
243 	 * @return <code>null</code when voting is disabled in JIRA
244 	 */
245 	@Nullable
246 	public BasicVotes getVotes() {
247 		return votes;
248 	}
249 
250 	public Iterable<Worklog> getWorklogs() {
251 		return worklogs;
252 	}
253 
254 	/**
255 	 * @return <code>null</code when watching is disabled in JIRA 
256 	 */
257 	@Nullable
258 	public BasicWatchers getWatchers() {
259 		return watchers;
260 	}
261 
262 	@Nullable
263 	public Iterable<Version> getFixVersions() {
264 		return fixVersions;
265 	}
266 
267 	@Nullable
268     public URI getTransitionsUri() {
269         return transitionsUri;
270     }
271 
272 	@Nullable
273     public Iterable<Version> getAffectedVersions() {
274 		return affectedVersions;
275 	}
276 
277 	public Iterable<BasicComponent> getComponents() {
278 		return components;
279 	}
280 
281 	public Set<String> getLabels() {
282 		return labels;
283 	}
284 
285 	/**
286 	 * Returns changelog available for issues retrieved with CHANGELOG expanded.
287 	 *
288 	 * @return issue changelog or <code>null</code> if CHANGELOG has not been expanded or REST API on the server side does not serve
289 	 * this information (pre-5.0)
290 	 * @see com.atlassian.jira.rest.client.IssueRestClient#getIssue(String, Iterable, com.atlassian.jira.rest.client.ProgressMonitor)
291 	 * @since client 0.6, server 5.0
292 	 */
293 	@Nullable
294 	public Iterable<ChangelogGroup> getChangelog() {
295 		return changelog;
296 	}
297 
298 	public URI getVotesUri() {
299 		return UriBuilder.fromUri(getSelf()).path("votes").build();
300 	}
301 
302 
303 
304 	@Nullable
305 	public BasicResolution getResolution() {
306 		return resolution;
307 	}
308 
309 	public DateTime getCreationDate() {
310 		return creationDate;
311 	}
312 
313 	public DateTime getUpdateDate() {
314 		return updateDate;
315 	}
316 
317 	@Nullable
318 	public TimeTracking getTimeTracking() {
319 		return timeTracking;
320 	}
321 
322 	@Nullable
323 	public String getDescription() {
324 		return description;
325 	}
326 
327 	@Override
328 	public String toString() {
329 		return Objects.toStringHelper(this).addValue(super.toString()).
330 				add("project", project).
331 				add("status", status).
332 				add("description", description).
333 				add("expandos", expandos).
334 				add("resolution", resolution).
335 				add("reporter", reporter).
336 				add("assignee", assignee).addValue("\n").
337 				add("fields", fields).addValue("\n").
338 				add("affectedVersions", affectedVersions).addValue("\n").
339 				add("fixVersions", fixVersions).addValue("\n").
340 				add("components", components).addValue("\n").
341 				add("issueType", issueType).
342 				add("creationDate", creationDate).
343 				add("updateDate", updateDate).addValue("\n").
344 				add("attachments", attachments).addValue("\n").
345 				add("comments", comments).addValue("\n").
346 				add("transitionsUri", transitionsUri).
347 				add("issueLinks", issueLinks).addValue("\n").
348 				add("votes", votes).addValue("\n").
349 				add("worklogs", worklogs).addValue("\n").
350 				add("watchers", watchers).
351 				add("timeTracking", timeTracking).
352 				add("changelog", changelog).
353 				add("labels", labels).
354 				toString();
355 	}
356 }