Coverage Report - org.kuali.rice.krad.util.InactiveRecordsHidingUtils
 
Classes in this File Line Coverage Branch Coverage Complexity
InactiveRecordsHidingUtils
0%
0/18
0%
0/8
2.75
 
 1  
 /*
 2  
  * Copyright 2007-2008 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 java.util.Map;
 19  
 
 20  
 /**
 21  
  * Inquiry screens and maintenance documents may render a collection of BOs on a screen.  These
 22  
  * BOs may implement {@link org.kuali.rice.krad.bo.Inactivatable}, which means that the BO has an active
 23  
  * flag of true or false.  Some screens may give the user the ability to not render (i.e. hide) inactive
 24  
  * collection elements.  This class has several utilities to control that behavior. 
 25  
  * 
 26  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 27  
  */
 28  
 public final class InactiveRecordsHidingUtils {
 29  
         
 30  0
         private InactiveRecordsHidingUtils() {
 31  0
                 throw new UnsupportedOperationException("do not call");
 32  
         }
 33  
         
 34  
     /**
 35  
      * Returns whether a collection has been set to show inactive records.  Note that if a collection has not been set to show inactive inactive records, then
 36  
      * this method will return false.
 37  
      * 
 38  
      * @param inactiveRecordDisplay a Map used to keep state between invocations of this method and {@link #setShowInactiveRecords(Map, String, boolean)}
 39  
      * @param collectionName the name of the collection 
 40  
      * @return
 41  
      */
 42  
     public static boolean getShowInactiveRecords(Map<String, Boolean> inactiveRecordDisplay, String collectionName) {
 43  
         // by default, show the actives
 44  0
         boolean showInactive = true;
 45  
         
 46  0
         if (collectionName == null) {
 47  0
             throw new IllegalArgumentException("collection name cannot be null");
 48  
         }
 49  
         // remove periods from the collection name due to parsing limitation in Apache beanutils 
 50  0
         collectionName = collectionName.replace( '.', '_' );
 51  
         
 52  0
         if (inactiveRecordDisplay.containsKey(collectionName)) {
 53  0
             Object inactiveSetting = inactiveRecordDisplay.get(collectionName);
 54  
             
 55  
             // warren: i copied this code from somewhere else, and have no idea why they're testing to see whether it's a
 56  
             // Boolean, but I'm guessing that it has to do w/ the PojoFormBase not setting things correctly
 57  0
             if (inactiveSetting instanceof Boolean) {
 58  0
                 showInactive = ((Boolean) inactiveSetting).booleanValue();
 59  
             }
 60  
             else {
 61  0
                 showInactive = Boolean.parseBoolean(((String[]) inactiveSetting)[0]);
 62  
             }
 63  
         }
 64  
         
 65  0
         return showInactive;
 66  
     }
 67  
     
 68  
     /**
 69  
      * Sets whether a method should show inactive records
 70  
      * 
 71  
      * @param inactiveRecordDisplay a Map used to keep state between invocations of this method and {@link #getShowInactiveRecords(Map, String)}
 72  
      * @param collectionName the name of the collection
 73  
      * @param showInactive whether to show inactive records
 74  
      */
 75  
     public static void setShowInactiveRecords(Map<String, Boolean> inactiveRecordDisplay, String collectionName, boolean showInactive) {
 76  0
         if (collectionName == null) {
 77  0
             throw new IllegalArgumentException("collection name cannot be null");
 78  
         }
 79  
         
 80  
         // remove periods from the collection name due to parsing limitation in Apache beanutils 
 81  0
         collectionName = collectionName.replace( '.', '_' );
 82  
 
 83  0
         inactiveRecordDisplay.put(collectionName, new Boolean(showInactive));
 84  0
     }
 85  
     
 86  
     public static String formatCollectionName(String collectionName) {
 87  0
         return collectionName.replace( '.', '_' );
 88  
     }
 89  
 }