Coverage Report - org.kuali.rice.kew.docsearch.service.impl.SearchableAttributeProcessor
 
Classes in this File Line Coverage Branch Coverage Complexity
SearchableAttributeProcessor
0%
0/33
0%
0/8
3
 
 1  
 /*
 2  
  * Copyright 2005-2007 The Kuali Foundation
 3  
  *
 4  
  *
 5  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 6  
  * you may not use this file except in compliance with the License.
 7  
  * You may obtain a copy of the License at
 8  
  *
 9  
  * http://www.opensource.org/licenses/ecl2.php
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.kuali.rice.kew.docsearch.service.impl;
 18  
 
 19  
 import java.util.ArrayList;
 20  
 import java.util.Iterator;
 21  
 import java.util.List;
 22  
 
 23  
 import org.apache.log4j.Logger;
 24  
 import org.kuali.rice.kew.api.WorkflowRuntimeException;
 25  
 import org.kuali.rice.kew.docsearch.DocSearchUtils;
 26  
 import org.kuali.rice.kew.docsearch.SearchableAttribute;
 27  
 import org.kuali.rice.kew.docsearch.SearchableAttributeValue;
 28  
 import org.kuali.rice.kew.docsearch.service.SearchableAttributeProcessingService;
 29  
 import org.kuali.rice.kew.doctype.bo.DocumentType;
 30  
 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValueContent;
 31  
 import org.kuali.rice.kew.service.KEWServiceLocator;
 32  
 
 33  
 
 34  
 /**
 35  
  * Implementation of {@link SearchableAttributeProcessingService}.
 36  
  *
 37  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 38  
  */
 39  0
 public class SearchableAttributeProcessor implements SearchableAttributeProcessingService {
 40  
 
 41  0
         private static Logger LOG = Logger.getLogger(SearchableAttributeProcessor.class);
 42  
 
 43  
         public void indexDocument(String documentId) {
 44  0
                 indexDocument(documentId, true);
 45  0
         }
 46  
 
 47  
         public void indexDocument(String documentId, boolean useMostRecentDocType) {
 48  0
                 long t1 = System.currentTimeMillis();                
 49  0
                 LOG.info("Indexing document " + documentId + " for document search...");
 50  
                 try {
 51  0
                         DocumentType documentType = KEWServiceLocator.getDocumentTypeService().findByDocumentId(documentId);
 52  0
                         DocumentRouteHeaderValueContent docContent = KEWServiceLocator.getRouteHeaderService().getContent(documentId);
 53  0
                         List<SearchableAttributeValue> attributes = buildSearchableAttributeValues(documentType, documentId, docContent.getDocumentContent(), useMostRecentDocType);
 54  0
                         KEWServiceLocator.getRouteHeaderService().updateRouteHeaderSearchValues(documentId, attributes);
 55  0
                 } catch (Exception e) {
 56  0
                         String errorMsg = "Encountered an error when attempting to index searchable attributes, requeuing.";
 57  0
                         LOG.error(errorMsg, e);
 58  0
                         throw new WorkflowRuntimeException(errorMsg,e);
 59  0
                 }
 60  0
                 long t2 = System.currentTimeMillis();
 61  0
                 LOG.info("...finished indexing document " + documentId + " for document search, total time = " + (t2-t1) + " ms.");
 62  0
         }
 63  
 
 64  
         private List<SearchableAttributeValue> buildSearchableAttributeValues(DocumentType docType, String documentId, String docContent, boolean useMostRecentDocType) {
 65  0
                 if (useMostRecentDocType) {
 66  0
                         docType = KEWServiceLocator.getDocumentTypeService().findByName(docType.getName());
 67  
                 }
 68  0
                 List<SearchableAttributeValue> searchableAttributeValues = new ArrayList<SearchableAttributeValue>();
 69  
 
 70  0
                 for (Iterator iterator = docType.getSearchableAttributes().iterator(); iterator.hasNext();) {
 71  0
                         SearchableAttribute searchableAttribute = (SearchableAttribute) iterator.next();
 72  0
                         List searchStorageValues = searchableAttribute.getSearchStorageValues(
 73  
                                         DocSearchUtils.getDocumentSearchContext(documentId, docType.getName(), docContent));
 74  0
                         if (searchStorageValues != null) {
 75  0
                                 for (Iterator iterator2 = searchStorageValues.iterator(); iterator2.hasNext();) {
 76  0
                                         SearchableAttributeValue searchableAttributeValue = (SearchableAttributeValue) iterator2.next();
 77  0
                                         searchableAttributeValue.setDocumentId(documentId);
 78  0
                                         searchableAttributeValues.add(searchableAttributeValue);
 79  0
                                         searchableAttributeValue.setRouteHeader(null); // let the documentId we set represent this reference
 80  0
                                 }
 81  
                         }
 82  0
                 }
 83  
 
 84  0
                 return searchableAttributeValues;
 85  
         }
 86  
 
 87  
 }