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.PurapKeyConstants;
21  import org.kuali.ole.module.purap.PurapPropertyConstants;
22  import org.kuali.ole.module.purap.document.PurchasingDocument;
23  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
24  import org.kuali.ole.sys.service.PostalCodeValidationService;
25  import org.kuali.ole.vnd.businessobject.CampusParameter;
26  import org.kuali.rice.core.api.datetime.DateTimeService;
27  import org.kuali.rice.krad.service.BusinessObjectService;
28  import org.kuali.rice.krad.util.GlobalVariables;
29  
30  import java.util.Collections;
31  
32  public class PurchasingDeliveryValidation extends PurchasingProcessRequestorPhoneAndEmailAddressValidation {
33  
34      protected DateTimeService dateTimeService;
35      protected BusinessObjectService businessObjectService;
36      protected PostalCodeValidationService postalCodeValidationService;
37  
38      @Override
39      public boolean validate(AttributedDocumentEvent event) {
40          boolean valid = true;
41          PurchasingDocument purDocument = (PurchasingDocument) event.getDocument();
42  
43          GlobalVariables.getMessageMap().addToErrorPath(PurapConstants.DELIVERY_TAB_ERRORS);        
44          /*//perform the validation against phone Number
45          if (StringUtils.isNotBlank(purDocument.getRequestorPersonPhoneNumber())) {
46              if (!validatePhoneNumber(purDocument.getRequestorPersonPhoneNumber())) {
47                  valid &= false;
48                  GlobalVariables.getMessageMap().putError(PurapPropertyConstants.REQUESTOR_PERSON_PHONE_NUMBER, PurapKeyConstants.ERROR_INVALID_PH0NE_NUMBER);
49              }
50          }*/
51  
52          //perform the validation against email address
53          if (StringUtils.isNotBlank(purDocument.getRequestorPersonEmailAddress())) {
54              if (!validateEmailAddress(purDocument.getRequestorPersonEmailAddress())) {
55                  valid &= false;
56                  GlobalVariables.getMessageMap().putError(PurapPropertyConstants.REQUESTOR_PERSON_EMAIL_ADDRESS, PurapKeyConstants.ERROR_INVALID_EMAIL_ADDRESS);
57              }
58          }
59  
60          postalCodeValidationService.validateAddress(purDocument.getDeliveryCountryCode(), purDocument.getDeliveryStateCode(), purDocument.getDeliveryPostalCode(), PurapPropertyConstants.DELIVERY_STATE_CODE, PurapPropertyConstants.DELIVERY_POSTAL_CODE);
61  
62          int match = businessObjectService.countMatching(CampusParameter.class, Collections.singletonMap("campusCode", purDocument.getDeliveryCampusCode()));
63          if (match < 1) {
64              valid = false;
65              GlobalVariables.getMessageMap().putError(PurapPropertyConstants.DELIVERY_CAMPUS_CODE, PurapKeyConstants.ERROR_DELIVERY_CAMPUS_INVALID);
66          }
67  
68          GlobalVariables.getMessageMap().clearErrorPath();
69          return valid;
70      }
71  
72      public void setDateTimeService(DateTimeService dateTimeService) {
73          this.dateTimeService = dateTimeService;
74      }
75  
76      public void setBusinessObjectService(BusinessObjectService businessObjectService) {
77          this.businessObjectService = businessObjectService;
78      }
79  
80      public void setPostalCodeValidationService(PostalCodeValidationService postalCodeValidationService) {
81          this.postalCodeValidationService = postalCodeValidationService;
82      }
83  }