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.service.impl; 017 018 import java.util.ArrayList; 019 import java.util.List; 020 import java.util.SortedSet; 021 import java.util.TreeSet; 022 023 import org.apache.commons.lang.StringUtils; 024 import org.kuali.kfs.coa.businessobject.ObjectCode; 025 import org.kuali.kfs.coa.dataaccess.ObjectCodeDao; 026 import org.kuali.kfs.coa.service.ObjectCodeService; 027 import org.kuali.kfs.sys.service.NonTransactional; 028 import org.kuali.kfs.sys.service.UniversityDateService; 029 import org.kuali.rice.kns.util.spring.CacheNoCopy; 030 031 /** 032 * This class is the service implementation for the ObjectCode structure. This is the default implementation, that is delivered with 033 * Kuali. 034 */ 035 036 @NonTransactional 037 public class ObjectCodeServiceImpl implements ObjectCodeService { 038 039 private ObjectCodeDao objectCodeDao; 040 private UniversityDateService universityDateService; 041 042 /** 043 * @see org.kuali.kfs.coa.service.ObjectCodeService#getByPrimaryId(java.lang.Integer, java.lang.String, java.lang.String) 044 */ 045 public ObjectCode getByPrimaryId(Integer universityFiscalYear, String chartOfAccountsCode, String financialObjectCode) { 046 return objectCodeDao.getByPrimaryId(universityFiscalYear, chartOfAccountsCode, financialObjectCode); 047 } 048 049 /** 050 * @see org.kuali.kfs.coa.service.ObjectCodeService#getByPrimaryIdWithCaching(java.lang.Integer, java.lang.String, 051 * java.lang.String) 052 */ 053 @CacheNoCopy 054 public ObjectCode getByPrimaryIdWithCaching(Integer universityFiscalYear, String chartOfAccountsCode, String financialObjectCode) { 055 return objectCodeDao.getByPrimaryId(universityFiscalYear, chartOfAccountsCode, financialObjectCode); 056 } 057 058 /** 059 * @return ObjectCodeDao 060 */ 061 public ObjectCodeDao getObjectCodeDao() { 062 return objectCodeDao; 063 } 064 065 /** 066 * Injects the ObjectCodeDao 067 * 068 * @param objectCodeDao 069 */ 070 public void setObjectCodeDao(ObjectCodeDao objectCodeDao) { 071 this.objectCodeDao = objectCodeDao; 072 } 073 074 /** 075 * Gets the universityDateService attribute. 076 * 077 * @return Returns the universityDateService. 078 */ 079 public UniversityDateService getUniversityDateService() { 080 return universityDateService; 081 } 082 083 /** 084 * Sets the universityDateService attribute value. 085 * 086 * @param universityDateService The universityDateService to set. 087 */ 088 public void setUniversityDateService(UniversityDateService universityDateService) { 089 this.universityDateService = universityDateService; 090 } 091 092 /** 093 * @see org.kuali.kfs.coa.service.ObjectCodeService#getYearList(java.lang.String, java.lang.String) 094 */ 095 public List getYearList(String chartOfAccountsCode, String financialObjectCode) { 096 return objectCodeDao.getYearList(chartOfAccountsCode, financialObjectCode); 097 } 098 099 /** 100 * @see org.kuali.kfs.coa.service.ObjectCodeService#getObjectCodeNamesByCharts(java.lang.Integer, java.lang.String[], 101 * java.lang.String) 102 */ 103 public String getObjectCodeNamesByCharts(Integer universityFiscalYear, String[] chartOfAccountCodes, String financialObjectCode) { 104 String onlyObjectCodeName = ""; 105 SortedSet<String> objectCodeNames = new TreeSet<String>(); 106 List<String> objectCodeNameList = new ArrayList<String>(); 107 for (String chartOfAccountsCode : chartOfAccountCodes) { 108 ObjectCode objCode = this.getByPrimaryId(universityFiscalYear, chartOfAccountsCode, financialObjectCode); 109 if (objCode != null) { 110 onlyObjectCodeName = objCode.getFinancialObjectCodeName(); 111 objectCodeNames.add(objCode.getFinancialObjectCodeName()); 112 objectCodeNameList.add(chartOfAccountsCode + ": " + objCode.getFinancialObjectCodeName()); 113 } 114 else { 115 onlyObjectCodeName = "Not Found"; 116 objectCodeNameList.add(chartOfAccountsCode + ": Not Found"); 117 } 118 } 119 if (objectCodeNames.size() > 1) { 120 return StringUtils.join(objectCodeNames.toArray(), ", "); 121 } 122 else { 123 return onlyObjectCodeName; 124 } 125 } 126 127 /** 128 * @see org.kuali.kfs.coa.service.ObjectCodeService#getByPrimaryIdForCurrentYear(java.lang.String, java.lang.String) 129 */ 130 public ObjectCode getByPrimaryIdForCurrentYear(String chartOfAccountsCode, String financialObjectCode) { 131 return this.getByPrimaryId(universityDateService.getCurrentFiscalYear(), chartOfAccountsCode, financialObjectCode); 132 } 133 }