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  	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       * @return The current leave calendar document
97       */
98      public static LeaveCalendarDocument getCurrentLeaveCalendarDocument() {
99          return  (LeaveCalendarDocument)TKContext.getStorageMap().get(LDOC_OBJ_KEY);
100     }
101 
102     /**
103      *
104      * @param ldoc The leave calendar document
105      */
106     public static void setCurrentLeaveCalendarDocument(LeaveCalendarDocument ldoc) {
107         TKContext.getStorageMap().put(LDOC_OBJ_KEY, ldoc);
108     }
109 
110     /**
111      *
112      * @return The current leave calendar document Id
113      */
114     public static String getCurrentLeaveCalendarDocumentId() {
115         return (String)TKContext.getStorageMap().get(LDOC_KEY);
116     }
117 
118     /**
119      *
120      * @param leaveCalendarDocumentId The leave calendar document Id
121      */
122     public static void setCurrentLeaveCalendarDocumentId(String leaveCalendarDocumentId) {
123         TKContext.getStorageMap().put(LDOC_KEY, leaveCalendarDocumentId);
124     }	
125 }