View Javadoc

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