001/* 002 * Copyright 2011 The Kuali Foundation. 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.kuali.ole.select.lookup; 018 019import org.apache.commons.lang3.StringUtils; 020import org.kuali.ole.select.OleSelectConstant; 021import org.kuali.ole.select.bo.OLEInvoiceSearchDocument; 022import org.kuali.ole.select.businessobject.OleInvoiceItem; 023import org.kuali.ole.select.document.OleInvoiceDocument; 024import org.kuali.ole.select.service.OLEInvoiceSearchService; 025import org.kuali.rice.krad.lookup.LookupableImpl; 026import org.kuali.rice.krad.service.KRADServiceLocator; 027import org.kuali.rice.krad.web.form.LookupForm; 028 029import java.text.DateFormat; 030import java.text.ParseException; 031import java.text.SimpleDateFormat; 032import java.util.*; 033 034public class OLEInvoiceSearchDocumentLookupableImpl extends LookupableImpl { 035 @Override 036 public Collection<?> performSearch(LookupForm form, Map<String, String> searchCriteria, boolean bounded) { 037 List<OLEInvoiceSearchDocument> oleInvoiceSearchDocuments=new ArrayList<OLEInvoiceSearchDocument>(); 038 List<OLEInvoiceSearchDocument> oleInvoiceDocuments=new ArrayList<OLEInvoiceSearchDocument>(); 039 List<OLEInvoiceSearchDocument> oleInvoiceDocumentsForTitle=new ArrayList<OLEInvoiceSearchDocument>(); 040 Map<String, String> searchDocumentMap = new HashMap<String, String>(); 041 Map<String, String> fieldConversion=form.getFieldConversions(); 042 boolean isAddTitleScreen=false; 043 if (fieldConversion.containsKey("invoiceNbr")) { 044 isAddTitleScreen=true; 045 for (Map.Entry<String, String> mapEntry : searchCriteria.entrySet()) { 046 if (StringUtils.isNotEmpty(mapEntry.getValue())) { 047 if (mapEntry.getKey().equalsIgnoreCase("invoiceNbr")) { 048 searchDocumentMap.put(OleSelectConstant.InvoiceSearch.INV_NUMBER, mapEntry.getValue()); 049 } else { 050 searchDocumentMap.put(mapEntry.getKey(), mapEntry.getValue()); 051 } 052 } 053 } 054 } else { 055 for (Map.Entry<String, String> mapEntry : searchCriteria.entrySet()) { 056 if (StringUtils.isNotEmpty(mapEntry.getValue())) { 057 searchDocumentMap.put(mapEntry.getKey(), mapEntry.getValue()); 058 } 059 } 060 } 061 OLEInvoiceSearchService oleInvoiceSearchService=new OLEInvoiceSearchService(); 062 try { 063 oleInvoiceDocuments= oleInvoiceSearchService.searchResults(searchDocumentMap); 064 } catch (Exception e) { 065 e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. 066 } 067 if(isAddTitleScreen){ 068 for(OLEInvoiceSearchDocument oleInvoiceSearchDocument:oleInvoiceDocuments){ 069 if(oleInvoiceSearchDocument.getDocumentStatus().equalsIgnoreCase("Initiated")){ 070 oleInvoiceDocumentsForTitle.add(oleInvoiceSearchDocument); 071 } 072 } 073 return oleInvoiceDocumentsForTitle; 074 } 075 return oleInvoiceDocuments; 076 } 077}