1 package org.kuali.ole.vnd.document.validation.impl;
2
3 import org.apache.commons.lang.StringUtils;
4 import org.kuali.ole.select.document.OlePurchaseOrderDocument;
5 import org.kuali.ole.select.document.OleRequisitionDocument;
6 import org.kuali.ole.vnd.VendorKeyConstants;
7 import org.kuali.ole.vnd.VendorPropertyConstants;
8 import org.kuali.ole.vnd.businessobject.VendorAlias;
9 import org.kuali.ole.vnd.businessobject.VendorDetail;
10 import org.kuali.ole.vnd.businessobject.VendorTransmissionFormatDetail;
11 import org.kuali.rice.kns.document.MaintenanceDocument;
12 import org.kuali.rice.krad.service.KRADServiceLocator;
13
14 import java.util.ArrayList;
15 import java.util.HashMap;
16 import java.util.List;
17 import java.util.Map;
18
19
20
21
22
23
24
25
26 public class OleVendorRule extends VendorRule {
27
28 @Override
29 protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) {
30 boolean valid = processValidation(document);
31 VendorDetail vendorDetail = (VendorDetail)document.getNewMaintainableObject().getDataObject();
32 List<VendorTransmissionFormatDetail> vendorTransmissionFormatDetailList = vendorDetail.getVendorTransmissionFormat();
33 List formatId = new ArrayList();
34 for(VendorTransmissionFormatDetail vendorTransmissionFormatDetail : vendorTransmissionFormatDetailList) {
35 if (formatId.contains(vendorTransmissionFormatDetail.getVendorTransmissionFormatId())) {
36 putFieldError(VendorPropertyConstants.VENDOR_TRANSMISSION_FORMAT, VendorKeyConstants.OLE_VENDOR_DUPLICATE_TRANS_FORMAT);
37 valid &= false;
38 }
39 formatId.add(vendorTransmissionFormatDetail.getVendorTransmissionFormatId());
40 }
41 HashMap vendor = new HashMap();
42 vendor.put("vendorHeaderGeneratedIdentifier", vendorDetail.getVendorHeaderGeneratedIdentifier());
43 vendor.put("vendorDetailAssignedIdentifier", vendorDetail.getVendorDetailAssignedIdentifier());
44 List<OleRequisitionDocument> oleRequisitionDocuments = (List<OleRequisitionDocument>)KRADServiceLocator.getBusinessObjectService().findMatching(OleRequisitionDocument.class, vendor);
45 List<OlePurchaseOrderDocument> purchaseOrderDocuments = (List<OlePurchaseOrderDocument>)KRADServiceLocator.getBusinessObjectService().findMatching(OlePurchaseOrderDocument.class, vendor);
46 if(oleRequisitionDocuments.size()>0){
47 putFieldError(VendorPropertyConstants.VENDOR_ACTIVE_INDICATOR, VendorKeyConstants.OLE_VENDOR_REQUISITION_LINKED);
48 }
49 if(purchaseOrderDocuments.size()>0){
50 putFieldError(VendorPropertyConstants.VENDOR_ACTIVE_INDICATOR, VendorKeyConstants.OLE_VENDOR_PURCHSEORDER_LINKED);
51 }
52 vendor = new HashMap();
53 vendor.put("gokbId", vendorDetail.getGokbId());
54 List<VendorDetail> vendorDetails = (List<VendorDetail>)KRADServiceLocator.getBusinessObjectService().findMatching(VendorDetail.class, vendor);
55 if (vendorDetail.getVendorHeaderGeneratedIdentifier() == null && vendorDetail.getVendorDetailAssignedIdentifier() == null) {
56 if (vendorDetails.size() > 0) {
57 putFieldError(VendorPropertyConstants.VENDOR_GOKB_ID, VendorKeyConstants.OLE_VENDOR_GOKB_EXISTS);
58 }
59 } else {
60 if (vendorDetails.size() > 0) {
61
62 }
63 }
64 return valid & super.processCustomRouteDocumentBusinessRules(document);
65 }
66
67 private boolean processValidation(MaintenanceDocument document) {
68 boolean valid = true;
69 VendorDetail vendorDetail = (VendorDetail) document.getNewMaintainableObject().getDataObject();
70 valid &= processExternalVendorCode(vendorDetail);
71
72 return valid;
73 }
74
75 protected boolean processExternalVendorCode(VendorDetail vendorDetail) {
76 boolean valid = true;
77 List<VendorAlias> vendorAliases = vendorDetail.getVendorAliases();
78 List<String> aliasList=new ArrayList<>();
79 if(vendorAliases.size()>0) {
80 for(VendorAlias vendorAlias : vendorAliases) {
81 if(!aliasList.contains(vendorAlias.getVendorAliasType().getAliasType()))
82 {
83 aliasList.add(vendorAlias.getVendorAliasType().getAliasType());
84 } else{
85 putFieldError(VendorPropertyConstants.VENDOR_SEARCH_ALIASES, VendorKeyConstants.OLE_VENDOR_DUPLICATE_ALIAS_NAME);
86 valid &= false;
87 }
88 }
89 }
90 if (StringUtils.isBlank(vendorDetail.getVendorName())) {
91
92
93 if (StringUtils.isBlank(vendorDetail.getVendorFirstName()) && StringUtils.isBlank(vendorDetail.getVendorLastName())) {
94
95
96
97 putFieldError(VendorPropertyConstants.VENDOR_ALIAS_NAME, VendorKeyConstants.OLE_VENDOR_EMPTY_NAME);
98 valid &= false;
99 }
100
101
102 }
103
104 return valid;
105 }
106 }