1 /*
2 * Copyright 2009 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.ole.coa.businessobject.inquiry;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21 import org.kuali.ole.coa.service.OrganizationReversionService;
22 import org.kuali.ole.sys.businessobject.inquiry.KfsInquirableImpl;
23 import org.kuali.ole.sys.context.SpringContext;
24 import org.kuali.rice.kns.web.ui.Field;
25 import org.kuali.rice.kns.web.ui.Row;
26 import org.kuali.rice.kns.web.ui.Section;
27 import org.kuali.rice.krad.bo.BusinessObject;
28
29 public class OrganizationReversionInquirable extends KfsInquirableImpl {
30 private OrganizationReversionService organizationReversionService;
31
32 /**
33 * Overridden to take out details with inactive categories
34 * @see org.kuali.rice.kns.inquiry.KualiInquirableImpl#getSections(org.kuali.rice.krad.bo.BusinessObject)
35 *
36 * KRAD Conversion: Inquirable performs conditional display/hiding of the fields/sections on the inquiry
37 * But all field/section definitions are in data dictionary for bo Organization.
38 */
39 @Override
40 public List<Section> getSections(BusinessObject bo) {
41 List<Section> sections = super.getSections(bo);
42 if (organizationReversionService == null) {
43 organizationReversionService = SpringContext.getBean(OrganizationReversionService.class);
44 }
45 for (Section section : sections) {
46 for (Row row : section.getRows()) {
47 List<Field> updatedFields = new ArrayList<Field>();
48 for (Field field : row.getFields()) {
49 if (shouldIncludeField(field)) {
50 updatedFields.add(field);
51 }
52 }
53 row.setFields(updatedFields);
54 }
55 }
56 return sections;
57 }
58
59 /**
60 * Determines if the given field should be included in the updated row, once we take out inactive categories
61 * @param field the field to check
62 * @return true if the field should be included (ie, it doesn't describe an organization reversion with an inactive category); false otherwise
63 *
64 * KRAD Conversion: Determines if fields should be included in the section.
65 * But all field/section definitions are in data dictionary.
66 */
67 protected boolean shouldIncludeField(Field field) {
68 boolean includeField = true;
69 if (field.getContainerRows() != null) {
70 for (Row containerRow : field.getContainerRows()) {
71 for (Field containedField : containerRow.getFields()) {
72 if (containedField.getPropertyName().matches("organizationReversionDetail\\[\\d+\\]\\.organizationReversionCategoryCode")) {
73 final String categoryValue = containedField.getPropertyValue();
74 includeField = organizationReversionService.isCategoryActive(categoryValue);
75 }
76 }
77 }
78 }
79 return includeField;
80 }
81 }