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.document;
17  
18  import org.apache.commons.collections.CollectionUtils;
19  import org.apache.commons.lang.StringUtils;
20  import org.joda.time.DateTime;
21  import org.kuali.ole.DocumentUniqueIDPrefix;
22  import org.kuali.ole.docstore.common.client.DocstoreClientLocator;
23  import org.kuali.ole.docstore.common.document.Bib;
24  import org.kuali.ole.docstore.common.document.Item;
25  import org.kuali.ole.docstore.common.document.ItemOleml;
26  import org.kuali.ole.docstore.common.document.content.enums.DocType;
27  import org.kuali.ole.docstore.common.search.SearchResponse;
28  import org.kuali.ole.docstore.common.search.SearchResult;
29  import org.kuali.ole.docstore.common.search.SearchResultField;
30  import org.kuali.ole.docstore.engine.service.index.solr.BibConstants;
31  import org.kuali.ole.docstore.engine.service.index.solr.ItemConstants;
32  import org.kuali.ole.module.purap.PurapConstants;
33  import org.kuali.ole.module.purap.PurapPropertyConstants;
34  import org.kuali.ole.module.purap.businessobject.PurchaseOrderType;
35  import org.kuali.ole.module.purap.document.PurchaseOrderDocument;
36  import org.kuali.ole.module.purap.document.service.PurchaseOrderService;
37  import org.kuali.ole.module.purap.document.service.ReceivingService;
38  import org.kuali.ole.select.OleSelectConstant;
39  import org.kuali.ole.select.businessobject.*;
40  import org.kuali.ole.select.document.service.OleCopyHelperService;
41  import org.kuali.ole.select.document.service.OleDocstoreHelperService;
42  import org.kuali.ole.select.document.service.OleLineItemReceivingService;
43  import org.kuali.ole.select.document.service.OleNoteTypeService;
44  import org.kuali.ole.select.document.service.impl.OleLineItemReceivingServiceImpl;
45  import org.kuali.ole.select.lookup.DocData;
46  import org.kuali.ole.select.service.OleDocStoreLookupService;
47  import org.kuali.ole.sys.OLEConstants;
48  import org.kuali.ole.sys.OLEKeyConstants;
49  import org.kuali.ole.sys.OLEPropertyConstants;
50  import org.kuali.ole.sys.context.SpringContext;
51  import org.kuali.ole.vnd.businessobject.VendorDetail;
52  import org.kuali.rice.core.api.config.property.ConfigurationService;
53  import org.kuali.rice.core.api.datetime.DateTimeService;
54  import org.kuali.rice.core.api.util.RiceKeyConstants;
55  import org.kuali.rice.core.api.util.type.KualiDecimal;
56  import org.kuali.rice.core.api.util.type.KualiInteger;
57  import org.kuali.rice.kew.api.KewApiConstants;
58  import org.kuali.rice.kew.api.KewApiServiceLocator;
59  import org.kuali.rice.kew.api.document.DocumentStatus;
60  import org.kuali.rice.kew.api.document.attribute.DocumentAttribute;
61  import org.kuali.rice.kew.api.document.search.DocumentSearchCriteria;
62  import org.kuali.rice.kew.api.document.search.DocumentSearchResult;
63  import org.kuali.rice.kew.api.document.search.DocumentSearchResults;
64  import org.kuali.rice.kew.api.exception.WorkflowException;
65  import org.kuali.rice.kew.exception.WorkflowServiceError;
66  import org.kuali.rice.kew.exception.WorkflowServiceErrorException;
67  import org.kuali.rice.kew.service.KEWServiceLocator;
68  import org.kuali.rice.kim.api.KimConstants;
69  import org.kuali.rice.kim.api.identity.Person;
70  import org.kuali.rice.kim.api.identity.PersonService;
71  import org.kuali.rice.kns.service.DocumentHelperService;
72  import org.kuali.rice.krad.bo.AdHocRoutePerson;
73  import org.kuali.rice.krad.document.TransactionalDocumentBase;
74  import org.kuali.rice.krad.exception.DocumentAuthorizationException;
75  import org.kuali.rice.krad.service.BusinessObjectService;
76  import org.kuali.rice.krad.service.DocumentService;
77  import org.kuali.rice.krad.service.KRADServiceLocator;
78  import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
79  import org.kuali.rice.krad.util.GlobalVariables;
80  import org.kuali.rice.krad.util.KRADConstants;
81  import org.kuali.rice.krad.util.ObjectUtils;
82  
83  import java.math.BigDecimal;
84  import java.text.DateFormat;
85  import java.text.ParseException;
86  import java.text.SimpleDateFormat;
87  import java.util.*;
88  
89  public class OleReceivingQueueSearchDocument extends TransactionalDocumentBase {
90  
91      private String purchaseOrderNumber;
92  
93      private String standardNumber;
94  
95      private String title;
96  
97      //private String journal;
98  
99      private String vendorName;
100 
101     private String beginDate;
102 
103     private String endDate;
104 
105     /*private boolean serials;
106 
107     private boolean standingOrders;
108 
109     private boolean vendor;*/
110 
111     private boolean monograph;
112 
113     //private boolean purchaseOrderDate;
114 
115     //private boolean status;
116 
117     private VendorDetail vendorDetail;
118 
119     private String purchaseOrderStatusDescription;
120 
121     private PurchaseOrderType orderType;
122 
123     private String purchaseOrderType;
124 
125     private boolean receive;
126 
127     private String author;
128 
129     private String publisher;
130 
131     private String edition;
132 
133     private String quatityOrdered;
134 
135     private String points;
136 
137     private String instructions;
138 
139     private PurchaseOrderDocument purchaseOrderDocument;
140 
141     public boolean isDateLookup = false;
142 
143     private List<String> receivingDocumentsList = new ArrayList<String>();
144 
145    /* private int poId=0;*/
146 
147     private String documentNumber = null;
148 
149     private DateTimeService dateTimeService;
150 
151     public DateTimeService getDateTimeService() {
152         if (dateTimeService == null) {
153             dateTimeService = SpringContext.getBean(DateTimeService.class);
154         }
155         return dateTimeService;
156     }
157 
158     public List<OlePurchaseOrderItem> purchaseOrders = new ArrayList<OlePurchaseOrderItem>(0);
159 
160     protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OleReceivingQueueSearchDocument.class);
161 
162     private boolean claimFilter;
163 
164 
165     public boolean isClaimFilter() {
166         return claimFilter;
167     }
168 
169     public void setClaimFilter(boolean claimFilter) {
170         this.claimFilter = claimFilter;
171     }
172 
173     /**
174      * Gets the purchaseOrderStatusDescription attribute.
175      *
176      * @return Returns the purchaseOrderStatusDescription.
177      */
178     public String getPurchaseOrderStatusDescription() {
179         return purchaseOrderStatusDescription;
180     }
181 
182     /**
183      * Sets the purchaseOrderStatusDescription attribute value.
184      *
185      * @param purchaseOrderStatusDescription The purchaseOrderStatusDescription to set.
186      */
187     public void setPurchaseOrderStatusDescription(String purchaseOrderStatusDescription) {
188         this.purchaseOrderStatusDescription = purchaseOrderStatusDescription;
189     }
190 
191     /**
192      * Gets the orderType attribute.
193      *
194      * @return Returns the orderType.
195      */
196     public PurchaseOrderType getOrderType() {
197         return orderType;
198     }
199 
200     /**
201      * Sets the orderType attribute value.
202      *
203      * @param orderType The orderType to set.
204      */
205     public void setOrderType(PurchaseOrderType orderType) {
206         this.orderType = orderType;
207     }
208 
209     /**
210      * Gets the purchaseOrderType attribute.
211      *
212      * @return Returns the purchaseOrderType.
213      */
214     public String getPurchaseOrderType() {
215         return purchaseOrderType;
216     }
217 
218     /**
219      * Sets the purchaseOrderType attribute value.
220      *
221      * @param purchaseOrderType The purchaseOrderType to set.
222      */
223     public void setPurchaseOrderType(String purchaseOrderType) {
224         this.purchaseOrderType = purchaseOrderType;
225     }
226 
227     /**
228      * Gets the purchaseOrderNumber attribute.
229      *
230      * @return Returns the purchaseOrderNumber.
231      */
232     public String getPurchaseOrderNumber() {
233         return purchaseOrderNumber;
234     }
235 
236     /**
237      * Sets the purchaseOrderNumber attribute value.
238      *
239      * @param purchaseOrderNumber The purchaseOrderNumber to set.
240      */
241     public void setPurchaseOrderNumber(String purchaseOrderNumber) {
242         this.purchaseOrderNumber = purchaseOrderNumber;
243     }
244 
245     /**
246      * Gets the standardNumber attribute.
247      *
248      * @return Returns the standardNumber.
249      */
250     public String getStandardNumber() {
251         return standardNumber;
252     }
253 
254     /**
255      * Sets the standardNumber attribute value.
256      *
257      * @param standardNumber The standardNumber to set.
258      */
259     public void setStandardNumber(String standardNumber) {
260         this.standardNumber = standardNumber;
261     }
262 
263     /**
264      * Gets the title attribute.
265      *
266      * @return Returns the title.
267      */
268     public String getTitle() {
269         return title;
270     }
271 
272     /**
273      * Sets the title attribute value.
274      *
275      * @param title The title to set.
276      */
277     public void setTitle(String title) {
278         this.title = title;
279     }
280 
281     /**
282      * Gets the journal attribute.
283      * @return Returns the journal.
284      *//*
285     public String getJournal() {
286         return journal;
287     }
288 
289     *//**
290      * Sets the journal attribute value.
291      * @param journal The journal to set.
292      *//*
293     public void setJournal(String journal) {
294         this.journal = journal;
295     }*/
296 
297     /**
298      * Gets the vendorName attribute.
299      *
300      * @return Returns the vendorName.
301      */
302     public String getVendorName() {
303         return vendorName;
304     }
305 
306     /**
307      * Sets the vendorName attribute value.
308      *
309      * @param vendorName The vendorName to set.
310      */
311     public void setVendorName(String vendorName) {
312         this.vendorName = vendorName;
313     }
314 
315     /**
316      * Gets the serials attribute.
317      * @return Returns the serials.
318      *//*
319     public boolean isSerials() {
320         return serials;
321     }
322 
323     *//**
324      * Sets the serials attribute value.
325      * @param serials The serials to set.
326      *//*
327     public void setSerials(boolean serials) {
328         this.serials = serials;
329     }
330 
331     *//**
332      * Gets the standingOrders attribute.
333      * @return Returns the standingOrders.
334      *//*
335     public boolean isStandingOrders() {
336         return standingOrders;
337     }
338 
339     *//**
340      * Sets the standingOrders attribute value.
341      * @param standingOrders The standingOrders to set.
342      *//*
343     public void setStandingOrders(boolean standingOrders) {
344         this.standingOrders = standingOrders;
345     }
346 
347     *//**
348      * Gets the vendor attribute.
349      * @return Returns the vendor.
350      *//*
351     public boolean isVendor() {
352         return vendor;
353     }
354 
355     *//**
356      * Sets the vendor attribute value.
357      * @param vendor The vendor to set.
358      *//*
359     public void setVendor(boolean vendor) {
360         this.vendor = vendor;
361     }*/
362 
363     /**
364      * Gets the monograph attribute.
365      *
366      * @return Returns the monograph.
367      */
368     public boolean isMonograph() {
369         return monograph;
370     }
371 
372     /**
373      * Sets the monograph attribute value.
374      *
375      * @param monograph The monograph to set.
376      */
377     public void setMonograph(boolean monograph) {
378         this.monograph = monograph;
379     }
380 
381     /**
382      * Gets the purchaseOrderDate attribute.
383      * @return Returns the purchaseOrderDate.
384      *//*
385     public boolean isPurchaseOrderDate() {
386         return purchaseOrderDate;
387     }
388 
389     *//**
390      * Sets the purchaseOrderDate attribute value.
391      * @param purchaseOrderDate The purchaseOrderDate to set.
392      *//*
393     public void setPurchaseOrderDate(boolean purchaseOrderDate) {
394         this.purchaseOrderDate = purchaseOrderDate;
395     }*/
396 
397     /**
398      * Gets the status attribute.
399      * @return Returns the status.
400      *//*
401     public boolean isStatus() {
402         return status;
403     }
404 
405     *//**
406      * Sets the status attribute value.
407      * @param status The status to set.
408      *//*
409     public void setStatus(boolean status) {
410         this.status = status;
411     }*/
412 
413     /**
414      * Gets the vendorDetail attribute.
415      *
416      * @return Returns the vendorDetail.
417      */
418     public VendorDetail getVendorDetail() {
419         return vendorDetail;
420     }
421 
422     /**
423      * Sets the vendorDetail attribute value.
424      *
425      * @param vendorDetail The vendorDetail to set.
426      */
427     public void setVendorDetail(VendorDetail vendorDetail) {
428         this.vendorDetail = vendorDetail;
429     }
430 
431     /**
432      * Gets the receive attribute.
433      *
434      * @return Returns the receive.
435      */
436     public boolean isReceive() {
437         return receive;
438     }
439 
440     /**
441      * Sets the receive attribute value.
442      *
443      * @param receive The receive to set.
444      */
445     public void setReceive(boolean receive) {
446         this.receive = receive;
447     }
448 
449     /**
450      * Gets the author attribute.
451      *
452      * @return Returns the author.
453      */
454     public String getAuthor() {
455         return author;
456     }
457 
458     /**
459      * Sets the author attribute value.
460      *
461      * @param author The author to set.
462      */
463     public void setAuthor(String author) {
464         this.author = author;
465     }
466 
467     /**
468      * Gets the publisher attribute.
469      *
470      * @return Returns the publisher.
471      */
472     public String getPublisher() {
473         return publisher;
474     }
475 
476     /**
477      * Sets the publisher attribute value.
478      *
479      * @param publisher The publisher to set.
480      */
481     public void setPublisher(String publisher) {
482         this.publisher = publisher;
483     }
484 
485     /**
486      * Gets the edition attribute.
487      *
488      * @return Returns the edition.
489      */
490     public String getEdition() {
491         return edition;
492     }
493 
494     /**
495      * Sets the edition attribute value.
496      *
497      * @param edition The edition to set.
498      */
499     public void setEdition(String edition) {
500         this.edition = edition;
501     }
502 
503     /**
504      * Gets the quatityOrdered attribute.
505      *
506      * @return Returns the quatityOrdered.
507      */
508     public String getQuatityOrdered() {
509         return quatityOrdered;
510     }
511 
512     /**
513      * Sets the quatityOrdered attribute value.
514      *
515      * @param quatityOrdered The quatityOrdered to set.
516      */
517     public void setQuatityOrdered(String quatityOrdered) {
518         this.quatityOrdered = quatityOrdered;
519     }
520 
521     /**
522      * Gets the points attribute.
523      *
524      * @return Returns the points.
525      */
526     public String getPoints() {
527         return points;
528     }
529 
530     /**
531      * Sets the points attribute value.
532      *
533      * @param points The points to set.
534      */
535     public void setPoints(String points) {
536         this.points = points;
537     }
538 
539     /**
540      * Gets the instructions attribute.
541      *
542      * @return Returns the instructions.
543      */
544     public String getInstructions() {
545         return instructions;
546     }
547 
548     /**
549      * Sets the instructions attribute value.
550      *
551      * @param instructions The instructions to set.
552      */
553     public void setInstructions(String instructions) {
554         this.instructions = instructions;
555     }
556 
557     /**
558      * Gets the purchaseOrderDocument attribute.
559      *
560      * @return Returns the purchaseOrderDocument.
561      */
562     public PurchaseOrderDocument getPurchaseOrderDocument() {
563         return purchaseOrderDocument;
564     }
565 
566     /**
567      * Sets the purchaseOrderDocument attribute value.
568      *
569      * @param purchaseOrderDocument The purchaseOrderDocument to set.
570      */
571     public void setPurchaseOrderDocument(PurchaseOrderDocument purchaseOrderDocument) {
572         this.purchaseOrderDocument = purchaseOrderDocument;
573     }
574 
575     /**
576      * Gets the purchaseOrders attribute.
577      *
578      * @return Returns the purchaseOrders.
579      */
580     public List<OlePurchaseOrderItem> getPurchaseOrders() {
581         return purchaseOrders;
582     }
583 
584     /**
585      * Sets the purchaseOrders attribute value.
586      *
587      * @param purchaseOrders The purchaseOrders to set.
588      */
589     public void setPurchaseOrders(List<OlePurchaseOrderItem> purchaseOrders) {
590         this.purchaseOrders = purchaseOrders;
591     }
592 
593     /**
594      * Gets the receivingDocumentsList attribute.
595      *
596      * @return Returns the receivingDocumentsList.
597      */
598 
599     public List<String> getReceivingDocumentsList() {
600         return receivingDocumentsList;
601     }
602 
603     /**
604      * Sets the receivingDocumentsList attribute value.
605      *
606      * @param receivingDocumentsList The receivingDocumentsList to set.
607      */
608     public void setReceivingDocumentsList(List<String> receivingDocumentsList) {
609         this.receivingDocumentsList = receivingDocumentsList;
610     }
611 
612     @SuppressWarnings("rawtypes")
613 
614     protected LinkedHashMap toStringMapper_RICE20_REFACTORME() {
615         LinkedHashMap m = new LinkedHashMap();
616         return m;
617     }
618 
619     public boolean isPurchaseOrderDocumentAdded() {
620         if (this.purchaseOrders != null) {
621             return this.purchaseOrders.size() > 0;
622         } else {
623             return false;
624         }
625     }
626 
627     private DocstoreClientLocator docstoreClientLocator;
628 
629     public DocstoreClientLocator getDocstoreClientLocator() {
630 
631         if (docstoreClientLocator == null) {
632             docstoreClientLocator = SpringContext.getBean(DocstoreClientLocator.class);
633 
634         }
635         return docstoreClientLocator;
636     }
637 
638     /**
639      * This method Takes Value from UI and return results after selecting search
640      *
641      * @throws Exception
642      */
643     public void receiveingQueueRecordSearch() {
644         Long b1 = System.currentTimeMillis();
645         Set<String> bibIds = new HashSet<String>();
646         List<OlePurchaseOrderItem> purchaseOrderItemList = new ArrayList<>();
647         List<OlePurchaseOrderItem> results = new ArrayList<>();
648         boolean isOnlyDocCriteria = false;
649         boolean isDbCriteriaExist = false;
650         if ((StringUtils.isNotBlank(purchaseOrderNumber) || StringUtils.isNotBlank(purchaseOrderType) || StringUtils.isNotBlank(vendorName)
651                 || StringUtils.isNotBlank(purchaseOrderStatusDescription) || ObjectUtils.isNotNull(beginDate) || ObjectUtils.isNotNull(endDate))) {
652             isDbCriteriaExist = true;
653         }
654         BigDecimal orderTypeId = null;
655         if (StringUtils.isNotBlank(this.purchaseOrderType)) {
656             Map<String, String> orderTypeMap = new HashMap<String, String>();
657             orderTypeMap.put("purchaseOrderType", this.purchaseOrderType);
658             List<PurchaseOrderType> items = (List<PurchaseOrderType>) KRADServiceLocator.getBusinessObjectService().findMatching(PurchaseOrderType.class, orderTypeMap);
659             if (CollectionUtils.isNotEmpty(items)) {
660                 orderTypeId = items.get(0).getPurchaseOrderTypeId();
661             }
662         }
663         if (!isDbCriteriaExist && (StringUtils.isNotBlank(this.title) || (StringUtils.isNotBlank(this.standardNumber)))) {
664             isOnlyDocCriteria = true;
665             List<String> newBibIds = new ArrayList<>();
666             List<DocData> docDatas=getDocDatas(this.title, this.standardNumber);
667             for (DocData docData : docDatas) {
668                 Map<String, String> poItemMap = new HashMap<String, String>();
669                 poItemMap.put("itemTitleId", docData.getBibIdentifier());
670                 poItemMap.put("itemTypeCode", "ITEM");
671                 List<OlePurchaseOrderItem> items = (List<OlePurchaseOrderItem>) KRADServiceLocator.getBusinessObjectService().findMatching(OlePurchaseOrderItem.class, poItemMap);
672                 if (CollectionUtils.isNotEmpty(items)) {
673                     for (OlePurchaseOrderItem orderItem : items) {
674                         orderItem.setDocData(docData);
675                         int purAppNum = orderItem.getPurchaseOrder().getPurapDocumentIdentifier();
676                         String docNumber = orderItem.getPurchaseOrder().getDocumentNumber();
677                         if (validatePurchaseOrderItem(orderItem) && validateRecords(purAppNum, docNumber)) {
678                             newBibIds.add(orderItem.getItemTitleId());
679                             results.add(orderItem);
680                         }
681 
682                     }
683                 }
684             }
685             bibIds.clear();
686             ;
687             bibIds.addAll(newBibIds);
688             this.setPurchaseOrders(results);
689         } else {
690 
691             if (StringUtils.isNotBlank(purchaseOrderNumber)) {
692                 String[] purchaseOrderNumbers = (this.purchaseOrderNumber.toString()).split(",");
693                 for (int i = 0; i < purchaseOrderNumbers.length; i++) {
694                     results.addAll(getSearchResults(purchaseOrderNumbers[i], bibIds, orderTypeId));
695                 }
696 
697             } else {
698                 results.addAll(getSearchResults("", bibIds, orderTypeId));
699             }
700             try {
701                 if (CollectionUtils.isNotEmpty(bibIds)) {
702                     List<Bib> bibs = new ArrayList<>();
703                     bibs.addAll(getDocstoreClientLocator().getDocstoreClient().acquisitionSearchRetrieveBibs(new ArrayList<String>(bibIds)));
704                     if (bibIds!=null && bibs!=null) {
705                         for (OlePurchaseOrderItem orderItem : results) {
706                             inner:
707                             for (Bib bib : bibs) {
708                                 if (bib.getId().equals(orderItem.getItemTitleId())) {
709                                     boolean isAllowed = true;
710                                     boolean isTitle = true;
711                                     boolean isIsbn = true;
712                                     if (StringUtils.isNotBlank(this.title)) {
713                                         if (!bib.getTitle().contains(this.title)) {
714                                             isTitle = false;
715                                         }
716                                         isAllowed = false;
717                                     }
718                                     if (StringUtils.isNotBlank(this.standardNumber)) {
719                                         if (!bib.getIsbn().equals(this.standardNumber)) {
720                                             isIsbn = false;
721                                         }
722                                         isAllowed = false;
723                                     }
724                                     if (!isAllowed) {
725                                         isAllowed = isIsbn && isTitle;
726                                     }
727                                     if (isAllowed) {
728                                         DocData docData = new DocData();
729                                         docData.setTitle(bib.getTitle());
730                                         docData.setAuthor(bib.getAuthor());
731                                         docData.setPublisher(bib.getPublisher());
732                                         if(StringUtils.isNotBlank(bib.getIsbn())){
733                                             docData.setIsbn(bib.getIsbn());
734                                         } else {
735                                             docData.setIsbn(bib.getIssn());
736                                         }
737 
738                                         docData.setLocalIdentifier(DocumentUniqueIDPrefix.getDocumentId(bib.getId()));
739                                         docData.setBibIdentifier(bib.getId());
740                                         orderItem.setDocData(docData);
741                                         purchaseOrderItemList.add(orderItem);
742                                         break inner;
743                                     }
744 
745                                 }
746                             }
747                         }
748                     }
749                 }
750             } catch (Exception e) {
751 
752             }
753             this.setPurchaseOrders(purchaseOrderItemList);
754         }
755 
756     }
757 
758     public List<OlePurchaseOrderItem> getSearchResults(String poNumber, Set<String> bibIds, BigDecimal orderTypeId) {
759         List<OlePurchaseOrderItem> results = new ArrayList<>();
760         DocumentSearchCriteria.Builder docSearchCriteria = DocumentSearchCriteria.Builder.create();
761         docSearchCriteria.setDocumentTypeName(PurapConstants.PurapDocTypeCodes.PO_DOCUMENT);
762         List<DocumentStatus> documentStatuses = new ArrayList<>();
763         documentStatuses.add(DocumentStatus.FINAL);
764         Map<String, List<String>> fixedParameters = new HashMap<>();
765         Map<String, List<String>> itemTitleIds = new HashMap<>();
766         Map<String, List<String>> attributes = new HashMap<String, List<String>>();
767         if (StringUtils.isNotBlank(poNumber))
768             fixedParameters.put("purapDocumentIdentifier", Arrays.asList(poNumber));
769         if (StringUtils.isNotBlank(vendorName)) {
770             fixedParameters.put("vendorName", Arrays.asList(vendorName));
771         }
772         if (docSearchCriteria != null) {
773             if (!fixedParameters.isEmpty()) {
774                 for (String propertyField : fixedParameters.keySet()) {
775                     if (fixedParameters.get(propertyField) != null) {
776                         attributes.put(propertyField, fixedParameters.get(propertyField));
777                     }
778                 }
779             }
780         }
781         docSearchCriteria.setDocumentAttributeValues(attributes);
782         //docSearchCriteria.setSearchOptions(itemTitleIds);
783         Date currentDate = new Date();
784         docSearchCriteria.setDateCreatedTo(new DateTime(currentDate));
785         //docSearchCriteria.setMaxResults(500);
786         //docSearchCriteria.setApplicationDocumentStatus(PurapConstants.PurchaseOrderStatuses.APPDOC_OPEN);
787         List<String> applicationStatus = new ArrayList<String>();
788         applicationStatus.add(PurapConstants.PurchaseOrderStatuses.APPDOC_OPEN);
789         if (StringUtils.isNotBlank(this.purchaseOrderStatusDescription)) {
790             applicationStatus.clear();
791             applicationStatus.add(this.purchaseOrderStatusDescription);
792         }
793         docSearchCriteria.setApplicationDocumentStatuses(applicationStatus);
794         try {
795             if (ObjectUtils.isNotNull(this.beginDate)) {
796                 docSearchCriteria.setDateCreatedFrom(new DateTime(this.beginDate));
797             }
798             if (ObjectUtils.isNotNull(this.endDate)) {
799                 docSearchCriteria.setDateCreatedTo(new DateTime(this.endDate));
800             }
801         } catch (Exception e) {
802 
803         }
804 
805         //docSearchCriteria.setDocumentStatuses(documentStatuses);
806         List<String> purchaseOrderIds = new ArrayList<>();
807         DocumentSearchCriteria docSearchCriteriaDTO = docSearchCriteria.build();
808         DocumentSearchResults components = null;
809         components = KEWServiceLocator.getDocumentSearchService().lookupDocuments(GlobalVariables.getUserSession().getPrincipalId(), docSearchCriteriaDTO);
810         List<DocumentSearchResult> docSearchResults = components.getSearchResults();
811         for (DocumentSearchResult searchResult : docSearchResults) {
812             if (StringUtils.isNotBlank(searchResult.getDocument().getDocumentId())) {
813                 purchaseOrderIds.add(searchResult.getDocument().getDocumentId());
814                 Map<String, String> poItemMap = new HashMap<String, String>();
815                 poItemMap.put("documentNumber", searchResult.getDocument().getDocumentId());
816                 poItemMap.put("itemTypeCode", "ITEM");
817                 List<OlePurchaseOrderItem> items = (List<OlePurchaseOrderItem>) KRADServiceLocator.getBusinessObjectService().findMatching(OlePurchaseOrderItem.class, poItemMap);
818                 if (CollectionUtils.isNotEmpty(items)) {
819                     if (orderTypeId != null) {
820                         for (OlePurchaseOrderItem orderItem : items) {
821                             if (orderItem.getPurchaseOrder() != null && orderItem.getPurchaseOrder().getPurchaseOrderTypeId() != null && orderItem.getPurchaseOrder().getPurchaseOrderTypeId().equals(orderTypeId)) {
822                                 if (validatePurchaseOrderItem(orderItem)) {
823                                     bibIds.add(orderItem.getItemTitleId());
824                                     results.add(orderItem);
825                                 }
826                             }
827                         }
828                     } else {
829                         for (OlePurchaseOrderItem orderItem : items) {
830                             if (validatePurchaseOrderItem(orderItem)) {
831                                 bibIds.add(orderItem.getItemTitleId());
832                                 results.add(orderItem);
833                             }
834                         }
835                     }
836                 }
837             }
838         }
839         return results;
840     }
841 
842     public boolean validatePurchaseOrderItem(OlePurchaseOrderItem olePurchaseOrderItem) {
843         SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
844         String dateString = dateFormat.format(new Date());
845         String actionDateString = olePurchaseOrderItem.getClaimDate() != null ? dateFormat.format(olePurchaseOrderItem.getClaimDate()) : "";
846         boolean isValid = true;
847         PurchaseOrderDocument olePurchaseOrderDocument = olePurchaseOrderItem.getPurapDocument();
848       /*  int purAppNum = olePurchaseOrderDocument.getPurapDocumentIdentifier();
849         olePurchaseOrderDocument = SpringContext.getBean(PurchaseOrderService.class).getCurrentPurchaseOrder(purAppNum);*/
850 
851         Map purchaseOrderTypeIdMap = new HashMap();
852         purchaseOrderTypeIdMap.put("purchaseOrderTypeId", olePurchaseOrderDocument.getPurchaseOrderTypeId());
853         org.kuali.rice.krad.service.BusinessObjectService businessObject = SpringContext.getBean(org.kuali.rice.krad.service.BusinessObjectService.class);
854         List<PurchaseOrderType> purchaseOrderTypeDocumentList = (List) businessObject.findMatching(PurchaseOrderType.class, purchaseOrderTypeIdMap);
855 
856         int purAppNum = olePurchaseOrderDocument.getPurapDocumentIdentifier();
857         olePurchaseOrderDocument = SpringContext.getBean(PurchaseOrderService.class).getCurrentPurchaseOrder(purAppNum);
858         String docNumber = olePurchaseOrderDocument.getDocumentNumber();
859         isValid = isValid && validateRecords(purAppNum, docNumber);
860         isValid = isValid && validatePurchaseOrderStatus(purchaseOrderTypeDocumentList, olePurchaseOrderDocument);
861         isValid = isValid && validatePoByRetiredVersionStatus(olePurchaseOrderDocument);
862         isValid = isValid && !(checkSpecialHandlingNotesExsist(olePurchaseOrderItem));
863         //isValid =isValid && validateCopiesAndParts(olePurchaseOrderItem);
864 
865         if (isValid) {
866             boolean serialPOLink = olePurchaseOrderItem.getCopyList() != null && olePurchaseOrderItem.getCopyList().size() > 0 ? olePurchaseOrderItem.getCopyList().get(0).getSerialReceivingIdentifier() != null : false;
867             boolean continuing = (purchaseOrderTypeDocumentList != null && purchaseOrderTypeDocumentList.size() > 0 ?
868                     purchaseOrderTypeDocumentList.get(0).getPurchaseOrderType().equalsIgnoreCase("Continuing") : false);
869             if (olePurchaseOrderItem.getReceiptStatusId() != null && olePurchaseOrderItem.getReceiptStatusId().toString().equalsIgnoreCase((String.valueOf(getReceiptStatusDetails(OLEConstants.PO_RECEIPT_STATUS_FULLY_RECEIVED))))) {
870                 GlobalVariables.clear();
871                 GlobalVariables.getMessageMap().putInfo(OleSelectConstant.RECEIVING_QUEUE_SEARCH,
872                         OLEKeyConstants.ERROR_NO_PURCHASEORDERS_FOUND_FOR_FULLY_RECEIVED);
873             } else if (this.isClaimFilter()) {
874                 if (!olePurchaseOrderItem.isDoNotClaim() && olePurchaseOrderItem.getClaimDate() != null && (actionDateString.equalsIgnoreCase(dateString) || olePurchaseOrderItem.getClaimDate().before(new Date()))
875                         && !serialPOLink && !continuing) {
876                     olePurchaseOrderItem.setClaimFilter(true);
877                     isValid = isValid & true;
878                 }
879             } else {
880                 if (!olePurchaseOrderItem.isDoNotClaim() && olePurchaseOrderItem.getClaimDate() != null && (actionDateString.equalsIgnoreCase(dateString) || olePurchaseOrderItem.getClaimDate().before(new Date()))
881                         && !serialPOLink && !continuing) {
882                     olePurchaseOrderItem.setClaimFilter(true);
883                 }
884                 isValid = isValid & true;
885             }
886         }
887 
888         return isValid;
889     }
890 
891 
892     public Set<String> getDocSearchResults(String title, String isbn) {
893         int maxLimit = Integer.parseInt(SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(OLEConstants.DOCSEARCH_ORDERQUEUE_LIMIT_KEY));
894         Set<String> itemTitles = new HashSet<>();
895         try {
896             org.kuali.ole.docstore.common.document.Item item = new ItemOleml();
897             org.kuali.ole.docstore.common.search.SearchParams searchParams = new org.kuali.ole.docstore.common.search.SearchParams();
898             searchParams.setPageSize(maxLimit);
899             if (StringUtils.isNotBlank(title)) {
900                 searchParams.getSearchConditions().add(searchParams.buildSearchCondition("phrase", searchParams.buildSearchField(org.kuali.ole.docstore.common.document.content.enums.DocType.BIB.getCode(), BibConstants.TITLE_SEARCH, title), "AND"));
901             }
902             if (StringUtils.isNotBlank(isbn)) {
903                 searchParams.getSearchConditions().add(searchParams.buildSearchCondition("phrase", searchParams.buildSearchField(org.kuali.ole.docstore.common.document.content.enums.DocType.BIB.getCode(), BibConstants.ISBN_SEARCH, isbn), "OR"));
904                 searchParams.getSearchConditions().add(searchParams.buildSearchCondition("phrase", searchParams.buildSearchField(org.kuali.ole.docstore.common.document.content.enums.DocType.BIB.getCode(), BibConstants.ISSN_SEARCH, isbn), "OR"));
905             }
906             SearchResponse searchResponse = null;
907             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.BIB.getCode(), ItemConstants.BIB_IDENTIFIER));
908             searchResponse = getDocstoreClientLocator().getDocstoreClient().search(searchParams);
909             for (SearchResult searchResult : searchResponse.getSearchResults()) {
910                 for (SearchResultField searchResultField : searchResult.getSearchResultFields()) {
911                     if (StringUtils.isNotBlank(searchResultField.getFieldValue())) {
912                         if (searchResultField.getFieldName().equals("bibIdentifier")) {
913                             itemTitles.add(searchResultField.getFieldValue());
914                         }
915                     }
916                 }
917             }
918         } catch (Exception ex) {
919             GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, "Item Exists");
920             LOG.error(org.kuali.ole.OLEConstants.ITEM_EXIST + ex);
921         }
922 
923         return itemTitles;
924     }
925 
926     public List<DocData> getDocDatas(String title, String isbn) {
927         List<DocData> docDatas=new ArrayList<>();
928         int maxLimit = Integer.parseInt(SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(OLEConstants.DOCSEARCH_ORDERQUEUE_LIMIT_KEY));
929         Set<String> itemTitles = new HashSet<>();
930         try {
931             org.kuali.ole.docstore.common.document.Item item = new ItemOleml();
932             org.kuali.ole.docstore.common.search.SearchParams searchParams = new org.kuali.ole.docstore.common.search.SearchParams();
933             searchParams.setPageSize(maxLimit);
934             if (StringUtils.isNotBlank(title)) {
935                 searchParams.getSearchConditions().add(searchParams.buildSearchCondition("phrase", searchParams.buildSearchField(org.kuali.ole.docstore.common.document.content.enums.DocType.BIB.getCode(), BibConstants.TITLE_SEARCH, title), "AND"));
936             }
937             if (StringUtils.isNotBlank(isbn)) {
938                 searchParams.getSearchConditions().add(searchParams.buildSearchCondition("phrase", searchParams.buildSearchField(org.kuali.ole.docstore.common.document.content.enums.DocType.BIB.getCode(), BibConstants.ISBN_SEARCH, isbn), "OR"));
939                 searchParams.getSearchConditions().add(searchParams.buildSearchCondition("phrase", searchParams.buildSearchField(org.kuali.ole.docstore.common.document.content.enums.DocType.BIB.getCode(), BibConstants.ISSN_SEARCH, isbn), "OR"));
940             }
941             SearchResponse searchResponse = null;
942             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.BIB.getCode(), BibConstants.TITLE_DISPLAY));
943             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.BIB.getCode(), BibConstants.AUTHOR_DISPLAY));
944             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.BIB.getCode(), BibConstants.PUBLISHER_DISPLAY));
945             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.BIB.getCode(), BibConstants.ISBN_DISPLAY));
946             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.BIB.getCode(), ItemConstants.BIB_IDENTIFIER));
947             searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.BIB.getCode(), BibConstants.ISSN_DISPLAY));
948             searchResponse = getDocstoreClientLocator().getDocstoreClient().search(searchParams);
949             for (SearchResult searchResult : searchResponse.getSearchResults()) {
950                 DocData docData=new DocData();
951                 for (SearchResultField searchResultField : searchResult.getSearchResultFields()) {
952                     if (StringUtils.isNotBlank(searchResultField.getFieldValue())) {
953                         if (searchResultField.getFieldName().equals(ItemConstants.BIB_IDENTIFIER)) {
954                             docData.setBibIdentifier(searchResultField.getFieldValue());
955                         }
956                         if (searchResultField.getFieldName().equals(BibConstants.TITLE_DISPLAY)) {
957                             docData.setTitle(searchResultField.getFieldValue());
958                         }
959                         if (searchResultField.getFieldName().equals(BibConstants.AUTHOR_DISPLAY)) {
960                             docData.setAuthor(searchResultField.getFieldValue());
961                         }
962                         if (searchResultField.getFieldName().equals(BibConstants.PUBLISHER_DISPLAY)) {
963                             docData.setPublisher(searchResultField.getFieldValue());
964                         }
965                         if (searchResultField.getFieldName().equals(BibConstants.ISBN_DISPLAY) && StringUtils.isNotBlank(searchResultField.getFieldValue())) {
966                             docData.setIsbn(searchResultField.getFieldValue());
967                         }
968                         if (searchResultField.getFieldName().equals(BibConstants.ISSN_DISPLAY) && StringUtils.isNotBlank(searchResultField.getFieldValue())) {
969                             docData.setIsbn(searchResultField.getFieldValue());
970                         }
971 
972                     }
973                 }
974                 docDatas.add(docData);
975             }
976         } catch (Exception ex) {
977             GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, "Item Exists");
978             LOG.error(org.kuali.ole.OLEConstants.ITEM_EXIST + ex);
979         }
980 
981         return docDatas;
982     }
983 
984     private boolean validatePoByRetiredVersionStatus(PurchaseOrderDocument olePurchaseOrderDocument) {
985         return (olePurchaseOrderDocument.getPurchaseOrderCurrentIndicatorForSearching());
986     }
987 
988     private boolean validatePurchaseOrderStatus(List<PurchaseOrderType> purchasrOrderTypeList, PurchaseOrderDocument po) {
989         boolean valid = false;
990         for (PurchaseOrderType purchaseOrderTypes : purchasrOrderTypeList) {
991             BigDecimal poTypeId = purchaseOrderTypes.getPurchaseOrderTypeId();
992             if (poTypeId.compareTo(po.getPurchaseOrderTypeId()) == 0) {
993                 valid = true;
994             }
995         }
996         return valid;
997     }
998 
999 
1000     public void valueSearch() throws Exception {
1001         String[] purchaseOrderNumbers = {};
1002         Collection results = new ArrayList<OlePurchaseOrderItem>();
1003         Map purapDocumentIdentifierMap = new HashMap();
1004         if (this.purchaseOrderNumber != null) {
1005             purchaseOrderNumbers = (this.purchaseOrderNumber.toString()).split(",");
1006             for (int i = 0; i < purchaseOrderNumbers.length; i++) {
1007                 // TODO Auto-generated method stub
1008                 List<String> poDocNumbers = new ArrayList<String>();
1009                 LOG.debug(" OleReceivingQueueSearchDocument.valueSearch method starts ");
1010                 purapDocumentIdentifierMap = new HashMap();
1011 
1012                 if (purchaseOrderNumbers[i] != null) {
1013                     purapDocumentIdentifierMap.put("purchaseOrder.purapDocumentIdentifier", purchaseOrderNumbers[i]);
1014                 }
1015                 if (this.vendorName != null) {
1016                     purapDocumentIdentifierMap.put("purchaseOrder.vendorName", this.vendorName);
1017                 }
1018                 if (this.title != null) {
1019                     purapDocumentIdentifierMap.put("docData.title", this.title);
1020                 }
1021                 if (this.standardNumber != null) {
1022                     purapDocumentIdentifierMap.put("docData.isbn", this.standardNumber);
1023                 }
1024                 results.addAll(SpringContext.getBean(OleDocStoreLookupService.class).findCollectionBySearch(OlePurchaseOrderItem.class, purapDocumentIdentifierMap));
1025             }
1026 
1027         } else {
1028             purapDocumentIdentifierMap = new HashMap();
1029             if (this.purchaseOrderNumber != null) {
1030                 purapDocumentIdentifierMap.put("purchaseOrder.purapDocumentIdentifier", this.purchaseOrderNumber);
1031             }
1032             if (this.vendorName != null) {
1033                 purapDocumentIdentifierMap.put("purchaseOrder.vendorName", this.vendorName);
1034             }
1035             if (this.title != null) {
1036                 purapDocumentIdentifierMap.put("docData.title", this.title);
1037             }
1038             if (this.standardNumber != null) {
1039                 purapDocumentIdentifierMap.put("docData.isbn", this.standardNumber);
1040             }
1041             results.addAll(SpringContext.getBean(OleDocStoreLookupService.class).findCollectionBySearch(OlePurchaseOrderItem.class, purapDocumentIdentifierMap));
1042         }
1043 
1044 
1045         //results from docstore
1046         // Collection results = SpringContext.getBean(OleDocStoreLookupService.class).findCollectionBySearch(OlePurchaseOrderItem.class, purapDocumentIdentifierMap);
1047         boolean isbeginEndDateExsist = false;
1048         boolean isEndDateSmallerThanBeginDate = false;
1049         List<OlePurchaseOrderItem> tempResult = (List<OlePurchaseOrderItem>) results;
1050         List<String> docNumberList = new ArrayList<String>();
1051 
1052         //This code executes if begin date and end date is not null and checks whether enddate is greatter than begin date
1053         if (this.beginDate != null && this.endDate != null) {
1054             DateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
1055             Date startDate = formatter.parse(this.beginDate);
1056             Date endDate = formatter.parse(this.endDate);
1057             if (startDate.compareTo(endDate) > 0) {
1058                 isEndDateSmallerThanBeginDate = true;
1059                 GlobalVariables.getMessageMap().putError(OleSelectConstant.RECEIVING_QUEUE_SEARCH, OLEKeyConstants.PUR_ORD_DATE_TO_NOT_LESSER_THAN_PUR_ORD_DATE_FROM, new String[]{});
1060             }
1061         }
1062 
1063         //if enddate is greater than begin date this code will not execute
1064         /*if((this.beginDate!=null || this.endDate!=null) && !isEndDateSmallerThanBeginDate) {
1065             docNumberList= filterOtherSearchCriteria();
1066             isbeginEndDateExsist = true;
1067         }*/
1068 
1069         if (!isEndDateSmallerThanBeginDate) {
1070             if ((this.beginDate != null || this.endDate != null)) {
1071                 docNumberList = filterOtherSearchCriteria();
1072                 isbeginEndDateExsist = true;
1073             }
1074             for (int i = 0; i < tempResult.size(); i++) {
1075                 int purAppNum = tempResult.get(i).getPurchaseOrder().getPurapDocumentIdentifier();
1076                 String docNumber = tempResult.get(i).getPurchaseOrder().getDocumentNumber();
1077 
1078                 // int itemLineNumber = tempResult.get(i).getItemLineNumber();
1079                 boolean isValidRecord = validateRecords(purAppNum, docNumber);
1080                 boolean isSpecHandlingNotesExist = false;
1081                 /*
1082                  * if(isValidRecord) { isValidRecord = checkForReceivingLineItem(purAppNum,itemLineNumber); }
1083                  */
1084                 if (isValidRecord) {
1085                     isValidRecord = validateCopiesAndParts(tempResult.get(i));
1086                 }
1087                 if (tempResult.get(i).getNotes() != null) {
1088                     isSpecHandlingNotesExist = checkSpecialHandlingNotesExsist(tempResult.get(i));
1089                 }
1090                 if (this.purchaseOrderType != null && isValidRecord) {
1091                     isValidRecord = validatePurchaseOrderStatus(this.purchaseOrderType, purAppNum);
1092                 }
1093                 if (isbeginEndDateExsist) {
1094                     if (!docNumberList.contains(docNumber)) {
1095                         isValidRecord = false;
1096                     }
1097                 }
1098                 boolean isRetiredVersionPo = !(validatePoByRetiredVersionStatus((OlePurchaseOrderItem) tempResult.get(i)));
1099                 OlePurchaseOrderItem olePurchaseOrderItem = tempResult.get(i);
1100                 if (!isValidRecord || isRetiredVersionPo || isSpecHandlingNotesExist) {
1101                     tempResult.remove(i);
1102                     i--;
1103                 }
1104             }
1105 
1106             if (tempResult.size() <= 0) {
1107                 if(!GlobalVariables.getMessageMap().hasInfo()) {
1108                 GlobalVariables.getMessageMap().putInfo(OleSelectConstant.RECEIVING_QUEUE_SEARCH,
1109                         OLEKeyConstants.ERROR_NO_PURCHASEORDERS_FOUND);
1110                 }
1111             }
1112             this.setPurchaseOrders(removeReceivedTitles(tempResult));
1113             if(this.getPurchaseOrders().size()>0){
1114                 GlobalVariables.clear();
1115             }
1116         }
1117 
1118         LOG.debug(" OleReceivingQueueSearchDocument.valueSearch method ends ");
1119     }
1120 
1121     private List<OlePurchaseOrderItem> removeReceivedTitles(List<OlePurchaseOrderItem> purchaseOrderItems){
1122         SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
1123         String dateString = dateFormat.format(new Date());
1124         List<OlePurchaseOrderItem> result=new ArrayList<OlePurchaseOrderItem>();
1125             for(OlePurchaseOrderItem olePurchaseOrderItem:purchaseOrderItems){
1126                 String actionDateString = olePurchaseOrderItem.getClaimDate()!=null ? dateFormat.format(olePurchaseOrderItem.getClaimDate()) : "";
1127                 boolean serialPOLink = olePurchaseOrderItem.getCopyList()!=null && olePurchaseOrderItem.getCopyList().size()>0 ? olePurchaseOrderItem.getCopyList().get(0).getSerialReceivingIdentifier()!=null : false ;
1128                 OlePurchaseOrderDocument olePurchaseOrderDocument = olePurchaseOrderItem.getPurapDocument();
1129                 Map purchaseOrderTypeIdMap = new HashMap();
1130                 purchaseOrderTypeIdMap.put("purchaseOrderTypeId", olePurchaseOrderDocument.getPurchaseOrderTypeId());
1131                 org.kuali.rice.krad.service.BusinessObjectService businessObject = SpringContext.getBean(org.kuali.rice.krad.service.BusinessObjectService.class);
1132                 List<PurchaseOrderType> purchaseOrderTypeDocumentList = (List) businessObject.findMatching(PurchaseOrderType.class, purchaseOrderTypeIdMap);
1133                 boolean  continuing = purchaseOrderTypeDocumentList!=null && purchaseOrderTypeDocumentList.size()>0?
1134                         purchaseOrderTypeDocumentList.get(0).getPurchaseOrderType().equalsIgnoreCase("Continuing"):false;
1135                 if(olePurchaseOrderItem.getReceiptStatusId()!=null&&olePurchaseOrderItem.getReceiptStatusId().toString().equalsIgnoreCase((String.valueOf(getReceiptStatusDetails(OLEConstants.PO_RECEIPT_STATUS_FULLY_RECEIVED))))){
1136                     GlobalVariables.clear();
1137                     GlobalVariables.getMessageMap().putInfo(OleSelectConstant.RECEIVING_QUEUE_SEARCH,
1138                             OLEKeyConstants.ERROR_NO_PURCHASEORDERS_FOUND_FOR_FULLY_RECEIVED);
1139                 }
1140                 else if(this.isClaimFilter()){
1141                     if(!olePurchaseOrderItem.isDoNotClaim() && olePurchaseOrderItem.getClaimDate()!=null && (actionDateString.equalsIgnoreCase(dateString) || olePurchaseOrderItem.getClaimDate().before(new Date()))
1142                             && !serialPOLink && !continuing){
1143                         olePurchaseOrderItem.setClaimFilter(true);
1144                         result.add(olePurchaseOrderItem);
1145                     }
1146                 }else {
1147                     if(!olePurchaseOrderItem.isDoNotClaim() && olePurchaseOrderItem.getClaimDate()!=null && (actionDateString.equalsIgnoreCase(dateString) || olePurchaseOrderItem.getClaimDate().before(new Date()))
1148                             && !serialPOLink && !continuing){
1149                         olePurchaseOrderItem.setClaimFilter(true);
1150                     }
1151                     result.add(olePurchaseOrderItem);
1152                 }
1153 
1154             }
1155         return result;
1156     }
1157     private List<OlePurchaseOrderItem> removeFullyReceivedPO(List<OlePurchaseOrderItem> purchaseOrderItems){
1158         List<OlePurchaseOrderItem> result=new ArrayList<OlePurchaseOrderItem>();
1159         Map<String,List<OlePurchaseOrderItem>> listMap=new HashMap<String,List<OlePurchaseOrderItem>>();
1160         for (OlePurchaseOrderItem olePurchaseOrderItem : purchaseOrderItems) {
1161             if(olePurchaseOrderItem.getItemTypeCode().equalsIgnoreCase("Item")){
1162                 if(!listMap.containsKey(olePurchaseOrderItem.getDocumentNumber())){
1163                     List<OlePurchaseOrderItem> orderItems=new ArrayList<OlePurchaseOrderItem>();
1164                     orderItems.add(olePurchaseOrderItem);
1165                     listMap.put(olePurchaseOrderItem.getDocumentNumber(),orderItems);
1166                 } else {
1167                     for(Map.Entry<String,List<OlePurchaseOrderItem>> entry:listMap.entrySet()){
1168                         if(entry.getKey().equalsIgnoreCase(olePurchaseOrderItem.getDocumentNumber())){
1169                             List<OlePurchaseOrderItem> orderItems=entry.getValue();
1170                             orderItems.add(olePurchaseOrderItem);
1171                             entry.setValue(orderItems);
1172                         }
1173                     }
1174                 }
1175 
1176             }
1177         }
1178         for(Map.Entry<String,List<OlePurchaseOrderItem>> entry:listMap.entrySet()){
1179             int size=((List<OlePurchaseOrderItem>)entry.getValue()).size();
1180             boolean isFullyReceived=false;
1181             int count=0;
1182             List<OlePurchaseOrderItem> orderItems=entry.getValue();
1183             for(OlePurchaseOrderItem olePurchaseOrderItem:orderItems){
1184                 if(olePurchaseOrderItem.getReceiptStatusId()!=null&&olePurchaseOrderItem.getReceiptStatusId().toString().equalsIgnoreCase("5")){
1185                     count++;
1186                 }
1187             }
1188             if(size!=count){
1189                 result.addAll(orderItems);
1190             }
1191         }
1192 
1193 
1194         return result;
1195     }
1196 
1197     private boolean validatePoByRetiredVersionStatus(OlePurchaseOrderItem olePurchaseOrderItem) {
1198 
1199         Map<String, String> map = new HashMap<String, String>();
1200         map.put("documentNumber", olePurchaseOrderItem.getDocumentNumber());
1201         PurchaseOrderDocument po = SpringContext.getBean(PurchaseOrderService.class).getCurrentPurchaseOrder(olePurchaseOrderItem.getPurapDocumentIdentifier());
1202        /* po.getPurchaseOrderCurrentIndicatorForSearching(); */   /**/
1203         List<OlePurchaseOrderDocument> olePurchaseOrderDocumentList = (List<OlePurchaseOrderDocument>) KRADServiceLocator.getBusinessObjectService().findMatching(OlePurchaseOrderDocument.class, map);
1204         OlePurchaseOrderDocument olePurchaseOrderDocument = olePurchaseOrderDocumentList.get(0);
1205         return (olePurchaseOrderDocument.getPurchaseOrderCurrentIndicatorForSearching());
1206     }
1207 
1208     private boolean validatePurchaseOrderStatus(String purchaseOrderType, Integer purAppNum) {
1209         boolean valid = false;
1210         PurchaseOrderDocument po = SpringContext.getBean(PurchaseOrderService.class).getCurrentPurchaseOrder(purAppNum);
1211         /*
1212          * if(purchaseOrderStatus.equalsIgnoreCase(po.getStatusCode())) valid = true;
1213          */
1214         Map purchaseOrderTypeMap = new HashMap();
1215         purchaseOrderTypeMap.put("purchaseOrderType", purchaseOrderType);
1216         List<PurchaseOrderType> purchasrOrderTypeList = (List) SpringContext.getBean(BusinessObjectService.class)
1217                 .findMatching(PurchaseOrderType.class, purchaseOrderTypeMap);
1218         for (PurchaseOrderType purchaseOrderTypes : purchasrOrderTypeList) {
1219             BigDecimal poTypeId = purchaseOrderTypes.getPurchaseOrderTypeId();
1220             if (poTypeId.compareTo(po.getPurchaseOrderTypeId()) == 0) {
1221                 valid = true;
1222             }
1223         }
1224         return valid;
1225     }
1226 
1227     public boolean checkSpecialHandlingNotesExsist(OlePurchaseOrderItem olePurchaseOrderItem) {
1228         for (OleNotes poNote : olePurchaseOrderItem.getNotes()) {
1229             OleNoteType oleNoteType = SpringContext.getBean(OleNoteTypeService.class).getNoteTypeDetails(
1230                     poNote.getNoteTypeId());
1231             String noteType = oleNoteType.getNoteType();
1232             if (noteType.equalsIgnoreCase(OLEConstants.SPECIAL_PROCESSING_INSTRUCTION_NOTE)) {
1233                 if (LOG.isDebugEnabled()) {
1234                     LOG.debug("PO ID " + olePurchaseOrderItem.getPurapDocumentIdentifier()
1235                             + "has special handling notes");
1236                 }
1237                 return true;
1238             }
1239         }
1240         return false;
1241     }
1242 
1243     /*
1244      * public boolean checkForReceivingLineItem(Integer purAppNum, int itemLineNumber){ boolean valid=true; Map<String,Object>
1245      * poIdMap = new HashMap<String,Object>(); poIdMap.put("purchaseOrderIdentifier", purAppNum); List<OleLineItemReceivingDocument>
1246      * oleLineItemReceivingDocumentList =
1247      * (List)SpringContext.getBean(BusinessObjectService.class).findMatching(OleLineItemReceivingDocument.class, poIdMap); for(int
1248      * i=0;i<oleLineItemReceivingDocumentList.size();i++) { String docNum =
1249      * oleLineItemReceivingDocumentList.get(i).getDocumentNumber(); Map<String,Object> lineItemDocNumMap = new
1250      * HashMap<String,Object>(); lineItemDocNumMap.put("documentNumber", docNum); List<OleLineItemReceivingItem>
1251      * oleLineItemReceivingItemList =
1252      * (List)SpringContext.getBean(BusinessObjectService.class).findMatching(OleLineItemReceivingItem.class, lineItemDocNumMap);
1253      * if(oleLineItemReceivingItemList.size()>0) valid &= false; //Iterator itr = oleLineItemReceivingItemList.iterator(); //int
1254      * itmLineNumber = oleLineItemReceivingItemList.iterator().next().getItemLineNumber(); //if(itemLineNumber == itmLineNumber) {
1255      * // } } return valid; }
1256      */
1257 
1258     /**
1259      * This method validate records and returns boolean based on the validation
1260      *
1261      * @param purAppNum
1262      * @param docNumber
1263      * @return boolean
1264      */
1265     public boolean validateRecords(Integer purAppNum, String docNumber) {
1266         boolean valid = true;
1267         // Commented for checking receiving document checking
1268 
1269         /*
1270          * PurchaseOrderDocument po = SpringContext.getBean(PurchaseOrderService.class).getCurrentPurchaseOrder(purAppNum); if
1271          * (ObjectUtils.isNull(po)) { valid &= false; } Map<String,Object> poIdMap = new HashMap<String,Object>();
1272          * poIdMap.put("purchaseOrderIdentifier", purAppNum); List<OleLineItemReceivingDocument> oleLineItemReceivingDocumentList =
1273          * (List)SpringContext.getBean(BusinessObjectService.class).findMatching(OleLineItemReceivingDocument.class, poIdMap);
1274          * if(oleLineItemReceivingDocumentList.size()>0) { valid &= false; } if
1275          * (!SpringContext.getBean(ReceivingService.class).isPurchaseOrderActiveForLineItemReceivingDocumentCreation(purAppNum)){
1276          * valid &= false; } if( SpringContext.getBean(ReceivingService.class).canCreateLineItemReceivingDocument(purAppNum, null)
1277          * == false){ String inProcessDocNum = ""; List<String> inProcessDocNumbers =
1278          * SpringContext.getBean(ReceivingService.class).getLineItemReceivingDocumentNumbersInProcessForPurchaseOrder(purAppNum,
1279          * null); if (!inProcessDocNumbers.isEmpty()) { // should not be empty if we reach this point inProcessDocNum =
1280          * inProcessDocNumbers.get(0); } valid &= false; }
1281          */
1282         /*if(!po.getApplicationDocumentStatus().equalsIgnoreCase(OleSelectConstant.PURCHASEORDER_STATUS_OPEN) && valid){
1283             valid &= false;
1284         }
1285         else if(po.getApplicationDocumentStatus().equalsIgnoreCase(OleSelectConstant.PURCHASEORDER_STATUS_OPEN) && valid) {
1286             Map purchaseOrderIdMap = new HashMap();
1287             purchaseOrderIdMap.put("documentNumber", docNumber);
1288             List<OlePurchaseOrderDocument> purchasrOrderList = (List)SpringContext.getBean(BusinessObjectService.class).findMatching(OlePurchaseOrderDocument.class, purchaseOrderIdMap);
1289             for(int i=0;i<purchasrOrderList.size();i++){
1290                 if(!purchasrOrderList.get(i).getApplicationDocumentStatus().equalsIgnoreCase(OleSelectConstant.PURCHASEORDER_STATUS_OPEN)){
1291                     valid &= false;
1292                 }
1293             }
1294         }*/
1295         PurchaseOrderDocument po = SpringContext.getBean(PurchaseOrderService.class).getCurrentPurchaseOrder(purAppNum);
1296         valid &= SpringContext.getBean(ReceivingService.class).canCreateLineItemReceivingDocument(purAppNum, null);
1297         if (this.purchaseOrderStatusDescription != null && valid) {
1298             if (!purchaseOrderStatusDescription.equalsIgnoreCase(po.getApplicationDocumentStatus())) {
1299                 valid &= false;
1300             }
1301 
1302         }
1303         if(po.getApplicationDocumentStatus().equalsIgnoreCase("closed")){
1304             valid &= false;
1305             GlobalVariables.clear();
1306             GlobalVariables.getMessageMap().putInfo(OleSelectConstant.RECEIVING_QUEUE_SEARCH,
1307                     OLEKeyConstants.ERROR_NO_PURCHASEORDERS_FOUND_FOR_CLOSED);
1308 
1309         }
1310         // Check for existence of Special Handling Notes in PO. Create Line Item Receiving Document only if there are no Special handling notes
1311         /*if(hasSpecialHandlingNotes(po)){
1312             valid &= false;
1313         }*/
1314         return valid;
1315     }
1316 
1317 
1318     /**
1319      * This method checks whether Purchase order exists with given begin date and end date is exists
1320      *
1321      * @return List of Document Numbers
1322      * @throws WorkflowException
1323      */
1324     public List<String> filterOtherSearchCriteria() throws WorkflowException, ParseException {
1325         // date lookup
1326         Map<String, List<String>> fixedParameters = new HashMap<String, List<String>>();
1327         if (ObjectUtils.isNotNull(this.beginDate)) {
1328             fixedParameters.put(OleSelectConstant.FROM_DATE_CREATED, Collections.singletonList(this.beginDate));
1329         } else {
1330             fixedParameters.put(OleSelectConstant.FROM_DATE_CREATED, Collections.singletonList(""));
1331         }
1332         if (ObjectUtils.isNotNull(this.endDate)) {
1333             fixedParameters.put(OleSelectConstant.TO_DATE_CREATED, Collections.singletonList(this.endDate));
1334         }
1335 
1336         List<String> docNumber = new ArrayList<String>();
1337         if (!((fixedParameters.get(OleSelectConstant.FROM_DATE_CREATED) == null || fixedParameters.get(OleSelectConstant.FROM_DATE_CREATED).get(0).isEmpty()) &&
1338                 (fixedParameters.get(OleSelectConstant.TO_DATE_CREATED) == null || fixedParameters.get(OleSelectConstant.TO_DATE_CREATED).get(0).isEmpty()))) {
1339             docNumber = filterWorkflowStatusDate(fixedParameters);
1340             isDateLookup = true;
1341         }
1342 
1343         return docNumber;
1344     }
1345 
1346     /**
1347      * This method checks whether Purchase order exists with given begin date and end date
1348      *
1349      * @param fixedParameters
1350      * @return List of Document Numbers
1351      */
1352     public List<String> filterWorkflowStatusDate(Map<String, List<String>> fixedParameters) throws ParseException {
1353         DocumentSearchCriteria.Builder criteria = DocumentSearchCriteria.Builder.create();
1354         criteria.setDocumentAttributeValues(fixedParameters);
1355         if (StringUtils.isNotEmpty(this.beginDate)) {
1356             criteria.setDateCreatedFrom(new DateTime((SpringContext.getBean(DateTimeService.class)).convertToDate(beginDate)));
1357         }
1358         if (StringUtils.isNotEmpty(this.endDate)) {
1359             criteria.setDateCreatedTo(new DateTime((SpringContext.getBean(DateTimeService.class)).convertToDate(endDate)));
1360         }
1361         List<String> documentNumberList = new ArrayList();
1362         boolean isDateSpecified = true;
1363         try {
1364             DocumentSearchResults components = KewApiServiceLocator.getWorkflowDocumentService().documentSearch(GlobalVariables.getUserSession().getPrincipalId(), criteria.build());
1365             List<DocumentSearchResult> docSearchResults = components.getSearchResults();
1366             for (DocumentSearchResult docSearchResult : docSearchResults) {
1367                 documentNumberList.add(docSearchResult.getDocument().getDocumentId());
1368             }
1369         } catch (WorkflowServiceErrorException wsee) {
1370             for (WorkflowServiceError workflowServiceError : (List<WorkflowServiceError>) wsee.getServiceErrors()) {
1371                 if (workflowServiceError.getMessageMap() != null && workflowServiceError.getMessageMap().hasErrors()) {
1372                     // merge the message maps
1373                     GlobalVariables.getMessageMap().merge(workflowServiceError.getMessageMap());
1374                 } else {
1375                     //TODO: can we add something to this to get it to highlight the right field too?  Maybe in arg1
1376                     GlobalVariables.getMessageMap().putError(workflowServiceError.getMessage(), RiceKeyConstants.ERROR_CUSTOM, workflowServiceError.getMessage());
1377                 }
1378             }
1379             ;
1380         }
1381         return documentNumberList;
1382     }
1383 
1384     /**
1385      * This method validates if a receiving document can be created from a POID.
1386      * If all validations are passed, it initiates and submits receiving document for a POID.
1387      * This method does only complete receiving and populates error messages in case of exceptions.
1388      *
1389      * @param rlDoc                   OleLineItemReceivingDocument
1390      * @param purchaseOrderIdentifier Purchase Order Id
1391      */
1392     public boolean receivePO(OleLineItemReceivingDocument rlDoc, Integer purchaseOrderIdentifier, boolean isCreateRCV) {
1393         LOG.debug("Inside receivePO of OleReceivingQueueSearchDocument");
1394         GlobalVariables.getMessageMap().clearErrorPath();
1395         GlobalVariables.getMessageMap().addToErrorPath(OLEPropertyConstants.DOCUMENT);
1396 
1397         boolean receivePOSuccess = false;
1398 
1399         // Setting defaults
1400         rlDoc.setPurchaseOrderIdentifier(purchaseOrderIdentifier);
1401         DateTimeService dateTimeService = SpringContext.getBean(DateTimeService.class);
1402         rlDoc.setShipmentReceivedDate(dateTimeService.getCurrentSqlDate());
1403 
1404         if (LOG.isDebugEnabled()) {
1405             LOG.debug("PO ID in OleReceivingQueueSearchDocument.receivePO -" + purchaseOrderIdentifier);
1406         }
1407 
1408         // Validations Start
1409         boolean valid = true;
1410 
1411         PurchaseOrderDocument po = SpringContext.getBean(PurchaseOrderService.class).getCurrentPurchaseOrder(purchaseOrderIdentifier);
1412 
1413         if (ObjectUtils.isNotNull(po)) {
1414             rlDoc.setAccountsPayablePurchasingDocumentLinkIdentifier(po.getAccountsPayablePurchasingDocumentLinkIdentifier());
1415             if (!SpringContext.getBean(DocumentHelperService.class).getDocumentAuthorizer(rlDoc).isAuthorizedByTemplate(rlDoc, KRADConstants.KNS_NAMESPACE, KimConstants.PermissionTemplateNames.OPEN_DOCUMENT, GlobalVariables.getUserSession().getPrincipalId())) {
1416                 throw new DocumentAuthorizationException(GlobalVariables.getUserSession().getPerson().getPrincipalName(), "initiate document", rlDoc.getDocumentNumber());
1417             }
1418         } else {
1419             GlobalVariables.getMessageMap().putError(PurapPropertyConstants.PURCHASE_ORDER_IDENTIFIER, OLEKeyConstants.ERROR_RECEIVING_LINE_PO_NOT_EXIST, rlDoc.getPurchaseOrderIdentifier().toString());
1420         }
1421 
1422 
1423         if (!SpringContext.getBean(ReceivingService.class).isPurchaseOrderActiveForLineItemReceivingDocumentCreation(rlDoc.getPurchaseOrderIdentifier())) {
1424             GlobalVariables.getMessageMap().putError(PurapPropertyConstants.PURCHASE_ORDER_IDENTIFIER, OLEKeyConstants.ERROR_RECEIVING_LINE_PONOTACTIVE, rlDoc.getPurchaseOrderIdentifier().toString());
1425             valid &= false;
1426         }
1427 
1428         if (SpringContext.getBean(ReceivingService.class).canCreateLineItemReceivingDocument(rlDoc.getPurchaseOrderIdentifier(), rlDoc.getDocumentNumber()) == false) {
1429             String inProcessDocNum = "";
1430             List<String> inProcessDocNumbers = SpringContext.getBean(ReceivingService.class).getLineItemReceivingDocumentNumbersInProcessForPurchaseOrder(rlDoc.getPurchaseOrderIdentifier(), rlDoc.getDocumentNumber());
1431             if (!inProcessDocNumbers.isEmpty()) {    // should not be empty if we reach this point
1432                 inProcessDocNum = inProcessDocNumbers.get(0);
1433             }
1434             GlobalVariables.getMessageMap().putError(PurapPropertyConstants.PURCHASE_ORDER_IDENTIFIER, OLEKeyConstants.ERROR_RECEIVING_LINE_DOCUMENT_ACTIVE_FOR_PO, rlDoc.getPurchaseOrderIdentifier().toString(), inProcessDocNum);
1435             valid &= false;
1436         }
1437 
1438         // Check for existence of Special Handling Notes in PO. Create Line Item Receiving Document only if there are no Special handling notes
1439         /*if(hasSpecialHandlingNotes(po)){
1440             GlobalVariables.getMessageMap().putError(PurapPropertyConstants.PURCHASE_ORDER_IDENTIFIER, OLEKeyConstants.ERROR_PO_HAS_SPECIAL_HANDLING_NOTES, po.getPurapDocumentIdentifier().toString());
1441             valid &= false;
1442         }*/
1443 
1444         // Validations Ends
1445         if (LOG.isDebugEnabled()) {
1446             LOG.debug("PO ID in OleReceivingQueueSearchDocument.receivePO " + purchaseOrderIdentifier + "passed all validations");
1447         }
1448 
1449         try {
1450             if (valid) {
1451 
1452                 SpringContext.getBean(ReceivingService.class).populateAndSaveLineItemReceivingDocument(rlDoc);
1453 
1454                 List<OleLineItemReceivingItem> itemList = new ArrayList<OleLineItemReceivingItem>();
1455                 for (Object item : rlDoc.getItems()) {
1456                     OleLineItemReceivingItem rlItem = (OleLineItemReceivingItem) item;
1457                     // Receiving 100pc
1458                     boolean isPOItemPresent = false;
1459                     for (OlePurchaseOrderItem poItem : this.getPurchaseOrders()) {
1460                         if (poItem.isPoAdded()) {
1461                             if (!isPOItemPresent
1462                                     && poItem.getItemIdentifier().equals(rlItem.getPurchaseOrderIdentifier())) {
1463                                 rlItem.setItemReceivedTotalQuantity(rlItem.getItemReceivedToBeQuantity());
1464                                 rlItem.setItemReceivedTotalParts(rlItem.getItemReceivedToBeParts());
1465                                 rlItem.setPoSelected(true);
1466                                 /*
1467                                  * rlItem.setItemReceivedTotalQuantity(rlItem.getItemOrderedQuantity());
1468                                  * rlItem.setItemReceivedTotalParts(rlItem.getItemOrderedParts());
1469                                  */
1470                                 isPOItemPresent = true;
1471                             } else if (!isPOItemPresent) {
1472                                 rlItem.setItemReceivedTotalQuantity(KualiDecimal.ZERO);
1473                                 rlItem.setItemReceivedTotalParts(KualiDecimal.ZERO);
1474                             }
1475                         }
1476                     }
1477 
1478                     itemList.add(rlItem);
1479                 }
1480 
1481                 if (ObjectUtils.isNotNull(itemList) && itemList.size() > 0) {
1482                     rlDoc.setItems(itemList);
1483 
1484                     Person principalPerson = SpringContext.getBean(PersonService.class).getPerson(GlobalVariables.getUserSession().getPerson().getPrincipalId());
1485                     //rlDoc.getDocumentHeader().setWorkflowDocument(KRADServiceLocatorWeb.getWorkflowDocumentService().createWorkflowDocument(rlDoc.getDocumentHeader().getWorkflowDocument().getDocumentTypeName(), principalPerson));
1486                     rlDoc.getDocumentHeader().setWorkflowDocument(KRADServiceLocatorWeb.getWorkflowDocumentService().loadWorkflowDocument(rlDoc.getDocumentNumber(), principalPerson));
1487                     //rlDoc.setAdHocRoutePersons(buildFyiRecipient());
1488                     if (isCreateRCV) {
1489                         SpringContext.getBean(DocumentService.class).saveDocument(rlDoc);
1490                     } else {
1491                         List<OleLineItemReceivingItem> items = rlDoc.getItems();
1492                         for (OleLineItemReceivingItem item : items) {
1493                             OleLineItemReceivingService oleLineItemReceivingService = SpringContext.getBean(OleLineItemReceivingServiceImpl.class);
1494                             OlePurchaseOrderItem olePurchaseOrderItem = oleLineItemReceivingService.getOlePurchaseOrderItem(item.getPurchaseOrderIdentifier());
1495                             if (olePurchaseOrderItem != null) {
1496                                 if (item.isPoSelected()) {
1497                                     for (OleCopy oleCopy : item.getCopyList()) {
1498                                         oleCopy.setReceiptStatus(OLEConstants.OleLineItemReceiving.RECEIVED_STATUS);
1499                                     }
1500                                     OleCopyHelperService oleCopyHelperService = SpringContext.getBean(OleCopyHelperService.class);
1501                                     oleCopyHelperService.updateRequisitionAndPOItems(olePurchaseOrderItem, item, null, rlDoc.getIsATypeOfRCVGDoc());
1502                                 }
1503                             }
1504                         }
1505                         SpringContext.getBean(DocumentService.class).routeDocument(rlDoc,
1506                                 "Line Item Receiving from Receiving Queue Search page", null);
1507                     }
1508                     //GlobalVariables.getMessageMap().putInfo(PurapPropertyConstants.PURCHASE_ORDER_IDENTIFIER, OLEKeyConstants.MESSAGE_RECEIVING_LINE_SUBMITTED, new String[]{rlDoc.getPurchaseOrderIdentifier().toString(), rlDoc.getDocumentNumber()});
1509                     receivePOSuccess = true;
1510                 }
1511             }
1512         } catch (WorkflowException wfe) {
1513             String rcvDocNum = rlDoc.getDocumentNumber();
1514             String poId = rlDoc.getPurchaseOrderIdentifier().toString();
1515             GlobalVariables.getMessageMap().putError(PurapPropertyConstants.PURCHASE_ORDER_IDENTIFIER, OLEKeyConstants.ERROR_RECEIVING_LINE_SAVE_OR_SUBMIT, new String[]{poId, rcvDocNum, wfe.getMessage()});
1516             wfe.printStackTrace();
1517         }
1518 
1519         if (LOG.isDebugEnabled()) {
1520             LOG.debug("Receive PO status for PO ID " + purchaseOrderIdentifier + " is " + receivePOSuccess);
1521             LOG.debug("Leaving receivePO of OleReceivingQueueSearchDocument");
1522         }
1523 
1524         return receivePOSuccess;
1525     }
1526 
1527     public void updateRequisitionAndPOItems(OlePurchaseOrderItem olePurchaseOrderItem,
1528                                             OleLineItemReceivingItem oleLineItemReceivingItem) {
1529 
1530         List<OleCopy> copyList = oleLineItemReceivingItem.getCopyList() != null ? oleLineItemReceivingItem.getCopyList() : new ArrayList<OleCopy>();
1531         Integer receivedCount = 0;
1532         for (OleCopy oleCopy : copyList) {
1533             if (oleCopy.getReceiptStatus().equalsIgnoreCase("Received")) {
1534                 receivedCount++;
1535             }
1536         }
1537         if (receivedCount == 0) {
1538             oleLineItemReceivingItem
1539                     .setReceiptStatusId(getReceiptStatusDetails(OLEConstants.PO_RECEIPT_STATUS_NOT_RECEIVED));
1540         } else if (receivedCount == copyList.size()) {
1541             oleLineItemReceivingItem
1542                     .setReceiptStatusId(getReceiptStatusDetails(OLEConstants.PO_RECEIPT_STATUS_FULLY_RECEIVED));
1543         } else {
1544             oleLineItemReceivingItem
1545                     .setReceiptStatusId(getReceiptStatusDetails(OLEConstants.PO_RECEIPT_STATUS_PARTIALLY_RECEIVED));
1546         }
1547         olePurchaseOrderItem.setReceiptStatusId(oleLineItemReceivingItem.getReceiptStatusId());
1548         if (olePurchaseOrderItem.getItemQuantity().equals(new KualiDecimal(1)) && olePurchaseOrderItem.getItemNoOfParts().isGreaterThan(new KualiInteger(1))) {
1549             olePurchaseOrderItem.setNoOfCopiesReceived("N/A");
1550             olePurchaseOrderItem.setNoOfPartsReceived(receivedCount.toString());
1551         } else if (olePurchaseOrderItem.getItemQuantity().isGreaterThan(new KualiDecimal(1)) && olePurchaseOrderItem.getItemNoOfParts().equals(new KualiDecimal(1))) {
1552             olePurchaseOrderItem.setNoOfCopiesReceived(receivedCount.toString());
1553             olePurchaseOrderItem.setNoOfPartsReceived("N/A");
1554         } else if (olePurchaseOrderItem.getItemQuantity().isGreaterThan(new KualiDecimal(1)) && olePurchaseOrderItem.getItemNoOfParts().isGreaterThan(new KualiInteger(1))) {
1555             olePurchaseOrderItem.setNoOfCopiesReceived("See Copies Section");
1556             olePurchaseOrderItem.setNoOfPartsReceived("See Copies Section");
1557         }
1558         SpringContext.getBean(BusinessObjectService.class).save(olePurchaseOrderItem);
1559 
1560         String reqsItemId = copyList.size() > 0 ? copyList.get(0).getReqItemId().toString() : "";
1561         Map<String, String> reqItemMap = new HashMap<String, String>();
1562         reqItemMap.put("itemIdentifier", reqsItemId);
1563         OleRequisitionItem oleRequisitionItem = SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(OleRequisitionItem.class, reqItemMap);
1564         if (oleRequisitionItem != null) {
1565             oleRequisitionItem.setNoOfCopiesReceived(olePurchaseOrderItem.getNoOfCopiesReceived());
1566             oleRequisitionItem.setNoOfPartsReceived(olePurchaseOrderItem.getNoOfPartsReceived());
1567             oleRequisitionItem.setReceiptStatusId(olePurchaseOrderItem.getReceiptStatusId());
1568             SpringContext.getBean(BusinessObjectService.class).save(oleRequisitionItem);
1569         }
1570        /* olePurchaseOrderItem.setNoOfCopiesReceived((olePurchaseOrderItem.getNoOfCopiesReceived().add(new KualiInteger(
1571             oleLineItemReceivingItem.getItemReceivedTotalQuantity().bigDecimalValue()))).subtract(new KualiInteger(
1572             oleLineItemReceivingItem.getItemReturnedTotalQuantity().bigDecimalValue())));
1573         olePurchaseOrderItem.setNoOfPartsReceived((olePurchaseOrderItem.getNoOfPartsReceived().add(new KualiInteger(
1574             oleLineItemReceivingItem.getItemReceivedTotalParts().bigDecimalValue()))).subtract(new KualiInteger(
1575             oleLineItemReceivingItem.getItemReturnedTotalParts().bigDecimalValue())));
1576         if (olePurchaseOrderItem.getItemQuantity().intValue() == olePurchaseOrderItem.getNoOfCopiesReceived()
1577                 .intValue()
1578                 && olePurchaseOrderItem.getItemNoOfParts().intValue() == olePurchaseOrderItem.getNoOfPartsReceived()
1579                         .intValue()) {
1580             olePurchaseOrderItem
1581                     .setReceiptStatusId(getReceiptStatusDetails(OLEConstants.PO_RECEIPT_STATUS_FULLY_RECEIVED));
1582         }
1583         else {
1584             if (olePurchaseOrderItem.getNoOfPartsReceived().isZero()
1585                     && olePurchaseOrderItem.getNoOfCopiesReceived().isZero()) {
1586                 olePurchaseOrderItem
1587                         .setReceiptStatusId(getReceiptStatusDetails(OLEConstants.PO_RECEIPT_STATUS_NOT_RECEIVED));
1588             }
1589             else {
1590                 olePurchaseOrderItem
1591                         .setReceiptStatusId(getReceiptStatusDetails(OLEConstants.PO_RECEIPT_STATUS_PARTIALLY_RECEIVED));
1592             }
1593         }
1594         SpringContext.getBean(BusinessObjectService.class).save(olePurchaseOrderItem);
1595         Map<String, String> purDocNumMap = new HashMap<String, String>();
1596         purDocNumMap.put(OLEConstants.DOC_NUMBER, olePurchaseOrderItem.getDocumentNumber());
1597         List<OlePurchaseOrderDocument> poDocList = (List) SpringContext.getBean(BusinessObjectService.class)
1598                 .findMatching(OlePurchaseOrderDocument.class, purDocNumMap);
1599         for (OlePurchaseOrderDocument olePurchaseOrderDocument : poDocList) {
1600             String reqsDocIdentifier = olePurchaseOrderDocument.getRequisitionIdentifier().toString();
1601             Map<String, String> reqDocNumMap = new HashMap<String, String>();
1602             reqDocNumMap.put(OLEConstants.PUR_DOC_IDENTIFIER, reqsDocIdentifier);
1603             List<OleRequisitionItem> reqItemList = (List) SpringContext.getBean(BusinessObjectService.class)
1604                     .findMatching(OleRequisitionItem.class, reqDocNumMap);
1605             for (OleRequisitionItem oleRequisitionItem : reqItemList) {
1606                 if (null != oleRequisitionItem.getItemLineNumber()
1607                         && OLEConstants.ITEM.equalsIgnoreCase(oleRequisitionItem.getItemTypeCode())) {
1608                     if (oleLineItemReceivingItem.getItemLineNumber().intValue() == oleRequisitionItem
1609                             .getItemLineNumber().intValue()) {
1610                         oleRequisitionItem.setNoOfCopiesReceived(olePurchaseOrderItem.getNoOfCopiesReceived());
1611                         oleRequisitionItem.setNoOfPartsReceived(olePurchaseOrderItem.getNoOfPartsReceived());
1612                         oleRequisitionItem.setReceiptStatusId(olePurchaseOrderItem.getReceiptStatusId());
1613                         SpringContext.getBean(BusinessObjectService.class).save(oleRequisitionItem);
1614                     }
1615                 }
1616             }
1617         }*/
1618     }
1619 
1620     public int getReceiptStatusDetails(String receiptStatusCd) {
1621         int receiptStatusId = 0;
1622         Map<String, String> receiptStatusCdMap = new HashMap<String, String>();
1623         receiptStatusCdMap.put(OLEConstants.RCPT_STATUS_CD, receiptStatusCd);
1624         List<OleReceiptStatus> oleReceiptStatusList = (List) SpringContext.getBean(BusinessObjectService.class)
1625                 .findMatching(OleReceiptStatus.class, receiptStatusCdMap);
1626         for (OleReceiptStatus oleReceiptStatus : oleReceiptStatusList) {
1627             receiptStatusId = oleReceiptStatus.getReceiptStatusId().intValue();
1628         }
1629         return receiptStatusId;
1630     }
1631 
1632     /**
1633      * This method check if any item in PurchaseOrderDocument has special handling notes in it.
1634      *
1635      * @param po
1636      * @return
1637      */
1638     private boolean hasSpecialHandlingNotes(PurchaseOrderDocument po) {
1639         LOG.debug("Inside hasSpecialHandlingNotes of OleReceivingQueueSearchDocument");
1640         for (OlePurchaseOrderItem poItem : (List<OlePurchaseOrderItem>) po.getItems()) {
1641             for (OleNotes poNote : poItem.getNotes()) {
1642                 OleNoteType oleNoteType = SpringContext.getBean(OleNoteTypeService.class).getNoteTypeDetails(poNote.getNoteTypeId());
1643                 String noteType = oleNoteType.getNoteType();
1644                 if (noteType.equalsIgnoreCase(OLEConstants.SPECIAL_PROCESSING_INSTRUCTION_NOTE)) {
1645                     if (LOG.isDebugEnabled()) {
1646                         LOG.debug("PO ID " + poItem.getPurapDocumentIdentifier() + "has special handling notes");
1647                     }
1648                     return true;
1649                 }
1650             }
1651         }
1652         LOG.debug("Leaving hasSpecialHandlingNotes of OleReceivingQueueSearchDocument");
1653         return false;
1654     }
1655 
1656     /**
1657      * Gets the beginDate attribute.
1658      *
1659      * @return Returns the beginDate.
1660      */
1661     public String getBeginDate() {
1662         return beginDate;
1663     }
1664 
1665     /**
1666      * Sets the beginDate attribute value.
1667      *
1668      * @param beginDate The beginDate to set.
1669      */
1670     public void setBeginDate(String beginDate) {
1671         this.beginDate = beginDate;
1672     }
1673 
1674     /**
1675      * Gets the endDate attribute.
1676      *
1677      * @return Returns the endDate.
1678      */
1679     public String getEndDate() {
1680         return endDate;
1681     }
1682 
1683     /**
1684      * Sets the endDate attribute value.
1685      *
1686      * @param endDate The endDate to set.
1687      */
1688     public void setEndDate(String endDate) {
1689         this.endDate = endDate;
1690     }
1691 
1692     private boolean validateCopiesAndParts(OlePurchaseOrderItem poItem) {
1693         boolean isValid = true;
1694       /*  if ((poItem.getNoOfCopiesReceived() != null && poItem.getItemQuantity().compareTo(
1695                 poItem.getNoOfCopiesReceived().kualiDecimalValue()) == 0)
1696                 && (poItem.getNoOfPartsReceived() != null && poItem.getItemNoOfParts().compareTo(
1697                         poItem.getNoOfPartsReceived()) == 0)) {
1698             isValid = false;
1699         }*/
1700         return isValid;
1701     }
1702 
1703     private List<AdHocRoutePerson> buildFyiRecipient() {
1704         List<AdHocRoutePerson> persons = new ArrayList<AdHocRoutePerson>();
1705         AdHocRoutePerson adHocRoutePerson = new AdHocRoutePerson();
1706         adHocRoutePerson.setActionRequested(KewApiConstants.ACTION_REQUEST_FYI_REQ);
1707         adHocRoutePerson.setId(GlobalVariables.getUserSession().getPrincipalName());
1708         persons.add(adHocRoutePerson);
1709         return persons;
1710     }
1711 }