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.ObjectLevel; 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 /** 031 * This class... 032 */ 033 public class ObjectLevelCodeDescriptionFormatter extends CodeDescriptionFormatterBase { 034 035 private String chartOfAccountsCode; 036 037 public ObjectLevelCodeDescriptionFormatter(String chartOfAccountsCode) { 038 this.chartOfAccountsCode = chartOfAccountsCode; 039 } 040 041 /** 042 * @see org.kuali.kfs.sys.document.web.CodeDescriptionFormatterBase#getDescriptionOfBO(org.kuali.rice.kns.bo.BusinessObject) 043 */ 044 @Override 045 protected String getDescriptionOfBO(PersistableBusinessObject bo) { 046 return ((ObjectLevel) bo).getFinancialObjectLevelName(); 047 } 048 049 /** 050 * @see org.kuali.kfs.sys.document.web.CodeDescriptionFormatterBase#getValuesToBusinessObjectsMap(java.util.Set) 051 */ 052 @Override 053 protected Map<String, PersistableBusinessObject> getValuesToBusinessObjectsMap(Set values) { 054 Map<String, Object> criteria = new HashMap<String, Object>(); 055 criteria.put(KFSConstants.CHART_OF_ACCOUNTS_CODE_PROPERTY_NAME, chartOfAccountsCode); 056 criteria.put(KFSConstants.FINANCIAL_OBJECT_LEVEL_CODE_PROPERTY_NAME, values); 057 Collection<ObjectLevel> coll = SpringContext.getBean(BusinessObjectService.class).findMatchingOrderBy(ObjectLevel.class, criteria, KFSConstants.VERSION_NUMBER, true); 058 059 Map<String, PersistableBusinessObject> results = new HashMap<String, PersistableBusinessObject>(); 060 // TODO: worry about version #s 061 for (ObjectLevel ol : coll) { 062 results.put(ol.getFinancialObjectLevelCode(), ol); 063 } 064 return results; 065 } 066 067 }