View Javadoc

1   /**
2    * Copyright 2004-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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"; // Timesheet Document ID Key
32  	//private static final String USER_KEY = "_USER_KEY";
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       * @return The current timesheet document id, as set by the detail/clock
53       * pages.
54       */
55      public static String getCurrentTimesheetDocumentId() {
56          return (String)TKContext.getStorageMap().get(TDOC_KEY);
57      }
58  
59      /**
60       * Set the current timesheet document id.
61       * @param timesheetDocumentId The ID we are setting this value to.
62       */
63      public static void setCurrentTimesheetDocumentId(String timesheetDocumentId) {
64          TKContext.getStorageMap().put(TDOC_KEY, timesheetDocumentId);
65      }
66  
67  	/**
68  	 * TKUser has the internal concept of Backdoor User vs.Actual User.
69  	 * @return
70  	 */
71  	public static TKUser getUser() {
72          //TODO, this method isn't needed if everything in TKUser is accessed in a static fashion...
73          return new TKUser();
74  	}
75  
76  	//public static void setUser(TKUser user) {
77  	//	GlobalVariables.getUserSession().addObject(USER_KEY, user);
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      * @return The current leave calendar document
110      */
111     public static LeaveCalendarDocument getCurrentLeaveCalendarDocument() {
112         return  (LeaveCalendarDocument)TKContext.getStorageMap().get(LDOC_OBJ_KEY);
113     }
114 
115     /**
116      *
117      * @param ldoc The leave calendar document
118      */
119     public static void setCurrentLeaveCalendarDocument(LeaveCalendarDocument ldoc) {
120         TKContext.getStorageMap().put(LDOC_OBJ_KEY, ldoc);
121     }
122 
123     /**
124      *
125      * @return The current leave calendar document Id
126      */
127     public static String getCurrentLeaveCalendarDocumentId() {
128         return (String)TKContext.getStorageMap().get(LDOC_KEY);
129     }
130 
131     /**
132      *
133      * @param leaveCalendarDocumentId The leave calendar document Id
134      */
135     public static void setCurrentLeaveCalendarDocumentId(String leaveCalendarDocumentId) {
136         TKContext.getStorageMap().put(LDOC_KEY, leaveCalendarDocumentId);
137     }	
138 }