View Javadoc
1   package org.kuali.ole.describe.rule;
2   
3   
4   import org.kuali.ole.OLEConstants;
5   import org.kuali.ole.describe.bo.OleAccessMethod;
6   import org.kuali.rice.krad.maintenance.MaintenanceDocument;
7   import org.kuali.rice.krad.rules.MaintenanceDocumentRuleBase;
8   
9   import java.util.HashMap;
10  import java.util.List;
11  import java.util.Map;
12  
13  /**
14   * OleAccessMethodsRule validates maintenance object for Access Method Maintenance Document
15   */
16  public class OleAccessMethodsRule extends MaintenanceDocumentRuleBase {
17  
18      /**
19       * @param document
20       * @return boolean
21       */
22  
23      protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
24          boolean isValid = true;
25          OleAccessMethod accessMethod = (OleAccessMethod) document.getNewMaintainableObject().getDataObject();
26          isValid &= validateAccessMethodCode(accessMethod);
27          return isValid;
28      }
29  
30      /**
31       * This method  validates duplicate accessMethod Id and return boolean value.
32       *
33       * @param accessMethod
34       * @return boolean
35       */
36      private boolean validateAccessMethodCode(OleAccessMethod accessMethod) {
37          if (accessMethod.getAccessMethodCode() != null) {
38              Map<String, String> criteria = new HashMap<String, String>();
39              criteria.put(OLEConstants.OleAccessMethod.ACCESS_METHOD_CD, accessMethod.getAccessMethodCode());
40              List<OleAccessMethod> accessMethodInDatabase = (List<OleAccessMethod>) getBoService().findMatching(OleAccessMethod.class, criteria);
41              if ((accessMethodInDatabase.size() > 0)) {
42                  for (OleAccessMethod accessMethodObj : accessMethodInDatabase) {
43                      Integer accessMethodId = accessMethodObj.getAccessMethodId();
44                      if (null == accessMethod.getAccessMethodId() || (accessMethod.getAccessMethodId().intValue() != accessMethodId.intValue())) {
45                          this.putFieldError(OLEConstants.OleAccessMethod.ACCESS_METHOD_CODE, "error.duplicate.code");
46                          return false;
47                      }
48                  }
49              }
50          }
51          return true;
52      }
53  }
54