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