View Javadoc
1   /*
2    * The Kuali Financial System, a comprehensive financial management system for higher education.
3    * 
4    * Copyright 2005-2014 The Kuali Foundation
5    * 
6    * This program is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU Affero General Public License as
8    * published by the Free Software Foundation, either version 3 of the
9    * License, or (at your option) any later version.
10   * 
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU Affero General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Affero General Public License
17   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  package org.kuali.kfs.coa.document;
20  
21  import java.util.HashMap;
22  import java.util.List;
23  import java.util.Map;
24  
25  import org.kuali.kfs.coa.service.OrganizationService;
26  import org.kuali.kfs.sys.KFSPropertyConstants;
27  import org.kuali.kfs.sys.context.SpringContext;
28  import org.kuali.kfs.sys.document.FinancialSystemMaintainable;
29  import org.kuali.rice.kns.document.MaintenanceDocument;
30  import org.kuali.rice.kns.maintenance.Maintainable;
31  import org.kuali.rice.kns.web.ui.Field;
32  import org.kuali.rice.kns.web.ui.Row;
33  import org.kuali.rice.kns.web.ui.Section;
34  
35  /**
36   * This class overrides the getCoreSections method to provide specific field conversions for the postal code
37   */
38  public class KualiOrgMaintainable extends FinancialSystemMaintainable {
39      private static final long serialVersionUID = -3182120468758958991L;
40  
41      protected static final String KUALI_ORG_SECTION = "Edit Organization Code";
42  
43      /**
44       * Provides special field conversions for the Org.organizationZipCode
45       *
46       * @see org.kuali.rice.kns.maintenance.Maintainable#getCoreSections(org.kuali.rice.kns.maintenance.Maintainable)
47       *
48       * KRAD Conversion: Maintainable performs the logic to adds new fields to sections if
49       * organization zip code field exists in the core sections.
50       * The fields definitions are built here for the new section.  They are not in data dictionary.
51       */
52      @Override
53      public List getCoreSections(MaintenanceDocument document, Maintainable oldMaintainable) {
54  
55          boolean fieldFound = false;
56          boolean sectionFound = false;
57  
58          // walk the sections
59          List<Section> sections = super.getCoreSections(document, oldMaintainable);
60          for ( Section section : sections ) {
61              // if this is the section we're looking for
62              if (section.getSectionTitle().equalsIgnoreCase(KUALI_ORG_SECTION)) {
63                  // mark that we found the section
64                  sectionFound = true;
65                  // walk the rows
66                  List rows = section.getRows();
67                  for ( Row row : section.getRows() ) {
68                      // walk the fields
69                      for ( Field field : row.getFields() ) {
70                          // if this is the field we're looking for ...
71                          if (field.getPropertyName().equalsIgnoreCase(KFSPropertyConstants.ORGANIZATION_ZIP_CODE)) {
72                              // build the fieldConversions for the UserID field lookup
73                              Map<String,String> fieldConversions = new HashMap<String,String>(3);
74                              fieldConversions.put(KFSPropertyConstants.CODE, KFSPropertyConstants.ORGANIZATION_ZIP_CODE);
75                              fieldConversions.put(KFSPropertyConstants.POSTAL_STATE_CODE, KFSPropertyConstants.ORGANIZATION_STATE_CODE);
76                              fieldConversions.put(KFSPropertyConstants.POSTAL_CITY_NAME, KFSPropertyConstants.ORGANIZATION_CITY_NAME);
77  
78                              // add the fieldConversions, lookupParameters and the lookup class
79                              field.setFieldConversions(fieldConversions);
80                              // field.setLookupParameters(lookupParameters);
81                              // field.setQuickFinderClassNameImpl(Person.class.getName());
82  
83                              // mark that we've found the field
84                              fieldFound = true;
85                              break;
86                          }
87                      }
88                      // if we found the field, we don't need the rest of the rows
89                      if ( fieldFound ) {
90                          break;
91                      }
92                  }
93                  break; // we've found the section, no need to look further
94              }
95          }
96  
97          // if the section no longer exists, fail loudly
98          if (!sectionFound) {
99              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.");
100         }
101         // if the field was not found, fail loudly
102         if (!fieldFound) {
103             throw new RuntimeException("There is no longer a field titled '" + KFSPropertyConstants.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 KFSPropertyConstants class.");
104         }
105 
106         return sections;
107     }
108 
109     /**
110      * Override to purge the parent org cache when an organization is saved.
111      */
112     @Override
113     public void saveBusinessObject() {
114         super.saveBusinessObject();
115         SpringContext.getBean(OrganizationService.class).flushParentOrgCache();
116     }
117 }
118