1 package org.kuali.ole.vnd.document.validation.impl;
2
3 import org.apache.commons.lang.StringUtils;
4 import org.kuali.ole.vnd.VendorKeyConstants;
5 import org.kuali.ole.vnd.VendorPropertyConstants;
6 import org.kuali.ole.vnd.businessobject.VendorAlias;
7 import org.kuali.ole.vnd.businessobject.VendorDetail;
8 import org.kuali.rice.kns.document.MaintenanceDocument;
9 import org.kuali.rice.krad.util.GlobalVariables;
10 import org.kuali.rice.krad.util.ObjectUtils;
11
12 import java.lang.reflect.Array;
13 import java.util.ArrayList;
14 import java.util.List;
15
16
17
18
19
20
21
22
23 public class OleVendorRule extends VendorRule {
24
25 @Override
26 protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) {
27 boolean valid = processValidation(document);
28 return valid & super.processCustomRouteDocumentBusinessRules(document);
29 }
30
31 private boolean processValidation(MaintenanceDocument document) {
32 boolean valid = true;
33 VendorDetail vendorDetail = (VendorDetail) document.getNewMaintainableObject().getDataObject();
34 valid &= processExternalVendorCode(vendorDetail);
35
36 return valid;
37 }
38
39 protected boolean processExternalVendorCode(VendorDetail vendorDetail) {
40 boolean valid = true;
41 List<VendorAlias> vendorAliases = vendorDetail.getVendorAliases();
42 List<String> aliasList=new ArrayList<>();
43 if(vendorAliases.size()>0) {
44 for(VendorAlias vendorAlias : vendorAliases) {
45 if(!aliasList.contains(vendorAlias.getVendorAliasType().getAliasType()))
46 {
47 aliasList.add(vendorAlias.getVendorAliasType().getAliasType());
48 } else{
49 putFieldError(VendorPropertyConstants.VENDOR_SEARCH_ALIASES, VendorKeyConstants.OLE_VENDOR_DUPLICATE_ALIAS_NAME);
50 valid &= false;
51 }
52 }
53 }
54 if (StringUtils.isBlank(vendorDetail.getVendorName())) {
55
56
57 if (StringUtils.isBlank(vendorDetail.getVendorFirstName()) && StringUtils.isBlank(vendorDetail.getVendorLastName())) {
58
59
60
61 putFieldError(VendorPropertyConstants.VENDOR_ALIAS_NAME, VendorKeyConstants.OLE_VENDOR_EMPTY_NAME);
62 valid &= false;
63 }
64
65
66 }
67
68 return valid;
69 }
70 }