View Javadoc
1   package org.kuali.ole.select.rule;
2   
3   import org.kuali.ole.OLEConstants;
4   import org.kuali.ole.select.bo.OLEEResourceStatus;
5   import org.kuali.rice.krad.maintenance.MaintenanceDocument;
6   import org.kuali.rice.krad.rules.MaintenanceDocumentRuleBase;
7   import org.kuali.rice.krad.util.GlobalVariables;
8   
9   import java.util.HashMap;
10  import java.util.List;
11  import java.util.Map;
12  
13  /**
14   * Created with IntelliJ IDEA.
15   * User: chenchulakshmig
16   * Date: 6/21/13
17   * Time: 3:58 PM
18   * To change this template use File | Settings | File Templates.
19   */
20  public class OLEEResourceStatusRule extends MaintenanceDocumentRuleBase {
21  
22      protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
23          boolean isValid = true;
24          OLEEResourceStatus statusMethod = (OLEEResourceStatus) document.getNewMaintainableObject().getDataObject();
25          isValid &= validateAccessMethodCode(statusMethod);
26          return isValid;
27      }
28  
29      /**
30       * This method  validates duplicate authenticationMethod Id and return boolean value.
31       *
32       * @param statusMethod
33       * @return boolean
34       */
35      private boolean validateAccessMethodCode(OLEEResourceStatus statusMethod) {
36          if (statusMethod.getOleEResourceStatusName() != null) {
37              Map<String, String> criteria = new HashMap<String, String>();
38              criteria.put(OLEConstants.OleEResourceStatus.E_RES_STAT_TYPE_NAME, statusMethod.getOleEResourceStatusName());
39              List<OLEEResourceStatus> authenticationMethodInDatabase = (List<OLEEResourceStatus>) getBoService().findMatching(OLEEResourceStatus.class, criteria);
40              if ((authenticationMethodInDatabase.size() > 0)) {
41                  for (OLEEResourceStatus authenticationMethodObj : authenticationMethodInDatabase) {
42                      String oleEResourceStatusId = authenticationMethodObj.getOleEResourceStatusId();
43                      if (null == statusMethod.getOleEResourceStatusId() || (!statusMethod.getOleEResourceStatusId().equalsIgnoreCase(oleEResourceStatusId))) {
44                          GlobalVariables.getMessageMap().putError(OLEConstants.OleEResourceStatus.E_RES_STAT_TYPE_NAME_FIELD, OLEConstants.ERROR_DUPLICATE_CODE);
45                          return false;
46                      }
47                  }
48              }
49          }
50          return true;
51      }
52  }