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 public static String getPrincipalId(){
68 return GlobalVariables.getUserSession().getPrincipalId();
69 }
70
71 public static String getTargetPrincipalId() {
72 return TKUser.getCurrentTargetPersonId();
73 }
74
75 public static HttpServletRequest getHttpServletRequest() {
76 return (HttpServletRequest) getStorageMap().get("REQUEST");
77 }
78
79 public static void setHttpServletRequest(HttpServletRequest request) {
80 getStorageMap().put("REQUEST", request);
81 }
82
83 public static Map<String, Object> getStorageMap() {
84 return STORAGE_MAP.get();
85 }
86
87 public static void resetStorageMap() {
88 STORAGE_MAP.remove();
89 }
90
91 public static void clear() {
92 resetStorageMap();
93 }
94
95
96
97
98 public static LeaveCalendarDocument getCurrentLeaveCalendarDocument() {
99 return (LeaveCalendarDocument)TKContext.getStorageMap().get(LDOC_OBJ_KEY);
100 }
101
102
103
104
105
106 public static void setCurrentLeaveCalendarDocument(LeaveCalendarDocument ldoc) {
107 TKContext.getStorageMap().put(LDOC_OBJ_KEY, ldoc);
108 }
109
110
111
112
113
114 public static String getCurrentLeaveCalendarDocumentId() {
115 return (String)TKContext.getStorageMap().get(LDOC_KEY);
116 }
117
118
119
120
121
122 public static void setCurrentLeaveCalendarDocumentId(String leaveCalendarDocumentId) {
123 TKContext.getStorageMap().put(LDOC_KEY, leaveCalendarDocumentId);
124 }
125 }