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  
28  /**
29   * Single JIRA issue
30   *
31   * @since v0.1
32   */
33  public class Issue extends BasicIssue implements ExpandableResource {
34  
35      public Issue(String summary, URI self, String key, BasicProject project, BasicIssueType issueType, BasicStatus status,
36  			String description, @Nullable BasicPriority priority, @Nullable BasicResolution resolution, Collection<Attachment> attachments,
37  			@Nullable BasicUser reporter, @Nullable BasicUser assignee, DateTime creationDate, DateTime updateDate,
38  			Collection<Version> affectedVersions, Collection<Version> fixVersions, Collection<BasicComponent> components,
39  			@Nullable TimeTracking timeTracking, Collection<Field> fields, Collection<Comment> comments,
40  			@Nullable URI transitionsUri,
41  			@Nullable Collection<IssueLink> issueLinks,
42  			BasicVotes votes, Collection<Worklog> worklogs, BasicWatchers watchers, Iterable<String> expandos,
43  			@Nullable Collection<Subtask> subtasks) {
44  		super(self, key);
45          this.summary = summary;
46  		this.project = project;
47  		this.status = status;
48  		this.description = description;
49  		this.resolution = resolution;
50  		this.expandos = expandos;
51          this.comments = comments;
52          this.attachments = attachments;
53  		this.fields = fields;
54  		this.issueType = issueType;
55  		this.reporter = reporter;
56  		this.assignee = assignee;
57  		this.creationDate = creationDate;
58  		this.updateDate = updateDate;
59  		this.transitionsUri = transitionsUri;
60  		this.issueLinks = issueLinks;
61  		this.votes = votes;
62  		this.worklogs = worklogs;
63  		this.watchers = watchers;
64  		this.fixVersions = fixVersions;
65  		this.affectedVersions = affectedVersions;
66  		this.components = components;
67  		this.priority = priority;
68  		this.timeTracking = timeTracking;
69  		this.subtasks = subtasks;
70  	}
71  
72  	private final BasicStatus status;
73  	private BasicIssueType issueType;
74  	private BasicProject project;
75  	private final URI transitionsUri;
76  	private final Iterable<String> expandos;
77  	private final Collection<BasicComponent> components;
78      private final String summary;
79  	@Nullable
80  	private final String description;
81  	@Nullable
82  	private BasicUser reporter;
83  	private BasicUser assignee;
84  	@Nullable
85  	private final BasicResolution resolution;
86  	private Collection<Field> fields;
87  	private DateTime creationDate;
88  	private DateTime updateDate;
89  	private final BasicPriority priority;
90  	private final BasicVotes votes;
91  	@Nullable
92  	private final Collection<Version> fixVersions;
93  	@Nullable
94  	private final Collection<Version> affectedVersions;
95  
96  	private final Collection<Comment> comments;
97  
98  	@Nullable
99  	private final Collection<IssueLink> issueLinks;
100 
101 	private final Collection<Attachment> attachments;
102 
103 	private final Collection<Worklog> worklogs;
104 	private final BasicWatchers watchers;
105 
106 	@Nullable
107 	private final TimeTracking timeTracking;
108 	@Nullable
109 	private final Collection<Subtask> subtasks;
110 
111 	public BasicStatus getStatus() {
112 		return status;
113 	}
114 
115 	/**
116 	 * @return reporter of this issue or <code>null</code> if this issue has no reporter
117 	 */
118 	@Nullable
119 	public BasicUser getReporter() {
120 		return reporter;
121 	}
122 
123 	/**
124 	 * @return assignee of this issue or <code>null</code> if this issue is unassigned.
125 	 */
126 	@Nullable
127 	public BasicUser getAssignee() {
128 		return assignee;
129 	}
130 
131 
132 
133 	public String getSummary() {
134 		return summary;
135 	}
136 
137 	/**
138 	 * @return priority of this issue
139 	 */
140 	@Nullable
141 	public BasicPriority getPriority() {
142 		return priority;
143 	}
144 
145 	/**
146 	 *
147 	 * @return issue links for this issue (possibly nothing) or <code>null</code> when issue links are deactivated for this JIRA instance
148 	 */
149 	@Nullable
150 	public Iterable<IssueLink> getIssueLinks() {
151 		return issueLinks;
152 	}
153 
154 	@Nullable
155 	public Iterable<Subtask> getSubtasks() {
156 		return subtasks;
157 	}
158 
159 	/**
160 	 * @return fields inaccessible by concrete getter methods (e.g. all custom fields)
161 	 */
162 	public Iterable<Field> getFields() {
163 		return fields;
164 	}
165 
166 	/**
167 	 *
168 	 * @param id identifier of the field (inaccessible by concrete getter method)
169 	 * @return field with given id, or <code>null</code> when no field with given id exists for this issue
170 	 */
171 	@Nullable
172 	public Field getField(String id) {
173 		for (Field field : fields) {
174 			if (field.getId().equals(id)) {
175 				return field;
176 			}
177 		}
178 		return null;
179 	}
180 
181 	/**
182 	 * This method returns the first field with specified name.
183 	 * 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.
184 	 * It's added just for convenience. For identify fields you should use id rather than name.
185 	 *
186 	 * @param name name of the field.
187 	 * @return the first field matching selected name or <code>null</code> when no field with given name exists for this issue
188 	 */
189 	@Nullable
190 	public Field getFieldByName(String name) {
191 		for (Field field : fields) {
192 			if (field.getName().equals(name)) {
193 				return field;
194 			}
195 		}
196 		return null;
197 	}
198 
199 	@Override
200 	public Iterable<String> getExpandos() {
201 		return expandos;
202 	}
203 
204 	/**
205 	 * @return issue type
206 	 */
207 	public BasicIssueType getIssueType() {
208 		return issueType;
209 	}
210 
211 	/**
212 	 * @return attachments of this issue
213 	 */
214 	public Iterable<Attachment> getAttachments() {
215         return attachments;
216     }
217 
218 	public URI getAttachmentsUri() {
219 		return UriBuilder.fromUri(getSelf()).path("attachments").build();
220 	}
221 
222 	/**
223 	 * @return comments for this issue
224 	 */
225     public Iterable<Comment> getComments() {
226         return comments;
227     }
228 
229 	/**
230 	 * @return project this issue belongs to
231 	 */
232 	public BasicProject getProject() {
233 		return project;
234 	}
235 
236 	/**
237 	 * @return <code>null</code when voting is disabled in JIRA
238 	 */
239 	@Nullable
240 	public BasicVotes getVotes() {
241 		return votes;
242 	}
243 
244 	public Iterable<Worklog> getWorklogs() {
245 		return worklogs;
246 	}
247 
248 	/**
249 	 * @return <code>null</code when watching is disabled in JIRA 
250 	 */
251 	@Nullable
252 	public BasicWatchers getWatchers() {
253 		return watchers;
254 	}
255 
256 	@Nullable
257 	public Iterable<Version> getFixVersions() {
258 		return fixVersions;
259 	}
260 
261 	@Nullable
262     public URI getTransitionsUri() {
263         return transitionsUri;
264     }
265 
266 	@Nullable
267     public Iterable<Version> getAffectedVersions() {
268 		return affectedVersions;
269 	}
270 
271 	public Iterable<BasicComponent> getComponents() {
272 		return components;
273 	}
274 
275 	public URI getVotesUri() {
276 		return UriBuilder.fromUri(getSelf()).path("votes").build();
277 	}
278 
279 
280 
281 	@Nullable
282 	public BasicResolution getResolution() {
283 		return resolution;
284 	}
285 
286 	public DateTime getCreationDate() {
287 		return creationDate;
288 	}
289 
290 	public DateTime getUpdateDate() {
291 		return updateDate;
292 	}
293 
294 	@Nullable
295 	public TimeTracking getTimeTracking() {
296 		return timeTracking;
297 	}
298 
299 	@Nullable
300 	public String getDescription() {
301 		return description;
302 	}
303 
304 	@Override
305 	public String toString() {
306 		return Objects.toStringHelper(this).addValue(super.toString()).
307 				add("project", project).
308 				add("status", status).
309 				add("description", description).
310 				add("expandos", expandos).
311 				add("resolution", resolution).
312 				add("reporter", reporter).
313 				add("assignee", assignee).addValue("\n").
314 				add("fields", fields).addValue("\n").
315 				add("affectedVersions", affectedVersions).addValue("\n").
316 				add("fixVersions", fixVersions).addValue("\n").
317 				add("components", components).addValue("\n").
318 				add("issueType", issueType).
319 				add("creationDate", creationDate).
320 				add("updateDate", updateDate).addValue("\n").
321 				add("attachments", attachments).addValue("\n").
322 				add("comments", comments).addValue("\n").
323 				add("transitionsUri", transitionsUri).
324 				add("issueLinks", issueLinks).addValue("\n").
325 				add("votes", votes).addValue("\n").
326 				add("worklogs", worklogs).addValue("\n").
327 				add("watchers", watchers).
328 				add("timeTracking", timeTracking).
329 				toString();
330 	}
331 }