1 package org.kuali.ole.docstore.engine.service.index;
2
3 import org.apache.solr.client.solrj.SolrServerException;
4 import org.kuali.ole.docstore.common.constants.DocstoreConstants;
5 import org.kuali.ole.docstore.common.document.*;
6 import org.kuali.ole.docstore.common.document.content.enums.DocCategory;
7 import org.kuali.ole.docstore.common.document.content.enums.DocFormat;
8 import org.kuali.ole.docstore.common.document.content.enums.DocType;
9 import org.kuali.ole.docstore.engine.factory.DocumentIndexerManagerFactory;
10 import org.kuali.ole.docstore.engine.service.index.solr.BibMarcIndexer;
11 import org.kuali.ole.docstore.engine.service.index.solr.DocumentIndexer;
12 import org.kuali.ole.docstore.engine.service.index.solr.HoldingsOlemlIndexer;
13 import org.kuali.ole.docstore.engine.service.index.solr.ItemOlemlIndexer;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
16
17 import java.io.IOException;
18 import java.util.List;
19
20
21
22
23
24
25
26
27 public class DocstoreIndexServiceImpl implements DocstoreIndexService, DocstoreConstants {
28
29 private static final Logger LOG = LoggerFactory.getLogger(DocstoreIndexServiceImpl.class);
30
31 @Override
32 public void createBib(Bib bib) {
33 DocumentIndexer documentIndexer = DocumentIndexerManagerFactory.getInstance().getDocumentIndexManager(bib.getCategory(), bib.getType(), bib.getFormat());
34 documentIndexer.create(bib);
35 }
36
37 @Override
38 public void createHoldings(Holdings holdings) {
39 DocumentIndexer documentIndexer = DocumentIndexerManagerFactory.getInstance().getDocumentIndexManager(holdings.getCategory(), holdings.getType(), holdings.getFormat());
40 documentIndexer.create(holdings);
41 }
42
43 @Override
44 public void createItem(Item item) {
45 DocumentIndexer documentIndexer = DocumentIndexerManagerFactory.getInstance().getDocumentIndexManager(item.getCategory(), item.getType(), item.getFormat());
46 documentIndexer.create(item);
47 }
48
49 @Override
50 public void createHoldingsTree(HoldingsTree holdingsTree) {
51
52 DocumentIndexer documentIndexer = HoldingsOlemlIndexer.getInstance();
53 documentIndexer.createTree(holdingsTree);
54
55
56
57
58
59
60 }
61
62 @Override
63 public void createBibTree(BibTree bibTree) {
64 DocumentIndexer documentIndexer = BibMarcIndexer.getInstance();
65 documentIndexer.createTree(bibTree);
66
67
68
69
70
71
72
73 }
74
75 @Override
76 public void updateBib(Bib bib) {
77 DocumentIndexer documentIndexer = DocumentIndexerManagerFactory.getInstance().getDocumentIndexManager(bib.getCategory(), bib.getType(), bib.getFormat());
78 documentIndexer.update(bib);
79 }
80
81 @Override
82 public void updateBibs(List<Bib> bibs) {
83 for (Bib bib : bibs) {
84 DocumentIndexer documentIndexer = DocumentIndexerManagerFactory.getInstance().getDocumentIndexManager(bib.getCategory(), bib.getType(), bib.getFormat());
85 documentIndexer.update(bib);
86 }
87 }
88
89 @Override
90 public void updateHoldings(Holdings holdings) {
91 DocumentIndexer documentIndexer = DocumentIndexerManagerFactory.getInstance().getDocumentIndexManager(DocCategory.WORK.getCode(), DocType.HOLDINGS.getCode(), DocFormat.OLEML.getCode());
92 documentIndexer.update(holdings);
93 }
94
95 @Override
96 public void updateItem(Item item) {
97 DocumentIndexer documentIndexer = DocumentIndexerManagerFactory.getInstance().getDocumentIndexManager(DocCategory.WORK.getCode(), DocType.ITEM.getCode(), DocFormat.OLEML.getCode());
98 documentIndexer.update(item);
99
100 }
101
102 @Override
103 public void deleteBib(String bibId) {
104 DocumentIndexer documentIndexer = BibMarcIndexer.getInstance();
105 documentIndexer.delete(bibId);
106
107 }
108
109 @Override
110 public void deleteHoldings(String holdingsId) {
111 DocumentIndexer documentIndexer = HoldingsOlemlIndexer.getInstance();
112 documentIndexer.delete(holdingsId);
113
114 }
115
116 @Override
117 public void deleteItem(String itemId) {
118 DocumentIndexer documentIndexer = ItemOlemlIndexer.getInstance();
119 documentIndexer.delete(itemId);
120
121 }
122
123 @Override
124 public void boundHoldingsWithBibs(String holdingsId, List<String> bibIds) {
125 DocumentIndexer documentIndexer = BibMarcIndexer.getInstance();
126 try {
127 documentIndexer.bind(holdingsId, bibIds);
128 } catch (SolrServerException e) {
129 LOG.info("Exception :", e);
130 } catch (IOException e) {
131 LOG.info("Exception :", e);
132 }
133 }
134
135 @Override
136 public void transferHoldings(List<String> holdingsIds, String bibId) {
137 DocumentIndexer documentIndexer = HoldingsOlemlIndexer.getInstance();
138 documentIndexer.transfer(holdingsIds, bibId);
139 }
140
141 @Override
142 public void transferItems(List<String> itemIds, String holdingsId) {
143 DocumentIndexer documentIndexer = ItemOlemlIndexer.getInstance();
144 documentIndexer.transfer(itemIds, holdingsId);
145 }
146
147 @Override
148 public void createBibTrees(BibTrees bibTrees) {
149
150 DocumentIndexer documentIndexer = BibMarcIndexer.getInstance();
151 documentIndexer.createTrees(bibTrees);
152 }
153
154 @Override
155 public void deleteBibs(List<String> bibIds) {
156 for (String id : bibIds) {
157 deleteBib(id);
158 }
159 }
160
161 @Override
162 public void createLicense(License license) {
163 DocumentIndexer documentIndexer = DocumentIndexerManagerFactory.getInstance().getDocumentIndexManager(license.getCategory(), license.getType(), license.getFormat());
164 documentIndexer.create(license);
165 }
166
167 @Override
168 public void createLicenses(Licenses licenses) {
169 DocumentIndexer documentIndexer = DocumentIndexerManagerFactory.getInstance().getDocumentIndexManager(licenses.getLicenses().get(0).getCategory(), licenses.getLicenses().get(0).getType(), licenses.getLicenses().get(0).getFormat());
170 documentIndexer.createTrees(licenses);
171 }
172
173 @Override
174 public void updateLicense(License license) {
175 DocumentIndexer documentIndexer = DocumentIndexerManagerFactory.getInstance().getDocumentIndexManager(license.getCategory(), license.getType(), license.getFormat());
176 documentIndexer.update(license);
177 }
178
179 @Override
180 public void updateLicenses(Licenses licenses) {
181 for(License license : licenses.getLicenses()) {
182 DocumentIndexer documentIndexer = DocumentIndexerManagerFactory.getInstance().getDocumentIndexManager(license.getCategory(), license.getType(), license.getFormat());
183 documentIndexer.update(license);
184 }
185 }
186
187 @Override
188 public void deleteLicense(String id) {
189 DocumentIndexer documentIndexer = DocumentIndexerManagerFactory.getInstance().getDocumentIndexManager(DocCategory.WORK.getCode(), DocType.LICENSE.getCode(), DocFormat.ONIXPL.getCode());
190 documentIndexer.delete(id);
191 }
192
193 @Override
194 public void createAnalyticsRelation(String seriesHoldingsId, List<String> itemIds) {
195 DocumentIndexer documentIndexer = BibMarcIndexer.getInstance();
196 try {
197 documentIndexer.bindAnalytics(seriesHoldingsId, itemIds, CREATE_RELATION);
198 } catch (SolrServerException e) {
199 LOG.info("Exception occurred while creating analytic relation :", e);
200 } catch (IOException e) {
201 LOG.info("Exception occurred while creating analytic relation :", e);
202 }
203 }
204
205 @Override
206 public void breakAnalyticsRelation(String seriesHoldingsId, List<String> itemIds) {
207 DocumentIndexer documentIndexer = BibMarcIndexer.getInstance();
208 try {
209 documentIndexer.bindAnalytics(seriesHoldingsId, itemIds, BREAK_RELATION);
210 } catch (SolrServerException e) {
211 LOG.info("Exception occurred while breaking analytic relation :", e);
212 } catch (IOException e) {
213 LOG.info("Exception occurred while breaking analytic relation :", e);
214 }
215 }
216
217 @Override
218 public void processBibTrees(BibTrees bibTrees) {
219 DocumentIndexer documentIndexer = BibMarcIndexer.getInstance();
220 documentIndexer.processBibTrees(bibTrees);
221 }
222
223 @Override
224 public void unbindWithOneBib(List<String> holdingsIds, String bibId) {
225 DocumentIndexer documentIndexer = BibMarcIndexer.getInstance();
226 try {
227 documentIndexer.unbindOne(holdingsIds, bibId);
228 } catch (SolrServerException e) {
229 LOG.info("Exception :", e);
230 } catch (IOException e) {
231 LOG.info("Exception :", e);
232 }
233 }
234
235 @Override
236 public void unbindWithAllBibs(List<String> holdingsIds, String bibId) {
237 DocumentIndexer documentIndexer = BibMarcIndexer.getInstance();
238 try {
239 documentIndexer.unbindAll(holdingsIds, bibId);
240 } catch (SolrServerException e) {
241 LOG.info("Exception :", e);
242 } catch (IOException e) {
243 LOG.info("Exception :", e);
244 }
245 }
246
247 }