View Javadoc
1   /*
2    * The Kuali Financial System, a comprehensive financial management system for higher education.
3    * 
4    * Copyright 2005-2014 The Kuali Foundation
5    * 
6    * This program is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU Affero General Public License as
8    * published by the Free Software Foundation, either version 3 of the
9    * License, or (at your option) any later version.
10   * 
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU Affero General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Affero General Public License
17   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  package org.kuali.kfs.coa.document.web;
20  
21  import java.util.Collection;
22  import java.util.HashMap;
23  import java.util.Map;
24  import java.util.Set;
25  
26  import org.kuali.kfs.coa.businessobject.ObjectLevel;
27  import org.kuali.kfs.sys.KFSConstants;
28  import org.kuali.kfs.sys.context.SpringContext;
29  import org.kuali.kfs.sys.document.web.CodeDescriptionFormatterBase;
30  import org.kuali.rice.krad.bo.PersistableBusinessObject;
31  import org.kuali.rice.krad.service.BusinessObjectService;
32  
33  /**
34   * This class...
35   */
36  public class ObjectLevelCodeDescriptionFormatter extends CodeDescriptionFormatterBase {
37  
38      private String chartOfAccountsCode;
39  
40      public ObjectLevelCodeDescriptionFormatter(String chartOfAccountsCode) {
41          this.chartOfAccountsCode = chartOfAccountsCode;
42      }
43  
44      /**
45       * @see org.kuali.kfs.sys.document.web.CodeDescriptionFormatterBase#getDescriptionOfBO(org.kuali.rice.krad.bo.BusinessObject)
46       */
47      @Override
48      protected String getDescriptionOfBO(PersistableBusinessObject bo) {
49          return ((ObjectLevel) bo).getFinancialObjectLevelName();
50      }
51  
52      /**
53       * @see org.kuali.kfs.sys.document.web.CodeDescriptionFormatterBase#getValuesToBusinessObjectsMap(java.util.Set)
54       */
55      @Override
56      protected Map<String, PersistableBusinessObject> getValuesToBusinessObjectsMap(Set values) {
57          Map<String, Object> criteria = new HashMap<String, Object>();
58          criteria.put(KFSConstants.CHART_OF_ACCOUNTS_CODE_PROPERTY_NAME, chartOfAccountsCode);
59          criteria.put(KFSConstants.FINANCIAL_OBJECT_LEVEL_CODE_PROPERTY_NAME, values);
60          Collection<ObjectLevel> coll = SpringContext.getBean(BusinessObjectService.class).findMatchingOrderBy(ObjectLevel.class, criteria, KFSConstants.VERSION_NUMBER, true);
61  
62          Map<String, PersistableBusinessObject> results = new HashMap<String, PersistableBusinessObject>();
63          // TODO: worry about version #s
64          for (ObjectLevel ol : coll) {
65              results.put(ol.getFinancialObjectLevelCode(), ol);
66          }
67          return results;
68      }
69  
70  }