1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.select.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.PurapParameterConstants;
22 import org.kuali.ole.module.purap.PurapRuleConstants;
23 import org.kuali.ole.module.purap.document.PurchasingDocument;
24 import org.kuali.ole.module.purap.document.PurchasingDocumentBase;
25 import org.kuali.ole.module.purap.document.validation.impl.PurchasingProcessVendorValidation;
26 import org.kuali.ole.select.service.OleForiegnVendorPhoneNumberService;
27 import org.kuali.ole.sys.OLEConstants;
28 import org.kuali.ole.sys.OLEKeyConstants;
29 import org.kuali.ole.sys.context.SpringContext;
30 import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
31 import org.kuali.ole.sys.service.impl.OleParameterConstants;
32 import org.kuali.ole.vnd.VendorKeyConstants;
33 import org.kuali.ole.vnd.VendorPropertyConstants;
34 import org.kuali.ole.vnd.businessobject.VendorAddress;
35 import org.kuali.ole.vnd.businessobject.VendorDetail;
36 import org.kuali.ole.vnd.businessobject.VendorHeader;
37 import org.kuali.ole.vnd.document.service.VendorService;
38 import org.kuali.rice.coreservice.framework.parameter.ParameterService;
39 import org.kuali.rice.kns.datadictionary.validation.fieldlevel.PhoneNumberValidationPattern;
40 import org.kuali.rice.kns.service.DataDictionaryService;
41 import org.kuali.rice.krad.util.GlobalVariables;
42 import org.kuali.rice.krad.util.MessageMap;
43 import org.kuali.rice.krad.util.ObjectUtils;
44
45 import java.util.ArrayList;
46 import java.util.List;
47
48 public class OlePurchasingProcessVendorValidation extends PurchasingProcessVendorValidation {
49
50 private VendorService vendorService;
51 private ParameterService parameterService;
52
53
54
55
56 @Override
57 public boolean validate(AttributedDocumentEvent event) {
58 boolean valid = true;
59 PurchasingDocument purDocument = (PurchasingDocument) event.getDocument();
60 MessageMap errorMap = GlobalVariables.getMessageMap();
61 errorMap.clearErrorPath();
62 errorMap.addToErrorPath(PurapConstants.VENDOR_ERRORS);
63 VendorDetail vendorDetail = vendorService.getVendorDetail(purDocument.getVendorHeaderGeneratedIdentifier(), purDocument.getVendorDetailAssignedIdentifier());
64 if (ObjectUtils.isNull(vendorDetail)) {
65 return valid;
66 }
67 VendorHeader vendorHeader = vendorDetail.getVendorHeader();
68
69
70
71
72
73
74
75 if (vendorDetail.isVendorDebarred()) {
76 if (parameterService.getParameterValueAsBoolean(OLEConstants.OptionalModuleNamespaces.PURCHASING_ACCOUNTS_PAYABLE, "Requisition", PurapParameterConstants.SHOW_DEBARRED_VENDOR_WARNING_IND)) {
77 if (StringUtils.isEmpty(((PurchasingDocumentBase) purDocument).getJustification())) {
78 errorMap.putWarning(VendorPropertyConstants.VENDOR_NAME, PurapKeyConstants.WARNING_DEBARRED_VENDOR, vendorDetail.getVendorName());
79 valid &= false;
80 }
81 } else {
82 errorMap.putError(VendorPropertyConstants.VENDOR_NAME, PurapKeyConstants.ERROR_DEBARRED_VENDOR);
83 valid &= false;
84 }
85 }
86
87
88 List<String> allowedVendorTypes = new ArrayList<String>(parameterService.getParameterValuesAsString(OleParameterConstants.PURCHASING_DOCUMENT.class, PurapRuleConstants.PURAP_VENDOR_TYPE_ALLOWED_ON_REQ_AND_PO));
89 if (allowedVendorTypes != null && !allowedVendorTypes.isEmpty()) {
90 if (ObjectUtils.isNotNull(vendorHeader) && ObjectUtils.isNotNull(vendorHeader.getVendorTypeCode()) && !allowedVendorTypes.contains(vendorHeader.getVendorTypeCode())) {
91 valid &= false;
92 errorMap.putError(VendorPropertyConstants.VENDOR_NAME, PurapKeyConstants.ERROR_INVALID_VENDOR_TYPE);
93 }
94 }
95
96 if (purDocument.getRequisitionSourceCode() != null && !purDocument.getRequisitionSourceCode().equals(PurapConstants.RequisitionSources.B2B)) {
97
98
99
100 if (purDocument.getVendorHeaderGeneratedIdentifier() != null && purDocument.getPurchaseOrderTransmissionMethodCode().equals(PurapConstants.POTransmissionMethods.FAX) && StringUtils.isBlank(purDocument.getVendorFaxNumber())) {
101 valid &= false;
102 String attributeLabel = SpringContext.getBean(DataDictionaryService.class).
103 getDataDictionary().getBusinessObjectEntry(VendorAddress.class.getName()).
104 getAttributeDefinition(VendorPropertyConstants.VENDOR_FAX_NUMBER).getLabel();
105 errorMap.putError(VendorPropertyConstants.VENDOR_FAX_NUMBER, OLEKeyConstants.ERROR_REQUIRED, attributeLabel);
106 }
107 boolean foriegnVendor = vendorHeader.getVendorForeignIndicator();
108 if (StringUtils.isNotBlank(purDocument.getVendorFaxNumber())) {
109 PhoneNumberValidationPattern phonePattern = new PhoneNumberValidationPattern();
110 if (foriegnVendor) {
111 if (StringUtils.isNotEmpty(purDocument.getVendorFaxNumber()) && !SpringContext.getBean(OleForiegnVendorPhoneNumberService.class).isValidForiegnVendorPhoneNumber(purDocument.getVendorFaxNumber())) {
112 GlobalVariables.getMessageMap().putError(VendorPropertyConstants.VENDOR_FAX_NUMBER, VendorKeyConstants.ERROR_FORIEGN_VENDOR_FAX_NUMBER);
113 valid &= false;
114 }
115 } else {
116 if (!phonePattern.matches(purDocument.getVendorFaxNumber())) {
117 valid &= false;
118 errorMap.putError(VendorPropertyConstants.VENDOR_FAX_NUMBER, PurapKeyConstants.ERROR_FAX_NUMBER_INVALID);
119 }
120 }
121 }
122 }
123
124
125 if (!vendorDetail.isActiveIndicator()) {
126 valid &= false;
127 errorMap.putError(VendorPropertyConstants.VENDOR_NAME, PurapKeyConstants.ERROR_INACTIVE_VENDOR);
128 }
129
130 errorMap.clearErrorPath();
131 return valid;
132
133 }
134
135
136
137
138
139
140 @Override
141 public VendorService getVendorService() {
142 return vendorService;
143 }
144
145
146
147
148
149
150 @Override
151 public void setVendorService(VendorService vendorService) {
152 this.vendorService = vendorService;
153 }
154
155
156
157
158
159
160 @Override
161 public ParameterService getParameterService() {
162 return parameterService;
163 }
164
165
166
167
168
169
170 @Override
171 public void setParameterService(ParameterService parameterService) {
172 this.parameterService = parameterService;
173 }
174
175
176 }