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 package org.kuali.kfs.module.ar.businessobject.lookup;
017
018 import java.util.Iterator;
019 import java.util.List;
020 import java.util.Map;
021
022 import org.kuali.kfs.module.ar.businessobject.AccountsReceivableDocumentHeader;
023 import org.kuali.kfs.module.ar.document.CustomerInvoiceDocument;
024 import org.kuali.kfs.sys.KFSConstants;
025 import org.kuali.kfs.sys.context.SpringContext;
026 import org.kuali.rice.kew.exception.WorkflowException;
027 import org.kuali.rice.kns.bo.BusinessObject;
028 import org.kuali.rice.kns.document.Document;
029 import org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl;
030 import org.kuali.rice.kns.service.DataDictionaryService;
031 import org.kuali.rice.kns.service.DocumentService;
032
033 public class AccountsReceivablesDocumentHeaderLookupableHelperServiceImpl extends KualiLookupableHelperServiceImpl {
034
035 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(AccountsReceivablesDocumentHeaderLookupableHelperServiceImpl.class);
036 private DataDictionaryService dataDictionaryService;
037
038 /**
039 * @see org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#getSearchResults(java.util.Map)
040 */
041 @Override
042 public List<? extends BusinessObject> getSearchResults(Map<String, String> fieldValues) {
043 setBackLocation(fieldValues.get(KFSConstants.BACK_LOCATION));
044 setDocFormKey(fieldValues.get(KFSConstants.DOC_FORM_KEY));
045 setReferencesToRefresh(fieldValues.get(KFSConstants.REFERENCES_TO_REFRESH));
046
047 List searchResults = (List) getLookupService().findCollectionBySearchHelper(getBusinessObjectClass(), fieldValues, false);
048
049 try {
050 for (Iterator iter = searchResults.iterator(); iter.hasNext();) {
051 AccountsReceivableDocumentHeader accountsReceivableDocumentHeader = (AccountsReceivableDocumentHeader) iter.next();
052 Document document = SpringContext.getBean(DocumentService.class).getByDocumentHeaderId(accountsReceivableDocumentHeader.getDocumentNumber());
053
054 String documentTypeName = document.getDocumentHeader().getWorkflowDocument().getDocumentType();
055 if (!documentTypeName.equals(dataDictionaryService.getDocumentTypeNameByClass(CustomerInvoiceDocument.class))) {
056 iter.remove();
057 }
058 }
059 } catch (WorkflowException wfe) {
060
061 }
062
063 return searchResults;
064 }
065 /**
066 * Gets dataDictionaryService
067 * @see org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#getDataDictionaryService()
068 */
069 public DataDictionaryService getDataDictionaryService() {
070 return dataDictionaryService;
071 }
072
073 /**
074 * sets dataDictionaryService sets dataDictionaryService
075 * @see org.kuali.rice.kns.lookup.AbstractLookupableHelperServiceImpl#setDataDictionaryService(org.kuali.rice.kns.service.DataDictionaryService)
076 */
077 public void setDataDictionaryService(DataDictionaryService dataDictionaryService) {
078 this.dataDictionaryService = dataDictionaryService;
079 }
080 }