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