View Javadoc
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.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       * @deprecated, use enumeration Notification.Role instead
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       * @deprecated
42       */
43      public static String getRoleName(int value) {
44          return getRoleName(value, ITrackerResources.getLocale());
45      }
46  
47      /**
48       * @deprecated
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 }