View Javadoc

1   /*
2    * Copyright 2011 The Kuali Foundation.
3    *
4    * Licensed under the Educational Community License, Version 1.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/ecl1.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.fp.document.authorization;
17  
18  import java.util.Set;
19  
20  import org.kuali.ole.fp.batch.ProcurementCardCreateDocumentsStep;
21  import org.kuali.ole.sys.context.SpringContext;
22  import org.kuali.ole.sys.document.authorization.FinancialSystemMaintenanceDocumentPresentationControllerBase;
23  import org.kuali.rice.coreservice.framework.parameter.ParameterService;
24  import org.kuali.rice.krad.bo.BusinessObject;
25  
26  /**
27   * Presentation controller for the ProcurementCardDefault Maintenance Document
28   */
29  public class ProcurementCardDefaultMaintenanceDocumentPresentationController extends FinancialSystemMaintenanceDocumentPresentationControllerBase {
30      protected static ParameterService parameterService;
31  
32      protected final static String PROCUREMENT_CARD_DEFAULT_HOLDER_SECTION_ID = "KFS-FP_ProcurementCardDefault-EditProcurementCardHolder";
33      protected final static String PROCUREMENT_CARD_DEFAULT_ACCOUNTING_SECTION_ID = "KFS-FP_ProcurementCardDefault-EditProcurementCardAccounting";
34  
35      /**
36       * Displays or hides the KFS-FP_ProcurementCardDefault-EditProcurementCardHolder and KFS-FP_ProcurementCardDefault-EditProcurementCardAccounting
37       * sections based on if parameters for use are turned on
38       * @see org.kuali.rice.kns.document.authorization.MaintenanceDocumentPresentationControllerBase#getConditionallyHiddenSectionIds(org.kuali.rice.kns.bo.BusinessObject)
39       */
40      @Override
41      public Set<String> getConditionallyHiddenSectionIds(BusinessObject businessObject) {
42          Set<String> sectionIds = super.getConditionallyHiddenSectionIds(businessObject);
43          final boolean cardHolderDefaultTurnedOn = isCardHolderDefaultTurnedOn();
44          if (!cardHolderDefaultTurnedOn) {
45              sectionIds.add(PROCUREMENT_CARD_DEFAULT_HOLDER_SECTION_ID);
46          }
47          if (!cardHolderDefaultTurnedOn && !isAccountDefaultTurnedOn()) {
48              sectionIds.add(PROCUREMENT_CARD_DEFAULT_ACCOUNTING_SECTION_ID);
49          }
50          return sectionIds;
51      }
52  
53      /**
54       * @return true if use of card holder defaults is turned on via parameter, false if it is turned off
55       */
56      protected boolean isCardHolderDefaultTurnedOn() {
57          return getParameterService().getParameterValueAsBoolean(ProcurementCardCreateDocumentsStep.class, ProcurementCardCreateDocumentsStep.USE_CARD_HOLDER_DEFAULT_PARAMETER_NAME);
58      }
59  
60      /**
61       * @return true if use of accounting defaults is turned on via parameter, false if it is turned off
62       */
63      protected boolean isAccountDefaultTurnedOn() {
64          return getParameterService().getParameterValueAsBoolean(ProcurementCardCreateDocumentsStep.class, ProcurementCardCreateDocumentsStep.USE_ACCOUNTING_DEFAULT_PARAMETER_NAME);
65      }
66  
67      /**
68       * @return the default implementation of the ParameterService
69       */
70      @Override
71      protected synchronized ParameterService getParameterService() {
72          if (parameterService == null) {
73              parameterService = SpringContext.getBean(ParameterService.class);
74          }
75          return parameterService;
76      }
77  }