View Javadoc
1   /*
2    * Copyright 2011 The Kuali Foundation.
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.select.batch.service.impl;
17  
18  import org.kuali.ole.module.purap.PurapConstants.RequisitionStatuses;
19  import org.kuali.ole.module.purap.businessobject.PurApAccountingLine;
20  import org.kuali.ole.module.purap.businessobject.RequisitionAccount;
21  import org.kuali.ole.module.purap.businessobject.RequisitionItem;
22  import org.kuali.ole.module.purap.document.RequisitionDocument;
23  import org.kuali.ole.select.OleSelectConstant;
24  import org.kuali.ole.select.batch.service.OleRequisitionCreateDocumentService;
25  import org.kuali.ole.select.batch.service.RequisitionCreateDocumentService;
26  import org.kuali.ole.select.businessobject.*;
27  import org.kuali.ole.select.document.OleRequisitionDocument;
28  import org.kuali.ole.select.document.service.OleRequestSourceService;
29  import org.kuali.ole.select.document.service.OleRequestorService;
30  import org.kuali.ole.select.service.BibInfoService;
31  import org.kuali.ole.select.validation.BibInfoValidation;
32  import org.kuali.ole.select.validation.StandardNumberValidation;
33  import org.kuali.ole.select.validation.impl.BibinfoValidationImpl;
34  import org.kuali.ole.select.validation.impl.StandardNumberValidationImpl;
35  import org.kuali.ole.sys.OLEConstants;
36  import org.kuali.ole.sys.OLEConstants.FinancialDocumentTypeCodes;
37  import org.kuali.ole.sys.businessobject.Building;
38  import org.kuali.ole.sys.context.SpringContext;
39  import org.kuali.ole.vnd.VendorConstants;
40  import org.kuali.ole.vnd.businessobject.VendorAddress;
41  import org.kuali.ole.vnd.businessobject.VendorContract;
42  import org.kuali.ole.vnd.businessobject.VendorDetail;
43  import org.kuali.ole.vnd.document.service.VendorService;
44  import org.kuali.rice.core.api.config.property.ConfigurationService;
45  import org.kuali.rice.core.api.util.type.KualiDecimal;
46  import org.kuali.rice.kew.api.exception.WorkflowException;
47  import org.kuali.rice.krad.service.BusinessObjectService;
48  import org.kuali.rice.krad.service.DocumentService;
49  import org.kuali.rice.krad.util.ObjectUtils;
50  
51  import java.math.BigDecimal;
52  import java.util.*;
53  
54  public class OleRequisitionCreateDocumentServiceImpl extends RequisitionCreateDocumentServiceImpl implements OleRequisitionCreateDocumentService {
55  
56      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OleRequisitionCreateDocumentServiceImpl.class);
57  
58      protected RequisitionCreateDocumentService requisitionCreateDocumentService;
59      protected OleRequestorService oleRequestorService;
60      protected VendorService vendorService;
61      protected OleRequestSourceService oleRequestSourceService;
62      protected BusinessObjectService businessObjectService;
63      protected DocumentService documentService;
64      protected BibInfoService bibInfoService;
65      protected ConfigurationService kualiConfigurationService;
66      protected List reqList;
67  
68      public RequisitionCreateDocumentService getRequisitionCreateDocumentService() {
69          return requisitionCreateDocumentService;
70      }
71  
72      public void setRequisitionCreateDocumentService(RequisitionCreateDocumentService requisitionCreateDocumentService) {
73          this.requisitionCreateDocumentService = requisitionCreateDocumentService;
74      }
75  
76      public OleRequestorService getOleRequestorService() {
77          return oleRequestorService;
78      }
79  
80      public void setOleRequestorService(OleRequestorService oleRequestorService) {
81          this.oleRequestorService = oleRequestorService;
82      }
83  
84      public VendorService getVendorService() {
85          return vendorService;
86      }
87  
88      public void setVendorService(VendorService vendorService) {
89          this.vendorService = vendorService;
90      }
91  
92      public OleRequestSourceService getOleRequestSourceService() {
93          return oleRequestSourceService;
94      }
95  
96      public void setOleRequestSourceService(OleRequestSourceService oleRequestSourceService) {
97          this.oleRequestSourceService = oleRequestSourceService;
98      }
99  
100     public BibInfoService getBibInfoService() {
101         return bibInfoService;
102     }
103 
104     public void setBibInfoService(BibInfoService bibInfoService) {
105         this.bibInfoService = bibInfoService;
106     }
107 
108     public BusinessObjectService getBusinessObjectService() {
109         return businessObjectService;
110     }
111 
112     public void setBusinessObjectService(BusinessObjectService businessObjectService) {
113         this.businessObjectService = businessObjectService;
114     }
115 
116     public List getReqList() {
117         return reqList;
118     }
119 
120     public ConfigurationService getConfigurationService() {
121         return kualiConfigurationService;
122     }
123 
124     public void setConfigurationService(ConfigurationService kualiConfigurationService) {
125         this.kualiConfigurationService = kualiConfigurationService;
126     }
127 
128     /**
129      * Set the values for the Requisition Document and save.
130      *
131      * @param bibInfoBeanList ArrayList
132      */
133     public String saveRequisitionDocument(List<BibInfoBean> bibInfoBeanList, boolean vendorRecordMappingFlag) throws Exception {
134         String docNumber = "";
135         vendorService = getVendorService();
136         oleRequestorService = getOleRequestorService();
137         requisitionCreateDocumentService = getRequisitionCreateDocumentService();
138         oleRequestSourceService = getOleRequestSourceService();
139         if (vendorRecordMappingFlag) {
140             reqList = new ArrayList(0);
141             HashMap<String, String> dataMap = new HashMap<String, String>();
142             if (bibInfoBeanList.iterator().hasNext()) {
143                 if (bibInfoBeanList.iterator().next().getRequisitionSource().equals(OleSelectConstant.REQUISITON_SRC_TYPE_MANUALINGEST)) {
144                     dataMap.put(OleSelectConstant.DOC_CATEGORY_TYPE, OleSelectConstant.DOC_CATEGORY_TYPE_ITEM);
145                     bibInfoBeanList = bibInfoService.getUUID(bibInfoBeanList, dataMap);
146                 }
147             }
148             for (BibInfoBean bibInfoBean : bibInfoBeanList) {
149                 StandardNumberValidation validation = new StandardNumberValidationImpl();
150                 BibInfoValidation mandatoryValidation = new BibinfoValidationImpl();
151                 String message = validation.isValidStandardNumbers(bibInfoBean);
152                 message = mandatoryValidation.validateMadatory(bibInfoBean);
153                 if (message.equalsIgnoreCase(OleSelectConstant.STATUS) || message.equals("")) {
154                     OleRequisitionDocument requisitionDocument = createRequisitionDocument();
155                     requisitionDocument.setItems(generateItemList(bibInfoBean));
156                     //requisitionDocument.setBoNotes(generateBoNotesList(bibInfoBean));
157                     requisitionDocument.setRequisitionSourceCode(bibInfoBean.getRequisitionSource());
158                     if (bibInfoBeanList != null && bibInfoBeanList.size() > 0) {
159 
160                         if (bibInfoBean.getPurchaseOrderType() != null) {
161                             requisitionDocument.setPurchaseOrderTypeId(bibInfoBean.getPurchaseOrderType());
162                         } /*else{
163                          requisitionDocument.setPurchaseOrderTypeId("firm_fixed_ybp");
164                      }*/
165                         setDocumentValues(requisitionDocument, bibInfoBean);
166                     }
167                     // requisitionCreateDocumentService.saveRequisitionDocuments(requisitionDocument);
168                     docNumber = requisitionCreateDocumentService.saveRequisitionDocuments(requisitionDocument);
169                     reqList.add(requisitionDocument.getPurapDocumentIdentifier());
170 
171                 } else {
172                     docNumber = message;
173                 }
174             }
175 
176         } else {
177             OleRequisitionDocument requisitionDocument = createRequisitionDocument();
178             requisitionDocument.setItems(generateMultipleItemsForOneRequisition(bibInfoBeanList));
179             if (bibInfoBeanList != null && bibInfoBeanList.size() > 0) {
180                 if (bibInfoBeanList.get(1).getPurchaseOrderType() != null) {
181                     requisitionDocument.setPurchaseOrderTypeId(bibInfoBeanList.get(1).getPurchaseOrderType());
182                 } /*else{
183                  requisitionDocument.setPurchaseOrderTypeId("firm_fixed_ybp");
184              }*/
185 
186                 setDocumentValues(requisitionDocument, bibInfoBeanList.get(1));
187             }
188             docNumber = requisitionCreateDocumentService.saveRequisitionDocuments(requisitionDocument);
189 
190         }
191         return docNumber;
192     }
193 
194     /**
195      * To create the Requisition document object
196      *
197      * @return OleRequisitionDocument
198      */
199     protected OleRequisitionDocument createRequisitionDocument() throws WorkflowException {
200         return (OleRequisitionDocument) SpringContext.getBean(DocumentService.class).getNewDocument(FinancialDocumentTypeCodes.REQUISITION);
201     }
202 
203     /**
204      * To create the requisition document
205      *
206      * @param bibInfoBean BibInfoBean
207      * @return RequisitionDocument
208      */
209     protected RequisitionDocument setDocumentValues(OleRequisitionDocument requisitionDocument, BibInfoBean bibInfoBean) throws Exception {
210         // ******************Document Overview Section******************
211         //requisitionDocument.getDocumentHeader().setDocumentDescription(bibInfoBean.getIsbn());
212         //  requisitionDocument.setStatusCode(PurapConstants.RequisitionStatuses.APPDOC_IN_PROCESS);
213         requisitionDocument.setApplicationDocumentStatus(RequisitionStatuses.APPDOC_IN_PROCESS);
214         requisitionDocument.setVendorPoNumber(bibInfoBean.getYbp());
215         // ******************Financial Document Detail Section******************
216         //requisitionDocument.setFinancialYear(bibInfoBean.getFinancialYear());
217 
218 
219         // ******************Requisition Detail Section******************
220 
221         requisitionDocument.setChartOfAccountsCode(bibInfoBean.getChartOfAccountsCode());
222         requisitionDocument.setOrganizationCode(bibInfoBean.getOrganizationCode());
223         requisitionDocument.setDocumentFundingSourceCode(bibInfoBean.getDocumentFundingSourceCode());
224         requisitionDocument.setUseTaxIndicator(bibInfoBean.isUseTaxIndicator());
225 
226         // ******************Delivery Section******************
227 
228         setDeliveryDetails(requisitionDocument, bibInfoBean);
229         requisitionDocument.setDeliveryCampusCode(bibInfoBean.getDeliveryCampusCode());
230 
231         // ******************Vendor Section******************
232 
233         setVendorDetails(requisitionDocument, bibInfoBean);
234 
235         // ******************Items Section******************
236         // requisitionDocument.setListprice(bibInfoBean.getListprice());
237         // requisitionDocument.setQuantity(bibInfoBean.getQuantity());
238 
239         // ******************Capital Assets Section******************
240         // ******************Payment INfo Section******************
241         if (LOG.isDebugEnabled())
242             LOG.debug("----------Billing Name in OleRequisition--------------" + bibInfoBean.getBillingName());
243         requisitionDocument.setBillingName(bibInfoBean.getBillingName());
244         requisitionDocument.setBillingLine1Address(bibInfoBean.getBillingLine1Address());
245         requisitionDocument.setBillingCityName(bibInfoBean.getBillingCityName());
246         requisitionDocument.setBillingStateCode(bibInfoBean.getBillingStateCode());
247         requisitionDocument.setBillingPostalCode(bibInfoBean.getBillingPostalCode());
248         requisitionDocument.setBillingPhoneNumber(bibInfoBean.getBillingPhoneNumber());
249         requisitionDocument.setBillingCountryCode(bibInfoBean.getBillingCountryCode());
250         requisitionDocument.setDeliveryBuildingRoomNumber(bibInfoBean.getDeliveryBuildingRoomNumber());
251         // ******************Additional Institutional Info Section******************
252 
253         requisitionDocument.setPurchaseOrderTransmissionMethodCode(bibInfoBean.getPurchaseOrderTransmissionMethodCode());
254         requisitionDocument.setPurchaseOrderCostSourceCode(bibInfoBean.getPurchaseOrderCostSourceCode());
255         requisitionDocument.setRequestorPersonName(bibInfoBean.getRequestorPersonName());
256         requisitionDocument.setRequestorPersonPhoneNumber(bibInfoBean.getRequestorPersonPhoneNumber());
257         requisitionDocument.setRequestorPersonEmailAddress(bibInfoBean.getRequestorPersonEmailAddress());
258 
259         // ******************Account Summary Section******************
260         // ******************View Related Documents Section******************
261         // ******************View Payment History Section******************
262         // ******************Notes and Attachments Section******************
263         // ******************Ad Hoc Recipients Section******************
264         // ******************Route Log Section ******************
265 
266 
267         // ******************Common Document Properties..******************
268         //requisitionDocument.setFundcode(bibInfoBean.getAccountNumber());
269         //requisitionDocument.setLocation(bibInfoBean.getLocation());
270         //requsitionDocument.setSubAccountNumber(bibInfoBean.getSubAccountNumber());
271         //requisitionDocument.setRequisitionSourceCode(PurapConstants.RequisitionSources.STANDARD_ORDER);
272         requisitionDocument.setOrganizationAutomaticPurchaseOrderLimit(new KualiDecimal(bibInfoBean.getOrganizationAutomaticPurchaseOrderLimit()));
273         requisitionDocument.setPurchaseOrderAutomaticIndicator(bibInfoBean.isPurchaseOrderAutomaticIndicator());
274         requisitionDocument.setReceivingDocumentRequiredIndicator(bibInfoBean.isReceivingDocumentRequiredIndicator());
275         requisitionDocument.setPaymentRequestPositiveApprovalIndicator(bibInfoBean.isPaymentRequestPositiveApprovalIndicator());
276         
277         /*requisitionDocument.setLicensingRequirementIndicator(bibInfoBean.isLicensingRequirementIndicator());*/
278         /*requisitionDocument.setLicensingRequirementCode(bibInfoBean.getLicensingRequirementCode());*/
279 
280         return requisitionDocument;
281 
282     }
283 
284     /**
285      * To set the delivery details for the Requisition Document
286      *
287      * @param bibInfoBean BibInfoBean
288      * @return requisitionDocument OleRequisitionDocument
289      */
290     private void setDeliveryDetails(OleRequisitionDocument requisitionDocument, BibInfoBean bibInfoBean) {
291         if (LOG.isDebugEnabled())
292             LOG.debug("bibInfoBean.getDeliveryBuildingCode----------->" + bibInfoBean.getDeliveryBuildingCode());
293 
294         if (bibInfoBean.getDeliveryCampusCode() != null && bibInfoBean.getDeliveryBuildingCode() != null) {
295             Building building = vendorService.getBuildingDetails(bibInfoBean.getDeliveryCampusCode(), bibInfoBean.getDeliveryBuildingCode());
296             if (building != null) {
297                 requisitionDocument.setDeliveryBuildingCode(building.getBuildingCode());
298                 requisitionDocument.setDeliveryCampusCode(building.getCampusCode());
299                 requisitionDocument.setDeliveryBuildingLine1Address(building.getBuildingStreetAddress());
300                 requisitionDocument.setDeliveryBuildingName(building.getBuildingName());
301                 requisitionDocument.setDeliveryCityName(building.getBuildingAddressCityName());
302                 requisitionDocument.setDeliveryStateCode(building.getBuildingAddressStateCode());
303                 requisitionDocument.setDeliveryPostalCode(building.getBuildingAddressZipCode());
304                 requisitionDocument.setDeliveryCountryCode(building.getBuildingAddressCountryCode());
305             }
306         }
307         requisitionDocument.setDeliveryToName(bibInfoBean.getDeliveryToName());
308         requisitionDocument.setDeliveryBuildingOtherIndicator(bibInfoBean.isDeliveryBuildingOtherIndicator());
309     }
310 
311     /**
312      * To set the vendor details for the Requisition Document
313      *
314      * @param bibInfoBean BibInfoBean
315      * @return requisitionDocument OleRequisitionDocument
316      */
317     private void setVendorDetails(OleRequisitionDocument requisitionDocument, BibInfoBean bibInfoBean) {
318         if (bibInfoBean.getVendorCode() != null) {
319             VendorDetail vendorDetail = vendorService.getVendorDetail(bibInfoBean.getVendorCode());
320 
321             requisitionDocument.setVendorCustomerNumber(bibInfoBean.getVendorCustomerNumber());
322             requisitionDocument.setVendorNumber(bibInfoBean.getVendorCode());
323             requisitionDocument.setVendorNumber(vendorDetail.getVendorNumber());
324             requisitionDocument.setVendorName(vendorDetail.getVendorName());
325             requisitionDocument.setVendorHeaderGeneratedIdentifier(vendorDetail.getVendorHeaderGeneratedIdentifier());
326             requisitionDocument.setVendorDetailAssignedIdentifier(vendorDetail.getVendorDetailAssignedIdentifier());
327             requisitionDocument.setVendorDetail(vendorDetail);
328 
329             String deliveryCampus = bibInfoBean.getDeliveryCampusCode();
330             Integer headerId = null;
331             Integer detailId = null;
332             int dashInd = vendorDetail.getVendorNumber().indexOf('-');
333             // make sure there's at least one char before and after '-'
334             if (dashInd > 0 && dashInd < vendorDetail.getVendorNumber().length() - 1) {
335                 headerId = new Integer(vendorDetail.getVendorNumber().substring(0, dashInd));
336                 detailId = new Integer(vendorDetail.getVendorNumber().substring(dashInd + 1));
337             }
338             VendorAddress vendorAddress = vendorService.getVendorDefaultAddress(headerId, detailId, VendorConstants.AddressTypes.PURCHASE_ORDER, deliveryCampus);
339             setVendorAddress(vendorAddress, requisitionDocument);
340 
341             List<VendorContract> vendorContracts = vendorDetail.getVendorContracts();
342             for (Iterator<VendorContract> vendorContract = vendorContracts.iterator(); vendorContract.hasNext(); ) {
343                 requisitionDocument.setVendorContractGeneratedIdentifier((vendorContract.next()).getVendorContractGeneratedIdentifier());
344             }
345         }
346 
347     }
348 
349     /**
350      * To generate single Item list for the Requisition Document
351      *
352      * @param bibInfoBean BibInfoBean
353      * @return ArrayList
354      */
355     private List<RequisitionItem> generateItemList(BibInfoBean bibInfoBean) throws Exception {
356         List<RequisitionItem> items = new ArrayList<RequisitionItem>();
357         int itemLineNumber = 1;
358         items.add(createRequisitionItem(bibInfoBean, itemLineNumber));
359         return items;
360     }
361     /*private List<Note> generateBoNotesList(BibInfoBean bibInfoBean) {
362         List<Note> notes = new ArrayList<Note>();
363         notes.add(createNotes(bibInfoBean));                         
364         return notes;
365     }*/
366 
367     /**
368      * To generate multiple Item list for the Requisition Document
369      *
370      * @param bibInfoBeanList List<BibInfoBean>
371      * @return ArrayList
372      */
373     private List<RequisitionItem> generateMultipleItemsForOneRequisition(List<BibInfoBean> bibInfoBeanList) throws Exception {
374         List<RequisitionItem> items = new ArrayList<RequisitionItem>();
375         int itemLineNumber = 0;
376         // set items to document
377         for (BibInfoBean tempBibInfoBean : bibInfoBeanList) {
378             itemLineNumber++;
379             items.add(createRequisitionItem(tempBibInfoBean, itemLineNumber));
380         }
381         return items;
382     }
383 
384     /**
385      * To create the requisition item for the Requisition Document.
386      *
387      * @param bibInfoBean BibInfoBean
388      * @return RequisitionItem
389      */
390     @SuppressWarnings("deprecation")
391     protected RequisitionItem createRequisitionItem(BibInfoBean bibInfoBean, int itemLineNumber) throws Exception {
392         OleRequisitionItem item = new OleRequisitionItem();
393 
394         item.setBibInfoBean(bibInfoBean);
395         item.setItemLineNumber(itemLineNumber);
396         item.setItemUnitOfMeasureCode(bibInfoBean.getUom());
397         item.setItemQuantity(new KualiDecimal(bibInfoBean.getQuantity()));
398         item.setItemDescription(bibInfoBean.getIsbn());
399         item.setItemUnitPrice(new BigDecimal(bibInfoBean.getListprice()));
400         item.setItemTypeCode(bibInfoBean.getItemTypeCode());
401         item.setItemListPrice(new KualiDecimal(bibInfoBean.getListprice()));
402         if (ObjectUtils.isNotNull(bibInfoBean.getTitleId())) {
403             item.setItemTitleId(bibInfoBean.getTitleId());
404         }
405 
406         if (item.getItemType() == null) {
407             org.kuali.ole.module.purap.businessobject.ItemType itemType = businessObjectService.findBySinglePrimaryKey(org.kuali.ole.module.purap.businessobject.ItemType.class, bibInfoBean.getItemTypeCode());
408             item.setItemType(itemType);
409         }
410 
411         RequisitionAccount requisitionAccount = new RequisitionAccount();
412         requisitionAccount.setChartOfAccountsCode(bibInfoBean.getChart());
413         requisitionAccount.setAccountNumber(bibInfoBean.getAccountNumber());
414         requisitionAccount.setFinancialObjectCode(bibInfoBean.getObjectCode());
415         requisitionAccount.setDebitCreditCode(OLEConstants.GL_DEBIT_CODE);
416         if (bibInfoBean.getListprice() != null) {
417             requisitionAccount.setAmount(new KualiDecimal(bibInfoBean.getListprice()));
418         }
419         if (bibInfoBean.getPercent() != null) {
420             requisitionAccount.setAccountLinePercent(new BigDecimal(bibInfoBean.getPercent()));
421         }
422         if (bibInfoBean.getAccountNumber() != null) {
423             List<PurApAccountingLine> sourceAccountingLines = item.getSourceAccountingLines();
424             if (sourceAccountingLines.size() == 0) {
425                 sourceAccountingLines = new ArrayList<PurApAccountingLine>(0);
426             }
427             sourceAccountingLines.add((PurApAccountingLine) requisitionAccount);
428             item.setSourceAccountingLines(sourceAccountingLines);
429         }
430       
431 /*        OleRequestor oleRequestor = checkRequestorExist(bibInfoBean); 
432         if(oleRequestor == null) {
433             
434             oleRequestor =  new OleRequestor();
435             oleRequestor = saveRequestor(bibInfoBean, oleRequestor);
436         }
437         
438         item.setOleRequestor(oleRequestor);
439        
440         item.setRequestorId(oleRequestor.getRequestorId());
441 //        item.setRequestSourceTypeId(oleRequestSourceService.getRequestSourceTypeId(bibInfoBean.getRequestSource()));
442         item.setRequestorFirstName(oleRequestor.getRequestorFirstName());
443        
444         item.setRequestorLastName(oleRequestor.getRequestorLastName());*/
445         item.setRequestorId(bibInfoBean.getRequestorId());
446         item.setRequestSourceUrl(bibInfoBean.getRequestSourceUrl());
447 
448         //getOleRequestorService().saveRequestor(oleRequestor);
449 
450         String requestorType = bibInfoBean.getRequestorType();
451 
452         if (requestorType == null || "".equals(requestorType)) {
453 
454             requestorType = OleSelectConstant.REQUESTOR_TYPE_STAFF;
455         }
456 
457         int requestorTypeId = getRequestorTypeId(requestorType);
458         item.setRequestorTypeId(requestorTypeId);
459         if (bibInfoBean.getRequisitionSource().equals(OleSelectConstant.REQUISITON_SRC_TYPE_WEBFORM) && !bibInfoBean.getRequestersNotes().trim().equals("")) {
460             OleRequisitionNotes note = new OleRequisitionNotes();
461             Map notes = new HashMap();
462             String noteType = OleSelectConstant.REQUESTOR_NOTES_PRE_ORDER_SERVICE;
463             notes.put("noteType", noteType);
464             List<OleNoteType> noteTypeList = (List) businessObjectService.findMatching(org.kuali.ole.select.businessobject.OleNoteType.class, notes);
465             note.setNoteTypeId(noteTypeList.get(0).getNoteTypeId());
466             note.setNote(bibInfoBean.getRequestersNotes());
467             item.getNotes().add(note);
468         }
469         return item;
470     }
471 
472     public int getRequestorTypeId(String requestorType) {
473         int requestorTypeId;
474         Map requestorTypeMap = new HashMap();
475         requestorTypeMap.put("requestorType", requestorType);
476         BusinessObjectService businessObjectService = SpringContext.getBean(org.kuali.rice.krad.service.BusinessObjectService.class);
477         List<OleRequestorType> requestorTypeIdList = (List) businessObjectService.findMatching(OleRequestorType.class, requestorTypeMap);
478         Iterator itr = requestorTypeIdList.iterator();
479         requestorTypeId = requestorTypeIdList.iterator().next().getRequestorTypeId();
480         return requestorTypeId;
481     }
482     
483 /*    public Integer getRequestSourceTypeId(String requestSourceType)throws Exception{
484         Integer requestSourceTypeId = null;
485         Map requestorSourceTypeMap = new HashMap();
486         requestorSourceTypeMap.put("requestSourceType", requestSourceType);
487         BusinessObjectService businessObjectService = SpringContext.getBean(org.kuali.rice.krad.service.BusinessObjectService.class);
488         List<OleRequestSourceType> requestorSourceTypeList = (List) businessObjectService.findMatching(OleRequestSourceType.class, requestorSourceTypeMap);
489         if(requestorSourceTypeList.iterator().hasNext()){
490             requestSourceTypeId = requestorSourceTypeList.iterator().next().getRequestSourceTypeId();
491         }
492         return requestSourceTypeId;
493     }*/
494 
495     /**
496      * This method will check whether Requestor exist ,if exist returns existing record if not save the requester.
497      *
498      * @param bibInfoBean
499      * @return OleRequestor
500      */
501     protected OleRequestor checkRequestorExist(BibInfoBean bibInfoBean) {
502 
503         String requestorFirstName = bibInfoBean.getRequestorsFirstName();
504         String requestorLastName = bibInfoBean.getRequestorsLastName();
505         String firstName;
506         String lastName;
507         Map requestorName = new HashMap();
508         requestorName.put("requestorFirstName", requestorFirstName);
509         requestorName.put("requestorLastName", requestorLastName);
510         List<OleRequestor> requestorList = (List) businessObjectService.findMatching(OleRequestor.class, requestorName);
511         if (requestorList.size() < 1) {
512             return null;
513         } else {
514             for (int i = 0; i < requestorList.size(); i++) {
515                 firstName = requestorList.get(i).getRequestorFirstName().toString();
516                 lastName = requestorList.get(i).getRequestorLastName().toString();
517                 if (requestorFirstName.equalsIgnoreCase(firstName) && requestorLastName.equalsIgnoreCase(lastName)) {
518                     return requestorList.get(i);
519                 }
520             }
521             return null;
522         }
523     }
524 
525     /**
526      * This method will set the values on OleRequestor and save.
527      *
528      * @return OleRequestor
529      */
530     protected OleRequestor saveRequestor(BibInfoBean bibInfoBean, OleRequestor oleRequestor) {
531 
532         if ((bibInfoBean.getRequestorsFirstName() != null && bibInfoBean.getRequestorsFirstName().length() > 0)
533                 || (bibInfoBean.getRequestorsLastName() != null && bibInfoBean.getRequestorsLastName().length() > 0)
534                 || (bibInfoBean.getRequestorsEmail() != null && bibInfoBean.getRequestorsEmail().length() > 0)) {
535             oleRequestor.setRequestorFirstName(bibInfoBean.getRequestorsFirstName() != null ? bibInfoBean.getRequestorsFirstName() : "");
536             oleRequestor.setRequestorLastName(bibInfoBean.getRequestorsLastName() != null ? bibInfoBean.getRequestorsLastName() : "");
537             oleRequestor.setRequestorAddress1(bibInfoBean.getRequestorsAddress1() != null ? bibInfoBean.getRequestorsAddress1() : "");
538             oleRequestor.setRequestorAddress2(bibInfoBean.getRequestorsAddress2() != null ? bibInfoBean.getRequestorsAddress2() : "");
539             oleRequestor.setRequestorCityName(bibInfoBean.getRequestorsCity() != null ? bibInfoBean.getRequestorsCity() : "");
540             oleRequestor.setRequestorStateCode(bibInfoBean.getRequestorsState() != null ? bibInfoBean.getRequestorsState() : "");
541             oleRequestor.setRequestorPostalCode(bibInfoBean.getRequestorsZipCode() != null ? bibInfoBean.getRequestorsZipCode() : "");
542             oleRequestor.setRequestorCountryCode(bibInfoBean.getRequestorsCountryCode() != null ? bibInfoBean.getRequestorsCountryCode() : "");
543             oleRequestor.setRequestorPhoneNumber(bibInfoBean.getRequestorsPhone() != null ? bibInfoBean.getRequestorsPhone() : "");
544             oleRequestor.setRequestorEmail(bibInfoBean.getRequestorsEmail() != null ? bibInfoBean.getRequestorsEmail() : "");
545             oleRequestor.setRequestorSms(bibInfoBean.getRequestorsSMS() != null ? bibInfoBean.getRequestorsSMS() : "");
546             oleRequestor.setRequestorTypeId(bibInfoBean.getRequestorType() != null ? Integer.toString(getRequestorTypeId(bibInfoBean.getRequestorType())) : "");
547             getOleRequestorService().saveRequestor(oleRequestor);
548         }
549                 /*else{
550                     Properties properties = loadPropertiesFromClassPath("org/kuali/ole/select/batch/service/impl/bibinfo.properties");
551                     oleRequestor.setRequestorFirstName(properties.getProperty("firstName"));
552                     oleRequestor.setRequestorLastName(properties.getProperty("lastName"));
553                     oleRequestor.setRequestorAddress1(properties.getProperty("address1"));
554                     oleRequestor.setRequestorAddress2(properties.getProperty("address2"));
555                     oleRequestor.setRequestorCityName(properties.getProperty("city"));
556                     oleRequestor.setRequestorStateCode(properties.getProperty("stateCode"));
557                     oleRequestor.setRequestorPostalCode(properties.getProperty("postalCode"));
558                     oleRequestor.setRequestorCountryCode(properties.getProperty("countryCode"));
559                     oleRequestor.setRequestorPhoneNumber(properties.getProperty("phoneNumber"));
560                     oleRequestor.setRequestorEmail(properties.getProperty("email"));
561                     oleRequestor.setRequestorSms(properties.getProperty("sms"));
562                 }
563         getOleRequestorService().saveRequestor(oleRequestor);*/
564 
565 
566         return oleRequestor;
567     }
568 
569 
570     /**
571      * Set the Vendor address of the given ID.
572      *
573      * @param vendorAddress       VendorAddress
574      * @param requisitionDocument RequisitionDocument
575      */
576     protected void setVendorAddress(VendorAddress vendorAddress, RequisitionDocument requisitionDocument) {
577 
578         if (vendorAddress != null) {
579             requisitionDocument.setVendorAddressGeneratedIdentifier(vendorAddress.getVendorAddressGeneratedIdentifier());
580             requisitionDocument.setVendorAddressInternationalProvinceName(vendorAddress.getVendorAddressInternationalProvinceName());
581             requisitionDocument.setVendorLine1Address(vendorAddress.getVendorLine1Address());
582             requisitionDocument.setVendorLine2Address(vendorAddress.getVendorLine2Address());
583             requisitionDocument.setVendorCityName(vendorAddress.getVendorCityName());
584             requisitionDocument.setVendorStateCode(vendorAddress.getVendorStateCode());
585             requisitionDocument.setVendorPostalCode(vendorAddress.getVendorZipCode());
586             requisitionDocument.setVendorCountryCode(vendorAddress.getVendorCountryCode());
587         }
588 
589     }
590 
591 
592 }