1 package org.kuali.ole.describe.service;
2
3
4 import org.apache.commons.httpclient.HttpClient;
5 import org.apache.commons.httpclient.NameValuePair;
6 import org.apache.commons.httpclient.methods.DeleteMethod;
7 import org.apache.commons.httpclient.methods.GetMethod;
8 import org.apache.commons.io.IOUtils;
9 import org.apache.commons.lang.StringUtils;
10 import org.apache.log4j.Logger;
11 import org.apache.solr.client.solrj.SolrServerException;
12 import org.kuali.ole.BibliographicRecordHandler;
13 import org.kuali.ole.OLEConstants;
14 import org.kuali.ole.OleItemRecordHandler;
15 import org.kuali.ole.deliver.bo.OleDeliverRequestBo;
16 import org.kuali.ole.deliver.bo.OleItemSearch;
17 import org.kuali.ole.describe.keyvalue.LocationValuesBuilder;
18 import org.kuali.ole.docstore.common.client.DocstoreClientLocator;
19 import org.kuali.ole.docstore.common.document.*;
20 import org.kuali.ole.docstore.common.document.content.instance.*;
21 import org.kuali.ole.docstore.common.document.content.instance.Item;
22 import org.kuali.ole.docstore.common.document.content.instance.Items;
23 import org.kuali.ole.docstore.common.document.content.instance.xstream.HoldingOlemlRecordProcessor;
24 import org.kuali.ole.docstore.common.document.content.instance.xstream.InstanceOlemlRecordProcessor;
25 import org.kuali.ole.docstore.discovery.service.QueryService;
26 import org.kuali.ole.docstore.discovery.service.QueryServiceImpl;
27 import org.kuali.ole.docstore.model.bo.WorkBibDocument;
28 import org.kuali.ole.docstore.model.enums.DocCategory;
29 import org.kuali.ole.docstore.model.enums.DocFormat;
30 import org.kuali.ole.docstore.model.enums.DocType;
31 import org.kuali.ole.docstore.model.jaxb.config.DocumentConfigConverter;
32 import org.kuali.ole.docstore.model.xmlpojo.config.DocumentConfig;
33 import org.kuali.ole.docstore.model.xmlpojo.ingest.*;
34 import org.kuali.ole.docstore.model.xmlpojo.work.bib.marc.DataField;
35 import org.kuali.ole.docstore.model.xmlpojo.work.bib.marc.SubField;
36 import org.kuali.ole.docstore.model.xstream.ingest.RequestHandler;
37 import org.kuali.ole.docstore.model.xstream.ingest.ResponseHandler;
38 import org.kuali.ole.docstore.common.document.content.instance.xstream.ItemOlemlRecordProcessor;
39 import org.kuali.ole.ingest.pojo.ProfileAttributeBo;
40 import org.kuali.ole.pojo.ProfileAttribute;
41 import org.kuali.ole.pojo.bib.BibliographicRecord;
42 import org.kuali.ole.pojo.bib.Collection;
43 import org.kuali.ole.pojo.edi.LineItemOrder;
44 import org.kuali.ole.select.bo.OLEInstanceSearch;
45 import org.kuali.ole.sys.context.SpringContext;
46 import org.kuali.rice.core.api.config.property.ConfigContext;
47 import org.kuali.rice.krad.util.GlobalVariables;
48
49 import java.io.*;
50 import java.net.URL;
51 import java.net.URLConnection;
52 import java.net.URLEncoder;
53 import java.text.DateFormat;
54 import java.text.SimpleDateFormat;
55 import java.util.*;
56
57
58
59
60
61
62
63 public class DocstoreHelperService {
64
65 private static final String DOCSTORE_URL = "docstore.url";
66 private final String CREATE_NEW_DOCSTORE_RECORD_QUERY_STRING = "docAction=ingestContent&stringContent=";
67 private final String CHECKOUT_DOCSTORE_RECORD_QUERY_STRING = "docAction=checkOut&uuid=";
68 private final String UPDATE_EXISTING_DOCSTORE_RECORD_QUERY_STRING = "docAction=checkIn&stringContent=";
69 private final String ROLLBACK_DATA_FROM_DOCSTORE = "docAction=deleteWithLinkedDocs&requestContent=";
70 private final String TRANSFER_INSTANCES_QUERY_STRING = "docAction=transferInstances&stringContent=";
71 private final String TRANSFER_ITEMS_QUERY_STRING = "docAction=transferItems&stringContent=";
72 private static final String DOCSTORE_BASE_URL = "ole.docstore.url.base";
73 private static final String DOC_CONFIG_INFO = "/getDocumentConfigInfo";
74 private InstanceOlemlRecordProcessor instanceOlemlRecordProcessor;
75 private HoldingOlemlRecordProcessor holdingOlemlRecordProcessor;
76 private ItemOlemlRecordProcessor itemOlemlRecordProcessor;
77
78 private static final Logger LOG = Logger.getLogger(DocstoreHelperService.class);
79
80 private List<ProfileAttribute> attributes = new ArrayList<ProfileAttribute>();
81
82 private DocstoreClientLocator docstoreClientLocator;
83
84 public DocstoreClientLocator getDocstoreClientLocator() {
85 if (docstoreClientLocator == null) {
86 docstoreClientLocator = SpringContext.getBean(DocstoreClientLocator.class);
87 }
88 return docstoreClientLocator;
89 }
90
91 public InstanceOlemlRecordProcessor getInstanceOlemlRecordProcessor() {
92 if (instanceOlemlRecordProcessor == null) {
93 instanceOlemlRecordProcessor = new InstanceOlemlRecordProcessor();
94 }
95 return instanceOlemlRecordProcessor;
96 }
97
98 public HoldingOlemlRecordProcessor getHoldingOlemlRecordProcessor() {
99 if (holdingOlemlRecordProcessor == null) {
100 holdingOlemlRecordProcessor = new HoldingOlemlRecordProcessor();
101 }
102 return holdingOlemlRecordProcessor;
103 }
104
105 private ItemOlemlRecordProcessor getItemOlemlRecordProcessor() {
106 if (itemOlemlRecordProcessor == null) {
107 itemOlemlRecordProcessor = new ItemOlemlRecordProcessor();
108 }
109 return itemOlemlRecordProcessor;
110 }
111
112 public String persistToDocstoreForEditor(String content, String uuid, String format) throws Exception {
113 String responseFromDocstore = callToDocstore(null, content, uuid, format);
114 return responseFromDocstore;
115 }
116
117 public String persistToDocstoreFromUnifiedEditor(String reqContent, String uuid, String format) throws Exception {
118 String responseFromDocstore = callToDocstore(reqContent, null, uuid, format);
119 return responseFromDocstore;
120 }
121
122 private String callToDocstore(String reqContent, String content, String uuid, String format) throws Exception {
123 String docstoreURL = ConfigContext.getCurrentContextConfig().getProperty(DOCSTORE_URL);
124 String queryString = null;
125 if (null == uuid) {
126 String xmlContent = "";
127 if (reqContent != null) {
128 xmlContent = reqContent;
129 } else {
130 xmlContent = buildRequestDocXML(content, format);
131 }
132 queryString = CREATE_NEW_DOCSTORE_RECORD_QUERY_STRING + URLEncoder.encode(xmlContent, "UTF-8");
133 } else {
134 String xmlContent = buildRequestDocXML(content, uuid, format);
135 queryString = UPDATE_EXISTING_DOCSTORE_RECORD_QUERY_STRING + URLEncoder.encode(xmlContent, "UTF-8");
136 }
137
138 return postData(docstoreURL, queryString);
139 }
140
141
142 private String callToDocstoreWithAdditionalAttributes(String content, AdditionalAttributes additionalAttributes, String uuid, String format) throws Exception {
143 String docstoreURL = ConfigContext.getCurrentContextConfig().getProperty(DOCSTORE_URL);
144 String queryString = null;
145
146 if (null == uuid) {
147 String xmlContent = buildRequestDocXMLWithAdditionalAttributes(content, additionalAttributes, format);
148 queryString = CREATE_NEW_DOCSTORE_RECORD_QUERY_STRING + URLEncoder.encode(xmlContent, "UTF-8");
149 } else {
150 String xmlContent = buildRequestDocXMLWithAdditionalAttributes(content, additionalAttributes, uuid, format);
151 queryString = UPDATE_EXISTING_DOCSTORE_RECORD_QUERY_STRING + URLEncoder.encode(xmlContent, "UTF-8");
152 }
153
154 return postData(docstoreURL, queryString);
155 }
156
157
158
159 public String persistToDocstoreWithAdditionalAttributesForEditor(String content,
160 AdditionalAttributes additionalAttributes,
161 String uuid, String format) throws Exception {
162 String responseFromDocstore = callToDocstoreWithAdditionalAttributes(content, additionalAttributes, uuid,
163 format);
164 return responseFromDocstore;
165 }
166
167 public String persistNewToDocstoreForIngest(BibliographicRecord bibliographicRecord, List<ProfileAttributeBo> profileAttributes) throws Exception {
168 this.attributes = buildListOfProfileAttributes(profileAttributes);
169 BibliographicRecordHandler bibliographicRecordHandler = new BibliographicRecordHandler();
170 String bibXMLContent = bibliographicRecordHandler.generateXML(bibliographicRecord);
171 String instanceXMLContent = getInstanceXML(bibliographicRecord);
172 String requestXML = buildReuestDocXMLForIngest(bibXMLContent, instanceXMLContent);
173 String queryString = CREATE_NEW_DOCSTORE_RECORD_QUERY_STRING + URLEncoder.encode(requestXML);
174 String docstoreURL = ConfigContext.getCurrentContextConfig().getProperty(DOCSTORE_URL);
175 String responseXML = postData(docstoreURL, queryString + queryString);
176 return responseXML;
177 }
178
179 public String persistNewToDocstoreForIngest(LineItemOrder lineItemOrder, BibliographicRecord bibliographicRecord, List<ProfileAttributeBo> profileAttributes) throws Exception {
180 this.attributes = buildListOfProfileAttributes(profileAttributes);
181 BibliographicRecordHandler bibliographicRecordHandler = new BibliographicRecordHandler();
182 String bibXMLContent = bibliographicRecordHandler.generateXML(bibliographicRecord);
183 String instanceXMLContent = getInstanceXML(lineItemOrder, bibliographicRecord);
184 String requestXML = buildReuestDocXMLForIngest(bibXMLContent, instanceXMLContent);
185 String queryString = CREATE_NEW_DOCSTORE_RECORD_QUERY_STRING + URLEncoder.encode(requestXML);
186 String docstoreURL = ConfigContext.getCurrentContextConfig().getProperty(DOCSTORE_URL);
187 String responseXML = postData(docstoreURL, queryString + queryString);
188 return responseXML;
189 }
190
191 public String getDocstoreData(String uuid) throws Exception {
192 String docstoreURL = ConfigContext.getCurrentContextConfig().getProperty(DOCSTORE_URL);
193 String queryString = CHECKOUT_DOCSTORE_RECORD_QUERY_STRING + uuid;
194 String responseFromDocstore = postData(docstoreURL, queryString);
195 Response response = new ResponseHandler().toObject(responseFromDocstore);
196 String responseContent = getResponseContent(response);
197 return responseContent;
198 }
199
200 public String getDocstoreData(String docCategory, String docType, String docFormat, String uuid) throws Exception {
201 String docstoreURL = ConfigContext.getCurrentContextConfig().getProperty(DOCSTORE_URL);
202 String queryString = CHECKOUT_DOCSTORE_RECORD_QUERY_STRING + uuid + "&docCategory=" + docCategory + "&docType=" + docType + "&docFormat=" + docFormat;
203 String responseFromDocstore = postData(docstoreURL, queryString);
204 Response response = new ResponseHandler().toObject(responseFromDocstore);
205 String responseContent = getResponseContent(response);
206 return responseContent;
207 }
208
209 public ResponseDocument checkOutDocument(String docCategory, String docType, String docFormat, String uuid) throws Exception {
210 ResponseDocument responseDocument = null;
211 String docstoreURL = ConfigContext.getCurrentContextConfig().getProperty(DOCSTORE_URL);
212 String queryString = CHECKOUT_DOCSTORE_RECORD_QUERY_STRING + uuid + "&docCategory=" + docCategory + "&docType=" + docType + "&docFormat=" + docFormat;
213 String responseFromDocstore = postData(docstoreURL, queryString);
214 Response response = new ResponseHandler().toObject(responseFromDocstore);
215 responseDocument = response.getDocuments().get(0);
216 return responseDocument;
217 }
218
219 public String getResponseContent(Response response) {
220 String responseString = null;
221 if (response != null) {
222 List<ResponseDocument> responseDocumentList = response.getDocuments();
223 if (responseDocumentList.size() > 0) {
224 ResponseDocument responseDocument = responseDocumentList.get(0);
225 if(responseDocument.getStatus() != null && responseDocument.getStatus().contains("Failed")) {
226 return null;
227 }
228 Content contentObj = responseDocument.getContent();
229 if (contentObj != null) {
230 responseString = contentObj.getContent();
231 }
232 }
233 }
234 return responseString;
235 }
236
237
238 public static String postData(String target, String content) throws Exception {
239 String response = "";
240 URL url = new URL(target);
241 URLConnection conn = url.openConnection();
242 conn.setDoInput(true);
243 conn.setDoOutput(true);
244 conn.setUseCaches(false);
245 conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
246
247 Writer w = new OutputStreamWriter(conn.getOutputStream(), "UTF-8");
248 w.write(content);
249 w.close();
250 BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
251 String temp;
252 while ((temp = in.readLine()) != null) {
253 response += temp + "\n";
254 }
255 in.close();
256 return response;
257 }
258
259
260 private String buildRequestDocXML(String xmlContent, String format) {
261 return buildRequestDocXML(xmlContent, null, format);
262 }
263
264 private String buildRequestDocXMLWithAdditionalAttributes(String xmlContent, AdditionalAttributes additionalAttributes, String format) {
265 return buildRequestDocXMLWithAdditionalAttributes(xmlContent, additionalAttributes, null, format);
266 }
267
268 public String buildReuestDocXMLForIngest(String bibXML, String instanceXML) {
269 Request requestObject = new Request();
270 requestObject.setUser(GlobalVariables.getUserSession() != null ? GlobalVariables.getUserSession().getPrincipalName() : "");
271 requestObject.setOperation(OLEConstants.INGEST_OPERATION);
272 RequestDocument requestDocument = new RequestDocument();
273 requestDocument.setId("1");
274 requestDocument.setCategory(OLEConstants.WORK_CATEGORY);
275 requestDocument.setType(OLEConstants.BIB_DOC_TYPE);
276 requestDocument.setFormat(OLEConstants.MARC_FORMAT);
277 requestDocument.setContent(new Content(bibXML));
278
279 AdditionalAttributes additionalAttributes = new AdditionalAttributes();
280 DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
281 additionalAttributes.setDateEntered(String.valueOf(dateFormat.format(new Date())));
282 additionalAttributes.setLastUpdated(String.valueOf(dateFormat.format(new Date())));
283 additionalAttributes.setFastAddFlag("true");
284 additionalAttributes.setSupressFromPublic("false");
285 additionalAttributes.setAttribute("dateEntered", String.valueOf(dateFormat.format(new Date())));
286 additionalAttributes.setAttribute("lastUpdated", String.valueOf(dateFormat.format(new Date())));
287 additionalAttributes.setAttribute("fastAddFlag", "true");
288 additionalAttributes.setAttribute("supressFromPublic", "false");
289 requestDocument.setAdditionalAttributes(additionalAttributes);
290
291 RequestDocument linkedRequestDocument = new RequestDocument();
292 linkedRequestDocument.setId("2");
293 linkedRequestDocument.setCategory(OLEConstants.WORK_CATEGORY);
294 linkedRequestDocument.setType(OLEConstants.INSTANCE_DOC_TYPE);
295 linkedRequestDocument.setContent(new Content(instanceXML));
296 linkedRequestDocument.setFormat(OLEConstants.OLEML_FORMAT);
297
298 ArrayList<RequestDocument> linkedRequestDocuments = new ArrayList<RequestDocument>();
299 linkedRequestDocuments.add(linkedRequestDocument);
300
301 requestDocument.setLinkedRequestDocuments(linkedRequestDocuments);
302
303 ArrayList<RequestDocument> requestDocuments = new ArrayList<RequestDocument>();
304 requestDocuments.add(requestDocument);
305 requestObject.setRequestDocuments(requestDocuments);
306
307 RequestHandler requestHandler = new RequestHandler();
308 String xml = requestHandler.toXML(requestObject);
309 return xml;
310 }
311
312
313 private String buildRequestDocXML(String xmlContent, String uuid, String format) {
314 String INSTANCE_MARC_XML_STRING = "<instanceCollection>\n" +
315 " <instance>\n" +
316 "<instanceIdentifier></instanceIdentifier>\n" +
317 " <oleHoldings primary=\"true\">\n" +
318 " <holdingsIdentifier></holdingsIdentifier>\n" +
319 " <receiptStatus></receiptStatus>\n" +
320 " <uri></uri>\n" +
321 " <note type=\"public\"></note>\n" +
322 " <location primary=\"true\" status=\"permanent\">\n" +
323 " <locationLevel>\n" +
324 " <name></name>\n" +
325 " <level></level>\n" +
326 " <locationLevel>\n" +
327 " <name></name>\n" +
328 " <level></level>\n" +
329 " <locationLevel>\n" +
330 " <name></name>\n" +
331 " <level></level>\n" +
332 " <locationLevel>\n" +
333 " <name></name>\n" +
334 " <level></level>\n" +
335 " </locationLevel>\n" +
336 " </locationLevel>\n" +
337 " </locationLevel>\n" +
338 " </locationLevel>\n" +
339 " </location>\n" +
340 " <extension>\n" +
341 " <additionalAttributes>\n" +
342 " <createdBy></createdBy>\n" +
343 " <dateEntered></dateEntered>\n" +
344 " </additionalAttributes>\n" +
345 " </extension>\n" +
346 " <callNumber>\n" +
347 " <type></type>\n" +
348 " <prefix></prefix>\n" +
349 " <number></number>\n" +
350 " <shelvingScheme>\n" +
351 " <codeValue></codeValue>\n" +
352 " </shelvingScheme>\n" +
353 " <shelvingOrder>\n" +
354 " <codeValue></codeValue>\n" +
355 " </shelvingOrder>\n" +
356 " </callNumber>\n" +
357 " </oleHoldings>\n" +
358 " <items>\n" +
359 " <item>\n" +
360 " <staffOnlyFlag>false</staffOnlyFlag>\n" +
361 " <fastAddFlag>false</fastAddFlag>\n" +
362 " <extension reference=\"../../../oleHoldings/extension\"/>\n" +
363 " </item>\n" +
364 " </items>\n" +
365 " </instance>\n" +
366 "</instanceCollection>";
367 Request requestObject = new Request();
368 RequestDocument requestDocument = new RequestDocument();
369
370 if (null == uuid) {
371 requestDocument.setId("1");
372 RequestDocument linkedRequestDocument = new RequestDocument();
373 linkedRequestDocument.setId("2");
374 linkedRequestDocument.setCategory(OLEConstants.WORK_CATEGORY);
375 linkedRequestDocument.setType(OLEConstants.INSTANCE_DOC_TYPE);
376 linkedRequestDocument.setContent(new Content(INSTANCE_MARC_XML_STRING));
377 linkedRequestDocument.setFormat(OLEConstants.OLEML_FORMAT);
378
379 ArrayList<RequestDocument> linkedRequestDocuments = new ArrayList<RequestDocument>();
380 linkedRequestDocuments.add(linkedRequestDocument);
381
382 requestObject.setOperation(OLEConstants.INGEST_OPERATION);
383 requestObject.setUser(GlobalVariables.getUserSession() != null ? GlobalVariables.getUserSession().getPrincipalName() : "");
384 requestDocument.setLinkedRequestDocuments(linkedRequestDocuments);
385 } else {
386 requestDocument.setId(uuid);
387 requestObject.setOperation(OLEConstants.CHECK_IN_OPERATION);
388 requestObject.setUser("editor");
389 }
390 requestDocument.setCategory(OLEConstants.WORK_CATEGORY);
391 requestDocument.setType(OLEConstants.BIB_DOC_TYPE);
392
393 if (format.equalsIgnoreCase("marc")) {
394 requestDocument.setFormat(OLEConstants.MARC_FORMAT);
395 } else if (format.equalsIgnoreCase("dublinunq")) {
396 requestDocument.setFormat(OLEConstants.UNQUALIFIED_DUBLIN_FORMAT);
397 }
398
399 requestDocument.setContent(new Content(xmlContent));
400
401 if (format.equalsIgnoreCase("marc")) {
402 AdditionalAttributes additionalAttributes = new AdditionalAttributes();
403 DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
404 if (null == uuid) {
405 additionalAttributes.setDateEntered(String.valueOf(dateFormat.format(new Date())));
406 }
407 additionalAttributes.setLastUpdated(String.valueOf(dateFormat.format(new Date())));
408 additionalAttributes.setFastAddFlag("true");
409 additionalAttributes.setSupressFromPublic("false");
410 requestDocument.setAdditionalAttributes(additionalAttributes);
411 }
412
413 ArrayList<RequestDocument> requestDocuments = new ArrayList<RequestDocument>();
414 requestDocuments.add(requestDocument);
415 requestObject.setRequestDocuments(requestDocuments);
416
417 RequestHandler requestHandler = new RequestHandler();
418 String xml = requestHandler.toXML(requestObject);
419
420 if (format.equalsIgnoreCase(OLEConstants.UNQUALIFIED_DUBLIN_FORMAT)) {
421 xml = modifyXmlContent(xml);
422 }
423 return xml;
424 }
425
426 private String buildRequestDocXMLWithAdditionalAttributes(String xmlContent,
427 AdditionalAttributes additionalAttributes, String uuid,
428 String format) {
429 String user = null;
430 user = GlobalVariables.getUserSession().getPrincipalName();
431 String INSTANCE_MARC_XML_STRING = "<instanceCollection>\n" +
432 " <instance>\n" +
433 "<instanceIdentifier></instanceIdentifier>\n" +
434 " <oleHoldings primary=\"true\">\n" +
435 " <holdingsIdentifier></holdingsIdentifier>\n" +
436 " <!--Zero or more repetitions:-->\n" +
437 " <extentOfOwnership>\n" +
438 " <textualHoldings></textualHoldings>\n" +
439 " <!--Zero or more repetitions:-->\n" +
440 " <note type=\"string\"></note>\n" +
441 " <type></type>\n" +
442 " </extentOfOwnership>\n" +
443 " <receiptStatus></receiptStatus>\n" +
444 " <uri></uri>\n" +
445 " <note type=\"public\"></note>\n" +
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466 " <extension>\n" +
467 " <additionalAttributes>\n" +
468 " <createdBy>" + user + "</createdBy>\n" +
469 " <dateEntered></dateEntered>\n" +
470 " </additionalAttributes>\n" +
471 " </extension>\n" +
472 " <callNumber>\n" +
473 " <type></type>\n" +
474 " <prefix></prefix>\n" +
475 " <number></number>\n" +
476 " <shelvingScheme>\n" +
477 " <codeValue></codeValue>\n" +
478 " </shelvingScheme>\n" +
479 " <shelvingOrder>\n" +
480 " <codeValue></codeValue>\n" +
481 " <fullValue></fullValue>\n" +
482 " </shelvingOrder>\n" +
483 " </callNumber>\n" +
484 " </oleHoldings>\n" +
485 " <items>\n" +
486 " <item>\n" +
487 " <copyNumber></copyNumber>\n" +
488 " <volumeNumber></volumeNumber>\n" +
489 " <note type=\"public\"></note>" +
490 " <callNumber>\n" +
491 " <number></number>\n" +
492 " </callNumber>\n" +
493 " <staffOnlyFlag>false</staffOnlyFlag>\n" +
494 " <fastAddFlag>false</fastAddFlag>\n" +
495 " <extension reference=\"../../../oleHoldings/extension\"/>\n" +
496 " </item>\n" +
497 " </items>\n" +
498 " </instance>\n" +
499 "</instanceCollection>";
500 Request requestObject = new Request();
501 RequestDocument requestDocument = new RequestDocument();
502 if (null == uuid) {
503 requestDocument.setId("1");
504 RequestDocument linkedRequestDocument = new RequestDocument();
505 linkedRequestDocument.setId("2");
506 linkedRequestDocument.setCategory(OLEConstants.WORK_CATEGORY);
507 linkedRequestDocument.setType(OLEConstants.INSTANCE_DOC_TYPE);
508 linkedRequestDocument.setContent(new Content(INSTANCE_MARC_XML_STRING));
509 linkedRequestDocument.setFormat(OLEConstants.OLEML_FORMAT);
510
511 ArrayList<RequestDocument> linkedRequestDocuments = new ArrayList<RequestDocument>();
512 linkedRequestDocuments.add(linkedRequestDocument);
513
514 requestObject.setOperation(OLEConstants.INGEST_OPERATION);
515 requestObject.setUser(
516 GlobalVariables.getUserSession() != null ? GlobalVariables.getUserSession().getPrincipalName()
517 : "");
518 requestDocument.setLinkedRequestDocuments(linkedRequestDocuments);
519 } else {
520 requestDocument.setId(uuid);
521 requestObject.setOperation(OLEConstants.CHECK_IN_OPERATION);
522 requestObject.setUser(
523 GlobalVariables.getUserSession() != null ? GlobalVariables.getUserSession().getPrincipalName()
524 : "");
525
526 }
527 requestDocument.setCategory(OLEConstants.WORK_CATEGORY);
528 requestDocument.setType(OLEConstants.BIB_DOC_TYPE);
529
530 if (format.equalsIgnoreCase("marc")) {
531 requestDocument.setFormat(OLEConstants.MARC_FORMAT);
532 } else if (format.equalsIgnoreCase("dublinunq")) {
533 requestDocument.setFormat(OLEConstants.UNQUALIFIED_DUBLIN_FORMAT);
534 }
535
536 requestDocument.setContent(new Content(xmlContent));
537 if (additionalAttributes != null && requestDocument.getType().equalsIgnoreCase(OLEConstants.BIB_DOC_TYPE)) {
538 requestDocument.setAdditionalAttributes(additionalAttributes);
539 }
540
541 ArrayList<RequestDocument> requestDocuments = new ArrayList<RequestDocument>();
542 requestDocuments.add(requestDocument);
543 requestObject.setRequestDocuments(requestDocuments);
544
545 RequestHandler requestHandler = new RequestHandler();
546 String xml = requestHandler.toXML(requestObject);
547 if (format.equalsIgnoreCase(OLEConstants.UNQUALIFIED_DUBLIN_FORMAT)) {
548 xml = modifyXmlContent(xml);
549 }
550 return xml;
551 }
552
553 public String getInstanceXML(BibliographicRecord bibliographicRecord) {
554 InstanceOlemlRecordProcessor instanceOlemlRecordProcessor = new InstanceOlemlRecordProcessor();
555 InstanceCollection instanceCollection = new InstanceCollection();
556 Instance oleInstance = new Instance();
557 List<Item> oleItemList = new ArrayList<Item>();
558 oleItemList.add(getOleItem(bibliographicRecord));
559 if (oleInstance.getItems() == null) {
560 oleInstance.setItems(new Items());
561 }
562 oleInstance.getItems().setItem(oleItemList);
563 oleInstance.setOleHoldings(getOleHolding(bibliographicRecord));
564
565 Extension extension = new Extension();
566 AdditionalAttributes additionalAttributes = new AdditionalAttributes();
567 DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
568 additionalAttributes.setDateEntered(String.valueOf(dateFormat.format(new Date())));
569 additionalAttributes.setLastUpdated(String.valueOf(dateFormat.format(new Date())));
570 additionalAttributes.setSupressFromPublic("false");
571 additionalAttributes.setFastAddFlag("false");
572 additionalAttributes.setHarvestable("true");
573 additionalAttributes.setStatus("n");
574 additionalAttributes.setAttribute("dateEntered", additionalAttributes.getDateEntered());
575 additionalAttributes.setAttribute("lastUpdated", additionalAttributes.getLastUpdated());
576 additionalAttributes.setAttribute("fastAddFlag", additionalAttributes.getFastAddFlag());
577 additionalAttributes.setAttribute("supressFromPublic", additionalAttributes.getSupressFromPublic());
578 additionalAttributes.setAttribute("harvestable", additionalAttributes.getHarvestable());
579 additionalAttributes.setAttribute("status", additionalAttributes.getStatus());
580 extension.getContent().add(additionalAttributes);
581
582
583 oleInstance.setExtension(extension);
584 oleInstance.getOleHoldings().setPrimary(OLEConstants.TRUE);
585
586 Uri uri = new Uri();
587 uri.setValue("");
588 uri.setResolvable(null);
589 oleInstance.getOleHoldings().getUri().add(uri);
590 Note note = new Note();
591 note.setType(OLEConstants.NOTE_TYPE);
592 oleInstance.getOleHoldings().getNote().add(note);
593 CallNumber callNumber = new CallNumber();
594 ShelvingScheme shelvingScheme = new ShelvingScheme();
595 ShelvingOrder shelvingOrder = new ShelvingOrder();
596 callNumber.setType("");
597 callNumber.setPrefix("");
598 callNumber.setNumber("");
599 shelvingScheme.setCodeValue("");
600 shelvingOrder.setCodeValue("");
601 callNumber.setShelvingScheme(shelvingScheme);
602 callNumber.setShelvingOrder(shelvingOrder);
603 oleInstance.getOleHoldings().setCallNumber(callNumber);
604 List<Instance> oleInstanceList = new ArrayList<Instance>();
605 OleHoldings oleHoldings = oleInstance.getOleHoldings();
606 if (oleHoldings.getLocation() == null) {
607 LocationLevel locationLevel = new LocationLevel();
608 Location location = new Location();
609 locationLevel.setLevel("");
610 locationLevel.setName("");
611 location.setPrimary(OLEConstants.TRUE);
612 location.setStatus(OLEConstants.PERMANENT);
613 location.setLocationLevel(locationLevel);
614 oleInstance.getOleHoldings().setLocation(location);
615 }
616 oleInstanceList.add(oleInstance);
617 instanceCollection.setInstance(oleInstanceList);
618
619 String instanceXML = instanceOlemlRecordProcessor.toXML(instanceCollection);
620 return instanceXML;
621 }
622
623 public String getInstanceXML(LineItemOrder lineItemOrder, BibliographicRecord bibliographicRecord) {
624 InstanceOlemlRecordProcessor instanceOlemlRecordProcessor = new InstanceOlemlRecordProcessor();
625 InstanceCollection instanceCollection = new InstanceCollection();
626 Instance oleInstance = new Instance();
627 List<Item> oleItemList = new ArrayList<Item>();
628 oleItemList.add(getOleItem(lineItemOrder, bibliographicRecord));
629 if (oleInstance.getItems() == null) {
630 oleInstance.setItems(new Items());
631 }
632 oleInstance.getItems().setItem(oleItemList);
633 oleInstance.setOleHoldings(getOleHolding(bibliographicRecord));
634
635 Extension extension = new Extension();
636 AdditionalAttributes additionalAttributes = new AdditionalAttributes();
637 DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
638 additionalAttributes.setDateEntered(String.valueOf(dateFormat.format(new Date())));
639 additionalAttributes.setLastUpdated(String.valueOf(dateFormat.format(new Date())));
640 additionalAttributes.setSupressFromPublic("false");
641 additionalAttributes.setFastAddFlag("false");
642 additionalAttributes.setHarvestable("true");
643 additionalAttributes.setStatus("n");
644 additionalAttributes.setAttribute("dateEntered", additionalAttributes.getDateEntered());
645 additionalAttributes.setAttribute("lastUpdated", additionalAttributes.getLastUpdated());
646 additionalAttributes.setAttribute("fastAddFlag", additionalAttributes.getFastAddFlag());
647 additionalAttributes.setAttribute("supressFromPublic", additionalAttributes.getSupressFromPublic());
648 additionalAttributes.setAttribute("harvestable", additionalAttributes.getHarvestable());
649 additionalAttributes.setAttribute("status", additionalAttributes.getStatus());
650 extension.getContent().add(additionalAttributes);
651
652
653 oleInstance.setExtension(extension);
654 oleInstance.getOleHoldings().setPrimary(OLEConstants.TRUE);
655
656 Uri uri = new Uri();
657 uri.setValue("");
658 uri.setResolvable(null);
659 oleInstance.getOleHoldings().getUri().add(uri);
660 Note note = new Note();
661 note.setType(OLEConstants.NOTE_TYPE);
662 oleInstance.getOleHoldings().getNote().add(note);
663 CallNumber callNumber = new CallNumber();
664 ShelvingScheme shelvingScheme = new ShelvingScheme();
665 ShelvingOrder shelvingOrder = new ShelvingOrder();
666 callNumber.setType("");
667 callNumber.setPrefix("");
668 callNumber.setNumber("");
669 shelvingScheme.setCodeValue("");
670 shelvingOrder.setCodeValue("");
671 callNumber.setShelvingScheme(shelvingScheme);
672 callNumber.setShelvingOrder(shelvingOrder);
673 oleInstance.getOleHoldings().setCallNumber(callNumber);
674 List<Instance> oleInstanceList = new ArrayList<Instance>();
675 OleHoldings oleHoldings = oleInstance.getOleHoldings();
676 if (oleHoldings.getLocation() == null) {
677 LocationLevel locationLevel = new LocationLevel();
678 Location location = new Location();
679 locationLevel.setLevel("");
680 locationLevel.setName("");
681 location.setPrimary(OLEConstants.TRUE);
682 location.setStatus(OLEConstants.PERMANENT);
683 location.setLocationLevel(locationLevel);
684 oleInstance.getOleHoldings().setLocation(location);
685 }
686 oleInstanceList.add(oleInstance);
687 instanceCollection.setInstance(oleInstanceList);
688
689 String instanceXML = instanceOlemlRecordProcessor.toXML(instanceCollection);
690 return instanceXML;
691 }
692
693 public OleHoldings getOleHolding(BibliographicRecord bibliographicRecord) {
694
695 return null;
696 }
697
698 public Item getOleItem(BibliographicRecord bibliographicRecord) {
699 for (DataField dataField : bibliographicRecord.getDatafields()) {
700 if (dataField.getTag().equalsIgnoreCase(OLEConstants.DATA_FIELD_985)) {
701 List<SubField> subFieldList = dataField.getSubFields();
702 SubField subField = new SubField();
703 subField.setCode(OLEConstants.SUB_FIELD_A);
704 subField.setValue(OLEConstants.DEFAULT_LOCATION_LEVEL_INSTITUTION);
705 subFieldList.add(subField);
706 dataField.setSubFields(subFieldList);
707 }
708 }
709
710 return null;
711 }
712
713 public Item getOleItem(LineItemOrder lineItemOrder, BibliographicRecord bibliographicRecord) {
714 for (DataField dataField : bibliographicRecord.getDatafields()) {
715 if (dataField.getTag().equalsIgnoreCase(OLEConstants.DATA_FIELD_985)) {
716 List<SubField> subFieldList = dataField.getSubFields();
717 SubField subField = new SubField();
718 subField.setCode(OLEConstants.SUB_FIELD_A);
719 subField.setValue(OLEConstants.DEFAULT_LOCATION_LEVEL_INSTITUTION);
720 subFieldList.add(subField);
721 dataField.setSubFields(subFieldList);
722 }
723 }
724
725 return null;
726 }
727
728 private List<ProfileAttribute> buildListOfProfileAttributes(List<ProfileAttributeBo> profileAttributes) {
729 for (Iterator iterator = profileAttributes.iterator(); iterator.hasNext(); ) {
730 ProfileAttributeBo profileAttributeBo = (ProfileAttributeBo) iterator.next();
731 ProfileAttribute profileAttribute = new ProfileAttribute();
732 profileAttribute.setAgendaName(profileAttributeBo.getAgendaName());
733 profileAttribute.setAttributeName(profileAttributeBo.getAttributeName());
734 profileAttribute.setAttributeValue(profileAttributeBo.getAttributeValue());
735 profileAttribute.setSystemValue(profileAttributeBo.getSystemValue());
736 attributes.add(profileAttribute);
737 }
738 return attributes;
739 }
740
741 private String modifyXmlContent(String inputXmlContent) {
742 StringBuffer modifiedContent = new StringBuffer(inputXmlContent);
743 modifiedContent.replace(modifiedContent.indexOf("<oai_dc:dc"), modifiedContent.indexOf(">", modifiedContent.indexOf("<oai_dc:dc")),
744 "<oai_dc:dc xmlns:oai_dc=\"http://www.openarchives.org/OAI/2.0/oai_dc/\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\"");
745 return modifiedContent.toString();
746 }
747
748 public void rollbackData(String xmlForRollback) throws Exception {
749 String queryString = ROLLBACK_DATA_FROM_DOCSTORE + URLEncoder.encode(xmlForRollback, "UTF-8");
750 String docstoreURL = ConfigContext.getCurrentContextConfig().getProperty(DOCSTORE_URL);
751 postData(docstoreURL, queryString + queryString);
752 }
753
754
755 public String updateItem(BibliographicRecord bibliographicRecord, String itemUUID) {
756 String responseXML = null;
757 try {
758 Item oleItem = getOleItem(bibliographicRecord);
759 OleItemRecordHandler oleItemRecordHandler = new OleItemRecordHandler();
760
761 String itemXML = "";
762 String requestXML = buildReuestDocXMLForUpdate(itemXML, itemUUID);
763 String queryString = UPDATE_EXISTING_DOCSTORE_RECORD_QUERY_STRING + URLEncoder.encode(requestXML, "UTF-8");
764 String docstoreURL = ConfigContext.getCurrentContextConfig().getProperty(DOCSTORE_URL);
765 responseXML = postData(docstoreURL, queryString);
766 } catch (Exception e) {
767
768 LOG.error("updateItem Exception:" + e);
769 }
770 return responseXML;
771 }
772
773 public String buildReuestDocXMLForUpdate(String itemXML, String itemUUID) {
774 Request requestObject = new Request();
775 RequestDocument requestDocument = new RequestDocument();
776 requestDocument.setId(itemUUID);
777 requestDocument.setCategory(OLEConstants.WORK_CATEGORY);
778 requestDocument.setType(OLEConstants.ITEM_DOC_TYPE);
779 requestDocument.setFormat(OLEConstants.OLEML_FORMAT);
780 requestDocument.setContent(new Content(itemXML));
781
782 ArrayList<RequestDocument> requestDocuments = new ArrayList<RequestDocument>();
783 requestDocuments.add(requestDocument);
784 requestObject.setRequestDocuments(requestDocuments);
785 RequestHandler requestHandler = new RequestHandler();
786 String xml = requestHandler.toXML(requestObject);
787 return xml;
788 }
789
790
791
792
793
794
795
796
797
798
799 public String instanceRecordCallToDocstore(String content, String uuid, String format) throws Exception {
800 String docstoreURL = ConfigContext.getCurrentContextConfig().getProperty(DOCSTORE_URL);
801 String queryString = null;
802 String xmlContent = buildInstanceRequestDocXML(content, uuid, format);
803 queryString = CREATE_NEW_DOCSTORE_RECORD_QUERY_STRING + URLEncoder.encode(xmlContent, "UTF-8");
804 return postData(docstoreURL, queryString);
805 }
806
807
808
809
810
811
812
813
814
815 private String buildInstanceRequestDocXML(String xmlContent, String uuid, String format) {
816 Request requestObject = new Request();
817 RequestDocument requestDocument = new RequestDocument();
818 if (null == uuid) {
819 requestDocument.setId("1");
820 requestObject.setOperation(OLEConstants.INGEST_OPERATION);
821 } else {
822 requestDocument.setId(uuid);
823 requestObject.setOperation(OLEConstants.CHECK_IN_OPERATION);
824 }
825 requestObject.setUser(GlobalVariables.getUserSession().getPrincipalName());
826 requestDocument.setCategory(OLEConstants.WORK_CATEGORY);
827 requestDocument.setType(OLEConstants.INSTANCE_DOC_TYPE);
828 requestDocument.setFormat(OLEConstants.OLEML_FORMAT);
829
830 requestDocument.setContent(new Content(xmlContent));
831
832 ArrayList<RequestDocument> requestDocuments = new ArrayList<RequestDocument>();
833 requestDocuments.add(requestDocument);
834 requestObject.setRequestDocuments(requestDocuments);
835
836 RequestHandler requestHandler = new RequestHandler();
837 String requestXml = requestHandler.toXML(requestObject);
838 return requestXml;
839 }
840
841
842
843
844
845
846
847
848
849
850 public String updateInstanceRecord(String uuid, String docType, String xmlContent) throws Exception {
851 String docstoreURL = ConfigContext.getCurrentContextConfig().getProperty(DOCSTORE_URL);
852 Request requestObject = new Request();
853 requestObject.setUser(GlobalVariables.getUserSession() != null ? GlobalVariables.getUserSession().getPrincipalName() :
854 "admin");
855 LOG.info("requestObject.getUser()" + requestObject.getUser());
856 requestObject.setOperation(OLEConstants.CHECK_IN_OPERATION);
857 RequestDocument requestDocument = new RequestDocument();
858
859 requestDocument.setId(uuid);
860 requestDocument.setCategory(OLEConstants.WORK_CATEGORY);
861 requestDocument.setType(docType);
862 requestDocument.setFormat(OLEConstants.OLEML_FORMAT);
863 requestDocument.setContent(new Content(xmlContent));
864
865 ArrayList<RequestDocument> requestDocuments = new ArrayList<RequestDocument>();
866 requestDocuments.add(requestDocument);
867 requestObject.setRequestDocuments(requestDocuments);
868
869 RequestHandler requestHandler = new RequestHandler();
870 String xml = requestHandler.toXML(requestObject);
871
872 String queryString = UPDATE_EXISTING_DOCSTORE_RECORD_QUERY_STRING + URLEncoder.encode(xml, "UTF-8");
873
874 return postData(docstoreURL, queryString);
875 }
876
877 public String updateInstanceRecord(String uuid, String docType, String xmlContent, AdditionalAttributes additionalAttributes) throws Exception {
878 String docstoreURL = ConfigContext.getCurrentContextConfig().getProperty(DOCSTORE_URL);
879 Request requestObject = new Request();
880 requestObject.setUser(GlobalVariables.getUserSession() != null ? GlobalVariables.getUserSession().getPrincipalName() :
881 "admin");
882 LOG.info("requestObject.getUser()" + requestObject.getUser());
883 requestObject.setOperation(OLEConstants.CHECK_IN_OPERATION);
884 RequestDocument requestDocument = new RequestDocument();
885
886 requestDocument.setId(uuid);
887 requestDocument.setCategory(OLEConstants.WORK_CATEGORY);
888 requestDocument.setType(docType);
889 requestDocument.setFormat(OLEConstants.OLEML_FORMAT);
890 requestDocument.setContent(new Content(xmlContent));
891 requestDocument.setAdditionalAttributes(additionalAttributes);
892
893 ArrayList<RequestDocument> requestDocuments = new ArrayList<RequestDocument>();
894 requestDocuments.add(requestDocument);
895 requestObject.setRequestDocuments(requestDocuments);
896
897 RequestHandler requestHandler = new RequestHandler();
898 String xml = requestHandler.toXML(requestObject);
899
900 String queryString = UPDATE_EXISTING_DOCSTORE_RECORD_QUERY_STRING + URLEncoder.encode(xml, "UTF-8");
901
902 return postData(docstoreURL, queryString);
903 }
904
905
906
907
908
909
910
911
912
913 public String deleteInstanceRecord(Instance instance) throws Exception {
914 String docstoreURL = ConfigContext.getCurrentContextConfig().getProperty(DOCSTORE_URL);
915
916 String uuid = instance.getInstanceIdentifier();
917 String queryString = "docAction=delete&requestContent=" + uuid;
918 String response = postData(docstoreURL, queryString);
919 return response;
920
921 }
922
923
924
925
926
927
928
929
930 public String deleteDocstoreRecord(String uuid) throws Exception {
931 String docstoreURL = ConfigContext.getCurrentContextConfig().getProperty(DOCSTORE_URL);
932 String queryString = "docAction=delete&requestContent=" + uuid;
933 String response = postData(docstoreURL, queryString);
934 return response;
935
936 }
937
938
939
940
941
942
943
944
945
946
947 public String createItemForInstanceRecord(String instanceUuid, String docType, String xmlContent) throws Exception {
948 String docstoreURL = ConfigContext.getCurrentContextConfig().getProperty(DOCSTORE_URL);
949 Request requestObject = new Request();
950 requestObject.setUser(GlobalVariables.getUserSession() != null ? GlobalVariables.getUserSession().getPrincipalName() : "");
951 requestObject.setOperation(OLEConstants.CHECK_IN_OPERATION);
952 RequestDocument requestDocument = new RequestDocument();
953
954 requestDocument.setId(instanceUuid);
955 requestDocument.setCategory(OLEConstants.WORK_CATEGORY);
956 requestDocument.setType(OLEConstants.INSTANCE_DOC_TYPE);
957 requestDocument.setFormat(OLEConstants.OLEML_FORMAT);
958
959
960 RequestDocument linkedRequestDocument = new RequestDocument();
961 linkedRequestDocument.setId(OLEConstants.NEW_ITEM_ID);
962 linkedRequestDocument.setCategory(OLEConstants.WORK_CATEGORY);
963 linkedRequestDocument.setType(docType);
964 linkedRequestDocument.setFormat(OLEConstants.OLEML_FORMAT);
965 linkedRequestDocument.setContent(new Content(xmlContent));
966
967 List<RequestDocument> linkedRequestDocuments = new ArrayList<RequestDocument>();
968 linkedRequestDocuments.add(linkedRequestDocument);
969 requestDocument.setLinkedRequestDocuments(linkedRequestDocuments);
970
971
972 ArrayList<RequestDocument> requestDocuments = new ArrayList<RequestDocument>();
973 requestDocuments.add(requestDocument);
974 requestObject.setRequestDocuments(requestDocuments);
975
976 RequestHandler requestHandler = new RequestHandler();
977 String xml = requestHandler.toXML(requestObject);
978
979 String queryString = UPDATE_EXISTING_DOCSTORE_RECORD_QUERY_STRING + URLEncoder.encode(xml, "UTF-8");
980
981 return postData(docstoreURL, queryString);
982
983 }
984
985 public String createItemForInstanceRecord(String instanceUuid, String docType, String xmlContent, AdditionalAttributes additionalAttributes) throws Exception {
986 String docstoreURL = ConfigContext.getCurrentContextConfig().getProperty(DOCSTORE_URL);
987 Request requestObject = new Request();
988 requestObject.setUser(GlobalVariables.getUserSession() != null ? GlobalVariables.getUserSession().getPrincipalName() : "");
989 requestObject.setOperation(OLEConstants.CHECK_IN_OPERATION);
990 RequestDocument requestDocument = new RequestDocument();
991
992 requestDocument.setId(instanceUuid);
993 requestDocument.setCategory(OLEConstants.WORK_CATEGORY);
994 requestDocument.setType(OLEConstants.INSTANCE_DOC_TYPE);
995 requestDocument.setFormat(OLEConstants.OLEML_FORMAT);
996 requestDocument.setAdditionalAttributes(additionalAttributes);
997
998
999 RequestDocument linkedRequestDocument = new RequestDocument();
1000 linkedRequestDocument.setId(OLEConstants.NEW_ITEM_ID);
1001 linkedRequestDocument.setCategory(OLEConstants.WORK_CATEGORY);
1002 linkedRequestDocument.setType(docType);
1003 linkedRequestDocument.setFormat(OLEConstants.OLEML_FORMAT);
1004 linkedRequestDocument.setContent(new Content(xmlContent));
1005
1006 List<RequestDocument> linkedRequestDocuments = new ArrayList<RequestDocument>();
1007 linkedRequestDocuments.add(linkedRequestDocument);
1008 requestDocument.setLinkedRequestDocuments(linkedRequestDocuments);
1009
1010
1011 ArrayList<RequestDocument> requestDocuments = new ArrayList<RequestDocument>();
1012 requestDocuments.add(requestDocument);
1013 requestObject.setRequestDocuments(requestDocuments);
1014
1015 RequestHandler requestHandler = new RequestHandler();
1016 String xml = requestHandler.toXML(requestObject);
1017
1018 String queryString = UPDATE_EXISTING_DOCSTORE_RECORD_QUERY_STRING + URLEncoder.encode(xml, "UTF-8");
1019
1020 return postData(docstoreURL, queryString);
1021
1022 }
1023
1024 public void transferInstances(String requestXML) throws Exception {
1025 String docstoreURL = ConfigContext.getCurrentContextConfig().getProperty(DOCSTORE_URL);
1026 LOG.debug("transferInstances docstoreURL " + docstoreURL);
1027 String queryString = TRANSFER_INSTANCES_QUERY_STRING + URLEncoder.encode(requestXML, "UTF-8");
1028 postData(docstoreURL, queryString);
1029 }
1030
1031
1032 public String transferItems(String requestXML) throws Exception {
1033 String docstoreURL = ConfigContext.getCurrentContextConfig().getProperty(DOCSTORE_URL);
1034 LOG.debug("transferItems docstoreURL " + docstoreURL);
1035 String queryString = TRANSFER_ITEMS_QUERY_STRING + URLEncoder.encode(requestXML, "UTF-8");
1036 String response = postData(docstoreURL, queryString);
1037 LOG.debug("response transferItems " + response);
1038 return response;
1039 }
1040
1041
1042 public String deleteItemrecord(String uuid) throws Exception {
1043 String docstoreURL = ConfigContext.getCurrentContextConfig().getProperty(DOCSTORE_URL);
1044 String queryString = "docAction=delete&requestContent=" + uuid;
1045 String response = postData(docstoreURL, queryString);
1046 return response;
1047
1048 }
1049
1050 public WorkBibDocument getInfoForBibTree(WorkBibDocument workBibDocument) {
1051 QueryService queryService = QueryServiceImpl.getInstance();
1052
1053 try {
1054 workBibDocument = queryService.queryForBibTree(workBibDocument);
1055 } catch (Exception e) {
1056
1057 LOG.error("getInfoForBibTree Exception:" + e);
1058 }
1059 return workBibDocument;
1060
1061 }
1062
1063 public List<WorkBibDocument> getInfoForBibTree(List<WorkBibDocument> bibDocumentList) {
1064 List<WorkBibDocument> workBibDocumentList = new ArrayList<WorkBibDocument>();
1065 for (WorkBibDocument workBibDocument : bibDocumentList) {
1066 getInfoForBibTree(workBibDocument);
1067 workBibDocumentList.add(workBibDocument);
1068 }
1069
1070 return workBibDocumentList;
1071 }
1072
1073 public BibliographicRecord getBibliographicRecord(String bibUUID) throws Exception {
1074 BibliographicRecord bibliographicRecord = null;
1075 String responseDocStoreData = getDocstoreData(bibUUID);
1076
1077
1078
1079
1080 Collection bibliographicRecords = new BibliographicRecordHandler().fromXML(responseDocStoreData);
1081 List<BibliographicRecord> bibliographicRecordList = bibliographicRecords.getRecords();
1082 Iterator<BibliographicRecord> bibliographicRecordListIterator = bibliographicRecordList.iterator();
1083 if (bibliographicRecordListIterator.hasNext()) {
1084 bibliographicRecord = bibliographicRecordListIterator.next();
1085 }
1086 return bibliographicRecord;
1087 }
1088
1089 public InstanceCollection getInstanceCollection(String instanceUUID) throws Exception {
1090 String responseFromDocstore = getDocstoreData(instanceUUID);
1091 InstanceCollection instanceCollection = new InstanceOlemlRecordProcessor().fromXML(responseFromDocstore);
1092 return instanceCollection;
1093 }
1094
1095 public String updateInstanceToDocstore(InstanceCollection instanceCollection) throws Exception {
1096 String instanceXMLString = getInstanceOlemlRecordProcessor().toXML(instanceCollection);
1097 String instanceUUID = instanceCollection.getInstance().iterator().next().getInstanceIdentifier();
1098 String response = updateInstanceRecord(instanceUUID, OLEConstants.INSTANCE_DOC_TYPE, instanceXMLString);
1099 return response;
1100 }
1101
1102 public String updateOleHoldingToDocstore(OleHoldings oleHoldings) throws Exception {
1103 String oleHoldingXMLString = getHoldingOlemlRecordProcessor().toXML(oleHoldings);
1104 String oleHoldingUUID = oleHoldings.getHoldingsIdentifier();
1105 String response = updateInstanceRecord(oleHoldingUUID, OLEConstants.HOLDING_DOC_TYPE, oleHoldingXMLString);
1106 return response;
1107 }
1108
1109 public String updateOleItemToDocstore(Item item) throws Exception {
1110 String itemXMLString = getItemOlemlRecordProcessor().toXML(item);
1111 String oleItemUUID = item.getItemIdentifier();
1112 if (LOG.isInfoEnabled()) {
1113 LOG.info("oleItemUUID---------->" + oleItemUUID);
1114 }
1115 String response = updateInstanceRecord(oleItemUUID, OLEConstants.ITEM_DOC_TYPE, itemXMLString);
1116 return response;
1117 }
1118
1119 public String persistNewToDocstoreForIngest(BibliographicRecord bibliographicRecord, Item item, OleHoldings oleHoldings) {
1120
1121 BibliographicRecordHandler bibliographicRecordHandler = new BibliographicRecordHandler();
1122 InstanceOlemlRecordProcessor instanceOlemlRecordProcessor = new InstanceOlemlRecordProcessor();
1123 DocstoreHelperService docstoreHelperService = new DocstoreHelperService();
1124
1125 String responseXML = null;
1126 Items items = new Items();
1127 List<Item> itemList = new ArrayList<Item>();
1128 try {
1129
1130
1131 String bibXML = bibliographicRecordHandler.generateXML(bibliographicRecord);
1132 itemList.add(item);
1133 InstanceCollection instanceCollection = new InstanceCollection();
1134 Instance oleInstance = new Instance();
1135
1136 if (oleInstance.getItems() == null) {
1137 oleInstance.setItems(new Items());
1138 }
1139 oleInstance.getItems().setItem(itemList);
1140 oleInstance.setOleHoldings(oleHoldings);
1141
1142 List<Instance> oleInstanceList = new ArrayList<Instance>();
1143 oleInstanceList.add(oleInstance);
1144 instanceCollection.setInstance(oleInstanceList);
1145 String instanceXML = instanceOlemlRecordProcessor.toXML(instanceCollection);
1146 String requestXML = docstoreHelperService.buildReuestDocXMLForIngest(bibXML, instanceXML);
1147 if (LOG.isDebugEnabled()) {
1148 LOG.debug("Fast Add instance xml : " + instanceXML);
1149 LOG.debug("Fast Add request xml : " + requestXML);
1150 }
1151 String queryString = CREATE_NEW_DOCSTORE_RECORD_QUERY_STRING + URLEncoder.encode(requestXML);
1152 String docstoreURL = ConfigContext.getCurrentContextConfig().getProperty(DOCSTORE_URL);
1153 responseXML = docstoreHelperService.postData(docstoreURL, queryString + queryString);
1154 if (LOG.isDebugEnabled()) {
1155 LOG.debug("Fast Add response xml : " + responseXML);
1156 }
1157 } catch (Exception ex) {
1158 LOG.info("exception ---> " + ex.getStackTrace());
1159 }
1160 return responseXML;
1161 }
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171 public Item getItemPojo(String itemXml) throws Exception {
1172 LOG.debug("Inside the getItemPojo method");
1173 Item oleItem = null;
1174 try {
1175 ItemOlemlRecordProcessor itemOlemlRecordProcessor = new ItemOlemlRecordProcessor();
1176 oleItem = itemOlemlRecordProcessor.fromXML(itemXml);
1177 } catch (Exception e) {
1178 LOG.error(OLEConstants.PAR_EXP);
1179 throw new Exception(OLEConstants.PAR_EXP);
1180 }
1181 return oleItem;
1182 }
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192 public String getItemXML(String itemUUID) throws Exception {
1193 LOG.debug("Inside the getItemXML method");
1194 String itemXml = "";
1195 try {
1196 itemXml = getDocstoreData(itemUUID);
1197 LOG.info("item XML ----- > " + itemXml);
1198 } catch (Exception e) {
1199 LOG.error(OLEConstants.ITM_BARCD_NT_AVAL_DOC);
1200 throw new Exception(OLEConstants.ITM_BARCD_NT_AVAL_DOC);
1201 }
1202 return itemXml;
1203 }
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213 public OleHoldings getOleHoldings(String instanceUUID) throws Exception {
1214 LOG.info("--Inside getOleHoldings---");
1215 DocstoreHelperService docstoreHelperService = new DocstoreHelperService();
1216 String responseFromDocstore = docstoreHelperService.getDocstoreData(instanceUUID);
1217 InstanceCollection instanceCollection = new InstanceOlemlRecordProcessor().fromXML(responseFromDocstore);
1218 List<Instance> instances = instanceCollection != null ? instanceCollection.getInstance() : new ArrayList<Instance>();
1219 Instance instance = instances.size() > 0 ? instances.get(0) : null;
1220 OleHoldings oleHoldings = instance != null ? instance.getOleHoldings() : null;
1221 return oleHoldings;
1222 }
1223
1224
1225 private List<OleItemSearch> getOleItemListByItemInfo(String solrQuery, Map<String, String> searchCriteria) {
1226
1227 List<OleItemSearch> oleItemSearchList = new ArrayList<OleItemSearch>();
1228 int rowSize = 10;
1229 String bibIdentifier = null;
1230 String itemIdentfier = "";
1231 String instanceIdentifier = "";
1232 String holdingsIdentifier = "";
1233 if (searchCriteria.get("rowSize") != null)
1234 rowSize = Integer.parseInt(searchCriteria.get("rowSize"));
1235 try {
1236
1237 List<HashMap<String, Object>> documentList = QueryServiceImpl.getInstance().retriveResults("(DocType:item) AND (" + solrQuery + ")", rowSize);
1238 for (int i = 0; i < documentList.size(); i++) {
1239 OleItemSearch oleItemSearch = null;
1240 try {
1241 if (documentList.get(i).get("ItemIdentifier_display") != null) {
1242 itemIdentfier = (String) ((ArrayList) documentList.get(i).get("ItemIdentifier_display")).get(0);
1243 instanceIdentifier = (String) ((ArrayList) documentList.get(i).get("instanceIdentifier")).get(0);
1244 holdingsIdentifier = (String) ((ArrayList) documentList.get(i).get("holdingsIdentifier")).get(0);
1245 bibIdentifier = (String) ((ArrayList) documentList.get(i).get("bibIdentifier")).get(0);
1246 }
1247 String itemXml = getItemXML(itemIdentfier);
1248 Item oleItem = getItemPojo(itemXml);
1249 if (oleItem != null) {
1250 if (oleItem != null && ((oleItem.getLocation() == null || oleItem.getCallNumber() == null) || (oleItem.getCallNumber()!=null && StringUtils.isEmpty(oleItem.getCallNumber().getNumber())))) {
1251 OleHoldings oleHoldings = getOleHoldings(instanceIdentifier);
1252 oleItem.setLocation(oleHoldings.getLocation());
1253 oleItem.setCallNumber(oleHoldings.getCallNumber());
1254 }
1255 if (oleItem != null && (oleItem.getLocation() != null)) {
1256 if (oleItem != null && oleItem.getLocation().getLocationLevel() == null) {
1257 OleHoldings oleHoldings = getOleHoldings(instanceIdentifier);
1258 oleItem.setLocation(oleHoldings.getLocation());
1259 oleItem.setCallNumber(oleHoldings.getCallNumber());
1260 }
1261 }
1262 LocationValuesBuilder locationValuesBuilder = new LocationValuesBuilder();
1263
1264
1265 oleItemSearch = new OleItemSearch();
1266 oleItemSearch.setItemBarCode(oleItem.getAccessInformation() == null ? "" : oleItem.getAccessInformation().getBarcode());
1267 oleItemSearch.setCallNumber(oleItem.getCallNumber() == null ? "" : oleItem.getCallNumber().getNumber());
1268 oleItemSearch.setItemType(oleItem.getItemType() == null ? "" : oleItem.getItemType().getCodeValue());
1269 oleItemSearch.setItemUUID(oleItem.getItemIdentifier());
1270 oleItemSearch.setInstanceUUID(instanceIdentifier);
1271 oleItemSearch.setBibUUID(bibIdentifier);
1272 oleItemSearch.setCopyNumber(oleItem.getCopyNumber());
1273 oleItemSearch.setShelvingLocation(locationValuesBuilder.getShelvingLocation(oleItem.getLocation()));
1274 if (oleItem.getItemStatus() != null) {
1275 oleItemSearch.setItemStatus(oleItem.getItemStatus().getCodeValue());
1276 }
1277 oleItemSearch.setHoldingUUID(holdingsIdentifier);
1278 if (bibIdentifier != null) {
1279 Map<String, String> bibDetails = QueryServiceImpl.getInstance().getBibInformation(bibIdentifier, searchCriteria);
1280 if (bibDetails != null) {
1281 if (bibDetails.get("Title") != null)
1282 oleItemSearch.setTitle((String) bibDetails.get("Title"));
1283 if (bibDetails.get("Author") != null)
1284 oleItemSearch.setAuthor((String) bibDetails.get("Author"));
1285 if (bibDetails.get("Publisher") != null)
1286 oleItemSearch.setPublisher((String) bibDetails.get("Publisher"));
1287
1288 oleItemSearchList.add(oleItemSearch);
1289 }
1290 }
1291
1292 }
1293 } catch (Exception e) {
1294
1295 LOG.error("getOleItemListByItemInfo Exception:" + e);
1296 }
1297
1298
1299 }
1300 } catch (Exception ex) {
1301 LOG.info("Exception ------> " + ex);
1302 ex.printStackTrace();
1303 }
1304
1305 return oleItemSearchList;
1306 }
1307
1308 private List<OleItemSearch> getOleItemListByBibInfo(String solrQuery, Map<String, String> searchCriteria) {
1309
1310 int rowSize = 10;
1311 List<OleItemSearch> oleItemSearchList = new ArrayList<OleItemSearch>();
1312 if (searchCriteria.get("rowSize") != null)
1313 rowSize = Integer.parseInt(searchCriteria.get("rowSize"));
1314 try {
1315
1316 List<HashMap<String, Object>> documentList = QueryServiceImpl.getInstance().retriveResults("(DocType:bibliographic) AND (" + solrQuery + ")", rowSize);
1317 for (int i = 0; i < documentList.size(); i++) {
1318 String instanceIdentifier = null;
1319 OleItemSearch oleItemSearch = new OleItemSearch();
1320 Item itemDetails = null;
1321 try {
1322 HashMap<String, Object> itemvalues = documentList.get(i);
1323 if (itemvalues.get("Title_display") != null)
1324 oleItemSearch.setTitle((String) ((ArrayList) itemvalues.get("Title_display")).get(0));
1325 else if (itemvalues.get("Title_search") != null)
1326 oleItemSearch.setTitle((String) ((ArrayList) itemvalues.get("Title_search")).get(0));
1327 if (itemvalues.get("Author_display") != null)
1328 oleItemSearch.setAuthor((String) ((ArrayList) itemvalues.get("Author_display")).get(0));
1329 else if (itemvalues.get("Author_search") != null)
1330 oleItemSearch.setAuthor((String) ((ArrayList) itemvalues.get("Author_search")).get(0));
1331 if (itemvalues.get("Publisher_display") != null)
1332 oleItemSearch.setPublisher((String) ((ArrayList) itemvalues.get("Publisher_display")).get(0));
1333 else if (itemvalues.get("Publisher_search") != null)
1334 oleItemSearch.setPublisher((String) ((ArrayList) itemvalues.get("Publisher_search")).get(0));
1335
1336 if (itemvalues.get("uniqueId") != null)
1337 oleItemSearch.setBibUUID((String) itemvalues.get("uniqueId"));
1338 if (itemvalues.get("instanceIdentifier") != null) {
1339 instanceIdentifier = ((String) ((ArrayList) itemvalues.get("instanceIdentifier")).get(0));
1340 if (!"".equals(instanceIdentifier) && instanceIdentifier != null) {
1341 oleItemSearch.setInstanceUUID(instanceIdentifier);
1342 String query = "id:" + instanceIdentifier;
1343 List<HashMap<String, Object>> documentList1 = QueryServiceImpl.getInstance().retriveResults(query);
1344 if (documentList1.size() > 0) {
1345 HashMap<String, Object> itemIDvalues = documentList1.get(0);
1346 String itemUUID = (String) ((ArrayList) itemIDvalues.get("itemIdentifier")).get(0);
1347 String holdingUUID = (String) ((ArrayList) itemIDvalues.get("holdingsIdentifier")).get(0);
1348 oleItemSearch.setItemUUID(itemUUID);
1349 oleItemSearch.setHoldingUUID(holdingUUID);
1350 }
1351 }
1352 }
1353
1354 if (instanceIdentifier != null) {
1355 itemDetails = getItemInformation(instanceIdentifier, searchCriteria, oleItemSearch.getItemUUID());
1356 if (itemDetails != null) {
1357 LocationValuesBuilder locationValuesBuilder = new LocationValuesBuilder();
1358 oleItemSearch.setItemBarCode(itemDetails.getAccessInformation() == null ? "" : itemDetails.getAccessInformation().getBarcode());
1359 oleItemSearch.setCallNumber(itemDetails.getCallNumber() == null ? "" : itemDetails.getCallNumber().getNumber());
1360 oleItemSearch.setItemType(itemDetails.getItemType() == null ? "" : itemDetails.getItemType().getCodeValue());
1361 oleItemSearch.setCopyNumber(itemDetails.getCopyNumber());
1362 oleItemSearch.setItemStatus(itemDetails.getItemStatus().getCodeValue());
1363 if (itemDetails.getLocation() != null)
1364 oleItemSearch.setShelvingLocation(locationValuesBuilder.getShelvingLocation(itemDetails.getLocation()));
1365
1366 }
1367
1368 }
1369 } catch (Exception e) {
1370
1371 LOG.error("getOleItemListByBibInfo Exception:" + e);
1372 }
1373 if (itemDetails != null && !"".equals(oleItemSearch.getTitle()) && oleItemSearch.getTitle() != null)
1374 oleItemSearchList.add(oleItemSearch);
1375 }
1376
1377 } catch (Exception ex) {
1378
1379 LOG.error("getOleItemListByBibInfo Exception:" + ex);
1380 }
1381
1382 return oleItemSearchList;
1383 }
1384
1385 private Item getItemInformation(String instanceIdentifier, Map<String, String> searchCriteria, String itemIdentfier) throws Exception {
1386
1387 String callNumber = (String) searchCriteria.get("callNumber");
1388 String itemType = (String) searchCriteria.get("itemType");
1389 String itemBarCode = (String) searchCriteria.get("itemBarCode");
1390
1391 StringBuffer solrQuery = new StringBuffer();
1392
1393 if (callNumber != null && !callNumber.equals(""))
1394 solrQuery.append("(CallNumber_search:" + callNumber.toLowerCase() + "*) AND ");
1395 if (itemType != null && !itemType.equals(""))
1396 solrQuery.append("(ItemTypeCodeValue_search:" + itemType.toLowerCase() + ") AND ");
1397 if (itemBarCode != null && !itemBarCode.equals(""))
1398 solrQuery.append("(ItemBarcode_display:" + itemBarCode + ") AND ");
1399
1400 if (!solrQuery.toString().equals("")) {
1401 solrQuery.append("(id:" + itemIdentfier + ") AND ");
1402 String query = solrQuery.substring(0, solrQuery.lastIndexOf("AND"));
1403 List<HashMap<String, Object>> documentList = QueryServiceImpl.getInstance().retriveResults("(DocType:item) AND (" + query + ")");
1404 if (documentList.size() == 0) {
1405 return null;
1406 }
1407 }
1408 String itemXml = getItemXML(itemIdentfier);
1409 Item oleItem = getItemPojo(itemXml);
1410 if (oleItem != null && ((oleItem.getLocation() == null || oleItem.getCallNumber() == null) || (oleItem.getCallNumber()!=null && StringUtils.isEmpty(oleItem.getCallNumber().getNumber())))) {
1411 OleHoldings oleHoldings = getOleHoldings(instanceIdentifier);
1412 oleItem.setLocation(oleHoldings.getLocation());
1413 oleItem.setCallNumber(oleHoldings.getCallNumber());
1414 return oleItem;
1415 }
1416 if (oleItem != null && (oleItem.getLocation() != null)) {
1417 if (oleItem != null && oleItem.getLocation().getLocationLevel() == null) {
1418 OleHoldings oleHoldings = getOleHoldings(instanceIdentifier);
1419 oleItem.setLocation(oleHoldings.getLocation());
1420 oleItem.setCallNumber(oleHoldings.getCallNumber());
1421 return oleItem;
1422 }
1423 }
1424 return oleItem;
1425 }
1426
1427
1428
1429
1430
1431
1432
1433
1434 public boolean isItemAvailableInDocStore(OleDeliverRequestBo oleDeliverRequestBo) {
1435 LOG.info("Inside isItemAvailableInDocStore");
1436 boolean available = false;
1437 Map<String, String> itemMap = new HashMap<String, String>();
1438 LocationValuesBuilder locationValuesBuilder = new LocationValuesBuilder();
1439 try {
1440 Map<String, String> itemUUIDMap = QueryServiceImpl.getInstance().getItemDetails(oleDeliverRequestBo.getItemId(), null);
1441 String itemUUID = itemUUIDMap.get(OLEConstants.ITEM_UUID);
1442 oleDeliverRequestBo.setItemUuid(itemUUID);
1443
1444 itemMap.put(OLEConstants.ITEM_UUID, oleDeliverRequestBo.getItemUuid());
1445 List<OleItemSearch> itemSearchList = getOleItemSearchList(itemMap);
1446 if (itemSearchList != null && itemSearchList.size() > 0) {
1447 oleDeliverRequestBo.setTitle(itemSearchList.get(0).getTitle());
1448 oleDeliverRequestBo.setAuthor(itemSearchList.get(0).getAuthor());
1449 oleDeliverRequestBo.setCallNumber(itemSearchList.get(0).getCallNumber());
1450 oleDeliverRequestBo.setItemType(itemSearchList.get(0).getItemType());
1451 }
1452 String itemXml = getItemXML(oleDeliverRequestBo.getItemUuid());
1453 Item oleItem = getItemPojo(itemXml);
1454 oleDeliverRequestBo.setOleItem(oleItem);
1455 oleDeliverRequestBo.setCopyNumber(oleItem.getCopyNumber());
1456 oleDeliverRequestBo.setItemStatus(oleItem.getItemStatus().getCodeValue());
1457 locationValuesBuilder.getLocation(oleItem, oleDeliverRequestBo, (String) itemUUIDMap.get(OLEConstants.INSTANCE_UUID));
1458 available = true;
1459 } catch (Exception e) {
1460 LOG.error(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.INVAL_LOC) + e);
1461 }
1462
1463
1464 return available;
1465 }
1466
1467
1468 public List<OleItemSearch> getOleItemSearchList(Map<String, String> searchCriteria) {
1469
1470 List<OleItemSearch> oleItemSearchList = new ArrayList<OleItemSearch>();
1471 StringBuffer query = new StringBuffer("");
1472 String title = ((String) searchCriteria.get("title"));
1473 String author = ((String) searchCriteria.get("author"));
1474 String publisher = ((String) searchCriteria.get("publisher"));
1475 String callNumber = ((String) searchCriteria.get("callNumber"));
1476 String itemType = ((String) searchCriteria.get("itemType"));
1477 String itemBarCode = (String) searchCriteria.get("itemBarCode");
1478 String itemUuid = (String) searchCriteria.get("itemUuid");
1479
1480
1481 if (title != null && !title.equals(""))
1482 query.append("((Title_search:" + title.toLowerCase() + ")OR(Title_search:" + title.toLowerCase() + "*)) AND ");
1483 if (author != null && !author.equals(""))
1484 query.append("((Author_search:" + author.toLowerCase() + ")OR(Author_search:" + author.toLowerCase() + "*)) AND ");
1485 if (publisher != null && !publisher.equals(""))
1486 query.append("((Publisher_search:" + publisher.toLowerCase() + ")OR(Publisher_search:" + publisher.toLowerCase() + "*)) AND");
1487
1488 if (!query.toString().equals("")) {
1489 query = new StringBuffer(query.substring(0, query.lastIndexOf("AND")));
1490 oleItemSearchList = getOleItemListByBibInfo(query.toString(), searchCriteria);
1491 return oleItemSearchList;
1492 }
1493
1494
1495 if (itemBarCode != null && !itemBarCode.equals(""))
1496 query.append("(ItemBarcode_display:" + itemBarCode + ") AND ");
1497 if (callNumber != null && !callNumber.equals(""))
1498 query.append("((CallNumber_search:" + callNumber.toLowerCase() + ")OR(CallNumber_search:" + callNumber.toLowerCase() + "*)) AND ");
1499 if (itemType != null && !itemType.equals(""))
1500 query.append("(ItemTypeCodeValue_search:" + itemType.toLowerCase() + ") AND ");
1501 if (itemUuid != null && !itemUuid.equals(""))
1502 query.append("(id:" + itemUuid + ") AND ");
1503
1504 if (!query.toString().equals("")) {
1505 query = new StringBuffer(query.substring(0, query.lastIndexOf("AND")));
1506 oleItemSearchList = getOleItemListByItemInfo(query.toString(), searchCriteria);
1507 return oleItemSearchList;
1508 }
1509
1510 if (query.toString().equals("")) {
1511 query.append("*:*");
1512 oleItemSearchList = getOleItemListByBibInfo(query.toString(), searchCriteria);
1513 }
1514 return oleItemSearchList;
1515 }
1516
1517 public DocumentConfig getDocumentConfigObj() {
1518 String docstoreURL = ConfigContext.getCurrentContextConfig().getProperty(DOCSTORE_BASE_URL);
1519 DocumentConfigConverter documentConverter = new DocumentConfigConverter();
1520 DocumentConfig documentConfig = null;
1521 try {
1522 URL url = new URL(docstoreURL + DOC_CONFIG_INFO);
1523 InputStream in = new BufferedInputStream(url.openStream());
1524 BufferedReader br = new BufferedReader(new InputStreamReader(in));
1525 String line;
1526 StringBuilder sb = new StringBuilder();
1527 while ((line = br.readLine()) != null) {
1528 sb.append(line);
1529 }
1530 String docXml = sb.toString();
1531 documentConfig = documentConverter.unmarshal(docXml);
1532 } catch (Exception e) {
1533 LOG.error(e);
1534 }
1535
1536 return documentConfig;
1537 }
1538
1539
1540
1541
1542
1543
1544
1545 public boolean checkItemStatus(List<String> uuids, List<String> fieldValueList) throws SolrServerException {
1546 for (String uuid : uuids) {
1547 boolean isNotValidItem = QueryServiceImpl.getInstance()
1548 .verifyFieldValue(uuid, "ItemStatus_display", fieldValueList);
1549 if (isNotValidItem) {
1550 return true;
1551 }
1552 }
1553 return false;
1554 }
1555
1556
1557
1558
1559
1560
1561
1562 public boolean checkItemStatusForInstances(List<String> instanceIds, List<String> fieldValueList) throws SolrServerException {
1563
1564 List<String> itemIds = QueryServiceImpl.getInstance().getItemIdsForInstanceIds(instanceIds);
1565
1566 return checkItemStatus(itemIds, fieldValueList);
1567 }
1568
1569
1570
1571 public List<OLEInstanceSearch> getOleInstanceSearchList(Map<String, String> searchCriteria) {
1572
1573 List<OLEInstanceSearch> oleInstanceSearchList = new ArrayList<OLEInstanceSearch>();
1574 StringBuffer query = new StringBuffer("");
1575 String title = ((String) searchCriteria.get("title"));
1576 String author = ((String) searchCriteria.get("author"));
1577 String publisher = ((String) searchCriteria.get("publisher"));
1578 String instanceId = ((String) searchCriteria.get("instanceIdentifier"));
1579
1580 if (title != null && !title.equals(""))
1581 query.append("((Title_search:" + title.toLowerCase() + ")OR(Title_search:" + title.toLowerCase() + "*)) AND ");
1582 if (author != null && !author.equals(""))
1583 query.append("((Author_search:" + author.toLowerCase() + ")OR(Author_search:" + author.toLowerCase() + "*)) AND ");
1584 if (publisher != null && !publisher.equals(""))
1585 query.append("((Publisher_search:" + publisher.toLowerCase() + ")OR(Publisher_search:" + publisher.toLowerCase() + "*)) AND");
1586 if (instanceId != null && !instanceId.equals(""))
1587 query.append("((instanceIdentifier:" + instanceId + ")OR(instanceIdentifier:" + instanceId + "*)) AND");
1588
1589 if (!query.toString().equals("")) {
1590 query = new StringBuffer(query.substring(0, query.lastIndexOf("AND")));
1591 oleInstanceSearchList = getOleInstanceListByBibInfo(query.toString(), searchCriteria);
1592 return oleInstanceSearchList;
1593 }
1594 return oleInstanceSearchList;
1595 }
1596
1597
1598 private List<OLEInstanceSearch> getOleInstanceListByBibInfo(String solrQuery, Map<String, String> searchCriteria) {
1599
1600 int rowSize = 10;
1601 List<OLEInstanceSearch> oleInstanceSearchList = new ArrayList<OLEInstanceSearch>();
1602 if (searchCriteria.get("rowSize") != null)
1603 rowSize = Integer.parseInt(searchCriteria.get("rowSize"));
1604 try {
1605 List<HashMap<String, Object>> documentList = QueryServiceImpl.getInstance().retriveResults("(DocType:bibliographic) AND " + solrQuery + "", rowSize);
1606
1607 for (int i = 0; i < documentList.size(); i++) {
1608 String instanceIdentifier = null;
1609 String bibIdentifier = null;
1610
1611 OLEInstanceSearch oleInstanceSearch = new OLEInstanceSearch();
1612 try {
1613 HashMap<String, Object> itemvalues = documentList.get(i);
1614 if (itemvalues.get("Title_display") != null)
1615 oleInstanceSearch.setTitle((String) ((ArrayList) itemvalues.get("Title_display")).get(0));
1616 else if (itemvalues.get("Title_search") != null)
1617 oleInstanceSearch.setTitle((String) ((ArrayList) itemvalues.get("Title_search")).get(0));
1618 if (itemvalues.get("Author_display") != null)
1619 oleInstanceSearch.setAuthor((String) ((ArrayList) itemvalues.get("Author_display")).get(0));
1620 else if (itemvalues.get("Author_search") != null)
1621 oleInstanceSearch.setAuthor((String) ((ArrayList) itemvalues.get("Author_search")).get(0));
1622 if (itemvalues.get("Publisher_display") != null)
1623 oleInstanceSearch.setPublisher((String) ((ArrayList) itemvalues.get("Publisher_display")).get(0));
1624 else if (itemvalues.get("Publisher_search") != null)
1625 oleInstanceSearch.setPublisher((String) ((ArrayList) itemvalues.get("Publisher_search")).get(0));
1626 if (itemvalues.get("LocalId_display") != null) {
1627 oleInstanceSearch.setLocalId((String) itemvalues.get("LocalId_display"));
1628 }
1629 if (itemvalues.get("ISSN_display") != null) {
1630 oleInstanceSearch.setIssn((String) itemvalues.get("ISSN_display"));
1631 }
1632 if (itemvalues.get("instanceIdentifier") != null) {
1633 ArrayList<String> list = ((ArrayList) itemvalues.get("instanceIdentifier"));
1634 oleInstanceSearch.setInstanceIdList(list);
1635 }
1636 if (itemvalues.get("id") != null) {
1637 bibIdentifier = (String) itemvalues.get("id");
1638 }
1639 oleInstanceSearch.setBibId(bibIdentifier);
1640 } catch (Exception e) {
1641
1642 LOG.error("getOleInstanceListByBibInfo Exception:" + e);
1643 }
1644 oleInstanceSearchList.add(oleInstanceSearch);
1645
1646 }
1647
1648 } catch (Exception ex) {
1649 LOG.info("Exception ------> " + ex);
1650 LOG.error("getOleInstanceListByBibInfo Exception:" + ex);
1651 }
1652 return oleInstanceSearchList;
1653 }
1654
1655
1656 public void getInstanceLocation(OLEInstanceSearch instanceSearch) {
1657
1658
1659 String query = "id:" + instanceSearch.getInstanceId();
1660 List<HashMap<String, Object>> documentList1 = QueryServiceImpl.getInstance().retriveResults(query);
1661 HashMap<String, Object> itemIDvalues = documentList1.get(0);
1662 String holdingUUID = itemIDvalues != null && itemIDvalues.get("holdingsIdentifier") != null ? (String) ((ArrayList) itemIDvalues.get("holdingsIdentifier")).get(0) : null;
1663 String location = "";
1664 String callNumber = "";
1665 String copyNumber="";
1666
1667 if (holdingUUID != null) {
1668 String queryForLocation = "id:" + holdingUUID;
1669 List<HashMap<String, Object>> documentList = QueryServiceImpl.getInstance().retriveResults(queryForLocation);
1670 HashMap<String, Object> itemlocvalues = documentList != null && documentList.size() > 0 ? documentList.get(0) : null;
1671 Object locationValue = itemlocvalues.get("Location_display");
1672 if(locationValue!=null){
1673 if (locationValue instanceof String) {
1674 location= itemlocvalues.get("Location_display").toString();
1675 } else if (locationValue instanceof List) {
1676 location= (String)((ArrayList) itemlocvalues.get("Location_display")).get(0);
1677 }
1678 }
1679 instanceSearch.setLocation(location);
1680 Object callNumberValue = itemlocvalues.get("CallNumber_display");
1681 if(callNumberValue!=null){
1682 if (callNumberValue instanceof String) {
1683 callNumber= itemlocvalues.get("CallNumber_display").toString();
1684 } else if (callNumberValue instanceof List) {
1685 callNumber= (String)((ArrayList) itemlocvalues.get("CallNumber_display")).get(0);
1686 }
1687 }
1688 instanceSearch.setCallNumber(callNumber);
1689
1690 Object value = itemlocvalues.get("CopyNumber_display");
1691 if(value!=null){
1692 if (value instanceof String) {
1693 copyNumber= itemlocvalues.get("CopyNumber_display").toString();
1694 } else if (value instanceof List) {
1695 copyNumber= (String)((ArrayList) itemlocvalues.get("CopyNumber_display")).get(0);
1696 }
1697 }
1698 instanceSearch.setCopyNumber(copyNumber);
1699 }
1700
1701
1702 }
1703
1704 public String getContentFromDocStore(String uuid) throws IOException {
1705 String docStoreResponse = null;
1706 String restfulUrl = ConfigContext.getCurrentContextConfig().getProperty("docstore.restful.url");
1707 restfulUrl = restfulUrl.concat("/") + uuid;
1708 LOG.info("restful url-->" + restfulUrl);
1709 HttpClient client = new HttpClient();
1710 GetMethod getMethod = new GetMethod(restfulUrl);
1711 client.executeMethod(getMethod);
1712 InputStream inputStream = getMethod.getResponseBodyAsStream();
1713 docStoreResponse = IOUtils.toString(inputStream);
1714 return docStoreResponse;
1715 }
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815 public String buildRequestIdsForDelete(List bibIdsList) {
1816 StringBuffer ids = new StringBuffer("");
1817 if (bibIdsList != null && bibIdsList.size() > 0) {
1818 int i = 0;
1819 for (; i < bibIdsList.size() - 1; i++) {
1820 ids.append(bibIdsList.get(i) + ",");
1821 }
1822 ids.append(bibIdsList.get(i));
1823
1824 }
1825 return ids.toString();
1826 }
1827
1828 public Response performRestFulOperation(String docCategory, String docType, String docFormat, String ids) throws Exception {
1829
1830 String restfulUrl = ConfigContext.getCurrentContextConfig().getProperty("docstore.restful.url");
1831 restfulUrl = restfulUrl.concat("/") + ids;
1832 HttpClient httpClient = new HttpClient();
1833 DeleteMethod deleteMethod = new DeleteMethod(restfulUrl);
1834 NameValuePair nvp1 = new NameValuePair("identifierType", "UUID");
1835 NameValuePair nvp2 = new NameValuePair("operation", "delete");
1836
1837 NameValuePair category = new NameValuePair("docCategory", docCategory);
1838 NameValuePair type = new NameValuePair("docType", docType);
1839 NameValuePair format = new NameValuePair("docFormat", docFormat);
1840 deleteMethod.setQueryString(new NameValuePair[]{nvp1, nvp2, category, type, format});
1841 int statusCode = httpClient.executeMethod(deleteMethod);
1842 LOG.info("statusCode-->" + statusCode);
1843 InputStream inputStream = deleteMethod.getResponseBodyAsStream();
1844 String responseXML = IOUtils.toString(inputStream, "UTF-8");
1845 LOG.info("Response-->" + responseXML);
1846 return new ResponseHandler().toObject(responseXML);
1847 }
1848
1849
1850 public RequestDocument buildRequestDocument(String bibXML, String uuid) {
1851 RequestDocument requestDocument = new RequestDocument();
1852 if (StringUtils.isNotEmpty(uuid)) {
1853 requestDocument.setId(uuid);
1854 requestDocument.setUuid(uuid);
1855 } else {
1856 requestDocument.setId("1");
1857
1858 }
1859 requestDocument.setCategory(OLEConstants.WORK_CATEGORY);
1860 requestDocument.setType(OLEConstants.BIB_DOC_TYPE);
1861 requestDocument.setFormat(OLEConstants.MARC_FORMAT);
1862 requestDocument.setContent(new Content(bibXML));
1863
1864 AdditionalAttributes additionalAttributes = new AdditionalAttributes();
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874 requestDocument.setAdditionalAttributes(additionalAttributes);
1875
1876 return requestDocument;
1877 }
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902 public Item getPO(String itemXml) throws Exception {
1903
1904 return getItemPojo(itemXml);
1905 }
1906
1907 }