1 /*
2 * Copyright 2006 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.document;
17
18 import java.util.HashMap;
19 import java.util.List;
20 import java.util.Map;
21
22 import org.kuali.ole.coa.service.OrganizationService;
23 import org.kuali.ole.sys.OLEPropertyConstants;
24 import org.kuali.ole.sys.context.SpringContext;
25 import org.kuali.ole.sys.document.FinancialSystemMaintainable;
26 import org.kuali.rice.kns.document.MaintenanceDocument;
27 import org.kuali.rice.kns.maintenance.Maintainable;
28 import org.kuali.rice.kns.web.ui.Field;
29 import org.kuali.rice.kns.web.ui.Row;
30 import org.kuali.rice.kns.web.ui.Section;
31
32 /**
33 * This class overrides the getCoreSections method to provide specific field conversions for the postal code
34 */
35 public class KualiOrgMaintainable extends FinancialSystemMaintainable {
36 private static final long serialVersionUID = -3182120468758958991L;
37
38 protected static final String KUALI_ORG_SECTION = "Edit Organization Code";
39
40 /**
41 * Provides special field conversions for the Org.organizationZipCode
42 *
43 * @see org.kuali.rice.kns.maintenance.Maintainable#getCoreSections(org.kuali.rice.kns.maintenance.Maintainable)
44 *
45 * KRAD Conversion: Maintainable performs the logic to adds new fields to sections if
46 * organization zip code field exists in the core sections.
47 * The fields definitions are built here for the new section. They are not in data dictionary.
48 */
49 @Override
50 public List getCoreSections(MaintenanceDocument document, Maintainable oldMaintainable) {
51
52 boolean fieldFound = false;
53 boolean sectionFound = false;
54
55 // walk the sections
56 List<Section> sections = super.getCoreSections(document, oldMaintainable);
57 for ( Section section : sections ) {
58 // if this is the section we're looking for
59 if (section.getSectionTitle().equalsIgnoreCase(KUALI_ORG_SECTION)) {
60 // mark that we found the section
61 sectionFound = true;
62 // walk the rows
63 List rows = section.getRows();
64 for ( Row row : section.getRows() ) {
65 // walk the fields
66 for ( Field field : row.getFields() ) {
67 // if this is the field we're looking for ...
68 if (field.getPropertyName().equalsIgnoreCase(OLEPropertyConstants.ORGANIZATION_ZIP_CODE)) {
69 // build the fieldConversions for the UserID field lookup
70 Map<String,String> fieldConversions = new HashMap<String,String>(3);
71 fieldConversions.put(OLEPropertyConstants.CODE, OLEPropertyConstants.ORGANIZATION_ZIP_CODE);
72 fieldConversions.put(OLEPropertyConstants.POSTAL_STATE_CODE, OLEPropertyConstants.ORGANIZATION_STATE_CODE);
73 fieldConversions.put(OLEPropertyConstants.POSTAL_CITY_NAME, OLEPropertyConstants.ORGANIZATION_CITY_NAME);
74
75 // add the fieldConversions, lookupParameters and the lookup class
76 field.setFieldConversions(fieldConversions);
77 // field.setLookupParameters(lookupParameters);
78 // field.setQuickFinderClassNameImpl(Person.class.getName());
79
80 // mark that we've found the field
81 fieldFound = true;
82 break;
83 }
84 }
85 // if we found the field, we don't need the rest of the rows
86 if ( fieldFound ) {
87 break;
88 }
89 }
90 break; // we've found the section, no need to look further
91 }
92 }
93
94 // if the section no longer exists, fail loudly
95 if (!sectionFound) {
96 throw new RuntimeException("There is no longer a section titled '" + KUALI_ORG_SECTION + "'. " + "As a result, the lookup setup will not work as expected and the maintenance document will be broken. The correct name needs to be set in the Constant in this class.");
97 }
98 // if the field was not found, fail loudly
99 if (!fieldFound) {
100 throw new RuntimeException("There is no longer a field titled '" + OLEPropertyConstants.ORGANIZATION_ZIP_CODE + "'. " + "As a result, the lookup setup will not work as expected and the maintenance document will be broken. The correct name needs to be set in the OLEPropertyConstants class.");
101 }
102
103 return sections;
104 }
105
106 /**
107 * Override to purge the parent org cache when an organization is saved.
108 */
109 @Override
110 public void saveBusinessObject() {
111 super.saveBusinessObject();
112 SpringContext.getBean(OrganizationService.class).flushParentOrgCache();
113 }
114 }
115