001/* 002 * Copyright 2009 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.ole.module.purap.document.validation.impl; 017 018import org.kuali.ole.integration.purap.CapitalAssetLocation; 019import org.kuali.ole.module.purap.document.service.PurchasingService; 020import org.kuali.ole.sys.context.SpringContext; 021import org.kuali.ole.sys.document.validation.GenericValidation; 022import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent; 023import org.kuali.rice.coreservice.framework.parameter.ParameterService; 024 025import java.util.HashMap; 026import java.util.Map; 027 028public class PurchasingAddCapitalAssetLocationValidation extends GenericValidation { 029 030 protected CapitalAssetLocation location; 031 protected ParameterService parameterService; 032 protected PurchasingService purchasingService; 033 034 public boolean validate(AttributedDocumentEvent event) { 035 boolean valid = true; 036 // TODO: Move this into CABModuleService? 037 // Retrieve and evaluate the parameter which determines whether location's address is required. 038 // CHARTS_REQUIRING_LOCATIONS_ADDRESS_ON_(REQUISITION/PURCHASE_ORDER) 039 Map<String, String> fieldValues = new HashMap<String, String>(); 040 041 //List<Parameter> results = getParameterService().retrieveParametersGivenLookupCriteria(fieldValues); 042 // If the location's address is required, enforce the validation of the individual fields of the address. 043 044 valid = getPurchasingService().checkCapitalAssetLocation(getLocation()); 045 valid &= getPurchasingService().checkValidRoomNumber(getLocation()); 046 047 //valid = purchasingService.checkCapitalAssetLocation(getLocation()); 048 //valid &= purchasingService.checkValidRoomNumber(getLocation()); 049 return valid; 050 } 051 052 public CapitalAssetLocation getLocation() { 053 return location; 054 } 055 056 public void setLocation(CapitalAssetLocation location) { 057 this.location = location; 058 } 059 060 protected ParameterService getParameterService() { 061 if (parameterService == null) { 062 parameterService = SpringContext.getBean(ParameterService.class); 063 } 064 return parameterService; 065 } 066 067 protected PurchasingService getPurchasingService() { 068 if (parameterService == null) { 069 purchasingService = SpringContext.getBean(PurchasingService.class); 070 } 071 return purchasingService; 072 } 073 074}