1 18 19 package cowsultants.itracker.ejb.client.util; 20 21 import java.util.*; 22 23 import cowsultants.itracker.ejb.client.models.*; 24 import cowsultants.itracker.ejb.client.resources.*; 25 26 public class ProjectUtilities { 27 public static final int OPTION_SURPRESS_HISTORY_HTML = 1; 29 public static final int OPTION_ALLOW_ASSIGN_TO_CLOSE = 2; 30 public static final int OPTION_PREDEFINED_RESOLUTIONS = 4; 31 public static final int OPTION_ALLOW_SELF_REGISTERED_CREATE = 8; 32 public static final int OPTION_ALLOW_SELF_REGISTERED_VIEW_ALL = 16; 33 public static final int OPTION_NO_ATTACHMENTS = 32; 34 public static final int OPTION_LITERAL_HISTORY_HTML = 64; 35 36 public static final int STATUS_DELETED = -1; 37 public static final int STATUS_ACTIVE = 1; 38 public static final int STATUS_VIEWABLE = 2; 39 public static final int STATUS_LOCKED = 3; 40 41 private static HashMap statusNames = new HashMap(); 42 43 public ProjectUtilities() { 44 } 45 46 public static String getStatusName(int value) { 47 return getStatusName(value, ITrackerResources.getLocale()); 48 } 49 50 public static String getStatusName(int value, Locale locale) { 51 return ITrackerResources.getString(ITrackerResources.KEY_BASE_PROJECT_STATUS + value, locale); 52 } 53 54 public static HashMap getStatusNames() { 55 return getStatusNames(ITrackerResources.getLocale()); 56 } 57 58 public static HashMap getStatusNames(Locale locale) { 59 HashMap statuses = (HashMap) statusNames.get(locale); 60 if(statuses == null) { 61 statuses = new HashMap(); 62 statuses.put(Integer.toString(STATUS_DELETED), getStatusName(STATUS_DELETED, locale)); 63 statuses.put(Integer.toString(STATUS_ACTIVE), getStatusName(STATUS_ACTIVE, locale)); 64 statuses.put(Integer.toString(STATUS_VIEWABLE), getStatusName(STATUS_VIEWABLE, locale)); 65 statuses.put(Integer.toString(STATUS_LOCKED), getStatusName(STATUS_LOCKED, locale)); 66 } 67 statusNames.put(locale, statuses); 68 return statuses; 69 } 70 71 public static boolean hasOption(int option, int currentOptions) { 72 return ((option & currentOptions) == option); 73 } 74 75 public static Integer [] getOptions(int currentOptions) { 76 Vector options = new Vector(); 77 if(hasOption(OPTION_SURPRESS_HISTORY_HTML, currentOptions)) { 78 options.add(new Integer (OPTION_SURPRESS_HISTORY_HTML)); 79 } 80 if(hasOption(OPTION_ALLOW_ASSIGN_TO_CLOSE, currentOptions)) { 81 options.add(new Integer (OPTION_ALLOW_ASSIGN_TO_CLOSE)); 82 } 83 if(hasOption(OPTION_PREDEFINED_RESOLUTIONS, currentOptions)) { 84 options.add(new Integer (OPTION_PREDEFINED_RESOLUTIONS)); 85 } 86 if(hasOption(OPTION_ALLOW_SELF_REGISTERED_CREATE, currentOptions)) { 87 options.add(new Integer (OPTION_ALLOW_SELF_REGISTERED_CREATE)); 88 } 89 if(hasOption(OPTION_ALLOW_SELF_REGISTERED_VIEW_ALL, currentOptions)) { 90 options.add(new Integer (OPTION_ALLOW_SELF_REGISTERED_VIEW_ALL)); 91 } 92 if(hasOption(OPTION_NO_ATTACHMENTS, currentOptions)) { 93 options.add(new Integer (OPTION_NO_ATTACHMENTS)); 94 } 95 if(hasOption(OPTION_LITERAL_HISTORY_HTML, currentOptions)) { 96 options.add(new Integer (OPTION_LITERAL_HISTORY_HTML)); 97 } 98 Integer [] optionsArray = new Integer [options.size()]; 99 options.copyInto(optionsArray); 100 return optionsArray; 101 } 102 103 109 public static boolean hasProjectAccess(Integer projectId, HashMap permissions) { 110 if(permissions == null) { 111 return false; 112 } 113 114 Boolean superUser = (Boolean ) permissions.get(Integer.toString(-1)); 115 if(superUser != null && superUser.booleanValue()) { 116 return true; 117 } 118 119 if(projectId != null && projectId.intValue() > 0) { 120 HashSet projectPermissions = (HashSet) permissions.get(projectId); 121 122 if(projectPermissions != null && projectPermissions.size() > 0) { 123 return true; 124 } 125 } 126 return false; 127 } 128 } 129 | Popular Tags |