View Javadoc
1   /*
2    * Copyright 2011 The Kuali Foundation.
3    *
4    * Licensed under the Educational Community License,  Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing,  software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,  either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.select.document;
17  
18  import org.apache.commons.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   * This class is the document Class for Acquisition Search
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       * Stores the value of documentType.
56       */
57      private String documentType;
58  
59      /**
60       * Stores the value of initiator of the document.
61       */
62      private String initiator;
63  
64      /**
65       * Stores the value of title.
66       */
67      private String title;
68  
69      /**
70       * Stores the value of author.
71       */
72      private String author;
73  
74      /**
75       * Stores the value of publisher.
76       */
77      private String publisher;
78  
79      /**
80       * Stores the value of isbn.
81       */
82      private String isbn;
83  
84      private String localIdentifier;
85  
86      /**
87       * Stores the value of document Number.
88       */
89      private String docNumber;
90  
91      /**
92       * Stores the value of requestorName.
93       */
94      private String requestorName;
95  
96      /**
97       * Stores the value of internalRequestorId.
98       */
99      private String internalRequestorId;
100 
101     /**
102      * Stores the value of externalRequestorId.
103      */
104     private String externalRequestorId;
105 
106     /**
107      * Stores the value of vendorName.
108      */
109     private String vendorName;
110 
111     /**
112      * Stores the value of Starting of creation Date.
113      */
114     private String dateFrom;
115 
116     /**
117      * Stores the value of Creation Date Ending.
118      */
119     private String dateTo;
120 
121     /**
122      * Stores the value of purapDocumentIdentifier.
123      */
124     private String purapDocumentIdentifier;
125 
126     /**
127      * Stores the value of accountNumber.
128      */
129     private String accountNumber;
130 
131     /**
132      * Stores the value of organizationCode.
133      */
134     private String organizationCode;
135 
136     /**
137      * Stores the value of chartOfAccountsCode.
138      */
139     private String chartOfAccountsCode;
140 
141     /**
142      * Stores the value of searchType.
143      */
144     private boolean searchType;
145 
146    /* private List<DocData> docDataList = new ArrayList<DocData>();
147 
148     public List<DocData> getDocDataList() {
149         return docDataList;
150     }
151 
152     public void setDocDataList(List<DocData> docDataList) {
153         this.docDataList = docDataList;
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      * Gets the Initiator attribute.
235      *
236      * @return Returns the Initiator.
237      */
238     public String getInitiator() {
239         return initiator;
240     }
241 
242     /**
243      * Sets the Initiator attribute value.
244      *
245      * @param initiator
246      */
247     public void setInitiator(String initiator) {
248         this.initiator = initiator;
249     }
250 
251     /**
252      * Getter for property: title.<br/>
253      * Stores the value of title.
254      */
255     public String getTitle() {
256         return title;
257     }
258 
259     /**
260      * Setter for property: title.<br/>
261      * Stores the value of title.
262      */
263     public void setTitle(String title) {
264         this.title = title;
265     }
266 
267     /**
268      * Getter for property: author.<br/>
269      * Stores the value of author.
270      */
271     public String getAuthor() {
272         return author;
273     }
274 
275     /**
276      * Setter for property: author.<br/>
277      * Stores the value of author.
278      */
279     public void setAuthor(String author) {
280         this.author = author;
281     }
282 
283     /**
284      * Getter for property: publisher.<br/>
285      * Stores the value of publisher.
286      */
287     public String getPublisher() {
288         return publisher;
289     }
290 
291     /**
292      * Setter for property: publisher.<br/>
293      * Stores the value of publisher.
294      */
295     public void setPublisher(String publisher) {
296         this.publisher = publisher;
297     }
298 
299     /**
300      * Getter for property: isxn.<br/>
301      * Stores the value of isxn.
302      */
303     public String getIsbn() {
304         return isbn;
305     }
306 
307     /**
308      * Setter for property: isbn.<br/>
309      * Stores the value of isbn.
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      * Getter for property: docNumber.<br/>
325      * Stores the value of document Number.
326      */
327     public String getDocNumber() {
328         return docNumber;
329     }
330 
331     /**
332      * Setter for property: docNumber.<br/>
333      * Stores the value of document Number.
334      */
335     public void setDocNumber(String docNumber) {
336         this.docNumber = docNumber;
337     }
338 
339     /**
340      * Getter for property: requestorName.<br/>
341      * Stores the value of requestorName.
342      */
343     public String getRequestorName() {
344         return requestorName;
345     }
346 
347     /**
348      * Setter for property: requestorName.<br/>
349      * Stores the value of requestorName.
350      */
351     public void setRequestorName(String requestorName) {
352         this.requestorName = requestorName;
353     }
354 
355     /**
356      * Getter for property: vendorName.<br/>
357      * Stores the value of vendorName.
358      */
359     public String getVendorName() {
360         return vendorName;
361     }
362 
363     /**
364      * Setter for property: vendorName.<br/>
365      * Stores the value of vendorName.
366      */
367     public void setVendorName(String vendorName) {
368         this.vendorName = vendorName;
369     }
370 
371     /**
372      * Getter for property: dateFrom.<br/>
373      * Stores the value of Starting of creation Date.
374      */
375     public String getDateFrom() {
376         return dateFrom;
377     }
378 
379     /**
380      * Setter for property: dateFrom.<br/>
381      * Stores the value of Starting of creation Date.
382      */
383     public void setDateFrom(String dateFrom) {
384         this.dateFrom = dateFrom;
385     }
386 
387     /**
388      * Getter for property: dateTo.<br/>
389      * Stores the value of Creation Date Ending.
390      */
391     public String getDateTo() {
392         return dateTo;
393     }
394 
395     /**
396      * Setter for property: dateTo.<br/>
397      * Stores the value of Creation Date Ending.
398      */
399     public void setDateTo(String dateTo) {
400         this.dateTo = dateTo;
401     }
402 
403     /**
404      * Getter for property: purapDocumentIdentifier.<br/>
405      * Stores the value of purapDocumentIdentifier.
406      */
407     public String getPurapDocumentIdentifier() {
408         return purapDocumentIdentifier;
409     }
410 
411     /**
412      * Setter for property: purapDocumentIdentifier.<br/>
413      * Stores the value of purapDocumentIdentifier.
414      */
415     public void setPurapDocumentIdentifier(String purapDocumentIdentifier) {
416         this.purapDocumentIdentifier = purapDocumentIdentifier;
417     }
418 
419     /**
420      * Getter for property: accountNumber.<br/>
421      * Stores the value of accountNumber.
422      */
423     public String getAccountNumber() {
424         return accountNumber;
425     }
426 
427     /**
428      * Setter for property: accountNumber.<br/>
429      * Stores the value of accountNumber.
430      */
431     public void setAccountNumber(String accountNumber) {
432         this.accountNumber = accountNumber;
433     }
434 
435     /**
436      * Getter for property: organizationCode.<br/>
437      * Stores the value of organizationCode.
438      */
439     public String getOrganizationCode() {
440         return organizationCode;
441     }
442 
443     /**
444      * Setter for property: organizationCode.<br/>
445      * Stores the value of organizationCode.
446      */
447     public void setOrganizationCode(String organizationCode) {
448         this.organizationCode = organizationCode;
449     }
450 
451     /**
452      * Getter for property: chartOfAccountsCode.<br/>
453      * Stores the value of chartOfAccountsCode.
454      */
455     public String getChartOfAccountsCode() {
456         return chartOfAccountsCode;
457     }
458 
459     /**
460      * Setter for property: chartOfAccountsCode.<br/>
461      * Stores the value of chartOfAccountsCode.
462      */
463     public void setChartOfAccountsCode(String chartOfAccountsCode) {
464         this.chartOfAccountsCode = chartOfAccountsCode;
465     }
466 
467     /**
468      * Getter for property: searchType.<br/>
469      * Stores the value of searchType.
470      */
471     public boolean getSearchType() {
472         return searchType;
473     }
474 
475     /**
476      * Setter for property: searchType.<br/>
477      * Stores the value of searchType.
478      */
479     public void setSearchType(boolean searchType) {
480         this.searchType = searchType;
481     }
482 
483     /**
484      * Getter for property: internalRequestorId.<br/>
485      * Stores the value of internalRequestorId.
486      */
487     public String getInternalRequestorId() {
488         return internalRequestorId;
489     }
490 
491     /**
492      * Setter for property: internalRequestorId.<br/>
493      * Stores the value of internalRequestorId.
494      */
495     public void setInternalRequestorId(String internalRequestorId) {
496         this.internalRequestorId = internalRequestorId;
497     }
498 
499     /**
500      * Getter for property: initiator.<br/>
501      * Stores the value of externalRequestorId.
502      */
503     public String getExternalRequestorId() {
504         return externalRequestorId;
505     }
506 
507     /**
508      * Setter for property: initiator.<br/>
509      * Stores the value of externalRequestorId.
510      */
511     public void setExternalRequestorId(String externalRequestorId) {
512         this.externalRequestorId = externalRequestorId;
513     }
514 
515     /**
516      * Getter for property: documentType.<br/>
517      * Stores the value of documentType.
518      */
519     public String getDocumentType() {
520         return documentType;
521     }
522 
523     /**
524      * Setter for property: documentType.<br/>
525      * Stores the value of documentType.
526      */
527     public void setDocumentType(String documentType) {
528         this.documentType = documentType;
529     }
530 
531     /**
532      * Getter for property: docDataList.<br/>
533      * Stores the value of list of docData.
534      */
535 
536     /**
537      * @return map
538      * @see org.kuali.rice.krad.bo.BusinessObjectBase#toStringMapper ()
539      */
540     @SuppressWarnings("rawtypes")
541 
542     protected LinkedHashMap toStringMapper_RICE20_REFACTORME() {
543         LinkedHashMap map = new LinkedHashMap();
544         return map;
545     }
546 
547     /**
548      * Getter for property: acqSearchResults.<br/>
549      * Stores the value of list of oleAcquisitionSearchResult.
550      */
551     public List<OleAcquisitionSearchResult> getAcqSearchResults() {
552         return acqSearchResults;
553     }
554 
555     /**
556      * Setter for property: acqSearchResults.<br/>
557      * Stores the value of list of OleAcquisitionSearchResult.
558      */
559     public void setAcqSearchResults(List<OleAcquisitionSearchResult> acqSearchResults) {
560         this.acqSearchResults = acqSearchResults;
561     }
562 
563     /**
564      * Depends on the document type this will check for Accounting details which are given
565      * if that document doesn't contain correct accounting details this will return false
566      *
567      * @param docType
568      * @return isValid(boolean)
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      * This method populates a map search criteria that are entered
602      *
603      * @return Map containing Item fieldname and fieldvalues
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                     /*else
623                         searchCriteriaMap.put(attr, new String[]{""});*/
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      * This method populates a map bib search criteria that are entered
637      *
638      * @return bibSearchCriteriaMap
639      */
640    /* public Map<String, String> getBibSearchCriteria() throws Exception {
641         Map<String, String> bibSearchCriteriaMap = new HashMap<String, String>();
642         DocumentEntry documentEntry = SpringContext.getBean(DataDictionaryService.class).getDataDictionary().getDocumentEntry(OleAcquisitionsSearchDocument.class.getName());
643 
644         Set attributeNames = documentEntry.getAttributeNames();
645         for (Object attributeName : attributeNames) {
646             String attr = (String) attributeName;
647             if ((OleSelectConstant.AcquisitionsSearch.ACQ_TITLE.equals(attr)
648                     || OleSelectConstant.AcquisitionsSearch.ACQ_AUTHOR.equals(attr)
649                     || OleSelectConstant.AcquisitionsSearch.ACQ_PUBLISHER.equals(attr)
650                     || OleSelectConstant.AcquisitionsSearch.ACQ_ISBN.equals(attr)
651                     || OleSelectConstant.AcquisitionsSearch.ACQ_LOCAL_ID.equals(attr))) {
652                 String attrValue = (String) PropertyUtils.getProperty(this, attr);
653                 attr = OleSelectConstant.AcquisitionsSearch.DOC_STORE_FIELDS.get(attr);
654                 if (StringUtils.isNotEmpty(attr) && StringUtils.isNotEmpty(attrValue)) {
655                     bibSearchCriteriaMap.put(attr, attrValue);
656                 }
657             }
658         }
659         return bibSearchCriteriaMap;
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      * This method populates a map for the search criteria's entered
692      * and gets the final result
693      *
694      * @param resultRows
695      * @return documentNumbers
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         //fixedParameters.put("docTypeFullName", new String[]{docTypeFullName});
703         docSearchCriteria.setDocumentTypeName(docTypeFullName);
704         if (StringUtils.isNotEmpty(this.dateFrom)) {
705             docSearchCriteria.setDateCreatedFrom(new DateTime(getDateTimeService().convertToDate(dateFrom)));
706         } else {
707 
708             // Condition Added by Aditya for Jira OLE-2563
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             //setDateFrom(currentDate);
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      * This method checks whether any search criteria present or not
741      *
742      * @return isPresent
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      * This method checks for Bibliographic search criteria's
765      *
766      * @return boolean
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      * checks for the existing documentTypes
784      *
785      * @return boolean
786      */
787     private boolean validateDocumentType() {
788         if (docTypeNames.contains(documentType.toUpperCase())) {
789             return true;
790         }
791         return false;
792     }
793 
794     /**
795      * checks the documentType and search criteria's and depending on that the search methods will be called
796      * and a final Searched Results will be returned
797      *
798      * @return results (OleAcquisitionsSearchAttributes)
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                     //docDataList = getOleDocStoreSearchService().getDocResult(getBibSearchCriteria());
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                             /*resultRows.addAll(populateCriteriaAndSearch(documentType.toUpperCase(), searchCriterias));*/
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                         //searchCriteriaFlag=true;
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      * This method tests Whether DateTO is Lesser than DateFrom and returns true if Lesser.
997      *
998      * @return boolean
999      * @throws Exception
1000      */
1001     public boolean isToDateLesserThanFromDate() throws Exception {
1002         //for adding date
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 }