1 package org.kuali.ole.docstore.discovery.service;
2
3 import org.kuali.ole.docstore.discovery.bo.OleDiscoveryMarcExportProfile;
4 import org.kuali.ole.docstore.discovery.bo.OleDiscoveryMarcMappingField;
5 import org.kuali.ole.docstore.model.xmlpojo.ingest.AdditionalAttributes;
6 import org.kuali.ole.docstore.model.xmlpojo.work.bib.marc.DataField;
7 import org.kuali.ole.docstore.model.xmlpojo.work.bib.marc.SubField;
8 import org.kuali.ole.docstore.model.xmlpojo.work.instance.oleml.Instance;
9 import org.kuali.ole.docstore.model.xmlpojo.work.instance.oleml.InstanceCollection;
10 import org.kuali.ole.docstore.model.xmlpojo.work.instance.oleml.Item;
11 import org.kuali.ole.docstore.model.xmlpojo.work.instance.oleml.Items;
12
13 import java.util.ArrayList;
14 import java.util.List;
15 import java.util.logging.Logger;
16
17
18
19
20
21
22
23
24
25 public class OleInstanceToMarcConvertor {
26
27 private static final Logger LOG = Logger.getLogger(String.valueOf(OleInstanceToMarcConvertor.class));
28
29 public List<DataField> generateDataField(InstanceCollection instanceCollection,OleDiscoveryMarcExportProfile oleDiscoveryMarcExportProfile){
30 List<Instance> instanceList = new ArrayList<Instance>();
31 List<DataField> dataFieldList = new ArrayList<DataField>();
32 if(instanceCollection!=null){
33 DataField dataField;
34 Instance instance;
35 List<SubField> SubFieldList;
36 for(int i=0;i<instanceCollection.getInstance().size();i++){
37 instance = instanceCollection.getInstance().get(i);
38 Items items = (Items)instance.getItems();
39 for(int j=0;j<items.getItem().size();j++){
40 dataField = new DataField();
41 dataField.setTag(oleDiscoveryMarcExportProfile.getDataField());
42 dataField.setSubFields(generateSubFields(oleDiscoveryMarcExportProfile,instance,items.getItem().get(j)));
43 dataFieldList.add(dataField);
44 }
45 }
46 }
47 return dataFieldList;
48 }
49
50 private List<SubField> generateSubFields(OleDiscoveryMarcExportProfile oleDiscoveryMarcExportProfile,Instance instance,Item item){
51 List<SubField> subFieldList = new ArrayList<SubField>();
52 List<OleDiscoveryMarcMappingField> oleDiscoveryMarcMappingFieldList = oleDiscoveryMarcExportProfile.getOleDiscoveryMarcMappingFields();
53
54 for(OleDiscoveryMarcMappingField mappingField : oleDiscoveryMarcMappingFieldList) {
55 if(mappingField.getItemField().equalsIgnoreCase("Call Number")){
56 subFieldList.add(generateMarcCallNumber(instance,mappingField.getMarcField()));
57 }
58 if(mappingField.getItemField().equalsIgnoreCase("Class Scheme")) {
59 subFieldList.add(generateMarcCallSchema(instance, mappingField.getMarcField()));
60 }
61 if(mappingField.getItemField().equalsIgnoreCase("Copy Number")) {
62 subFieldList.add(generateMarcCopyNumber(item,mappingField.getMarcField()));
63 }
64 if(mappingField.getItemField().equalsIgnoreCase("Item Id")) {
65 subFieldList.add(generateMarcItemNumber(item,mappingField.getMarcField()));
66 }
67 if(mappingField.getItemField().equalsIgnoreCase("Type")) {
68 subFieldList.add(generateMarcItemType(item,mappingField.getMarcField()));
69 }
70 if(mappingField.getItemField().equalsIgnoreCase("Date Created")) {
71 subFieldList.add(generateMarcDateCreated(instance,mappingField.getMarcField()));
72 }
73 if(mappingField.getItemField().equalsIgnoreCase("Current Location")) {
74 subFieldList.add(generateCurrentLocation(item,mappingField.getMarcField()));
75 }
76 if(mappingField.getItemField().equalsIgnoreCase("Home Location")) {
77 subFieldList.add(generateHomeLocation(instance,mappingField.getMarcField()));
78 }
79 if(mappingField.getItemField().equalsIgnoreCase("Library")) {
80 subFieldList.add(generateLibraryLocation(instance,mappingField.getMarcField()));
81 }
82 }
83
84 return subFieldList;
85 }
86
87 private SubField generateMarcCallNumber(Instance instance,String code){
88 SubField subField=new SubField();
89 subField.setCode(code);
90 subField.setValue("");
91 if(instance!=null && instance.getOleHoldings()!=null && instance.getOleHoldings().getCallNumber()!=null && instance.getOleHoldings().getCallNumber().getNumber()!=null){
92 subField.setValue(instance.getOleHoldings().getCallNumber().getNumber());
93 }
94 return subField;
95 }
96
97 private SubField generateMarcCallSchema(Instance instance,String code) {
98 SubField subField = new SubField();
99 subField.setCode(code);
100 subField.setValue("");
101 if(instance != null && instance.getOleHoldings() != null && instance.getOleHoldings().getCallNumber() !=null && instance.getOleHoldings().getCallNumber().getType() !=null){
102 subField.setValue(instance.getOleHoldings().getCallNumber().getType());
103 }
104 return subField;
105 }
106
107 private SubField generateMarcCopyNumber(Item item,String code) {
108 SubField subField = new SubField();
109 subField.setCode(code);
110 subField.setValue("");
111 if(item!=null && item.getCopyNumber()!=null){
112 subField.setValue(item.getCopyNumber());
113 }
114 return subField;
115 }
116 private SubField generateMarcEnumeration(Item item,String code) {
117 SubField subField = new SubField();
118 subField.setCode(code);
119 subField.setValue("");
120 if(item!=null && item.getEnumeration()!=null) {
121 subField.setValue(item.getEnumeration());
122 }
123 return subField;
124 }
125 private SubField generateMarcItemNumber(Item item,String code) {
126 SubField subField = new SubField();
127 subField.setCode(code);
128 subField.setValue("");
129 if(item!=null && item.getAccessInformation()!=null && item.getAccessInformation().getBarcode()!=null){
130 subField.setValue(item.getAccessInformation().getBarcode());
131 }
132 return subField;
133 }
134
135 private SubField generateMarcItemType(Item item,String code) {
136 SubField subField = new SubField();
137 subField.setCode(code);
138 subField.setValue("");
139 if(item != null && item.getItemType() != null) {
140 subField.setValue(item.getItemType().getCodeValue());
141 }
142 return subField;
143 }
144
145
146 private SubField generateMarcDateCreated(Instance instance,String code) {
147 SubField subField = new SubField();
148 subField.setCode(code);
149 subField.setValue("");
150 try{
151 if(instance!=null && instance.getExtension().getContent()!=null){
152 List<Object> additionalAttributes =(List<Object>)instance.getExtension().getContent();
153 if(additionalAttributes.size() >0) {
154 AdditionalAttributes additionalAttributes1 = (AdditionalAttributes)additionalAttributes.get(0);
155 subField.setValue(additionalAttributes1.getDateEntered());
156 }
157 }
158 }catch (Exception e){
159 LOG.info("Date Created value is not available");
160 }
161 return subField;
162 }
163
164 private SubField generateCurrentLocation(Item item,String code) {
165 SubField subField = new SubField();
166 subField.setCode(code);
167 subField.setValue("");
168 try{
169 if(item != null && item.getLocation().getLocationLevel().getName() != null) {
170 if(!item.getLocation().getLocationLevel().equals("") && item.getLocation().getLocationLevel() != null) {
171 if(item.getLocation().getLocationLevel().getName() .equals("Shelving Location")) {
172 subField.setValue(item.getLocation().getLocationLevel().getName());
173 }
174 }
175 }
176 } catch(Exception e){
177 LOG.info("Current Location is not available");
178 }
179 return subField;
180 }
181
182 private SubField generateHomeLocation(Instance instance,String code) {
183 SubField subField = new SubField();
184 subField.setCode(code);
185 subField.setValue("");
186 try{
187 if(instance != null ) {
188 if(!instance.getOleHoldings().getLocation().equals("") && instance.getOleHoldings().getLocation().getLocationLevel() != null) {
189 if(instance.getOleHoldings().getLocation().getLocationLevel().getName().equals("Collection")) {
190 subField.setValue(instance.getOleHoldings().getLocation().getLocationLevel().getName());
191 }
192 }
193 }
194 }catch(Exception e){
195 LOG.info("Home Location is not available");
196 }
197 return subField;
198 }
199
200
201 private SubField generateLibraryLocation(Instance instance,String code) {
202 SubField subField = new SubField();
203 subField.setCode(code);
204 subField.setValue("");
205 try{
206 if(instance != null ) {
207 if(!instance.getOleHoldings().getLocation().equals("") && instance.getOleHoldings().getLocation().getLocationLevel() != null) {
208 if(instance.getOleHoldings().getLocation().getLocationLevel().getName().equals("Library")) {
209 subField.setValue(instance.getOleHoldings().getLocation().getLocationLevel().getName());
210 }
211 }
212 } }catch(Exception e){
213 LOG.info("Library Location is not available");
214 }
215 return subField;
216 }
217
218 }