1 package org.kuali.ole.docstore.engine.service;
2
3 import org.apache.commons.lang.StringUtils;
4 import org.kuali.ole.DocumentUniqueIDPrefix;
5 import org.kuali.ole.docstore.common.document.*;
6 import org.kuali.ole.docstore.common.document.HoldingsTree;
7 import org.kuali.ole.docstore.common.document.Item;
8 import org.kuali.ole.docstore.common.document.content.instance.*;
9 import org.kuali.ole.docstore.common.document.content.instance.xstream.HoldingOlemlRecordProcessor;
10 import org.kuali.ole.docstore.common.document.content.instance.xstream.ItemOlemlRecordProcessor;
11 import org.kuali.ole.docstore.common.exception.*;
12 import org.kuali.ole.docstore.common.search.*;
13 import org.kuali.ole.docstore.common.service.DocstoreService;
14 import org.kuali.ole.docstore.engine.service.index.DocstoreIndexService;
15 import org.kuali.ole.docstore.engine.service.index.DocstoreIndexServiceImpl;
16 import org.kuali.ole.docstore.engine.service.search.DocstoreSearchService;
17 import org.kuali.ole.docstore.engine.service.search.DocstoreSolrSearchService;
18 import org.kuali.ole.docstore.engine.service.storage.DocstoreRDBMSStorageService;
19 import org.kuali.ole.docstore.engine.service.storage.DocstoreStorageService;
20 import org.kuali.ole.docstore.model.enums.DocCategory;
21 import org.kuali.ole.docstore.model.enums.DocFormat;
22 import org.kuali.ole.docstore.model.enums.DocType;
23 import org.kuali.rice.coreservice.api.CoreServiceApiServiceLocator;
24 import org.kuali.rice.coreservice.api.parameter.Parameter;
25 import org.kuali.rice.coreservice.api.parameter.ParameterKey;
26 import org.kuali.rice.coreservice.impl.parameter.ParameterServiceImpl;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30 import java.util.ArrayList;
31 import java.util.HashMap;
32 import java.util.List;
33 import java.util.Map;
34
35
36
37
38
39
40
41
42 public class DocstoreServiceImpl implements DocstoreService {
43 private static final Logger LOG = LoggerFactory.getLogger(DocstoreServiceImpl.class);
44 private DocstoreStorageService docstoreStorageService = null;
45 private DocstoreSearchService docstoreSearchService = null;
46 private DocstoreIndexService docstoreIndexService = null;
47 protected ParameterServiceImpl parameterService = new ParameterServiceImpl();
48
49 public String getParameter() {
50 ParameterKey parameterKey = ParameterKey.create(OLE, OLE_DESC, DESCRIBE, PROCESS_SOLR_IND);
51 Parameter parameter = CoreServiceApiServiceLocator.getParameterRepositoryService().getParameter(parameterKey);
52 return parameter != null ? parameter.getValue() : null;
53 }
54
55 @Override
56 public void createBib(Bib bib) {
57 try {
58 getDocstoreStorageService().createBib(bib);
59 } catch (Exception e) {
60 LOG.error("Exception occurred while creating Bib", e);
61 throw e;
62 }
63 try {
64 getDocstoreIndexService().createBib(bib);
65 } catch (Exception e) {
66 LOG.error("Exception occurred while indexing created Bib", e);
67 docstoreStorageService.rollback();
68 throw e;
69 }
70 }
71
72 @Override
73 public void createHoldings(Holdings holdings) {
74 try {
75 getDocstoreStorageService().createHoldings(holdings);
76 } catch (Exception e) {
77 LOG.error("Exception occurred while creating Holdings or EHoldings", e);
78 throw e;
79 }
80 try {
81 getDocstoreIndexService().createHoldings(holdings);
82 } catch (Exception e) {
83 LOG.error("Exception occurred while indexing created Holdings or EHoldings", e);
84 docstoreStorageService.rollback();
85 throw e;
86 }
87 }
88
89 @Override
90 public void createItem(Item item) {
91 try {
92 getDocstoreStorageService().createItem(item);
93 } catch (Exception e) {
94 LOG.error("Exception occurred while creating item", e);
95 throw e;
96 }
97 try {
98 getDocstoreIndexService().createItem(item);
99 } catch (Exception e) {
100 LOG.error("Exception occurred while indexing created item", e);
101 docstoreStorageService.rollback();
102 throw e;
103 }
104 }
105
106 @Override
107 public void createHoldingsTree(HoldingsTree holdingsTree) {
108 try {
109 getDocstoreStorageService().createHoldingsTree(holdingsTree);
110 } catch (Exception e) {
111 LOG.error("Exception occurred while creating Holdings tree", e);
112 throw e;
113 }
114 try {
115 getDocstoreIndexService().createHoldingsTree(holdingsTree);
116 } catch (Exception e) {
117 LOG.error("Exception occurred while indexing created Holdings tree", e);
118 docstoreStorageService.rollback();
119 throw e;
120 }
121 }
122
123 @Override
124 public void createBibTree(BibTree bibTree) {
125 try {
126 getDocstoreStorageService().createBibTree(bibTree);
127 } catch (Exception e) {
128 LOG.error("Exception occurred while creating Bib tree", e);
129 throw e;
130 }
131 try {
132 getDocstoreIndexService().createBibTree(bibTree);
133 } catch (Exception e) {
134 LOG.error("Exception occurred while indexing created Bib tree", e);
135 docstoreStorageService.rollback();
136 throw e;
137 }
138
139
140 }
141
142 @Override
143 public Bib retrieveBib(String bibId) {
144 Bib bib = getDocstoreStorageService().retrieveBib(bibId);
145 return bib;
146 }
147
148 @Override
149 public List<Bib> retrieveBibs(List<String> bibIds) {
150 List<Bib> bibs = getDocstoreStorageService().retrieveBibs(bibIds);
151 return bibs;
152 }
153
154 @Override
155 public List<Item> retrieveItems(List<String> itemIds) {
156 List<Item> items = getDocstoreStorageService().retrieveItems(itemIds);
157 return items;
158 }
159
160 @Override
161 public HashMap<String, Item> retrieveItemMap(List<String> itemIds) {
162 HashMap<String, Item> items = getDocstoreStorageService().retrieveItemMap(itemIds);
163 return items;
164 }
165
166 @Override
167 public Holdings retrieveHoldings(String holdingsId) {
168 Holdings holdings = getDocstoreStorageService().retrieveHoldings(holdingsId);
169
170
171
172
173 holdings.setId(holdingsId);
174 holdings.setCategory(DocCategory.WORK.getCode());
175 holdings.setType(DocType.HOLDINGS.getCode());
176 holdings.setFormat(DocFormat.OLEML.getCode());
177 return holdings;
178 }
179
180 @Override
181 public Item retrieveItem(String itemId) {
182 Item item = getDocstoreStorageService().retrieveItem(itemId);
183 item.setId(itemId);
184 item.setCategory(DocCategory.WORK.getCode());
185 item.setType(DocType.ITEM.getCode());
186 item.setFormat(DocFormat.OLEML.getCode());
187 return item;
188 }
189
190 @Override
191 public HoldingsTree retrieveHoldingsTree(String holdingsId) {
192 HoldingsTree holdingsTree = getDocstoreStorageService().retrieveHoldingsTree(holdingsId);
193 return holdingsTree;
194 }
195
196 @Override
197 public BibTree retrieveBibTree(String bibId) {
198 BibTree bibTree = getDocstoreStorageService().retrieveBibTree(bibId);
199 return bibTree;
200 }
201
202 @Override
203 public BibTrees retrieveBibTrees(List<String> bibIds) {
204 BibTrees bibTrees = new BibTrees();
205 bibTrees.getBibTrees().addAll(getDocstoreStorageService().retrieveBibTrees(bibIds));
206 return bibTrees;
207 }
208
209 @Override
210 public void updateBib(Bib bib) {
211 try {
212 getDocstoreStorageService().updateBib(bib);
213 } catch (Exception e) {
214 LOG.error("Exception occurred while updating Bib ", e);
215 throw e;
216 }
217 try {
218 getDocstoreIndexService().updateBib(bib);
219 } catch (Exception e) {
220 LOG.error("Exception occurred while indexing updated Bib ", e);
221 docstoreStorageService.rollback();
222 throw e;
223 }
224 }
225
226 @Override
227 public void updateBibs(List<Bib> bibs) {
228 try {
229 getDocstoreStorageService().updateBibs(bibs);
230 } catch (Exception e) {
231 LOG.error("Exception occurred while updating list of Bib ", e);
232 throw e;
233 }
234 try {
235 getDocstoreIndexService().updateBibs(bibs);
236 } catch (Exception e) {
237 LOG.error("Exception occurred while indexing updated list of Bib ", e);
238 docstoreStorageService.rollback();
239 throw e;
240 }
241 }
242
243 @Override
244 public void updateHoldings(Holdings holdings) {
245 try {
246 getDocstoreStorageService().updateHoldings(holdings);
247 } catch (Exception e) {
248 LOG.error("Exception occurred while updating Holdings ", e);
249 throw e;
250 }
251 try {
252 getDocstoreIndexService().updateHoldings(holdings);
253 } catch (Exception e) {
254 LOG.error("Exception occurred while indexing updated Holdings ", e);
255 docstoreStorageService.rollback();
256 throw e;
257 }
258 }
259
260 @Override
261 public void updateItem(Item item) {
262 try {
263 getDocstoreStorageService().updateItem(item);
264 } catch (Exception e) {
265 LOG.error("Exception occurred while updating item ", e);
266 throw e;
267 }
268 try {
269 getDocstoreIndexService().updateItem(item);
270 } catch (Exception e) {
271 LOG.error("Exception occurred while indexing updated item ", e);
272 docstoreStorageService.rollback();
273 throw e;
274 }
275 }
276
277 @Override
278 public void deleteBib(String bibId) {
279 if (!DocumentUniqueIDPrefix.hasPrefix(bibId)) {
280 bibId = DocumentUniqueIDPrefix.getPrefixedId(DocumentUniqueIDPrefix.PREFIX_WORK_BIB_MARC, bibId);
281 }
282 try {
283 getDocstoreStorageService().deleteBib(bibId);
284 } catch (Exception e) {
285 LOG.error("Exception occurred while deleting Bib ", e);
286 throw e;
287 }
288 try {
289 getDocstoreIndexService().deleteBib(bibId);
290 } catch (Exception e) {
291 LOG.error("Exception occurred while indexing deleted Bib ", e);
292 docstoreStorageService.rollback();
293 throw e;
294 }
295 }
296
297 @Override
298 public void deleteHoldings(String holdingsId) {
299 if (!DocumentUniqueIDPrefix.hasPrefix(holdingsId)) {
300 holdingsId = DocumentUniqueIDPrefix.getPrefixedId(DocumentUniqueIDPrefix.PREFIX_WORK_HOLDINGS_OLEML, holdingsId);
301 }
302 try {
303 getDocstoreStorageService().deleteHoldings(holdingsId);
304 } catch (Exception e) {
305 LOG.error("Exception occurred while deleting Holdings ", e);
306 throw e;
307 }
308 try {
309 getDocstoreIndexService().deleteHoldings(holdingsId);
310 } catch (Exception e) {
311 LOG.error("Exception occurred while indexing deleted Holdings ", e);
312 docstoreStorageService.rollback();
313 throw e;
314 }
315 }
316
317 @Override
318 public void deleteItem(String itemId) {
319 if (!DocumentUniqueIDPrefix.hasPrefix(itemId)) {
320 itemId = DocumentUniqueIDPrefix.getPrefixedId(DocumentUniqueIDPrefix.PREFIX_WORK_ITEM_OLEML, itemId);
321 }
322 try {
323 getDocstoreStorageService().deleteItem(itemId);
324 } catch (Exception e) {
325 LOG.error("Exception occurred while deleting item ", e);
326 throw e;
327 }
328 try {
329 getDocstoreIndexService().deleteItem(itemId);
330 } catch (Exception e) {
331 LOG.error("Exception occurred while indexing deleted item ", e);
332 docstoreStorageService.rollback();
333 throw e;
334 }
335 }
336
337 @Override
338 public SearchResponse search(SearchParams searchParams) {
339 SearchResponse searchResponse = null;
340 try {
341 DocstoreSearchService searchService = getDocstoreSearchService();
342 searchResponse = searchService.search(searchParams);
343 } catch (Exception e) {
344 LOG.error("Exception occurred in Search Response service ", e);
345 throw e;
346 }
347 return searchResponse;
348 }
349
350 public void setResultFieldsForHoldings(Holdings holdings, List<SearchResultField> searchResultFields) {
351 OleHoldings oleHoldings = new HoldingOlemlRecordProcessor().fromXML(holdings.getContent());
352 try {
353 for (SearchResultField searchResultField : searchResultFields) {
354 if (searchResultField.getDocType().equalsIgnoreCase("Holdings")) {
355 if (searchResultField.getFieldName().equalsIgnoreCase(Holdings.CALL_NUMBER)) {
356 holdings.setCallNumber(oleHoldings.getCallNumber().getNumber());
357 } else if (searchResultField.getFieldName().equalsIgnoreCase(Holdings.CALLNUMBER_PREFIX)) {
358 holdings.setCallNumberPrefix(oleHoldings.getCallNumber().getPrefix());
359 } else if (searchResultField.getFieldName().equalsIgnoreCase(Holdings.CALLNUMBER_TYPE)) {
360 holdings.setCallNumberType(oleHoldings.getCallNumber().getType());
361 } else if (searchResultField.getFieldName().equalsIgnoreCase(Holdings.COPY_NUMBER)) {
362 holdings.setCopyNumber(oleHoldings.getCopyNumber());
363 } else if (searchResultField.getFieldName().equalsIgnoreCase(Holdings.LOCATION_NAME)) {
364 holdings.setLocationName(oleHoldings.getLocation().getLocationLevel().getName());
365
366
367
368
369
370
371
372
373 }
374 }
375 }
376 } catch (Exception e) {
377 LOG.error("Exception occurred in setting the result fields for Holdings ", e);
378 throw e;
379 }
380 }
381
382 public void setResultFieldsForItem(Item itemDoc, List<SearchResultField> searchResultFields) {
383 org.kuali.ole.docstore.common.document.content.instance.Item item = new ItemOlemlRecordProcessor().fromXML(itemDoc.getContent());
384 for (SearchResultField searchResultField : searchResultFields) {
385 if (searchResultField.getDocType().equalsIgnoreCase("Item")) {
386 if (searchResultField.getFieldName().equalsIgnoreCase(itemDoc.ITEM_STATUS)) {
387 itemDoc.setItemStatus(item.getItemStatus().getCodeValue());
388 } else if (searchResultField.getFieldName().equalsIgnoreCase(itemDoc.CALL_NUMBER)) {
389 itemDoc.setCallNumber(item.getCallNumber().getNumber());
390 } else if (searchResultField.getFieldName().equalsIgnoreCase(itemDoc.CALL_NUMBER_TYPE)) {
391 itemDoc.setCallNumber(item.getCallNumber().getShelvingScheme().getCodeValue());
392 } else if (searchResultField.getFieldName().equalsIgnoreCase(itemDoc.CALL_NUMBER_PREFIX)) {
393 itemDoc.setCallNumberPrefix(item.getCallNumber().getPrefix());
394 } else if (searchResultField.getFieldName().equalsIgnoreCase(itemDoc.LOCATION)) {
395 itemDoc.setLocation(item.getLocation().toString());
396 } else if (searchResultField.getFieldName().equalsIgnoreCase(itemDoc.SHELVING_ORDER)) {
397 itemDoc.setShelvingOrder(item.getCallNumber().getShelvingOrder().getCodeValue());
398 } else if (searchResultField.getFieldName().equalsIgnoreCase(itemDoc.ITEM_BARCODE)) {
399 itemDoc.setBarcode(item.getAccessInformation().getBarcode());
400 } else if (searchResultField.getFieldName().equalsIgnoreCase(itemDoc.COPY_NUMBER)) {
401 itemDoc.setCopyNumber(item.getCopyNumber());
402 } else if (searchResultField.getFieldName().equalsIgnoreCase(itemDoc.ENUMERATION)) {
403 itemDoc.setEnumeration(item.getEnumeration());
404 } else if (searchResultField.getFieldName().equalsIgnoreCase(itemDoc.CHRONOLOGY)) {
405 itemDoc.setChronology(item.getChronology());
406 } else if (searchResultField.getFieldName().equalsIgnoreCase(itemDoc.ITEM_TYPE)) {
407 itemDoc.setItemType(item.getItemType().getCodeValue());
408 }
409 }
410 }
411 }
412
413 @Override
414 public void setResultFieldsForBib(Bib bib, List<SearchResultField> searchResultFields) {
415 for (SearchResultField searchResultField : searchResultFields) {
416 if (searchResultField.getDocType().equalsIgnoreCase(DocType.BIB.getCode())) {
417 if (searchResultField.getFieldName().equalsIgnoreCase("Title")) {
418 bib.setTitle(searchResultField.getFieldValue());
419 }
420 if (searchResultField.getFieldName().equalsIgnoreCase("Format")) {
421 bib.setFormat(searchResultField.getFieldValue());
422 }
423 if (searchResultField.getFieldName().equalsIgnoreCase("Id")) {
424 bib.setId(searchResultField.getFieldValue());
425 }
426 if (searchResultField.getFieldName().equalsIgnoreCase("LocalId")) {
427 bib.setLocalId(searchResultField.getFieldValue());
428 }
429 if (searchResultField.getFieldName().equalsIgnoreCase("Author")) {
430 bib.setAuthor(searchResultField.getFieldValue());
431 }
432 if (searchResultField.getFieldName().equalsIgnoreCase("PublicationDate")) {
433 bib.setPublicationDate(searchResultField.getFieldValue());
434 }
435 }
436 }
437 }
438
439 @Override
440 public void createLicense(License license) {
441 try {
442 getDocstoreStorageService().createLicense(license);
443 } catch (Exception e) {
444 LOG.error("Exception occurred while creating license for docstore ", e);
445 throw e;
446 }
447 try {
448 getDocstoreIndexService().createLicense(license);
449 } catch (Exception e) {
450 LOG.error("Exception occurred while indexing created license for docstore ", e);
451 docstoreStorageService.rollback();
452 throw e;
453 }
454 }
455
456 @Override
457 public Bib findBib(Map<String, String> map) {
458 String id = null;
459 try {
460 id = getDocstoreSearchService().findBib(map);
461 if (id != null) {
462 return retrieveBib(id);
463 }
464 } catch (Exception e) {
465 LOG.error("Exception occurred while retrieving a bib for the id:" + id, e);
466 throw e;
467 }
468 return null;
469 }
470
471 @Override
472 public BibTree findBibTree(Map<String, String> map) {
473 String id = null;
474 try {
475 id = getDocstoreSearchService().findBib(map);
476 if (id != null) {
477 return retrieveBibTree(id);
478 }
479 } catch (Exception e) {
480 LOG.error("Exception occurred while retrieving bib tree for the id:" + id, e);
481 throw e;
482 }
483 return null;
484 }
485
486 @Override
487 public Holdings findHoldings(Map<String, String> map) {
488 String id = null;
489 try {
490 id = getDocstoreSearchService().findBib(map);
491 if (id != null) {
492 return retrieveHoldings(id);
493 }
494 } catch (Exception e) {
495 LOG.error("Exception occurred while retrieving Holdings for the id:" + id, e);
496 throw e;
497 }
498 return null;
499 }
500
501 @Override
502 public HoldingsTree findHoldingsTree(Map<String, String> map) {
503 String id = null;
504 try {
505 id = getDocstoreSearchService().findBib(map);
506 if (id != null) {
507 return retrieveHoldingsTree(id);
508 }
509 } catch (Exception e) {
510 LOG.error("Exception occurred while retrieving Holdings tree for the id:" + id, e);
511 throw e;
512 }
513 return null;
514 }
515
516 @Override
517 public Item findItem(Map<String, String> map) {
518 String id = null;
519 try {
520 id = getDocstoreSearchService().findBib(map);
521 if (id != null) {
522 return retrieveItem(id);
523 }
524 } catch (Exception e) {
525 LOG.error("Exception occurred while retrieving item for the id:" + id, e);
526 throw e;
527 }
528 return null;
529 }
530
531 @Override
532 public void boundHoldingsWithBibs(String holdingsId, List<String> bibIds) {
533 try {
534 getDocstoreStorageService().boundHoldingsWithBibs(holdingsId, bibIds);
535 } catch (Exception e) {
536 LOG.error("Exception occurred in bound holdings with bibs ", e);
537 throw e;
538 }
539 try {
540 getDocstoreIndexService().boundHoldingsWithBibs(holdingsId, bibIds);
541 } catch (Exception e) {
542 docstoreStorageService.rollback();
543 LOG.error("Exception occurred while indexing the bounded holdings with bibs ", e);
544 throw e;
545 }
546
547 }
548
549 @Override
550 public void transferHoldings(List<String> holdingsIds, String bibId) {
551
552
553
554
555 try {
556 getDocstoreStorageService().transferHoldings(holdingsIds, bibId);
557 } catch (Exception e) {
558 LOG.error("Exception occurred while transferring Holdings ", e);
559 throw e;
560 }
561 try {
562 getDocstoreIndexService().transferHoldings(holdingsIds, bibId);
563 } catch (Exception e) {
564 LOG.error("Exception occurred while indexing a transferred Holdings ", e);
565 docstoreStorageService.rollback();
566 throw e;
567 }
568 }
569
570 @Override
571 public void transferItems(List<String> itemIds, String holdingsId) {
572 try {
573 getDocstoreStorageService().transferItems(itemIds, holdingsId);
574 } catch (Exception e) {
575 LOG.error("Exception occurred while transferring items ", e);
576 throw e;
577 }
578 try {
579 getDocstoreIndexService().transferItems(itemIds, holdingsId);
580 } catch (Exception e) {
581 LOG.error("Exception occurred while indexing a transferred items ", e);
582 docstoreStorageService.rollback();
583 throw e;
584 }
585 }
586
587 @Override
588 public void createBibTrees(BibTrees bibTrees) {
589 try {
590 getDocstoreStorageService().createBibTrees(bibTrees);
591 } catch (Exception e) {
592 LOG.error("Exception occurred while creating bib trees ", e);
593 }
594 try {
595 getDocstoreIndexService().createBibTrees(bibTrees);
596 } catch (Exception e) {
597 LOG.error("Exception occurred while indexing created bib trees ", e);
598 docstoreStorageService.rollback();
599 throw new DocstoreIndexException();
600 }
601 }
602
603 @Override
604 public void deleteBibs(List<String> bibIds) {
605 try {
606 getDocstoreStorageService().deleteBibs(bibIds);
607 } catch (Exception e) {
608 LOG.error("Exception occurred while deleting bib records ", e);
609 throw e;
610 }
611 try {
612 getDocstoreIndexService().deleteBibs(bibIds);
613 } catch (Exception e) {
614 LOG.error("Exception occurred while indexing bib records after deletion", e);
615 docstoreStorageService.rollback();
616 throw e;
617 }
618 }
619
620 @Override
621 public SearchResponse browseItems(BrowseParams browseParams) {
622 try {
623 SearchResponse searchResponse = getDocstoreSearchService().search(browseParams);
624
625
626
627
628
629
630
631
632
633 return searchResponse;
634
635 } catch (Exception e) {
636 LOG.error("Exception occurred getting the search response for browse items ", e);
637 throw e;
638 }
639
640 }
641
642 @Override
643 public SearchResponse browseHoldings(BrowseParams browseParams) {
644 try {
645 SearchResponse searchResponse = getDocstoreSearchService().search(browseParams);
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664 return searchResponse;
665 } catch (Exception e) {
666 LOG.error("Exception occurred getting the search response for browse Holdings ", e);
667 throw e;
668 }
669 }
670
671 private DocstoreStorageService getDocstoreStorageService() {
672 if (docstoreStorageService == null) {
673 docstoreStorageService = new DocstoreRDBMSStorageService();
674 }
675 return docstoreStorageService;
676 }
677
678 private DocstoreSearchService getDocstoreSearchService() {
679 if (docstoreSearchService == null) {
680 docstoreSearchService = new DocstoreSolrSearchService();
681 }
682
683 return docstoreSearchService;
684 }
685
686 private DocstoreIndexService getDocstoreIndexService() {
687 if (docstoreIndexService == null) {
688 docstoreIndexService = new DocstoreIndexServiceImpl();
689 }
690 return docstoreIndexService;
691 }
692
693 @Override
694 public void createLicenses(Licenses licenses) {
695 try {
696 getDocstoreStorageService().createLicenses(licenses);
697 } catch (Exception e) {
698 LOG.error("Exception occurred while creating license for docstore ", e);
699 throw e;
700 }
701 try {
702 getDocstoreIndexService().createLicenses(licenses);
703 } catch (Exception e) {
704 LOG.error("Exception occurred while doing indexing the created license ", e);
705 docstoreStorageService.rollback();
706 throw e;
707 }
708 }
709
710 @Override
711 public License retrieveLicense(String licenseId) {
712 License license = null;
713 try {
714 license = (License) getDocstoreStorageService().retrieveLicense(licenseId);
715 } catch (Exception e) {
716 LOG.error("Exception occurred while retrieving a created license , id : " + licenseId, e);
717 throw e;
718 }
719 return license;
720 }
721
722 @Override
723 public Licenses retrieveLicenses(List<String> licenseIds) {
724 Licenses licenses = null;
725 try {
726 licenses = getDocstoreStorageService().retrieveLicenses(licenseIds);
727 } catch (Exception e) {
728 LOG.error("Exception occurred while retrieving a created licenses , ids : " + licenseIds, e);
729 throw e;
730 }
731 return licenses;
732 }
733
734 @Override
735 public void updateLicense(License license) {
736 try {
737 getDocstoreStorageService().updateLicense(license);
738 } catch (Exception e) {
739 LOG.error("Exception occurred while updating license ", e);
740 throw e;
741 }
742 try {
743 getDocstoreIndexService().updateLicense(license);
744 } catch (Exception e) {
745 LOG.error("Exception occurred while indexing updated license ", e);
746 docstoreStorageService.rollback();
747 throw e;
748 }
749 }
750
751 @Override
752 public void updateLicenses(Licenses licenses) {
753 try {
754 getDocstoreStorageService().updateLicenses(licenses);
755 } catch (Exception e) {
756 LOG.error("Exception occurred while updating licenses ", e);
757 throw e;
758 }
759 try {
760 getDocstoreIndexService().updateLicenses(licenses);
761 } catch (Exception e) {
762 LOG.error("Exception occurred while indexing updated licenses ", e);
763 docstoreStorageService.rollback();
764 throw e;
765 }
766 }
767
768 @Override
769 public void deleteLicense(String licenseId) {
770
771
772
773 try {
774 getDocstoreStorageService().deleteLicense(licenseId);
775 } catch (Exception e) {
776 LOG.error("Exception occurred while deleting license for id : " + licenseId, e);
777 throw e;
778 }
779 try {
780 getDocstoreIndexService().deleteLicense(licenseId);
781 } catch (Exception e) {
782 LOG.error("Exception occurred while indexing the license for id : " + licenseId, e);
783 docstoreStorageService.rollback();
784 throw e;
785 }
786 }
787
788 @Override
789 public void createAnalyticsRelation(String seriesHoldingsId, List<String> itemIds) {
790 try {
791 getDocstoreStorageService().createAnalyticsRelation(seriesHoldingsId, itemIds);
792 } catch (Exception e) {
793 LOG.error("Exception occurred while creating analytical relation ", e);
794 throw e;
795 }
796
797 try {
798 getDocstoreIndexService().createAnalyticsRelation(seriesHoldingsId, itemIds);
799 } catch (Exception e) {
800 docstoreStorageService.rollback();
801 LOG.error("Exception occurred while indexing created analytical relation ", e);
802 throw e;
803 }
804 }
805
806 @Override
807 public void bulkUpdateHoldings(Holdings holdings, List<String> holdingIds, String canUpdateStaffOnlyFlag) {
808 HoldingOlemlRecordProcessor holdingOlemlRecordProcessor = new HoldingOlemlRecordProcessor();
809 OleHoldings oleHoldings = holdingOlemlRecordProcessor.fromXML(holdings.getContent());
810 try {
811 for (String holdingId : holdingIds) {
812 Holdings existingHoldings = (Holdings) getDocstoreStorageService().retrieveHoldings(holdingId);
813 if (existingHoldings != null) {
814 OleHoldings existingOleHoldings = holdingOlemlRecordProcessor.fromXML(existingHoldings.getContent());
815 if (oleHoldings != null && oleHoldings.getLocation() != null &&
816 oleHoldings.getLocation().getLocationLevel() != null &&
817 oleHoldings.getLocation().getLocationLevel().getName() != null &&
818 !oleHoldings.getLocation().getLocationLevel().getName().isEmpty()) {
819
820
821
822 existingOleHoldings.setLocation(oleHoldings.getLocation());
823
824
825 }
826 if (canUpdateStaffOnlyFlag.equalsIgnoreCase("true")) {
827 existingHoldings.setStaffOnly(oleHoldings.isStaffOnlyFlag());
828 }
829 if (oleHoldings.getCallNumber() != null) {
830 if (existingOleHoldings.getCallNumber() != null) {
831 if (oleHoldings.getCallNumber().getPrefix() != null) {
832 existingOleHoldings.getCallNumber().setPrefix(oleHoldings.getCallNumber().getPrefix());
833 }
834 if (oleHoldings.getCallNumber().getNumber() != null) {
835 existingOleHoldings.getCallNumber().setNumber(oleHoldings.getCallNumber().getNumber());
836 }
837 if (oleHoldings.getCallNumber().getShelvingScheme() != null &&
838 oleHoldings.getCallNumber().getShelvingScheme().getCodeValue() != null) {
839 existingOleHoldings.getCallNumber().getShelvingScheme().setCodeValue(oleHoldings.getCallNumber().getShelvingScheme().getCodeValue());
840 }
841 if (oleHoldings.getCallNumber().getShelvingOrder() != null &&
842 oleHoldings.getCallNumber().getShelvingOrder().getFullValue() != null) {
843 existingOleHoldings.getCallNumber().getShelvingOrder().setFullValue(oleHoldings.getCallNumber().getShelvingOrder().getFullValue());
844 }
845 } else {
846 existingOleHoldings.setCallNumber(oleHoldings.getCallNumber());
847 }
848 }
849 if (oleHoldings.getNote() != null && oleHoldings.getNote().size() > 0) {
850 List<Note> holdingNotes = existingOleHoldings.getNote();
851 if (holdingNotes != null && holdingNotes.size() > 0) {
852 for (Note note : oleHoldings.getNote()) {
853 if (note.getType() != null && note.getValue() != null && !note.getValue().isEmpty()) {
854 holdingNotes.add(note);
855 }
856 }
857 existingOleHoldings.setNote(holdingNotes);
858 } else {
859
860 for (Note note : oleHoldings.getNote()) {
861 if (note.getType() != null && note.getValue() != null && !note.getValue().isEmpty()) {
862 holdingNotes.add(note);
863 }
864 }
865 if (holdingNotes != null && holdingNotes.size() > 0)
866 existingOleHoldings.setNote(holdingNotes);
867
868 }
869 }
870
871 if (holdings instanceof PHoldings) {
872 setPHoldingInformation(oleHoldings, existingOleHoldings);
873 } else {
874 setEHoldingInformation(oleHoldings, existingOleHoldings);
875 }
876 if (canUpdateStaffOnlyFlag.equalsIgnoreCase("true")) {
877 existingHoldings.setStaffOnly(holdings.isStaffOnly());
878 }
879 existingHoldings.setUpdatedBy(holdings.getUpdatedBy());
880 existingHoldings.setUpdatedOn(holdings.getUpdatedOn());
881 existingHoldings.setLastUpdated(holdings.getLastUpdated());
882 existingHoldings.setCategory(holdings.getCategory());
883 existingHoldings.setType(holdings.getType());
884 existingHoldings.setFormat(holdings.getFormat());
885 existingHoldings.setContent(holdingOlemlRecordProcessor.toXML(existingOleHoldings));
886 updateHoldings(existingHoldings);
887 } else {
888 DocstoreException docstoreException = new DocstoreValidationException(DocstoreResources.HOLDING_ID_NOT_FOUND, DocstoreResources.HOLDING_ID_NOT_FOUND);
889 docstoreException.addErrorParams("holdingsId", holdingId);
890 throw docstoreException;
891 }
892
893 }
894 } catch (Exception e) {
895 LOG.error("Exception occurred while doing bulk update of Holdings ", e);
896 throw e;
897 }
898 }
899
900 @Override
901 public void bulkUpdateItem(Item item, List<String> itemIds, String canUpdateStaffOnlyFlag) {
902 ItemOlemlRecordProcessor itemOlemlRecordProcessor = new ItemOlemlRecordProcessor();
903 org.kuali.ole.docstore.common.document.content.instance.Item itemContent = itemOlemlRecordProcessor.fromXML(item.getContent());
904 try {
905 for (String itemId : itemIds) {
906 Item existingItem = (Item) getDocstoreStorageService().retrieveItem(itemId);
907 if (existingItem != null) {
908 org.kuali.ole.docstore.common.document.content.instance.Item existingItemContent = itemOlemlRecordProcessor.fromXML(existingItem.getContent());
909 if (itemContent != null && itemContent.getLocation() != null &&
910 itemContent.getLocation().getLocationLevel() != null &&
911 itemContent.getLocation().getLocationLevel().getName() != null &&
912 !itemContent.getLocation().getLocationLevel().getName().isEmpty()) {
913 if (existingItemContent.getLocation() != null && existingItemContent.getLocation().getLocationLevel() != null) {
914 existingItemContent.getLocation().getLocationLevel().setName(itemContent.getLocation().getLocationLevel().getName());
915 } else {
916 existingItemContent.setLocation(itemContent.getLocation());
917 }
918
919 }
920 if (canUpdateStaffOnlyFlag.equalsIgnoreCase("true")) {
921 existingItemContent.setStaffOnlyFlag(item.isStaffOnly());
922 }
923 if (itemContent.getCallNumber() != null) {
924 if (existingItemContent.getCallNumber() != null) {
925 if (StringUtils.isNotBlank(itemContent.getCallNumber().getPrefix())) {
926 existingItemContent.getCallNumber().setPrefix(itemContent.getCallNumber().getPrefix());
927 }
928 if (StringUtils.isNotBlank(itemContent.getCallNumber().getNumber())) {
929 existingItemContent.getCallNumber().setNumber(itemContent.getCallNumber().getNumber());
930 if (itemContent.getCallNumber().getShelvingScheme() != null &&
931 StringUtils.isNotBlank(itemContent.getCallNumber().getShelvingScheme().getCodeValue()) && !itemContent.getCallNumber().getShelvingScheme().getCodeValue().equalsIgnoreCase("NOINFO")) {
932 existingItemContent.getCallNumber().setShelvingScheme(itemContent.getCallNumber().getShelvingScheme());
933 }
934 }
935 if (itemContent.getCallNumber().getShelvingOrder() != null &&
936 StringUtils.isNotBlank(itemContent.getCallNumber().getShelvingOrder().getFullValue())) {
937 existingItemContent.getCallNumber().setShelvingOrder(itemContent.getCallNumber().getShelvingOrder());
938 }
939 } else {
940 existingItemContent.setCallNumber(itemContent.getCallNumber());
941 }
942 }
943 if (StringUtils.isNotBlank(itemContent.getEnumeration())) {
944 existingItemContent.setEnumeration(itemContent.getEnumeration());
945 }
946 if (itemContent.getAccessInformation() != null) {
947 if (itemContent.getAccessInformation().getBarcode() != null && !itemContent.getAccessInformation().getBarcode().isEmpty()) {
948 if (existingItemContent.getAccessInformation() != null && existingItemContent.getAccessInformation().getBarcode() != null) {
949 existingItemContent.getAccessInformation().setBarcode(itemContent.getAccessInformation().getBarcode());
950 } else {
951 existingItemContent.setAccessInformation(itemContent.getAccessInformation());
952 }
953 }
954 if (itemContent.getAccessInformation().getUri() != null &&
955 itemContent.getAccessInformation().getUri().getValue() != null && !itemContent.getAccessInformation().getUri().getValue().isEmpty()) {
956 existingItemContent.setAccessInformation(itemContent.getAccessInformation());
957 }
958 }
959 if (itemContent.getChronology() != null && !itemContent.getChronology().isEmpty()) {
960 existingItemContent.setChronology(itemContent.getChronology());
961 }
962 if (itemContent.getBarcodeARSL() != null && !itemContent.getBarcodeARSL().isEmpty()) {
963 existingItemContent.setBarcodeARSL(itemContent.getBarcodeARSL());
964 }
965 if (itemContent.getCopyNumber() != null && !itemContent.getCopyNumber().isEmpty()) {
966 existingItemContent.setCopyNumber(itemContent.getCopyNumber());
967 }
968 if (itemContent.getFormerIdentifier() != null && itemContent.getFormerIdentifier().size() > 0 &&
969 itemContent.getFormerIdentifier().get(0) != null && itemContent.getFormerIdentifier().get(0).getIdentifier() != null
970 && itemContent.getFormerIdentifier().get(0).getIdentifier().getIdentifierValue() != null) {
971 existingItemContent.setFormerIdentifier(itemContent.getFormerIdentifier());
972 }
973 if (itemContent.getStatisticalSearchingCode() != null && itemContent.getStatisticalSearchingCode().size() > 0 &&
974 itemContent.getStatisticalSearchingCode().get(0).getCodeValue() != null) {
975 existingItemContent.setStatisticalSearchingCode(itemContent.getStatisticalSearchingCode());
976 }
977 if (itemContent.getItemType() != null && itemContent.getItemType().getCodeValue() != null && !itemContent.getItemType().getCodeValue().isEmpty()) {
978 existingItemContent.setItemType(itemContent.getItemType());
979 }
980 if (itemContent.getTemporaryItemType() != null && itemContent.getTemporaryItemType().getCodeValue() != null &&
981 !itemContent.getTemporaryItemType().getCodeValue().isEmpty()) {
982 existingItemContent.setTemporaryItemType(itemContent.getTemporaryItemType());
983 }
984 if (itemContent.getNumberOfPieces() != null && !itemContent.getNumberOfPieces().isEmpty()) {
985 existingItemContent.setNumberOfPieces(itemContent.getNumberOfPieces());
986 }
987 if (itemContent.getPrice() != null) {
988 existingItemContent.setPrice(itemContent.getPrice());
989 }
990 if (itemContent.getDonorInfo() != null && itemContent.getDonorInfo().size() > 0) {
991 List<DonorInfo> donorInfos = existingItemContent.getDonorInfo();
992 if (donorInfos != null && donorInfos.size() > 0) {
993 for (DonorInfo donorInfo : itemContent.getDonorInfo()) {
994 donorInfos.add(donorInfo);
995 }
996 existingItemContent.setDonorInfo(donorInfos);
997 } else {
998
999 for (DonorInfo donorInfo : itemContent.getDonorInfo()) {
1000 donorInfos.add(donorInfo);
1001 }
1002 if (donorInfos != null && donorInfos.size() > 0)
1003 existingItemContent.setDonorInfo(donorInfos);
1004
1005 }
1006 }
1007 if(itemContent.getItemClaimsReturnedRecords() != null && itemContent.getItemClaimsReturnedRecords().size() > 0){
1008 List<ItemClaimsReturnedRecord> itemClaimsReturnedRecords = existingItemContent.getItemClaimsReturnedRecords();
1009 if(itemClaimsReturnedRecords != null && itemClaimsReturnedRecords.size() > 0){
1010 for(ItemClaimsReturnedRecord itemClaimsReturnedRecord : itemContent.getItemClaimsReturnedRecords()){
1011 itemClaimsReturnedRecords.add(itemClaimsReturnedRecord);
1012 }
1013 existingItemContent.setItemClaimsReturnedRecords(itemClaimsReturnedRecords);
1014 } else {
1015 for(ItemClaimsReturnedRecord itemClaimsReturnedRecord : itemContent.getItemClaimsReturnedRecords()){
1016 itemClaimsReturnedRecords.add(itemClaimsReturnedRecord);
1017 }
1018 if(itemClaimsReturnedRecords != null && itemClaimsReturnedRecords.size() > 0)
1019 existingItemContent.setItemClaimsReturnedRecords(itemClaimsReturnedRecords);
1020 }
1021 }
1022 if(itemContent.getItemDamagedRecords() != null && itemContent.getItemDamagedRecords().size() > 0){
1023 List<ItemDamagedRecord> itemDamagedRecords = existingItemContent.getItemDamagedRecords();
1024 if(itemDamagedRecords != null && itemDamagedRecords.size() > 0){
1025 for(ItemDamagedRecord itemDamagedRecord : itemContent.getItemDamagedRecords()){
1026 itemDamagedRecords.add(itemDamagedRecord);
1027 }
1028 existingItemContent.setItemDamagedRecords(itemDamagedRecords);
1029 } else {
1030 for(ItemDamagedRecord itemDamagedRecord : itemContent.getItemDamagedRecords()){
1031 itemDamagedRecords.add(itemDamagedRecord);
1032 }
1033 if(itemDamagedRecords != null && itemDamagedRecords.size() > 0)
1034 existingItemContent.setItemDamagedRecords(itemDamagedRecords);
1035 }
1036 }
1037 if(itemContent.getMissingPieceItemRecordList() != null && itemContent.getMissingPieceItemRecordList().size() > 0){
1038 List<MissingPieceItemRecord> missingPieceItemRecords = existingItemContent.getMissingPieceItemRecordList();
1039 if(missingPieceItemRecords != null && missingPieceItemRecords.size()>0){
1040 for(MissingPieceItemRecord missingPieceItemRecord : itemContent.getMissingPieceItemRecordList()){
1041 missingPieceItemRecords.add(missingPieceItemRecord);
1042 }
1043 existingItemContent.setMissingPieceItemRecordList(missingPieceItemRecords);
1044 } else {
1045 for(MissingPieceItemRecord missingPieceItemRecord : itemContent.getMissingPieceItemRecordList()){
1046 missingPieceItemRecords.add(missingPieceItemRecord);
1047 }
1048 if(missingPieceItemRecords != null && missingPieceItemRecords.size()>0){
1049 existingItemContent.setMissingPieceItemRecordList(missingPieceItemRecords);
1050 }
1051 }
1052 }
1053
1054
1055 if (itemContent.getCheckinNote() != null && !itemContent.getCheckinNote().isEmpty()) {
1056 existingItemContent.setCheckinNote(itemContent.getCheckinNote());
1057 }
1058 if (itemContent.isFastAddFlag()) {
1059 existingItemContent.setFastAddFlag(itemContent.isFastAddFlag());
1060 }
1061 if (itemContent.isClaimsReturnedFlag()) {
1062 existingItemContent.setClaimsReturnedFlag(itemContent.isClaimsReturnedFlag());
1063 if (itemContent.getClaimsReturnedFlagCreateDate() != null) {
1064 existingItemContent.setClaimsReturnedFlagCreateDate(itemContent.getClaimsReturnedFlagCreateDate());
1065 }
1066 if (itemContent.getClaimsReturnedNote() != null) {
1067 existingItemContent.setClaimsReturnedNote(itemContent.getClaimsReturnedNote());
1068 }
1069 }
1070 if (itemContent.isItemDamagedStatus()) {
1071 existingItemContent.setItemDamagedStatus(itemContent.isItemDamagedStatus());
1072 if (itemContent.getDamagedItemNote() != null) {
1073 existingItemContent.setDamagedItemNote(itemContent.getDamagedItemNote());
1074 }
1075 }
1076 if (itemContent.isMissingPieceFlag()) {
1077 existingItemContent.setMissingPieceFlag(itemContent.isMissingPieceFlag());
1078 if (itemContent.getMissingPiecesCount() != null) {
1079 existingItemContent.setMissingPiecesCount(itemContent.getMissingPiecesCount());
1080 }
1081 if (itemContent.getMissingPieceFlagNote() != null) {
1082 existingItemContent.setMissingPieceFlagNote(itemContent.getMissingPieceFlagNote());
1083 }
1084 }
1085 if (itemContent.getNote() != null && itemContent.getNote().size() > 0) {
1086 List<Note> notes = existingItemContent.getNote();
1087 if (notes != null) {
1088 for (Note note : itemContent.getNote()) {
1089 if (note.getType() != null && note.getValue() != null && !note.getValue().isEmpty()) {
1090 notes.add(note);
1091 }
1092 existingItemContent.setNote(notes);
1093 }
1094 } else {
1095
1096 for (Note note : itemContent.getNote()) {
1097 if (note.getType() != null && note.getValue() != null && !note.getValue().isEmpty()) {
1098 notes.add(note);
1099 }
1100 }
1101 if (notes != null && notes.size() > 0)
1102 existingItemContent.setNote(notes);
1103
1104 }
1105 }
1106
1107 if (itemContent.getHighDensityStorage() != null &&
1108 itemContent.getHighDensityStorage().getRow() != null) {
1109 existingItemContent.setHighDensityStorage(itemContent.getHighDensityStorage());
1110 }
1111 if (itemContent.getItemStatus() != null) {
1112 if (StringUtils.isNotBlank(itemContent.getItemStatus().getCodeValue()) || StringUtils.isNotBlank(itemContent.getItemStatus().getFullValue())) {
1113 existingItemContent.setItemStatus(itemContent.getItemStatus());
1114 }
1115 }
1116 if (canUpdateStaffOnlyFlag.equalsIgnoreCase("true")) {
1117 existingItem.setStaffOnly(item.isStaffOnly());
1118 }
1119 existingItem.setCategory(item.getCategory());
1120 existingItem.setType(item.getType());
1121 existingItem.setFormat(item.getFormat());
1122 existingItem.setContent(itemOlemlRecordProcessor.toXML(existingItemContent));
1123 updateItem(existingItem);
1124
1125 } else {
1126 DocstoreException docstoreException = new DocstoreValidationException(DocstoreResources.ITEM_ID_NOT_FOUND, DocstoreResources.ITEM_ID_NOT_FOUND);
1127 docstoreException.addErrorParams("itemId", itemId);
1128 throw docstoreException;
1129 }
1130 }
1131 } catch (Exception e) {
1132 LOG.error("Exception occurred while doing bulk update for item ", e);
1133 throw e;
1134 }
1135 }
1136
1137 @Override
1138 public Item retrieveItemByBarcode(String barcode) {
1139 Item item = getDocstoreStorageService().retrieveItemByBarcode(barcode);
1140 return item;
1141 }
1142
1143 private void setPHoldingInformation(OleHoldings oleHoldings, OleHoldings existingOleHoldings) {
1144 if (oleHoldings.getCopyNumber() != null) {
1145 existingOleHoldings.setCopyNumber(oleHoldings.getCopyNumber());
1146 }
1147 if (oleHoldings.getExtentOfOwnership() != null && oleHoldings.getExtentOfOwnership().size() > 0) {
1148 List<ExtentOfOwnership> extentOfOwnerships = existingOleHoldings.getExtentOfOwnership();
1149 if (extentOfOwnerships != null && extentOfOwnerships.size() > 0) {
1150 for (ExtentOfOwnership extentOfOwnership : oleHoldings.getExtentOfOwnership()) {
1151 if (extentOfOwnership.getType() != null && extentOfOwnership.getNote() != null && extentOfOwnership.getTextualHoldings() != null) {
1152
1153 extentOfOwnerships.add(extentOfOwnership);
1154 }
1155 }
1156 existingOleHoldings.setExtentOfOwnership(extentOfOwnerships);
1157 } else {
1158
1159 for (ExtentOfOwnership extentOfOwnership : oleHoldings.getExtentOfOwnership()) {
1160 if (extentOfOwnership.getType() != null && extentOfOwnership.getNote() != null && extentOfOwnership.getTextualHoldings() != null) {
1161 extentOfOwnerships.add(extentOfOwnership);
1162 }
1163 }
1164 if (extentOfOwnerships != null && extentOfOwnerships.size() > 0)
1165 existingOleHoldings.setExtentOfOwnership(extentOfOwnerships);
1166
1167 }
1168 }
1169 if (oleHoldings.getReceiptStatus() != null) {
1170 existingOleHoldings.setReceiptStatus(oleHoldings.getReceiptStatus());
1171 }
1172
1173 if (oleHoldings.getUri() != null && oleHoldings.getUri().size() > 0) {
1174 List<Uri> uriList = existingOleHoldings.getUri();
1175 if (uriList != null && uriList.size() > 0) {
1176 for (Uri uri : oleHoldings.getUri()) {
1177 if (uri.getValue() != null && !uri.getValue().isEmpty()) {
1178
1179 uriList.add(uri);
1180 }
1181 }
1182 existingOleHoldings.setUri(uriList);
1183 } else {
1184 for (Uri uri : oleHoldings.getUri()) {
1185 if (uri.getValue() != null && !uri.getValue().isEmpty()) {
1186 uriList.add(uri);
1187 }
1188 }
1189 if (uriList != null && uriList.size() > 0)
1190 existingOleHoldings.setUri(uriList);
1191 }
1192 }
1193 }
1194
1195 private void setEHoldingInformation(OleHoldings oleHoldings, OleHoldings existingOleHoldings) {
1196
1197 if (oleHoldings.getAccessStatus() != null) {
1198 existingOleHoldings.setAccessStatus(oleHoldings.getAccessStatus());
1199 }
1200 if (oleHoldings.getPlatform() != null) {
1201 if (existingOleHoldings.getPlatform() != null) {
1202 if (oleHoldings.getPlatform().getPlatformName() != null && !oleHoldings.getPlatform().getPlatformName().isEmpty()) {
1203 existingOleHoldings.getPlatform().setPlatformName(oleHoldings.getPlatform().getPlatformName());
1204 }
1205 if (oleHoldings.getPlatform().getAdminUrl() != null && !oleHoldings.getPlatform().getAdminUrl().isEmpty()) {
1206 existingOleHoldings.getPlatform().setAdminUrl(oleHoldings.getPlatform().getAdminUrl());
1207 }
1208 if (oleHoldings.getPlatform().getAdminPassword() != null && !oleHoldings.getPlatform().getAdminPassword().isEmpty()) {
1209 existingOleHoldings.getPlatform().setAdminPassword(oleHoldings.getPlatform().getAdminPassword());
1210 }
1211 if (oleHoldings.getPlatform().getAdminUserName() != null && !oleHoldings.getPlatform().getAdminUserName().isEmpty()) {
1212 existingOleHoldings.getPlatform().setAdminUserName(oleHoldings.getPlatform().getAdminUserName());
1213 }
1214 } else {
1215 existingOleHoldings.setPlatform(oleHoldings.getPlatform());
1216 }
1217 }
1218 if (oleHoldings.getStatusDate() != null && !oleHoldings.getStatusDate().isEmpty()) {
1219 existingOleHoldings.setStatusDate(oleHoldings.getStatusDate());
1220 }
1221 if (oleHoldings.getPublisher() != null && !oleHoldings.getPublisher().isEmpty()) {
1222 existingOleHoldings.setPublisher(oleHoldings.getPublisher());
1223 }
1224
1225
1226
1227 if (oleHoldings.getImprint() != null && !oleHoldings.getImprint().isEmpty()) {
1228 existingOleHoldings.setImprint(oleHoldings.getImprint());
1229 }
1230 if (oleHoldings.getStatisticalSearchingCode() != null && oleHoldings.getStatisticalSearchingCode().getCodeValue() != null &&
1231 !oleHoldings.getStatisticalSearchingCode().getCodeValue().isEmpty()) {
1232 if (existingOleHoldings.getStatisticalSearchingCode() != null) {
1233 existingOleHoldings.getStatisticalSearchingCode().setCodeValue(oleHoldings.getStatisticalSearchingCode().getCodeValue());
1234 } else {
1235 existingOleHoldings.setStatisticalSearchingCode(oleHoldings.getStatisticalSearchingCode());
1236 }
1237 }
1238 if (oleHoldings.getExtentOfOwnership() != null &&
1239 oleHoldings.getExtentOfOwnership().size() > 0) {
1240 List<ExtentOfOwnership> existingExtendOfOwnerShip = existingOleHoldings.getExtentOfOwnership();
1241 if (existingExtendOfOwnerShip != null && existingExtendOfOwnerShip.size() > 0) {
1242 for (ExtentOfOwnership extendOwnership : oleHoldings.getExtentOfOwnership()) {
1243 List<Coverage> extendCoverages = new ArrayList<>();
1244 if ((extendOwnership.getCoverages() != null && extendOwnership.getCoverages().getCoverage() != null &&
1245 extendOwnership.getCoverages().getCoverage().size() > 0) ||
1246 (extendOwnership.getPerpetualAccesses() != null && extendOwnership.getPerpetualAccesses().getPerpetualAccess() != null &&
1247 extendOwnership.getPerpetualAccesses().getPerpetualAccess().size() > 0)) {
1248 existingExtendOfOwnerShip.add(extendOwnership);
1249 }
1250 }
1251 existingOleHoldings.setExtentOfOwnership(existingExtendOfOwnerShip);
1252 } else {
1253 existingOleHoldings.setExtentOfOwnership(oleHoldings.getExtentOfOwnership());
1254 }
1255 }
1256 if (oleHoldings.getSubscriptionStatus() != null && !oleHoldings.getSubscriptionStatus().isEmpty()) {
1257 existingOleHoldings.setSubscriptionStatus(oleHoldings.getSubscriptionStatus());
1258 }
1259 if (oleHoldings.getDonorInfo() != null && oleHoldings.getDonorInfo().size() > 0) {
1260 List<DonorInfo> donorInfos = existingOleHoldings.getDonorInfo();
1261 if (donorInfos != null && donorInfos.size() > 0) {
1262 for (DonorInfo donorInfo : oleHoldings.getDonorInfo()) {
1263 donorInfos.add(donorInfo);
1264 }
1265 existingOleHoldings.setDonorInfo(donorInfos);
1266 } else {
1267
1268 for (DonorInfo donorInfo : oleHoldings.getDonorInfo()) {
1269 donorInfos.add(donorInfo);
1270 }
1271 if (donorInfos != null && donorInfos.size() > 0)
1272 existingOleHoldings.setDonorInfo(donorInfos);
1273 }
1274
1275 }
1276 if (oleHoldings.getLink() != null) {
1277 existingOleHoldings.setLink(oleHoldings.getLink());
1278 }
1279 if (oleHoldings.getHoldingsAccessInformation() != null &&
1280 ((oleHoldings.getHoldingsAccessInformation().getNumberOfSimultaneousUser() != null && !oleHoldings.getHoldingsAccessInformation().getNumberOfSimultaneousUser().isEmpty()) ||
1281 (oleHoldings.getHoldingsAccessInformation().getAccessUsername() != null && !oleHoldings.getHoldingsAccessInformation().getAccessUsername().isEmpty()) ||
1282 (oleHoldings.getHoldingsAccessInformation().getAccessPassword() != null && !oleHoldings.getHoldingsAccessInformation().getAccessPassword().isEmpty()) ||
1283 (oleHoldings.getHoldingsAccessInformation().getAuthenticationType() != null && !oleHoldings.getHoldingsAccessInformation().getAuthenticationType().isEmpty()) ||
1284 (oleHoldings.getHoldingsAccessInformation().getProxiedResource() != null && !oleHoldings.getHoldingsAccessInformation().getProxiedResource().isEmpty()) ||
1285 (oleHoldings.getHoldingsAccessInformation().getAccessLocation() != null && !oleHoldings.getHoldingsAccessInformation().getAccessLocation().isEmpty()))) {
1286 existingOleHoldings.setHoldingsAccessInformation(oleHoldings.getHoldingsAccessInformation());
1287 }
1288 if (oleHoldings.getLocalPersistentLink() != null && !oleHoldings.getLocalPersistentLink().isEmpty()) {
1289 existingOleHoldings.setLocalPersistentLink(oleHoldings.getLocalPersistentLink());
1290 }
1291 if (oleHoldings.getLink() != null) {
1292 existingOleHoldings.setLink(oleHoldings.getLink());
1293 }
1294 if (oleHoldings.isInterLibraryLoanAllowed()) {
1295 existingOleHoldings.setInterLibraryLoanAllowed(oleHoldings.isInterLibraryLoanAllowed());
1296 }
1297
1298 }
1299
1300 @Override
1301 public void breakAnalyticsRelation(String seriesHoldingsId, List<String> itemIds) {
1302 try {
1303 getDocstoreStorageService().breakAnalyticsRelation(seriesHoldingsId, itemIds);
1304 } catch (Exception e) {
1305 LOG.error("Exception occurred breaking analytical relation ", e);
1306 throw e;
1307 }
1308 try {
1309 getDocstoreIndexService().breakAnalyticsRelation(seriesHoldingsId, itemIds);
1310 } catch (Exception e) {
1311 docstoreStorageService.rollback();
1312 LOG.error("Exception occurred indexing of break analytical relation ", e);
1313 throw e;
1314 }
1315 }
1316
1317
1318
1319
1320
1321
1322
1323
1324 @Override
1325 public BibTrees processBibTrees(BibTrees bibTrees) {
1326 try {
1327 getDocstoreStorageService().processBibTrees(bibTrees);
1328 if(!"false".equalsIgnoreCase(getParameter())){
1329 getDocstoreIndexService().processBibTrees(bibTrees);
1330 }
1331 } catch (Exception e) {
1332 LOG.error("Exception occurred while processing bib trees ", e);
1333 for(BibTree bibTree:bibTrees.getBibTrees()){
1334 Bib bib = bibTree.getBib();
1335 if(bib.getResult().equals(Holdings.ResultType.FAILURE)){
1336 throw new DocstoreException("Exception while processing BIB "+bib.getMessage());
1337 }
1338 for(HoldingsTree holdingsTree:bibTree.getHoldingsTrees()){
1339 Holdings holdings = holdingsTree.getHoldings();
1340 if(holdings.getResult().equals(Holdings.ResultType.FAILURE)){
1341 throw new DocstoreException("Exception while processing Holdings :"+holdings.getMessage());
1342 }
1343 for(Item item:holdingsTree.getItems()){
1344 if(item.getResult().equals(Holdings.ResultType.FAILURE)){
1345 throw new DocstoreException("Exception while processing Item :"+item.getMessage());
1346 }
1347 }
1348 }
1349 }
1350 throw e;
1351 }
1352 return bibTrees;
1353 }
1354
1355 @Override
1356 public void unbindWithOneBib(List<String> holdingsIds, String bibId) {
1357 try {
1358 getDocstoreStorageService().unbindWithOneBib(holdingsIds, bibId);
1359 } catch (Exception e) {
1360 LOG.error("Exception occurred in unbinding holdings with bibs ", e);
1361 throw e;
1362 }
1363 try {
1364 getDocstoreIndexService().unbindWithOneBib(holdingsIds, bibId);
1365 } catch (Exception e) {
1366 docstoreStorageService.rollback();
1367 LOG.error("Exception occurred while indexing the unbinded holdings with bibs ", e);
1368 throw e;
1369 }
1370
1371 }
1372
1373 @Override
1374 public void unbindWithAllBibs(List<String> holdingsIds, String bibId) {
1375 try {
1376 getDocstoreStorageService().unbindWithAllBibs(holdingsIds, bibId);
1377 } catch (Exception e) {
1378 LOG.error("Exception occurred in unbinding holdings with bibs ", e);
1379 throw e;
1380 }
1381 try {
1382 getDocstoreIndexService().unbindWithAllBibs(holdingsIds, bibId);
1383 } catch (Exception e) {
1384 docstoreStorageService.rollback();
1385 LOG.error("Exception occurred while indexing the unbinded holdings with bibs ", e);
1386 throw e;
1387 }
1388 }
1389
1390
1391
1392
1393
1394
1395
1396
1397 @Override
1398 public BibTrees processBibTreesForBatch(BibTrees bibTrees) {
1399 try {
1400 getDocstoreStorageService().processBibTreesForBatch(bibTrees);
1401 getDocstoreIndexService().processBibTrees(bibTrees);
1402
1403 } catch (Exception e) {
1404 LOG.error("Exception occurred while processing bib trees ", e);
1405 for(BibTree bibTree:bibTrees.getBibTrees()){
1406 Bib bib = bibTree.getBib();
1407 if(bib.getResult().equals(Holdings.ResultType.FAILURE)){
1408 throw new DocstoreException("Exception while processing BIB "+bib.getMessage());
1409 }
1410 for(HoldingsTree holdingsTree:bibTree.getHoldingsTrees()){
1411 Holdings holdings = holdingsTree.getHoldings();
1412 if(holdings.getResult().equals(Holdings.ResultType.FAILURE)){
1413 throw new DocstoreException("Exception while processing Holdings :"+holdings.getMessage());
1414 }
1415 for(Item item:holdingsTree.getItems()){
1416 if(item.getResult().equals(Holdings.ResultType.FAILURE)){
1417 throw new DocstoreException("Exception while processing Item :"+item.getMessage());
1418 }
1419 }
1420 }
1421 }
1422 throw e;
1423 }
1424 return bibTrees;
1425 }
1426
1427 }