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