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 org.apache.commons.lang.StringUtils; 019 import org.kuali.kfs.module.purap.PurapKeyConstants; 020 import org.kuali.kfs.module.purap.PurapPropertyConstants; 021 import org.kuali.kfs.module.purap.businessobject.PurchaseOrderVendorQuote; 022 import org.kuali.kfs.module.purap.document.PurchaseOrderDocument; 023 import org.kuali.kfs.sys.KFSKeyConstants; 024 import org.kuali.kfs.sys.document.validation.GenericValidation; 025 import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent; 026 import org.kuali.kfs.vnd.businessobject.VendorDetail; 027 import org.kuali.kfs.vnd.document.service.VendorService; 028 import org.kuali.rice.kns.util.GlobalVariables; 029 030 /** 031 * A validation that checks whether the given accounting line is accessible to the given user or not 032 */ 033 public class PurchaseOrderAddQuoteToVendorValidation extends GenericValidation { 034 035 private PurchaseOrderDocument accountingDocumentForValidation; 036 private PurchaseOrderVendorQuote vendorQuote; 037 private VendorService vendorService; 038 039 /** 040 * Applies rules for validation of the Split of PO and PO child documents 041 * 042 * @param document A PurchaseOrderDocument (or one of its children) 043 * @return True if all relevant validation rules are passed. 044 */ 045 public boolean validate(AttributedDocumentEvent event) { 046 boolean valid = true; 047 valid &= isVendorQuoteActiveNotDebarredVendor(vendorQuote.getVendorHeaderGeneratedIdentifier(), vendorQuote.getVendorDetailAssignedIdentifier()); 048 valid &= vendorQuoteHasRequiredFields(vendorQuote); 049 return valid; 050 } 051 052 protected boolean isVendorQuoteActiveNotDebarredVendor(Integer vendorHeaderGeneratedIdentifier, Integer vendorDetailAssignedIdentifer) { 053 VendorDetail vendorDetail = vendorService.getVendorDetail(vendorHeaderGeneratedIdentifier, vendorDetailAssignedIdentifer); 054 if (vendorDetail != null) { 055 if (!vendorDetail.isActiveIndicator()) { 056 GlobalVariables.getMessageMap().putError(PurapPropertyConstants.NEW_PURCHASE_ORDER_VENDOR_QUOTE_VENDOR_NAME, PurapKeyConstants.ERROR_PURCHASE_ORDER_QUOTE_INACTIVE_VENDOR); 057 return false; 058 } 059 else if (vendorDetail.isVendorDebarred()) { 060 GlobalVariables.getMessageMap().putError(PurapPropertyConstants.NEW_PURCHASE_ORDER_VENDOR_QUOTE_VENDOR_NAME, PurapKeyConstants.ERROR_PURCHASE_ORDER_QUOTE_DEBARRED_VENDOR); 061 return false; 062 } 063 } 064 return true; 065 } 066 067 protected boolean vendorQuoteHasRequiredFields (PurchaseOrderVendorQuote vendorQuote) { 068 boolean valid = true; 069 if ( StringUtils.isBlank(vendorQuote.getVendorName()) ) { 070 GlobalVariables.getMessageMap().putError(PurapPropertyConstants.NEW_PURCHASE_ORDER_VENDOR_QUOTE_VENDOR_NAME, KFSKeyConstants.ERROR_REQUIRED, "Vendor Name"); 071 valid = false; 072 } 073 if (StringUtils.isBlank(vendorQuote.getVendorLine1Address())) { 074 GlobalVariables.getMessageMap().putError(PurapPropertyConstants.NEW_PURCHASE_ORDER_VENDOR_QUOTE_VENDOR_LINE_1_ADDR, KFSKeyConstants.ERROR_REQUIRED, "Vendor Line 1 Address"); 075 valid = false; 076 } 077 if (StringUtils.isBlank(vendorQuote.getVendorCityName())) { 078 GlobalVariables.getMessageMap().putError(PurapPropertyConstants.NEW_PURCHASE_ORDER_VENDOR_QUOTE_VENDOR_CITY_NAME, KFSKeyConstants.ERROR_REQUIRED, "Vendor City Name"); 079 valid = false; 080 } 081 return valid; 082 } 083 084 public PurchaseOrderDocument getAccountingDocumentForValidation() { 085 return accountingDocumentForValidation; 086 } 087 088 public void setAccountingDocumentForValidation(PurchaseOrderDocument accountingDocumentForValidation) { 089 this.accountingDocumentForValidation = accountingDocumentForValidation; 090 } 091 092 public PurchaseOrderVendorQuote getVendorQuote() { 093 return vendorQuote; 094 } 095 096 public void setVendorQuote(PurchaseOrderVendorQuote vendorQuote) { 097 this.vendorQuote = vendorQuote; 098 } 099 100 public VendorService getVendorService() { 101 return vendorService; 102 } 103 104 public void setVendorService(VendorService vendorService) { 105 this.vendorService = vendorService; 106 } 107 108 } 109