View Javadoc

1   package org.kuali.ole.catalog.rule;
2   
3   import org.kuali.ole.OLEConstants;
4   import org.kuali.ole.catalog.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      @Override
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       * @param oleNewAction
28       * @return  boolean
29       */
30      private boolean validateActionCode(OleAction oleNewAction) {
31  
32          if (oleNewAction.getActionCode() != null) {
33              Map<String, String> criteria = new HashMap<String, String>();
34              criteria.put(OLEConstants.OleAction.ACTION_CD, oleNewAction.getActionCode());
35              List<OleAction> actionCodeInDatabase = (List<OleAction>) getBoService().findMatching(OleAction.class, criteria);
36              if ((actionCodeInDatabase.size() > 0)) {
37                  for (OleAction actionObj : actionCodeInDatabase) {
38                      Integer actionId = actionObj.getActionId();
39                      if (null == oleNewAction.getActionId() || (oleNewAction.getActionId().intValue() != actionId.intValue())) {
40                          this.putFieldError(OLEConstants.OleAction.ACTION_CODE, "error.duplicate.code");
41                          return false;
42                      }
43                  }
44              }
45          }
46          return true;
47      }
48  }