1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.pdp.document.validation.impl;
17
18 import java.util.HashMap;
19 import java.util.Map;
20
21 import org.kuali.ole.pdp.PdpPropertyConstants;
22 import org.kuali.ole.pdp.businessobject.PayeeACHAccount;
23 import org.kuali.ole.sys.OLEKeyConstants;
24 import org.kuali.ole.sys.context.SpringContext;
25 import org.kuali.rice.kim.api.identity.Person;
26 import org.kuali.rice.kns.document.MaintenanceDocument;
27 import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase;
28 import org.kuali.rice.krad.service.BusinessObjectService;
29 import org.kuali.rice.krad.util.GlobalVariables;
30
31
32
33
34 public class PayeeAchAccountRule extends MaintenanceDocumentRuleBase {
35 protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(PayeeACHAccount.class);
36
37 protected PayeeACHAccount oldPayeeAchAccount;
38 protected PayeeACHAccount newPayeeAchAccount;
39
40
41
42
43 public void setupConvenienceObjects() {
44 LOG.info("setupConvenienceObjects called");
45
46
47 oldPayeeAchAccount = (PayeeACHAccount) super.getOldBo();
48
49
50 newPayeeAchAccount = (PayeeACHAccount) super.getNewBo();
51 }
52
53
54
55
56 protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
57 LOG.info("processCustomSaveDocumentBusinessRules called");
58
59
60 processCustomRouteDocumentBusinessRules(document);
61
62
63 return true;
64 }
65
66
67
68
69 protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) {
70 LOG.info("processCustomRouteDocumentBusinessRules called");
71 setupConvenienceObjects();
72
73
74 if (!checkTransactionTypeAllowed()) return false;
75
76 return checkForDuplicateRecord();
77 }
78
79
80
81
82
83
84
85
86 protected boolean checkForDuplicateRecord() {
87 String newPayeeIdNumber = newPayeeAchAccount.getPayeeIdNumber();
88 String newPayeeIdTypeCd = newPayeeAchAccount.getPayeeIdentifierTypeCode();
89 String newAchTransactionType = newPayeeAchAccount.getAchTransactionType();
90
91 boolean valid = true;
92
93 if (newPayeeAchAccount.getAchAccountGeneratedIdentifier() != null && oldPayeeAchAccount.getAchAccountGeneratedIdentifier() != null && newPayeeAchAccount.getAchAccountGeneratedIdentifier().equals(oldPayeeAchAccount.getAchAccountGeneratedIdentifier())) {
94 if (newPayeeIdTypeCd.equals(oldPayeeAchAccount.getPayeeIdentifierTypeCode()) && newAchTransactionType.equals(oldPayeeAchAccount.getAchTransactionType())) {
95 if (newPayeeAchAccount.getPayeeIdNumber().equals(oldPayeeAchAccount.getPayeeIdNumber())) {
96 return valid;
97 }
98 }
99 }
100
101
102 Map<String, Object> criteria = new HashMap<String, Object>();
103
104 criteria.put(PdpPropertyConstants.ACH_TRANSACTION_TYPE, newAchTransactionType);
105 criteria.put(PdpPropertyConstants.PAYEE_IDENTIFIER_TYPE_CODE, newPayeeIdTypeCd);
106 criteria.put(PdpPropertyConstants.PAYEE_ID_NUMBER, newPayeeIdNumber);
107
108 int matches = SpringContext.getBean(BusinessObjectService.class).countMatching(PayeeACHAccount.class, criteria);
109 if (matches > 0) {
110 putFieldError(PdpPropertyConstants.PAYEE_ID_NUMBER, OLEKeyConstants.ERROR_DOCUMENT_PAYEEACHACCOUNTMAINT_DUPLICATE_RECORD);
111 valid = false;
112 }
113
114 return valid;
115 }
116
117
118
119
120
121
122
123
124 protected boolean checkTransactionTypeAllowed() {
125 String docTypeName = maintDocDictionaryService.getDocumentTypeName(PayeeACHAccount.class);
126 Person user = GlobalVariables.getUserSession().getPerson();
127 boolean allowed = businessObjectAuthorizationService.canMaintain(newPayeeAchAccount, user, docTypeName);
128 String transType = newPayeeAchAccount.getAchTransactionType();
129
130 if (!allowed) {
131 putFieldError(PdpPropertyConstants.ACH_TRANSACTION_TYPE, OLEKeyConstants.ERROR_DOCUMENT_PAYEEACHACCOUNTMAINT_TRANSACTION_TYPE_NOT_ALLOWED, transType);
132 }
133 return allowed;
134 }
135
136 }