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
78 public static String getPrincipalId(){
79 return GlobalVariables.getUserSession().getPrincipalId();
80 }
81
82 public static String getTargetPrincipalId() {
83 return TKUser.getCurrentTargetPerson().getPrincipalId();
84 }
85
86 public static HttpServletRequest getHttpServletRequest() {
87 return (HttpServletRequest) getStorageMap().get("REQUEST");
88 }
89
90 public static void setHttpServletRequest(HttpServletRequest request) {
91 getStorageMap().put("REQUEST", request);
92 }
93
94 public static Map<String, Object> getStorageMap() {
95 return STORAGE_MAP.get();
96 }
97
98 public static void resetStorageMap() {
99 STORAGE_MAP.remove();
100 }
101
102 public static void clear() {
103 resetStorageMap();
104 }
105 }