View Javadoc
1   package org.kuali.ole.docstore.indexer.solr;
2   
3   import org.apache.commons.lang.time.StopWatch;
4   import org.apache.solr.common.SolrInputDocument;
5   import org.kuali.ole.docstore.discovery.solr.work.instance.oleml.WorkInstanceOlemlDocBuilder;
6   import org.kuali.ole.docstore.model.xmlpojo.ingest.RequestDocument;
7   import org.kuali.ole.docstore.utility.BatchIngestStatistics;
8   import org.kuali.ole.docstore.utility.BulkIngestStatistics;
9   import org.slf4j.Logger;
10  import org.slf4j.LoggerFactory;
11  
12  import java.util.ArrayList;
13  import java.util.List;
14  
15  /**
16   * Created with IntelliJ IDEA.
17   * User: mjagan
18   * Date: 7/2/13
19   * Time: 7:05 PM
20   * To change this template use File | Settings | File Templates.
21   */
22  public class WorkItemDocumentIndexer extends AbstractDocumentIndexer {
23  
24      private Logger logger = LoggerFactory.getLogger(this.getClass());
25      private static WorkItemDocumentIndexer ourInstance = null;
26  
27      public static WorkItemDocumentIndexer getInstance() {
28          if (null == ourInstance) {
29              ourInstance = new WorkItemDocumentIndexer();
30          }
31          return ourInstance;
32      }
33  
34      @Override
35      public String indexDocuments(List<RequestDocument> requestDocuments, boolean commit) {
36          BatchIngestStatistics batchStatistics = BulkIngestStatistics.getInstance().getCurrentBatch();
37  
38          String result = null;
39          StopWatch timer = new StopWatch();
40          StopWatch xmlToObjTime = new StopWatch();
41          xmlToObjTime.start();
42          xmlToObjTime.suspend();
43          timer.start();
44          List<SolrInputDocument> solrInputDocuments = new ArrayList<SolrInputDocument>();
45          if (requestDocuments != null && requestDocuments.size() > 0) {
46              StopWatch buildSolrInputDocTime = new StopWatch();
47              StopWatch xmlToPojoTimer = new StopWatch();
48              buildSolrInputDocTime.start();
49              buildSolrInputDocTime.suspend();
50              xmlToPojoTimer.start();
51              xmlToPojoTimer.suspend();
52              try {
53                  for (RequestDocument requestDocument : requestDocuments) {
54                      new WorkInstanceOlemlDocBuilder()
55                              .buildSolrInputDocument(requestDocument, solrInputDocuments);
56                      assignUUIDs(solrInputDocuments, null);
57                  }
58              } catch (Exception e1) {
59                  result = buildFailureMsg(null, "Indexing failed. " + e1.getMessage());
60                  logger.error(result, e1);
61              }
62              timer.stop();
63              if ((null == solrInputDocuments) || (solrInputDocuments.isEmpty())) {
64                  result = buildFailureMsg(null, "No valid documents found in input.");
65                  return result;
66              }
67              int numDocs = solrInputDocuments.size();
68              batchStatistics.setTimeToConvertXmlToPojo(xmlToPojoTimer.getTime());
69              batchStatistics.setTimeToConvertToSolrInputDocs(buildSolrInputDocTime.getTime());
70              logger.info("Conversion to Solr docs- Num:" + numDocs + ": Time taken:" + timer.toString());
71              result = indexSolrDocuments(solrInputDocuments, commit);
72          }
73          return result;
74      }
75  }