1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.sys.service.impl;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21 import org.apache.commons.lang.ArrayUtils;
22 import org.apache.commons.lang.StringUtils;
23 import org.kuali.ole.sys.OLEParameterKeyConstants;
24 import org.kuali.ole.sys.businessobject.Bank;
25 import org.kuali.ole.sys.context.SpringContext;
26 import org.kuali.ole.sys.service.BankService;
27 import org.kuali.rice.core.api.parameter.ParameterEvaluator;
28 import org.kuali.rice.core.api.parameter.ParameterEvaluatorService;
29 import org.kuali.rice.coreservice.framework.parameter.ParameterService;
30 import org.kuali.rice.kns.service.DataDictionaryService;
31 import org.kuali.rice.krad.service.BusinessObjectService;
32 import org.springframework.cache.annotation.Cacheable;
33
34
35
36
37
38
39 public class BankServiceImpl implements BankService {
40 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(BankServiceImpl.class);
41
42 protected BusinessObjectService businessObjectService;
43 protected DataDictionaryService dataDictionaryService;
44 protected ParameterService parameterService;
45 protected ParameterEvaluatorService parameterEvaluatorService;
46
47
48
49
50 @Override
51 @Cacheable(value=Bank.CACHE_NAME, key="'bankCode='+#p0")
52 public Bank getByPrimaryId(String bankCode) {
53 if ( StringUtils.isBlank(bankCode) ) {
54 return null;
55 }
56 return businessObjectService.findBySinglePrimaryKey(Bank.class, bankCode);
57 }
58
59
60
61
62 @Override
63 @Cacheable(value=Bank.CACHE_NAME, key="'DefaultByDocType-'+#p0")
64 public Bank getDefaultBankByDocType(String documentTypeCode) {
65 if (parameterService.parameterExists(Bank.class, OLEParameterKeyConstants.DEFAULT_BANK_BY_DOCUMENT_TYPE)) {
66 List<String> parmValues = new ArrayList<String>( parameterService.getSubParameterValuesAsString(Bank.class, OLEParameterKeyConstants.DEFAULT_BANK_BY_DOCUMENT_TYPE, documentTypeCode) );
67
68 if (parmValues != null && !parmValues.isEmpty()) {
69 String defaultBankCode = parmValues.get(0);
70
71 Bank defaultBank = getByPrimaryId(defaultBankCode);
72
73
74 if ( defaultBank != null && !defaultBank.isActive() && defaultBank.getContinuationBank() != null && defaultBank.getContinuationBank().isActive()) {
75 return defaultBank.getContinuationBank();
76 }
77
78 return defaultBank;
79 }
80 }
81
82 return null;
83 }
84
85
86
87
88 @Override
89 @Cacheable(value=Bank.CACHE_NAME, key="'DefaultByDocClass-'+#p0")
90 public Bank getDefaultBankByDocType(Class<?> documentClass) {
91 String documentTypeCode = dataDictionaryService.getDocumentTypeNameByClass(documentClass);
92
93 if (StringUtils.isBlank(documentTypeCode)) {
94 throw new RuntimeException("Document type not found for document class: " + documentClass.getName());
95 }
96 return getDefaultBankByDocType(documentTypeCode);
97 }
98
99
100
101
102 @Override
103 @Cacheable(value=Bank.CACHE_NAME, key="'isBankSpecificationEnabled'")
104 public boolean isBankSpecificationEnabled() {
105 return parameterService.getParameterValueAsBoolean(Bank.class, OLEParameterKeyConstants.ENABLE_BANK_SPECIFICATION_IND);
106 }
107
108
109
110
111 @Override
112 @Cacheable(value=Bank.CACHE_NAME, key="'isBankSpecificationEnabled'+#p0")
113 public boolean isBankSpecificationEnabledForDocument(Class<?> documentClass) {
114 String documentTypeCode = dataDictionaryService.getDocumentTypeNameByClass(documentClass);
115 if (ArrayUtils.contains(PERMANENT_BANK_SPECIFICATION_ENABLED_DOCUMENT_TYPES, documentTypeCode)) {
116 return true;
117 }
118 ParameterEvaluator evaluator = SpringContext.getBean(ParameterEvaluatorService.class).getParameterEvaluator(Bank.class, OLEParameterKeyConstants.BANK_CODE_DOCUMENT_TYPES, documentTypeCode);
119 return evaluator.evaluationSucceeds();
120 }
121
122 public void setBusinessObjectService(BusinessObjectService businessObjectService) {
123 this.businessObjectService = businessObjectService;
124 }
125
126 public void setDataDictionaryService(DataDictionaryService dataDictionaryService) {
127 this.dataDictionaryService = dataDictionaryService;
128 }
129
130 public void setParameterService(ParameterService parameterService) {
131 this.parameterService = parameterService;
132 }
133
134 public void setParameterEvaluatorService(ParameterEvaluatorService parameterEvaluatorService) {
135 this.parameterEvaluatorService = parameterEvaluatorService;
136 }
137 }