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