PageRenderTime 50ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins/tasks/jira-connector/src/atlassian/java/com/atlassian/theplugin/jira/api/JIRAIssueBean.java

http://github.com/JetBrains/intellij-community
Java | 487 lines | 384 code | 87 blank | 16 comment | 37 complexity | bc4699dfd5274ead7f5ab4677bdc117d MD5 | raw file
Possible License(s): BSD-3-Clause, Apache-2.0, MPL-2.0-no-copyleft-exception, MIT, EPL-1.0, AGPL-1.0
  1. /**
  2. * Copyright (C) 2008 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. package com.atlassian.theplugin.jira.api;
  17. import org.jdom.Element;
  18. import java.text.DateFormat;
  19. import java.text.SimpleDateFormat;
  20. import java.util.*;
  21. public class JIRAIssueBean implements JIRAIssue {
  22. private String serverUrl;
  23. private Long id;
  24. private String key;
  25. private String summary;
  26. private String status;
  27. private String statusUrl;
  28. private String type;
  29. private String typeUrl;
  30. private String priority;
  31. private String priorityUrl;
  32. private String description;
  33. private String projectKey;
  34. private JIRAConstant statusConstant;
  35. private JIRAConstant typeConstant;
  36. private JIRAConstant priorityConstant;
  37. private String assignee;
  38. private String assigneeId;
  39. private String reporter;
  40. private String reporterId;
  41. private String resolution;
  42. private String created;
  43. private String updated;
  44. private long statusId;
  45. private long priorityId;
  46. private long typeId;
  47. private List<JIRAConstant> affectsVersions;
  48. private List<JIRAConstant> fixVersions;
  49. private List<JIRAConstant> components;
  50. private List<String> subTaskList;
  51. private boolean thisIsASubTask;
  52. private String parentIssueKey;
  53. private String originalEstimate;
  54. private String remainingEstimate;
  55. private String timeSpent;
  56. private List<JIRAComment> commentsList;
  57. public JIRAIssueBean() {
  58. }
  59. public JIRAIssueBean(String serverUrl) {
  60. this.serverUrl = serverUrl;
  61. }
  62. public JIRAIssueBean(JIRAIssue issue) {
  63. serverUrl = issue.getServerUrl();
  64. id = issue.getId();
  65. key = issue.getKey();
  66. summary = issue.getSummary();
  67. status = issue.getStatus();
  68. statusUrl = issue.getStatusTypeUrl();
  69. type = issue.getType();
  70. typeUrl = issue.getTypeIconUrl();
  71. priority = issue.getPriority();
  72. priorityUrl = issue.getPriorityIconUrl();
  73. description = issue.getDescription();
  74. projectKey = issue.getProjectKey();
  75. statusConstant = issue.getStatusConstant();
  76. typeConstant = issue.getTypeConstant();
  77. priorityConstant = issue.getPriorityConstant();
  78. assignee = issue.getAssignee();
  79. assigneeId = issue.getAssigneeId();
  80. reporter = issue.getReporter();
  81. reporterId = issue.getReporterId();
  82. resolution = issue.getResolution();
  83. created = issue.getCreated();
  84. updated = issue.getUpdated();
  85. statusId = issue.getStatusId();
  86. priorityId = issue.getPriorityId();
  87. typeId = issue.getTypeId();
  88. thisIsASubTask = issue.isSubTask();
  89. subTaskList = issue.getSubTaskKeys();
  90. parentIssueKey = issue.getParentIssueKey();
  91. }
  92. public JIRAIssueBean(String serverUrl, Element e, boolean getComments) {
  93. this.serverUrl = serverUrl;
  94. this.summary = getTextSafely(e, "summary");
  95. this.key = getTextSafely(e, "key");
  96. this.id = new Long(getAttributeSafely(e, "key", "id"));
  97. updateProjectKey();
  98. this.status = getTextSafely(e, "status");
  99. this.statusUrl = getAttributeSafely(e, "status", "iconUrl");
  100. try {
  101. this.statusId = Long.parseLong(getAttributeSafely(e, "status", "id"));
  102. } catch (NumberFormatException ex) {
  103. this.statusId = 0;
  104. }
  105. this.priority = getTextSafely(e, "priority");
  106. this.priorityUrl = getAttributeSafely(e, "priority", "iconUrl");
  107. try {
  108. this.priorityId = Long.parseLong(getAttributeSafely(e, "priority", "id"));
  109. } catch (NumberFormatException ex) {
  110. this.priorityId = 0;
  111. }
  112. this.description = getTextSafely(e, "description");
  113. this.type = getTextSafely(e, "type");
  114. this.typeUrl = getAttributeSafely(e, "type", "iconUrl");
  115. try {
  116. this.typeId = Long.parseLong(getAttributeSafely(e, "type", "id"));
  117. } catch (NumberFormatException ex) {
  118. this.typeId = 0;
  119. }
  120. this.assignee = getTextSafely(e, "assignee");
  121. this.assigneeId = getAttributeSafely(e, "assignee", "username");
  122. this.reporter = getTextSafely(e, "reporter");
  123. this.reporterId = getAttributeSafely(e, "reporter", "username");
  124. this.created = getTextSafely(e, "created");
  125. this.updated = getTextSafely(e, "updated");
  126. this.resolution = getTextSafely(e, "resolution");
  127. this.parentIssueKey = getTextSafely(e, "parent");
  128. this.thisIsASubTask = parentIssueKey != null;
  129. subTaskList = new ArrayList<String>();
  130. Element subtasks = e.getChild("subtasks");
  131. if (subtasks != null) {
  132. for (Object subtask : subtasks.getChildren("subtask")) {
  133. String subTaskKey = ((Element) subtask).getText();
  134. if (subTaskKey != null) {
  135. subTaskList.add(subTaskKey);
  136. }
  137. }
  138. }
  139. this.originalEstimate = getTextSafely(e, "timeoriginalestimate");
  140. this.remainingEstimate = getTextSafely(e, "timeestimate");
  141. this.timeSpent = getTextSafely(e, "timespent");
  142. Element comments = e.getChild("comments");
  143. if (comments != null && getComments) {
  144. commentsList = new ArrayList<JIRAComment>();
  145. for (Object comment : comments.getChildren("comment")) {
  146. Element el = (Element) comment;
  147. String commentId = el.getAttributeValue("id", "-1");
  148. String author = el.getAttributeValue("author", "Unknown");
  149. String text = el.getText();
  150. String creationDate = el.getAttributeValue("created", "Unknown");
  151. Calendar cal = Calendar.getInstance();
  152. DateFormat df = new SimpleDateFormat("EEE MMM d HH:mm:ss Z yyyy", Locale.US);
  153. try {
  154. cal.setTime(df.parse(creationDate));
  155. } catch (java.text.ParseException ex) {
  156. // oh well, invalid time - now what? :(
  157. }
  158. commentsList.add(new JIRACommentBean(commentId, author, text, cal));
  159. }
  160. }
  161. }
  162. public JIRAConstant getPriorityConstant() {
  163. return priorityConstant;
  164. }
  165. public void setPriority(JIRAConstant priority) {
  166. this.priority = priority.getName();
  167. this.priorityConstant = priority;
  168. }
  169. public JIRAIssueBean(String serverUrl, Map params) {
  170. this.serverUrl = serverUrl;
  171. this.summary = (String) params.get("summary");
  172. this.status = (String) params.get("status");
  173. this.key = (String) params.get("key");
  174. this.id = new Long(params.get("key").toString());
  175. updateProjectKey();
  176. this.description = (String) params.get("description");
  177. this.type = (String) params.get("type");
  178. this.priority = (String) params.get("priority");
  179. }
  180. private void updateProjectKey() {
  181. if (key != null) {
  182. if (key.indexOf("-") >= 0) {
  183. projectKey = key.substring(0, key.indexOf("-"));
  184. } else {
  185. projectKey = key;
  186. }
  187. }
  188. }
  189. private String getTextSafely(Element e, String name) {
  190. Element child = e.getChild(name);
  191. if (child == null) {
  192. return null;
  193. }
  194. return child.getText();
  195. }
  196. private String getAttributeSafely(Element e, String elementName, String attributeName) {
  197. Element child = e.getChild(elementName);
  198. if (child == null || child.getAttribute(attributeName) == null) {
  199. return null;
  200. }
  201. return child.getAttributeValue(attributeName);
  202. }
  203. public String getServerUrl() {
  204. return serverUrl;
  205. }
  206. public void setServerUrl(String serverUrl) {
  207. this.serverUrl = serverUrl;
  208. }
  209. public String getProjectUrl() {
  210. return serverUrl + "/browse/" + getProjectKey();
  211. }
  212. public String getIssueUrl() {
  213. return serverUrl + "/browse/" + getKey();
  214. }
  215. public Long getId() {
  216. return id;
  217. }
  218. public boolean isSubTask() {
  219. return thisIsASubTask;
  220. }
  221. public String getParentIssueKey() {
  222. return parentIssueKey;
  223. }
  224. public List<String> getSubTaskKeys() {
  225. return subTaskList;
  226. }
  227. public String getProjectKey() {
  228. return projectKey;
  229. }
  230. public String getStatus() {
  231. return status;
  232. }
  233. public String getStatusTypeUrl() {
  234. return statusUrl;
  235. }
  236. public String getPriority() {
  237. return priority;
  238. }
  239. public String getPriorityIconUrl() {
  240. return priorityUrl;
  241. }
  242. public String getKey() {
  243. return key;
  244. }
  245. public void setKey(String key) {
  246. this.key = key;
  247. }
  248. public String getSummary() {
  249. return summary;
  250. }
  251. public String getType() {
  252. return type;
  253. }
  254. public String getTypeIconUrl() {
  255. return typeUrl;
  256. }
  257. public void setTypeIconUrl(String newTypeUrl) {
  258. this.typeUrl = newTypeUrl;
  259. }
  260. public String getDescription() {
  261. return description;
  262. }
  263. public void setSummary(String summary) {
  264. this.summary = summary;
  265. }
  266. public void setProjectKey(String projectKey) {
  267. this.projectKey = projectKey;
  268. }
  269. public void setDescription(String description) {
  270. this.description = description;
  271. }
  272. public JIRAConstant getTypeConstant() {
  273. return typeConstant;
  274. }
  275. public void setType(JIRAConstant type) {
  276. this.type = type.getName();
  277. this.typeConstant = type;
  278. }
  279. public JIRAConstant getStatusConstant() {
  280. return statusConstant;
  281. }
  282. public void setStatus(JIRAConstant status) {
  283. this.status = status.getName();
  284. this.statusConstant = status;
  285. }
  286. public String getAssignee() {
  287. return assignee;
  288. }
  289. public void setAssignee(String assignee) {
  290. this.assignee = assignee;
  291. }
  292. public long getPriorityId() {
  293. return priorityId;
  294. }
  295. public long getStatusId() {
  296. return statusId;
  297. }
  298. public long getTypeId() {
  299. return typeId;
  300. }
  301. public String getReporter() {
  302. return reporter;
  303. }
  304. public void setReporter(String reporter) {
  305. this.reporter = reporter;
  306. }
  307. public String getResolution() {
  308. return resolution;
  309. }
  310. public void setResolution(String resolution) {
  311. this.resolution = resolution;
  312. }
  313. public String getCreated() {
  314. return created;
  315. }
  316. public void setCreated(String created) {
  317. this.created = created;
  318. }
  319. public String getUpdated() {
  320. return updated;
  321. }
  322. public void setUpdated(String updated) {
  323. this.updated = updated;
  324. }
  325. public boolean equals(Object o) {
  326. if (this == o) {
  327. return true;
  328. }
  329. if (o == null || getClass() != o.getClass()) {
  330. return false;
  331. }
  332. JIRAIssueBean that = (JIRAIssueBean) o;
  333. if (key != null ? !key.equals(that.key) : that.key != null) {
  334. return false;
  335. }
  336. if (serverUrl != null ? !serverUrl.equals(that.serverUrl) : that.serverUrl != null) {
  337. return false;
  338. }
  339. return !(summary != null ? !summary.equals(that.summary) : that.summary != null);
  340. }
  341. private static final int ONE_EFF = 31;
  342. public int hashCode() {
  343. int result;
  344. result = (serverUrl != null ? serverUrl.hashCode() : 0);
  345. result = ONE_EFF * result + (key != null ? key.hashCode() : 0);
  346. result = ONE_EFF * result + (summary != null ? summary.hashCode() : 0);
  347. return result;
  348. }
  349. public String getAssigneeId() {
  350. return assigneeId;
  351. }
  352. public void setAssigneeId(String assigneeId) {
  353. this.assigneeId = assigneeId;
  354. }
  355. public String getReporterId() {
  356. return reporterId;
  357. }
  358. public void setReporterId(String reporterId) {
  359. this.reporterId = reporterId;
  360. }
  361. public List<JIRAConstant> getAffectsVersions() {
  362. return affectsVersions;
  363. }
  364. public void setAffectsVersions(List<JIRAConstant> affectsVersions) {
  365. this.affectsVersions = affectsVersions;
  366. }
  367. public List<JIRAConstant> getFixVersions() {
  368. return fixVersions;
  369. }
  370. public void setFixVersions(List<JIRAConstant> fixVersions) {
  371. this.fixVersions = fixVersions;
  372. }
  373. public List<JIRAConstant> getComponents() {
  374. return components;
  375. }
  376. public void setComponents(List<JIRAConstant> components) {
  377. this.components = components;
  378. }
  379. public String getOriginalEstimate() {
  380. return originalEstimate;
  381. }
  382. public void setOriginalEstimate(String originalEstimate) {
  383. this.originalEstimate = originalEstimate;
  384. }
  385. public String getRemainingEstimate() {
  386. return remainingEstimate;
  387. }
  388. public void setRemainingEstimate(String remainingEstimate) {
  389. this.remainingEstimate = remainingEstimate;
  390. }
  391. public String getTimeSpent() {
  392. return timeSpent;
  393. }
  394. public void setTimeSpent(String timeSpent) {
  395. this.timeSpent = timeSpent;
  396. }
  397. public List<JIRAComment> getComments() {
  398. return commentsList;
  399. }
  400. }