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.time.timesheet.TimesheetDocument;
25 import org.kuali.rice.krad.util.GlobalVariables;
26
27 public class TKContext {
28
29 private static final String TDOC_OBJ_KEY = "_TDOC_O_KEY";
30 private static final String TDOC_KEY = "_TDOC_ID_KEY";
31
32
33 private static final ThreadLocal<Map<String, Object>> STORAGE_MAP = new ThreadLocal<Map<String, Object>>() {
34 @Override
35 protected Map<String, Object> initialValue() {
36 return Collections.synchronizedMap(new HashMap<String, Object>());
37 }
38 };
39
40 public static TimesheetDocument getCurrentTimesheetDocument() {
41 return (TimesheetDocument)TKContext.getStorageMap().get(TDOC_OBJ_KEY);
42 }
43
44 public static void setCurrentTimesheetDocument(TimesheetDocument tdoc) {
45 TKContext.getStorageMap().put(TDOC_OBJ_KEY, tdoc);
46 }
47
48
49
50
51
52 public static String getCurrentTimesheetDocumentId() {
53 return (String)TKContext.getStorageMap().get(TDOC_KEY);
54 }
55
56
57
58
59
60 public static void setCurrentTimesheetDocumentId(String timesheetDocumentId) {
61 TKContext.getStorageMap().put(TDOC_KEY, timesheetDocumentId);
62 }
63
64
65
66
67
68 public static TKUser getUser() {
69
70 return new TKUser();
71 }
72
73
74
75
76
77 public static String getPrincipalId(){
78 return GlobalVariables.getUserSession().getPrincipalId();
79 }
80
81 public static String getTargetPrincipalId() {
82 return TKUser.getCurrentTargetPerson().getPrincipalId();
83 }
84
85 public static HttpServletRequest getHttpServletRequest() {
86 return (HttpServletRequest) getStorageMap().get("REQUEST");
87 }
88
89 public static void setHttpServletRequest(HttpServletRequest request) {
90 getStorageMap().put("REQUEST", request);
91 }
92
93 public static Map<String, Object> getStorageMap() {
94 return STORAGE_MAP.get();
95 }
96
97 public static void resetStorageMap() {
98 STORAGE_MAP.remove();
99 }
100
101 public static void clear() {
102 resetStorageMap();
103 }
104 }