001/* 002 * Copyright 2011 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 */ 016package org.kuali.ole.fp.document.authorization; 017 018import java.util.Set; 019 020import org.kuali.ole.fp.batch.ProcurementCardCreateDocumentsStep; 021import org.kuali.ole.sys.context.SpringContext; 022import org.kuali.ole.sys.document.authorization.FinancialSystemMaintenanceDocumentPresentationControllerBase; 023import org.kuali.rice.coreservice.framework.parameter.ParameterService; 024import org.kuali.rice.krad.bo.BusinessObject; 025 026/** 027 * Presentation controller for the ProcurementCardDefault Maintenance Document 028 */ 029public class ProcurementCardDefaultMaintenanceDocumentPresentationController extends FinancialSystemMaintenanceDocumentPresentationControllerBase { 030 protected static ParameterService parameterService; 031 032 protected final static String PROCUREMENT_CARD_DEFAULT_HOLDER_SECTION_ID = "KFS-FP_ProcurementCardDefault-EditProcurementCardHolder"; 033 protected final static String PROCUREMENT_CARD_DEFAULT_ACCOUNTING_SECTION_ID = "KFS-FP_ProcurementCardDefault-EditProcurementCardAccounting"; 034 035 /** 036 * Displays or hides the KFS-FP_ProcurementCardDefault-EditProcurementCardHolder and KFS-FP_ProcurementCardDefault-EditProcurementCardAccounting 037 * sections based on if parameters for use are turned on 038 * @see org.kuali.rice.kns.document.authorization.MaintenanceDocumentPresentationControllerBase#getConditionallyHiddenSectionIds(org.kuali.rice.kns.bo.BusinessObject) 039 */ 040 @Override 041 public Set<String> getConditionallyHiddenSectionIds(BusinessObject businessObject) { 042 Set<String> sectionIds = super.getConditionallyHiddenSectionIds(businessObject); 043 final boolean cardHolderDefaultTurnedOn = isCardHolderDefaultTurnedOn(); 044 if (!cardHolderDefaultTurnedOn) { 045 sectionIds.add(PROCUREMENT_CARD_DEFAULT_HOLDER_SECTION_ID); 046 } 047 if (!cardHolderDefaultTurnedOn && !isAccountDefaultTurnedOn()) { 048 sectionIds.add(PROCUREMENT_CARD_DEFAULT_ACCOUNTING_SECTION_ID); 049 } 050 return sectionIds; 051 } 052 053 /** 054 * @return true if use of card holder defaults is turned on via parameter, false if it is turned off 055 */ 056 protected boolean isCardHolderDefaultTurnedOn() { 057 return getParameterService().getParameterValueAsBoolean(ProcurementCardCreateDocumentsStep.class, ProcurementCardCreateDocumentsStep.USE_CARD_HOLDER_DEFAULT_PARAMETER_NAME); 058 } 059 060 /** 061 * @return true if use of accounting defaults is turned on via parameter, false if it is turned off 062 */ 063 protected boolean isAccountDefaultTurnedOn() { 064 return getParameterService().getParameterValueAsBoolean(ProcurementCardCreateDocumentsStep.class, ProcurementCardCreateDocumentsStep.USE_ACCOUNTING_DEFAULT_PARAMETER_NAME); 065 } 066 067 /** 068 * @return the default implementation of the ParameterService 069 */ 070 @Override 071 protected synchronized ParameterService getParameterService() { 072 if (parameterService == null) { 073 parameterService = SpringContext.getBean(ParameterService.class); 074 } 075 return parameterService; 076 } 077}