View Javadoc
1   /*
2    * Copyright 2008 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.PurapConstants;
20  import org.kuali.ole.module.purap.PurapConstants.PODocumentsStrings;
21  import org.kuali.ole.module.purap.PurapKeyConstants;
22  import org.kuali.ole.module.purap.PurapPropertyConstants;
23  import org.kuali.ole.module.purap.document.PurchaseOrderDocument;
24  import org.kuali.ole.module.purap.document.PurchasingAccountsPayableDocument;
25  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
26  import org.kuali.ole.vnd.VendorConstants.VendorTypes;
27  import org.kuali.ole.vnd.VendorPropertyConstants;
28  import org.kuali.ole.vnd.businessobject.VendorDetail;
29  import org.kuali.rice.kns.service.DataDictionaryService;
30  import org.kuali.rice.krad.util.GlobalVariables;
31  import org.kuali.rice.krad.util.MessageMap;
32  import org.kuali.rice.krad.util.ObjectUtils;
33  
34  public class PurchaseOrderProcessVendorValidation extends PurchasingProcessVendorValidation {
35  
36      private DataDictionaryService dataDictionaryService;
37  
38      /**
39       * Validation for the Stipulation tab.
40       *
41       * @param poDocument the purchase order document to be validated
42       * @return boolean false if the vendor stipulation description is blank.
43       */
44      public boolean validate(AttributedDocumentEvent event) {
45          boolean valid = super.validate(event);
46          PurchasingAccountsPayableDocument purapDocument = (PurchasingAccountsPayableDocument) event.getDocument();
47          PurchaseOrderDocument poDocument = (PurchaseOrderDocument) purapDocument;
48          MessageMap errorMap = GlobalVariables.getMessageMap();
49          errorMap.clearErrorPath();
50          errorMap.addToErrorPath(PurapConstants.VENDOR_ERRORS);
51  
52          // check to see if the vendor exists in the database, i.e. its ID is not null
53          Integer vendorHeaderID = poDocument.getVendorHeaderGeneratedIdentifier();
54          if (ObjectUtils.isNull(vendorHeaderID)) {
55              valid = false;
56              errorMap.putError(VendorPropertyConstants.VENDOR_NAME, PurapKeyConstants.ERROR_NONEXIST_VENDOR);
57          }
58  
59          // vendor active validation...
60          VendorDetail vendorDetail = super.getVendorService().getVendorDetail(poDocument.getVendorHeaderGeneratedIdentifier(), poDocument.getVendorDetailAssignedIdentifier());
61          if (ObjectUtils.isNull(vendorDetail))
62              return valid;
63  
64          // make sure that the vendor is active
65          if (!vendorDetail.isActiveIndicator()) {
66              valid &= false;
67              errorMap.putError(VendorPropertyConstants.VENDOR_NAME, PurapKeyConstants.ERROR_INACTIVE_VENDOR);
68          }
69  
70          // validate vendor address
71          super.getPostalCodeValidationService().validateAddress(poDocument.getVendorCountryCode(), poDocument.getVendorStateCode(), poDocument.getVendorPostalCode(), PurapPropertyConstants.VENDOR_STATE_CODE, PurapPropertyConstants.VENDOR_POSTAL_CODE);
72  
73          // Do checks for alternate payee vendor.
74          Integer alternateVendorHdrGeneratedId = poDocument.getAlternateVendorHeaderGeneratedIdentifier();
75          Integer alternateVendorHdrDetailAssignedId = poDocument.getAlternateVendorDetailAssignedIdentifier();
76  
77          VendorDetail alternateVendor = super.getVendorService().getVendorDetail(alternateVendorHdrGeneratedId, alternateVendorHdrDetailAssignedId);
78  
79          if (alternateVendor != null) {
80              if (alternateVendor.isVendorDebarred()) {
81                  errorMap.putError(PurapPropertyConstants.ALTERNATE_VENDOR_NAME, PurapKeyConstants.ERROR_PURCHASE_ORDER_ALTERNATE_VENDOR_DEBARRED);
82                  valid &= false;
83              }
84              if (StringUtils.equals(alternateVendor.getVendorHeader().getVendorTypeCode(), VendorTypes.DISBURSEMENT_VOUCHER)) {
85                  errorMap.putError(PurapPropertyConstants.ALTERNATE_VENDOR_NAME, PurapKeyConstants.ERROR_PURCHASE_ORDER_ALTERNATE_VENDOR_DV_TYPE);
86                  valid &= false;
87              }
88              if (!alternateVendor.isActiveIndicator()) {
89                  errorMap.putError(PurapPropertyConstants.ALTERNATE_VENDOR_NAME, PurapKeyConstants.ERROR_PURCHASE_ORDER_ALTERNATE_VENDOR_INACTIVE, PODocumentsStrings.ALTERNATE_PAYEE_VENDOR);
90                  valid &= false;
91              }
92          }
93  
94          errorMap.clearErrorPath();
95          return valid;
96      }
97  
98      public DataDictionaryService getDataDictionaryService() {
99          return dataDictionaryService;
100     }
101 
102     public void setDataDictionaryService(DataDictionaryService dataDictionaryService) {
103         this.dataDictionaryService = dataDictionaryService;
104     }
105 }