1 package org.kuali.ole.docstore.engine.service.index.solr;
2
3 import org.apache.commons.collections.CollectionUtils;
4 import org.apache.commons.lang.StringUtils;
5 import org.apache.solr.client.solrj.SolrQuery;
6 import org.apache.solr.client.solrj.SolrServer;
7 import org.apache.solr.client.solrj.SolrServerException;
8 import org.apache.solr.client.solrj.response.QueryResponse;
9 import org.apache.solr.client.solrj.response.UpdateResponse;
10 import org.apache.solr.common.SolrDocument;
11 import org.apache.solr.common.SolrInputDocument;
12 import org.apache.solr.common.SolrInputField;
13 import org.kuali.ole.docstore.OleDocStoreException;
14 import org.kuali.ole.docstore.common.document.Holdings;
15 import org.kuali.ole.docstore.common.document.Item;
16 import org.kuali.ole.docstore.common.document.content.instance.*;
17 import org.kuali.ole.docstore.common.document.content.instance.xstream.ItemOlemlRecordProcessor;
18 import org.kuali.ole.docstore.common.exception.DocstoreIndexException;
19 import org.kuali.ole.docstore.discovery.service.SolrServerManager;
20 import org.kuali.ole.docstore.discovery.solr.work.bib.marc.WorkBibMarcDocBuilder;
21 import org.kuali.ole.docstore.indexer.solr.DocumentLocalId;
22 import org.kuali.ole.docstore.model.enums.DocCategory;
23 import org.kuali.ole.docstore.utility.XMLUtility;
24 import org.kuali.ole.utility.callnumber.CallNumberFactory;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27
28 import java.io.IOException;
29 import java.text.DecimalFormat;
30 import java.util.ArrayList;
31 import java.util.Date;
32 import java.util.List;
33
34
35
36
37
38
39
40
41 public class ItemOlemlIndexer extends DocstoreSolrIndexService implements ItemConstants {
42
43 private static final Logger LOG = LoggerFactory.getLogger(ItemOlemlIndexer.class);
44 private static ItemOlemlIndexer itemOlemlIndexer = null;
45
46 public static ItemOlemlRecordProcessor itemOlemlRecordProcessor = new ItemOlemlRecordProcessor();
47 public static XMLUtility xmlUtility = new XMLUtility();
48
49 public static ItemOlemlIndexer getInstance() {
50 if(itemOlemlIndexer == null) {
51 itemOlemlIndexer = new ItemOlemlIndexer();
52 }
53 return itemOlemlIndexer;
54 }
55
56 protected void updateRecordInSolr(Object object, List<SolrInputDocument> solrInputDocuments) {
57 LOG.info("Class - ItemOlemlIndexer");
58 LOG.info("Method - updateRecordInSolr");
59 Item itemDocument = (Item)object;
60 LOG.info("Incoming Item Document " + itemDocument.toString());
61 SolrInputDocument solrInputDocument = getSolrInputFieldsForItem(itemDocument);
62 SolrDocument solrDocument = getSolrDocumentByUUID(itemDocument.getId());
63 if (solrDocument != null && solrDocument.size() > 0) {
64 Object bibs = solrDocument.getFieldValue(BIB_IDENTIFIER);
65 Object holdingsIds = solrDocument.getFieldValue(HOLDINGS_IDENTIFIER);
66 solrInputDocument.addField(HOLDINGS_IDENTIFIER, holdingsIds);
67 solrInputDocument.addField(BIB_IDENTIFIER, bibs);
68 }
69
70 addBibInfoForHoldingsOrItems1(solrInputDocument, solrDocument);
71 solrInputDocuments.add(solrInputDocument);
72 LOG.info("Solr Input Document " + solrInputDocument.toString());
73 }
74
75 protected void updateRecordInSolrForItem(Object object, List<SolrInputDocument> solrInputDocuments, SolrDocument holdingsSolrDocument) {
76 LOG.info("Class - ItemOlemlIndexer");
77 LOG.info("Method - updateRecordInSolrForItem");
78 Item itemDocument = (Item) object;
79 LOG.info("Incoming Item Document " + itemDocument.toString());
80 String bibId = itemDocument.getHolding().getBib().getId();
81 String holdingsId = itemDocument.getHolding().getId();
82 SolrInputDocument solrInputDocument = getSolrInputFieldsForItem(itemDocument);
83 if (itemDocument.isAnalytic()) {
84 List<String> holdingsIds = new ArrayList<>();
85 for (Holdings holdings : itemDocument.getHoldings()) {
86 holdingsIds.add(holdings.getId());
87 }
88 solrInputDocument.addField(HOLDINGS_IDENTIFIER, holdingsIds);
89 }
90 solrInputDocument.addField(HOLDINGS_IDENTIFIER, holdingsId);
91 solrInputDocument.addField(BIB_IDENTIFIER, bibId);
92 addBibInfoForHoldingsOrItems(solrInputDocument, holdingsSolrDocument);
93 solrInputDocuments.add(solrInputDocument);
94 LOG.info("Solr Input Document " + solrInputDocument.toString());
95 }
96
97 protected void buildSolrInputDocument(Object object, List<SolrInputDocument> solrInputDocuments) {
98
99
100 Item itemDocument = (Item) object;
101 String holdingsId = itemDocument.getHolding().getId();
102
103 SolrInputDocument solrInputDocument = getSolrInputFieldsForItem(itemDocument);
104
105 if (holdingsId != null) {
106 solrInputDocument.addField(HOLDINGS_IDENTIFIER, holdingsId);
107 }
108 SolrDocument holdingsSolrDoc = getSolrDocumentByUUID(holdingsId);
109 Object bibs = holdingsSolrDoc.getFieldValue(BIB_IDENTIFIER);
110 holdingsSolrDoc.addField(ITEM_IDENTIFIER, itemDocument.getId());
111 SolrInputDocument holdingsSolrInput = buildSolrInputDocFromSolrDoc(holdingsSolrDoc);
112 List<String> bibIds = new ArrayList<>();
113
114 if (bibs instanceof String) {
115 bibIds.add((String) bibs);
116 } else if (bibs instanceof List) {
117 bibIds = (List) bibs;
118 }
119
120 addBibInfoForHoldingsOrItems(solrInputDocument, holdingsSolrDoc);
121
122 solrInputDocument.addField("bibIdentifier", bibIds);
123 solrInputDocuments.add(solrInputDocument);
124 solrInputDocuments.add(holdingsSolrInput);
125 }
126
127
128
129 protected void buildSolrInputDocumentForBatchProcess(Object object, List<SolrInputDocument> solrInputDocuments, SolrInputDocument holdingsSolrInputs) {
130 Item itemDocument = (Item) object;
131 String holdingsId = itemDocument.getHolding().getId();
132
133 SolrInputDocument solrInputDocument = getSolrInputFieldsForItem(itemDocument);
134
135 if (holdingsId != null) {
136 solrInputDocument.addField(HOLDINGS_IDENTIFIER, holdingsId);
137 }
138 SolrDocument holdingsSolrDoc = getSolrDocumentByUUID(holdingsId);
139 Object bibs = holdingsSolrDoc.getFieldValue(BIB_IDENTIFIER);
140 holdingsSolrDoc.addField(ITEM_IDENTIFIER, itemDocument.getId());
141 if(holdingsSolrInputs == null ){
142 SolrInputDocument holdingsSolrInput = buildSolrInputDocFromSolrDoc(holdingsSolrDoc);
143 solrInputDocuments.add(holdingsSolrInput);
144 }
145
146 List<String> bibIds = new ArrayList<>();
147
148 if (bibs instanceof String) {
149 bibIds.add((String) bibs);
150 } else if (bibs instanceof List) {
151 bibIds = (List) bibs;
152 }
153
154 addBibInfoForHoldingsOrItems(solrInputDocument, holdingsSolrDoc);
155
156 solrInputDocument.addField(BIB_IDENTIFIER, bibIds);
157 solrInputDocuments.add(solrInputDocument);
158
159 }
160
161
162 protected SolrInputDocument getSolrInputFieldsForItem(Item itemDocument) {
163 org.kuali.ole.docstore.common.document.content.instance.Item item = null;
164 if (StringUtils.isNotEmpty(itemDocument.getContent())) {
165 item = itemOlemlRecordProcessor.fromXML(itemDocument.getContent());
166 }
167 else if(itemDocument.getContentObject() != null) {
168 item = (org.kuali.ole.docstore.common.document.content.instance.Item) itemDocument.getContentObject();
169 }
170
171 SolrInputDocument solrInputDocument = new SolrInputDocument();
172
173 solrInputDocument.addField(DOC_CATEGORY, DocCategory.WORK.getCode());
174 solrInputDocument.addField(DOC_TYPE, DOC_TYPE_ITEM_VALUE);
175 solrInputDocument.addField(DOC_FORMAT, DOC_FORMAT_INSTANCE_VALUE);
176 solrInputDocument.addField(ID, itemDocument.getId());
177 solrInputDocument.addField(ITEM_IDENTIFIER, itemDocument.getId());
178 solrInputDocument.addField(LOCALID_DISPLAY, DocumentLocalId.getDocumentIdDisplay(itemDocument.getId()));
179 solrInputDocument.addField(LOCALID_SEARCH, DocumentLocalId.getDocumentId(itemDocument.getId()));
180
181 solrInputDocument.addField(ALL_TEXT, getAllTextValueForItem(item));
182 solrInputDocument.addField(CLMS_RET_FLAG, item.isClaimsReturnedFlag());
183 solrInputDocument.addField(CLMS_RET_FLAG_CRE_DATE, item.getClaimsReturnedFlagCreateDate());
184 solrInputDocument.addField(CLMS_RET_NOTE, item.getClaimsReturnedNote());
185 solrInputDocument.addField(CURRENT_BORROWER, item.getCurrentBorrower());
186 solrInputDocument.addField(PROXY_BORROWER, item.getProxyBorrower());
187 solrInputDocument.addField(DUE_DATE_TIME, item.getDueDateTime());
188 solrInputDocument.addField(ITEM_STATUS_EFFECTIVE_DATE, item.getItemStatusEffectiveDate());
189 solrInputDocument.addField(CHECK_OUT_DUE_DATE_TIME, item.getCheckOutDateTime());
190 solrInputDocument.addField(STAFF_ONLY_FLAG, itemDocument.isStaffOnly());
191 solrInputDocument.addField(IS_ANALYTIC, itemDocument.isAnalytic());
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210 Date date = new Date();
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236 solrInputDocument.addField(ITEM_IDENTIFIER_SEARCH, itemDocument.getId());
237 solrInputDocument.addField(BARCODE_ARSL_SEARCH, item.getBarcodeARSL());
238 solrInputDocument.addField(COPY_NUMBER_SEARCH, item.getCopyNumber());
239 solrInputDocument.addField(COPY_NUMBER_LABEL_SEARCH, item.getCopyNumberLabel());
240 solrInputDocument.addField(PURCHASE_ORDER_LINE_ITEM_IDENTIFIER_SEARCH, item.getPurchaseOrderLineItemIdentifier());
241 solrInputDocument.addField(VENDOR_LINE_ITEM_IDENTIFIER_SEARCH, item.getVendorLineItemIdentifier());
242 solrInputDocument.addField(COPY_NUMBER_LABEL_SEARCH, item.getCopyNumberLabel());
243 solrInputDocument.addField(VOLUME_NUMBER_LABEL_SEARCH, item.getVolumeNumberLabel());
244 solrInputDocument.addField(VOLUME_NUMBER_SEARCH, item.getVolumeNumberLabel());
245 solrInputDocument.addField(ENUMERATION_SEARCH, item.getEnumeration());
246 solrInputDocument.addField(CHRONOLOGY_SEARCH, item.getChronology());
247 solrInputDocument.addField(MISSING_PIECE_FLAG_NOTE_SEARCH, item.getMissingPieceFlagNote());
248 solrInputDocument.addField(CLAIMS_RETURNED_NOTE_SEARCH, item.getClaimsReturnedNote());
249 solrInputDocument.addField(DAMAGED_ITEM_NOTE_SEARCH, item.getDamagedItemNote());
250 solrInputDocument.addField(MISSING_PIECE_FLAG_SEARCH, item.isMissingPieceFlag());
251 solrInputDocument.addField(CLAIMS_RETURNED_FLAG_SEARCH, item.isClaimsReturnedFlag());
252 solrInputDocument.addField(ITEM_DAMAGED_FLAG_SEARCH, item.isItemDamagedStatus());
253 solrInputDocument.addField(MISSING_PIECE_COUNT_SEARCH,item.getMissingPiecesCount());
254 solrInputDocument.addField(NUMBER_OF_PIECES_SEARCH,item.getNumberOfPieces());
255
256
257 String itemCallNumber = null;
258
259
260
261
262
263
264
265
266
267
268
269 if (item.getCallNumber() != null && item.getCallNumber().getNumber() != null) {
270 if (StringUtils.isNotEmpty(item.getCallNumber().getNumber())) {
271 itemCallNumber = item.getCallNumber().getNumber();
272 solrInputDocument.addField(CALL_NUMBER_SEARCH, item.getCallNumber().getNumber());
273 solrInputDocument.addField(CALL_NUMBER_DISPLAY, item.getCallNumber().getNumber());
274 }
275 }
276
277 if (item.getCallNumber() != null) {
278 solrInputDocument.addField(CALL_NUMBER_TYPE_SEARCH, item.getCallNumber().getType());
279 solrInputDocument.addField(CALL_NUMBER_PREFIX_SEARCH, item.getCallNumber().getPrefix());
280 solrInputDocument.addField(CLASSIFICATION_PART_SEARCH, item.getCallNumber().getClassificationPart());
281
282 solrInputDocument.addField(CALL_NUMBER_TYPE_DISPLAY, item.getCallNumber().getType());
283 solrInputDocument.addField(CALL_NUMBER_PREFIX_DISPLAY, item.getCallNumber().getPrefix());
284 solrInputDocument.addField(CLASSIFICATION_PART_DISPLAY, item.getCallNumber().getClassificationPart());
285
286
287 String shelvingSchemeCode = "";
288 String shelvingSchemeValue = "";
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320 if(item.getCallNumber() != null && item.getCallNumber().getShelvingScheme() != null && item.getCallNumber().getShelvingScheme().getCodeValue() != null) {
321 shelvingSchemeCode = item.getCallNumber().getShelvingScheme().getCodeValue();
322 if (StringUtils.isNotEmpty(shelvingSchemeCode)) {
323 solrInputDocument.addField(SHELVING_SCHEME_CODE_SEARCH, shelvingSchemeCode);
324 solrInputDocument.addField(SHELVING_SCHEME_CODE_DISPLAY, shelvingSchemeCode);
325 }
326 if (StringUtils.isNotEmpty(shelvingSchemeValue)) {
327 solrInputDocument.addField(SHELVING_SCHEME_VALUE_SEARCH, shelvingSchemeValue);
328
329
330 solrInputDocument.addField(SHELVING_SCHEME_VALUE_DISPLAY, shelvingSchemeValue);
331
332 }
333 }
334
335 String shelvingOrder = null;
336
337 if (item.getCallNumber().getShelvingOrder() != null) {
338 shelvingOrder = item.getCallNumber().getShelvingOrder().getFullValue();
339 }
340 if (StringUtils.isEmpty(shelvingOrder) && item.getCallNumber() != null) {
341 try {
342
343 if (item.getCallNumber().getShelvingScheme() != null) {
344
345
346
347
348
349
350 if(StringUtils.isNotEmpty(itemCallNumber) && itemCallNumber.trim().length() > 0) {
351 shelvingOrder = buildSortableCallNumber(itemCallNumber, item.getCallNumber().getShelvingScheme().getCodeValue());
352 }
353 }
354 } catch (Exception e) {
355 LOG.info("Exception due to :" + e.getMessage(), e);
356 LOG.error(e.getMessage(), e);
357 }
358
359 }
360 if (StringUtils.isNotEmpty(shelvingOrder)) {
361 shelvingOrder = shelvingOrder.replaceAll(" ", "-");
362 solrInputDocument.addField(SHELVING_ORDER_SORT, shelvingOrder + itemDocument.getId());
363 solrInputDocument.addField(SHELVING_ORDER_SEARCH, shelvingOrder);
364 solrInputDocument.addField(SHELVING_ORDER_DISPLAY, shelvingOrder);
365 }
366 if (item.getCallNumber() != null && item.getCallNumber().getPrefix() != null) {
367 solrInputDocument.addField(CALLNUMBER_PREFIX_SORT, item.getCallNumber().getPrefix());
368 }
369 if (item.getCallNumber() != null && item.getCallNumber().getNumber() != null) {
370 solrInputDocument.addField(CALLNUMBER_SORT, item.getCallNumber().getNumber());
371 }
372 if (item.getEnumeration() != null) {
373 String enumerationSort = getNormalizedEnumeration(item.getEnumeration());
374 solrInputDocument.addField(ENUMERATION_SORT, enumerationSort);
375 }
376 if (item.getChronology() != null) {
377 solrInputDocument.addField(CHRONOLOGY_SORT, item.getChronology());
378 }
379 if (item.getCopyNumber() != null) {
380 String copyNumberSort = getNormalizedEnumeration(item.getCopyNumber());
381 solrInputDocument.addField(COPYNUMBER_SORT, copyNumberSort);
382 }
383 if (item.getAccessInformation() != null && item.getAccessInformation().getBarcode() != null) {
384 solrInputDocument.addField(ITEM_BARCODE_SORT, item.getAccessInformation().getBarcode());
385 }
386 }
387
388 if (item.getItemStatus() != null) {
389 solrInputDocument.addField(ITEM_STATUS_DISPLAY, item.getItemStatus().getCodeValue());
390 solrInputDocument.addField(ITEM_STATUS_SEARCH, item.getItemStatus().getCodeValue());
391 }
392 if (item.getLocation() != null &&
393 item.getLocation().getLocationLevel() != null) {
394 StringBuffer locationName = new StringBuffer();
395 StringBuffer locationLevel = new StringBuffer();
396 Location location = item.getLocation();
397 buildLocationNameAndLocationLevel(location, locationName, locationLevel);
398 solrInputDocument.addField(LOCATION_LEVEL_SEARCH, locationName.toString());
399 solrInputDocument.addField(LOCATION_LEVEL_NAME_SEARCH, locationLevel.toString());
400 solrInputDocument.addField(LOCATION_LEVEL_DISPLAY, locationName.toString());
401 solrInputDocument.addField(LOCATION_LEVEL_NAME_DISPLAY, locationLevel.toString());
402 solrInputDocument.addField(LOCATION_LEVEL_SORT, locationName.toString());
403 }
404
405
406 if (item.getItemType() != null) {
407 solrInputDocument.addField(ITEM_TYPE_FULL_VALUE_SEARCH, item.getItemType().getFullValue());
408 solrInputDocument.addField(ITEM_TYPE_CODE_VALUE_SEARCH, item.getItemType().getCodeValue());
409 solrInputDocument.addField(ITEM_TYPE_FULL_VALUE_DISPLAY, item.getItemType().getFullValue());
410 solrInputDocument.addField(ITEM_TYPE_CODE_VALUE_DISPLAY, item.getItemType().getCodeValue());
411 }
412
413 if (item.getTemporaryItemType() != null) {
414 solrInputDocument.addField(TEMPORARY_ITEM_TYPE_FULL_VALUE_SEARCH, item.getTemporaryItemType().getFullValue());
415 solrInputDocument.addField(TEMPORARY_ITEM_TYPE_CODE_VALUE_SEARCH, item.getTemporaryItemType().getCodeValue());
416 solrInputDocument.addField(TEMPORARY_ITEM_TYPE_FULL_VALUE_DISPLAY, item.getTemporaryItemType().getFullValue());
417 solrInputDocument.addField(TEMPORARY_ITEM_TYPE_CODE_VALUE_DISPLAY, item.getTemporaryItemType().getCodeValue());
418 }
419
420 if (item.getAccessInformation() != null) {
421 if (item.getAccessInformation().getBarcode() != null) {
422 solrInputDocument.addField(ITEM_BARCODE_SEARCH, item.getAccessInformation().getBarcode());
423 solrInputDocument.addField(ITEM_BARCODE_DISPLAY, item.getAccessInformation().getBarcode());
424 }
425 if (item.getAccessInformation().getUri() != null) {
426 solrInputDocument.addField(ITEM_URI_SEARCH, item.getAccessInformation().getUri().getValue());
427 solrInputDocument.addField(ITEM_URI_DISPLAY, item.getAccessInformation().getUri().getValue());
428 }
429 }
430
431 for (StatisticalSearchingCode searchingCode : item.getStatisticalSearchingCode()) {
432 if (searchingCode != null) {
433 solrInputDocument.addField(STATISTICAL_SEARCHING_CODE_VALUE_SEARCH, searchingCode.getCodeValue());
434 solrInputDocument.addField(STATISTICAL_SEARCHING_CODE_VALUE_DISPLAY, searchingCode.getCodeValue());
435 solrInputDocument.addField(STATISTICAL_SEARCHING_FULL_VALUE_SEARCH, searchingCode.getFullValue());
436 solrInputDocument.addField(STATISTICAL_SEARCHING_FULL_VALUE_DISPLAY, searchingCode.getFullValue());
437 }
438 }
439 solrInputDocument.addField(ITEM_IDENTIFIER_DISPLAY, itemDocument.getId());
440 solrInputDocument.addField(BARCODE_ARSL_DISPLAY, item.getBarcodeARSL());
441 solrInputDocument.addField(COPY_NUMBER_DISPLAY, item.getCopyNumber());
442 solrInputDocument.addField(COPY_NUMBER_LABEL_DISPLAY, item.getCopyNumberLabel());
443 solrInputDocument.addField(PURCHASE_ORDER_LINE_ITEM_IDENTIFIER_DISPLAY, item.getPurchaseOrderLineItemIdentifier());
444 solrInputDocument.addField(VENDOR_LINE_ITEM_IDENTIFIER_DISPLAY, item.getVendorLineItemIdentifier());
445 solrInputDocument.addField(COPY_NUMBER_LABEL_DISPLAY, item.getCopyNumberLabel());
446 solrInputDocument.addField(VOLUME_NUMBER_LABEL_DISPLAY, item.getVolumeNumberLabel());
447 solrInputDocument.addField(VOLUME_NUMBER_DISPLAY, item.getVolumeNumber());
448 solrInputDocument.addField(ENUMERATION_DISPLAY, item.getEnumeration());
449 solrInputDocument.addField(CHRONOLOGY_DISPLAY, item.getChronology());
450 solrInputDocument.addField(MISSING_PIECE_FLAG_NOTE_DISPLAY, item.getMissingPieceFlagNote());
451 solrInputDocument.addField(CLAIMS_RETURNED_NOTE_DISPLAY, item.getClaimsReturnedNote());
452 solrInputDocument.addField(DAMAGED_ITEM_NOTE_DISPLAY, item.getDamagedItemNote());
453 solrInputDocument.addField(MISSING_PIECE_FLAG_DISPLAY, item.isMissingPieceFlag());
454 solrInputDocument.addField(CLAIMS_RETURNED_FLAG_DISPLAY, item.isClaimsReturnedFlag());
455 solrInputDocument.addField(ITEM_DAMAGED_FLAG_DISPLAY, item.isItemDamagedStatus());
456 solrInputDocument.addField(MISSING_PIECE_COUNT_DISPLAY,item.getMissingPiecesCount());
457 solrInputDocument.addField(NUMBER_OF_PIECES_DISPLAY,item.getNumberOfPieces());
458
459 for (DonorInfo donorInfo : item.getDonorInfo()) {
460 solrInputDocument.addField(DONOR_CODE_SEARCH, donorInfo.getDonorCode());
461 solrInputDocument.addField(DONOR_CODE_DISPLAY, donorInfo.getDonorCode());
462 solrInputDocument.addField(DONOR_PUBLIC_DISPLAY, donorInfo.getDonorPublicDisplay());
463 solrInputDocument.addField(DONOR_NOTE_DISPLAY, donorInfo.getDonorNote());
464 }
465 if (item.getHighDensityStorage() != null) {
466 solrInputDocument.addField(HIGHDENSITYSTORAGE_ROW_DISPLAY, item.getHighDensityStorage().getRow());
467 solrInputDocument.addField(HIGHDENSITYSTORAGE_MODULE_DISPLAY, item.getHighDensityStorage().getModule());
468 solrInputDocument.addField(HIGHDENSITYSTORAGE_SHELF_DISPLAY, item.getHighDensityStorage().getShelf());
469 solrInputDocument.addField(HIGHDENSITYSTORAGE_TRAY_DISPLAY, item.getHighDensityStorage().getTray());
470 }
471 for (Note note : item.getNote()) {
472 solrInputDocument.addField(ITEMNOTE_VALUE_DISPLAY, note.getValue());
473 solrInputDocument.addField(ITEMNOTE_TYPE_DISPLAY, note.getType());
474 }
475 solrInputDocument.addField(NUMBER_OF_RENEW, item.getNumberOfRenew());
476 solrInputDocument.addField(UNIQUE_ID, itemDocument.getId());
477 return solrInputDocument;
478 }
479
480
481 protected boolean validateCallNumber(String callNumber, String codeValue) throws OleDocStoreException {
482 boolean isValid = false;
483 if (StringUtils.isNotEmpty(callNumber) && StringUtils.isNotEmpty(codeValue)) {
484 org.kuali.ole.utility.callnumber.CallNumber callNumberObj = CallNumberFactory.getInstance().getCallNumber(codeValue);
485 if (callNumberObj != null) {
486 isValid = callNumberObj.isValid(callNumber);
487 }
488 }
489 return isValid;
490 }
491 protected void processRecord(SolrServer solrServer, String id, List<SolrInputDocument> solrInputDocumentList) throws IOException, SolrServerException {
492 boolean isDocumentExists = false;
493 SolrInputDocument solrInputDocumentExists = null;
494 for (SolrInputDocument solrInputDocument : solrInputDocumentList) {
495 SolrInputField docType = solrInputDocument.get("DocType");
496 if (docType.getValue().equals("holdings")) {
497 SolrInputField holdingsIds = solrInputDocument.get("itemIdentifier");
498 ArrayList<String> ids = (ArrayList<String>) holdingsIds.getValue();
499 for (Object itemId : ids) {
500 if (itemId.equals(id)) {
501 solrInputDocumentExists = solrInputDocument;
502 isDocumentExists = true;
503 break;
504 }
505 }
506 }
507 }
508
509 if (!isDocumentExists) {
510 processDocument(solrServer, id, solrInputDocumentList);
511 } else {
512 solrInputDocumentExists.getFieldValues("itemIdentifier").remove(id);
513 }
514 }
515
516 private void processDocument(SolrServer solrServer, String id, List<SolrInputDocument> solrInputDocumentList) throws SolrServerException {
517 String query = "itemIdentifier:" + id + " AND DocType:holdings";
518 SolrQuery solrQuery = new SolrQuery();
519 solrQuery.setQuery(query);
520 QueryResponse response = solrServer.query(solrQuery);
521 List<SolrDocument> solrDocumentList = response.getResults();
522 for (SolrDocument instanceSolrDocument : solrDocumentList) {
523 List<String> itemIdentifierList = new ArrayList<String>();
524 Object itemIdentifier = instanceSolrDocument.getFieldValue(ItemConstants.ITEM_IDENTIFIER);
525 if (itemIdentifier instanceof List) {
526 itemIdentifierList = (List<String>) itemIdentifier;
527 if (itemIdentifierList.contains(id)) {
528 itemIdentifierList.remove(id);
529 instanceSolrDocument.setField(ItemConstants.ITEM_IDENTIFIER, itemIdentifierList);
530 }
531 } else if (itemIdentifier instanceof String) {
532 String itemId = (String) itemIdentifier;
533 if (itemId.equalsIgnoreCase(id)) {
534 itemIdentifier = null;
535 instanceSolrDocument.setField(ItemConstants.ITEM_IDENTIFIER, itemIdentifier);
536 }
537 }
538 solrInputDocumentList.add(new WorkBibMarcDocBuilder().buildSolrInputDocFromSolrDoc(instanceSolrDocument));
539 }
540 }
541
542
543 protected void deleteRecordInSolr(SolrServer solrServer, String id) throws IOException, SolrServerException {
544 UpdateResponse updateResponse = solrServer.deleteById(id);
545 List<SolrInputDocument> solrInputDocumentList = new ArrayList<SolrInputDocument>();
546 processDocument(solrServer, id, solrInputDocumentList);
547 indexSolrDocuments(solrInputDocumentList, true);
548 }
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568 protected void rollback(SolrServer solrServer) {
569 try {
570 solrServer.rollback();
571 } catch (SolrServerException e) {
572 LOG.info("Exception :", e);
573 throw new DocstoreIndexException(e.getMessage());
574 } catch (IOException e) {
575 LOG.info("Exception :", e);
576 throw new DocstoreIndexException(e.getMessage());
577 }
578 }
579
580 public String getNormalizedEnumeration(String enumation) {
581 if (enumation.contains(".")) {
582 StringBuffer resultBuf = new StringBuffer();
583 String[] splitEnum = enumation.split("\\.");
584 if (splitEnum.length > 1) {
585 String enumerationNo = splitEnum[1];
586 String enumBufAfterDot = null;
587 String enumBufAfterSpecial = null;
588 String normalizedEnum = null;
589 if (enumerationNo != null && (enumerationNo.trim().length() > 0)) {
590 int pos = 0;
591 boolean numCheck = false;
592 for (int i = 0; i < enumerationNo.length(); i++) {
593 char c = enumerationNo.charAt(i);
594 String convertedEnum = String.valueOf(c);
595 if (convertedEnum.matches("[0-9]")) {
596 if (Character.isDigit(c)) {
597 pos = i;
598 numCheck = true;
599 } else {
600 break;
601 }
602 } else {
603 if (pos == 0 && numCheck == false) {
604 return enumation;
605 }
606 break;
607 }
608 }
609 enumBufAfterDot = enumerationNo.substring(0, pos + 1);
610 normalizedEnum = normalizeFloatForEnumeration(enumBufAfterDot, 5);
611 enumBufAfterSpecial = enumerationNo.substring(pos + 1);
612 splitEnum[1] = normalizedEnum + enumBufAfterSpecial;
613 }
614 for (int j = 0; j < splitEnum.length; j++) {
615 resultBuf.append(splitEnum[j]);
616 resultBuf.append(".");
617 }
618
619 return resultBuf.substring(0, resultBuf.length() - 1).toString();
620 } else {
621 return enumation;
622 }
623 } else {
624 return enumation;
625 }
626 }
627
628 public String normalizeFloatForEnumeration(String floatStr, int digitsB4) {
629 String replacString = floatStr.replaceAll("[^a-zA-Z0-9]+", "");
630 double value = Double.valueOf(replacString).doubleValue();
631 String formatStr = getFormatString(digitsB4);
632 DecimalFormat normFormat = new DecimalFormat(formatStr);
633 String norm = normFormat.format(value);
634 if (norm.endsWith("."))
635 norm = norm.substring(0, norm.length() - 1);
636 return norm;
637 }
638
639 private String getFormatString(int numDigits) {
640 StringBuilder b4 = new StringBuilder();
641 if (numDigits < 0)
642 b4.append("############");
643 else if (numDigits > 0) {
644 for (int i = 0; i < numDigits; i++) {
645 b4.append('0');
646 }
647 }
648 return b4.toString();
649 }
650
651
652
653 protected void modifySolrDocForDestination(String holdingsId, List<String> itemIds, List<SolrInputDocument> solrInputDocumentListFinal) {
654 SolrDocument solrDocumentForDestinationInstance = getSolrDocumentByUUID(holdingsId);
655
656 for (String item : itemIds) {
657 SolrDocument solrDocumentForItem = getSolrDocumentByUUID(item);
658 String sourceInstanceUUID = (String) solrDocumentForItem.getFieldValue("holdingsIdentifier");
659 removeItemsInSourceInstance(sourceInstanceUUID, item,solrInputDocumentListFinal);
660 solrDocumentForItem
661 .setField("bibIdentifier", solrDocumentForDestinationInstance.getFieldValue("bibIdentifier"));
662 solrDocumentForItem
663 .setField("holdingsIdentifier", solrDocumentForDestinationInstance.getFieldValue("id"));
664
665 SolrInputDocument solrInputDocument = new SolrInputDocument();
666 buildSolrInputDocFromSolrDoc(solrDocumentForItem,solrInputDocument);
667 solrInputDocumentListFinal.add(solrInputDocument);
668 }
669 }
670
671 private void removeItemsInSourceInstance(String sourceInstanceUuid, String itemId ,List<SolrInputDocument> solrInputDocumentListFinal) {
672
673 List<String> itemIdentifierList = new ArrayList<>();
674 SolrDocument solrDocumentForSourceInstance = getSolrDocumentByUUID(sourceInstanceUuid);
675 Object field = solrDocumentForSourceInstance.getFieldValue("itemIdentifier");
676 if (field instanceof String) {
677 String instanceIdentifier = (String) solrDocumentForSourceInstance.getFieldValue("itemIdentifier");
678 itemIdentifierList.add(instanceIdentifier);
679 } else if (field instanceof List) {
680 itemIdentifierList = (List) solrDocumentForSourceInstance.getFieldValue("itemIdentifier");
681 }
682 itemIdentifierList.remove(itemId);
683 solrDocumentForSourceInstance.setField("itemIdentifier", itemIdentifierList);
684
685 SolrInputDocument solrInputDocument = new SolrInputDocument();
686 buildSolrInputDocFromSolrDoc(solrDocumentForSourceInstance, solrInputDocument);
687 solrInputDocumentListFinal.add(solrInputDocument);
688 }
689
690
691
692 protected void modifySolrDocForSource(List<String> itemsIds, String holdingsId, List<SolrInputDocument> solrInputDocumentListFinal) {
693
694
695 SolrDocument solrDocumentForDestinationInstance = getSolrDocumentByUUID(holdingsId);
696 solrDocumentForDestinationInstance.addField("itemIdentifier", itemsIds);
697
698 SolrInputDocument destinationHoldingsDocument = new SolrInputDocument();
699 buildSolrInputDocFromSolrDoc(solrDocumentForDestinationInstance, destinationHoldingsDocument);
700
701 solrInputDocumentListFinal.add(destinationHoldingsDocument);
702 }
703
704
705 protected void addBibInfoForHoldingsOrItems(SolrInputDocument solrInputDocument, SolrDocument sourceDocument) {
706 super.addBibInfoForHoldingsOrItems(solrInputDocument, sourceDocument);
707 solrInputDocument.addField(HOLDINGS_CALLNUMBER_SEARCH, sourceDocument.getFieldValue(CALL_NUMBER_SEARCH));
708 solrInputDocument.addField(HOLDINGS_LOCATION_SEARCH, sourceDocument.getFieldValue(LOCATION_LEVEL_SEARCH));
709 solrInputDocument.addField(HOLDINGS_CALLNUMBER_DISPLAY, sourceDocument.getFieldValue(CALL_NUMBER_DISPLAY));
710 solrInputDocument.addField(HOLDINGS_LOCATION_DISPLAY, sourceDocument.getFieldValue(LOCATION_LEVEL_DISPLAY));
711 solrInputDocument.addField(HOLDINGS_COPYNUMBER_SEARCH,sourceDocument.getFieldValue(COPY_NUMBER_SEARCH));
712 solrInputDocument.addField(HOLDINGS_COPYNUMBER_DISPLAY,sourceDocument.getFieldValue(COPY_NUMBER_DISPLAY));
713 }
714
715 protected void addBibInfoForHoldingsOrItems1(SolrInputDocument solrInputDocument, SolrDocument sourceDocument) {
716 super.addBibInfoForHoldingsOrItems(solrInputDocument, sourceDocument);
717 solrInputDocument.addField(HOLDINGS_CALLNUMBER_SEARCH, sourceDocument.getFieldValue(HOLDINGS_CALLNUMBER_SEARCH));
718 solrInputDocument.addField(HOLDINGS_LOCATION_SEARCH, sourceDocument.getFieldValue(HOLDINGS_LOCATION_SEARCH));
719 solrInputDocument.addField(HOLDINGS_CALLNUMBER_DISPLAY, sourceDocument.getFieldValue(HOLDINGS_CALLNUMBER_DISPLAY));
720 solrInputDocument.addField(HOLDINGS_LOCATION_DISPLAY, sourceDocument.getFieldValue(HOLDINGS_LOCATION_DISPLAY));
721 solrInputDocument.addField(HOLDINGS_COPYNUMBER_SEARCH, sourceDocument.getFieldValue(HOLDINGS_COPYNUMBER_SEARCH));
722 solrInputDocument.addField(HOLDINGS_COPYNUMBER_DISPLAY,sourceDocument.getFieldValue(HOLDINGS_COPYNUMBER_DISPLAY));
723 }
724
725
726 public String getAllTextValueForItem(org.kuali.ole.docstore.common.document.content.instance.Item item) {
727 StringBuffer sb = new StringBuffer();
728 String itemIdentifier = item.getItemIdentifier();
729 String copyNumber = item.getCopyNumber();
730 String enumeration = item.getEnumeration();
731 String analytic = item.getAnalytic();
732 String barcodeARSL = item.getBarcodeARSL();
733 String chronology = item.getChronology();
734 String checkinNote = item.getCheckinNote();
735 String claimsReturnedFlagCreateDate = item.getClaimsReturnedFlagCreateDate();
736 String claimsReturnedNote = item.getClaimsReturnedNote();
737 String copyNumberLabel = item.getCopyNumberLabel();
738 String currentBorrower = item.getCurrentBorrower();
739 String damagedItemNote = item.getDamagedItemNote();
740 String dueDateTime = item.getDueDateTime();
741 String fund = item.getFund();
742 String itemStatusEffectiveDate = item.getItemStatusEffectiveDate();
743 String missingPieceEffectiveDate = item.getMissingPieceEffectiveDate();
744 String missingPieceFlagNote = item.getMissingPieceFlagNote();
745 String missingPiecesCount = item.getMissingPiecesCount();
746 String numberOfPieces = item.getNumberOfPieces();
747 String price = item.getPrice();
748 String proxyBorrower = item.getProxyBorrower();
749 String purchaseOrderLineItemIdentifier = item.getPurchaseOrderLineItemIdentifier();
750 String resourceIdentifier = item.getResourceIdentifier();
751 String vendorLineItemIdentifier = item.getVendorLineItemIdentifier();
752 String volumeNumber = item.getVolumeNumber();
753 String volumeNumberLabel = item.getVolumeNumberLabel();
754
755 appendData(sb, itemIdentifier);
756 appendData(sb, copyNumber);
757 appendData(sb, enumeration);
758 appendData(sb, analytic);
759 appendData(sb, chronology);
760 appendData(sb, barcodeARSL);
761 appendData(sb, checkinNote);
762 appendData(sb, claimsReturnedFlagCreateDate);
763 appendData(sb, claimsReturnedNote);
764 appendData(sb, copyNumberLabel);
765 appendData(sb, currentBorrower);
766 appendData(sb, damagedItemNote);
767 appendData(sb, dueDateTime);
768 appendData(sb, fund);
769 appendData(sb, itemStatusEffectiveDate);
770 appendData(sb, missingPieceEffectiveDate);
771 appendData(sb, missingPieceFlagNote);
772 appendData(sb, missingPiecesCount);
773 appendData(sb, numberOfPieces);
774 appendData(sb, price);
775 appendData(sb, proxyBorrower);
776 appendData(sb, purchaseOrderLineItemIdentifier);
777 appendData(sb, resourceIdentifier);
778 appendData(sb, vendorLineItemIdentifier);
779 appendData(sb, volumeNumber);
780 appendData(sb, volumeNumberLabel);
781
782 boolean staffOnlyFlag = item.isStaffOnlyFlag();
783 boolean claimsReturnedFlag = item.isClaimsReturnedFlag();
784 boolean fastAddFlag = item.isFastAddFlag();
785 boolean itemDamagedStatus = item.isItemDamagedStatus();
786 boolean missingPieceFlag = item.isMissingPieceFlag();
787
788 appendData(sb, String.valueOf(staffOnlyFlag));
789 appendData(sb, String.valueOf(claimsReturnedFlag));
790 appendData(sb, String.valueOf(fastAddFlag));
791 appendData(sb, String.valueOf(itemDamagedStatus));
792 appendData(sb, String.valueOf(missingPieceFlag));
793
794 AccessInformation accessInformation = item.getAccessInformation();
795 if (accessInformation != null) {
796 String barcode = accessInformation.getBarcode();
797 appendData(sb, barcode);
798 if (accessInformation.getUri() != null) {
799 String resolvable = accessInformation.getUri().getResolvable();
800 String value = accessInformation.getUri().getValue();
801 appendData(sb, resolvable);
802 appendData(sb, value);
803 }
804 }
805
806 CallNumber callNumber = item.getCallNumber();
807 if (callNumber != null) {
808 String number = callNumber.getNumber();
809 String prefix = callNumber.getPrefix();
810 String classificationPart = callNumber.getClassificationPart();
811 String itemPart = callNumber.getItemPart();
812 String type = callNumber.getType();
813 if (callNumber.getShelvingScheme() != null) {
814 String shelvingSchemeCodeValue = callNumber.getShelvingScheme().getCodeValue();
815 String shelvingSchemeFullValue = callNumber.getShelvingScheme().getFullValue();
816
817 appendData(sb, shelvingSchemeCodeValue);
818 appendData(sb, shelvingSchemeFullValue);
819 }
820 if (callNumber.getShelvingOrder() != null) {
821 String shelvingOrderCodeValue = callNumber.getShelvingOrder().getCodeValue();
822 String shelvingOrderFullValue = callNumber.getShelvingOrder().getFullValue();
823 appendData(sb, shelvingOrderCodeValue);
824 appendData(sb, shelvingOrderFullValue);
825 }
826
827 appendData(sb, number);
828 appendData(sb, prefix);
829 appendData(sb, classificationPart);
830 appendData(sb, itemPart);
831 appendData(sb, type);
832 }
833
834
835 for (DonorInfo donorInfo : item.getDonorInfo()) {
836 if (donorInfo != null) {
837 String donorCode = donorInfo.getDonorCode();
838 String donorNote = donorInfo.getDonorNote();
839 String donorPublicDisplay = donorInfo.getDonorPublicDisplay();
840 appendData(sb, donorCode);
841 appendData(sb, donorNote);
842 appendData(sb, donorPublicDisplay);
843 }
844 }
845
846 for (FormerIdentifier formerIdentifier : item.getFormerIdentifier()) {
847 if (formerIdentifier.getIdentifierType() != null) {
848 String identifierType = formerIdentifier.getIdentifierType();
849 String identifierValue = formerIdentifier.getIdentifier().getIdentifierValue();
850 String source = formerIdentifier.getIdentifier().getSource();
851 appendData(sb, identifierType);
852 appendData(sb, identifierValue);
853 appendData(sb, source);
854 }
855 }
856
857 HighDensityStorage highDensityStorage = item.getHighDensityStorage();
858 if (highDensityStorage != null) {
859 String module = highDensityStorage.getModule();
860 String row = highDensityStorage.getRow();
861 String shelf = highDensityStorage.getShelf();
862 String tray = highDensityStorage.getTray();
863 appendData(sb, module);
864 appendData(sb, row);
865 appendData(sb, shelf);
866 appendData(sb, tray);
867 }
868
869 ItemStatus itemStatus = item.getItemStatus();
870 if(itemStatus != null) {
871 String itemStatusCodeValue = itemStatus.getCodeValue();
872 String itemStatusFullValue = itemStatus.getFullValue();
873 appendData(sb, itemStatusCodeValue);
874 appendData(sb, itemStatusFullValue);
875 }
876
877 ItemType itemType = item.getItemType();
878 if(itemType != null) {
879 String itemTypeCodeValue = itemType.getCodeValue();
880 String itemTypeFullValue = itemType.getFullValue();
881 if (itemType.getTypeOrSource() != null) {
882 String itemTypeText = itemType.getTypeOrSource().getText();
883 String itemTypePointer = itemType.getTypeOrSource().getPointer();
884 appendData(sb, itemTypeText);
885 appendData(sb, itemTypePointer);
886 }
887 appendData(sb, itemTypeCodeValue);
888 appendData(sb, itemTypeFullValue);
889 }
890
891 for (Note note : item.getNote()) {
892 String itemNoteValue = note.getValue();
893 String itemNoteType = note.getType();
894 appendData(sb, itemNoteValue);
895 appendData(sb, itemNoteType);
896 }
897
898 NumberOfCirculations numberOfCirculations = item.getNumberOfCirculations();
899 if(numberOfCirculations != null) {
900 for (CheckInLocation checkInLocation : numberOfCirculations.getCheckInLocation()) {
901
902 if (checkInLocation != null) {
903 if (checkInLocation.getCount() != null) {
904 String checkInLocationCount = checkInLocation.getCount().toString();
905 appendData(sb, checkInLocationCount);
906 }
907 if (checkInLocation.getInHouseCount() != null) {
908 String checkInLocationInHouseCount = checkInLocation.getInHouseCount().toString();
909 appendData(sb, checkInLocationInHouseCount);
910 }
911 String checkInLocationName = checkInLocation.getName();
912 appendData(sb, checkInLocationName);
913 }
914 }
915 }
916
917 for (StatisticalSearchingCode statisticalSearchingCode : item.getStatisticalSearchingCode()) {
918 if (statisticalSearchingCode != null) {
919 String codeValue = statisticalSearchingCode.getCodeValue();
920 appendData(sb, codeValue);
921 String fullValue = statisticalSearchingCode.getFullValue();
922 appendData(sb, fullValue);
923 }
924 }
925
926 ItemType temporaryItemType = item.getTemporaryItemType();
927 if (temporaryItemType != null) {
928 String temporaryItemTypeCodeValue = temporaryItemType.getCodeValue();
929 String temporaryItemTypeFullValue = temporaryItemType.getFullValue();
930 appendData(sb, temporaryItemTypeCodeValue);
931 appendData(sb, temporaryItemTypeFullValue);
932 }
933
934 buildLocationNameAndLocationLevel(item.getLocation(), sb, sb);
935
936 return sb.toString();
937
938 }
939
940 }