1 package org.kuali.ole.catalog.rule;
2
3 import org.kuali.ole.OLEConstants;
4 import org.kuali.ole.catalog.bo.OleReceiptStatus;
5 import org.kuali.rice.krad.maintenance.MaintenanceDocument;
6 import org.kuali.rice.krad.rules.MaintenanceDocumentRuleBase;
7
8 import java.util.HashMap;
9 import java.util.List;
10 import java.util.Map;
11
12
13
14
15 public class OleReceiptStatusRule extends MaintenanceDocumentRuleBase {
16
17 @Override
18 protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
19 boolean isValid = true;
20 OleReceiptStatus oleReceiptStatus = (OleReceiptStatus) document.getNewMaintainableObject().getDataObject();
21
22 isValid &= validateReceiptStatusCode(oleReceiptStatus);
23 return isValid;
24 }
25
26
27
28
29
30
31 private boolean validateReceiptStatusCode(OleReceiptStatus oleReceiptStatus) {
32
33 if (oleReceiptStatus.getReceiptStatusCode() != null) {
34
35 Map<String, String> criteria = new HashMap<String, String>();
36
37 criteria.put(OLEConstants.OleReceiptStatus.RECEIPT_STATUS_CD, oleReceiptStatus.getReceiptStatusCode());
38
39 List<OleReceiptStatus> receiptStatusCodeInDatabase = (List<OleReceiptStatus>) getBoService().findMatching(OleReceiptStatus.class, criteria);
40
41 if ((receiptStatusCodeInDatabase.size() > 0)) {
42
43 for(OleReceiptStatus receiptStatusObj:receiptStatusCodeInDatabase){
44 String receiptStatusId=receiptStatusObj.getReceiptStatusId();
45 if(null == oleReceiptStatus.getReceiptStatusId() ||
46 !(receiptStatusId.equalsIgnoreCase(oleReceiptStatus.getReceiptStatusId()))) {
47 this.putFieldError(OLEConstants.OleReceiptStatus.RECEIPT_STATUS_CODE, "error.duplicate.code");
48 return false;
49 }
50 }
51 }
52 return true;
53 }
54 return false;
55 }
56 }