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