View Javadoc
1   package org.kuali.ole.describe.rule;
2   
3   import org.kuali.ole.OLEConstants;
4   import org.kuali.ole.describe.bo.OleLendingPolicy;
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   * OleLendingPolicyRule validates maintenance object for Lending Policy Rule Maintenance Document
14   */
15  public class OleLendingPolicyRule extends MaintenanceDocumentRuleBase {
16  
17  
18      protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
19          boolean isValid = true;
20          OleLendingPolicy oleLendingPolicy = (OleLendingPolicy) document.getNewMaintainableObject().getDataObject();
21  
22          isValid &= validateLendingPolicyCode(oleLendingPolicy);
23          return isValid;
24      }
25  
26      /**
27       * This method  validates duplicate encodingLevel Id and return boolean value.
28       *
29       * @param oleLendingPolicy
30       * @return boolean
31       */
32      private boolean validateLendingPolicyCode(OleLendingPolicy oleLendingPolicy) {
33  
34          if (oleLendingPolicy.getLendingPolicyCode() != null) {
35  
36              Map<String, String> criteria = new HashMap<String, String>();
37  
38              criteria.put(OLEConstants.OleLendingPolicy.LENDING_POLICY_CD, oleLendingPolicy.getLendingPolicyCode());
39  
40              List<OleLendingPolicy> lendingPolicyInDatabase = (List<OleLendingPolicy>) getBoService().findMatching(OleLendingPolicy.class, criteria);
41  
42              if ((lendingPolicyInDatabase.size() > 0)) {
43  
44                  for (OleLendingPolicy lendingPolicyObj : lendingPolicyInDatabase) {
45                      Integer lendingPolicyId = lendingPolicyObj.getLendingPolicyId();
46                      if (null == oleLendingPolicy.getLendingPolicyId() ||
47                              oleLendingPolicy.getLendingPolicyId().intValue() != lendingPolicyId.intValue()) {
48                          this.putFieldError(OLEConstants.OleLendingPolicy.LENDING_POLICY_CODE, "error.duplicate.code");
49                          return false;
50                      }
51                  }
52              }
53              return true;
54          }
55          return false;
56      }
57  }