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