KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > cowsultants > itracker > ejb > client > models > IssueModel


1 /*
2  * This software was designed and created by Jason Carroll.
3  * Copyright (c) 2002, 2003, 2004 Jason Carroll.
4  * The author can be reached at jcarroll@cowsultants.com
5  * ITracker website: http://www.cowsultants.com
6  * ITracker forums: http://www.cowsultants.com/phpBB/index.php
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it only under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  */

18
19 package cowsultants.itracker.ejb.client.models;
20
21 import java.util.Comparator JavaDoc;
22 import java.util.HashMap JavaDoc;
23
24 import cowsultants.itracker.ejb.client.util.IssueUtilities;
25
26 public class IssueModel extends GenericModel implements Comparator JavaDoc {
27     private String JavaDoc description;
28     private int severity;
29     private int status;
30     private String JavaDoc resolution;
31
32     private ProjectModel project;
33     private VersionModel targetVersion;
34
35     private UserModel creator;
36     private UserModel owner;
37
38     private IssueHistoryModel[] history;
39     private IssueAttachmentModel[] attachments;
40     private IssueFieldModel[] fields;
41     private NotificationModel[] notifications;
42     private ComponentModel[] components;
43     private VersionModel[] versions;
44
45     public IssueModel() {
46         description = "";
47         severity = -1;
48         status = -1;
49         resolution = "";
50         targetVersion = null;
51
52         creator = null;
53         owner = null;
54
55         project = null;
56         history = null;
57         attachments = null;
58         components = null;
59         versions = null;
60         notifications = null;
61     }
62
63     public String JavaDoc getDescription() {
64         return (description == null ? "" : description);
65     }
66
67     public void setDescription(String JavaDoc value) {
68         description = value;
69     }
70
71     public int getSeverity() {
72         return severity;
73     }
74
75     public void setSeverity(int value) {
76         severity = value;
77     }
78
79     public int getStatus() {
80         return status;
81     }
82
83     public void setStatus(int value) {
84         status = value;
85     }
86
87     public String JavaDoc getResolution() {
88         return (resolution == null ? "" : resolution);
89     }
90
91     public void setResolution(String JavaDoc value) {
92         resolution = value;
93     }
94
95     public ProjectModel getProject() {
96         return project;
97     }
98
99     public void setProject(ProjectModel value) {
100         project = value;
101     }
102
103     public Integer JavaDoc getProjectId() {
104         return (project == null ? new Integer JavaDoc(-1) : project.getId());
105     }
106
107     public String JavaDoc getProjectName() {
108         return (project == null ? "" : project.getName());
109     }
110
111     public VersionModel getTargetVersion() {
112         return targetVersion;
113     }
114
115     public void setTargetVersion(VersionModel value) {
116         targetVersion = value;
117     }
118
119     public String JavaDoc getTargetVersionNumber() {
120         return (targetVersion == null ? "" : targetVersion.getNumber());
121     }
122
123     public Integer JavaDoc getTargetVersionId() {
124         return (targetVersion == null ? new Integer JavaDoc(-1) : targetVersion.getId());
125     }
126
127     public UserModel getCreator() {
128         return creator;
129     }
130
131     public void setCreator(UserModel value) {
132         creator = value;
133     }
134
135     public Integer JavaDoc getCreatorId() {
136         return (creator == null ? new Integer JavaDoc(-1) : creator.getId());
137     }
138
139     public String JavaDoc getCreatorFirstName() {
140         return (creator == null ? "" : creator.getFirstName());
141     }
142
143     public String JavaDoc getCreatorLastName() {
144         return (creator == null ? "" : creator.getLastName());
145     }
146
147     public UserModel getOwner() {
148         return owner;
149     }
150
151     public void setOwner(UserModel value) {
152         owner = value;
153     }
154
155     public Integer JavaDoc getOwnerId() {
156         return (owner == null ? new Integer JavaDoc(-1) : owner.getId());
157     }
158
159     public String JavaDoc getOwnerLogin() {
160         return (owner == null ? "" : owner.getLogin());
161     }
162
163     public String JavaDoc getOwnerFirstName() {
164         return (owner == null ? "" : owner.getFirstName());
165     }
166
167     public String JavaDoc getOwnerLastName() {
168         return (owner == null ? "" : owner.getLastName());
169     }
170
171     public IssueHistoryModel[] getHistory() {
172         return (history == null ? new IssueHistoryModel[0] : history);
173     }
174
175     public void setHistory(IssueHistoryModel[] value) {
176         history = value;
177     }
178
179     public IssueAttachmentModel[] getAttachments() {
180         return (attachments == null ? new IssueAttachmentModel[0] : attachments);
181     }
182
183     public void setAttachments(IssueAttachmentModel[] value) {
184         attachments = value;
185     }
186
187     public IssueFieldModel[] getFields() {
188         return (fields == null ? new IssueFieldModel[0] : fields);
189     }
190
191     public void setFields(IssueFieldModel[] value) {
192         fields = value;
193     }
194
195     public NotificationModel[] getNotifications() {
196         return (notifications == null ? new NotificationModel[0] : notifications);
197     }
198
199     public void setNotifications(NotificationModel[] value) {
200         notifications = value;
201     }
202
203     public ComponentModel[] getComponents() {
204         return (components == null ? new ComponentModel[0] : components);
205     }
206
207     public void setComponents(ComponentModel[] value) {
208         components = value;
209     }
210
211     public VersionModel[] getVersions() {
212         return (versions == null ? new VersionModel[0] : versions);
213     }
214
215     public void setVersions(VersionModel[] value) {
216         versions = value;
217     }
218
219     public String JavaDoc toString() {
220         return "Issue [" + getId() + "] Description: " + getDescription() + " Project: " + getProjectId() +
221                " Severity: " + getSeverity() + " Status: " + getStatus() +
222                " Creator Id: " + getCreatorId() + " OwnerId: " + getOwnerId() +
223                " Num Affected Versions:" + getVersions().length +
224                " Num Affected Components: " + getComponents().length + " Num Attachments: " + getAttachments().length +
225                " Num History Entries: " + getHistory().length + " Created: " + getCreateDate() +
226                " Last Mod: " + getLastModifiedDate();
227     }
228
229     public int compare(Object JavaDoc a, Object JavaDoc b) {
230         return this.new CompareByStatus().compare(a, b);
231     }
232
233     public boolean equals(Object JavaDoc obj) {
234         return this.new CompareByStatus().equals(obj);
235     }
236
237     public int hashCode() {
238         return this.new CompareByStatus().hashCode();
239     }
240
241     public abstract class IssueModelComparator implements Comparator JavaDoc {
242         protected boolean isAscending = true;
243
244         public IssueModelComparator() {
245         }
246
247         public IssueModelComparator(boolean isAscending) {
248             setAscending(isAscending);
249         }
250
251         public void setAscending(boolean value) {
252             this.isAscending = value;
253         }
254
255         protected abstract int doComparison(IssueModel ma, IssueModel mb);
256
257         public final boolean equals(Object JavaDoc obj) {
258             if(! (obj instanceof IssueModel)) {
259                 return false;
260             }
261
262             try {
263                 IssueModel mo = (IssueModel) obj;
264                 if(IssueModel.this.getId() == mo.getId()) {
265                     return true;
266                 }
267             } catch(ClassCastException JavaDoc cce) {
268             }
269
270             return false;
271         }
272
273         public final int hashCode() {
274             return (IssueModel.this.getId() == null ? 1 : IssueModel.this.getId().intValue());
275         }
276
277         public final int compare(Object JavaDoc a, Object JavaDoc b) {
278             if(! (a instanceof IssueModel) || ! (b instanceof IssueModel)) {
279                 throw new ClassCastException JavaDoc();
280             }
281
282             IssueModel ma = (IssueModel) a;
283             IssueModel mb = (IssueModel) b;
284
285             int result = doComparison(ma, mb);
286             if(! isAscending) {
287                 result = result * -1;
288             }
289             return result;
290         }
291     }
292
293     public class CompareByStatus extends IssueModelComparator {
294         public CompareByStatus(){
295           super();
296         }
297
298         public CompareByStatus(boolean isAscending) {
299           super(isAscending);
300         }
301
302         protected int doComparison(IssueModel ma, IssueModel mb) {
303             if(ma.getStatus() == mb.getStatus()) {
304                 if(ma.getSeverity() == mb.getSeverity()) {
305                     return 0;
306                 } else if(ma.getSeverity() > mb.getSeverity()) {
307                     return 1;
308                 } else if(ma.getSeverity() < mb.getSeverity()) {
309                     return -1;
310                 }
311             } else if(ma.getStatus() > mb.getStatus()) {
312                 return 1;
313             } else if(ma.getStatus() < mb.getStatus()) {
314                 return -1;
315             }
316
317             return 0;
318         }
319     }
320
321     public class CompareByProjectAndStatus extends IssueModelComparator {
322         public CompareByProjectAndStatus() {
323             super();
324         }
325
326         public CompareByProjectAndStatus(boolean isAscending) {
327             super(isAscending);
328         }
329
330         protected int doComparison(IssueModel ma, IssueModel mb) {
331             if(ma.getProjectName().equals(mb.getProjectName())) {
332                 if(ma.getStatus() == mb.getStatus()) {
333                     if(ma.getSeverity() == mb.getSeverity()) {
334                         return 0;
335                     } else if(ma.getSeverity() > mb.getSeverity()) {
336                         return 1;
337                     } else if(ma.getSeverity() < mb.getSeverity()) {
338                         return -1;
339                     }
340                 } else if(ma.getStatus() > mb.getStatus()) {
341                     return 1;
342                 } else if(mb.getStatus() < mb.getStatus()) {
343                     return -1;
344                 }
345             } else {
346                 return ma.getProjectName().compareTo(mb.getProjectName());
347             }
348
349             return 0;
350         }
351     }
352
353     public class CompareByOwnerAndStatus extends IssueModelComparator {
354         public CompareByOwnerAndStatus() {
355             super();
356         }
357
358         public CompareByOwnerAndStatus(boolean isAscending) {
359             super(isAscending);
360         }
361
362         protected int doComparison(IssueModel ma, IssueModel mb) {
363             if(ma.getOwnerLastName().equals(mb.getOwnerLastName())) {
364                 if(ma.getOwnerFirstName().equals(mb.getOwnerFirstName())) {
365                     if(ma.getStatus() == mb.getStatus()) {
366                         if(ma.getSeverity() == mb.getSeverity()) {
367                             return 0;
368                         } else if(ma.getSeverity() > mb.getSeverity()) {
369                             return 1;
370                         } else if(ma.getSeverity() < mb.getSeverity()) {
371                             return -1;
372                         }
373                     } else if(ma.getStatus() > mb.getStatus()) {
374                         return 1;
375                     } else if(ma.getStatus() < mb.getStatus()) {
376                         return -1;
377                     }
378                 } else {
379                     return ma.getOwnerFirstName().compareTo(mb.getOwnerFirstName());
380                 }
381             } else {
382                 return ma.getOwnerLastName().compareTo(mb.getOwnerLastName());
383             }
384
385             return 0;
386         }
387     }
388
389     public class CompareById extends IssueModelComparator {
390         public CompareById() {
391             super();
392         }
393
394         public CompareById(boolean isAscending) {
395             super(isAscending);
396         }
397
398         protected int doComparison(IssueModel ma, IssueModel mb) {
399             if(ma.getId().intValue() > mb.getId().intValue()) {
400                 return 1;
401             } else if(ma.getId().intValue() < mb.getId().intValue()) {
402                 return -1;
403             }
404
405             return 0;
406         }
407     }
408
409     public class CompareBySeverity extends IssueModelComparator {
410         public CompareBySeverity() {
411             super();
412         }
413
414         public CompareBySeverity(boolean isAscending) {
415             super(isAscending);
416         }
417
418         protected int doComparison(IssueModel ma, IssueModel mb) {
419             if(ma.getSeverity() == mb.getSeverity()) {
420                 if(ma.getStatus() == mb.getStatus()) {
421                     return 0;
422                 } else if(ma.getStatus() > mb.getStatus()) {
423                     return 1;
424                 } else if(ma.getStatus() < mb.getStatus()) {
425                     return -1;
426                 }
427             } else if(ma.getSeverity() > mb.getSeverity()) {
428                 return 1;
429             } else if(ma.getSeverity() < mb.getSeverity()) {
430                 return -1;
431             }
432
433             return 0;
434         }
435     }
436
437     public class CompareByDate extends IssueModelComparator {
438         public CompareByDate() {
439             super();
440         }
441
442         public CompareByDate(boolean isAscending) {
443             super(isAscending);
444         }
445
446         protected int doComparison(IssueModel ma, IssueModel mb) {
447             if(ma.getLastModifiedDate() == null && mb.getLastModifiedDate() == null) {
448                 return 0;
449             } else if(ma.getLastModifiedDate() == null) {
450                 return -1;
451             } else if(mb.getLastModifiedDate() == null) {
452                 return 1;
453             }
454
455             if(ma.getLastModifiedDate().equals(mb.getLastModifiedDate())) {
456                 return 0;
457             } else if(ma.getLastModifiedDate().after(mb.getLastModifiedDate())) {
458                 return 1;
459             } else {
460                 return -1;
461             }
462         }
463     }
464 }
465
Popular Tags