001    /*
002     * Copyright 2011 The Kuali Foundation.
003     * 
004     * Licensed under the Educational Community License, Version 2.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/ecl2.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.kfs.module.bc.document.service.impl;
017    
018    import java.util.List;
019    
020    import org.kuali.kfs.module.bc.BCParameterKeyConstants;
021    import org.kuali.kfs.module.bc.BCConstants.AccountSalarySettingOnlyCause;
022    import org.kuali.kfs.module.bc.document.BudgetConstructionDocument;
023    import org.kuali.kfs.module.bc.document.service.BudgetParameterService;
024    import org.kuali.kfs.module.bc.util.BudgetParameterFinder;
025    import org.kuali.rice.kns.service.ParameterService;
026    
027    /**
028     * See BudgetParameterService. This implements value added methods associated with ParameterService that are specific to the budget
029     * module.
030     */
031    public class BudgetParameterServiceImpl implements BudgetParameterService {
032        private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(BudgetParameterService.class);
033    
034        private ParameterService parameterService;
035    
036        /**
037         * @see org.kuali.kfs.module.bc.document.service.BudgetParameterService#getParameterValues(java.lang.Class, java.lang.String)
038         */
039        public List getParameterValues(Class componentClass, String parameterName) {
040            List paramValues = null;
041    
042            if (parameterService.parameterExists(componentClass, parameterName)) {
043                paramValues = parameterService.getParameterValues(componentClass, parameterName);
044            }
045            else {
046                LOG.info("Can't find system parameter " + parameterName);
047            }
048            return paramValues;
049        }
050    
051        /**
052         * @see org.kuali.kfs.module.bc.document.service.BudgetParameterService#isSalarySettingOnlyAccount(org.kuali.kfs.module.bc.document.BudgetConstructionDocument)
053         */
054        public AccountSalarySettingOnlyCause isSalarySettingOnlyAccount(BudgetConstructionDocument bcDoc) {
055            AccountSalarySettingOnlyCause retVal = AccountSalarySettingOnlyCause.MISSING_PARAM;
056            
057            List<String> salarySettingFundGroupsParamValues = BudgetParameterFinder.getSalarySettingFundGroups();
058            List<String> salarySettingSubFundGroupsParamValues = BudgetParameterFinder.getSalarySettingSubFundGroups();
059    
060            if (salarySettingFundGroupsParamValues != null && salarySettingSubFundGroupsParamValues != null) {
061                retVal = AccountSalarySettingOnlyCause.NONE;
062    
063                // is the account in a salary setting only fund group or sub-fund group, if neither calc benefits
064                String fundGroup = bcDoc.getAccount().getSubFundGroup().getFundGroupCode();
065                String subfundGroup = bcDoc.getAccount().getSubFundGroup().getSubFundGroupCode();
066                if (salarySettingFundGroupsParamValues.contains(fundGroup) && salarySettingSubFundGroupsParamValues.contains(subfundGroup)) {
067                    retVal = AccountSalarySettingOnlyCause.FUND_AND_SUBFUND;
068                }
069                else {
070                    if (salarySettingFundGroupsParamValues.contains(fundGroup)) {
071                        retVal = AccountSalarySettingOnlyCause.FUND;
072                    }
073                    if (salarySettingSubFundGroupsParamValues.contains(subfundGroup)) {
074                        retVal = AccountSalarySettingOnlyCause.SUBFUND;
075                    }
076                }
077            }
078    
079            return retVal;
080        }
081    
082        /**
083         * @see org.kuali.kfs.module.bc.document.service.BudgetParameterService#getLookupObjectTypes(boolean)
084         * this implementation returns a string where the values are separated by the OR symbol. 
085         */
086        public String getLookupObjectTypes(boolean isRevenue) {
087    
088            List<String> objectTypes;
089            if (isRevenue) {
090                objectTypes = BudgetParameterFinder.getRevenueObjectTypes();
091            }
092            else {
093                objectTypes = BudgetParameterFinder.getExpenditureObjectTypes();
094            }
095            StringBuffer lookupBuilder = new StringBuffer(150);
096    
097            if (objectTypes.isEmpty()) {
098                // for an empty list, return an empty string
099                return new String("");
100            }
101            else {
102                lookupBuilder.append(objectTypes.get(0));
103                for (int idx = 1; idx < objectTypes.size(); idx++) {
104                    lookupBuilder.append("|");
105                    lookupBuilder.append(objectTypes.get(idx));
106                }
107            }
108            return lookupBuilder.toString();
109        }
110    
111        /**
112         * Sets the parameterService attribute value.
113         * 
114         * @param parameterService The parameterService to set.
115         */
116        public void setParameterService(ParameterService parameterService) {
117            this.parameterService = parameterService;
118        }
119    }