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.apache.commons.lang.time.DateUtils;
21 import org.apache.commons.lang.time.StopWatch;
22 import org.joda.time.DateTime;
23 import org.kuali.ole.DocumentUniqueIDPrefix;
24 import org.kuali.ole.docstore.common.client.DocstoreClientLocator;
25 import org.kuali.ole.docstore.common.constants.DocstoreConstants;
26 import org.kuali.ole.docstore.common.document.Bib;
27 import org.kuali.ole.docstore.common.document.ItemOleml;
28 import org.kuali.ole.docstore.common.document.content.enums.DocType;
29 import org.kuali.ole.docstore.common.search.SearchResponse;
30 import org.kuali.ole.docstore.common.search.SearchResult;
31 import org.kuali.ole.docstore.common.search.SearchResultField;
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.OleLineItemReceivingService;
42 import org.kuali.ole.select.document.service.OleNoteTypeService;
43 import org.kuali.ole.select.document.service.ReceivingQueueDAOService;
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.search.DocumentSearchCriteria;
61 import org.kuali.rice.kew.api.document.search.DocumentSearchResult;
62 import org.kuali.rice.kew.api.document.search.DocumentSearchResults;
63 import org.kuali.rice.kew.api.exception.WorkflowException;
64 import org.kuali.rice.kew.exception.WorkflowServiceError;
65 import org.kuali.rice.kew.exception.WorkflowServiceErrorException;
66 import org.kuali.rice.kew.service.KEWServiceLocator;
67 import org.kuali.rice.kim.api.KimConstants;
68 import org.kuali.rice.kim.api.identity.Person;
69 import org.kuali.rice.kim.api.identity.PersonService;
70 import org.kuali.rice.kns.service.DocumentHelperService;
71 import org.kuali.rice.krad.bo.AdHocRoutePerson;
72 import org.kuali.rice.krad.document.TransactionalDocumentBase;
73 import org.kuali.rice.krad.exception.DocumentAuthorizationException;
74 import org.kuali.rice.krad.service.BusinessObjectService;
75 import org.kuali.rice.krad.service.DocumentService;
76 import org.kuali.rice.krad.service.KRADServiceLocator;
77 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
78 import org.kuali.rice.krad.util.GlobalVariables;
79 import org.kuali.rice.krad.util.KRADConstants;
80 import org.kuali.rice.krad.util.ObjectUtils;
81
82 import java.math.BigDecimal;
83 import java.text.DateFormat;
84 import java.text.ParseException;
85 import java.text.SimpleDateFormat;
86 import java.util.*;
87
88 public class OleReceivingQueueSearchDocument extends TransactionalDocumentBase implements DocstoreConstants {
89
90 private String purchaseOrderNumber;
91
92 private String standardNumber;
93
94 private String title;
95
96
97
98 private String vendorName;
99
100 private String beginDate;
101
102 private String endDate;
103
104
105
106
107
108
109
110 private boolean monograph;
111
112
113
114
115
116 private VendorDetail vendorDetail;
117
118 private String purchaseOrderStatusDescription;
119
120 private PurchaseOrderType orderType;
121
122 private String purchaseOrderType;
123
124 private boolean receive;
125
126 private String author;
127
128 private String publisher;
129
130 private String edition;
131
132 private String quatityOrdered;
133
134 private String points;
135
136 private String instructions;
137
138 private PurchaseOrderDocument purchaseOrderDocument;
139
140 public boolean isDateLookup = false;
141
142 private List<String> receivingDocumentsList = new ArrayList<String>();
143
144
145
146 private String documentNumber = null;
147
148 private DateTimeService dateTimeService;
149
150 private PurchaseOrderService purchaseOrderService;
151
152 private BusinessObjectService businessObjectService;
153
154 private ConfigurationService configurationService;
155
156 private ReceivingService receivingService;
157
158 private OleNoteTypeService oleNoteTypeService;
159
160 private List<PurchaseOrderType> purchaseOrderTypeDocumentList = new ArrayList<>();
161
162 private Map<String, Object> queryCriteriaMap = new HashMap<>();
163
164 public DateTimeService getDateTimeService() {
165 if (dateTimeService == null) {
166 dateTimeService = SpringContext.getBean(DateTimeService.class);
167 }
168 return dateTimeService;
169 }
170
171 public List<OlePurchaseOrderItem> purchaseOrderItems = new ArrayList<OlePurchaseOrderItem>(0);
172
173 protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OleReceivingQueueSearchDocument.class);
174
175 private boolean claimFilter;
176
177
178 public boolean isClaimFilter() {
179 return claimFilter;
180 }
181
182 public void setClaimFilter(boolean claimFilter) {
183 this.claimFilter = claimFilter;
184 }
185
186
187
188
189
190
191 public String getPurchaseOrderStatusDescription() {
192 return purchaseOrderStatusDescription;
193 }
194
195
196
197
198
199
200 public void setPurchaseOrderStatusDescription(String purchaseOrderStatusDescription) {
201 this.purchaseOrderStatusDescription = purchaseOrderStatusDescription;
202 }
203
204
205
206
207
208
209 public PurchaseOrderType getOrderType() {
210 return orderType;
211 }
212
213
214
215
216
217
218 public void setOrderType(PurchaseOrderType orderType) {
219 this.orderType = orderType;
220 }
221
222
223
224
225
226
227 public String getPurchaseOrderType() {
228 return purchaseOrderType;
229 }
230
231
232
233
234
235
236 public void setPurchaseOrderType(String purchaseOrderType) {
237 this.purchaseOrderType = purchaseOrderType;
238 }
239
240
241
242
243
244
245 public String getPurchaseOrderNumber() {
246 return purchaseOrderNumber;
247 }
248
249
250
251
252
253
254 public void setPurchaseOrderNumber(String purchaseOrderNumber) {
255 this.purchaseOrderNumber = purchaseOrderNumber;
256 }
257
258
259
260
261
262
263 public String getStandardNumber() {
264 return standardNumber;
265 }
266
267
268
269
270
271
272 public void setStandardNumber(String standardNumber) {
273 this.standardNumber = standardNumber;
274 }
275
276
277
278
279
280
281 public String getTitle() {
282 return title;
283 }
284
285
286
287
288
289
290 public void setTitle(String title) {
291 this.title = title;
292 }
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315 public String getVendorName() {
316 return vendorName;
317 }
318
319
320
321
322
323
324 public void setVendorName(String vendorName) {
325 this.vendorName = vendorName;
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
369
370
371
372
373
374
375
376
377
378
379
380
381 public boolean isMonograph() {
382 return monograph;
383 }
384
385
386
387
388
389
390 public void setMonograph(boolean monograph) {
391 this.monograph = monograph;
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
419
420
421
422
423
424
425
426
427
428
429
430
431 public VendorDetail getVendorDetail() {
432 return vendorDetail;
433 }
434
435
436
437
438
439
440 public void setVendorDetail(VendorDetail vendorDetail) {
441 this.vendorDetail = vendorDetail;
442 }
443
444
445
446
447
448
449 public boolean isReceive() {
450 return receive;
451 }
452
453
454
455
456
457
458 public void setReceive(boolean receive) {
459 this.receive = receive;
460 }
461
462
463
464
465
466
467 public String getAuthor() {
468 return author;
469 }
470
471
472
473
474
475
476 public void setAuthor(String author) {
477 this.author = author;
478 }
479
480
481
482
483
484
485 public String getPublisher() {
486 return publisher;
487 }
488
489
490
491
492
493
494 public void setPublisher(String publisher) {
495 this.publisher = publisher;
496 }
497
498
499
500
501
502
503 public String getEdition() {
504 return edition;
505 }
506
507
508
509
510
511
512 public void setEdition(String edition) {
513 this.edition = edition;
514 }
515
516
517
518
519
520
521 public String getQuatityOrdered() {
522 return quatityOrdered;
523 }
524
525
526
527
528
529
530 public void setQuatityOrdered(String quatityOrdered) {
531 this.quatityOrdered = quatityOrdered;
532 }
533
534
535
536
537
538
539 public String getPoints() {
540 return points;
541 }
542
543
544
545
546
547
548 public void setPoints(String points) {
549 this.points = points;
550 }
551
552
553
554
555
556
557 public String getInstructions() {
558 return instructions;
559 }
560
561
562
563
564
565
566 public void setInstructions(String instructions) {
567 this.instructions = instructions;
568 }
569
570
571
572
573
574
575 public PurchaseOrderDocument getPurchaseOrderDocument() {
576 return purchaseOrderDocument;
577 }
578
579
580
581
582
583
584 public void setPurchaseOrderDocument(PurchaseOrderDocument purchaseOrderDocument) {
585 this.purchaseOrderDocument = purchaseOrderDocument;
586 }
587
588
589
590
591
592
593 public List<OlePurchaseOrderItem> getPurchaseOrderItems() {
594 return purchaseOrderItems;
595 }
596
597
598
599
600
601
602 public void setPurchaseOrderItems(List<OlePurchaseOrderItem> purchaseOrderItems) {
603 this.purchaseOrderItems = purchaseOrderItems;
604 }
605
606
607
608
609
610
611
612 public List<String> getReceivingDocumentsList() {
613 return receivingDocumentsList;
614 }
615
616
617
618
619
620
621 public void setReceivingDocumentsList(List<String> receivingDocumentsList) {
622 this.receivingDocumentsList = receivingDocumentsList;
623 }
624
625 @SuppressWarnings("rawtypes")
626
627 protected LinkedHashMap toStringMapper_RICE20_REFACTORME() {
628 LinkedHashMap m = new LinkedHashMap();
629 return m;
630 }
631
632 public boolean isPurchaseOrderDocumentAdded() {
633 if (this.purchaseOrderItems != null) {
634 return this.purchaseOrderItems.size() > 0;
635 } else {
636 return false;
637 }
638 }
639
640 private DocstoreClientLocator docstoreClientLocator;
641
642 public DocstoreClientLocator getDocstoreClientLocator() {
643
644 if (docstoreClientLocator == null) {
645 docstoreClientLocator = SpringContext.getBean(DocstoreClientLocator.class);
646
647 }
648 return docstoreClientLocator;
649 }
650
651
652
653
654
655
656 public void receiveingQueueRecordSearch() {
657 Long b1 = System.currentTimeMillis();
658 Set<String> bibIds = new HashSet<String>();
659 List<OlePurchaseOrderItem> purchaseOrderItemList = new ArrayList<>();
660 List<OlePurchaseOrderItem> results = new ArrayList<>();
661 boolean isOnlyDocCriteria = false;
662 boolean isDbCriteriaExist = false;
663 if ((StringUtils.isNotBlank(purchaseOrderNumber) || StringUtils.isNotBlank(purchaseOrderType) || StringUtils.isNotBlank(vendorName)
664 || StringUtils.isNotBlank(purchaseOrderStatusDescription) || ObjectUtils.isNotNull(beginDate) || ObjectUtils.isNotNull(endDate))) {
665 isDbCriteriaExist = true;
666 }
667 BigDecimal orderTypeId = null;
668 if (StringUtils.isNotBlank(this.purchaseOrderType)) {
669 Map<String, String> orderTypeMap = new HashMap<String, String>();
670 orderTypeMap.put("purchaseOrderType", this.purchaseOrderType);
671 List<PurchaseOrderType> items = (List<PurchaseOrderType>) KRADServiceLocator.getBusinessObjectService().findMatching(PurchaseOrderType.class, orderTypeMap);
672 if (CollectionUtils.isNotEmpty(items)) {
673 orderTypeId = items.get(0).getPurchaseOrderTypeId();
674 }
675 }
676 if (!isDbCriteriaExist && (StringUtils.isNotBlank(this.title) || (StringUtils.isNotBlank(this.standardNumber)))) {
677 isOnlyDocCriteria = true;
678 List<String> newBibIds = new ArrayList<>();
679 List<DocData> docDatas=getDocDatas(this.title, this.standardNumber);
680 for (DocData docData : docDatas) {
681 Map<String, String> poItemMap = new HashMap<String, String>();
682 poItemMap.put("itemTitleId", docData.getBibIdentifier());
683 poItemMap.put("itemTypeCode", "ITEM");
684 List<OlePurchaseOrderItem> items = (List<OlePurchaseOrderItem>) KRADServiceLocator.getBusinessObjectService().findMatching(OlePurchaseOrderItem.class, poItemMap);
685 if (CollectionUtils.isNotEmpty(items)) {
686 for (OlePurchaseOrderItem orderItem : items) {
687 if (orderItem.isItemActiveIndicator() &&
688 orderItem.getItemType().isQuantityBasedGeneralLedgerIndicator() &&
689 orderItem.getItemType().isLineItemIndicator()) {
690 orderItem.setDocData(docData);
691 int purAppNum = orderItem.getPurchaseOrder().getPurapDocumentIdentifier();
692 String docNumber = orderItem.getPurchaseOrder().getDocumentNumber();
693 if (validatePurchaseOrderItem(orderItem) && validateRecords(purAppNum, docNumber)) {
694 newBibIds.add(orderItem.getItemTitleId());
695 results.add(orderItem);
696 }
697 }
698
699 }
700 }
701 }
702 bibIds.clear();
703 bibIds.addAll(newBibIds);
704 this.setPurchaseOrderItems(results);
705 } else {
706
707 if (StringUtils.isNotBlank(purchaseOrderNumber)) {
708 String[] purchaseOrderNumbers = (this.purchaseOrderNumber.toString()).split(",");
709 for (int i = 0; i < purchaseOrderNumbers.length; i++) {
710 results.addAll(getSearchResults(purchaseOrderNumbers[i], bibIds, orderTypeId));
711 }
712
713 } else {
714 results.addAll(getSearchResults("", bibIds, orderTypeId));
715 }
716 try {
717 if (CollectionUtils.isNotEmpty(bibIds)) {
718 List<Bib> bibs = new ArrayList<>();
719 bibs.addAll(getDocstoreClientLocator().getDocstoreClient().acquisitionSearchRetrieveBibs(new ArrayList<String>(bibIds)));
720 if (bibIds != null && bibs != null) {
721 for (OlePurchaseOrderItem orderItem : results) {
722 if (orderItem.isItemActiveIndicator() &&
723 orderItem.getItemType().isQuantityBasedGeneralLedgerIndicator() &&
724 orderItem.getItemType().isLineItemIndicator()) {
725 inner:
726 for (Bib bib : bibs) {
727 if (bib.getId().equals(orderItem.getItemTitleId())) {
728 boolean isAllowed = true;
729 boolean isTitle = true;
730 boolean isIsbn = true;
731 if (StringUtils.isNotBlank(this.title)) {
732 if (!bib.getTitle().contains(this.title)) {
733 isTitle = false;
734 }
735 isAllowed = false;
736 }
737 if (StringUtils.isNotBlank(this.standardNumber)) {
738 if (!bib.getIsbn().equals(this.standardNumber)) {
739 isIsbn = false;
740 }
741 isAllowed = false;
742 }
743 if (!isAllowed) {
744 isAllowed = isIsbn && isTitle;
745 }
746 if (isAllowed) {
747 DocData docData = new DocData();
748 docData.setTitle(bib.getTitle());
749 docData.setAuthor(bib.getAuthor());
750 docData.setPublisher(bib.getPublisher());
751 if (StringUtils.isNotBlank(bib.getIsbn())) {
752 docData.setIsbn(bib.getIsbn());
753 } else {
754 docData.setIsbn(bib.getIssn());
755 }
756
757 docData.setLocalIdentifier(DocumentUniqueIDPrefix.getDocumentId(bib.getId()));
758 docData.setBibIdentifier(bib.getId());
759 orderItem.setDocData(docData);
760 purchaseOrderItemList.add(orderItem);
761 break inner;
762 }
763
764 }
765 }
766 }
767 }
768 }
769 }
770
771 } catch (Exception e) {
772
773 }
774 this.setPurchaseOrderItems(purchaseOrderItemList);
775 }
776
777 }
778
779 public void receiveingQueueRecordSearchs() {
780 queryCriteriaMap = new HashMap<>();
781 StopWatch searchRecordWatch=new StopWatch();
782 searchRecordWatch.start();
783 Set<String> bibIds = new HashSet<String>();
784 Map<String,DocData> docDataMap = new HashMap<>();
785 List<OlePurchaseOrderItem> purchaseOrderItemList = new ArrayList<>();
786 if ((StringUtils.isNotBlank(this.title) || (StringUtils.isNotBlank(this.standardNumber)))) {
787 List<DocData> docDatas=getDocDatas(this.title, this.standardNumber);
788 for (DocData docData : docDatas) {
789 bibIds.add(docData.getBibIdentifier());
790 docDataMap.put(docData.getBibIdentifier(),docData);
791 }
792 if(docDatas.size()==0){
793 queryCriteriaMap.put("title", title);
794 }
795 purchaseOrderItemList=getSearchResultsFromQuery(null, bibIds);
796 for(OlePurchaseOrderItem olePurchaseOrderItem:purchaseOrderItemList){
797 if(docDataMap.get(olePurchaseOrderItem.getItemTitleId())!=null){
798 olePurchaseOrderItem.setDocData(docDataMap.get(olePurchaseOrderItem.getItemTitleId()));
799 }
800 }
801 this.setPurchaseOrderItems(purchaseOrderItemList);
802 } else {
803 purchaseOrderItemList.addAll(getSearchResultsFromQuery(null, bibIds));
804 setBibInformations(purchaseOrderItemList,bibIds);
805
806 this.setPurchaseOrderItems(purchaseOrderItemList);
807 }
808 searchRecordWatch.stop();
809 }
810
811 private void setBibInformations(List<OlePurchaseOrderItem> purchaseOrderItemList,Set<String> bibIds){
812 try {
813 if (CollectionUtils.isNotEmpty(bibIds)) {
814 List<Bib> bibs = new ArrayList<>();
815 bibs.addAll(getDocstoreClientLocator().getDocstoreClient().acquisitionSearchRetrieveBibs(new ArrayList<String>(bibIds)));
816 if (bibIds!=null && bibs!=null) {
817 for (OlePurchaseOrderItem orderItem : purchaseOrderItemList) {
818 inner:
819 for (Bib bib : bibs) {
820 if (bib.getId().equals(orderItem.getItemTitleId())) {
821 boolean isAllowed = true;
822 boolean isTitle = true;
823 boolean isIsbn = true;
824 if (StringUtils.isNotBlank(this.title)) {
825 if (!bib.getTitle().contains(this.title)) {
826 isTitle = false;
827 }
828 isAllowed = false;
829 }
830 if (StringUtils.isNotBlank(this.standardNumber)) {
831 if (!bib.getIsbn().equals(this.standardNumber)) {
832 isIsbn = false;
833 }
834 isAllowed = false;
835 }
836 if (!isAllowed) {
837 isAllowed = isIsbn && isTitle;
838 }
839 if (isAllowed) {
840 DocData docData = new DocData();
841 docData.setTitle(bib.getTitle());
842 docData.setAuthor(bib.getAuthor());
843 docData.setPublisher(bib.getPublisher());
844 if(StringUtils.isNotBlank(bib.getIsbn())){
845 docData.setIsbn(bib.getIsbn());
846 } else {
847 docData.setIsbn(bib.getIssn());
848 }
849
850 docData.setLocalIdentifier(DocumentUniqueIDPrefix.getDocumentId(bib.getId()));
851 docData.setBibIdentifier(bib.getId());
852 orderItem.setDocData(docData);
853
854 break inner;
855 }
856
857 }
858 }
859 }
860 }
861 }
862 } catch (Exception e) {
863 e.printStackTrace();
864 }
865 }
866
867 public List<OlePurchaseOrderItem> getSearchResults(String poNumber, Set<String> bibIds, BigDecimal orderTypeId) {
868 List<OlePurchaseOrderItem> results = new ArrayList<>();
869 DocumentSearchCriteria.Builder docSearchCriteria = DocumentSearchCriteria.Builder.create();
870 docSearchCriteria.setDocumentTypeName(PurapConstants.PurapDocTypeCodes.PO_DOCUMENT);
871 List<DocumentStatus> documentStatuses = new ArrayList<>();
872 documentStatuses.add(DocumentStatus.FINAL);
873 Map<String, List<String>> fixedParameters = new HashMap<>();
874 Map<String, List<String>> itemTitleIds = new HashMap<>();
875 Map<String, List<String>> attributes = new HashMap<String, List<String>>();
876 if (StringUtils.isNotBlank(poNumber))
877 fixedParameters.put("purapDocumentIdentifier", Arrays.asList(poNumber));
878 if (StringUtils.isNotBlank(vendorName)) {
879 fixedParameters.put("vendorName", Arrays.asList(vendorName));
880 }
881 if (docSearchCriteria != null) {
882 if (!fixedParameters.isEmpty()) {
883 for (String propertyField : fixedParameters.keySet()) {
884 if (fixedParameters.get(propertyField) != null) {
885 attributes.put(propertyField, fixedParameters.get(propertyField));
886 }
887 }
888 }
889 }
890 docSearchCriteria.setDocumentAttributeValues(attributes);
891
892 Date currentDate = new Date();
893 docSearchCriteria.setDateCreatedTo(new DateTime(currentDate));
894
895
896 List<String> applicationStatus = new ArrayList<String>();
897 applicationStatus.add(PurapConstants.PurchaseOrderStatuses.APPDOC_OPEN);
898 if (StringUtils.isNotBlank(this.purchaseOrderStatusDescription)) {
899 applicationStatus.clear();
900 applicationStatus.add(this.purchaseOrderStatusDescription);
901 }
902 docSearchCriteria.setApplicationDocumentStatuses(applicationStatus);
903 try {
904 if (ObjectUtils.isNotNull(this.beginDate)) {
905 docSearchCriteria.setDateCreatedFrom(new DateTime(this.beginDate));
906 }
907 if (ObjectUtils.isNotNull(this.endDate)) {
908 docSearchCriteria.setDateCreatedTo(new DateTime(this.endDate));
909 }
910 } catch (Exception e) {
911 e.printStackTrace();
912 }
913
914
915 List<String> purchaseOrderIds = new ArrayList<>();
916 DocumentSearchCriteria docSearchCriteriaDTO = docSearchCriteria.build();
917 DocumentSearchResults components = null;
918 components = KEWServiceLocator.getDocumentSearchService().lookupDocuments(GlobalVariables.getUserSession().getPrincipalId(), docSearchCriteriaDTO);
919 List<DocumentSearchResult> docSearchResults = components.getSearchResults();
920 for (DocumentSearchResult searchResult : docSearchResults) {
921 if (StringUtils.isNotBlank(searchResult.getDocument().getDocumentId())) {
922 purchaseOrderIds.add(searchResult.getDocument().getDocumentId());
923 Map<String, String> poItemMap = new HashMap<String, String>();
924 poItemMap.put("documentNumber", searchResult.getDocument().getDocumentId());
925 poItemMap.put("itemTypeCode", "ITEM");
926 List<OlePurchaseOrderItem> items = (List<OlePurchaseOrderItem>) KRADServiceLocator.getBusinessObjectService().findMatching(OlePurchaseOrderItem.class, poItemMap);
927 if (CollectionUtils.isNotEmpty(items)) {
928 if (orderTypeId != null) {
929 for (OlePurchaseOrderItem orderItem : items) {
930 if (orderItem.getPurchaseOrder() != null && orderItem.getPurchaseOrder().getPurchaseOrderTypeId() != null && orderItem.getPurchaseOrder().getPurchaseOrderTypeId().equals(orderTypeId)) {
931 if (validatePurchaseOrderItem(orderItem)) {
932 bibIds.add(orderItem.getItemTitleId());
933 results.add(orderItem);
934 }
935 }
936 }
937 } else {
938 for (OlePurchaseOrderItem orderItem : items) {
939 if (validatePurchaseOrderItem(orderItem)) {
940 bibIds.add(orderItem.getItemTitleId());
941 results.add(orderItem);
942 }
943 }
944 }
945 }
946 }
947 }
948 return results;
949 }
950
951 public List<OlePurchaseOrderItem> getSearchResultsFromQuery(String poNumber, Set<String> bibIds) {
952 List<OlePurchaseOrderItem> results = new ArrayList<>();
953 queryCriteriaMap.put("bibIds",getBidsString(bibIds));
954 queryCriteriaMap.put("purchaseOrderNumber", purchaseOrderNumber);
955 queryCriteriaMap.put("vendorName", vendorName);
956 queryCriteriaMap.put("claimFilter", claimFilter);
957
958 queryCriteriaMap.put("standardNumber", standardNumber);
959 queryCriteriaMap.put("purchaseOrderStatus", purchaseOrderStatusDescription);
960 queryCriteriaMap.put("purchaseOrderType", purchaseOrderType);
961 DocumentSearchCriteria.Builder docSearchCriteria = DocumentSearchCriteria.Builder.create();
962 docSearchCriteria.setDocumentTypeName(PurapConstants.PurapDocTypeCodes.PO_DOCUMENT);
963 Map<String, List<String>> fixedParameters = new HashMap<>();
964 if (StringUtils.isNotBlank(poNumber))
965 fixedParameters.put("purapDocumentIdentifier", Arrays.asList(poNumber));
966 if (StringUtils.isNotBlank(vendorName)) {
967 fixedParameters.put("vendorName", Arrays.asList(vendorName));
968 }
969 try {
970 String criteriaDate = null;
971 if (ObjectUtils.isNotNull(this.beginDate)) {
972 queryCriteriaMap.put("poCreateFromDate",getFormattedDateForQuery(this.beginDate));
973 }
974 if (ObjectUtils.isNotNull(this.endDate)) {
975 queryCriteriaMap.put("poCreateToDate",getFormattedDateForQuery(this.endDate));
976 }
977 } catch (Exception e) {
978 e.printStackTrace();
979 }
980 String watchName = "searchPO";
981 StopWatch watch = new StopWatch();
982 watch.start();
983 ReceivingQueueDAOService receivingQueueDAOService = SpringContext.getBean(ReceivingQueueDAOService.class);
984 List<OlePurchaseOrderDocument> olePurchaseOrderDocumentList = receivingQueueDAOService.getPODocumentList(queryCriteriaMap);
985 watch.stop();
986 StopWatch forPOWatch = new StopWatch();
987 forPOWatch.start();
988 for(OlePurchaseOrderDocument olePurchaseOrderDocument:olePurchaseOrderDocumentList){
989 for(OlePurchaseOrderItem olePurchaseOrderItem:(List<OlePurchaseOrderItem>)olePurchaseOrderDocument.getItems()){
990 if (olePurchaseOrderItem.getItemTitleId()!=null&&!bibIds.contains(olePurchaseOrderItem.getItemTitleId())) {
991 bibIds.add(olePurchaseOrderItem.getItemTitleId());
992 }
993 results.add(olePurchaseOrderItem);
994 }
995 }
996 forPOWatch.stop();
997 return results;
998 }
999
1000 private String getBidsString(Set<String> bibIds){
1001 StringBuffer bibIdsString=new StringBuffer();
1002 Iterator bibIdIterator = bibIds.iterator();
1003 while(bibIdIterator.hasNext()){
1004 if(bibIdsString.length()>0){
1005 bibIdsString.append(",").append(bibIdIterator.next());
1006 }else{
1007 bibIdsString.append(bibIdIterator.next());
1008 }
1009 }
1010 if(bibIdsString.length()>0){
1011 return bibIdsString.toString();
1012 }
1013 return null;
1014 }
1015 private String getFormattedDateForQuery(String dateString){
1016 SimpleDateFormat simpleDateFormat = null;
1017 String outputDate = null;
1018 try {
1019 String inputDateFormat = "MM/dd/yyyy";
1020 simpleDateFormat = new SimpleDateFormat(inputDateFormat);
1021 Date inputDate=simpleDateFormat.parse(dateString);
1022 inputDate=DateUtils.addDays(inputDate,1);
1023
1024 String outputDateFormat = "yyyy-MM-dd";
1025 simpleDateFormat = new SimpleDateFormat(outputDateFormat);
1026 outputDate = simpleDateFormat.format(inputDate);
1027 } catch (ParseException e) {
1028 e.printStackTrace();
1029 }
1030 return outputDate;
1031 }
1032 public boolean validatePurchaseOrderItem(OlePurchaseOrderItem olePurchaseOrderItem) {
1033 SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
1034 String dateString = dateFormat.format(new Date());
1035 String actionDateString = olePurchaseOrderItem.getClaimDate() != null ? dateFormat.format(olePurchaseOrderItem.getClaimDate()) : "";
1036 boolean isValid = true;
1037 PurchaseOrderDocument olePurchaseOrderDocument = olePurchaseOrderItem.getPurapDocument();
1038
1039
1040
1041 Map purchaseOrderTypeIdMap = new HashMap();
1042 purchaseOrderTypeIdMap.put("purchaseOrderTypeId", olePurchaseOrderDocument.getPurchaseOrderTypeId());
1043 org.kuali.rice.krad.service.BusinessObjectService businessObject = SpringContext.getBean(org.kuali.rice.krad.service.BusinessObjectService.class);
1044 List<PurchaseOrderType> purchaseOrderTypeDocumentList = (List) businessObject.findMatching(PurchaseOrderType.class, purchaseOrderTypeIdMap);
1045
1046 int purAppNum = olePurchaseOrderDocument.getPurapDocumentIdentifier();
1047 olePurchaseOrderDocument = SpringContext.getBean(PurchaseOrderService.class).getCurrentPurchaseOrder(purAppNum);
1048 String docNumber = olePurchaseOrderDocument.getDocumentNumber();
1049 StringBuffer specialNotesPOIDStringBuffer = new StringBuffer();
1050 isValid = isValid && validateRecords(purAppNum, docNumber);
1051 isValid = isValid && validatePurchaseOrderStatus(purchaseOrderTypeDocumentList, olePurchaseOrderDocument);
1052 isValid = isValid && validatePoByRetiredVersionStatus(olePurchaseOrderDocument);
1053 isValid = isValid && !(checkSpecialHandlingNotesExsist(olePurchaseOrderItem,specialNotesPOIDStringBuffer));
1054 if (specialNotesPOIDStringBuffer.length()>0) {
1055 GlobalVariables.getMessageMap().putWarning("Notes warning:", "warning.poitem.specialhandling.notes",new String[]{specialNotesPOIDStringBuffer.toString()});
1056 }
1057
1058
1059 if (isValid) {
1060 boolean serialPOLink = olePurchaseOrderItem.getCopyList() != null && olePurchaseOrderItem.getCopyList().size() > 0 ? olePurchaseOrderItem.getCopyList().get(0).getSerialReceivingIdentifier() != null : false;
1061 boolean continuing = (purchaseOrderTypeDocumentList != null && purchaseOrderTypeDocumentList.size() > 0 ?
1062 purchaseOrderTypeDocumentList.get(0).getPurchaseOrderType().equalsIgnoreCase("Continuing") : false);
1063 if (olePurchaseOrderItem.getReceiptStatusId() != null && olePurchaseOrderItem.getReceiptStatusId().toString().equalsIgnoreCase((String.valueOf(getReceiptStatusDetails(OLEConstants.PO_RECEIPT_STATUS_FULLY_RECEIVED))))) {
1064 GlobalVariables.clear();
1065 GlobalVariables.getMessageMap().putInfo(OleSelectConstant.RECEIVING_QUEUE_SEARCH,
1066 OLEKeyConstants.ERROR_NO_PURCHASEORDERS_FOUND_FOR_FULLY_RECEIVED);
1067 } else if (this.isClaimFilter()) {
1068 if (!olePurchaseOrderItem.isDoNotClaim() && olePurchaseOrderItem.getClaimDate() != null && (actionDateString.equalsIgnoreCase(dateString) || olePurchaseOrderItem.getClaimDate().before(new Date()))
1069 && !serialPOLink && !continuing) {
1070 olePurchaseOrderItem.setClaimFilter(true);
1071 isValid = isValid & true;
1072 }
1073 } else {
1074 if (!olePurchaseOrderItem.isDoNotClaim() && olePurchaseOrderItem.getClaimDate() != null && (actionDateString.equalsIgnoreCase(dateString) || olePurchaseOrderItem.getClaimDate().before(new Date()))
1075 && !serialPOLink && !continuing) {
1076 olePurchaseOrderItem.setClaimFilter(true);
1077 }
1078 isValid = isValid & true;
1079 }
1080 }
1081
1082 return isValid;
1083 }
1084
1085
1086 public Set<String> getDocSearchResults(String title, String isbn) {
1087 int maxLimit = Integer.parseInt(SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(OLEConstants.DOCSEARCH_ORDERQUEUE_LIMIT_KEY));
1088 Set<String> itemTitles = new HashSet<>();
1089 try {
1090 org.kuali.ole.docstore.common.document.Item item = new ItemOleml();
1091 org.kuali.ole.docstore.common.search.SearchParams searchParams = new org.kuali.ole.docstore.common.search.SearchParams();
1092 searchParams.setPageSize(maxLimit);
1093 if (StringUtils.isNotBlank(title)) {
1094 searchParams.getSearchConditions().add(searchParams.buildSearchCondition("phrase", searchParams.buildSearchField(org.kuali.ole.docstore.common.document.content.enums.DocType.BIB.getCode(), TITLE_SEARCH, title), "AND"));
1095 }
1096 if (StringUtils.isNotBlank(isbn)) {
1097 searchParams.getSearchConditions().add(searchParams.buildSearchCondition("phrase", searchParams.buildSearchField(org.kuali.ole.docstore.common.document.content.enums.DocType.BIB.getCode(), ISBN_SEARCH, isbn), "OR"));
1098 searchParams.getSearchConditions().add(searchParams.buildSearchCondition("phrase", searchParams.buildSearchField(org.kuali.ole.docstore.common.document.content.enums.DocType.BIB.getCode(), ISSN_SEARCH, isbn), "OR"));
1099 }
1100 SearchResponse searchResponse = null;
1101 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.BIB.getCode(), BIB_IDENTIFIER));
1102 searchResponse = getDocstoreClientLocator().getDocstoreClient().search(searchParams);
1103 for (SearchResult searchResult : searchResponse.getSearchResults()) {
1104 for (SearchResultField searchResultField : searchResult.getSearchResultFields()) {
1105 if (StringUtils.isNotBlank(searchResultField.getFieldValue())) {
1106 if (searchResultField.getFieldName().equals("bibIdentifier")) {
1107 itemTitles.add(searchResultField.getFieldValue());
1108 }
1109 }
1110 }
1111 }
1112 } catch (Exception ex) {
1113 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, "Item Exists");
1114 LOG.error(org.kuali.ole.OLEConstants.ITEM_EXIST + ex);
1115 }
1116
1117 return itemTitles;
1118 }
1119
1120 public List<DocData> getDocDatas(String title, String isbn) {
1121 List<DocData> docDatas=new ArrayList<>();
1122 int maxLimit = Integer.parseInt(getConfigurationService().getPropertyValueAsString(OLEConstants.DOCSEARCH_ORDERQUEUE_LIMIT_KEY));
1123 Set<String> itemTitles = new HashSet<>();
1124 try {
1125 org.kuali.ole.docstore.common.document.Item item = new ItemOleml();
1126 org.kuali.ole.docstore.common.search.SearchParams searchParams = new org.kuali.ole.docstore.common.search.SearchParams();
1127 searchParams.setPageSize(maxLimit);
1128 if (StringUtils.isNotBlank(title)) {
1129 searchParams.getSearchConditions().add(searchParams.buildSearchCondition("phrase", searchParams.buildSearchField(org.kuali.ole.docstore.common.document.content.enums.DocType.BIB.getCode(), TITLE_SEARCH, title), "AND"));
1130 }
1131 if (StringUtils.isNotBlank(isbn)) {
1132 searchParams.getSearchConditions().add(searchParams.buildSearchCondition("phrase", searchParams.buildSearchField(org.kuali.ole.docstore.common.document.content.enums.DocType.BIB.getCode(), ISBN_SEARCH, isbn), "OR"));
1133 searchParams.getSearchConditions().add(searchParams.buildSearchCondition("phrase", searchParams.buildSearchField(org.kuali.ole.docstore.common.document.content.enums.DocType.BIB.getCode(), ISSN_SEARCH, isbn), "OR"));
1134 }
1135 SearchResponse searchResponse = null;
1136 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.BIB.getCode(), TITLE_DISPLAY));
1137 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.BIB.getCode(), AUTHOR_DISPLAY));
1138 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.BIB.getCode(), PUBLISHER_DISPLAY));
1139 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.BIB.getCode(), ISBN_DISPLAY));
1140 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.BIB.getCode(), BIB_IDENTIFIER));
1141 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(DocType.BIB.getCode(), ISSN_DISPLAY));
1142 searchResponse = getDocstoreClientLocator().getDocstoreClient().search(searchParams);
1143 for (SearchResult searchResult : searchResponse.getSearchResults()) {
1144 DocData docData=new DocData();
1145 for (SearchResultField searchResultField : searchResult.getSearchResultFields()) {
1146 if (StringUtils.isNotBlank(searchResultField.getFieldValue())) {
1147 if (searchResultField.getFieldName().equals(BIB_IDENTIFIER)) {
1148 docData.setBibIdentifier(searchResultField.getFieldValue());
1149 }
1150 if (searchResultField.getFieldName().equals(TITLE_DISPLAY)) {
1151 docData.setTitle(searchResultField.getFieldValue());
1152 }
1153 if (searchResultField.getFieldName().equals(AUTHOR_DISPLAY)) {
1154 docData.setAuthor(searchResultField.getFieldValue());
1155 }
1156 if (searchResultField.getFieldName().equals(PUBLISHER_DISPLAY)) {
1157 docData.setPublisher(searchResultField.getFieldValue());
1158 }
1159 if (searchResultField.getFieldName().equals(ISBN_DISPLAY) && StringUtils.isNotBlank(searchResultField.getFieldValue())) {
1160 docData.setIsbn(searchResultField.getFieldValue());
1161 }
1162 if (searchResultField.getFieldName().equals(ISSN_DISPLAY) && StringUtils.isNotBlank(searchResultField.getFieldValue())) {
1163 docData.setIsbn(searchResultField.getFieldValue());
1164 }
1165
1166 }
1167 }
1168 docDatas.add(docData);
1169 }
1170 } catch (Exception ex) {
1171 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, "Item Exists");
1172 LOG.error(org.kuali.ole.OLEConstants.ITEM_EXIST + ex);
1173 }
1174
1175 return docDatas;
1176 }
1177
1178 private boolean validatePoByRetiredVersionStatus(PurchaseOrderDocument olePurchaseOrderDocument) {
1179 return (olePurchaseOrderDocument.getPurchaseOrderCurrentIndicatorForSearching());
1180 }
1181
1182 private boolean validatePurchaseOrderStatus(List<PurchaseOrderType> purchasrOrderTypeList, PurchaseOrderDocument po) {
1183 boolean valid = false;
1184 for (PurchaseOrderType purchaseOrderTypes : purchasrOrderTypeList) {
1185 BigDecimal poTypeId = purchaseOrderTypes.getPurchaseOrderTypeId();
1186 if (poTypeId.compareTo(po.getPurchaseOrderTypeId()) == 0) {
1187 valid = true;
1188 }
1189 }
1190 return valid;
1191 }
1192
1193
1194 public void valueSearch() throws Exception {
1195 String[] purchaseOrderNumbers = {};
1196 Collection results = new ArrayList<OlePurchaseOrderItem>();
1197 Map purapDocumentIdentifierMap = new HashMap();
1198 if (this.purchaseOrderNumber != null) {
1199 purchaseOrderNumbers = (this.purchaseOrderNumber.toString()).split(",");
1200 for (int i = 0; i < purchaseOrderNumbers.length; i++) {
1201
1202 List<String> poDocNumbers = new ArrayList<String>();
1203 LOG.debug(" OleReceivingQueueSearchDocument.valueSearch method starts ");
1204 purapDocumentIdentifierMap = new HashMap();
1205
1206 if (purchaseOrderNumbers[i] != null) {
1207 purapDocumentIdentifierMap.put("purchaseOrder.purapDocumentIdentifier", purchaseOrderNumbers[i]);
1208 }
1209 if (this.vendorName != null) {
1210 purapDocumentIdentifierMap.put("purchaseOrder.vendorName", this.vendorName);
1211 }
1212 if (this.title != null) {
1213 purapDocumentIdentifierMap.put("docData.title", this.title);
1214 }
1215 if (this.standardNumber != null) {
1216 purapDocumentIdentifierMap.put("docData.isbn", this.standardNumber);
1217 }
1218 results.addAll(SpringContext.getBean(OleDocStoreLookupService.class).findCollectionBySearch(OlePurchaseOrderItem.class, purapDocumentIdentifierMap));
1219 }
1220
1221 } else {
1222 purapDocumentIdentifierMap = new HashMap();
1223 if (this.purchaseOrderNumber != null) {
1224 purapDocumentIdentifierMap.put("purchaseOrder.purapDocumentIdentifier", this.purchaseOrderNumber);
1225 }
1226 if (this.vendorName != null) {
1227 purapDocumentIdentifierMap.put("purchaseOrder.vendorName", this.vendorName);
1228 }
1229 if (this.title != null) {
1230 purapDocumentIdentifierMap.put("docData.title", this.title);
1231 }
1232 if (this.standardNumber != null) {
1233 purapDocumentIdentifierMap.put("docData.isbn", this.standardNumber);
1234 }
1235 results.addAll(SpringContext.getBean(OleDocStoreLookupService.class).findCollectionBySearch(OlePurchaseOrderItem.class, purapDocumentIdentifierMap));
1236 }
1237
1238
1239
1240
1241 boolean isbeginEndDateExsist = false;
1242 boolean isEndDateSmallerThanBeginDate = false;
1243 List<OlePurchaseOrderItem> tempResult = (List<OlePurchaseOrderItem>) results;
1244 List<String> docNumberList = new ArrayList<String>();
1245
1246
1247 if (this.beginDate != null && this.endDate != null) {
1248 DateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
1249 Date startDate = formatter.parse(this.beginDate);
1250 Date endDate = formatter.parse(this.endDate);
1251 if (startDate.compareTo(endDate) > 0) {
1252 isEndDateSmallerThanBeginDate = true;
1253 GlobalVariables.getMessageMap().putError(OleSelectConstant.RECEIVING_QUEUE_SEARCH, OLEKeyConstants.PUR_ORD_DATE_TO_NOT_LESSER_THAN_PUR_ORD_DATE_FROM, new String[]{});
1254 }
1255 }
1256
1257
1258
1259
1260
1261
1262
1263 if (!isEndDateSmallerThanBeginDate) {
1264 if ((this.beginDate != null || this.endDate != null)) {
1265 docNumberList = filterOtherSearchCriteria();
1266 isbeginEndDateExsist = true;
1267 }
1268 for (int i = 0; i < tempResult.size(); i++) {
1269 int purAppNum = tempResult.get(i).getPurchaseOrder().getPurapDocumentIdentifier();
1270 String docNumber = tempResult.get(i).getPurchaseOrder().getDocumentNumber();
1271
1272
1273 boolean isValidRecord = validateRecords(purAppNum, docNumber);
1274 boolean isSpecHandlingNotesExist = false;
1275
1276
1277
1278 if (isValidRecord) {
1279 isValidRecord = validateCopiesAndParts(tempResult.get(i));
1280 }
1281 if (tempResult.get(i).getNotes() != null) {
1282 isSpecHandlingNotesExist = checkSpecialHandlingNotesExsist(tempResult.get(i));
1283 }
1284 if (this.purchaseOrderType != null && isValidRecord) {
1285 isValidRecord = validatePurchaseOrderStatus(this.purchaseOrderType, purAppNum);
1286 }
1287 if (isbeginEndDateExsist) {
1288 if (!docNumberList.contains(docNumber)) {
1289 isValidRecord = false;
1290 }
1291 }
1292 boolean isRetiredVersionPo = !(validatePoByRetiredVersionStatus((OlePurchaseOrderItem) tempResult.get(i)));
1293 OlePurchaseOrderItem olePurchaseOrderItem = tempResult.get(i);
1294 if (!isValidRecord || isRetiredVersionPo || isSpecHandlingNotesExist) {
1295 tempResult.remove(i);
1296 i--;
1297 }
1298 }
1299
1300 if (tempResult.size() <= 0) {
1301 if(!GlobalVariables.getMessageMap().hasInfo()) {
1302 GlobalVariables.getMessageMap().putInfo(OleSelectConstant.RECEIVING_QUEUE_SEARCH,
1303 OLEKeyConstants.ERROR_NO_PURCHASEORDERS_FOUND);
1304 }
1305 }
1306 this.setPurchaseOrderItems(removeReceivedTitles(tempResult));
1307 if(this.getPurchaseOrderItems().size()>0){
1308 GlobalVariables.clear();
1309 }
1310 }
1311
1312 LOG.debug(" OleReceivingQueueSearchDocument.valueSearch method ends ");
1313 }
1314
1315 private List<OlePurchaseOrderItem> removeReceivedTitles(List<OlePurchaseOrderItem> purchaseOrderItems){
1316 SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
1317 String dateString = dateFormat.format(new Date());
1318 List<OlePurchaseOrderItem> result=new ArrayList<OlePurchaseOrderItem>();
1319 for(OlePurchaseOrderItem olePurchaseOrderItem:purchaseOrderItems){
1320 String actionDateString = olePurchaseOrderItem.getClaimDate()!=null ? dateFormat.format(olePurchaseOrderItem.getClaimDate()) : "";
1321 boolean serialPOLink = olePurchaseOrderItem.getCopyList()!=null && olePurchaseOrderItem.getCopyList().size()>0 ? olePurchaseOrderItem.getCopyList().get(0).getSerialReceivingIdentifier()!=null : false ;
1322 OlePurchaseOrderDocument olePurchaseOrderDocument = olePurchaseOrderItem.getPurapDocument();
1323 Map purchaseOrderTypeIdMap = new HashMap();
1324 purchaseOrderTypeIdMap.put("purchaseOrderTypeId", olePurchaseOrderDocument.getPurchaseOrderTypeId());
1325 org.kuali.rice.krad.service.BusinessObjectService businessObject = SpringContext.getBean(org.kuali.rice.krad.service.BusinessObjectService.class);
1326 List<PurchaseOrderType> purchaseOrderTypeDocumentList = (List) businessObject.findMatching(PurchaseOrderType.class, purchaseOrderTypeIdMap);
1327 boolean continuing = purchaseOrderTypeDocumentList!=null && purchaseOrderTypeDocumentList.size()>0?
1328 purchaseOrderTypeDocumentList.get(0).getPurchaseOrderType().equalsIgnoreCase("Continuing"):false;
1329 if(olePurchaseOrderItem.getReceiptStatusId()!=null&&olePurchaseOrderItem.getReceiptStatusId().toString().equalsIgnoreCase((String.valueOf(getReceiptStatusDetails(OLEConstants.PO_RECEIPT_STATUS_FULLY_RECEIVED))))){
1330 GlobalVariables.clear();
1331 GlobalVariables.getMessageMap().putInfo(OleSelectConstant.RECEIVING_QUEUE_SEARCH,
1332 OLEKeyConstants.ERROR_NO_PURCHASEORDERS_FOUND_FOR_FULLY_RECEIVED);
1333 }
1334 else if(this.isClaimFilter()){
1335 if(!olePurchaseOrderItem.isDoNotClaim() && olePurchaseOrderItem.getClaimDate()!=null && (actionDateString.equalsIgnoreCase(dateString) || olePurchaseOrderItem.getClaimDate().before(new Date()))
1336 && !serialPOLink && !continuing){
1337 olePurchaseOrderItem.setClaimFilter(true);
1338 result.add(olePurchaseOrderItem);
1339 }
1340 }else {
1341 if(!olePurchaseOrderItem.isDoNotClaim() && olePurchaseOrderItem.getClaimDate()!=null && (actionDateString.equalsIgnoreCase(dateString) || olePurchaseOrderItem.getClaimDate().before(new Date()))
1342 && !serialPOLink && !continuing){
1343 olePurchaseOrderItem.setClaimFilter(true);
1344 }
1345 result.add(olePurchaseOrderItem);
1346 }
1347
1348 }
1349 return result;
1350 }
1351 private List<OlePurchaseOrderItem> removeFullyReceivedPO(List<OlePurchaseOrderItem> purchaseOrderItems){
1352 List<OlePurchaseOrderItem> result=new ArrayList<OlePurchaseOrderItem>();
1353 Map<String,List<OlePurchaseOrderItem>> listMap=new HashMap<String,List<OlePurchaseOrderItem>>();
1354 for (OlePurchaseOrderItem olePurchaseOrderItem : purchaseOrderItems) {
1355 if(olePurchaseOrderItem.getItemTypeCode().equalsIgnoreCase("Item")){
1356 if(!listMap.containsKey(olePurchaseOrderItem.getDocumentNumber())){
1357 List<OlePurchaseOrderItem> orderItems=new ArrayList<OlePurchaseOrderItem>();
1358 orderItems.add(olePurchaseOrderItem);
1359 listMap.put(olePurchaseOrderItem.getDocumentNumber(),orderItems);
1360 } else {
1361 for(Map.Entry<String,List<OlePurchaseOrderItem>> entry:listMap.entrySet()){
1362 if(entry.getKey().equalsIgnoreCase(olePurchaseOrderItem.getDocumentNumber())){
1363 List<OlePurchaseOrderItem> orderItems=entry.getValue();
1364 orderItems.add(olePurchaseOrderItem);
1365 entry.setValue(orderItems);
1366 }
1367 }
1368 }
1369
1370 }
1371 }
1372 for(Map.Entry<String,List<OlePurchaseOrderItem>> entry:listMap.entrySet()){
1373 int size=((List<OlePurchaseOrderItem>)entry.getValue()).size();
1374 boolean isFullyReceived=false;
1375 int count=0;
1376 List<OlePurchaseOrderItem> orderItems=entry.getValue();
1377 for(OlePurchaseOrderItem olePurchaseOrderItem:orderItems){
1378 if(olePurchaseOrderItem.getReceiptStatusId()!=null&&olePurchaseOrderItem.getReceiptStatusId().toString().equalsIgnoreCase("5")){
1379 count++;
1380 }
1381 }
1382 if(size!=count){
1383 result.addAll(orderItems);
1384 }
1385 }
1386
1387
1388 return result;
1389 }
1390
1391 private boolean validatePoByRetiredVersionStatus(OlePurchaseOrderItem olePurchaseOrderItem) {
1392
1393 Map<String, String> map = new HashMap<String, String>();
1394 map.put("documentNumber", olePurchaseOrderItem.getDocumentNumber());
1395 PurchaseOrderDocument po = SpringContext.getBean(PurchaseOrderService.class).getCurrentPurchaseOrder(olePurchaseOrderItem.getPurapDocumentIdentifier());
1396
1397 List<OlePurchaseOrderDocument> olePurchaseOrderDocumentList = (List<OlePurchaseOrderDocument>) KRADServiceLocator.getBusinessObjectService().findMatching(OlePurchaseOrderDocument.class, map);
1398 OlePurchaseOrderDocument olePurchaseOrderDocument = olePurchaseOrderDocumentList.get(0);
1399 return (olePurchaseOrderDocument.getPurchaseOrderCurrentIndicatorForSearching());
1400 }
1401
1402 private boolean validatePurchaseOrderStatus(String purchaseOrderType, Integer purAppNum) {
1403 boolean valid = false;
1404 PurchaseOrderDocument po = SpringContext.getBean(PurchaseOrderService.class).getCurrentPurchaseOrder(purAppNum);
1405
1406
1407
1408 Map purchaseOrderTypeMap = new HashMap();
1409 purchaseOrderTypeMap.put("purchaseOrderType", purchaseOrderType);
1410 List<PurchaseOrderType> purchasrOrderTypeList = (List) SpringContext.getBean(BusinessObjectService.class)
1411 .findMatching(PurchaseOrderType.class, purchaseOrderTypeMap);
1412 for (PurchaseOrderType purchaseOrderTypes : purchasrOrderTypeList) {
1413 BigDecimal poTypeId = purchaseOrderTypes.getPurchaseOrderTypeId();
1414 if (poTypeId.compareTo(po.getPurchaseOrderTypeId()) == 0) {
1415 valid = true;
1416 }
1417 }
1418 return valid;
1419 }
1420
1421 public boolean checkSpecialHandlingNotesExsist(OlePurchaseOrderItem olePurchaseOrderItem) {
1422 for (OleNotes poNote : olePurchaseOrderItem.getNotes()) {
1423 OleNoteType oleNoteType = SpringContext.getBean(OleNoteTypeService.class).getNoteTypeDetails(
1424 poNote.getNoteTypeId());
1425 String noteType = oleNoteType.getNoteType();
1426 if (noteType.equalsIgnoreCase(OLEConstants.SPECIAL_PROCESSING_INSTRUCTION_NOTE)) {
1427 if (LOG.isDebugEnabled()) {
1428 LOG.debug("PO ID " + olePurchaseOrderItem.getPurapDocumentIdentifier()
1429 + "has special handling notes");
1430 }
1431 return true;
1432 }
1433 }
1434 return false;
1435 }
1436
1437 public boolean checkSpecialHandlingNotesExsist(OlePurchaseOrderItem olePurchaseOrderItem,StringBuffer specialNotesPOIDStringBuffer) {
1438 for (OleNotes poNote : olePurchaseOrderItem.getNotes()) {
1439 OleNoteType oleNoteType = getOleNoteTypeService().getNoteTypeDetails(
1440 poNote.getNoteTypeId());
1441 String noteType = oleNoteType.getNoteType();
1442 if (noteType.equalsIgnoreCase(OLEConstants.SPECIAL_PROCESSING_INSTRUCTION_NOTE)) {
1443 if(specialNotesPOIDStringBuffer.length()>0){
1444 specialNotesPOIDStringBuffer.append(",");
1445 }
1446 specialNotesPOIDStringBuffer.append(olePurchaseOrderItem.getPurchaseOrder().getPurapDocumentIdentifier());
1447 if (LOG.isDebugEnabled()) {
1448 LOG.debug("PO ID " + olePurchaseOrderItem.getPurapDocumentIdentifier()
1449 + "has special handling notes");
1450 }
1451 return true;
1452 }
1453 }
1454 return false;
1455 }
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479 public boolean validateRecords(Integer purAppNum, String docNumber) {
1480 boolean valid = true;
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509 PurchaseOrderDocument po = SpringContext.getBean(PurchaseOrderService.class).getCurrentPurchaseOrder(purAppNum);
1510 valid &= getReceivingService().canCreateLineItemReceivingDocument(purAppNum, null);
1511 if (this.purchaseOrderStatusDescription != null && valid) {
1512 if (!purchaseOrderStatusDescription.equalsIgnoreCase(po.getApplicationDocumentStatus())) {
1513 valid &= false;
1514 }
1515
1516 }
1517 if(po.getApplicationDocumentStatus().equalsIgnoreCase("closed")){
1518 valid &= false;
1519 GlobalVariables.clear();
1520 GlobalVariables.getMessageMap().putInfo(OleSelectConstant.RECEIVING_QUEUE_SEARCH,
1521 OLEKeyConstants.ERROR_NO_PURCHASEORDERS_FOUND_FOR_CLOSED);
1522
1523 }
1524
1525
1526
1527
1528 return valid;
1529 }
1530
1531
1532
1533
1534
1535
1536
1537
1538 public List<String> filterOtherSearchCriteria() throws WorkflowException, ParseException {
1539
1540 Map<String, List<String>> fixedParameters = new HashMap<String, List<String>>();
1541 if (ObjectUtils.isNotNull(this.beginDate)) {
1542 fixedParameters.put(OleSelectConstant.FROM_DATE_CREATED, Collections.singletonList(this.beginDate));
1543 } else {
1544 fixedParameters.put(OleSelectConstant.FROM_DATE_CREATED, Collections.singletonList(""));
1545 }
1546 if (ObjectUtils.isNotNull(this.endDate)) {
1547 fixedParameters.put(OleSelectConstant.TO_DATE_CREATED, Collections.singletonList(this.endDate));
1548 }
1549
1550 List<String> docNumber = new ArrayList<String>();
1551 if (!((fixedParameters.get(OleSelectConstant.FROM_DATE_CREATED) == null || fixedParameters.get(OleSelectConstant.FROM_DATE_CREATED).get(0).isEmpty()) &&
1552 (fixedParameters.get(OleSelectConstant.TO_DATE_CREATED) == null || fixedParameters.get(OleSelectConstant.TO_DATE_CREATED).get(0).isEmpty()))) {
1553 docNumber = filterWorkflowStatusDate(fixedParameters);
1554 isDateLookup = true;
1555 }
1556
1557 return docNumber;
1558 }
1559
1560
1561
1562
1563
1564
1565
1566 public List<String> filterWorkflowStatusDate(Map<String, List<String>> fixedParameters) throws ParseException {
1567 DocumentSearchCriteria.Builder criteria = DocumentSearchCriteria.Builder.create();
1568 criteria.setDocumentAttributeValues(fixedParameters);
1569 if (StringUtils.isNotEmpty(this.beginDate)) {
1570 criteria.setDateCreatedFrom(new DateTime((SpringContext.getBean(DateTimeService.class)).convertToDate(beginDate)));
1571 }
1572 if (StringUtils.isNotEmpty(this.endDate)) {
1573 criteria.setDateCreatedTo(new DateTime((SpringContext.getBean(DateTimeService.class)).convertToDate(endDate)));
1574 }
1575 List<String> documentNumberList = new ArrayList();
1576 boolean isDateSpecified = true;
1577 try {
1578 DocumentSearchResults components = KewApiServiceLocator.getWorkflowDocumentService().documentSearch(GlobalVariables.getUserSession().getPrincipalId(), criteria.build());
1579 List<DocumentSearchResult> docSearchResults = components.getSearchResults();
1580 for (DocumentSearchResult docSearchResult : docSearchResults) {
1581 documentNumberList.add(docSearchResult.getDocument().getDocumentId());
1582 }
1583 } catch (WorkflowServiceErrorException wsee) {
1584 for (WorkflowServiceError workflowServiceError : (List<WorkflowServiceError>) wsee.getServiceErrors()) {
1585 if (workflowServiceError.getMessageMap() != null && workflowServiceError.getMessageMap().hasErrors()) {
1586
1587 GlobalVariables.getMessageMap().merge(workflowServiceError.getMessageMap());
1588 } else {
1589
1590 GlobalVariables.getMessageMap().putError(workflowServiceError.getMessage(), RiceKeyConstants.ERROR_CUSTOM, workflowServiceError.getMessage());
1591 }
1592 }
1593 ;
1594 }
1595 return documentNumberList;
1596 }
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606 public boolean receivePO(OleLineItemReceivingDocument rlDoc, Integer purchaseOrderIdentifier, boolean isCreateRCV) {
1607 LOG.debug("Inside receivePO of OleReceivingQueueSearchDocument");
1608 GlobalVariables.getMessageMap().clearErrorPath();
1609 GlobalVariables.getMessageMap().addToErrorPath(OLEPropertyConstants.DOCUMENT);
1610
1611 boolean receivePOSuccess = false;
1612
1613
1614 rlDoc.setPurchaseOrderIdentifier(purchaseOrderIdentifier);
1615 DateTimeService dateTimeService = SpringContext.getBean(DateTimeService.class);
1616 rlDoc.setShipmentReceivedDate(dateTimeService.getCurrentSqlDate());
1617
1618 if (LOG.isDebugEnabled()) {
1619 LOG.debug("PO ID in OleReceivingQueueSearchDocument.receivePO -" + purchaseOrderIdentifier);
1620 }
1621
1622
1623 boolean valid = true;
1624
1625 PurchaseOrderDocument po = SpringContext.getBean(PurchaseOrderService.class).getCurrentPurchaseOrder(purchaseOrderIdentifier);
1626
1627 if (ObjectUtils.isNotNull(po)) {
1628 rlDoc.setAccountsPayablePurchasingDocumentLinkIdentifier(po.getAccountsPayablePurchasingDocumentLinkIdentifier());
1629 if (!SpringContext.getBean(DocumentHelperService.class).getDocumentAuthorizer(rlDoc).isAuthorizedByTemplate(rlDoc, KRADConstants.KNS_NAMESPACE, KimConstants.PermissionTemplateNames.OPEN_DOCUMENT, GlobalVariables.getUserSession().getPrincipalId())) {
1630 throw new DocumentAuthorizationException(GlobalVariables.getUserSession().getPerson().getPrincipalName(), "initiate document", rlDoc.getDocumentNumber());
1631 }
1632 } else {
1633 GlobalVariables.getMessageMap().putError(PurapPropertyConstants.PURCHASE_ORDER_IDENTIFIER, OLEKeyConstants.ERROR_RECEIVING_LINE_PO_NOT_EXIST, rlDoc.getPurchaseOrderIdentifier().toString());
1634 }
1635
1636
1637 if (!SpringContext.getBean(ReceivingService.class).isPurchaseOrderActiveForLineItemReceivingDocumentCreation(rlDoc.getPurchaseOrderIdentifier())) {
1638 GlobalVariables.getMessageMap().putError(PurapPropertyConstants.PURCHASE_ORDER_IDENTIFIER, OLEKeyConstants.ERROR_RECEIVING_LINE_PONOTACTIVE, rlDoc.getPurchaseOrderIdentifier().toString());
1639 valid &= false;
1640 }
1641
1642 if (SpringContext.getBean(ReceivingService.class).canCreateLineItemReceivingDocument(rlDoc.getPurchaseOrderIdentifier(), rlDoc.getDocumentNumber()) == false) {
1643 String inProcessDocNum = "";
1644 List<String> inProcessDocNumbers = SpringContext.getBean(ReceivingService.class).getLineItemReceivingDocumentNumbersInProcessForPurchaseOrder(rlDoc.getPurchaseOrderIdentifier(), rlDoc.getDocumentNumber());
1645 if (!inProcessDocNumbers.isEmpty()) {
1646 inProcessDocNum = inProcessDocNumbers.get(0);
1647 }
1648 GlobalVariables.getMessageMap().putError(PurapPropertyConstants.PURCHASE_ORDER_IDENTIFIER, OLEKeyConstants.ERROR_RECEIVING_LINE_DOCUMENT_ACTIVE_FOR_PO, rlDoc.getPurchaseOrderIdentifier().toString(), inProcessDocNum);
1649 valid &= false;
1650 }
1651
1652
1653
1654
1655
1656
1657
1658
1659 if (LOG.isDebugEnabled()) {
1660 LOG.debug("PO ID in OleReceivingQueueSearchDocument.receivePO " + purchaseOrderIdentifier + "passed all validations");
1661 }
1662
1663 try {
1664 if (valid) {
1665
1666 SpringContext.getBean(ReceivingService.class).populateAndSaveLineItemReceivingDocument(rlDoc);
1667
1668 List<OleLineItemReceivingItem> itemList = new ArrayList<OleLineItemReceivingItem>();
1669 for (Object item : rlDoc.getItems()) {
1670 OleLineItemReceivingItem rlItem = (OleLineItemReceivingItem) item;
1671
1672 boolean isPOItemPresent = false;
1673 for (OlePurchaseOrderItem poItem : this.getPurchaseOrderItems()) {
1674 if (poItem.isPoAdded()) {
1675 if (!isPOItemPresent
1676 && poItem.getItemIdentifier().equals(rlItem.getPurchaseOrderIdentifier())) {
1677 rlItem.setItemReceivedTotalQuantity(rlItem.getItemReceivedToBeQuantity());
1678 rlItem.setItemReceivedTotalParts(rlItem.getItemReceivedToBeParts());
1679 rlItem.setPoSelected(true);
1680
1681
1682
1683
1684 isPOItemPresent = true;
1685 } else if (!isPOItemPresent) {
1686 rlItem.setItemReceivedTotalQuantity(KualiDecimal.ZERO);
1687 rlItem.setItemReceivedTotalParts(KualiDecimal.ZERO);
1688 }
1689 }
1690 }
1691
1692 itemList.add(rlItem);
1693 }
1694
1695 if (ObjectUtils.isNotNull(itemList) && itemList.size() > 0) {
1696 rlDoc.setItems(itemList);
1697
1698 Person principalPerson = SpringContext.getBean(PersonService.class).getPerson(GlobalVariables.getUserSession().getPerson().getPrincipalId());
1699
1700 rlDoc.getDocumentHeader().setWorkflowDocument(KRADServiceLocatorWeb.getWorkflowDocumentService().loadWorkflowDocument(rlDoc.getDocumentNumber(), principalPerson));
1701
1702 if (isCreateRCV) {
1703 SpringContext.getBean(DocumentService.class).saveDocument(rlDoc);
1704 } else {
1705 List<OleLineItemReceivingItem> items = rlDoc.getItems();
1706 for (OleLineItemReceivingItem item : items) {
1707 OleLineItemReceivingService oleLineItemReceivingService = SpringContext.getBean(OleLineItemReceivingServiceImpl.class);
1708 OlePurchaseOrderItem olePurchaseOrderItem = oleLineItemReceivingService.getOlePurchaseOrderItem(item.getPurchaseOrderIdentifier());
1709 if (olePurchaseOrderItem != null) {
1710 if (item.isPoSelected()) {
1711 for (OleCopy oleCopy : item.getCopyList()) {
1712 oleCopy.setReceiptStatus(OLEConstants.OleLineItemReceiving.RECEIVED_STATUS);
1713 }
1714 OleCopyHelperService oleCopyHelperService = SpringContext.getBean(OleCopyHelperService.class);
1715 oleCopyHelperService.updateRequisitionAndPOItems(olePurchaseOrderItem, item, null, rlDoc.getIsATypeOfRCVGDoc());
1716 }
1717 }
1718 }
1719 SpringContext.getBean(DocumentService.class).routeDocument(rlDoc,
1720 "Line Item Receiving from Receiving Queue Search page", null);
1721 }
1722
1723 receivePOSuccess = true;
1724 }
1725 }
1726 } catch (WorkflowException wfe) {
1727 String rcvDocNum = rlDoc.getDocumentNumber();
1728 String poId = rlDoc.getPurchaseOrderIdentifier().toString();
1729 GlobalVariables.getMessageMap().putError(PurapPropertyConstants.PURCHASE_ORDER_IDENTIFIER, OLEKeyConstants.ERROR_RECEIVING_LINE_SAVE_OR_SUBMIT, new String[]{poId, rcvDocNum, wfe.getMessage()});
1730 wfe.printStackTrace();
1731 }
1732
1733 if (LOG.isDebugEnabled()) {
1734 LOG.debug("Receive PO status for PO ID " + purchaseOrderIdentifier + " is " + receivePOSuccess);
1735 LOG.debug("Leaving receivePO of OleReceivingQueueSearchDocument");
1736 }
1737
1738 return receivePOSuccess;
1739 }
1740
1741 public void updateRequisitionAndPOItems(OlePurchaseOrderItem olePurchaseOrderItem,
1742 OleLineItemReceivingItem oleLineItemReceivingItem) {
1743
1744 List<OleCopy> copyList = oleLineItemReceivingItem.getCopyList() != null ? oleLineItemReceivingItem.getCopyList() : new ArrayList<OleCopy>();
1745 Integer receivedCount = 0;
1746 for (OleCopy oleCopy : copyList) {
1747 if (oleCopy.getReceiptStatus().equalsIgnoreCase("Received")) {
1748 receivedCount++;
1749 }
1750 }
1751 if (receivedCount == 0) {
1752 oleLineItemReceivingItem
1753 .setReceiptStatusId(getReceiptStatusDetails(OLEConstants.PO_RECEIPT_STATUS_NOT_RECEIVED));
1754 } else if (receivedCount == copyList.size()) {
1755 oleLineItemReceivingItem
1756 .setReceiptStatusId(getReceiptStatusDetails(OLEConstants.PO_RECEIPT_STATUS_FULLY_RECEIVED));
1757 } else {
1758 oleLineItemReceivingItem
1759 .setReceiptStatusId(getReceiptStatusDetails(OLEConstants.PO_RECEIPT_STATUS_PARTIALLY_RECEIVED));
1760 }
1761 olePurchaseOrderItem.setReceiptStatusId(oleLineItemReceivingItem.getReceiptStatusId());
1762 if (olePurchaseOrderItem.getItemQuantity().equals(new KualiDecimal(1)) && olePurchaseOrderItem.getItemNoOfParts().isGreaterThan(new KualiInteger(1))) {
1763 olePurchaseOrderItem.setNoOfCopiesReceived("N/A");
1764 olePurchaseOrderItem.setNoOfPartsReceived(receivedCount.toString());
1765 } else if (olePurchaseOrderItem.getItemQuantity().isGreaterThan(new KualiDecimal(1)) && olePurchaseOrderItem.getItemNoOfParts().equals(new KualiDecimal(1))) {
1766 olePurchaseOrderItem.setNoOfCopiesReceived(receivedCount.toString());
1767 olePurchaseOrderItem.setNoOfPartsReceived("N/A");
1768 } else if (olePurchaseOrderItem.getItemQuantity().isGreaterThan(new KualiDecimal(1)) && olePurchaseOrderItem.getItemNoOfParts().isGreaterThan(new KualiInteger(1))) {
1769 olePurchaseOrderItem.setNoOfCopiesReceived("See Copies Section");
1770 olePurchaseOrderItem.setNoOfPartsReceived("See Copies Section");
1771 }
1772 SpringContext.getBean(BusinessObjectService.class).save(olePurchaseOrderItem);
1773
1774 String reqsItemId = copyList.size() > 0 ? copyList.get(0).getReqItemId().toString() : "";
1775 Map<String, String> reqItemMap = new HashMap<String, String>();
1776 reqItemMap.put("itemIdentifier", reqsItemId);
1777 OleRequisitionItem oleRequisitionItem = SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(OleRequisitionItem.class, reqItemMap);
1778 if (oleRequisitionItem != null) {
1779 oleRequisitionItem.setNoOfCopiesReceived(olePurchaseOrderItem.getNoOfCopiesReceived());
1780 oleRequisitionItem.setNoOfPartsReceived(olePurchaseOrderItem.getNoOfPartsReceived());
1781 oleRequisitionItem.setReceiptStatusId(olePurchaseOrderItem.getReceiptStatusId());
1782 SpringContext.getBean(BusinessObjectService.class).save(oleRequisitionItem);
1783 }
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832 }
1833
1834 public int getReceiptStatusDetails(String receiptStatusCd) {
1835 int receiptStatusId = 0;
1836 Map<String, String> receiptStatusCdMap = new HashMap<String, String>();
1837 receiptStatusCdMap.put(OLEConstants.RCPT_STATUS_CD, receiptStatusCd);
1838 List<OleReceiptStatus> oleReceiptStatusList = (List) SpringContext.getBean(BusinessObjectService.class)
1839 .findMatching(OleReceiptStatus.class, receiptStatusCdMap);
1840 for (OleReceiptStatus oleReceiptStatus : oleReceiptStatusList) {
1841 receiptStatusId = oleReceiptStatus.getReceiptStatusId().intValue();
1842 }
1843 return receiptStatusId;
1844 }
1845
1846
1847
1848
1849
1850
1851
1852 private boolean hasSpecialHandlingNotes(PurchaseOrderDocument po) {
1853 LOG.debug("Inside hasSpecialHandlingNotes of OleReceivingQueueSearchDocument");
1854 for (OlePurchaseOrderItem poItem : (List<OlePurchaseOrderItem>) po.getItems()) {
1855 for (OleNotes poNote : poItem.getNotes()) {
1856 OleNoteType oleNoteType = SpringContext.getBean(OleNoteTypeService.class).getNoteTypeDetails(poNote.getNoteTypeId());
1857 String noteType = oleNoteType.getNoteType();
1858 if (noteType.equalsIgnoreCase(OLEConstants.SPECIAL_PROCESSING_INSTRUCTION_NOTE)) {
1859 if (LOG.isDebugEnabled()) {
1860 LOG.debug("PO ID " + poItem.getPurapDocumentIdentifier() + "has special handling notes");
1861 }
1862 return true;
1863 }
1864 }
1865 }
1866 LOG.debug("Leaving hasSpecialHandlingNotes of OleReceivingQueueSearchDocument");
1867 return false;
1868 }
1869
1870
1871
1872
1873
1874
1875 public String getBeginDate() {
1876 return beginDate;
1877 }
1878
1879
1880
1881
1882
1883
1884 public void setBeginDate(String beginDate) {
1885 this.beginDate = beginDate;
1886 }
1887
1888
1889
1890
1891
1892
1893 public String getEndDate() {
1894 return endDate;
1895 }
1896
1897
1898
1899
1900
1901
1902 public void setEndDate(String endDate) {
1903 this.endDate = endDate;
1904 }
1905
1906 private boolean validateCopiesAndParts(OlePurchaseOrderItem poItem) {
1907 boolean isValid = true;
1908
1909
1910
1911
1912
1913
1914 return isValid;
1915 }
1916
1917 private List<AdHocRoutePerson> buildFyiRecipient() {
1918 List<AdHocRoutePerson> persons = new ArrayList<AdHocRoutePerson>();
1919 AdHocRoutePerson adHocRoutePerson = new AdHocRoutePerson();
1920 adHocRoutePerson.setActionRequested(KewApiConstants.ACTION_REQUEST_FYI_REQ);
1921 adHocRoutePerson.setId(GlobalVariables.getUserSession().getPrincipalName());
1922 persons.add(adHocRoutePerson);
1923 return persons;
1924 }
1925
1926
1927 public PurchaseOrderService getPurchaseOrderService() {
1928 if(purchaseOrderService == null) {
1929 purchaseOrderService = SpringContext.getBean(PurchaseOrderService.class);
1930 }
1931 return purchaseOrderService;
1932 }
1933
1934 public BusinessObjectService getBusinessObjectService() {
1935 if(businessObjectService == null) {
1936 businessObjectService = SpringContext.getBean(BusinessObjectService.class);
1937 }
1938 return businessObjectService;
1939 }
1940
1941 public ReceivingService getReceivingService() {
1942 if(receivingService == null) {
1943 receivingService = SpringContext.getBean(ReceivingService.class);
1944 }
1945 return receivingService;
1946 }
1947
1948 public OleNoteTypeService getOleNoteTypeService() {
1949 if(oleNoteTypeService == null) {
1950 oleNoteTypeService = SpringContext.getBean(OleNoteTypeService.class);
1951 }
1952 return oleNoteTypeService;
1953 }
1954
1955 public ConfigurationService getConfigurationService() {
1956 if(configurationService == null) {
1957 configurationService = SpringContext.getBean(ConfigurationService.class);
1958 }
1959 return configurationService;
1960 }
1961
1962 public List<PurchaseOrderType> getPurchaseOrderTypeDocumentList() {
1963 if(purchaseOrderTypeDocumentList.size() == 0) {
1964 purchaseOrderTypeDocumentList = (List) getBusinessObjectService().findAll(PurchaseOrderType.class);
1965 if(purchaseOrderTypeDocumentList.size() > 0) {
1966 return purchaseOrderTypeDocumentList;
1967 }
1968 }
1969 return purchaseOrderTypeDocumentList;
1970 }
1971 }