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