View Javadoc

1   package org.kuali.ole.catalog.rule;
2   
3   import org.kuali.ole.OLEConstants;
4   import org.kuali.ole.catalog.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   * Created by IntelliJ IDEA.
14   * User: syedk
15   * Date: 6/11/12
16   * Time: 4:21 PM
17   * To change this template use File | Settings | File Templates.
18   */
19  public class OleShelvingOrderRule extends MaintenanceDocumentRuleBase {
20  
21      @Override
22      protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
23          boolean isValid = true;
24          OleShelvingOrder oleShelvingOrder = (OleShelvingOrder) document.getNewMaintainableObject().getDataObject();
25  
26          isValid &= validateShelvingOrderCode(oleShelvingOrder);
27          return isValid;
28      }
29  
30      /**
31       * This method  validates duplicate shelvingOrder Id and return boolean value.
32       * @param oleShelvingOrder
33       * @return  boolean
34       */
35      private boolean validateShelvingOrderCode(OleShelvingOrder oleShelvingOrder) {
36  
37          if (oleShelvingOrder.getShelvingOrderCode() != null) {
38              Map<String, String> criteria = new HashMap<String, String>();
39              criteria.put(OLEConstants.OleShelvingOrder.SHELVING_ORDER_CD, oleShelvingOrder.getShelvingOrderCode());
40              List<OleShelvingOrder> shelvingOrderCodeInDatabase = (List<OleShelvingOrder>) getBoService().findMatching(OleShelvingOrder.class, criteria);
41              if ((shelvingOrderCodeInDatabase.size() > 0)) {
42                  for (OleShelvingOrder shelvingOrderObj : shelvingOrderCodeInDatabase) {
43                      Integer shelvingOrderId = shelvingOrderObj.getShelvingOrderId();
44                      if (null == oleShelvingOrder.getShelvingOrderId() || (oleShelvingOrder.getShelvingOrderId().intValue() != shelvingOrderId.intValue())) {
45                          this.putFieldError(OLEConstants.OleShelvingOrder.SHELVING_ORDER_CODE, "error.duplicate.code");
46                          return false;
47                      }
48                  }
49              }
50          }
51          return true;
52      }
53  }