View Javadoc
1   /*
2    * Copyright 2008 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.sys.document;
17  
18  import java.util.List;
19  
20  import org.apache.commons.lang.StringUtils;
21  import org.kuali.ole.sys.OLEConstants;
22  import org.kuali.ole.sys.businessobject.TaxRegion;
23  import org.kuali.rice.kns.document.MaintenanceDocument;
24  import org.kuali.rice.kns.maintenance.Maintainable;
25  import org.kuali.rice.kns.web.ui.Section;
26  
27  public class TaxRegionMaintainableImpl extends FinancialSystemMaintainable {
28  
29      
30      /**
31       * This method hides particular tax region sections based on tax region type code
32       * 
33       * @see org.kuali.rice.kns.maintenance.KualiMaintainableImpl#getCoreSections(org.kuali.rice.kns.maintenance.Maintainable)
34       * 
35       * KRAD Conversion: Maintainable customizes the hiding/showing of the sections
36       * No Use of data dictionary
37       */
38      @Override
39      public List<Section> getCoreSections(MaintenanceDocument document, Maintainable oldMaintainable) {
40          List<Section> sections = super.getCoreSections(document, oldMaintainable);
41  
42          TaxRegion taxRegion = (TaxRegion) getBusinessObject();
43  
44          //have to check if type code is empty, because on the oldMaintainable on a NEW action, none of the old Maintainable BO's values are set
45          if( StringUtils.isNotEmpty( taxRegion.getTaxRegionTypeCode() ) ) {
46              String sectionIdToDisplay = getSectionIdToDisplay(taxRegion.getTaxRegionTypeCode());
47              for (Section section : sections) {
48                  if (!isMainOrRateSection(section.getSectionId()) && !sectionIdToDisplay.equals(section.getSectionId())) {
49                      section.setHidden(true);
50                  }
51              }            
52          }
53          
54          return sections;
55      }
56  
57      /**
58       * This method returns the appropriate section ID that should NOT be hidden based on a specific tax region type code
59       * 
60       * @param taxRegionTypeCode
61       * @return
62       */
63      protected String getSectionIdToDisplay(String taxRegionTypeCode) {
64          if (OLEConstants.TaxRegionConstants.TAX_REGION_TYPE_CODE_STATE.equals(taxRegionTypeCode)) {
65              return OLEConstants.TaxRegionConstants.TAX_REGION_STATES_SECTION_ID;
66          }
67          else if (OLEConstants.TaxRegionConstants.TAX_REGION_TYPE_CODE_COUNTY.equals(taxRegionTypeCode)) {
68              return OLEConstants.TaxRegionConstants.TAX_REGION_COUNTIES_SECTION_ID;
69          }
70          else if (OLEConstants.TaxRegionConstants.TAX_REGION_TYPE_CODE_POSTAL_CODE.equals(taxRegionTypeCode)) {
71              return OLEConstants.TaxRegionConstants.TAX_REGION_POSTAL_CODES_SECTION_ID;
72          }
73          else {
74              throw new RuntimeException("No section is set up for tax region type code " + taxRegionTypeCode);
75          }
76      }
77  
78      /**
79       * This method returns true if section is main or tax region rate section
80       * 
81       * @param sectionId
82       * @return
83       */
84      protected boolean isMainOrRateSection(String sectionId) {
85          return OLEConstants.TaxRegionConstants.TAX_REGION_RATES_SECTION_ID.equals(sectionId) || OLEConstants.TaxRegionConstants.TAX_REGION_CREATE_SECTION_ID.equals(sectionId);
86      }
87  }