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.businessobject.PurchaseOrderSensitiveData;
19 import org.kuali.ole.module.purap.businessobject.SensitiveData;
20 import org.kuali.ole.sys.OLEKeyConstants;
21 import org.kuali.ole.sys.context.SpringContext;
22 import org.kuali.ole.vnd.businessobject.CommodityCode;
23 import org.kuali.rice.kns.document.MaintenanceDocument;
24 import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase;
25 import org.kuali.rice.krad.service.BusinessObjectService;
26
27 import java.util.HashMap;
28 import java.util.Map;
29
30
31
32
33 public class SensitiveDataRule extends MaintenanceDocumentRuleBase {
34
35
36
37
38
39
40
41
42
43 @Override
44 protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) {
45 boolean valid = true;
46 valid &= validateInactivationBlocking();
47 return valid;
48 }
49
50 protected boolean processCustomApproveDocumentBusinessRules(MaintenanceDocument document) {
51 boolean valid = true;
52 valid &= validateInactivationBlocking();
53 return valid;
54 }
55
56 protected boolean validateInactivationBlocking() {
57 SensitiveData oldSensitiveData = (SensitiveData) getOldBo();
58 SensitiveData newSensitiveData = (SensitiveData) getNewBo();
59 if (oldSensitiveData.isActive() && !newSensitiveData.isActive()) {
60 if (hasABlockingRecord(newSensitiveData.getSensitiveDataCode())) {
61 String documentLabel = "SensitiveData";
62 putGlobalError(OLEKeyConstants.ERROR_CANNOT_INACTIVATE_USED_BY_ACTIVE_RECORDS, documentLabel);
63 return false;
64 }
65 }
66 return true;
67 }
68
69 protected boolean hasABlockingRecord(String sensitiveDataCode) {
70 Map<String, Object> queryMap = new HashMap<String, Object>();
71 queryMap.put("sensitiveDataCode", sensitiveDataCode);
72
73
74 boolean hasPurchaseOrderSensitiveDataBlockingRecord = SpringContext.getBean(BusinessObjectService.class).countMatching(PurchaseOrderSensitiveData.class, queryMap) > 0;
75
76 queryMap.put("active", true);
77
78 boolean hasCommodityCodeBlockingRecord = SpringContext.getBean(BusinessObjectService.class).countMatching(CommodityCode.class, queryMap) > 0;
79
80 return hasPurchaseOrderSensitiveDataBlockingRecord || hasCommodityCodeBlockingRecord;
81 }
82
83 }