Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
MaintenanceActiveCollectionFilter |
|
| 3.0;3 |
1 | /** | |
2 | * Copyright 2005-2011 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.uif.container; | |
17 | ||
18 | import org.apache.commons.lang.StringUtils; | |
19 | import org.kuali.rice.core.api.mo.common.active.Inactivatable; | |
20 | import org.kuali.rice.krad.uif.view.View; | |
21 | import org.kuali.rice.krad.uif.util.ObjectPropertyUtils; | |
22 | ||
23 | import java.util.ArrayList; | |
24 | import java.util.List; | |
25 | ||
26 | /** | |
27 | * Collection filter for maintenance groups that removes inactive lines if certain | |
28 | * conditions are met | |
29 | * | |
30 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
31 | */ | |
32 | 0 | public class MaintenanceActiveCollectionFilter implements CollectionFilter { |
33 | private static final long serialVersionUID = -6045332235106531456L; | |
34 | ||
35 | private String oldBindingObjectPath; | |
36 | ||
37 | /** | |
38 | * Iterates through the collection and if the collection line type implements <code>Inactivatable</code> | |
39 | * active indexes are added to the show indexes list | |
40 | * | |
41 | * <p> | |
42 | * In the case of a new line being added, the user is not allowed to hide the record (even if it is inactive). | |
43 | * Likewise in the case of an edit where the active flag has changed between the old and new side, the user | |
44 | * is not allowed to hide | |
45 | * </p> | |
46 | * | |
47 | * @see CollectionFilter#filter(org.kuali.rice.krad.uif.view.View, Object, org.kuali.rice.krad.uif.container.CollectionGroup) | |
48 | */ | |
49 | @Override | |
50 | public List<Integer> filter(View view, Object model, CollectionGroup collectionGroup) { | |
51 | ||
52 | // get the collection for this group from the model | |
53 | 0 | List<Object> newCollection = |
54 | ObjectPropertyUtils.getPropertyValue(model, collectionGroup.getBindingInfo().getBindingPath()); | |
55 | ||
56 | // Get collection from old data object | |
57 | 0 | List<Object> oldCollection = null; |
58 | 0 | String oldCollectionBindingPath = null; |
59 | 0 | oldCollectionBindingPath = StringUtils.replaceOnce(collectionGroup.getBindingInfo().getBindingPath(), |
60 | collectionGroup.getBindingInfo().getBindingObjectPath(), oldBindingObjectPath); | |
61 | 0 | oldCollection = ObjectPropertyUtils.getPropertyValue(model, oldCollectionBindingPath); |
62 | ||
63 | // iterate through and add only active indexes | |
64 | 0 | List<Integer> showIndexes = new ArrayList<Integer>(); |
65 | 0 | for (int i = 0; i < newCollection.size(); i++) { |
66 | 0 | Object line = newCollection.get(i); |
67 | 0 | if (line instanceof Inactivatable) { |
68 | 0 | boolean active = ((Inactivatable) line).isActive(); |
69 | 0 | if ((oldCollection != null) && (oldCollection.size() > i)) { |
70 | // if active status has changed, show record | |
71 | 0 | Inactivatable oldLine = (Inactivatable) oldCollection.get(i); |
72 | 0 | if (oldLine.isActive()) { |
73 | 0 | showIndexes.add(i); |
74 | } | |
75 | 0 | } else { |
76 | // TODO: if newly added line, show record | |
77 | // If only new and no old add the newline | |
78 | 0 | if (active) { |
79 | 0 | showIndexes.add(i); |
80 | } | |
81 | } | |
82 | } | |
83 | } | |
84 | ||
85 | 0 | return showIndexes; |
86 | } | |
87 | ||
88 | /** | |
89 | * Gives the binding path to the old data object for comparison, used to | |
90 | * get the active status of the old object | |
91 | * | |
92 | * @return String binding path | |
93 | */ | |
94 | public String getOldBindingObjectPath() { | |
95 | 0 | return oldBindingObjectPath; |
96 | } | |
97 | ||
98 | /** | |
99 | * Setter for the path to the old data object | |
100 | * | |
101 | * @param oldBindingObjectPath | |
102 | */ | |
103 | public void setOldBindingObjectPath(String oldBindingObjectPath) { | |
104 | 0 | this.oldBindingObjectPath = oldBindingObjectPath; |
105 | 0 | } |
106 | } |