001/* 002 * Copyright 2006-2008 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.document.web; 017 018import java.util.Collection; 019import java.util.HashMap; 020import java.util.Map; 021import java.util.Set; 022 023import org.kuali.ole.coa.businessobject.ObjectCode; 024import org.kuali.ole.sys.OLEConstants; 025import org.kuali.ole.sys.context.SpringContext; 026import org.kuali.ole.sys.document.web.CodeDescriptionFormatterBase; 027import org.kuali.rice.krad.bo.PersistableBusinessObject; 028import org.kuali.rice.krad.service.BusinessObjectService; 029 030public class ObjectCodeDescriptionFormatter extends CodeDescriptionFormatterBase { 031 032 private Integer universityFiscalYear; 033 private String chartOfAccountsCode; 034 035 public ObjectCodeDescriptionFormatter(Integer universityFiscalYear, String chartOfAccountsCode) { 036 this.universityFiscalYear = universityFiscalYear; 037 this.chartOfAccountsCode = chartOfAccountsCode; 038 } 039 040 @Override 041 protected String getDescriptionOfBO(PersistableBusinessObject bo) { 042 return ((ObjectCode) bo).getFinancialObjectCodeName(); 043 } 044 045 @Override 046 protected Map<String, PersistableBusinessObject> getValuesToBusinessObjectsMap(Set values) { 047 Map<String, Object> criteria = new HashMap<String, Object>(); 048 criteria.put(OLEConstants.UNIVERSITY_FISCAL_YEAR_PROPERTY_NAME, universityFiscalYear); 049 criteria.put(OLEConstants.CHART_OF_ACCOUNTS_CODE_PROPERTY_NAME, chartOfAccountsCode); 050 criteria.put(OLEConstants.FINANCIAL_OBJECT_CODE_PROPERTY_NAME, values); 051 Collection<ObjectCode> coll = SpringContext.getBean(BusinessObjectService.class).findMatchingOrderBy(ObjectCode.class, criteria, OLEConstants.VERSION_NUMBER, true); 052 053 Map<String, PersistableBusinessObject> results = new HashMap<String, PersistableBusinessObject>(); 054 // TODO: worry about active flag? 055 for (ObjectCode oc : coll) { 056 results.put(oc.getFinancialObjectCode(), oc); 057 } 058 return results; 059 } 060}