1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
45
46
47
48
49
50
51
52
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 }