1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.krad.util; |
17 | |
|
18 | |
import org.kuali.rice.krad.UserSession; |
19 | |
|
20 | |
import java.util.HashMap; |
21 | |
import java.util.Map; |
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | 0 | public class GlobalVariables { |
29 | |
|
30 | 0 | private static ThreadLocal<UserSession> userSessions = new ThreadLocal<UserSession>(); |
31 | 0 | private static ThreadLocal<String> hideSessionFromTestsMessage = new ThreadLocal<String>(); |
32 | |
|
33 | 0 | private static ThreadLocal<MessageMap> messageMaps = new ThreadLocal<MessageMap>() { |
34 | |
@Override |
35 | |
protected MessageMap initialValue() { |
36 | 0 | return new MessageMap(); |
37 | |
} |
38 | |
}; |
39 | |
|
40 | 0 | private static ThreadLocal<HashMap<String, AuditCluster>> auditErrorMaps = new ThreadLocal<HashMap<String, AuditCluster>>() { |
41 | |
@Override |
42 | |
protected HashMap<String, AuditCluster> initialValue() { |
43 | 0 | return new HashMap<String, AuditCluster>(); |
44 | |
} |
45 | |
}; |
46 | |
|
47 | 0 | private static ThreadLocal<Map<String,Object>> requestCaches = new ThreadLocal<Map<String,Object>>() { |
48 | |
@Override |
49 | |
protected HashMap<String, Object> initialValue() { |
50 | 0 | return new HashMap<String, Object>(); |
51 | |
} |
52 | |
}; |
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
public static UserSession getUserSession() { |
59 | 0 | String message = hideSessionFromTestsMessage.get(); |
60 | 0 | if (message != null) { |
61 | 0 | throw new RuntimeException(message); |
62 | |
} |
63 | 0 | return userSessions.get(); |
64 | |
} |
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
public static void setHideSessionFromTestsMessage(String message) { |
73 | 0 | hideSessionFromTestsMessage.set(message); |
74 | 0 | } |
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
public static void setUserSession(UserSession userSession) { |
82 | 0 | userSessions.set(userSession); |
83 | 0 | } |
84 | |
|
85 | |
public static MessageMap getMessageMap() { |
86 | 0 | return messageMaps.get(); |
87 | |
} |
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
public static void mergeErrorMap(MessageMap messageMap) { |
94 | 0 | getMessageMap().getErrorMessages().putAll(messageMap.getErrorMessages()); |
95 | 0 | getMessageMap().getWarningMessages().putAll(messageMap.getWarningMessages()); |
96 | 0 | getMessageMap().getInfoMessages().putAll(messageMap.getInfoMessages()); |
97 | 0 | } |
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
public static void setMessageMap(MessageMap messageMap) { |
105 | 0 | messageMaps.set(messageMap); |
106 | 0 | } |
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
public static Map<String, AuditCluster> getAuditErrorMap() { |
112 | 0 | return auditErrorMaps.get(); |
113 | |
} |
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
public static void setAuditErrorMap(HashMap<String, AuditCluster> errorMap) { |
121 | 0 | auditErrorMaps.set(errorMap); |
122 | 0 | } |
123 | |
|
124 | |
public static Object getRequestCache( String cacheName ) { |
125 | 0 | return requestCaches.get().get(cacheName); |
126 | |
} |
127 | |
|
128 | |
public static void setRequestCache( String cacheName, Object cacheObject ) { |
129 | 0 | requestCaches.get().put(cacheName, cacheObject); |
130 | 0 | } |
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | |
public static void clear() { |
136 | 0 | messageMaps.set(new MessageMap()); |
137 | 0 | auditErrorMaps.set(new HashMap<String, AuditCluster>()); |
138 | 0 | requestCaches.set(new HashMap<String,Object>() ); |
139 | 0 | } |
140 | |
} |