1 package org.kuali.ole.docstore.model.converter;
2
3 import org.kuali.ole.docstore.discovery.solr.work.bib.WorkBibCommonFields;
4 import org.kuali.ole.docstore.discovery.solr.work.bib.marc.WorkBibMarcDocBuilder;
5 import org.kuali.ole.docstore.model.bo.WorkBibDocument;
6 import org.kuali.ole.docstore.model.xmlpojo.work.bib.marc.WorkBibMarcRecord;
7 import org.kuali.ole.docstore.model.xmlpojo.work.bib.marc.WorkBibMarcRecords;
8 import org.slf4j.Logger;
9 import org.slf4j.LoggerFactory;
10
11 import java.util.ArrayList;
12 import java.util.List;
13
14
15
16
17
18
19
20
21 public class WorkBibDocConverter
22 implements WorkBibCommonFields {
23
24 private static final Logger LOG = LoggerFactory.getLogger(WorkBibDocConverter.class);
25
26 public WorkBibDocument convert(WorkBibMarcRecord marcRecord) {
27 WorkBibDocument workBibDocument = new WorkBibDocument();
28 WorkBibMarcDocBuilder workBibMarcDocBuilder = new WorkBibMarcDocBuilder();
29
30 String field = AUTHOR_DISPLAY;
31 Object fieldValue = workBibMarcDocBuilder.buildFieldValue(field, marcRecord);
32 if (fieldValue instanceof List) {
33 List<String> fieldValueList = (List<String>) fieldValue;
34 workBibDocument.setAuthors(fieldValueList);
35 } else if (fieldValue instanceof String) {
36 String fieldVal = (String) fieldValue;
37 workBibDocument.setAuthor(fieldVal);
38 }
39
40 field = TITLE_DISPLAY;
41 fieldValue = workBibMarcDocBuilder.buildFieldValue(field, marcRecord);
42 if (fieldValue instanceof List) {
43 List<String> fieldValueList = (List<String>) fieldValue;
44 workBibDocument.setTitles(fieldValueList);
45 } else if (fieldValue instanceof String) {
46 String fieldVal = (String) fieldValue;
47 workBibDocument.setTitle(fieldVal);
48 }
49
50 field = PUBLICATIONDATE_DISPLAY;
51 fieldValue = workBibMarcDocBuilder.buildFieldValue(field, marcRecord);
52 if (fieldValue instanceof List) {
53 List<String> fieldValueList = (List<String>) fieldValue;
54 workBibDocument.setPublicationDates(fieldValueList);
55 } else if (fieldValue instanceof String) {
56 String fieldVal = (String) fieldValue;
57 workBibDocument.setPublicationDate(fieldVal);
58 }
59
60 field = PUBLISHER_DISPLAY;
61 fieldValue = workBibMarcDocBuilder.buildFieldValue(field, marcRecord);
62 if (fieldValue instanceof List) {
63 List<String> fieldValueList = (List<String>) fieldValue;
64 workBibDocument.setPublishers(fieldValueList);
65 } else if (fieldValue instanceof String) {
66 String fieldVal = (String) fieldValue;
67 workBibDocument.setPublisher(fieldVal);
68 }
69
70 field = EDITION_DISPLAY;
71 fieldValue = workBibMarcDocBuilder.buildFieldValue(field, marcRecord);
72 if (fieldValue instanceof List) {
73 List<String> fieldValueList = (List<String>) fieldValue;
74 workBibDocument.setEditions(fieldValueList);
75 } else if (fieldValue instanceof String) {
76 String fieldVal = (String) fieldValue;
77 workBibDocument.setEdition(fieldVal);
78 }
79
80 return workBibDocument;
81 }
82
83 public List<WorkBibDocument> convert(WorkBibMarcRecords marcRecordList) {
84 List<WorkBibDocument> workBibDocumentList = new ArrayList<WorkBibDocument>();
85 for (WorkBibMarcRecord marcRecord : marcRecordList.getRecords()) {
86 workBibDocumentList.add(convert(marcRecord));
87 }
88 return workBibDocumentList;
89 }
90
91
92 }