001 package org.kuali.ole.catalog.rule; 002 003 004 import org.kuali.ole.OLEConstants; 005 import org.kuali.ole.catalog.bo.OleAcquisitionMethod; 006 import org.kuali.rice.krad.maintenance.MaintenanceDocument; 007 import org.kuali.rice.krad.rules.MaintenanceDocumentRuleBase; 008 009 import java.util.HashMap; 010 import java.util.List; 011 import java.util.Map; 012 013 /** 014 * OleAcquisitionMethodsRule validates maintenance object for Acquisition Method Maintenance Document 015 */ 016 public class OleAcquisitionMethodsRule extends MaintenanceDocumentRuleBase { 017 018 @Override 019 protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) { 020 boolean isValid = true; 021 OleAcquisitionMethod acquisitionMethod = (OleAcquisitionMethod) document.getNewMaintainableObject().getDataObject(); 022 023 isValid &= validateAcquisitionCodeMethod(acquisitionMethod); 024 return isValid; 025 } 026 027 /** 028 * This method validates duplicate acquisitionMethod Id and return boolean value. 029 * @param acquisitionMethod 030 * @return boolean 031 */ 032 private boolean validateAcquisitionCodeMethod(OleAcquisitionMethod acquisitionMethod) { 033 034 if (acquisitionMethod.getAcquisitionMethodCode() != null) { 035 Map<String, String> criteria = new HashMap<String, String>(); 036 criteria.put(OLEConstants.OleAcquisitionMethod.ACQUISITION_METHOD_CD, acquisitionMethod.getAcquisitionMethodCode()); 037 List<OleAcquisitionMethod> acquisitionMethodInDatabase = (List<OleAcquisitionMethod>) getBoService().findMatching(OleAcquisitionMethod.class, criteria); 038 if ((acquisitionMethodInDatabase.size() > 0)) { 039 for (OleAcquisitionMethod acquisitionObj : acquisitionMethodInDatabase) { 040 Integer acquisitionMethodId = acquisitionObj.getAcquisitionMethodId(); 041 if (null == acquisitionMethod.getAcquisitionMethodId() || (acquisitionMethod.getAcquisitionMethodId().intValue() != acquisitionMethodId.intValue())) { 042 this.putFieldError(OLEConstants.OleAcquisitionMethod.ACQUISITION_METHOD_CODE, "error.duplicate.code"); 043 return false; 044 } 045 } 046 } 047 } 048 return true; 049 } 050 }