View Javadoc
1   package org.kuali.ole.select.rule;
2   
3   import org.kuali.ole.OLEConstants;
4   import org.kuali.ole.select.bo.OLEAccessLocation;
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 OLEAccessLocationRule extends MaintenanceDocumentRuleBase {
21  
22      protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
23          boolean isValid = true;
24          OLEAccessLocation accessMethod = (OLEAccessLocation) document.getNewMaintainableObject().getDataObject();
25          isValid &= validateAccessMethodCode(accessMethod);
26          return isValid;
27      }
28  
29      /**
30       * This method  validates duplicate authenticationMethod Id and return boolean value.
31       *
32       * @param accessMethod
33       * @return boolean
34       */
35      private boolean validateAccessMethodCode(OLEAccessLocation accessMethod) {
36          if (accessMethod.getOleAccessLocationName() != null) {
37              Map<String, String> criteria = new HashMap<String, String>();
38              criteria.put(OLEConstants.OleAccessLocation.ACCESS_TYPE_NAME, accessMethod.getOleAccessLocationName());
39              List<OLEAccessLocation> authenticationMethodInDatabase = (List<OLEAccessLocation>) getBoService().findMatching(OLEAccessLocation.class, criteria);
40              if ((authenticationMethodInDatabase.size() > 0)) {
41                  for (OLEAccessLocation authenticationMethodObj : authenticationMethodInDatabase) {
42                      String accessLocationId = authenticationMethodObj.getOleAccessLocationId();
43                      if (null == accessMethod.getOleAccessLocationId() || (!accessMethod.getOleAccessLocationId().equalsIgnoreCase(accessLocationId))) {
44                          GlobalVariables.getMessageMap().putError(OLEConstants.OleAccessLocation.ACCESS_TYPE_NAME_FIELD, OLEConstants.ERROR_DUPLICATE_CODE);
45                          return false;
46                      }
47                  }
48              }
49          }
50          return true;
51      }
52  }