View Javadoc
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   * Created with IntelliJ IDEA.
21   * User: arjuns
22   * Date: 7/15/13
23   * Time: 6:27 PM
24   * To change this template use File | Settings | File Templates.
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                  //vendorDetails.get(0).isActiveIndicator()
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              // At least one of the three vendor name fields must be filled in.
92  
93              if (StringUtils.isBlank(vendorDetail.getVendorFirstName()) && StringUtils.isBlank(vendorDetail.getVendorLastName())) {
94  //
95  //                GlobalVariables.getMessageMap().putErrorForSectionId("OleCirculationDesk-Locations", OLEConstants.OleCirculationDesk.OLE_VENDOR_DUPLICATE_ALIAS_NAME);
96  //                return getUIFModelAndView(form);
97                  putFieldError(VendorPropertyConstants.VENDOR_ALIAS_NAME, VendorKeyConstants.OLE_VENDOR_EMPTY_NAME);
98                  valid &= false;
99              }
100             // If either the vendor first name or the vendor last name have been entered, the other must be entered.
101 
102         }
103 
104         return valid;
105     }
106 }