View Javadoc
1   /*
2    * Copyright 2008-2009 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.module.purap.document.validation.impl;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.ole.module.purap.PurapKeyConstants;
20  import org.kuali.ole.module.purap.PurapPropertyConstants;
21  import org.kuali.ole.module.purap.businessobject.PurchaseOrderVendorQuote;
22  import org.kuali.ole.module.purap.document.PurchaseOrderDocument;
23  import org.kuali.ole.sys.OLEKeyConstants;
24  import org.kuali.ole.sys.document.validation.GenericValidation;
25  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
26  import org.kuali.ole.vnd.businessobject.VendorDetail;
27  import org.kuali.ole.vnd.document.service.VendorService;
28  import org.kuali.rice.krad.util.GlobalVariables;
29  
30  /**
31   * A validation that checks whether the given accounting line is accessible to the given user or not
32   */
33  public class PurchaseOrderAddQuoteToVendorValidation extends GenericValidation {
34  
35      private PurchaseOrderDocument accountingDocumentForValidation;
36      private PurchaseOrderVendorQuote vendorQuote;
37      private VendorService vendorService;
38  
39      /**
40       * Applies rules for validation of the Split of PO and PO child documents
41       *
42       * @param document A PurchaseOrderDocument (or one of its children)
43       * @return True if all relevant validation rules are passed.
44       */
45      public boolean validate(AttributedDocumentEvent event) {
46          boolean valid = true;
47          valid &= isVendorQuoteActiveNotDebarredVendor(vendorQuote.getVendorHeaderGeneratedIdentifier(), vendorQuote.getVendorDetailAssignedIdentifier());
48          valid &= vendorQuoteHasRequiredFields(vendorQuote);
49          return valid;
50      }
51  
52      protected boolean isVendorQuoteActiveNotDebarredVendor(Integer vendorHeaderGeneratedIdentifier, Integer vendorDetailAssignedIdentifer) {
53          VendorDetail vendorDetail = vendorService.getVendorDetail(vendorHeaderGeneratedIdentifier, vendorDetailAssignedIdentifer);
54          if (vendorDetail != null) {
55              if (!vendorDetail.isActiveIndicator()) {
56                  GlobalVariables.getMessageMap().putError(PurapPropertyConstants.NEW_PURCHASE_ORDER_VENDOR_QUOTE_VENDOR_NAME, PurapKeyConstants.ERROR_PURCHASE_ORDER_QUOTE_INACTIVE_VENDOR);
57                  return false;
58              } else if (vendorDetail.isVendorDebarred()) {
59                  GlobalVariables.getMessageMap().putError(PurapPropertyConstants.NEW_PURCHASE_ORDER_VENDOR_QUOTE_VENDOR_NAME, PurapKeyConstants.ERROR_PURCHASE_ORDER_QUOTE_DEBARRED_VENDOR);
60                  return false;
61              }
62          }
63          return true;
64      }
65  
66      protected boolean vendorQuoteHasRequiredFields(PurchaseOrderVendorQuote vendorQuote) {
67          boolean valid = true;
68          if (StringUtils.isBlank(vendorQuote.getVendorName())) {
69              GlobalVariables.getMessageMap().putError(PurapPropertyConstants.NEW_PURCHASE_ORDER_VENDOR_QUOTE_VENDOR_NAME, OLEKeyConstants.ERROR_REQUIRED, "Vendor Name");
70              valid = false;
71          }
72          if (StringUtils.isBlank(vendorQuote.getVendorLine1Address())) {
73              GlobalVariables.getMessageMap().putError(PurapPropertyConstants.NEW_PURCHASE_ORDER_VENDOR_QUOTE_VENDOR_LINE_1_ADDR, OLEKeyConstants.ERROR_REQUIRED, "Vendor Line 1 Address");
74              valid = false;
75          }
76          if (StringUtils.isBlank(vendorQuote.getVendorCityName())) {
77              GlobalVariables.getMessageMap().putError(PurapPropertyConstants.NEW_PURCHASE_ORDER_VENDOR_QUOTE_VENDOR_CITY_NAME, OLEKeyConstants.ERROR_REQUIRED, "Vendor City Name");
78              valid = false;
79          }
80          return valid;
81      }
82  
83      public PurchaseOrderDocument getAccountingDocumentForValidation() {
84          return accountingDocumentForValidation;
85      }
86  
87      public void setAccountingDocumentForValidation(PurchaseOrderDocument accountingDocumentForValidation) {
88          this.accountingDocumentForValidation = accountingDocumentForValidation;
89      }
90  
91      public PurchaseOrderVendorQuote getVendorQuote() {
92          return vendorQuote;
93      }
94  
95      public void setVendorQuote(PurchaseOrderVendorQuote vendorQuote) {
96          this.vendorQuote = vendorQuote;
97      }
98  
99      public VendorService getVendorService() {
100         return vendorService;
101     }
102 
103     public void setVendorService(VendorService vendorService) {
104         this.vendorService = vendorService;
105     }
106 
107 }
108