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.apache.commons.lang.StringUtils;
19 import org.kuali.ole.module.purap.PurapKeyConstants;
20 import org.kuali.ole.module.purap.businessobject.PurchaseOrderContractLanguage;
21 import org.kuali.rice.kns.document.MaintenanceDocument;
22 import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase;
23 import org.kuali.rice.krad.service.BusinessObjectService;
24
25 import java.util.HashMap;
26 import java.util.Map;
27
28
29
30
31 public class PurchaseOrderContractLanguageRule extends MaintenanceDocumentRuleBase {
32
33 protected PurchaseOrderContractLanguage newContractLanguage;
34 protected PurchaseOrderContractLanguage oldContractLanguage;
35 protected BusinessObjectService boService;
36
37
38
39
40 @Override
41 public void setupConvenienceObjects() {
42 oldContractLanguage = (PurchaseOrderContractLanguage) super.getOldBo();
43
44 newContractLanguage = (PurchaseOrderContractLanguage) super.getNewBo();
45 boService = (BusinessObjectService) super.getBoService();
46 super.setupConvenienceObjects();
47 }
48
49
50
51
52 protected boolean processCustomApproveDocumentBusinessRules(MaintenanceDocument document) {
53 LOG.info("processCustomApproveDocumentBusinessRules called");
54 this.setupConvenienceObjects();
55 boolean success = this.checkForDuplicate();
56 return success && super.processCustomApproveDocumentBusinessRules(document);
57 }
58
59
60
61
62 protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) {
63 LOG.info("processCustomRouteDocumentBusinessRules called");
64 this.setupConvenienceObjects();
65 boolean success = this.checkForDuplicate();
66 return success && super.processCustomRouteDocumentBusinessRules(document);
67 }
68
69
70
71
72 protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
73 LOG.info("processCustomSaveDocumentBusinessRules called");
74 this.setupConvenienceObjects();
75 boolean success = this.checkForDuplicate();
76 return success && super.processCustomSaveDocumentBusinessRules(document);
77 }
78
79
80
81
82
83
84 protected boolean checkForDuplicate() {
85 LOG.info("checkForDuplicate called");
86 boolean success = true;
87 Map fieldValues = new HashMap();
88
89 if (oldContractLanguage.getPurchaseOrderContractLanguageIdentifier() != null &&
90 newContractLanguage.getPurchaseOrderContractLanguageIdentifier() != null &&
91 StringUtils.equalsIgnoreCase(newContractLanguage.getCampusCode(), oldContractLanguage.getCampusCode()) &&
92 newContractLanguage.getPurchaseOrderContractLanguageIdentifier().equals(oldContractLanguage.getPurchaseOrderContractLanguageIdentifier()) &&
93 StringUtils.equalsIgnoreCase(newContractLanguage.getPurchaseOrderContractLanguageDescription(), oldContractLanguage.getPurchaseOrderContractLanguageDescription()) &&
94 newContractLanguage.getContractLanguageCreateDate().equals(oldContractLanguage.getContractLanguageCreateDate())) {
95 success = true;
96 } else {
97 fieldValues.put("campusCode", newContractLanguage.getCampusCode());
98 fieldValues.put("purchaseOrderContractLanguageDescription", newContractLanguage.getPurchaseOrderContractLanguageDescription());
99 fieldValues.put("contractLanguageCreateDate", newContractLanguage.getContractLanguageCreateDate());
100 if (boService.countMatching(newContractLanguage.getClass(), fieldValues) != 0) {
101 success &= false;
102 putGlobalError(PurapKeyConstants.PURAP_GENERAL_POTENTIAL_DUPLICATE);
103 }
104 }
105 return success;
106 }
107 }