001: /*
002: * Copyright 2006-2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.module.chart.maintenance;
017:
018: import java.util.HashMap;
019: import java.util.Iterator;
020: import java.util.List;
021: import java.util.Map;
022:
023: import org.kuali.core.maintenance.KualiMaintainableImpl;
024: import org.kuali.core.maintenance.Maintainable;
025: import org.kuali.core.web.ui.Field;
026: import org.kuali.core.web.ui.Row;
027: import org.kuali.core.web.ui.Section;
028: import org.kuali.kfs.KFSPropertyConstants;
029:
030: /**
031: * This class overrides the getCoreSections method to provide specific field conversions for the postal code
032: */
033: public class KualiOrgMaintainable extends KualiMaintainableImpl {
034:
035: private static final long serialVersionUID = -3182120468758958991L;
036:
037: public static final String KUALI_ORG_SECTION = "Edit Organization Code";
038:
039: /**
040: * Provides special field conversions for the Org.organizationZipCode
041: *
042: * @see org.kuali.core.maintenance.Maintainable#getCoreSections(org.kuali.core.maintenance.Maintainable)
043: */
044: public List getCoreSections(Maintainable oldMaintainable) {
045:
046: boolean fieldFound = false;
047: boolean sectionFound = false;
048:
049: String orgPostalCodeFieldName = KFSPropertyConstants.ORGANIZATION_ZIP_CODE;
050:
051: // walk the sections
052: List sections = super .getCoreSections(oldMaintainable);
053: for (Iterator sectionIterator = sections.iterator(); sectionIterator
054: .hasNext();) {
055: Section section = (Section) sectionIterator.next();
056:
057: // if this is the section we're looking for
058: if (section.getSectionTitle().equalsIgnoreCase(
059: KUALI_ORG_SECTION)) {
060:
061: // mark that we found the section
062: sectionFound = true;
063:
064: // walk the rows
065: List rows = section.getRows();
066: for (Iterator rowIterator = rows.iterator(); rowIterator
067: .hasNext();) {
068: Row row = (Row) rowIterator.next();
069:
070: // walk the fields
071: List fields = row.getFields();
072: for (Iterator fieldIterator = fields.iterator(); fieldIterator
073: .hasNext();) {
074: Field field = (Field) fieldIterator.next();
075:
076: // if this is the field we're looking for ...
077: if (field.getPropertyName().equalsIgnoreCase(
078: orgPostalCodeFieldName)) {
079:
080: // mark that we've found the field
081: fieldFound = true;
082:
083: // build the fieldConversions for the UserID field lookup
084: Map fieldConversions = new HashMap();
085: fieldConversions
086: .put(
087: KFSPropertyConstants.POSTAL_ZIP_CODE,
088: KFSPropertyConstants.ORGANIZATION_ZIP_CODE);
089: fieldConversions
090: .put(
091: KFSPropertyConstants.POSTAL_STATE_CODE,
092: KFSPropertyConstants.ORGANIZATION_STATE_CODE);
093: fieldConversions
094: .put(
095: KFSPropertyConstants.POSTAL_CITY_NAME,
096: KFSPropertyConstants.ORGANIZATION_CITY_NAME);
097:
098: // add the fieldConversions, lookupParameters and the lookup class
099: field.setFieldConversions(fieldConversions);
100: // field.setLookupParameters(lookupParameters);
101: // field.setQuickFinderClassNameImpl(UniversalUser.class.getName());
102: }
103: }
104: }
105: }
106:
107: }
108:
109: // if the section no longer exists, fail loudly
110: if (!sectionFound) {
111: throw new RuntimeException(
112: "There is no longer a section titled '"
113: + KUALI_ORG_SECTION
114: + "'. "
115: + "As a result, the lookup setup will not work as expected and the maintenance document "
116: + "will be broken. The correct name needs to be set in the Constant in this class.");
117: }
118: // if the field was not found, fail loudly
119: else if (!fieldFound) {
120: throw new RuntimeException(
121: "There is no longer a field titled '"
122: + KFSPropertyConstants.ORGANIZATION_ZIP_CODE
123: + "'. "
124: + "As a result, the lookup setup will not work as expected and the maintenance document "
125: + "will be broken. The correct name needs to be set in the KFSPropertyConstants class.");
126: }
127:
128: return sections;
129: }
130:
131: }
|