001 package org.kuali.ole.catalog.rule; 002 003 import org.kuali.ole.OLEConstants; 004 import org.kuali.ole.catalog.bo.OleLocationStatus; 005 import org.kuali.rice.krad.maintenance.MaintenanceDocument; 006 import org.kuali.rice.krad.rules.MaintenanceDocumentRuleBase; 007 008 import java.util.HashMap; 009 import java.util.List; 010 import java.util.Map; 011 012 /** 013 * OleLocationStatusRule validates maintenance object for Location Status Maintenance Document 014 */ 015 public class OleLocationStatusRule extends MaintenanceDocumentRuleBase { 016 017 /** 018 * 019 * @param document 020 * @return 021 */ 022 @Override 023 protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) { 024 boolean isValid = true; 025 OleLocationStatus oleLocationStatus = (OleLocationStatus) document.getNewMaintainableObject().getDataObject(); 026 027 isValid &= validateLocationStatusCode(oleLocationStatus); 028 return isValid; 029 } 030 031 /** 032 * This method validates duplicate locationStatus Id and return boolean value. 033 * @param oleLocationStatus 034 * @return boolean 035 */ 036 private boolean validateLocationStatusCode(OleLocationStatus oleLocationStatus) { 037 038 if (oleLocationStatus.getLocationStatusCode() != null) { 039 040 Map<String, String> criteria = new HashMap<String, String>(); 041 042 criteria.put(OLEConstants.OleLocationStatus.LOCATION_STATUS_CD, oleLocationStatus.getLocationStatusCode()); 043 044 List<OleLocationStatus> locationStatusCodeInDatabase = (List<OleLocationStatus>) getBoService().findMatching(OleLocationStatus.class, criteria); 045 046 if ((locationStatusCodeInDatabase.size() > 0)) { 047 048 for (OleLocationStatus locationStatusObj:locationStatusCodeInDatabase){ 049 String locationStatusId=locationStatusObj.getLocationStatusId(); 050 if(null == oleLocationStatus.getLocationStatusId() || 051 !(oleLocationStatus.getLocationStatusId().equalsIgnoreCase(locationStatusId))) { 052 this.putFieldError(OLEConstants.OleLocationStatus.LOCATION_STATUS_CODE, "error.duplicate.code"); 053 return false; 054 } 055 } 056 } 057 return true; 058 } 059 return false; 060 } 061 }