001 package org.kuali.ole.catalog.rule; 002 003 import org.kuali.ole.OLEConstants; 004 import org.kuali.ole.catalog.bo.OleGeneralRetentionPolicy; 005 import org.kuali.rice.krad.maintenance.MaintenanceDocument; 006 import org.kuali.rice.krad.rules.MaintenanceDocumentRuleBase; 007 008 009 import java.util.HashMap; 010 import java.util.List; 011 import java.util.Map; 012 013 /** 014 * OleGeneralRetentionPolicyRule validates maintenance object for General Retention Policy Maintenance Document 015 */ 016 public class OleGeneralRetentionPolicyRule extends MaintenanceDocumentRuleBase { 017 018 019 protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) { 020 boolean isValid = true; 021 OleGeneralRetentionPolicy oleGeneralRetentionPolicy = (OleGeneralRetentionPolicy) document.getNewMaintainableObject().getDataObject(); 022 023 isValid &= validateGeneralRetentionPolicyCode(oleGeneralRetentionPolicy); 024 return isValid; 025 } 026 027 /** 028 * This method validates duplicate generalRetentionPolicy Id and return boolean value. 029 * @param oleGeneralRetentionPolicy 030 * @return boolean 031 */ 032 private boolean validateGeneralRetentionPolicyCode(OleGeneralRetentionPolicy oleGeneralRetentionPolicy) { 033 034 if (oleGeneralRetentionPolicy.getGeneralRetentionPolicyCode() != null) { 035 036 Map<String, String> criteria = new HashMap<String, String>(); 037 038 criteria.put(OLEConstants.OleGeneralRetentionPolicy.GENERAL_RETENTION_POLICY_CD, oleGeneralRetentionPolicy.getGeneralRetentionPolicyCode()); 039 040 041 List<OleGeneralRetentionPolicy> generalRetentionPolicyInDatabase = (List<OleGeneralRetentionPolicy>) getBoService().findMatching(OleGeneralRetentionPolicy.class, criteria); 042 043 if ((generalRetentionPolicyInDatabase.size() > 0)) { 044 for(OleGeneralRetentionPolicy oleGeneralRetentionPolicyObj:generalRetentionPolicyInDatabase){ 045 Integer generalRetentionPolicyId=oleGeneralRetentionPolicyObj.getGeneralRetentionPolicyId(); 046 if(null==oleGeneralRetentionPolicy.getGeneralRetentionPolicyId()|| oleGeneralRetentionPolicy.getGeneralRetentionPolicyId().intValue()!=generalRetentionPolicyId) { 047 this.putFieldError(OLEConstants.OleGeneralRetentionPolicy.GENERAL_RETENTION_POLICY_CODE, "error.duplicate.code"); 048 return false; 049 } 050 } 051 } 052 } 053 054 return true; 055 } 056 }