View Javadoc
1   package org.kuali.ole.describe.rule;
2   
3   import org.kuali.ole.OLEConstants;
4   import org.kuali.ole.describe.bo.OleShelvingOrder;
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   * OleShelvingOrderRule validates maintenance object for Shelving Order Maintenance Document
14   */
15  public class OleShelvingOrderRule extends MaintenanceDocumentRuleBase {
16  
17  
18      protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
19          boolean isValid = true;
20          OleShelvingOrder oleShelvingOrder = (OleShelvingOrder) document.getNewMaintainableObject().getDataObject();
21  
22          isValid &= validateShelvingOrderCode(oleShelvingOrder);
23          return isValid;
24      }
25  
26      /**
27       * This method  validates duplicate shelvingOrder Id and return boolean value.
28       *
29       * @param oleShelvingOrder
30       * @return boolean
31       */
32      private boolean validateShelvingOrderCode(OleShelvingOrder oleShelvingOrder) {
33  
34          if (oleShelvingOrder.getShelvingOrderCode() != null) {
35              Map<String, String> criteria = new HashMap<String, String>();
36              criteria.put(OLEConstants.OleShelvingOrder.SHELVING_ORDER_CD, oleShelvingOrder.getShelvingOrderCode());
37              List<OleShelvingOrder> shelvingOrderCodeInDatabase = (List<OleShelvingOrder>) getBoService().findMatching(OleShelvingOrder.class, criteria);
38              if ((shelvingOrderCodeInDatabase.size() > 0)) {
39                  for (OleShelvingOrder shelvingOrderObj : shelvingOrderCodeInDatabase) {
40                      Integer shelvingOrderId = shelvingOrderObj.getShelvingOrderId();
41                      if (null == oleShelvingOrder.getShelvingOrderId() || (oleShelvingOrder.getShelvingOrderId().intValue() != shelvingOrderId.intValue())) {
42                          this.putFieldError(OLEConstants.OleShelvingOrder.SHELVING_ORDER_CODE, "error.duplicate.code");
43                          return false;
44                      }
45                  }
46              }
47          }
48          return true;
49      }
50  }