Coverage Report - org.kuali.rice.krad.util.GlobalVariables
 
Classes in this File Line Coverage Branch Coverage Complexity
GlobalVariables
0%
0/31
0%
0/2
1.143
GlobalVariables$1
0%
0/2
N/A
1.143
GlobalVariables$2
0%
0/2
N/A
1.143
GlobalVariables$3
0%
0/2
N/A
1.143
 
 1  
 /*
 2  
  * Copyright 2005-2007 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.rice.krad.util;
 17  
 
 18  
 import org.kuali.rice.krad.UserSession;
 19  
 
 20  
 import java.util.HashMap;
 21  
 import java.util.Map;
 22  
 
 23  
 /**
 24  
  * Holds all of our thread local variables and accessors for those
 25  
  *
 26  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 27  
  */
 28  0
 public class GlobalVariables {
 29  
 
 30  0
     private static ThreadLocal<UserSession> userSessions = new ThreadLocal<UserSession>();
 31  0
     private static ThreadLocal<String> hideSessionFromTestsMessage = new ThreadLocal<String>();
 32  
 
 33  0
     private static ThreadLocal<MessageMap> messageMaps = new ThreadLocal<MessageMap>()  {
 34  
                 @Override
 35  
                 protected MessageMap initialValue() {
 36  0
                         return new MessageMap();
 37  
                 }
 38  
         };
 39  
 
 40  0
     private static ThreadLocal<HashMap<String, AuditCluster>> auditErrorMaps = new ThreadLocal<HashMap<String, AuditCluster>>() {
 41  
             @Override
 42  
             protected HashMap<String, AuditCluster> initialValue() {
 43  0
                     return new HashMap<String, AuditCluster>();
 44  
             }
 45  
     };
 46  
     
 47  0
     private static ThreadLocal<Map<String,Object>> requestCaches = new ThreadLocal<Map<String,Object>>() {
 48  
             @Override
 49  
                 protected HashMap<String, Object> initialValue() {
 50  0
                     return new HashMap<String, Object>();
 51  
             }
 52  
     };
 53  
 
 54  
     /**
 55  
      * @return the UserSession that has been assigned to this thread of execution it is important that this not be called by
 56  
      *         anything that lives outside
 57  
      */
 58  
     public static UserSession getUserSession() {
 59  0
         String message = hideSessionFromTestsMessage.get();
 60  0
         if (message != null) {
 61  0
             throw new RuntimeException(message);
 62  
         }
 63  0
         return userSessions.get();
 64  
     }
 65  
 
 66  
     /**
 67  
      * Sets an error message for tests that try to use the session without declaring it.
 68  
      * This method should be use by only KualiTestBase, not by other test code and especially not by production code.
 69  
      *
 70  
      * @param message the detail to throw, or null to allow access to the session
 71  
      */
 72  
     public static void setHideSessionFromTestsMessage(String message) {
 73  0
         hideSessionFromTestsMessage.set(message);
 74  0
     }
 75  
 
 76  
     /**
 77  
      * sets the userSession object into the global variable for this thread
 78  
      *
 79  
      * @param userSession
 80  
      */
 81  
     public static void setUserSession(UserSession userSession) {
 82  0
         userSessions.set(userSession);
 83  0
     }
 84  
     
 85  
     public static MessageMap getMessageMap() {
 86  0
             return messageMaps.get();
 87  
     }
 88  
 
 89  
     /**
 90  
      * Merges a message map into the global variables error map
 91  
      * @param messageMap
 92  
      */
 93  
     public static void mergeErrorMap(MessageMap messageMap) {
 94  0
         getMessageMap().getErrorMessages().putAll(messageMap.getErrorMessages());
 95  0
         getMessageMap().getWarningMessages().putAll(messageMap.getWarningMessages());
 96  0
         getMessageMap().getInfoMessages().putAll(messageMap.getInfoMessages());
 97  0
     }
 98  
     
 99  
     /**
 100  
      * Sets a new (clean) MessageMap
 101  
      *
 102  
      * @param messageMap
 103  
      */
 104  
     public static void setMessageMap(MessageMap messageMap) {
 105  0
             messageMaps.set(messageMap);
 106  0
     }
 107  
 
 108  
     /**
 109  
      * @return ArrayList containing audit error messages.
 110  
      */
 111  
     public static Map<String, AuditCluster> getAuditErrorMap() {
 112  0
         return auditErrorMaps.get();
 113  
     }
 114  
 
 115  
     /**
 116  
      * Sets a new (clean) AuditErrorList
 117  
      *
 118  
      * @param errorMap
 119  
      */
 120  
     public static void setAuditErrorMap(HashMap<String, AuditCluster> errorMap) {
 121  0
         auditErrorMaps.set(errorMap);
 122  0
     }
 123  
 
 124  
     public static Object getRequestCache( String cacheName ) {
 125  0
             return requestCaches.get().get(cacheName);
 126  
     }
 127  
 
 128  
     public static void setRequestCache( String cacheName, Object cacheObject ) {
 129  0
             requestCaches.get().put(cacheName, cacheObject);
 130  0
     }
 131  
 
 132  
     /**
 133  
      * Clears out GlobalVariable objects with the exception of the UserSession
 134  
      */
 135  
     public static void clear() {
 136  0
         messageMaps.set(new MessageMap());
 137  0
         auditErrorMaps.set(new HashMap<String, AuditCluster>());
 138  0
         requestCaches.set(new HashMap<String,Object>() );
 139  0
     }
 140  
 }