1 /** 2 * Copyright 2005-2015 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.kns.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.core.api.mo.common.active.MutableInactivatable}, 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 * @deprecated Only used in KNS classes, use KRAD. 29 */ 30 @Deprecated 31 public final class InactiveRecordsHidingUtils { 32 33 private InactiveRecordsHidingUtils() { 34 throw new UnsupportedOperationException("do not call"); 35 } 36 37 /** 38 * 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 39 * this method will return false. 40 * 41 * @param inactiveRecordDisplay a Map used to keep state between invocations of this method and {@link #setShowInactiveRecords(Map, String, boolean)} 42 * @param collectionName the name of the collection 43 * @return 44 */ 45 public static boolean getShowInactiveRecords(Map<String, Boolean> inactiveRecordDisplay, String collectionName) { 46 // by default, show the actives 47 boolean showInactive = true; 48 49 if (collectionName == null) { 50 throw new IllegalArgumentException("collection name cannot be null"); 51 } 52 // remove periods from the collection name due to parsing limitation in Apache beanutils 53 collectionName = collectionName.replace( '.', '_' ); 54 55 if (inactiveRecordDisplay.containsKey(collectionName)) { 56 Object inactiveSetting = inactiveRecordDisplay.get(collectionName); 57 58 // warren: i copied this code from somewhere else, and have no idea why they're testing to see whether it's a 59 // Boolean, but I'm guessing that it has to do w/ the PojoFormBase not setting things correctly 60 if (inactiveSetting instanceof Boolean) { 61 showInactive = ((Boolean) inactiveSetting).booleanValue(); 62 } 63 else { 64 showInactive = Boolean.parseBoolean(((String[]) inactiveSetting)[0]); 65 } 66 } 67 68 return showInactive; 69 } 70 71 /** 72 * Sets whether a method should show inactive records 73 * 74 * @param inactiveRecordDisplay a Map used to keep state between invocations of this method and {@link #getShowInactiveRecords(Map, String)} 75 * @param collectionName the name of the collection 76 * @param showInactive whether to show inactive records 77 */ 78 public static void setShowInactiveRecords(Map<String, Boolean> inactiveRecordDisplay, String collectionName, boolean showInactive) { 79 if (collectionName == null) { 80 throw new IllegalArgumentException("collection name cannot be null"); 81 } 82 83 // remove periods from the collection name due to parsing limitation in Apache beanutils 84 collectionName = collectionName.replace( '.', '_' ); 85 86 inactiveRecordDisplay.put(collectionName, new Boolean(showInactive)); 87 } 88 89 public static String formatCollectionName(String collectionName) { 90 return collectionName.replace( '.', '_' ); 91 } 92 }