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.bib.marc.WorkBibMarcDocBuilder;
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
17
18
19
20
21
22 public class WorkBibMarcDocumentIndexer extends AbstractDocumentIndexer {
23
24 private Logger logger = LoggerFactory.getLogger(this.getClass());
25 private static WorkBibMarcDocumentIndexer ourInstance = null;
26
27 private WorkBibMarcDocumentIndexer() {
28 super();
29 }
30
31 public static WorkBibMarcDocumentIndexer getInstance() {
32 if (null == ourInstance) {
33 ourInstance = new WorkBibMarcDocumentIndexer();
34 }
35 return ourInstance;
36 }
37
38 @Override
39 public String indexDocuments(List<RequestDocument> requestDocuments, boolean commit) {
40 BatchIngestStatistics batchStatistics = BulkIngestStatistics.getInstance().getCurrentBatch();
41
42 String result = null;
43 StopWatch timer = new StopWatch();
44 StopWatch xmlToObjTime = new StopWatch();
45 xmlToObjTime.start();
46 xmlToObjTime.suspend();
47 timer.start();
48 List<SolrInputDocument> solrInputDocuments = new ArrayList<SolrInputDocument>();
49 if (requestDocuments != null && requestDocuments.size() > 0) {
50 StopWatch buildSolrInputDocTime = new StopWatch();
51 StopWatch xmlToPojoTimer = new StopWatch();
52 buildSolrInputDocTime.start();
53 buildSolrInputDocTime.suspend();
54 xmlToPojoTimer.start();
55 xmlToPojoTimer.suspend();
56 try {
57 for (RequestDocument requestDocument : requestDocuments) {
58 new WorkBibMarcDocBuilder()
59 .buildSolrInputDocument(requestDocument, solrInputDocuments, buildSolrInputDocTime,
60 xmlToPojoTimer);
61 assignUUIDs(solrInputDocuments, null);
62 }
63 } catch (Exception e1) {
64 result = buildFailureMsg(null, "Indexing failed. " + e1.getMessage());
65 logger.error(result, e1);
66 }
67 timer.stop();
68 if ((null == solrInputDocuments) || (solrInputDocuments.isEmpty())) {
69 result = buildFailureMsg(null, "No valid documents found in input.");
70 return result;
71 }
72 int numDocs = solrInputDocuments.size();
73 batchStatistics.setTimeToConvertXmlToPojo(xmlToPojoTimer.getTime());
74 batchStatistics.setTimeToConvertToSolrInputDocs(buildSolrInputDocTime.getTime());
75 logger.info("Conversion to Solr docs- Num:" + numDocs + ": Time taken:" + timer.toString());
76 result = indexSolrDocuments(solrInputDocuments, commit);
77 }
78 return result;
79 }
80
81
82 }