001 /*
002 * Copyright 2011 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 */
016 package org.kuali.kfs.module.purap.document.validation.impl;
017
018 import java.util.HashMap;
019 import java.util.List;
020 import java.util.Map;
021
022 import org.kuali.kfs.integration.purap.CapitalAssetLocation;
023 import org.kuali.kfs.module.purap.document.service.PurapService;
024 import org.kuali.kfs.module.purap.document.service.PurchasingService;
025 import org.kuali.kfs.sys.context.SpringContext;
026 import org.kuali.kfs.sys.document.validation.GenericValidation;
027 import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent;
028 import org.kuali.rice.kns.bo.Parameter;
029 import org.kuali.rice.kns.service.ParameterService;
030
031 public class PurchasingAddCapitalAssetLocationValidation extends GenericValidation {
032
033 protected CapitalAssetLocation location;
034 protected ParameterService parameterService;
035 protected PurchasingService purchasingService;
036
037 public boolean validate(AttributedDocumentEvent event) {
038 boolean valid = true;
039 // TODO: Move this into CABModuleService?
040 // Retrieve and evaluate the parameter which determines whether location's address is required.
041 // CHARTS_REQUIRING_LOCATIONS_ADDRESS_ON_(REQUISITION/PURCHASE_ORDER)
042 Map<String, String> fieldValues = new HashMap<String, String>();
043
044 //List<Parameter> results = getParameterService().retrieveParametersGivenLookupCriteria(fieldValues);
045 // If the location's address is required, enforce the validation of the individual fields of the address.
046
047 valid = getPurchasingService().checkCapitalAssetLocation(getLocation());
048 valid &= getPurchasingService().checkValidRoomNumber(getLocation());
049
050 //valid = purchasingService.checkCapitalAssetLocation(getLocation());
051 //valid &= purchasingService.checkValidRoomNumber(getLocation());
052 return valid;
053 }
054
055 public CapitalAssetLocation getLocation() {
056 return location;
057 }
058
059 public void setLocation(CapitalAssetLocation location) {
060 this.location = location;
061 }
062
063 protected ParameterService getParameterService() {
064 if ( parameterService == null ) {
065 parameterService = SpringContext.getBean(ParameterService.class);
066 }
067 return parameterService;
068 }
069
070 protected PurchasingService getPurchasingService() {
071 if ( parameterService == null ) {
072 purchasingService = SpringContext.getBean(PurchasingService.class);
073 }
074 return purchasingService;
075 }
076
077 }