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.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 } 072 073 //public static void setUser(TKUser user) { 074 // GlobalVariables.getUserSession().addObject(USER_KEY, user); 075 //} 076 077 public static String getPrincipalId(){ 078 return GlobalVariables.getUserSession().getPrincipalId(); 079 } 080 081 public static String getTargetPrincipalId() { 082 return TKUser.getCurrentTargetPerson().getPrincipalId(); 083 } 084 085 public static HttpServletRequest getHttpServletRequest() { 086 return (HttpServletRequest) getStorageMap().get("REQUEST"); 087 } 088 089 public static void setHttpServletRequest(HttpServletRequest request) { 090 getStorageMap().put("REQUEST", request); 091 } 092 093 public static Map<String, Object> getStorageMap() { 094 return STORAGE_MAP.get(); 095 } 096 097 public static void resetStorageMap() { 098 STORAGE_MAP.remove(); 099 } 100 101 public static void clear() { 102 resetStorageMap(); 103 } 104 }