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 public static String getPrincipalId(){
068 return GlobalVariables.getUserSession().getPrincipalId();
069 }
070
071 public static String getTargetPrincipalId() {
072 return TKUser.getCurrentTargetPersonId();
073 }
074
075 public static HttpServletRequest getHttpServletRequest() {
076 return (HttpServletRequest) getStorageMap().get("REQUEST");
077 }
078
079 public static void setHttpServletRequest(HttpServletRequest request) {
080 getStorageMap().put("REQUEST", request);
081 }
082
083 public static Map<String, Object> getStorageMap() {
084 return STORAGE_MAP.get();
085 }
086
087 public static void resetStorageMap() {
088 STORAGE_MAP.remove();
089 }
090
091 public static void clear() {
092 resetStorageMap();
093 }
094
095 /**
096 * @return The current leave calendar document
097 */
098 public static LeaveCalendarDocument getCurrentLeaveCalendarDocument() {
099 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 }