View Javadoc

1   package org.kuali.ole.catalog.rule;
2   
3   import org.kuali.ole.OLEConstants;
4   import org.kuali.ole.catalog.bo.OleGeneralRetentionPolicy;
5   import org.kuali.rice.krad.maintenance.MaintenanceDocument;
6   import org.kuali.rice.krad.rules.MaintenanceDocumentRuleBase;
7   
8   
9   import java.util.HashMap;
10  import java.util.List;
11  import java.util.Map;
12  
13  /**
14   * OleGeneralRetentionPolicyRule validates maintenance object for General Retention Policy Maintenance Document
15   */
16  public class OleGeneralRetentionPolicyRule extends MaintenanceDocumentRuleBase {
17  
18  
19      protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
20          boolean isValid = true;
21          OleGeneralRetentionPolicy oleGeneralRetentionPolicy = (OleGeneralRetentionPolicy) document.getNewMaintainableObject().getDataObject();
22  
23          isValid &= validateGeneralRetentionPolicyCode(oleGeneralRetentionPolicy);
24          return isValid;
25      }
26  
27      /**
28       * This method  validates duplicate  generalRetentionPolicy Id and return boolean value.
29       * @param oleGeneralRetentionPolicy
30       * @return boolean
31       */
32      private boolean validateGeneralRetentionPolicyCode(OleGeneralRetentionPolicy oleGeneralRetentionPolicy) {
33  
34          if (oleGeneralRetentionPolicy.getGeneralRetentionPolicyCode() != null) {
35  
36              Map<String, String> criteria = new HashMap<String, String>();
37  
38              criteria.put(OLEConstants.OleGeneralRetentionPolicy.GENERAL_RETENTION_POLICY_CD, oleGeneralRetentionPolicy.getGeneralRetentionPolicyCode());
39  
40  
41              List<OleGeneralRetentionPolicy> generalRetentionPolicyInDatabase = (List<OleGeneralRetentionPolicy>) getBoService().findMatching(OleGeneralRetentionPolicy.class, criteria);
42  
43              if ((generalRetentionPolicyInDatabase.size() > 0)) {
44                  for(OleGeneralRetentionPolicy oleGeneralRetentionPolicyObj:generalRetentionPolicyInDatabase){
45                      Integer generalRetentionPolicyId=oleGeneralRetentionPolicyObj.getGeneralRetentionPolicyId();
46                      if(null==oleGeneralRetentionPolicy.getGeneralRetentionPolicyId()|| oleGeneralRetentionPolicy.getGeneralRetentionPolicyId().intValue()!=generalRetentionPolicyId) {
47                          this.putFieldError(OLEConstants.OleGeneralRetentionPolicy.GENERAL_RETENTION_POLICY_CODE, "error.duplicate.code");
48                          return false;
49                      }
50                  }
51              }
52          }
53  
54          return true;
55      }
56  }