001/*
002 * Copyright 2006 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 */
016package org.kuali.ole.coa.service.impl;
017
018import java.util.Collection;
019
020import org.kuali.ole.coa.businessobject.Account;
021import org.kuali.ole.coa.businessobject.FundGroup;
022import org.kuali.ole.coa.businessobject.SubFundGroup;
023import org.kuali.ole.coa.dataaccess.SubFundGroupDao;
024import org.kuali.ole.coa.service.SubFundGroupService;
025import org.kuali.ole.sys.OLEConstants;
026import org.kuali.ole.sys.context.SpringContext;
027import org.kuali.rice.core.api.parameter.ParameterEvaluatorService;
028import org.kuali.rice.coreservice.framework.parameter.ParameterService;
029import org.kuali.rice.kns.service.DataDictionaryService;
030import org.kuali.rice.krad.service.BusinessObjectService;
031import org.kuali.rice.krad.util.ObjectUtils;
032
033/**
034 * This service implementation is the default implementation of the SubFundGroup service that is delivered with Kuali.
035 */
036public class SubFundGroupServiceImpl implements SubFundGroupService {
037    private ParameterService parameterService;
038    private DataDictionaryService dataDictionaryService;
039    private SubFundGroupDao subFundGroupDao;
040
041    /**
042     * @see org.kuali.ole.coa.service.SubFundGroupService#isForContractsAndGrants(org.kuali.ole.coa.businessobject.SubFundGroup)
043     */
044    public boolean isForContractsAndGrants(SubFundGroup subFundGroup) {
045        if (ObjectUtils.isNull(subFundGroup)) {
046            return false;
047        }
048        else if (fundGroupDenotesContractsAndGrants()) {
049            return /*REFACTORME*/SpringContext.getBean(ParameterEvaluatorService.class).getParameterEvaluator(Account.class, OLEConstants.ChartApcParms.ACCOUNT_CG_DENOTING_VALUE, subFundGroup.getFundGroupCode()).evaluationSucceeds();
050    //      return getContractsAndGrantsDenotingValue(subFundGroup.getFundGroupCode());
051        }
052        else {
053            return /*REFACTORME*/SpringContext.getBean(ParameterEvaluatorService.class).getParameterEvaluator(Account.class, OLEConstants.ChartApcParms.ACCOUNT_CG_DENOTING_VALUE, subFundGroup.getSubFundGroupCode()).evaluationSucceeds();
054
055           //return getContractsAndGrantsDenotingValue(subFundGroup.getSubFundGroupCode());
056        }
057    }
058
059    /**
060     * @see org.kuali.ole.coa.service.SubFundGroupService#getContractsAndGrantsDenotingAttributeLabel()
061     */
062    public String getContractsAndGrantsDenotingAttributeLabel() {
063        if (fundGroupDenotesContractsAndGrants()) {
064            return dataDictionaryService.getAttributeLabel(FundGroup.class, OLEConstants.FUND_GROUP_CODE_PROPERTY_NAME);
065        }
066        else {
067            return dataDictionaryService.getAttributeLabel(SubFundGroup.class, OLEConstants.SUB_FUND_GROUP_CODE_PROPERTY_NAME);
068        }
069    }
070
071    /**
072     * 
073     * @see org.kuali.ole.coa.service.SubFundGroupService#getContractsAndGrantsDenotingValue(org.kuali.ole.coa.businessobject.SubFundGroup)
074     */
075    public String getContractsAndGrantsDenotingValue(SubFundGroup subFundGroup) {
076        if (fundGroupDenotesContractsAndGrants()) {
077            return subFundGroup.getFundGroupCode();
078        }
079        else {
080            return subFundGroup.getSubFundGroupCode();
081        }
082    }
083
084
085    /**
086     * @see org.kuali.ole.coa.service.SubFundGroupService#getContractsAndGrantsDenotingValues()
087     */
088    public Collection<String> getContractsAndGrantsDenotingValues() {
089        return parameterService.getParameterValuesAsString(Account.class, OLEConstants.ChartApcParms.ACCOUNT_CG_DENOTING_VALUE);
090    }
091    
092    
093    /**
094     * @see org.kuali.ole.coa.service.SubFundGroupService#getContractsAndGrantsDenotingValueForMessage()
095     */
096    public String getContractsAndGrantsDenotingValueForMessage() {
097        return /*REFACTORME*/SpringContext.getBean(ParameterEvaluatorService.class).getParameterEvaluator(Account.class, OLEConstants.ChartApcParms.ACCOUNT_CG_DENOTING_VALUE).getParameterValuesForMessage();
098    }
099
100    /**
101     * 
102     * This checks to see if there is a value for checking if a Fund Group denotes Contracts and Grants
103     * @return false if there is no value
104     */
105    protected boolean fundGroupDenotesContractsAndGrants() {
106        return parameterService.getParameterValueAsBoolean(Account.class, OLEConstants.ChartApcParms.ACCOUNT_FUND_GROUP_DENOTES_CG);
107    }
108
109    /**
110     * @see org.kuali.ole.coa.service.SubFundGroupService#getByPrimaryId(java.lang.String)
111     */
112    public SubFundGroup getByPrimaryId(String subFundGroupCode) {
113        return (SubFundGroup)SpringContext.getBean(BusinessObjectService.class).findBySinglePrimaryKey(SubFundGroup.class, subFundGroupCode);
114    }
115
116    /**
117     * @see org.kuali.ole.coa.service.SubFundGroupService#getByChartAndAccount(java.lang.String, java.lang.String)
118     */
119    public SubFundGroup getByChartAndAccount(String chartCode, String accountNumber) {
120        return subFundGroupDao.getByChartAndAccount(chartCode, accountNumber);
121    }
122
123    /**
124     * 
125     * This method injects the ParameterService
126     * @param parameterService
127     */
128    public void setParameterService(ParameterService parameterService) {
129        this.parameterService = parameterService;
130    }
131
132    /**
133     * Sets the subFundGroupDao attribute values.
134     * 
135     * @param subFundGroupDao The subFundGroupDao to set.
136     */
137    public void setSubFundGroupDao(SubFundGroupDao subFundGroupDao) {
138        this.subFundGroupDao = subFundGroupDao;
139    }
140
141    /**
142     * Sets the dataDictionarySerivce
143     * 
144     * @param dataDictionaryService The dataDictionaryService implementation to set.
145     */
146    public void setDataDictionaryService(DataDictionaryService dataDictionaryService) {
147        this.dataDictionaryService = dataDictionaryService;
148    }
149}