1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.docstore.service;
17
18 import org.kuali.ole.docstore.discovery.service.IndexerService;
19 import org.kuali.ole.docstore.model.xmlpojo.ingest.RequestDocument;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 import java.util.ArrayList;
24 import java.util.HashMap;
25 import java.util.List;
26 import java.util.Map;
27
28
29
30
31
32
33
34 public class DocumentIndexer {
35
36 private static final Logger LOG = LoggerFactory.getLogger(DocumentIndexer.class);
37
38
39
40
41
42
43
44 public void indexDocuments(List<RequestDocument> reqDocs) throws Exception {
45 String result = ServiceLocator.getIndexerService().indexDocuments(reqDocs);
46 if (!result.startsWith("success")) {
47 throw new Exception(result);
48 }
49 }
50
51
52
53
54
55
56
57 public void indexDocumentsForBulk(List<RequestDocument> reqDocs, boolean isCommit) throws Exception {
58 String result = ServiceLocator.getIndexerService().bulkIndexDocuments(reqDocs, isCommit);
59 if (!result.startsWith("success")) {
60 throw new Exception(result);
61 }
62 }
63
64
65
66
67
68
69
70 public void indexDocument(RequestDocument reqDoc) throws Exception {
71 String result = ServiceLocator.getIndexerService().indexDocument(reqDoc);
72 if (result.startsWith(IndexerService.FAILURE)) {
73 throw new Exception("Indexing failed. Message=" + result);
74 }
75 }
76
77
78
79
80
81
82 public void rollbackIndexedData(List<RequestDocument> requestDocuments) {
83 try {
84 Map<String, List<String>> uuids = new HashMap<String, List<String>>();
85 for (RequestDocument document : requestDocuments) {
86 for (RequestDocument linkedDoc : document.getLinkedRequestDocuments()) {
87 if (uuids.get(linkedDoc.getCategory()) == null) {
88 uuids.put(linkedDoc.getCategory(), new ArrayList<String>());
89 }
90 uuids.get(linkedDoc.getCategory()).add(linkedDoc.getUuid());
91 }
92 if (uuids.get(document.getCategory()) == null) {
93 uuids.put(document.getCategory(), new ArrayList<String>());
94 }
95 uuids.get(document.getCategory()).add(document.getUuid());
96 }
97 for (String category : uuids.keySet()) {
98 ServiceLocator.getIndexerService().deleteDocuments(category, uuids.get(category));
99 }
100 }
101 catch (Exception e) {
102 LOG.info(e.getMessage());
103 }
104 }
105
106
107
108
109
110
111 public void optimizeSolr() throws Exception {
112 ServiceLocator.getDiscoveryAdminService().optimize();
113 }
114
115
116
117
118
119
120 public void optimizeSolr(Boolean waitFlush, Boolean waitSearcher) throws Exception {
121 ServiceLocator.getDiscoveryAdminService().optimize(waitFlush, waitSearcher);
122 }
123
124 }