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