View Javadoc

1   package org.kuali.ole.catalog.rule;
2   
3   import org.kuali.ole.OLEConstants;
4   import org.kuali.ole.catalog.bo.OleShelvingScheme;
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   * OleShelvingSchemeRule validates maintenance object for Shelving Scheme Maintenance Document
14   */
15  public class OleShelvingSchemeRule extends MaintenanceDocumentRuleBase {
16  
17      @Override
18      protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
19          boolean isValid = true;
20          OleShelvingScheme oleShelvingScheme = (OleShelvingScheme) document.getNewMaintainableObject().getDataObject();
21  
22          isValid &= validateShelvingSchemeCode(oleShelvingScheme);
23          return isValid;
24      }
25  
26      /**
27       * This method  validates duplicate shelvingScheme Id and return boolean value.
28       * @param oleShelvingScheme
29       * @return  boolean
30       */
31      private boolean validateShelvingSchemeCode(OleShelvingScheme oleShelvingScheme) {
32  
33          if (oleShelvingScheme.getShelvingSchemeCode() != null) {
34              Map<String, String> criteria = new HashMap<String, String>();
35              criteria.put(OLEConstants.OleShelvingScheme.SHELVING_SCHEME_CD, oleShelvingScheme.getShelvingSchemeCode());
36              List<OleShelvingScheme> shelvingSchemeCodeInDatabase = (List<OleShelvingScheme>) getBoService().findMatching(OleShelvingScheme.class, criteria);
37              if ((shelvingSchemeCodeInDatabase.size() > 0)) {
38                  for (OleShelvingScheme shelvingSchemeObj : shelvingSchemeCodeInDatabase) {
39                      Integer shelvingSchemeId = shelvingSchemeObj.getShelvingSchemeId();
40                      if (null == oleShelvingScheme.getShelvingSchemeId() || (oleShelvingScheme.getShelvingSchemeId().intValue() != shelvingSchemeId.intValue())) {
41                          this.putFieldError(OLEConstants.OleShelvingScheme.SHELVING_SCHEME_CODE, "error.duplicate.code");
42                          return false;
43                      }
44                  }
45              }
46          }
47          return true;
48      }
49  }