1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  package org.itracker.model.util;
20  
21  import org.apache.commons.lang.builder.CompareToBuilder;
22  import org.itracker.core.resources.ITrackerResources;
23  import org.itracker.model.Notification;
24  import org.itracker.model.Notification.Role;
25  import org.itracker.model.User;
26  
27  import java.util.*;
28  
29  public class NotificationUtilities {
30  
31      
32  
33  
34      private static HashMap<Locale, HashMap<Role, String>> roleNames = new HashMap<Locale, HashMap<Role, String>>();
35  
36      public NotificationUtilities() {
37          super();
38      }
39  
40      
41  
42  
43      public static String getRoleName(int value) {
44          return getRoleName(value, ITrackerResources.getLocale());
45      }
46  
47      
48  
49  
50      public static String getRoleName(int value, Locale locale) {
51          return ITrackerResources.getString("itracker.notification.role."
52                  + value, locale);
53      }
54  
55      public static String getRoleName(Role role) {
56          return getRoleName(role, ITrackerResources.getLocale());
57      }
58  
59      public static String getRoleName(Role role, Locale locale) {
60          String s;
61          if (null != (s = ITrackerResources.getString(
62                  "itracker.notification.role." + role, locale))) {
63              return s;
64          }
65  
66          return ITrackerResources.getString("itracker.notification.role."
67                  + role.getCode(), locale);
68      }
69  
70  
71      public static HashMap<Role, String> getRoleNames(Locale locale) {
72          HashMap<Role, String> roles = roleNames.get(locale);
73          if (roles == null) {
74              roles = new HashMap<Role, String>();
75              roles.put(Notification.Role.CREATOR,
76                      getRoleName(Notification.Role.CREATOR, locale));
77              roles.put(Notification.Role.OWNER, getRoleName(Role.OWNER, locale));
78              roles.put(Notification.Role.CONTRIBUTER, getRoleName(
79                      Notification.Role.CONTRIBUTER, locale));
80              roles.put(Notification.Role.QA, getRoleName(Role.QA, locale));
81              roles.put(Notification.Role.PM, getRoleName(Role.PM, locale));
82              roles.put(Notification.Role.PO, getRoleName(Role.PO, locale));
83              roles.put(Notification.Role.CO, getRoleName(Role.CO, locale));
84              roles.put(Notification.Role.VO, getRoleName(Role.VO, locale));
85              roles.put(Notification.Role.IP, getRoleName(Role.IP, locale));
86          }
87          roleNames.put(locale, roles);
88          return roles;
89      }
90  
91  
92      public static final Map<User, Set<Notification.Role>> mappedRoles(List<Notification> notifications) {
93  
94          Map<User, Set<Role>> mapping = new Hashtable<User, Set<Role>>();
95          Iterator<Notification> notificationIt = notifications.iterator();
96          while (notificationIt.hasNext()) {
97              Notificationorg/itracker/model/Notification.html#Notification">Notification notification = (Notification) notificationIt.next();
98              Set<Role> roles;
99              if (mapping.keySet().contains(notification.getUser())) {
100                 roles = mapping.get(notification.getUser());
101                 roles.add(notification.getRole());
102             } else {
103                 roles = new TreeSet<Role>(new Comparator<Role>() {
104                     public int compare(Role o1, Role o2) {
105                         return new CompareToBuilder().append(o1.getCode(), o2.getCode()).toComparison();
106                     }
107                 });
108                 roles.add(notification.getRole());
109                 mapping.put(notification.getUser(), roles);
110             }
111         }
112 
113 
114         return mapping;
115     }
116 
117 }