001 /**
002 * Copyright 2004-2013 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.hr.time.util;
017
018 import java.util.Collections;
019 import java.util.HashMap;
020 import java.util.Map;
021
022 import javax.servlet.http.HttpServletRequest;
023
024 import org.kuali.hr.lm.leavecalendar.LeaveCalendarDocument;
025 import org.kuali.hr.time.timesheet.TimesheetDocument;
026 import org.kuali.rice.krad.util.GlobalVariables;
027
028 public class TKContext {
029
030 private static final String TDOC_OBJ_KEY = "_TDOC_O_KEY";
031 private static final String TDOC_KEY = "_TDOC_ID_KEY"; // Timesheet Document ID Key
032 //private static final String USER_KEY = "_USER_KEY";
033 private static final String LDOC_OBJ_KEY = "_LDOC_O_KEY";
034 private static final String LDOC_KEY = "_LDOC_ID_KEY";
035
036 private static final ThreadLocal<Map<String, Object>> STORAGE_MAP = new ThreadLocal<Map<String, Object>>() {
037 @Override
038 protected Map<String, Object> initialValue() {
039 return Collections.synchronizedMap(new HashMap<String, Object>());
040 }
041 };
042
043 public static TimesheetDocument getCurrentTimesheetDocument() {
044 return (TimesheetDocument)TKContext.getStorageMap().get(TDOC_OBJ_KEY);
045 }
046
047 public static void setCurrentTimesheetDocument(TimesheetDocument tdoc) {
048 TKContext.getStorageMap().put(TDOC_OBJ_KEY, tdoc);
049 }
050
051 /**
052 * @return The current timesheet document id, as set by the detail/clock
053 * pages.
054 */
055 public static String getCurrentTimesheetDocumentId() {
056 return (String)TKContext.getStorageMap().get(TDOC_KEY);
057 }
058
059 /**
060 * Set the current timesheet document id.
061 * @param timesheetDocumentId The ID we are setting this value to.
062 */
063 public static void setCurrentTimesheetDocumentId(String timesheetDocumentId) {
064 TKContext.getStorageMap().put(TDOC_KEY, timesheetDocumentId);
065 }
066
067 /**
068 * TKUser has the internal concept of Backdoor User vs.Actual User.
069 * @return
070 */
071 public static TKUser getUser() {
072 //TODO, this method isn't needed if everything in TKUser is accessed in a static fashion...
073 return new TKUser();
074 }
075
076 //public static void setUser(TKUser user) {
077 // GlobalVariables.getUserSession().addObject(USER_KEY, user);
078 //}
079
080 public static String getPrincipalId(){
081 return GlobalVariables.getUserSession().getPrincipalId();
082 }
083
084 public static String getTargetPrincipalId() {
085 return TKUser.getCurrentTargetPerson().getPrincipalId();
086 }
087
088 public static HttpServletRequest getHttpServletRequest() {
089 return (HttpServletRequest) getStorageMap().get("REQUEST");
090 }
091
092 public static void setHttpServletRequest(HttpServletRequest request) {
093 getStorageMap().put("REQUEST", request);
094 }
095
096 public static Map<String, Object> getStorageMap() {
097 return STORAGE_MAP.get();
098 }
099
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 }