1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
38
39
40
41 @NonTransactional
42 public class ObjectCodeServiceImpl implements ObjectCodeService {
43
44 protected ObjectCodeDao objectCodeDao;
45 protected UniversityDateService universityDateService;
46
47
48
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
62
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
80
81 @Override
82 public List getYearList(String chartOfAccountsCode, String financialObjectCode) {
83 return objectCodeDao.getYearList(chartOfAccountsCode, financialObjectCode);
84 }
85
86
87
88
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
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 }