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.coa.document.web;
017    
018    import java.util.Collection;
019    import java.util.HashMap;
020    import java.util.Map;
021    import java.util.Set;
022    
023    import org.kuali.kfs.coa.businessobject.SubFundGroup;
024    import org.kuali.kfs.sys.KFSConstants;
025    import org.kuali.kfs.sys.context.SpringContext;
026    import org.kuali.kfs.sys.document.web.CodeDescriptionFormatterBase;
027    import org.kuali.rice.kns.bo.PersistableBusinessObject;
028    import org.kuali.rice.kns.service.BusinessObjectService;
029    
030    public class SubFundGroupCodeDescriptionFormatter extends CodeDescriptionFormatterBase {
031    
032        @Override
033        protected String getDescriptionOfBO(PersistableBusinessObject bo) {
034            return ((SubFundGroup) bo).getSubFundGroupDescription();
035        }
036    
037        @Override
038        protected Map<String, PersistableBusinessObject> getValuesToBusinessObjectsMap(Set values) {
039            Map<String, Object> criteria = new HashMap<String, Object>();
040            criteria.put(KFSConstants.SUB_FUND_GROUP_CODE_PROPERTY_NAME, values);
041    
042            Map<String, PersistableBusinessObject> map = new HashMap<String, PersistableBusinessObject>();
043    
044            Collection<SubFundGroup> coll = SpringContext.getBean(BusinessObjectService.class).findMatchingOrderBy(SubFundGroup.class, criteria, "versionNumber", true);
045            for (SubFundGroup sfg : coll) {
046                map.put(sfg.getSubFundGroupCode(), sfg);
047            }
048            return map;
049        }
050    
051    }