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.module.cg.document;
20  
21  import java.util.ArrayList;
22  import java.util.Collection;
23  import java.util.Iterator;
24  import java.util.List;
25  import java.util.Set;
26  
27  import org.kuali.kfs.sys.document.FinancialSystemMaintainable;
28  import org.kuali.rice.kns.datadictionary.MaintainableFieldDefinition;
29  import org.kuali.rice.kns.datadictionary.MaintainableItemDefinition;
30  import org.kuali.rice.kns.datadictionary.MaintainableSectionDefinition;
31  import org.kuali.rice.kns.document.MaintenanceDocument;
32  import org.kuali.rice.kns.document.authorization.MaintenanceDocumentPresentationController;
33  import org.kuali.rice.kns.document.authorization.MaintenanceDocumentRestrictions;
34  import org.kuali.rice.kns.maintenance.Maintainable;
35  import org.kuali.rice.kns.service.KNSServiceLocator;
36  import org.kuali.rice.kns.web.ui.Section;
37  import org.kuali.rice.kns.web.ui.SectionBridge;
38  import org.kuali.rice.krad.util.GlobalVariables;
39  
40  /**
41   * Abstract class that overrides getCoreSections to ignore CGB-specific sections if CGB is disabled.
42   */
43  public abstract class ContractsGrantsBillingMaintainable extends FinancialSystemMaintainable {
44  
45      protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ContractsGrantsBillingMaintainable.class);
46  
47      /**
48       * Essentially a copy of the overridden method with the addition of a call to getSectionIdsToIgnore, which is currently
49       * used to avoid processing / returning sections that are specific to the Contracts & Grants Billing (CGB) enhancement
50       * if CGB is not enabled.
51       *
52       * @see org.kuali.rice.kns.maintenance.KualiMaintainableImpl#getCoreSections(org.kuali.rice.kns.document.MaintenanceDocument, org.kuali.rice.kns.maintenance.Maintainable)
53       */
54      @Override
55      public List<Section> getCoreSections(MaintenanceDocument document, Maintainable oldMaintainable) {
56          List<Section> sections = new ArrayList<Section>();
57          MaintenanceDocumentRestrictions maintenanceRestrictions = KNSServiceLocator
58                  .getBusinessObjectAuthorizationService().getMaintenanceDocumentRestrictions(document,
59                          GlobalVariables.getUserSession().getPerson());
60  
61          MaintenanceDocumentPresentationController maintenanceDocumentPresentationController = (MaintenanceDocumentPresentationController) getDocumentHelperService()
62                  .getDocumentPresentationController(document);
63          Set<String> conditionallyRequiredFields = maintenanceDocumentPresentationController
64                  .getConditionallyRequiredPropertyNames(document);
65  
66          List<MaintainableSectionDefinition> sectionDefinitions = getMaintenanceDocumentDictionaryService()
67                  .getMaintainableSections(getDocumentTypeName());
68          try {
69              Collection<?> sectionIdsToIgnore = getSectionIdsToIgnore();
70  
71              // iterate through section definitions and create Section UI object
72              for (Iterator iter = sectionDefinitions.iterator(); iter.hasNext();) {
73                  MaintainableSectionDefinition maintSectionDef = (MaintainableSectionDefinition) iter.next();
74  
75                  List<String> displayedFieldNames = new ArrayList<String>();
76                  if (!maintenanceRestrictions.isHiddenSectionId(maintSectionDef.getId()) && !sectionIdsToIgnore.contains(maintSectionDef.getId())) {
77  
78                      for (Iterator iter2 = maintSectionDef.getMaintainableItems().iterator(); iter2.hasNext();) {
79                          MaintainableItemDefinition item = (MaintainableItemDefinition) iter2.next();
80                          if (item instanceof MaintainableFieldDefinition) {
81                              displayedFieldNames.add(((MaintainableFieldDefinition) item).getName());
82                          }
83                      }
84  
85                      Section section = SectionBridge
86                              .toSection(maintSectionDef, getBusinessObject(), this, oldMaintainable,
87                                      getMaintenanceAction(), displayedFieldNames, conditionallyRequiredFields);
88                      if (maintenanceRestrictions.isReadOnlySectionId(maintSectionDef.getId())) {
89                          section.setReadOnly(true);
90                      }
91  
92                      // add to section list
93                      sections.add(section);
94                  }
95  
96              }
97  
98          }
99          catch (InstantiationException | IllegalAccessException e) {
100             LOG.error("Unable to create instance of object class" + e.getMessage());
101             throw new RuntimeException("Unable to create instance of object class" + e.getMessage());
102         }
103 
104         return sections;
105     }
106 
107     /**
108      * If the Contracts & Grants Billing (CGB) enhancement is disabled, we don't want to
109      * process sections only related to CGB.
110      *
111      * @return Collection of section ids to ignore
112      */
113     protected abstract Collection<?> getSectionIdsToIgnore();
114 
115 }