001 /** 002 * Copyright 2004-2012 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.time.timesheet.TimesheetDocument; 025 import org.kuali.rice.krad.util.GlobalVariables; 026 027 public class TKContext { 028 029 private static final String TDOC_OBJ_KEY = "_TDOC_O_KEY"; 030 private static final String TDOC_KEY = "_TDOC_ID_KEY"; // Timesheet Document ID Key 031 //private static final String USER_KEY = "_USER_KEY"; 032 033 private static final ThreadLocal<Map<String, Object>> STORAGE_MAP = new ThreadLocal<Map<String, Object>>() { 034 @Override 035 protected Map<String, Object> initialValue() { 036 return Collections.synchronizedMap(new HashMap<String, Object>()); 037 } 038 }; 039 040 public static TimesheetDocument getCurrentTimesheetDocument() { 041 return (TimesheetDocument)TKContext.getStorageMap().get(TDOC_OBJ_KEY); 042 } 043 044 public static void setCurrentTimesheetDocument(TimesheetDocument tdoc) { 045 TKContext.getStorageMap().put(TDOC_OBJ_KEY, tdoc); 046 } 047 048 /** 049 * @return The current timesheet document id, as set by the detail/clock 050 * pages. 051 */ 052 public static String getCurrentTimesheetDocumentId() { 053 return (String)TKContext.getStorageMap().get(TDOC_KEY); 054 } 055 056 /** 057 * Set the current timesheet document id. 058 * @param timesheetDocumentId The ID we are setting this value to. 059 */ 060 public static void setCurrentTimesheetDocumentId(String timesheetDocumentId) { 061 TKContext.getStorageMap().put(TDOC_KEY, timesheetDocumentId); 062 } 063 064 /** 065 * TKUser has the internal concept of Backdoor User vs.Actual User. 066 * @return 067 */ 068 public static TKUser getUser() { 069 //TODO, this method isn't needed if everything in TKUser is accessed in a static fashion... 070 return new TKUser(); 071 //return (TKUser) GlobalVariables.getUserSession().retrieveObject(USER_KEY); 072 } 073 074 //public static void setUser(TKUser user) { 075 // GlobalVariables.getUserSession().addObject(USER_KEY, user); 076 //} 077 078 public static String getPrincipalId(){ 079 return GlobalVariables.getUserSession().getPrincipalId(); 080 } 081 082 public static String getTargetPrincipalId() { 083 return TKUser.getCurrentTargetPerson().getPrincipalId(); 084 } 085 086 public static HttpServletRequest getHttpServletRequest() { 087 return (HttpServletRequest) getStorageMap().get("REQUEST"); 088 } 089 090 public static void setHttpServletRequest(HttpServletRequest request) { 091 getStorageMap().put("REQUEST", request); 092 } 093 094 public static Map<String, Object> getStorageMap() { 095 return STORAGE_MAP.get(); 096 } 097 098 public static void resetStorageMap() { 099 STORAGE_MAP.remove(); 100 } 101 102 public static void clear() { 103 resetStorageMap(); 104 } 105 }