1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.util;
17
18 import java.util.Collections;
19 import java.util.HashMap;
20 import java.util.Map;
21
22 import javax.servlet.http.HttpServletRequest;
23
24 import org.kuali.hr.lm.leavecalendar.LeaveCalendarDocument;
25 import org.kuali.hr.time.timesheet.TimesheetDocument;
26 import org.kuali.rice.krad.util.GlobalVariables;
27
28 public class TKContext {
29
30 private static final String TDOC_OBJ_KEY = "_TDOC_O_KEY";
31 private static final String TDOC_KEY = "_TDOC_ID_KEY";
32
33 private static final String LDOC_OBJ_KEY = "_LDOC_O_KEY";
34 private static final String LDOC_KEY = "_LDOC_ID_KEY";
35
36 private static final ThreadLocal<Map<String, Object>> STORAGE_MAP = new ThreadLocal<Map<String, Object>>() {
37 @Override
38 protected Map<String, Object> initialValue() {
39 return Collections.synchronizedMap(new HashMap<String, Object>());
40 }
41 };
42
43 public static TimesheetDocument getCurrentTimesheetDocument() {
44 return (TimesheetDocument)TKContext.getStorageMap().get(TDOC_OBJ_KEY);
45 }
46
47 public static void setCurrentTimesheetDocument(TimesheetDocument tdoc) {
48 TKContext.getStorageMap().put(TDOC_OBJ_KEY, tdoc);
49 }
50
51
52
53
54
55 public static String getCurrentTimesheetDocumentId() {
56 return (String)TKContext.getStorageMap().get(TDOC_KEY);
57 }
58
59
60
61
62
63 public static void setCurrentTimesheetDocumentId(String timesheetDocumentId) {
64 TKContext.getStorageMap().put(TDOC_KEY, timesheetDocumentId);
65 }
66
67
68
69
70
71 public static TKUser getUser() {
72
73 return new TKUser();
74 }
75
76
77
78
79
80 public static String getPrincipalId(){
81 return GlobalVariables.getUserSession().getPrincipalId();
82 }
83
84 public static String getTargetPrincipalId() {
85 return TKUser.getCurrentTargetPerson().getPrincipalId();
86 }
87
88 public static HttpServletRequest getHttpServletRequest() {
89 return (HttpServletRequest) getStorageMap().get("REQUEST");
90 }
91
92 public static void setHttpServletRequest(HttpServletRequest request) {
93 getStorageMap().put("REQUEST", request);
94 }
95
96 public static Map<String, Object> getStorageMap() {
97 return STORAGE_MAP.get();
98 }
99
100 public static void resetStorageMap() {
101 STORAGE_MAP.remove();
102 }
103
104 public static void clear() {
105 resetStorageMap();
106 }
107
108
109
110
111 public static LeaveCalendarDocument getCurrentLeaveCalendarDocument() {
112 return (LeaveCalendarDocument)TKContext.getStorageMap().get(LDOC_OBJ_KEY);
113 }
114
115
116
117
118
119 public static void setCurrentLeaveCalendarDocument(LeaveCalendarDocument ldoc) {
120 TKContext.getStorageMap().put(LDOC_OBJ_KEY, ldoc);
121 }
122
123
124
125
126
127 public static String getCurrentLeaveCalendarDocumentId() {
128 return (String)TKContext.getStorageMap().get(LDOC_KEY);
129 }
130
131
132
133
134
135 public static void setCurrentLeaveCalendarDocumentId(String leaveCalendarDocumentId) {
136 TKContext.getStorageMap().put(LDOC_KEY, leaveCalendarDocumentId);
137 }
138 }