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.PurchaseOrderQuoteLanguage;
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 PurchaseOrderQuoteLanguageRule extends MaintenanceDocumentRuleBase {
32
33 protected PurchaseOrderQuoteLanguage oldQuoteLanguage;
34 protected PurchaseOrderQuoteLanguage newQuoteLanguage;
35 protected BusinessObjectService boService;
36
37
38
39
40 @Override
41 public void setupConvenienceObjects() {
42 oldQuoteLanguage = (PurchaseOrderQuoteLanguage) super.getOldBo();
43
44 newQuoteLanguage = (PurchaseOrderQuoteLanguage) super.getNewBo();
45 boService = (BusinessObjectService) super.getBoService();
46 super.setupConvenienceObjects();
47 }
48
49 protected boolean processCustomApproveDocumentBusinessRules(MaintenanceDocument document) {
50 LOG.info("processCustomApproveDocumentBusinessRules called");
51 this.setupConvenienceObjects();
52 boolean success = this.checkForDuplicate();
53 return success && super.processCustomApproveDocumentBusinessRules(document);
54 }
55
56 protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) {
57 LOG.info("processCustomRouteDocumentBusinessRules called");
58 this.setupConvenienceObjects();
59 boolean success = this.checkForDuplicate();
60 return success && super.processCustomRouteDocumentBusinessRules(document);
61 }
62
63 protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
64 LOG.info("processCustomSaveDocumentBusinessRules called");
65 this.setupConvenienceObjects();
66 boolean success = this.checkForDuplicate();
67 return success && super.processCustomSaveDocumentBusinessRules(document);
68 }
69
70 protected boolean checkForDuplicate() {
71 LOG.info("checkForDuplicate called");
72 boolean success = true;
73 Map fieldValues = new HashMap();
74
75 fieldValues.put("purchaseOrderQuoteLanguageDescription", newQuoteLanguage.getPurchaseOrderQuoteLanguageDescription());
76 fieldValues.put("purchaseOrderQuoteLanguageCreateDate", newQuoteLanguage.getPurchaseOrderQuoteLanguageCreateDate());
77
78 if (oldQuoteLanguage != null && newQuoteLanguage != null &&
79 newQuoteLanguage.getPurchaseOrderQuoteLanguageIdentifier() != null && oldQuoteLanguage.getPurchaseOrderQuoteLanguageIdentifier() != null &&
80 newQuoteLanguage.getPurchaseOrderQuoteLanguageCreateDate() != null && oldQuoteLanguage.getPurchaseOrderQuoteLanguageCreateDate() != null &&
81 StringUtils.equalsIgnoreCase(newQuoteLanguage.getPurchaseOrderQuoteLanguageDescription(), oldQuoteLanguage.getPurchaseOrderQuoteLanguageDescription()) &&
82 newQuoteLanguage.getPurchaseOrderQuoteLanguageIdentifier().equals(oldQuoteLanguage.getPurchaseOrderQuoteLanguageIdentifier()) &&
83 newQuoteLanguage.getPurchaseOrderQuoteLanguageCreateDate().equals(oldQuoteLanguage.getPurchaseOrderQuoteLanguageCreateDate())) {
84 success = true;
85 } else if (boService.countMatching(newQuoteLanguage.getClass(), fieldValues) != 0) {
86 success &= false;
87 putGlobalError(PurapKeyConstants.PURAP_GENERAL_POTENTIAL_DUPLICATE);
88 }
89 return success;
90 }
91 }