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.sys.document.workflow;
017    
018    import java.util.ArrayList;
019    import java.util.List;
020    import java.util.Map;
021    
022    import org.kuali.kfs.sys.context.SpringContext;
023    import org.kuali.kfs.sys.document.MultiselectableDocSearchConversion;
024    import org.kuali.rice.kew.docsearch.DocSearchCriteriaDTO;
025    import org.kuali.rice.kew.docsearch.DocSearchDTO;
026    import org.kuali.rice.kew.docsearch.DocumentSearchContext;
027    import org.kuali.rice.kew.docsearch.SearchAttributeCriteriaComponent;
028    import org.kuali.rice.kew.docsearch.SearchableAttributeValue;
029    import org.kuali.rice.kew.doctype.bo.DocumentType;
030    import org.kuali.rice.kew.rule.WorkflowAttributeValidationError;
031    import org.kuali.rice.kns.datadictionary.DocumentEntry;
032    import org.kuali.rice.kns.datadictionary.SearchingAttribute;
033    import org.kuali.rice.kns.datadictionary.SearchingTypeDefinition;
034    import org.kuali.rice.kns.document.Document;
035    import org.kuali.rice.kns.service.DataDictionaryService;
036    import org.kuali.rice.kns.web.ui.Column;
037    import org.kuali.rice.kns.web.ui.Row;
038    
039    public class DataDictionaryDocumentSearchCustomizer extends org.kuali.rice.kns.workflow.attribute.DataDictionaryDocumentSearchCustomizer {
040    
041        /**
042         * Constructs a DataDictionaryDocumentSearchCustomizer.java.
043         */
044        public DataDictionaryDocumentSearchCustomizer() {
045            setProcessResultSet(false);
046            setSearchResultProcessor( new KFSDocumentSearchResultProcessor() );
047        }
048    
049    
050    
051    
052        /**
053         * Retrieves the data dictionary entry for the document being operated on by the given route context
054         * @param context the current route context
055         * @return the data dictionary document entry
056         */
057        protected DocumentEntry getDocumentEntry(DocumentType documentType) {
058            return SpringContext.getBean(DataDictionaryService.class).getDataDictionary().getDocumentEntry(documentType.getName());
059        }
060    
061        @Override
062        public String generateSearchSql(DocSearchCriteriaDTO searchCriteria) {
063            DocumentEntry entry = SpringContext.getBean(DataDictionaryService.class).getDataDictionary().getDocumentEntry(searchCriteria.getDocTypeFullName());
064            DocSearchCriteriaDTO convertedSearchCriteria = searchCriteria;
065            if (entry != null) {
066                Class<? extends Document> docClass = entry.getDocumentClass();
067                Document doc = null;
068                try {
069                    doc = docClass.newInstance();
070                } catch (Exception e){}
071                if (doc instanceof MultiselectableDocSearchConversion) {
072                    MultiselectableDocSearchConversion multiselectable = (MultiselectableDocSearchConversion)doc;
073                    convertedSearchCriteria = multiselectable.convertSelections(searchCriteria);
074                }
075            }
076            return super.generateSearchSql(convertedSearchCriteria);
077        }
078    
079        // SEARCHABLE ATTRIBUTE IMPLEMENTATION
080        private FinancialSystemSearchableAttribute searchableAttribute = new FinancialSystemSearchableAttribute();
081    
082        @Override
083        public String getSearchContent(DocumentSearchContext documentSearchContext) {
084            return searchableAttribute.getSearchContent(documentSearchContext);
085        }
086    
087        @Override
088        public List<Row> getSearchingRows(DocumentSearchContext documentSearchContext) {
089            return searchableAttribute.getSearchingRows(documentSearchContext);
090        }
091    
092        @Override
093        public List<SearchableAttributeValue> getSearchStorageValues(DocumentSearchContext documentSearchContext) {
094            return searchableAttribute.getSearchStorageValues(documentSearchContext);
095        }
096    
097        @Override
098        public List<WorkflowAttributeValidationError> validateUserSearchInputs(Map<Object, Object> paramMap, DocumentSearchContext searchContext) {
099            return searchableAttribute.validateUserSearchInputs(paramMap, searchContext);
100        }
101    
102        @Override
103        public DocSearchCriteriaDTO clearSearch(DocSearchCriteriaDTO searchCriteria) {
104            DocSearchCriteriaDTO dscdto = new DocSearchCriteriaDTO();
105            // the following line can be uncommented to retain the doc type when the clear button is used on a doc search.
106            //dscdto.setDocTypeFullName(searchCriteria.getDocTypeFullName());
107            return dscdto;
108        }
109    }