1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
98
99 private String vendorName;
100
101 private String beginDate;
102
103 private String endDate;
104
105
106
107
108
109
110
111 private boolean monograph;
112
113
114
115
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
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
175
176
177
178 public String getPurchaseOrderStatusDescription() {
179 return purchaseOrderStatusDescription;
180 }
181
182
183
184
185
186
187 public void setPurchaseOrderStatusDescription(String purchaseOrderStatusDescription) {
188 this.purchaseOrderStatusDescription = purchaseOrderStatusDescription;
189 }
190
191
192
193
194
195
196 public PurchaseOrderType getOrderType() {
197 return orderType;
198 }
199
200
201
202
203
204
205 public void setOrderType(PurchaseOrderType orderType) {
206 this.orderType = orderType;
207 }
208
209
210
211
212
213
214 public String getPurchaseOrderType() {
215 return purchaseOrderType;
216 }
217
218
219
220
221
222
223 public void setPurchaseOrderType(String purchaseOrderType) {
224 this.purchaseOrderType = purchaseOrderType;
225 }
226
227
228
229
230
231
232 public String getPurchaseOrderNumber() {
233 return purchaseOrderNumber;
234 }
235
236
237
238
239
240
241 public void setPurchaseOrderNumber(String purchaseOrderNumber) {
242 this.purchaseOrderNumber = purchaseOrderNumber;
243 }
244
245
246
247
248
249
250 public String getStandardNumber() {
251 return standardNumber;
252 }
253
254
255
256
257
258
259 public void setStandardNumber(String standardNumber) {
260 this.standardNumber = standardNumber;
261 }
262
263
264
265
266
267
268 public String getTitle() {
269 return title;
270 }
271
272
273
274
275
276
277 public void setTitle(String title) {
278 this.title = title;
279 }
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302 public String getVendorName() {
303 return vendorName;
304 }
305
306
307
308
309
310
311 public void setVendorName(String vendorName) {
312 this.vendorName = vendorName;
313 }
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368 public boolean isMonograph() {
369 return monograph;
370 }
371
372
373
374
375
376
377 public void setMonograph(boolean monograph) {
378 this.monograph = monograph;
379 }
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418 public VendorDetail getVendorDetail() {
419 return vendorDetail;
420 }
421
422
423
424
425
426
427 public void setVendorDetail(VendorDetail vendorDetail) {
428 this.vendorDetail = vendorDetail;
429 }
430
431
432
433
434
435
436 public boolean isReceive() {
437 return receive;
438 }
439
440
441
442
443
444
445 public void setReceive(boolean receive) {
446 this.receive = receive;
447 }
448
449
450
451
452
453
454 public String getAuthor() {
455 return author;
456 }
457
458
459
460
461
462
463 public void setAuthor(String author) {
464 this.author = author;
465 }
466
467
468
469
470
471
472 public String getPublisher() {
473 return publisher;
474 }
475
476
477
478
479
480
481 public void setPublisher(String publisher) {
482 this.publisher = publisher;
483 }
484
485
486
487
488
489
490 public String getEdition() {
491 return edition;
492 }
493
494
495
496
497
498
499 public void setEdition(String edition) {
500 this.edition = edition;
501 }
502
503
504
505
506
507
508 public String getQuatityOrdered() {
509 return quatityOrdered;
510 }
511
512
513
514
515
516
517 public void setQuatityOrdered(String quatityOrdered) {
518 this.quatityOrdered = quatityOrdered;
519 }
520
521
522
523
524
525
526 public String getPoints() {
527 return points;
528 }
529
530
531
532
533
534
535 public void setPoints(String points) {
536 this.points = points;
537 }
538
539
540
541
542
543
544 public String getInstructions() {
545 return instructions;
546 }
547
548
549
550
551
552
553 public void setInstructions(String instructions) {
554 this.instructions = instructions;
555 }
556
557
558
559
560
561
562 public PurchaseOrderDocument getPurchaseOrderDocument() {
563 return purchaseOrderDocument;
564 }
565
566
567
568
569
570
571 public void setPurchaseOrderDocument(PurchaseOrderDocument purchaseOrderDocument) {
572 this.purchaseOrderDocument = purchaseOrderDocument;
573 }
574
575
576
577
578
579
580 public List<OlePurchaseOrderItem> getPurchaseOrders() {
581 return purchaseOrders;
582 }
583
584
585
586
587
588
589 public void setPurchaseOrders(List<OlePurchaseOrderItem> purchaseOrders) {
590 this.purchaseOrders = purchaseOrders;
591 }
592
593
594
595
596
597
598
599 public List<String> getReceivingDocumentsList() {
600 return receivingDocumentsList;
601 }
602
603
604
605
606
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
640
641
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
783 Date currentDate = new Date();
784 docSearchCriteria.setDateCreatedTo(new DateTime(currentDate));
785
786
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
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
849
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
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
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
1046
1047 boolean isbeginEndDateExsist = false;
1048 boolean isEndDateSmallerThanBeginDate = false;
1049 List<OlePurchaseOrderItem> tempResult = (List<OlePurchaseOrderItem>) results;
1050 List<String> docNumberList = new ArrayList<String>();
1051
1052
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
1064
1065
1066
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
1079 boolean isValidRecord = validateRecords(purAppNum, docNumber);
1080 boolean isSpecHandlingNotesExist = false;
1081
1082
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
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
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
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265 public boolean validateRecords(Integer purAppNum, String docNumber) {
1266 boolean valid = true;
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
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
1311
1312
1313
1314 return valid;
1315 }
1316
1317
1318
1319
1320
1321
1322
1323
1324 public List<String> filterOtherSearchCriteria() throws WorkflowException, ParseException {
1325
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
1348
1349
1350
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
1373 GlobalVariables.getMessageMap().merge(workflowServiceError.getMessageMap());
1374 } else {
1375
1376 GlobalVariables.getMessageMap().putError(workflowServiceError.getMessage(), RiceKeyConstants.ERROR_CUSTOM, workflowServiceError.getMessage());
1377 }
1378 }
1379 ;
1380 }
1381 return documentNumberList;
1382 }
1383
1384
1385
1386
1387
1388
1389
1390
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
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
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()) {
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
1439
1440
1441
1442
1443
1444
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
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
1468
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
1486 rlDoc.getDocumentHeader().setWorkflowDocument(KRADServiceLocatorWeb.getWorkflowDocumentService().loadWorkflowDocument(rlDoc.getDocumentNumber(), principalPerson));
1487
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
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
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
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
1634
1635
1636
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
1658
1659
1660
1661 public String getBeginDate() {
1662 return beginDate;
1663 }
1664
1665
1666
1667
1668
1669
1670 public void setBeginDate(String beginDate) {
1671 this.beginDate = beginDate;
1672 }
1673
1674
1675
1676
1677
1678
1679 public String getEndDate() {
1680 return endDate;
1681 }
1682
1683
1684
1685
1686
1687
1688 public void setEndDate(String endDate) {
1689 this.endDate = endDate;
1690 }
1691
1692 private boolean validateCopiesAndParts(OlePurchaseOrderItem poItem) {
1693 boolean isValid = true;
1694
1695
1696
1697
1698
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 }