View Javadoc
1   /*
2    * Copyright 2005-2006 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.coa.service.impl;
17  
18  import java.util.ArrayList;
19  import java.util.HashMap;
20  import java.util.List;
21  import java.util.Map;
22  import java.util.SortedSet;
23  import java.util.TreeSet;
24  
25  import org.apache.commons.lang.StringUtils;
26  import org.kuali.ole.coa.businessobject.ObjectCode;
27  import org.kuali.ole.coa.dataaccess.ObjectCodeDao;
28  import org.kuali.ole.coa.service.ObjectCodeService;
29  import org.kuali.ole.sys.OLEPropertyConstants;
30  import org.kuali.ole.sys.context.SpringContext;
31  import org.kuali.ole.sys.service.NonTransactional;
32  import org.kuali.ole.sys.service.UniversityDateService;
33  import org.kuali.rice.krad.service.BusinessObjectService;
34  import org.springframework.cache.annotation.Cacheable;
35  
36  /**
37   * This class is the service implementation for the ObjectCode structure. This is the default implementation, that is delivered with
38   * Kuali.
39   */
40  
41  @NonTransactional
42  public class ObjectCodeServiceImpl implements ObjectCodeService {
43  
44      protected ObjectCodeDao objectCodeDao;
45      protected UniversityDateService universityDateService;
46  
47      /**
48       * @see org.kuali.ole.coa.service.ObjectCodeService#getByPrimaryId(java.lang.Integer, java.lang.String, java.lang.String)
49       */
50      @Override
51      @Cacheable(value=ObjectCode.CACHE_NAME, key="#p0+'-'+#p1+'-'+#p2")
52      public ObjectCode getByPrimaryId(Integer universityFiscalYear, String chartOfAccountsCode, String financialObjectCode) {
53          Map<String, Object> keys = new HashMap<String, Object>(3);
54          keys.put(OLEPropertyConstants.UNIVERSITY_FISCAL_YEAR, universityFiscalYear);
55          keys.put(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, chartOfAccountsCode);
56          keys.put(OLEPropertyConstants.FINANCIAL_OBJECT_CODE, financialObjectCode);
57          return SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(ObjectCode.class, keys);
58      }
59  
60      /**
61       * @see org.kuali.ole.coa.service.ObjectCodeService#getByPrimaryIdWithCaching(java.lang.Integer, java.lang.String,
62       *      java.lang.String)
63       */
64      @Override
65      @Cacheable(value=ObjectCode.CACHE_NAME, key="#p0+'-'+#p1+'-'+#p2")
66      public ObjectCode getByPrimaryIdWithCaching(Integer universityFiscalYear, String chartOfAccountsCode, String financialObjectCode) {
67          ObjectCode objectCode = getByPrimaryId(universityFiscalYear, chartOfAccountsCode, financialObjectCode);
68          return objectCode;
69      }
70  
71      public void setObjectCodeDao(ObjectCodeDao objectCodeDao) {
72          this.objectCodeDao = objectCodeDao;
73      }
74      public void setUniversityDateService(UniversityDateService universityDateService) {
75          this.universityDateService = universityDateService;
76      }
77  
78      /**
79       * @see org.kuali.ole.coa.service.ObjectCodeService#getYearList(java.lang.String, java.lang.String)
80       */
81      @Override
82      public List getYearList(String chartOfAccountsCode, String financialObjectCode) {
83          return objectCodeDao.getYearList(chartOfAccountsCode, financialObjectCode);
84      }
85  
86      /**
87       * @see org.kuali.ole.coa.service.ObjectCodeService#getObjectCodeNamesByCharts(java.lang.Integer, java.lang.String[],
88       *      java.lang.String)
89       */
90      @Override
91      public String getObjectCodeNamesByCharts(Integer universityFiscalYear, String[] chartOfAccountCodes, String financialObjectCode) {
92          String onlyObjectCodeName = "";
93          SortedSet<String> objectCodeNames = new TreeSet<String>();
94          List<String> objectCodeNameList = new ArrayList<String>();
95          for (String chartOfAccountsCode : chartOfAccountCodes) {
96              ObjectCode objCode = this.getByPrimaryId(universityFiscalYear, chartOfAccountsCode, financialObjectCode);
97              if (objCode != null) {
98                  onlyObjectCodeName = objCode.getFinancialObjectCodeName();
99                  objectCodeNames.add(objCode.getFinancialObjectCodeName());
100                 objectCodeNameList.add(chartOfAccountsCode + ": " + objCode.getFinancialObjectCodeName());
101             }
102             else {
103                 onlyObjectCodeName = "Not Found";
104                 objectCodeNameList.add(chartOfAccountsCode + ": Not Found");
105             }
106         }
107         if (objectCodeNames.size() > 1) {
108             return StringUtils.join(objectCodeNames.toArray(), ", ");
109         }
110         else {
111             return onlyObjectCodeName;
112         }
113     }
114 
115     /**
116      * @see org.kuali.ole.coa.service.ObjectCodeService#getByPrimaryIdForCurrentYear(java.lang.String, java.lang.String)
117      */
118     @Override
119     @Cacheable(value=ObjectCode.CACHE_NAME, key="'CurrentFY'+'-'+#p0+'-'+#p1")
120     public ObjectCode getByPrimaryIdForCurrentYear(String chartOfAccountsCode, String financialObjectCode) {
121         return getByPrimaryId(universityDateService.getCurrentFiscalYear(), chartOfAccountsCode, financialObjectCode);
122     }
123 }