| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
package org.itracker.services.util; |
| 20 |
|
|
| 21 |
|
import java.util.Comparator; |
| 22 |
|
import java.util.HashMap; |
| 23 |
|
import java.util.Hashtable; |
| 24 |
|
import java.util.Iterator; |
| 25 |
|
import java.util.List; |
| 26 |
|
import java.util.Locale; |
| 27 |
|
import java.util.Map; |
| 28 |
|
import java.util.Set; |
| 29 |
|
import java.util.TreeSet; |
| 30 |
|
|
| 31 |
|
import org.apache.commons.lang.builder.CompareToBuilder; |
| 32 |
|
import org.itracker.core.resources.ITrackerResources; |
| 33 |
|
import org.itracker.model.Notification; |
| 34 |
|
import org.itracker.model.User; |
| 35 |
|
import org.itracker.model.Notification.Role; |
| 36 |
|
|
|
|
|
| 0% |
Uncovered Elements: 57 (57) |
Complexity: 15 |
Complexity Density: 0.39 |
|
| 37 |
|
public class NotificationUtilities { |
| 38 |
|
|
| 39 |
|
|
| 40 |
|
@deprecated |
| 41 |
|
|
| 42 |
|
public static final int ROLE_ANY = Notification.Role.ANY.getCode(); |
| 43 |
|
|
| 44 |
|
@deprecated |
| 45 |
|
|
| 46 |
|
public static final int ROLE_CREATOR = Notification.Role.CREATOR.getCode(); |
| 47 |
|
|
| 48 |
|
@deprecated |
| 49 |
|
|
| 50 |
|
public static final int ROLE_OWNER = Notification.Role.OWNER.getCode(); |
| 51 |
|
|
| 52 |
|
@deprecated |
| 53 |
|
|
| 54 |
|
public static final int ROLE_CONTRIBUTER = Notification.Role.CONTRIBUTER.getCode(); |
| 55 |
|
|
| 56 |
|
@deprecated |
| 57 |
|
|
| 58 |
|
public static final int ROLE_QA = Notification.Role.QA.getCode(); |
| 59 |
|
|
| 60 |
|
@deprecated |
| 61 |
|
|
| 62 |
|
public static final int ROLE_PM = Notification.Role.PM.getCode(); |
| 63 |
|
|
| 64 |
|
@deprecated |
| 65 |
|
|
| 66 |
|
public static final int ROLE_PO = Notification.Role.PO.getCode(); |
| 67 |
|
|
| 68 |
|
@deprecated |
| 69 |
|
|
| 70 |
|
public static final int ROLE_CO = Notification.Role.CO.getCode(); |
| 71 |
|
|
| 72 |
|
@deprecated |
| 73 |
|
|
| 74 |
|
public static final int ROLE_VO = Notification.Role.VO.getCode(); |
| 75 |
|
|
| 76 |
|
@deprecated |
| 77 |
|
|
| 78 |
|
public static final int ROLE_IP = Notification.Role.IP.getCode(); |
| 79 |
|
|
| 80 |
|
|
| 81 |
|
@deprecated |
| 82 |
|
|
| 83 |
|
public static final int TYPE_CREATED = Notification.Type.CREATED.getCode(); |
| 84 |
|
|
| 85 |
|
@deprecated |
| 86 |
|
|
| 87 |
|
public static final int TYPE_UPDATED = Notification.Type.UPDATED.getCode(); |
| 88 |
|
|
| 89 |
|
@deprecated |
| 90 |
|
|
| 91 |
|
public static final int TYPE_ASSIGNED = Notification.Type.ASSIGNED.getCode(); |
| 92 |
|
|
| 93 |
|
@deprecated |
| 94 |
|
|
| 95 |
|
public static final int TYPE_CLOSED = Notification.Type.CLOSED.getCode(); |
| 96 |
|
|
| 97 |
|
@deprecated |
| 98 |
|
|
| 99 |
|
public static final int TYPE_SELF_REGISTER = Notification.Type.SELF_REGISTER.getCode(); |
| 100 |
|
|
| 101 |
|
@deprecated |
| 102 |
|
|
| 103 |
|
public static final int TYPE_ISSUE_REMINDER = Notification.Type.ISSUE_REMINDER.getCode(); |
| 104 |
|
|
| 105 |
|
|
| 106 |
|
@deprecated |
| 107 |
|
|
| 108 |
|
private static HashMap<Locale, HashMap<Role, String>> roleNames = new HashMap<Locale, HashMap<Role, String>>(); |
| 109 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 110 |
0
|
public NotificationUtilities() {... |
| 111 |
0
|
super(); |
| 112 |
|
} |
| 113 |
|
|
| 114 |
|
|
| 115 |
|
@deprecated |
| 116 |
|
@param |
| 117 |
|
@return |
| 118 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 119 |
0
|
public static String getRoleName(int value) {... |
| 120 |
0
|
return getRoleName(value, ITrackerResources.getLocale()); |
| 121 |
|
} |
| 122 |
|
|
| 123 |
|
|
| 124 |
|
@deprecated |
| 125 |
|
@param |
| 126 |
|
@param |
| 127 |
|
@return |
| 128 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 129 |
0
|
public static String getRoleName(int value, Locale locale) {... |
| 130 |
0
|
return ITrackerResources.getString("itracker.notification.role." |
| 131 |
|
+ value, locale); |
| 132 |
|
} |
| 133 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 134 |
0
|
public static String getRoleName(Role role) {... |
| 135 |
0
|
return getRoleName(role, ITrackerResources.getLocale()); |
| 136 |
|
} |
| 137 |
|
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 138 |
0
|
public static String getRoleName(Role role, Locale locale) {... |
| 139 |
0
|
String s; |
| 140 |
0
|
if (null != (s = ITrackerResources.getString( |
| 141 |
|
"itracker.notification.role." + role, locale))) { |
| 142 |
0
|
return s; |
| 143 |
|
} |
| 144 |
|
|
| 145 |
0
|
return ITrackerResources.getString("itracker.notification.role." |
| 146 |
|
+ role.getCode(), locale); |
| 147 |
|
} |
| 148 |
|
|
| 149 |
|
|
| 150 |
|
@deprecated |
| 151 |
|
@return |
| 152 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 153 |
0
|
public static HashMap<Role, String> getRoleNames() {... |
| 154 |
0
|
return getRoleNames(ITrackerResources.getLocale()); |
| 155 |
|
} |
| 156 |
|
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 2 |
Complexity Density: 0.14 |
|
| 157 |
0
|
public static HashMap<Role, String> getRoleNames(Locale locale) {... |
| 158 |
0
|
HashMap<Role, String> roles = roleNames.get(locale); |
| 159 |
0
|
if (roles == null) { |
| 160 |
0
|
roles = new HashMap<Role, String>(); |
| 161 |
0
|
roles.put(Notification.Role.CREATOR, |
| 162 |
|
getRoleName(Notification.Role.CREATOR, locale)); |
| 163 |
0
|
roles.put(Notification.Role.OWNER, getRoleName(Role.OWNER, locale)); |
| 164 |
0
|
roles.put(Notification.Role.CONTRIBUTER, getRoleName( |
| 165 |
|
Notification.Role.CONTRIBUTER, locale)); |
| 166 |
0
|
roles.put(Notification.Role.QA, getRoleName(Role.QA, locale)); |
| 167 |
0
|
roles.put(Notification.Role.PM, getRoleName(Role.PM, locale)); |
| 168 |
0
|
roles.put(Notification.Role.PO, getRoleName(Role.PO, locale)); |
| 169 |
0
|
roles.put(Notification.Role.CO, getRoleName(Role.CO, locale)); |
| 170 |
0
|
roles.put(Notification.Role.VO, getRoleName(Role.VO, locale)); |
| 171 |
0
|
roles.put(Notification.Role.IP, getRoleName(Role.IP, locale)); |
| 172 |
|
} |
| 173 |
0
|
roleNames.put(locale, roles); |
| 174 |
0
|
return roles; |
| 175 |
|
} |
| 176 |
|
|
| 177 |
|
|
| 178 |
|
@deprecated |
| 179 |
|
@param |
| 180 |
|
@return |
| 181 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 182 |
0
|
public static String getTypeName(int value) {... |
| 183 |
0
|
return getTypeName(value, ITrackerResources.getLocale()); |
| 184 |
|
} |
| 185 |
|
|
| 186 |
|
|
| 187 |
|
@deprecated |
| 188 |
|
@param |
| 189 |
|
@param |
| 190 |
|
@return |
| 191 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 192 |
0
|
public static String getTypeName(int value, Locale locale) {... |
| 193 |
0
|
return ITrackerResources.getString("itracker.notification.type." |
| 194 |
|
+ value, locale); |
| 195 |
|
} |
| 196 |
|
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 3 |
Complexity Density: 0.25 |
|
| 197 |
0
|
public static final Map<User, Set<Notification.Role>> mappedRoles(List<Notification> notifications) {... |
| 198 |
|
|
| 199 |
0
|
Map<User, Set<Role>> mapping = new Hashtable<User, Set<Role>>(); |
| 200 |
0
|
Iterator<Notification> notificationIt = notifications.iterator(); |
| 201 |
0
|
while (notificationIt.hasNext()) { |
| 202 |
0
|
Notification notification = (Notification) notificationIt.next(); |
| 203 |
0
|
Set<Role> roles; |
| 204 |
0
|
if (mapping.keySet().contains(notification.getUser())) { |
| 205 |
0
|
roles = mapping.get(notification.getUser()); |
| 206 |
0
|
roles.add(notification.getRole()); |
| 207 |
|
} else { |
| 208 |
0
|
roles = new TreeSet<Role>(new Comparator<Role>() { |
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 209 |
0
|
public int compare(Role o1, Role o2) {... |
| 210 |
0
|
return new CompareToBuilder().append(o1.getCode(), o2.getCode()).toComparison(); |
| 211 |
|
} |
| 212 |
|
}); |
| 213 |
0
|
roles.add(notification.getRole()); |
| 214 |
0
|
mapping.put(notification.getUser(), roles); |
| 215 |
|
} |
| 216 |
|
} |
| 217 |
|
|
| 218 |
|
|
| 219 |
0
|
return mapping; |
| 220 |
|
} |
| 221 |
|
|
| 222 |
|
} |