1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.module.purap.document.validation.impl;
17
18 import org.kuali.ole.module.purap.PurapKeyConstants;
19 import org.kuali.ole.module.purap.businessobject.VendorStipulation;
20 import org.kuali.rice.kns.document.MaintenanceDocument;
21 import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase;
22 import org.kuali.rice.krad.service.BusinessObjectService;
23
24 import java.util.HashMap;
25 import java.util.Map;
26
27
28
29
30 public class VendorStipulationRule extends MaintenanceDocumentRuleBase {
31
32 private VendorStipulation newStipulation;
33 private VendorStipulation oldStipulation;
34 private BusinessObjectService boService;
35
36
37
38
39 @Override
40 public void setupConvenienceObjects() {
41
42 newStipulation = (VendorStipulation) super.getNewBo();
43 oldStipulation = (VendorStipulation) super.getOldBo();
44 boService = (BusinessObjectService) super.getBoService();
45 super.setupConvenienceObjects();
46 }
47
48
49
50
51 protected boolean processCustomApproveDocumentBusinessRules(MaintenanceDocument document) {
52 LOG.info("processCustomApproveDocumentBusinessRules called");
53 this.setupConvenienceObjects();
54 boolean success = this.checkForDuplicate();
55 return success && super.processCustomApproveDocumentBusinessRules(document);
56 }
57
58
59
60
61 protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) {
62 LOG.info("processCustomRouteDocumentBusinessRules called");
63 this.setupConvenienceObjects();
64 boolean success = this.checkForDuplicate();
65 return success && super.processCustomRouteDocumentBusinessRules(document);
66 }
67
68
69
70
71 protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
72 LOG.info("processCustomSaveDocumentBusinessRules called");
73 this.setupConvenienceObjects();
74 boolean success = this.checkForDuplicate();
75 return success && super.processCustomSaveDocumentBusinessRules(document);
76 }
77
78
79
80
81
82
83 protected boolean checkForDuplicate() {
84 LOG.info("checkForDuplicate called");
85 boolean success = true;
86 Map fieldValues = new HashMap();
87
88 if (oldStipulation.getVendorStipulationIdentifier() != null && newStipulation.getVendorStipulationIdentifier() != null &&
89 oldStipulation.getVendorStipulationIdentifier().equals(newStipulation.getVendorStipulationIdentifier()) &&
90 oldStipulation.getVendorStipulationName().equals(newStipulation.getVendorStipulationName())) {
91 return true;
92 } else {
93 fieldValues.put("vendorStipulationName", newStipulation.getVendorStipulationName());
94 if (boService.countMatching(newStipulation.getClass(), fieldValues) != 0) {
95 success &= false;
96 putGlobalError(PurapKeyConstants.PURAP_GENERAL_POTENTIAL_DUPLICATE);
97 }
98 }
99
100 return success;
101 }
102 }