1 package org.kuali.ole.describe.rule;
2
3 import org.kuali.ole.OLEConstants;
4 import org.kuali.ole.describe.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
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
32 private boolean validateReceiptStatusCode(OleReceiptStatus oleReceiptStatus) {
33
34 if (oleReceiptStatus.getReceiptStatusCode() != null) {
35
36 Map<String, String> criteria = new HashMap<String, String>();
37
38 criteria.put(OLEConstants.OleReceiptStatus.RECEIPT_STATUS_CD, oleReceiptStatus.getReceiptStatusCode());
39
40 List<OleReceiptStatus> receiptStatusCodeInDatabase = (List<OleReceiptStatus>) getBoService().findMatching(OleReceiptStatus.class, criteria);
41
42 if ((receiptStatusCodeInDatabase.size() > 0)) {
43
44 for (OleReceiptStatus receiptStatusObj : receiptStatusCodeInDatabase) {
45 String receiptStatusId = receiptStatusObj.getReceiptStatusId();
46 if (null == oleReceiptStatus.getReceiptStatusId() ||
47 !(receiptStatusId.equalsIgnoreCase(oleReceiptStatus.getReceiptStatusId()))) {
48 this.putFieldError(OLEConstants.OleReceiptStatus.RECEIPT_STATUS_CODE, "error.duplicate.code");
49 return false;
50 }
51 }
52 }
53 return true;
54 }
55 return false;
56 }
57 }