Clover Coverage Report - itracker
Coverage timestamp: Tue May 1 2012 16:42:12 CEST
40   271   28   2
18   144   0.7   3.33
20     1.4  
6    
 
 
  Notification       Line # 36 29 19 0% 0.0
  Notification.IssueUserRoleComparator       Line # 162 1 1 0% 0.0
  Notification.UserComparator       Line # 177 1 1 0% 0.0
  Notification.RoleComparator       Line # 192 5 3 0% 0.0
  Notification.Role       Line # 211 2 2 0% 0.0
  Notification.Type       Line # 245 2 2 0% 0.0
 
No Tests
 
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 org.itracker.model;
20   
21    import java.io.Serializable;
22    import java.util.Comparator;
23   
24    import org.apache.commons.lang.builder.CompareToBuilder;
25    import org.apache.commons.lang.builder.ToStringBuilder;
26   
27    /**
28    * A notification to a user about an Issue.
29    *
30    * <p>
31    * An Notification can only belong to 1 Issue (composition).
32    * </p>
33    *
34    * @author ready
35    */
 
36    public class Notification extends AbstractEntity implements Comparable<Entity> {
37   
38    /**
39    *
40    */
41    private static final long serialVersionUID = 1L;
42   
43    public static final Comparator<Notification> TYPE_COMPARATOR = new RoleComparator();
44   
45    public static final Comparator<Notification> USER_COMPARATOR = new UserComparator();
46   
47    public static final Comparator<Notification> ISSUE_USER_ROLE_COMPARATOR = new IssueUserRoleComparator();
48   
49    private Issue issue;
50   
51    private User user;
52   
53    private Role role;
54   
55    /**
56    * Default constructor (required by Hibernate).
57    *
58    * <p>
59    * PENDING: should be <code>private</code> so that it can only be used by
60    * Hibernate, to ensure that the fields which form an instance's identity
61    * are always initialized/never <tt>null</tt>.
62    * </p>
63    */
 
64  0 toggle public Notification() {
65    }
66   
67    /**
68    * @deprecated use Role instead int for role
69    * @param user
70    * @param issue
71    * @param role
72    */
 
73  0 toggle public Notification(User user, Issue issue, int role) {
74  0 this.setUser(user);
75  0 this.setIssue(issue);
76  0 this.setNotificationRole(role);
77   
78    }
79   
 
80  0 toggle public Notification(User user, Issue issue, Role role) {
81  0 this.setUser(user);
82  0 this.setIssue(issue);
83  0 this.setRole(role);
84    }
85   
 
86  0 toggle public Issue getIssue() {
87  0 return issue;
88    }
89   
 
90  0 toggle public void setIssue(Issue issue) {
91  0 if (issue == null) {
92  0 throw new IllegalArgumentException("null issue");
93    }
94  0 this.issue = issue;
95    }
96   
 
97  0 toggle public User getUser() {
98  0 return user;
99    }
100   
 
101  0 toggle public void setUser(User user) {
102  0 if (user == null) {
103  0 throw new IllegalArgumentException("null user");
104    }
105  0 this.user = user;
106    }
107   
108    /**
109    * @deprecated use getRole instead
110    * @return
111    */
 
112  0 toggle public int getNotificationRole() {
113  0 Role r = getRole();
114  0 if (null == r) {
115  0 r = Role.ANY;
116    }
117  0 return r.code;
118    }
119   
120    /**
121    * @deprecated
122    * @param role
123    */
 
124  0 toggle public void setNotificationRole(int role) {
125  0 Role r = getRoleForCode(role);
126  0 if (null == r) {
127  0 r = Role.ANY;
128    }
129  0 this.setRole(r);
130    }
131   
 
132  0 toggle private Role getRoleForCode(int code) {
133  0 for (int i = 0; i < Role.values().length; i++) {
134  0 if (Role.values()[i].code == code) {
135  0 return Role.values()[i];
136    }
137    }
138  0 return Role.ANY;
139    }
140   
 
141  0 toggle public Role getRole() {
142  0 return this.role;
143    }
144   
 
145  0 toggle public void setRole(Role role) {
146  0 this.role = role;
147    }
148   
 
149  0 toggle @Override
150    public String toString() {
151  0 return new ToStringBuilder(this).append("id", getId()).append("issue",
152    getIssue()).append("user", getUser()).append("role", getRole())
153    .toString();
154    }
155   
156    /**
157    * Compares by properties issue, user, role.
158    *
159    * @author ranks
160    *
161    */
 
162    public static final class IssueUserRoleComparator implements
163    Comparator<Notification>, Serializable {
164    /**
165    *
166    */
167    private static final long serialVersionUID = 1L;
168   
 
169  0 toggle public int compare(Notification o1, Notification o2) {
170  0 return new CompareToBuilder().append(o1.getIssue(), o2.getIssue())
171    .append(o1.getUser(), o2.getUser(), User.NAME_COMPARATOR)
172    .append(o1.getRole().getCode(), o2.getRole().getCode())
173    .toComparison();
174    }
175    }
176   
 
177    private static class UserComparator implements Comparator<Notification>,
178    Serializable {
179    /**
180    *
181    */
182    private static final long serialVersionUID = 1L;
183   
 
184  0 toggle public int compare(Notification a, Notification b) {
185  0 return new CompareToBuilder().append(a.getUser(), b.getUser(),
186    User.NAME_COMPARATOR).append(a.getRole(), b.getRole(),
187    Notification.TYPE_COMPARATOR).toComparison();
188    }
189   
190    }
191   
 
192    private static class RoleComparator implements Comparator<Notification>,
193    Serializable {
194    /**
195    *
196    */
197    private static final long serialVersionUID = 1L;
198   
 
199  0 toggle public int compare(Notification a, Notification b) {
200  0 if (null == a.getRole()) {
201  0 return null == b.getRole()?0 : -1;
202  0 } else if (b.getRole() == null) {
203  0 return 1;
204    }
205  0 return new CompareToBuilder().append(a.getRole().getCode(),
206    b.getRole().getCode()).toComparison();
207    }
208   
209    }
210   
 
211    public static enum Role {
212   
213    ANY(-1),
214   
215    CREATOR(1),
216   
217    OWNER(2),
218   
219    CONTRIBUTER(3),
220   
221    QA(4),
222   
223    PM(5),
224   
225    PO(6),
226   
227    CO(7),
228   
229    VO(8),
230   
231    IP(9);
232   
233    private final int code;
234   
 
235  0 toggle private Role(int code) {
236  0 this.code = code;
237    }
238   
 
239  0 toggle public Integer getCode() {
240  0 return this.code;
241    }
242   
243    }
244   
 
245    public static enum Type {
246   
247    CREATED(1),
248   
249    UPDATED(2),
250   
251    ASSIGNED(3),
252   
253    CLOSED(4),
254   
255    SELF_REGISTER(5),
256   
257    ISSUE_REMINDER(6);
258   
259    private final int code;
260   
 
261  0 toggle private Type(int code) {
262  0 this.code = code;
263    }
264   
 
265  0 toggle public Integer getCode() {
266  0 return code;
267    }
268   
269    }
270   
271    }