View Javadoc
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   * OleReceiptStatusRule validates maintenance object for Receipt Status Maintenance Document
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       * This method  validates duplicate receiptStatus Id and return boolean value.
28       *
29       * @param oleReceiptStatus
30       * @return boolean
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  }