1 package org.kuali.ole.docstore.engine.service.index.solr;
2
3 import org.apache.solr.common.SolrInputDocument;
4 import org.kuali.ole.docstore.common.document.License;
5 import org.kuali.ole.docstore.common.document.LicenseAttachment;
6 import org.kuali.ole.docstore.common.document.Licenses;
7 import org.kuali.ole.docstore.indexer.solr.DocumentLocalId;
8 import org.kuali.ole.docstore.model.enums.DocCategory;
9 import org.kuali.ole.docstore.model.enums.DocFormat;
10 import org.kuali.ole.docstore.model.enums.DocType;
11
12 import java.io.IOException;
13 import java.util.ArrayList;
14 import java.util.Date;
15 import java.util.List;
16
17
18
19
20
21
22
23
24 public class LicenseAttachmentIndexer extends LicenseOnixplIndexer {
25 private static LicenseAttachmentIndexer licenseAttachmentIndexer;
26
27 public static LicenseOnixplIndexer getInstance() {
28 if(licenseAttachmentIndexer == null) {
29 licenseAttachmentIndexer = new LicenseAttachmentIndexer();
30 }
31 return licenseAttachmentIndexer;
32 }
33
34 protected void buildSolrInputDocument(Object object, List<SolrInputDocument> solrInputDocuments) {
35 LicenseAttachment licenseAttachment = (LicenseAttachment) object;
36 SolrInputDocument solrInputDocument = new SolrInputDocument();
37 solrInputDocument.addField("dateEntered", new Date());
38 solrInputDocument.addField("createdBy", licenseAttachment.getCreatedBy());
39 solrInputDocument.addField(DOC_TYPE, DocType.LICENSE.getDescription());
40 solrInputDocument.addField(DOC_FORMAT, licenseAttachment.getFormat());
41 solrInputDocument.setField(DOC_CATEGORY, DocCategory.WORK.getCode());
42 solrInputDocument.setField("id", licenseAttachment.getId());
43 solrInputDocument.setField("uniqueId", licenseAttachment.getId());
44 solrInputDocument.setField("LocalId_search", DocumentLocalId.getDocumentId(licenseAttachment.getId()));
45 solrInputDocument.setField("LocalId_display", DocumentLocalId.getDocumentIdDisplay(licenseAttachment.getId()));
46 solrInputDocuments.add(solrInputDocument);
47
48 }
49
50 protected void updateRecordInSolr(Object object, List<SolrInputDocument> solrInputDocuments) {
51 LicenseAttachment licenseAttachment = (LicenseAttachment) object;
52 this.buildSolrInputDocument(object, solrInputDocuments);
53 solrInputDocuments.get(0).addField("updatedBy", licenseAttachment.getUpdatedBy());
54 solrInputDocuments.get(0).addField("dateUpdated", new Date());
55
56 }
57
58 }