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