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.beanutils.PropertyUtils;
19 import org.apache.commons.lang.StringUtils;
20 import org.eclipse.jdt.internal.compiler.flow.InsideSubRoutineFlowContext;
21 import org.joda.time.DateTime;
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.search.*;
25 import org.kuali.ole.module.purap.PurapConstants;
26 import org.kuali.ole.select.OleSelectConstant;
27 import org.kuali.ole.select.businessobject.OleAcquisitionSearchResult;
28 import org.kuali.ole.select.document.service.OleAcquisitionSearchService;
29 import org.kuali.ole.select.service.impl.BatchLoadServiceImpl;
30 import org.kuali.ole.select.service.impl.OleDocStoreSearchService;
31 import org.kuali.ole.sys.OLEConstants;
32 import org.kuali.ole.sys.OLEKeyConstants;
33 import org.kuali.ole.sys.context.SpringContext;
34 import org.kuali.rice.core.api.config.property.ConfigurationService;
35 import org.kuali.rice.core.api.datetime.DateTimeService;
36 import org.kuali.rice.kew.api.document.search.DocumentSearchCriteria;
37 import org.kuali.rice.kew.api.exception.WorkflowException;
38 import org.kuali.rice.kns.service.DataDictionaryService;
39 import org.kuali.rice.krad.datadictionary.DocumentEntry;
40 import org.kuali.rice.krad.document.TransactionalDocumentBase;
41 import org.kuali.rice.krad.util.GlobalVariables;
42
43 import java.text.DateFormat;
44 import java.text.ParseException;
45 import java.text.SimpleDateFormat;
46 import java.util.*;
47
48
49
50
51 public class OleAcquisitionsSearchDocument extends TransactionalDocumentBase {
52 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OleAcquisitionsSearchDocument.class);
53
54
55
56
57 private String documentType;
58
59
60
61
62 private String initiator;
63
64
65
66
67 private String title;
68
69
70
71
72 private String author;
73
74
75
76
77 private String publisher;
78
79
80
81
82 private String isbn;
83
84 private String localIdentifier;
85
86
87
88
89 private String docNumber;
90
91
92
93
94 private String requestorName;
95
96
97
98
99 private String internalRequestorId;
100
101
102
103
104 private String externalRequestorId;
105
106
107
108
109 private String vendorName;
110
111
112
113
114 private String dateFrom;
115
116
117
118
119 private String dateTo;
120
121
122
123
124 private String purapDocumentIdentifier;
125
126
127
128
129 private String accountNumber;
130
131
132
133
134 private String organizationCode;
135
136
137
138
139 private String chartOfAccountsCode;
140
141
142
143
144 private boolean searchType;
145
146
147
148
149
150
151
152
153
154
155 private List<Bib> docDataList = new ArrayList<Bib>();
156
157 private List<String> docTypeNames = new ArrayList<String>();
158
159
160 private List<OleAcquisitionSearchResult> acqSearchResults = new ArrayList<OleAcquisitionSearchResult>();
161
162 private transient OleAcquisitionSearchService oleAcquisitionSearchService;
163
164 private transient DateTimeService dateTimeService;
165
166 private transient OleDocStoreSearchService oleDocStoreSearchService;
167
168 private transient ConfigurationService ConfigurationService;
169
170 public OleAcquisitionSearchService getOleAcquisitionSearchService() {
171 if (oleAcquisitionSearchService == null) {
172 oleAcquisitionSearchService = SpringContext.getBean(OleAcquisitionSearchService.class);
173 }
174 return oleAcquisitionSearchService;
175 }
176
177 public DateTimeService getDateTimeService() {
178 if (dateTimeService == null) {
179 dateTimeService = SpringContext.getBean(DateTimeService.class);
180 }
181 return dateTimeService;
182 }
183 public List<Bib> getDocDataList() {
184 return docDataList;
185 }
186
187 public void setDocDataList(List<Bib> docDataList) {
188 this.docDataList = docDataList;
189 }
190 private DocstoreClientLocator docstoreClientLocator;
191
192 public DocstoreClientLocator getDocstoreClientLocator() {
193 if (docstoreClientLocator == null) {
194 docstoreClientLocator = SpringContext.getBean(DocstoreClientLocator.class);
195 }
196 return docstoreClientLocator;
197 }
198 public OleDocStoreSearchService getOleDocStoreSearchService() {
199 if (oleDocStoreSearchService == null) {
200 oleDocStoreSearchService = SpringContext.getBean(OleDocStoreSearchService.class);
201 }
202 return oleDocStoreSearchService;
203 }
204
205 public ConfigurationService getConfigurationService() {
206 if (ConfigurationService == null) {
207 ConfigurationService = SpringContext.getBean(ConfigurationService.class);
208 }
209 return ConfigurationService;
210 }
211
212 public OleAcquisitionsSearchDocument() {
213 super();
214 List<String> docTypes = new ArrayList<String>();
215 docTypes.add(PurapConstants.REQUISITION_DOCUMENT_TYPE);
216 docTypes.add(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_DOCUMENT);
217 docTypes.add(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_AMENDMENT_DOCUMENT);
218 docTypes.add(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_REOPEN_DOCUMENT);
219 docTypes.add(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_CLOSE_DOCUMENT);
220 docTypes.add(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_RETRANSMIT_DOCUMENT);
221 docTypes.add(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_PRINT_DOCUMENT);
222 docTypes.add(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_VOID_DOCUMENT);
223 docTypes.add(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_PAYMENT_HOLD_DOCUMENT);
224 docTypes.add(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_REMOVE_HOLD_DOCUMENT);
225 docTypes.add(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_SPLIT_DOCUMENT);
226 docTypes.add(OLEConstants.FinancialDocumentTypeCodes.LINE_ITEM_RECEIVING);
227 docTypes.add(OLEConstants.FinancialDocumentTypeCodes.CORRECTION_RECEIVING);
228 docTypes.add(PurapConstants.PurapDocTypeCodes.PAYMENT_REQUEST_DOCUMENT);
229 docTypes.add(PurapConstants.PurapDocTypeCodes.INVOICE_DOCUMENT);
230 this.docTypeNames = docTypes;
231 }
232
233
234
235
236
237
238 public String getInitiator() {
239 return initiator;
240 }
241
242
243
244
245
246
247 public void setInitiator(String initiator) {
248 this.initiator = initiator;
249 }
250
251
252
253
254
255 public String getTitle() {
256 return title;
257 }
258
259
260
261
262
263 public void setTitle(String title) {
264 this.title = title;
265 }
266
267
268
269
270
271 public String getAuthor() {
272 return author;
273 }
274
275
276
277
278
279 public void setAuthor(String author) {
280 this.author = author;
281 }
282
283
284
285
286
287 public String getPublisher() {
288 return publisher;
289 }
290
291
292
293
294
295 public void setPublisher(String publisher) {
296 this.publisher = publisher;
297 }
298
299
300
301
302
303 public String getIsbn() {
304 return isbn;
305 }
306
307
308
309
310
311 public void setIsbn(String isbn) {
312 this.isbn = isbn;
313 }
314
315 public String getLocalIdentifier() {
316 return localIdentifier;
317 }
318
319 public void setLocalIdentifier(String localIdentifier) {
320 this.localIdentifier = localIdentifier;
321 }
322
323
324
325
326
327 public String getDocNumber() {
328 return docNumber;
329 }
330
331
332
333
334
335 public void setDocNumber(String docNumber) {
336 this.docNumber = docNumber;
337 }
338
339
340
341
342
343 public String getRequestorName() {
344 return requestorName;
345 }
346
347
348
349
350
351 public void setRequestorName(String requestorName) {
352 this.requestorName = requestorName;
353 }
354
355
356
357
358
359 public String getVendorName() {
360 return vendorName;
361 }
362
363
364
365
366
367 public void setVendorName(String vendorName) {
368 this.vendorName = vendorName;
369 }
370
371
372
373
374
375 public String getDateFrom() {
376 return dateFrom;
377 }
378
379
380
381
382
383 public void setDateFrom(String dateFrom) {
384 this.dateFrom = dateFrom;
385 }
386
387
388
389
390
391 public String getDateTo() {
392 return dateTo;
393 }
394
395
396
397
398
399 public void setDateTo(String dateTo) {
400 this.dateTo = dateTo;
401 }
402
403
404
405
406
407 public String getPurapDocumentIdentifier() {
408 return purapDocumentIdentifier;
409 }
410
411
412
413
414
415 public void setPurapDocumentIdentifier(String purapDocumentIdentifier) {
416 this.purapDocumentIdentifier = purapDocumentIdentifier;
417 }
418
419
420
421
422
423 public String getAccountNumber() {
424 return accountNumber;
425 }
426
427
428
429
430
431 public void setAccountNumber(String accountNumber) {
432 this.accountNumber = accountNumber;
433 }
434
435
436
437
438
439 public String getOrganizationCode() {
440 return organizationCode;
441 }
442
443
444
445
446
447 public void setOrganizationCode(String organizationCode) {
448 this.organizationCode = organizationCode;
449 }
450
451
452
453
454
455 public String getChartOfAccountsCode() {
456 return chartOfAccountsCode;
457 }
458
459
460
461
462
463 public void setChartOfAccountsCode(String chartOfAccountsCode) {
464 this.chartOfAccountsCode = chartOfAccountsCode;
465 }
466
467
468
469
470
471 public boolean getSearchType() {
472 return searchType;
473 }
474
475
476
477
478
479 public void setSearchType(boolean searchType) {
480 this.searchType = searchType;
481 }
482
483
484
485
486
487 public String getInternalRequestorId() {
488 return internalRequestorId;
489 }
490
491
492
493
494
495 public void setInternalRequestorId(String internalRequestorId) {
496 this.internalRequestorId = internalRequestorId;
497 }
498
499
500
501
502
503 public String getExternalRequestorId() {
504 return externalRequestorId;
505 }
506
507
508
509
510
511 public void setExternalRequestorId(String externalRequestorId) {
512 this.externalRequestorId = externalRequestorId;
513 }
514
515
516
517
518
519 public String getDocumentType() {
520 return documentType;
521 }
522
523
524
525
526
527 public void setDocumentType(String documentType) {
528 this.documentType = documentType;
529 }
530
531
532
533
534
535
536
537
538
539
540 @SuppressWarnings("rawtypes")
541
542 protected LinkedHashMap toStringMapper_RICE20_REFACTORME() {
543 LinkedHashMap map = new LinkedHashMap();
544 return map;
545 }
546
547
548
549
550
551 public List<OleAcquisitionSearchResult> getAcqSearchResults() {
552 return acqSearchResults;
553 }
554
555
556
557
558
559 public void setAcqSearchResults(List<OleAcquisitionSearchResult> acqSearchResults) {
560 this.acqSearchResults = acqSearchResults;
561 }
562
563
564
565
566
567
568
569
570 private boolean checkForAccountingDetails(String docType) {
571 LOG.debug("Inside checkForAccountingDetails of OleAcquisitionsSearchDocument");
572 boolean isValid = true;
573 if (StringUtils.isNotEmpty(docType)) {
574 if (docType.equalsIgnoreCase(PurapConstants.PurapDocTypeCodes.PAYMENT_REQUEST_DOCUMENT)) {
575 if (StringUtils.isNotEmpty(getRequestorName())
576 || StringUtils.isNotEmpty(getOrganizationCode())) {
577 isValid = false;
578 }
579 } else if (docType.equalsIgnoreCase(OLEConstants.FinancialDocumentTypeCodes.LINE_ITEM_RECEIVING)) {
580 if (StringUtils.isNotEmpty(getAccountNumber())
581 || StringUtils.isNotEmpty(getChartOfAccountsCode())
582 || StringUtils.isNotEmpty(getOrganizationCode())
583 || StringUtils.isNotEmpty(getRequestorName())) {
584 isValid = false;
585 }
586 } else if (docType.equalsIgnoreCase(OLEConstants.FinancialDocumentTypeCodes.CORRECTION_RECEIVING)) {
587 if (StringUtils.isNotEmpty(getAccountNumber())
588 || StringUtils.isNotEmpty(getChartOfAccountsCode())
589 || StringUtils.isNotEmpty(getOrganizationCode())
590 || StringUtils.isNotEmpty(getRequestorName())
591 || StringUtils.isNotEmpty(getVendorName())) {
592 isValid = false;
593 }
594 }
595 }
596 LOG.debug("Leaving checkForAccountingDetails of OleAcquisitionsSearchDocument");
597 return isValid;
598 }
599
600
601
602
603
604
605 public Map<String, List<String>> getSearchCriteria(Map<String, String> itemFields) throws Exception {
606 LOG.debug("Inside populateRequisitionFields of OleAcquisitionsSearchDocument");
607 Map<String, List<String>> searchCriteriaMap = new HashMap<String, List<String>>();
608 DocumentEntry documentEntry = SpringContext.getBean(DataDictionaryService.class).getDataDictionary().getDocumentEntry(OleAcquisitionsSearchDocument.class.getName());
609
610 Set attributeNames = documentEntry.getAttributeNames();
611 for (Object attributeName : attributeNames) {
612 String attr = (String) attributeName;
613 if ((OleSelectConstant.AcquisitionsSearch.ACQ_PO_NUMBER.equals(attr)
614 || OleSelectConstant.AcquisitionsSearch.ACQ_ACCOUNT.equals(attr)
615 || OleSelectConstant.AcquisitionsSearch.ACQ_CHART.equals(attr)
616 || OleSelectConstant.AcquisitionsSearch.ACQ_VND_NAME.equals(attr)
617 || OleSelectConstant.AcquisitionsSearch.ACQ_ORG.equals(attr))) {
618 String attrValue = (String) PropertyUtils.getProperty(this, attr);
619 attr = itemFields.get(attr);
620 if (StringUtils.isNotEmpty(attr) && StringUtils.isNotEmpty(attrValue)) {
621 searchCriteriaMap.put(attr, new ArrayList<String>(Arrays.asList(attrValue)));
622
623
624 }
625 }
626 if (LOG.isDebugEnabled()) {
627 LOG.debug("Search Criteria Size in OleAcquisitionsSearchDocument.getSearchCriteria - " + searchCriteriaMap.size());
628 }
629 }
630
631 LOG.debug("Leaving populateRequisitionFields of OleAcquisitionsSearchDocument");
632 return searchCriteriaMap;
633 }
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661 public SearchParams getBibSearchCriteria() throws Exception {
662 DocumentEntry documentEntry = SpringContext.getBean(DataDictionaryService.class).getDataDictionary().getDocumentEntry(OleAcquisitionsSearchDocument.class.getName());
663 SearchParams searchParams=new SearchParams();
664 searchParams.setPageSize(Integer.parseInt("1000"));
665 Set attributeNames = documentEntry.getAttributeNames();
666 for (Object attributeName : attributeNames) {
667 String attr = (String) attributeName;
668 if ((Bib.TITLE.equals(attr.toUpperCase())
669 || Bib.AUTHOR.equals(attr.toUpperCase())
670 || Bib.PUBLISHER.equals(attr.toUpperCase())
671 || Bib.ISBN.equals(attr.toUpperCase())
672 || OleSelectConstant.AcquisitionsSearch.ACQ_LOCAL_ID.equals(attr))) {
673 String attrValue = (String) PropertyUtils.getProperty(this, attr);
674 attr = OleSelectConstant.AcquisitionsSearch.DOC_STORE_FIELDS.get(attr);
675 if(attr.equalsIgnoreCase("localIdentifier")){
676 attr="LocalId_search";
677 }
678 else{
679 attr=attr.toUpperCase();
680 }
681 if (StringUtils.isNotEmpty(attr) && StringUtils.isNotEmpty(attrValue)) {
682 searchParams.getSearchConditions().add(searchParams.buildSearchCondition("AND",searchParams.buildSearchField(OleSelectConstant.DOCSTORE_TYPE_BIB,attr,attrValue),"AND"));
683 searchParams.getSearchResultFields().add(searchParams.buildSearchResultField(OleSelectConstant.DOCSTORE_TYPE_BIB,"id"));
684 }
685 }
686 }
687 LOG.debug("Inside getBibSearchCriteria" );
688 return searchParams;
689 }
690
691
692
693
694
695
696
697 public List<OleAcquisitionSearchResult> populateCriteriaAndSearch(String docTypeFullName, Map<String, List<String>> fixedParameters)
698 throws WorkflowException, ParseException {
699 LOG.debug("Inside populateCriteriaAndSearch of OleAcquisitionsSearchDocument");
700 DocumentSearchCriteria.Builder docSearchCriteria = DocumentSearchCriteria.Builder.create();
701
702
703 docSearchCriteria.setDocumentTypeName(docTypeFullName);
704 if (StringUtils.isNotEmpty(this.dateFrom)) {
705 docSearchCriteria.setDateCreatedFrom(new DateTime(getDateTimeService().convertToDate(dateFrom)));
706 } else {
707
708
709 if (!isAnyDocFilterValue() && !isAnyBibFilterValues()) {
710 DateTimeService dateTimeService = getDateTimeService();
711 DateTime currentDate = new DateTime(dateTimeService.getCurrentSqlDate().getTime());
712 if (this.getDocumentType() == null) {
713 docSearchCriteria.setDateCreatedFrom(currentDate);
714
715 }
716 }
717
718 }
719 if (StringUtils.isNotEmpty(dateTo)) {
720 docSearchCriteria.setDateCreatedTo(new DateTime(getDateTimeService().convertToDate(dateTo)));
721 }
722 if (StringUtils.isNotEmpty(initiator)) {
723 docSearchCriteria.setInitiatorPrincipalName(initiator);
724 }
725 if (StringUtils.isNotEmpty(docNumber)) {
726 docSearchCriteria.setDocumentId(docNumber);
727 }
728 if (getSearchType()) {
729 fixedParameters.put("displayType", Arrays.asList("document"));
730 }
731
732 List<OleAcquisitionSearchResult> resultRows = new ArrayList<OleAcquisitionSearchResult>();
733 resultRows = getOleAcquisitionSearchService().performDocumentSearch(docSearchCriteria.build(), fixedParameters);
734
735 LOG.debug("Leaving populateCriteriaAndSearch of OleAcquisitionsSearchDocument");
736 return resultRows;
737 }
738
739
740
741
742
743
744 private boolean isAnyDocFilterValue() {
745 boolean isPresent = false;
746 if (StringUtils.isNotEmpty(getDocumentType())
747 || StringUtils.isNotEmpty(getAccountNumber())
748 || StringUtils.isNotEmpty(getChartOfAccountsCode())
749 || StringUtils.isNotEmpty(getOrganizationCode())
750 || StringUtils.isNotEmpty(getRequestorName())
751 || StringUtils.isNotEmpty(getVendorName())
752 || StringUtils.isNotEmpty(getDateFrom())
753 || StringUtils.isNotEmpty(getDateTo())
754 || StringUtils.isNotEmpty(getPurapDocumentIdentifier())
755 || StringUtils.isNotEmpty(getDocNumber())
756 || StringUtils.isNotEmpty(getInitiator())) {
757 isPresent = true;
758 }
759 return isPresent;
760
761 }
762
763
764
765
766
767
768 private boolean isAnyBibFilterValues() {
769 boolean isValid = false;
770 if (StringUtils.isNotEmpty(getTitle())
771 || StringUtils.isNotEmpty(getAuthor())
772 || StringUtils.isNotEmpty(getIsbn())
773 || StringUtils.isNotEmpty(getLocalIdentifier())
774 || StringUtils.isNotEmpty(getPublisher())) {
775 isValid = true;
776 }
777 return isValid;
778
779 }
780
781
782
783
784
785
786
787 private boolean validateDocumentType() {
788 if (docTypeNames.contains(documentType.toUpperCase())) {
789 return true;
790 }
791 return false;
792 }
793
794
795
796
797
798
799
800 public List<OleAcquisitionSearchResult> searchResults() {
801 LOG.debug("Inside SearchResults of OleAcquisitionsSearchDocument");
802 List<OleAcquisitionSearchResult> resultRows = new ArrayList<OleAcquisitionSearchResult>();
803 if (!isAnyDocFilterValue() && !isAnyBibFilterValues()) {
804 DateTimeService dateTimeService = getDateTimeService();
805 String currentDate = dateTimeService.toDateString(dateTimeService.getCurrentSqlDate());
806 if (!(this.getDocumentType() != null && this.getDateFrom() == null)) {
807 setDateFrom(currentDate);
808 }
809 }
810
811 try {
812 if (checkForAccountingDetails(getDocumentType())) {
813 List<String> titleList;
814 if (isAnyBibFilterValues()) {
815
816 SearchResponse searchResponse = getDocstoreClientLocator().getDocstoreClient().search(getBibSearchCriteria());
817 List<SearchResult> searchResults=searchResponse.getSearchResults();
818 Map<String, List<String>> searchCriterias = new HashMap<String, List<String>>();
819 List<String> titleIds = getOleAcquisitionSearchService().getTitleIds(searchResults);
820 if (titleIds.size() > 0) {
821 if (StringUtils.isNotEmpty(getDocumentType()) && validateDocumentType()) {
822 if ((documentType.equalsIgnoreCase(PurapConstants.REQUISITION_DOCUMENT_TYPE))) {
823 searchCriterias.put(OleSelectConstant.AcquisitionsSearch.ITEM_TITLE_ID,
824 titleIds);
825 searchCriterias.putAll(getSearchCriteria(OleSelectConstant.AcquisitionsSearch.REQUISITION_FIELDS));
826 resultRows.addAll(populateCriteriaAndSearch(documentType.toUpperCase(), searchCriterias));
827 } else if ((documentType.equalsIgnoreCase(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_DOCUMENT))
828 | (documentType.equalsIgnoreCase(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_AMENDMENT_DOCUMENT))
829 | (documentType.equalsIgnoreCase(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_REOPEN_DOCUMENT))
830 | (documentType.equalsIgnoreCase(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_CLOSE_DOCUMENT))
831 | (documentType.equalsIgnoreCase(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_RETRANSMIT_DOCUMENT))
832 | (documentType.equalsIgnoreCase(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_PRINT_DOCUMENT))
833 | (documentType.equalsIgnoreCase(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_VOID_DOCUMENT))
834 | (documentType.equalsIgnoreCase(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_PAYMENT_HOLD_DOCUMENT))
835 | (documentType.equalsIgnoreCase(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_REMOVE_HOLD_DOCUMENT))
836 | (documentType.equalsIgnoreCase(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_SPLIT_DOCUMENT))) {
837 searchCriterias.put(OleSelectConstant.AcquisitionsSearch.ITEM_TITLE_ID, titleIds);
838 searchCriterias.putAll(getSearchCriteria(OleSelectConstant.AcquisitionsSearch.PURCHASEORDER_FIELDS));
839 resultRows.addAll(populateCriteriaAndSearch(documentType.toUpperCase(), searchCriterias));
840 } else if (documentType.equalsIgnoreCase(OLEConstants.FinancialDocumentTypeCodes.LINE_ITEM_RECEIVING)) {
841 searchCriterias.put(OleSelectConstant.AcquisitionsSearch.ITEM_TITLE_ID, titleIds);
842 searchCriterias.putAll(getSearchCriteria(OleSelectConstant.AcquisitionsSearch.LINE_ITEM_RECEIVING_FIELDS));
843 resultRows.addAll(populateCriteriaAndSearch(documentType.toUpperCase(), searchCriterias));
844 } else if (documentType.equalsIgnoreCase(OLEConstants.FinancialDocumentTypeCodes.CORRECTION_RECEIVING)) {
845 searchCriterias.put(OleSelectConstant.AcquisitionsSearch.ITEM_TITLE_ID, titleIds);
846 searchCriterias.putAll(getSearchCriteria(OleSelectConstant.AcquisitionsSearch.CORRECTION_RECEIVING_FIELDS));
847 resultRows.addAll(populateCriteriaAndSearch(documentType.toUpperCase(), searchCriterias));
848 } else if (documentType.equalsIgnoreCase(PurapConstants.PurapDocTypeCodes.INVOICE_DOCUMENT)) {
849 searchCriterias.put(OleSelectConstant.AcquisitionsSearch.ITEM_TITLE_ID, titleIds);
850 searchCriterias.putAll(getSearchCriteria(OleSelectConstant.AcquisitionsSearch.INVOICE_FIELDS));
851 resultRows.addAll(populateCriteriaAndSearch(documentType.toUpperCase(), searchCriterias));
852 } else {
853 searchCriterias.put(OleSelectConstant.AcquisitionsSearch.ITEM_TITLE_ID, titleIds);
854 searchCriterias.putAll(getSearchCriteria(OleSelectConstant.AcquisitionsSearch.PAYMENT_FIELDS));
855 resultRows.addAll(populateCriteriaAndSearch(documentType.toUpperCase(), searchCriterias));
856 }
857 } else if (StringUtils.isEmpty(getDocumentType())) {
858 searchCriterias.put(OleSelectConstant.AcquisitionsSearch.ITEM_TITLE_ID, titleIds);
859 searchCriterias.putAll(getSearchCriteria(OleSelectConstant.AcquisitionsSearch.REQUISITION_FIELDS));
860 resultRows.addAll(populateCriteriaAndSearch(PurapConstants.REQUISITION_DOCUMENT_TYPE, searchCriterias));
861
862 searchCriterias.clear();
863 searchCriterias.put(OleSelectConstant.AcquisitionsSearch.ITEM_TITLE_ID, titleIds);
864 searchCriterias.putAll(getSearchCriteria(OleSelectConstant.AcquisitionsSearch.PURCHASEORDER_FIELDS));
865 resultRows.addAll(populateCriteriaAndSearch(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_DOCUMENT,
866 searchCriterias));
867 searchCriterias.put(OleSelectConstant.AcquisitionsSearch.ITEM_TITLE_ID, titleIds);
868 searchCriterias.putAll(getSearchCriteria(OleSelectConstant.AcquisitionsSearch.INVOICE_FIELDS));
869
870 if (StringUtils.isEmpty(getRequestorName())) {
871 searchCriterias.clear();
872 searchCriterias.put(OleSelectConstant.AcquisitionsSearch.ITEM_TITLE_ID, titleIds);
873 searchCriterias.putAll(getSearchCriteria(OleSelectConstant.AcquisitionsSearch.LINE_ITEM_RECEIVING_FIELDS));
874 resultRows.addAll(populateCriteriaAndSearch(OLEConstants.FinancialDocumentTypeCodes.LINE_ITEM_RECEIVING,
875 searchCriterias));
876
877 searchCriterias.clear();
878 searchCriterias.put(OleSelectConstant.AcquisitionsSearch.ITEM_TITLE_ID, titleIds);
879 searchCriterias.putAll(getSearchCriteria(OleSelectConstant.AcquisitionsSearch.CORRECTION_RECEIVING_FIELDS));
880 resultRows.addAll(populateCriteriaAndSearch(OLEConstants.FinancialDocumentTypeCodes.CORRECTION_RECEIVING,
881 searchCriterias));
882
883 searchCriterias.clear();
884 searchCriterias.put(OleSelectConstant.AcquisitionsSearch.ITEM_TITLE_ID, titleIds);
885 searchCriterias.putAll(getSearchCriteria(OleSelectConstant.AcquisitionsSearch.PAYMENT_FIELDS));
886 resultRows.addAll(populateCriteriaAndSearch(PurapConstants.PurapDocTypeCodes.PAYMENT_REQUEST_DOCUMENT,
887 searchCriterias));
888 }
889
890 } else {
891 GlobalVariables.getMessageMap().putError(OleSelectConstant.AcquisitionsSearch.REQUISITIONS,
892 OLEKeyConstants.ERROR_NO_DOC_TYPE_FOUND, new String[]{});
893 }
894 }
895 } else {
896 if (StringUtils.isNotEmpty(getDocumentType()) && validateDocumentType()) {
897 if ((documentType.equalsIgnoreCase(PurapConstants.REQUISITION_DOCUMENT_TYPE))) {
898 resultRows.addAll(populateCriteriaAndSearch(PurapConstants.REQUISITION_DOCUMENT_TYPE,
899 getSearchCriteria(OleSelectConstant.AcquisitionsSearch.REQUISITION_FIELDS)));
900 } else if ((documentType.equalsIgnoreCase(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_DOCUMENT))
901 | (documentType.equalsIgnoreCase(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_AMENDMENT_DOCUMENT))
902 | (documentType.equalsIgnoreCase(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_REOPEN_DOCUMENT))
903 | (documentType.equalsIgnoreCase(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_CLOSE_DOCUMENT))
904 | (documentType.equalsIgnoreCase(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_RETRANSMIT_DOCUMENT))
905 | (documentType.equalsIgnoreCase(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_PRINT_DOCUMENT))
906 | (documentType.equalsIgnoreCase(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_VOID_DOCUMENT))
907 | (documentType.equalsIgnoreCase(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_PAYMENT_HOLD_DOCUMENT))
908 | (documentType.equalsIgnoreCase(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_REMOVE_HOLD_DOCUMENT))
909 | (documentType.equalsIgnoreCase(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_SPLIT_DOCUMENT))) {
910 resultRows.addAll(populateCriteriaAndSearch(documentType.toUpperCase(),
911 getSearchCriteria(OleSelectConstant.AcquisitionsSearch.PURCHASEORDER_FIELDS)));
912 } else if (documentType.equalsIgnoreCase(OLEConstants.FinancialDocumentTypeCodes.LINE_ITEM_RECEIVING)) {
913 resultRows.addAll(populateCriteriaAndSearch(OLEConstants.FinancialDocumentTypeCodes.LINE_ITEM_RECEIVING,
914 getSearchCriteria(OleSelectConstant.AcquisitionsSearch.LINE_ITEM_RECEIVING_FIELDS)));
915 } else if (documentType.equalsIgnoreCase(OLEConstants.FinancialDocumentTypeCodes.CORRECTION_RECEIVING)) {
916 resultRows.addAll(populateCriteriaAndSearch(OLEConstants.FinancialDocumentTypeCodes.CORRECTION_RECEIVING,
917 getSearchCriteria(OleSelectConstant.AcquisitionsSearch.CORRECTION_RECEIVING_FIELDS)));
918 } else if (documentType.equalsIgnoreCase(PurapConstants.PurapDocTypeCodes.PAYMENT_REQUEST_DOCUMENT)) {
919 resultRows.addAll(populateCriteriaAndSearch(PurapConstants.PurapDocTypeCodes.PAYMENT_REQUEST_DOCUMENT,
920 getSearchCriteria(OleSelectConstant.AcquisitionsSearch.PAYMENT_FIELDS)));
921 }else if (documentType.equalsIgnoreCase(PurapConstants.PurapDocTypeCodes.INVOICE_DOCUMENT)) {
922 resultRows.addAll(populateCriteriaAndSearch(PurapConstants.PurapDocTypeCodes.INVOICE_DOCUMENT,
923 getSearchCriteria(OleSelectConstant.AcquisitionsSearch.INVOICE_FIELDS)));
924 }
925
926 } else if (StringUtils.isEmpty(getDocumentType())) {
927
928 resultRows.addAll(populateCriteriaAndSearch(PurapConstants.REQUISITION_DOCUMENT_TYPE,
929 getSearchCriteria(OleSelectConstant.AcquisitionsSearch.REQUISITION_FIELDS)));
930 resultRows.addAll(populateCriteriaAndSearch(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_DOCUMENT,
931 getSearchCriteria(OleSelectConstant.AcquisitionsSearch.PURCHASEORDER_FIELDS)));
932 resultRows.addAll(populateCriteriaAndSearch(PurapConstants.PurapDocTypeCodes.INVOICE_DOCUMENT,
933 getSearchCriteria(OleSelectConstant.AcquisitionsSearch.INVOICE_FIELDS)));
934 if (StringUtils.isEmpty(getRequestorName())) {
935 resultRows.addAll(populateCriteriaAndSearch(OLEConstants.FinancialDocumentTypeCodes.LINE_ITEM_RECEIVING,
936 getSearchCriteria(OleSelectConstant.AcquisitionsSearch.LINE_ITEM_RECEIVING_FIELDS)));
937 resultRows.addAll(populateCriteriaAndSearch(OLEConstants.FinancialDocumentTypeCodes.CORRECTION_RECEIVING,
938 getSearchCriteria(OleSelectConstant.AcquisitionsSearch.CORRECTION_RECEIVING_FIELDS)));
939 resultRows.addAll(populateCriteriaAndSearch(PurapConstants.PurapDocTypeCodes.PAYMENT_REQUEST_DOCUMENT,
940 getSearchCriteria(OleSelectConstant.AcquisitionsSearch.PAYMENT_FIELDS)));
941 }
942 } else {
943 GlobalVariables.getMessageMap().putError(OleSelectConstant.AcquisitionsSearch.REQUISITIONS,
944 OLEKeyConstants.ERROR_NO_DOC_TYPE_FOUND, new String[]{});
945 }
946
947 }
948 }
949 } catch (Exception ex) {
950 LOG.error("Exception while attempting to Search the Document: " + ex);
951 throw new RuntimeException(ex);
952 }
953 LOG.debug("Leaving SearchResults of OleAcquisitionsSearchDocument");
954
955 if (getConfigurationService().getPropertyValueAsString("dateFrom").equalsIgnoreCase(this.getDateFrom())) {
956 this.dateFrom = null;
957 }
958
959 return resultRows;
960 }
961
962
963 public List<OleAcquisitionSearchResult> listOfPOsSearchResults(String loadSumId) {
964 LOG.debug("Inside SearchResults of OleAcquisitionsSearchDocument");
965 List<OleAcquisitionSearchResult> resultRows = new ArrayList<OleAcquisitionSearchResult>();
966 try {
967 List allPOsList = SpringContext.getBean(BatchLoadServiceImpl.class).getPOList(loadSumId);
968 if (checkForAccountingDetails(getDocumentType())) {
969 if (StringUtils.isEmpty(getDocumentType())) {
970 if (allPOsList.size() > 0) {
971 for (int i = 0; i < allPOsList.size(); i++) {
972 this.docNumber = (String) allPOsList.get(i);
973 resultRows.addAll(populateCriteriaAndSearch(PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_DOCUMENT,
974 getSearchCriteria(OleSelectConstant.AcquisitionsSearch.PURCHASEORDER_FIELDS)));
975 }
976 } else {
977 GlobalVariables.getMessageMap().putError(OleSelectConstant.AcquisitionsSearch.REQUISITIONS,
978 OLEKeyConstants.ERROR_NO_DOC_TYPE_FOUND, new String[]{});
979 }
980 } else {
981 GlobalVariables.getMessageMap().putError(OleSelectConstant.AcquisitionsSearch.REQUISITIONS,
982 OLEKeyConstants.ERROR_NO_DOC_TYPE_FOUND, new String[]{});
983 }
984 }
985 this.docNumber = "";
986 } catch (Exception ex) {
987 LOG.error("Exception while attempting to Search the Document: " + ex);
988 throw new RuntimeException(ex);
989 }
990 LOG.debug("Leaving SearchResults of OleAcquisitionsSearchDocument");
991
992 return resultRows;
993 }
994
995
996
997
998
999
1000
1001 public boolean isToDateLesserThanFromDate() throws Exception {
1002
1003 if (this.getDocumentType() != null && this.getDateFrom() == null) {
1004 this.dateFrom = getConfigurationService().getPropertyValueAsString("dateFrom");
1005 }
1006 boolean isToDateLesserThanFromDate = false;
1007 if (this.dateFrom != null && this.dateTo != null) {
1008 DateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
1009 Date startDate = formatter.parse(this.dateFrom);
1010 Date endDate = formatter.parse(this.dateTo);
1011 if (startDate.compareTo(endDate) > 0) {
1012 isToDateLesserThanFromDate = true;
1013 }
1014 }
1015 return isToDateLesserThanFromDate;
1016 }
1017
1018 }