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.ObjectCode;
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 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(KFSConstants.UNIVERSITY_FISCAL_YEAR_PROPERTY_NAME, universityFiscalYear);
049 criteria.put(KFSConstants.CHART_OF_ACCOUNTS_CODE_PROPERTY_NAME, chartOfAccountsCode);
050 criteria.put(KFSConstants.FINANCIAL_OBJECT_CODE_PROPERTY_NAME, values);
051 Collection<ObjectCode> coll = SpringContext.getBean(BusinessObjectService.class).findMatchingOrderBy(ObjectCode.class, criteria, KFSConstants.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 }