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.license.binary.WorkLicenseBinaryDocBuilder;
6 import org.kuali.ole.docstore.discovery.solr.work.license.onixpl.WorkLicenseOnixplDocBuilder;
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 WorkLicenseDocumentIndexer extends AbstractDocumentIndexer {
25
26 private Logger logger = LoggerFactory.getLogger(this.getClass());
27 private static WorkLicenseDocumentIndexer ourInstance = null;
28
29 public static WorkLicenseDocumentIndexer getInstance() {
30 if (null == ourInstance) {
31 ourInstance = new WorkLicenseDocumentIndexer();
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 if (DocFormat.ONIXPL.isEqualTo((requestDocument.getFormat()))) {
57 new WorkLicenseOnixplDocBuilder()
58 .buildSolrInputDocument(requestDocument, solrInputDocuments);
59 } else if ((DocFormat.PDF.isEqualTo((requestDocument.getFormat()))) || DocFormat.DOC.isEqualTo(
60 requestDocument.getFormat()) || DocFormat.XSLT.isEqualTo(
61 requestDocument.getFormat())) {
62 new WorkLicenseBinaryDocBuilder()
63 .buildSolrInputDocument(requestDocument, solrInputDocuments);
64 } else {
65 throw new Exception(
66 "Unsupported Document Format : " + requestDocument.getFormat() + " Called.");
67 }
68 assignUUIDs(solrInputDocuments, null);
69 }
70 } catch (Exception e1) {
71 result = buildFailureMsg(null, "Indexing failed. " + e1.getMessage());
72 logger.error(result, e1);
73 }
74 timer.stop();
75 if ((null == solrInputDocuments) || (solrInputDocuments.isEmpty())) {
76 result = buildFailureMsg(null, "No valid documents found in input.");
77 return result;
78 }
79 int numDocs = solrInputDocuments.size();
80 batchStatistics.setTimeToConvertXmlToPojo(xmlToPojoTimer.getTime());
81 batchStatistics.setTimeToConvertToSolrInputDocs(buildSolrInputDocTime.getTime());
82 logger.info("Conversion to Solr docs- Num:" + numDocs + ": Time taken:" + timer.toString());
83 result = indexSolrDocuments(solrInputDocuments, commit);
84 }
85 return result;
86 }
87 }