View Javadoc
1   package org.kuali.ole.select.rule;
2   
3   import org.kuali.ole.OLEConstants;
4   import org.kuali.ole.select.bo.OLEPackageScope;
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/22/13
17   * Time: 12:47 PM
18   * To change this template use File | Settings | File Templates.
19   */
20  public class OLEPackageScopeRule extends MaintenanceDocumentRuleBase {
21  
22      protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
23          boolean isValid = true;
24          OLEPackageScope scopeMethod = (OLEPackageScope) document.getNewMaintainableObject().getDataObject();
25          isValid &= validateAccessMethodCode(scopeMethod);
26          return isValid;
27      }
28  
29      /**
30       * This method  validates duplicate authenticationMethod Id and return boolean value.
31       *
32       * @param scopeMethod
33       * @return boolean
34       */
35      private boolean validateAccessMethodCode(OLEPackageScope scopeMethod) {
36          if (scopeMethod.getOlePackageScopeName() != null) {
37              Map<String, String> criteria = new HashMap<String, String>();
38              criteria.put(OLEConstants.OlePackageScope.PACKG_SCOPE_NAME, scopeMethod.getOlePackageScopeName());
39              List<OLEPackageScope> authenticationMethodInDatabase = (List<OLEPackageScope>) getBoService().findMatching(OLEPackageScope.class, criteria);
40              if ((authenticationMethodInDatabase.size() > 0)) {
41                  for (OLEPackageScope authenticationMethodObj : authenticationMethodInDatabase) {
42                      String olePackageScopeId = authenticationMethodObj.getOlePackageScopeId();
43                      if (null == scopeMethod.getOlePackageScopeId() || (!scopeMethod.getOlePackageScopeId().equalsIgnoreCase(olePackageScopeId))) {
44                          GlobalVariables.getMessageMap().putError(OLEConstants.OlePackageScope.PACKG_SCOPE_NAME_FIELD, OLEConstants.ERROR_DUPLICATE_CODE);
45                          return false;
46                      }
47                  }
48              }
49          }
50          return true;
51      }
52  }