1 package org.kuali.ole.docstore.document.rdbms;
2
3 import org.apache.commons.lang.StringUtils;
4 import org.apache.solr.common.SolrDocument;
5 import org.kuali.ole.DocumentUniqueIDPrefix;
6 import org.kuali.ole.docstore.OleDocStoreException;
7 import org.kuali.ole.docstore.common.document.content.instance.*;
8 import org.kuali.ole.docstore.common.document.content.instance.xstream.InstanceOlemlRecordProcessor;
9 import org.kuali.ole.docstore.common.document.content.instance.xstream.ItemOlemlRecordProcessor;
10 import org.kuali.ole.docstore.model.enums.DocCategory;
11 import org.kuali.ole.docstore.model.enums.DocFormat;
12 import org.kuali.ole.docstore.model.enums.DocType;
13 import org.kuali.ole.docstore.engine.service.storage.rdbms.pojo.*;
14 import org.kuali.ole.docstore.model.xmlpojo.ingest.AdditionalAttributes;
15 import org.kuali.ole.docstore.model.xmlpojo.ingest.Content;
16 import org.kuali.ole.docstore.model.xmlpojo.ingest.Request;
17 import org.kuali.ole.docstore.model.xmlpojo.ingest.RequestDocument;
18 import org.kuali.ole.docstore.model.xmlpojo.ingest.ResponseDocument;
19 import org.kuali.ole.docstore.process.ProcessParameters;
20 import org.kuali.ole.docstore.service.ServiceLocator;
21 import org.kuali.ole.pojo.OleException;
22 import org.kuali.ole.utility.callnumber.CallNumberFactory;
23 import org.kuali.ole.utility.callnumber.CallNumberType;
24 import org.kuali.rice.krad.service.BusinessObjectService;
25 import org.kuali.rice.krad.service.KRADServiceLocator;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28
29 import javax.jcr.Node;
30 import javax.jcr.RepositoryException;
31 import javax.xml.datatype.DatatypeConfigurationException;
32 import javax.xml.datatype.DatatypeFactory;
33 import javax.xml.datatype.XMLGregorianCalendar;
34 import java.io.FileNotFoundException;
35 import java.sql.Timestamp;
36 import java.text.DateFormat;
37 import java.text.Format;
38 import java.text.ParseException;
39 import java.text.SimpleDateFormat;
40 import java.util.ArrayList;
41 import java.util.Collection;
42 import java.util.Date;
43 import java.util.GregorianCalendar;
44 import java.util.HashMap;
45 import java.util.List;
46 import java.util.Map;
47 import java.util.Set;
48
49
50
51
52
53
54
55
56 public class RdbmsWorkInstanceDocumentManager extends RdbmsAbstarctDocumentManager {
57
58 private static RdbmsWorkInstanceDocumentManager ourInstanceRdbms = null;
59 private static final Logger LOG = LoggerFactory.getLogger(RdbmsWorkInstanceDocumentManager.class);
60 private BusinessObjectService businessObjectService;
61
62 public static RdbmsWorkInstanceDocumentManager getInstance() {
63 if (null == ourInstanceRdbms) {
64 ourInstanceRdbms = new RdbmsWorkInstanceDocumentManager();
65 }
66 return ourInstanceRdbms;
67 }
68
69 public BusinessObjectService getBusinessObjectService() {
70 if (null == businessObjectService) {
71 businessObjectService = KRADServiceLocator.getBusinessObjectService();
72 }
73 return businessObjectService;
74 }
75
76 @Override
77 public Node storeDocument(RequestDocument requestDocument, Object object, ResponseDocument responseDocument) throws OleDocStoreException {
78 String bibUUid = null;
79 String prefixedUuid = responseDocument.getUuid();
80 if ((responseDocument.getUuid() != null) && (!"".equals(requestDocument.getUuid()))) {
81 bibUUid = DocumentUniqueIDPrefix.getDocumentId(responseDocument.getUuid());
82 }
83 try {
84 responseDocument.setUuid("");
85 InstanceOlemlRecordProcessor instanceOlemlRecordProcessor = new InstanceOlemlRecordProcessor();
86 businessObjectService = (BusinessObjectService) object;
87 if (requestDocument.getContent() == null || requestDocument.getContent().getContent() == null) {
88 return null;
89 }
90 InstanceCollection instanceCollection = new InstanceOlemlRecordProcessor().fromXML(requestDocument.getContent().getContent());
91 if (instanceCollection.getInstance() != null && instanceCollection.getInstance().size() > 0) {
92 Instance instance = instanceCollection.getInstance().get(0);
93 List<String> resIdList = new ArrayList<String>();
94 resIdList.addAll(instance.getResourceIdentifier());
95 List<String> resIdList1 = new ArrayList<String>();
96 resIdList1.addAll(resIdList);
97 for (String resId : instance.getResourceIdentifier()) {
98 Map bibMap = new HashMap();
99 bibMap.put("bibId", DocumentUniqueIDPrefix.getDocumentId(resId));
100 List<BibRecord> bibRecords = (List<BibRecord>) getBusinessObjectService().findMatching(BibRecord.class, bibMap);
101 if (bibRecords != null && bibRecords.size() == 0) {
102 resIdList1.remove(resId);
103 return null;
104 }
105 }
106 instance.setResourceIdentifier(resIdList1);
107
108 if (instance.getResourceIdentifier() != null && instance.getResourceIdentifier().size() > 0) {
109 bibUUid = DocumentUniqueIDPrefix.getDocumentId(instance.getResourceIdentifier().get(0));
110
111 }
112
113
114
115
116
117
118 OleHoldings oleHoldings = instance.getOleHoldings();
119 processCallNumber(oleHoldings);
120 Items items = instance.getItems();
121 String uniqueIdPrefixforInstance = DocumentUniqueIDPrefix.getPrefix(requestDocument.getCategory(), requestDocument.getType(), requestDocument.getFormat());
122 InstanceRecord instanceRecord = saveInstancerecord(bibUUid, uniqueIdPrefixforInstance);
123 String instanceId = instanceRecord.getInstanceId();
124 List<String> resIds = instance.getResourceIdentifier();
125 List<String> prefixedResourceId = new ArrayList<>();
126 for (String resId : resIds) {
127 String prefixedBibId = DocumentUniqueIDPrefix.getPrefixedId(DocumentUniqueIDPrefix.PREFIX_WORK_BIB_MARC, resId);
128 prefixedResourceId.add(prefixedBibId);
129 }
130
131
132 String uniqueIdPrefixForHoldings = DocumentUniqueIDPrefix.getPrefix(requestDocument.getCategory(), DocType.HOLDINGS.getCode(), requestDocument.getFormat());
133 HoldingsRecord holdingsRecord = null;
134 if (oleHoldings.getExtension() != null && oleHoldings.getExtension().getContent() != null && oleHoldings.getExtension().getContent().size() > 0) {
135 if (oleHoldings.getExtension().getContent().get(0) != null) {
136 AdditionalAttributes additionalAttributes = (AdditionalAttributes) oleHoldings.getExtension().getContent().get(0);
137 String staffOnlyFlagForHoldingsNew = additionalAttributes.getAttributeMap().get("staffOnlyFlag");
138 if (staffOnlyFlagForHoldingsNew != null) {
139 holdingsRecord = saveHoldingsRecord(oleHoldings, instanceId, uniqueIdPrefixForHoldings, staffOnlyFlagForHoldingsNew, additionalAttributes);
140 } else if (requestDocument.getAdditionalAttributes() != null) {
141
142 String staffOnlyFlagForHoldings = additionalAttributes.getAttribute(AdditionalAttributes.STAFFONLYFLAG);
143 additionalAttributes = requestDocument.getAdditionalAttributes();
144 holdingsRecord = saveHoldingsRecord(oleHoldings, instanceId, uniqueIdPrefixForHoldings, staffOnlyFlagForHoldings, additionalAttributes);
145 } else {
146 additionalAttributes = requestDocument.getAdditionalAttributes();
147 holdingsRecord = saveHoldingsRecord(oleHoldings, instanceId, uniqueIdPrefixForHoldings, "false", additionalAttributes);
148 }
149 }
150 } else {
151 AdditionalAttributes additionalAttributes = requestDocument.getAdditionalAttributes();
152 String staffOnlyFlagForHoldings = null;
153 if (additionalAttributes != null) {
154 staffOnlyFlagForHoldings = additionalAttributes.getAttribute(AdditionalAttributes.STAFFONLYFLAG);
155 additionalAttributes = requestDocument.getAdditionalAttributes();
156 } else {
157 if (additionalAttributes == null) {
158 additionalAttributes = new AdditionalAttributes();
159 String holdingsCreatedDate = null;
160 Format formatter = new SimpleDateFormat("yyyy-mm-dd HH:mm:ss");
161 holdingsCreatedDate = formatter.format(new Date());
162 additionalAttributes.setAttribute(AdditionalAttributes.HOLDINGS_CREATED_BY, "BulkIngest-User");
163 additionalAttributes.setAttribute(AdditionalAttributes.HOLDINGS_DATE_ENTERED, holdingsCreatedDate);
164 }
165 staffOnlyFlagForHoldings = "false";
166 }
167 holdingsRecord = saveHoldingsRecord(oleHoldings, instanceId, uniqueIdPrefixForHoldings, staffOnlyFlagForHoldings, additionalAttributes);
168 }
169
170 String uniqueIdPrefixForItem = DocumentUniqueIDPrefix.getPrefix(requestDocument.getCategory(), DocType.ITEM.getCode(), requestDocument.getFormat());
171 List<ItemRecord> itemRecords = saveItemRecords(items, instanceId, uniqueIdPrefixForItem, oleHoldings);
172 instance.setInstanceIdentifier(DocumentUniqueIDPrefix.getPrefixedId(instanceRecord.getUniqueIdPrefix(), instanceRecord.getInstanceId()));
173 instance.getOleHoldings().setHoldingsIdentifier(DocumentUniqueIDPrefix.getPrefixedId(holdingsRecord.getUniqueIdPrefix(), holdingsRecord.getHoldingsId()));
174 for (int i = 0; i < itemRecords.size(); i++) {
175 instance.getItems().getItem().get(i).setItemIdentifier(DocumentUniqueIDPrefix.getPrefixedId(itemRecords.get(i).getUniqueIdPrefix(), itemRecords.get(i).getItemId()));
176 }
177 instance.getResourceIdentifier().clear();
178 instance.getResourceIdentifier().addAll(prefixedResourceId);
179 instanceCollection.getInstance().set(0, instance);
180 requestDocument.getContent().setContentObject(instanceCollection);
181 requestDocument.getContent().setContent(instanceOlemlRecordProcessor.toXML(instanceCollection));
182 requestDocument.setUuid(DocumentUniqueIDPrefix.getPrefixedId(instanceRecord.getUniqueIdPrefix(), instanceId));
183 buildResponseDocument(responseDocument, holdingsRecord, itemRecords, instanceRecord);
184 }
185 } catch (Exception e) {
186 LOG.error("Exception :" + e);
187 Map map = new HashMap();
188 map.put("bibId", bibUUid);
189 businessObjectService.deleteMatching(BibRecord.class, map);
190 buildFailureResponse(requestDocument, responseDocument);
191 }
192
193 return null;
194 }
195
196 private void buildFailureResponse(RequestDocument requestDocument, ResponseDocument responseDocument) {
197 responseDocument.setId(requestDocument.getId());
198 responseDocument.setStatus("Ingest Failed");
199 }
200
201 private void buildResponseDocument(ResponseDocument responseDocument, HoldingsRecord holdingsRecord, List<ItemRecord> itemRecords, InstanceRecord instanceRecord) {
202 responseDocument.setUuid(DocumentUniqueIDPrefix.getPrefixedId(instanceRecord.getUniqueIdPrefix(), instanceRecord.getInstanceId()));
203 responseDocument.setCategory(DocCategory.WORK.getCode());
204 responseDocument.setType(DocType.INSTANCE.getCode());
205 responseDocument.setFormat(DocFormat.OLEML.getCode());
206 responseDocument.setStatus("Success");
207
208 List<ResponseDocument> responseDocuments = new ArrayList<ResponseDocument>();
209
210 ResponseDocument holdingResponseDocument = new ResponseDocument();
211 holdingResponseDocument.setCategory(DocCategory.WORK.getCode());
212 holdingResponseDocument.setType(DocType.HOLDINGS.getCode());
213 holdingResponseDocument.setFormat(DocFormat.OLEML.getCode());
214 holdingResponseDocument.setUuid(DocumentUniqueIDPrefix.getPrefixedId(holdingsRecord.getUniqueIdPrefix(), holdingsRecord.getHoldingsId()));
215 responseDocuments.add(holdingResponseDocument);
216
217 for (ItemRecord itemRecord : itemRecords) {
218 ResponseDocument itemResponseDocument = new ResponseDocument();
219 itemResponseDocument.setUuid(DocumentUniqueIDPrefix.getPrefixedId(itemRecord.getUniqueIdPrefix(), itemRecord.getItemId()));
220 itemResponseDocument.setCategory(DocCategory.WORK.getCode());
221 itemResponseDocument.setType(DocType.ITEM.getCode());
222 itemResponseDocument.setFormat(DocFormat.OLEML.getCode());
223 responseDocuments.add(itemResponseDocument);
224 }
225 responseDocument.setLinkedDocuments(responseDocuments);
226
227 }
228
229 private InstanceRecord saveInstancerecord(String bibId, String prefix) {
230
231 InstanceRecord instanceRecord = new InstanceRecord();
232 instanceRecord.setBibId(bibId);
233 instanceRecord.setUniqueIdPrefix(prefix);
234 getBusinessObjectService().save(instanceRecord);
235 return instanceRecord;
236 }
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271 private HoldingsRecord saveHoldingsRecord(OleHoldings oleHoldings, String instanceId, String prefix, String staffOnlyFlagForHoldings,AdditionalAttributes additionalAttributes) {
272
273 HoldingsRecord holdingsRecord = new HoldingsRecord();
274
275 holdingsRecord.setUniqueIdPrefix(prefix);
276 saveHoldingsRecordAdditonalAttributesForDate(holdingsRecord, additionalAttributes);
277 if (staffOnlyFlagForHoldings != null) {
278 holdingsRecord.setStaffOnlyFlag(Boolean.valueOf(staffOnlyFlagForHoldings));
279 }
280 saveHoldingsRecord(oleHoldings, holdingsRecord);
281 return holdingsRecord;
282 }
283
284 protected void saveHoldingsRecord(OleHoldings oleHoldings, HoldingsRecord holdingsRecord) {
285
286 StringBuffer locationLevel = new StringBuffer("");
287 holdingsRecord.setLocation(getLocation(oleHoldings.getLocation(), locationLevel));
288 holdingsRecord.setLocationLevel(locationLevel.toString());
289 if (oleHoldings.getCallNumber() != null) {
290 CallNumber callNumber = oleHoldings.getCallNumber();
291 holdingsRecord.setCallNumberPrefix(callNumber.getPrefix());
292 holdingsRecord.setCallNumber(callNumber.getNumber());
293
294 if (callNumber.getShelvingOrder() != null) {
295 holdingsRecord.setShelvingOrder(callNumber.getShelvingOrder().getFullValue());
296 }
297 CallNumberTypeRecord callNumberTypeRecord = saveCallNumberTypeRecord(callNumber.getShelvingScheme());
298 holdingsRecord.setCallNumberTypeId(callNumberTypeRecord == null ? null : callNumberTypeRecord.getCallNumberTypeId());
299
300 }
301 if (oleHoldings.getReceiptStatus() != null) {
302 ReceiptStatusRecord receiptStatusRecord = saveReceiptStatusRecord(oleHoldings.getReceiptStatus());
303 holdingsRecord.setReceiptStatusId(receiptStatusRecord == null ? null : receiptStatusRecord.getReceiptStatusId());
304 }
305 holdingsRecord.setContent("mock content");
306 holdingsRecord.setExtentOfOwnerShipRecords(null);
307 holdingsRecord.setDonorList(null);
308
309 holdingsRecord.setHoldingsNoteRecords(null);
310 if (oleHoldings.getCopyNumber() != null) {
311 holdingsRecord.setCopyNumber(oleHoldings.getCopyNumber());
312 }
313 getBusinessObjectService().save(holdingsRecord);
314 saveExtentOfOwnerShip(oleHoldings.getExtentOfOwnership(), holdingsRecord.getHoldingsId());
315 saveHoldingNoteRecords(oleHoldings.getNote(), holdingsRecord.getHoldingsId());
316 saveAccessUriRecord(oleHoldings.getUri(), holdingsRecord.getHoldingsId());
317 }
318
319
320 private List<ItemRecord> saveItemRecords(Items items, String instanceId, String prefix, OleHoldings oleHoldings) throws OleDocStoreException {
321
322 List<ItemRecord> itemRecords = new ArrayList<ItemRecord>();
323 for (Item item : items.getItem()) {
324 updateShelvingOrder(item, oleHoldings);
325 ItemRecord itemRecord = new ItemRecord();
326
327 itemRecord.setUniqueIdPrefix(prefix);
328 saveItemRecord(item, itemRecord);
329 itemRecords.add(itemRecord);
330 }
331
332
333 return itemRecords;
334 }
335
336 protected void saveItemRecord(Item item, ItemRecord itemRecord) {
337 itemRecord.setBarCodeArsl(item.getBarcodeARSL());
338 if (item.getCallNumber() != null) {
339
340 CallNumber callNumber = item.getCallNumber();
341 itemRecord.setCallNumberPrefix(callNumber.getPrefix());
342 itemRecord.setCallNumber(callNumber.getNumber());
343 if (callNumber.getShelvingOrder() != null) {
344 itemRecord.setShelvingOrder(callNumber.getShelvingOrder().getFullValue());
345 }
346 if (callNumber.getShelvingScheme() != null) {
347 CallNumberTypeRecord callNumberTypeRecord = saveCallNumberTypeRecord(callNumber.getShelvingScheme());
348 itemRecord.setCallNumberTypeId(callNumberTypeRecord == null ? null : callNumberTypeRecord.getCallNumberTypeId());
349 }
350 }
351 if (item.getAccessInformation() != null) {
352 itemRecord.setBarCode(item.getAccessInformation().getBarcode());
353 }
354 if (item.getItemType() != null) {
355 ItemTypeRecord itemTypeRecord = saveItemTypeRecord(item.getItemType());
356 itemRecord.setItemTypeId(itemTypeRecord == null ? null : itemTypeRecord.getItemTypeId());
357 }
358 if (item.getStatisticalSearchingCode() != null) {
359 StatisticalSearchRecord statisticalSearchRecord = saveStatisticalSearchRecord(item.getStatisticalSearchingCode());
360 itemRecord.setStatisticalSearchId(statisticalSearchRecord == null ? null : statisticalSearchRecord.getStatisticalSearchId());
361 }
362 if (item.getTemporaryItemType() != null) {
363 ItemTypeRecord tempItemTypeRecord = saveItemTypeRecord(item.getTemporaryItemType());
364 itemRecord.setTempItemTypeId(tempItemTypeRecord == null ? null : tempItemTypeRecord.getItemTypeId());
365 }
366 itemRecord.setChronology(item.getChronology());
367 itemRecord.setCopyNumber(item.getCopyNumber());
368 itemRecord.setEnumeration(item.getEnumeration());
369
370 itemRecord.setNumberOfPieces(item.getNumberOfPieces());
371 itemRecord.setPurchaseOrderItemLineId(item.getPurchaseOrderLineItemIdentifier());
372 itemRecord.setVendorLineItemId(item.getVendorLineItemIdentifier());
373 itemRecord.setFund(item.getFund());
374 itemRecord.setPrice(item.getPrice());
375 itemRecord.setCheckInNote(item.getCheckinNote());
376 itemRecord.setFastAddFlag(item.isFastAddFlag() ? Boolean.TRUE : Boolean.FALSE);
377 itemRecord.setItemDamagedStatus(item.isItemDamagedStatus());
378 itemRecord.setMissingPieceFlag(item.isMissingPieceFlag());
379 if (item.isMissingPieceFlag() == true) {
380 if (item.getMissingPieceEffectiveDate() != null && !item.getMissingPieceEffectiveDate().equalsIgnoreCase("")) {
381 SimpleDateFormat df = new SimpleDateFormat("MM/dd/yyyy");
382 Date parsedDate = null;
383 try {
384 parsedDate = df.parse(item.getMissingPieceEffectiveDate());
385 } catch (ParseException e) {
386 LOG.error("Exception : ", e);
387 }
388 Timestamp timestamp = new Timestamp(parsedDate.getTime());
389 itemRecord.setMissingPieceEffectiveDate(timestamp);
390 } else {
391 Timestamp timestamp = new Timestamp((new Date()).getTime());
392 itemRecord.setMissingPieceEffectiveDate(timestamp);
393 }
394 }
395 if(item.getMissingPiecesCount()!=null && !item.getMissingPiecesCount().equalsIgnoreCase("")){
396 int missingPieceCount = Integer.parseInt(item.getMissingPiecesCount());
397 if (missingPieceCount == 0) {
398 item.setMissingPieceFlag(false);
399 item.setMissingPiecesCount("");
400 } else {
401 itemRecord.setMissingPiecesCount(item.getMissingPiecesCount());
402 }
403 }
404
405
406
407 itemRecord.setClaimsReturnedFlag(item.isClaimsReturnedFlag());
408
409 String claimsReturnDate = item.getClaimsReturnedFlagCreateDate();
410 if (claimsReturnDate != null) {
411
412
413 String[] claimsReturnDateArray = claimsReturnDate.split(" ");
414 if (claimsReturnDateArray.length == 1 && claimsReturnDateArray[0] != "") {
415 claimsReturnDate = claimsReturnDate + " 00:00:00";
416 claimsReturnsCreateDateItem(item, itemRecord, claimsReturnDate);
417 } else if (claimsReturnDateArray.length > 1) {
418 claimsReturnsCreateDateItem(item, itemRecord, claimsReturnDate);
419 } else {
420 itemRecord.setClaimsReturnedFlagCreateDate(null);
421 }
422 } else {
423 itemRecord.setClaimsReturnedFlagCreateDate(null);
424 }
425
426 String dueDateItem = item.getDueDateTime();
427 if (dueDateItem != null) {
428
429
430 String[] dueDateItemArray = dueDateItem.split(" ");
431 if (dueDateItemArray.length == 1 && dueDateItemArray[0] != "") {
432 dueDateItem = dueDateItem + " 00:00:00";
433 dueDateTime(item, itemRecord, dueDateItem);
434 } else if (dueDateItemArray.length > 1) {
435 dueDateTime(item, itemRecord, dueDateItem);
436 } else {
437 itemRecord.setDueDateTime(null);
438 }
439 } else {
440 itemRecord.setDueDateTime(null);
441 }
442
443 itemRecord.setClaimsReturnedNote(item.getClaimsReturnedNote());
444 itemRecord.setProxyBorrower(item.getProxyBorrower());
445 itemRecord.setCurrentBorrower(item.getCurrentBorrower());
446
447 itemRecord.setFastAddFlag(item.isFastAddFlag());
448 String effectiveDateForItem = item.getItemStatusEffectiveDate();
449 if (effectiveDateForItem != null) {
450 String[] effectiveDateForItemArray = effectiveDateForItem.split(" ");
451 if (effectiveDateForItemArray.length == 1 && effectiveDateForItemArray[0] != "") {
452 effectiveDateForItem = effectiveDateForItem + " 00:00:00";
453 effectiveDateItem(item, itemRecord, effectiveDateForItem);
454 } else if (effectiveDateForItemArray.length > 1) {
455 effectiveDateItem(item, itemRecord, effectiveDateForItem);
456 } else {
457 itemRecord.setEffectiveDate(null);
458 }
459 } else {
460 itemRecord.setEffectiveDate(null);
461 }
462
463
464
465 String staffOnlyFlagForItem = null;
466 if (item.getExtension() != null && item.getExtension().getContent().size() > 0 && item.getExtension().getContent().get(0) != null) {
467 AdditionalAttributes additionalAttributes = (AdditionalAttributes) item.getExtension().getContent().get(0);
468 if (additionalAttributes.getAttributeMap() != null) {
469 staffOnlyFlagForItem = additionalAttributes.getAttributeMap().get("staffOnlyFlag");
470 if (staffOnlyFlagForItem != null) {
471 itemRecord.setStaffOnlyFlag(Boolean.valueOf(staffOnlyFlagForItem));
472 }
473 }
474 } else {
475 itemRecord.setStaffOnlyFlag(false);
476 }
477 if (item.getItemStatus() != null) {
478 ItemStatusRecord itemStatusRecord = saveItemStatusRecord(item.getItemStatus().getCodeValue());
479 itemRecord.setItemStatusId(itemStatusRecord == null ? null : itemStatusRecord.getItemStatusId());
480 }
481 if (item.getHighDensityStorage() != null) {
482 HighDensityStorageRecord highDensityStorageRecord = saveHighDensityStorageRecord(item.getHighDensityStorage());
483 itemRecord.setHighDensityStorageId(highDensityStorageRecord == null ? null : highDensityStorageRecord.getHighDensityStorageId());
484 }
485 StringBuffer locationLevel = new StringBuffer("");
486 itemRecord.setLocation(getLocation(item.getLocation(), locationLevel));
487 itemRecord.setLocationLevel(locationLevel.toString());
488 itemRecord.setFormerIdentifierRecords(null);
489 itemRecord.setLocationsCheckinCountRecords(null);
490 itemRecord.setItemNoteRecords(null);
491 if(item.getDamagedItemNote()!=null){
492 itemRecord.setDamagedItemNote(item.getDamagedItemNote());
493 }
494 if(item.getMissingPieceFlagNote()!=null){
495 itemRecord.setMissingPieceFlagNote(item.getMissingPieceFlagNote());
496 }
497 if (item.getAccessInformation() != null && item.getAccessInformation().getUri() != null) {
498 itemRecord.setUri(item.getAccessInformation().getUri().getValue());
499 }
500 getBusinessObjectService().save(itemRecord);
501
502 if (item.getFormerIdentifier() != null && item.getFormerIdentifier().size() > 0 && item.getFormerIdentifier().get(0).getIdentifier() != null) {
503 saveFormerIdentifierRecords(item.getFormerIdentifier(), itemRecord.getItemId());
504 }
505 if (item.getNote() != null && item.getNote().size() > 0) {
506 saveItemNoteRecord(item.getNote(), itemRecord.getItemId());
507 }
508 if (item.getNumberOfCirculations() != null && item.getNumberOfCirculations().getCheckInLocation() != null && item.getNumberOfCirculations().getCheckInLocation().size() > 0) {
509 saveCheckInLocationRecord(item.getNumberOfCirculations().getCheckInLocation(), itemRecord.getItemId());
510 }
511 if (item.getDonorInfo() != null && item.getDonorInfo().size() >= 0) {
512 saveDonorList(item.getDonorInfo(), itemRecord.getItemId());
513 }
514
515
516 }
517
518
519 @Override
520 public void deleteDocs(RequestDocument requestDocument, Object object) {
521 ResponseDocument responseDocument = new ResponseDocument();
522 BusinessObjectService businessObjectService = (BusinessObjectService) object;
523 InstanceRecord instanceRecord = new InstanceRecord();
524 Map instanceMap = new HashMap();
525 instanceMap.put("instanceId", DocumentUniqueIDPrefix.getDocumentId(requestDocument.getUuid()));
526 List<InstanceRecord> instanceRecords = (List<InstanceRecord>) businessObjectService.findMatching(InstanceRecord.class, instanceMap);
527 if (instanceRecords != null && instanceRecords.size() > 0) {
528 instanceRecord = instanceRecords.get(0);
529 if (instanceRecord.getHoldingsRecords() != null && instanceRecord.getHoldingsRecords().size() > 0) {
530 HoldingsRecord holdingsRecord = instanceRecord.getHoldingsRecords().get(0);
531
532 if (holdingsRecord.getExtentOfOwnerShipRecords() != null && holdingsRecord.getExtentOfOwnerShipRecords().size() > 0) {
533 List<ExtentOfOwnerShipRecord> extentOfOwnerShipRecords = holdingsRecord.getExtentOfOwnerShipRecords();
534 for (int i = 0; i < extentOfOwnerShipRecords.size(); i++) {
535 List<ExtentNoteRecord> extentNoteRecords = extentOfOwnerShipRecords.get(i).getExtentNoteRecords();
536 if (extentNoteRecords != null && extentNoteRecords.size() > 0) {
537 businessObjectService.delete(extentNoteRecords);
538 }
539 }
540 businessObjectService.delete(extentOfOwnerShipRecords);
541 }
542
543
544 if (holdingsRecord.getHoldingsNoteRecords() != null && holdingsRecord.getHoldingsNoteRecords().size() > 0) {
545 List<HoldingsNoteRecord> holdingsNoteRecords = holdingsRecord.getHoldingsNoteRecords();
546 businessObjectService.delete(holdingsNoteRecords);
547 }
548
549
550
551
552
553 holdingsRecord.setCallNumberTypeId(null);
554 holdingsRecord.setReceiptStatusId(null);
555
556 businessObjectService.delete(holdingsRecord);
557 }
558
559 List<ItemRecord> itemRecords = instanceRecord.getItemRecords();
560 for (ItemRecord itemRecord : itemRecords) {
561
562 if (itemRecord.getFormerIdentifierRecords() != null && itemRecord.getFormerIdentifierRecords().size() > 0) {
563 List<FormerIdentifierRecord> formerIdentifierRecords = itemRecord.getFormerIdentifierRecords();
564 businessObjectService.delete(formerIdentifierRecords);
565 }
566
567
568 if (itemRecord.getItemNoteRecords() != null && itemRecord.getItemNoteRecords().size() > 0) {
569 List<ItemNoteRecord> itemNoteRecords = itemRecord.getItemNoteRecords();
570 businessObjectService.delete(itemNoteRecords);
571 }
572
573
574 if (itemRecord.getLocationsCheckinCountRecords() != null && itemRecord.getLocationsCheckinCountRecords().size() > 0) {
575 List<LocationsCheckinCountRecord> locationsCheckinCountRecords = itemRecord.getLocationsCheckinCountRecords();
576 businessObjectService.delete(locationsCheckinCountRecords);
577 }
578 if (itemRecord.getDonorList() != null && itemRecord.getDonorList().size() > 0) {
579 List<OLEItemDonorRecord> donorList = itemRecord.getDonorList();
580 businessObjectService.delete(donorList);
581 }
582 itemRecord.setItemStatusId(null);
583 itemRecord.setItemTypeId(null);
584 itemRecord.setTempItemTypeId(null);
585 itemRecord.setStatisticalSearchId(null);
586 itemRecord.setHighDensityStorageId(null);
587 businessObjectService.delete(itemRecord);
588
589 }
590 businessObjectService.delete(instanceRecord);
591
592 }
593 buildResponseDocument(requestDocument, instanceRecord, responseDocument);
594
595 }
596
597 @Override
598 public ResponseDocument checkoutContent(RequestDocument requestDocument, Object object) {
599 ResponseDocument respDoc = new ResponseDocument();
600 Map instanceMap = new HashMap();
601 instanceMap.put("instanceId", DocumentUniqueIDPrefix.getDocumentId(requestDocument.getUuid()));
602 List<InstanceRecord> instanceRecords = (List<InstanceRecord>) getBusinessObjectService().findMatching(InstanceRecord.class, instanceMap);
603 if(instanceRecords != null && instanceRecords.size() > 0) {
604 InstanceRecord instanceRecord = instanceRecords.get(0);
605 String content = buildInstanceContent(instanceRecord);
606 if (content != null && instanceRecord.getHoldingsRecords()!=null && instanceRecord.getHoldingsRecords().size() > 0) {
607 HoldingsRecord holdingsRecord = instanceRecord.getHoldingsRecords().get(0);
608 AdditionalAttributes additionalAttributes = new AdditionalAttributes();
609 additionalAttributes.setAttribute(AdditionalAttributes.STAFFONLYFLAG, holdingsRecord.getStaffOnlyFlag().toString());
610 Content contentObj = new Content();
611 contentObj.setContent(content);
612 respDoc.setUuid(requestDocument.getUuid());
613 respDoc.setCategory(requestDocument.getCategory());
614 respDoc.setType(requestDocument.getType());
615 respDoc.setFormat(requestDocument.getFormat());
616 respDoc.setContent(contentObj);
617 respDoc.setAdditionalAttributes(additionalAttributes);
618 }
619 } else {
620 respDoc.setStatus("Failed");
621 respDoc.setStatusMessage("Instance does not exist.");
622 }
623 return respDoc;
624 }
625
626 @Override
627 public void checkInContent(RequestDocument requestDocument, Object object, ResponseDocument responseDocument) throws OleDocStoreException {
628
629 String instanceId = requestDocument.getId();
630 if (requestDocument.getLinkedRequestDocuments() != null) {
631 for (RequestDocument linkedRequestDocument : requestDocument.getLinkedRequestDocuments()) {
632 ItemOlemlRecordProcessor recordProcessor = new ItemOlemlRecordProcessor();
633 Item item = recordProcessor.fromXML(linkedRequestDocument.getContent().getContent());
634 HoldingsRecord holdingsRecord = null;
635 Map instanceMap = new HashMap();
636 instanceMap.put("instanceId", DocumentUniqueIDPrefix.getDocumentId(instanceId));
637 List<HoldingsRecord> holdingsRecords = (List<HoldingsRecord>) getBusinessObjectService().findMatching(HoldingsRecord.class, instanceMap);
638 if (holdingsRecords != null && holdingsRecords.size() > 0) {
639 holdingsRecord = holdingsRecords.get(0);
640 }
641 OleHoldings oleHoldings = buildHoldingsContent(holdingsRecord);
642 buildShelvingOrderForItem(item, oleHoldings);
643 ItemRecord itemRecord = new ItemRecord();
644
645 itemRecord.setUniqueIdPrefix(DocumentUniqueIDPrefix.getPrefix(linkedRequestDocument.getCategory(), linkedRequestDocument.getType(), linkedRequestDocument.getFormat()));
646 if (requestDocument.getAdditionalAttributes() != null) {
647 AdditionalAttributes additionalAttributes = requestDocument.getAdditionalAttributes();
648 String staffOnlyFlagForHoldings = additionalAttributes.getAttribute(AdditionalAttributes.STAFFONLYFLAG);
649 if (staffOnlyFlagForHoldings != null) {
650 itemRecord.setStaffOnlyFlag(Boolean.valueOf(staffOnlyFlagForHoldings));
651 }
652 }
653
654 saveItemRecord(item, itemRecord);
655
656 linkedRequestDocument.setId(DocumentUniqueIDPrefix.getPrefixedId(itemRecord.getUniqueIdPrefix(), itemRecord.getItemId()));
657 buildResponseWithLinkedDocument(requestDocument, responseDocument);
658 }
659
660 }
661 }
662
663 private void buildShelvingOrderForItem(Item item, OleHoldings oleHoldings) throws OleDocStoreException {
664 if (item != null) {
665 if (item.getCallNumber() == null) {
666 item.setCallNumber(new CallNumber());
667 }
668 updateShelvingOrder(item, oleHoldings);
669 }
670 }
671
672 private String buildInstanceContent(InstanceRecord instanceRecord) {
673 String content = null;
674 if (instanceRecord != null) {
675 Instance instance = new Instance();
676 List<Instance> instanceList = new ArrayList<Instance>();
677 InstanceCollection instanceCollection = new InstanceCollection();
678 Items items = new Items();
679 List<Item> itemList = new ArrayList<Item>();
680 instance.setInstanceIdentifier(DocumentUniqueIDPrefix.getPrefixedId(instanceRecord.getUniqueIdPrefix(), instanceRecord.getInstanceId()));
681
682
683
684 List<HoldingsRecord> holdingsRecords = instanceRecord.getHoldingsRecords();
685 if(holdingsRecords!=null && holdingsRecords.size()>0) {
686 OleHoldings oleHoldings = buildHoldingsContent(holdingsRecords.get(0));
687 instance.setOleHoldings(oleHoldings);
688 }
689
690 List<ItemRecord> oleItemRecords = instanceRecord.getItemRecords();
691 instanceRecord.setItemRecords(oleItemRecords);
692 for (ItemRecord itemRecord : oleItemRecords) {
693 Item item = buildItemContent(itemRecord);
694 itemList.add(item);
695 }
696 items.setItem(itemList);
697 instance.setItems(items);
698 instanceList.add(instance);
699 if(StringUtils.isNotEmpty(instanceRecord.getBibId())) {
700 instance.getResourceIdentifier().add(DocumentUniqueIDPrefix.getPrefixedId(DocumentUniqueIDPrefix.PREFIX_WORK_BIB_MARC, instanceRecord.getBibId()));
701 }
702 instanceCollection.setInstance(instanceList);
703 content = new InstanceOlemlRecordProcessor().toXML(instanceCollection);
704 }
705 return content;
706 }
707
708 public ResponseDocument buildResponseDocument(RequestDocument requestDocument, InstanceRecord instanceRecord, ResponseDocument responseDocument) {
709 responseDocument.setId(instanceRecord.getInstanceId());
710 responseDocument.setCategory(requestDocument.getCategory());
711 responseDocument.setType(requestDocument.getType());
712 responseDocument.setFormat(requestDocument.getFormat());
713 responseDocument.setUuid(DocumentUniqueIDPrefix.getPrefixedId(instanceRecord.getUniqueIdPrefix(),instanceRecord.getInstanceId()));
714 responseDocument.setId(instanceRecord.getInstanceId());
715 return responseDocument;
716 }
717
718 @Override
719 public ResponseDocument bind(RequestDocument requestDocument, Object object, String operation)
720 throws OleDocStoreException, RepositoryException, OleException, FileNotFoundException {
721 BusinessObjectService businessObjectService = (BusinessObjectService) object;
722 if (operation.equalsIgnoreCase(Request.Operation.bind.toString())) {
723 updateInstanceData(requestDocument, businessObjectService);
724 }
725 return buildResponseForBind(requestDocument);
726 }
727
728 @Override
729 public void validateInput(RequestDocument requestDocument, Object object, List<String> fieldValues) throws OleDocStoreException {
730 businessObjectService = (BusinessObjectService) object;
731 String content = requestDocument.getContent().getContent();
732 if (content == null) {
733 if (requestDocument.getLinkedRequestDocuments().size() > 0) {
734 List<RequestDocument> linkedRequestDocuments = requestDocument.getLinkedRequestDocuments();
735 for (RequestDocument linkedRequestDocument : linkedRequestDocuments) {
736 if (linkedRequestDocument.getType().equalsIgnoreCase(DocType.ITEM.getCode())) {
737 RdbmsWorkItemDocumentManager.getInstance().validateNewItem(linkedRequestDocument, businessObjectService, fieldValues, DocumentUniqueIDPrefix.getDocumentId(
738 requestDocument.getId()));
739 }
740 }
741 }
742 } else {
743 InstanceOlemlRecordProcessor instProcessor = new InstanceOlemlRecordProcessor();
744 InstanceCollection instanceCollection = instProcessor.fromXML(content);
745 List<Instance> instanceList = instanceCollection.getInstance();
746 for (Instance instance : instanceList) {
747 if (instance.getOleHoldings() != null) {
748 OleHoldings oleHoldings = instance.getOleHoldings();
749 RdbmsWorkHoldingsDocumentManager.getInstance().validateHoldings(oleHoldings);
750 }
751 if (instance.getItems() != null) {
752 Items items = instance.getItems();
753 List<Item> itemList = items.getItem();
754 if (itemList.size() > 0) {
755 for (Item item : itemList) {
756 RdbmsWorkItemDocumentManager.getInstance().itemBarcodeValidation(item, fieldValues, null);
757 if (item.getCallNumber() != null) {
758 CallNumber callNumber = item.getCallNumber();
759 if (instance.getOleHoldings() != null) {
760 OleHoldings oleHoldings = instance.getOleHoldings();
761 validateCallNumber(callNumber, oleHoldings);
762 } else {
763 validateCallNumber(callNumber, null);
764 }
765 }
766 }
767 }
768 }
769 }
770 }
771 }
772
773 public void validateCallNumber(CallNumber itemCNum, OleHoldings holdings) throws OleDocStoreException {
774
775 if ((itemCNum.getNumber() != null && itemCNum.getNumber().length() > 0)) {
776 validateCNumNCNumType(itemCNum);
777 validateShelvingOrderNCNum(itemCNum);
778 }
779
780 else if (holdings != null) {
781 if (holdings.getCallNumber() != null) {
782 CallNumber holCNum = holdings.getCallNumber();
783 validateCNumNCNumType(holCNum);
784
785 if (itemCNum.getShelvingOrder() != null && itemCNum.getShelvingOrder().getFullValue() != null &&
786 itemCNum.getShelvingOrder().getFullValue().trim().length() > 0) {
787 if (!(holCNum.getNumber() != null && holCNum.getNumber().length() > 0)) {
788 throw new OleDocStoreException("Shelving order value is available, Please enter call number information");
789 }
790 }
791 }
792
793 else if (itemCNum.getShelvingOrder() != null && itemCNum.getShelvingOrder().getFullValue() != null &&
794 itemCNum.getShelvingOrder().getFullValue().trim().length() > 0) {
795 throw new OleDocStoreException("Shelving order value is available, Please enter call number information");
796 }
797
798 }
799 }
800
801
802
803
804
805 private void validateCNumNCNumType(CallNumber cNum) throws OleDocStoreException {
806 String callNumber = "";
807 String callNumberType = "";
808
809 if (cNum != null) {
810 callNumber = cNum.getNumber();
811 if (cNum.getShelvingScheme() != null) {
812 callNumberType = cNum.getShelvingScheme().getCodeValue();
813 }
814 }
815
816 if (StringUtils.isNotEmpty(callNumber)) {
817
818 if ((callNumberType == null) || (callNumberType.length() == 0) || (callNumberType.equals("NOINFO"))) {
819 throw new OleDocStoreException("Please enter valid call number type value in call number information ");
820 }
821 }
822 }
823
824 private void validateShelvingOrderNCNum(CallNumber cNum) throws OleDocStoreException {
825 if (cNum.getShelvingOrder() != null && cNum.getShelvingOrder().getFullValue() != null &&
826 cNum.getShelvingOrder().getFullValue().trim().length() > 0) {
827 if (!(cNum.getNumber() != null && cNum.getNumber().length() > 0)) {
828 throw new OleDocStoreException("Shelving order value is available, so please enter call number information");
829 }
830 }
831 }
832
833 public void validateCallNumber(CallNumber cNum) throws OleDocStoreException {
834 validateCNumNCNumType(cNum);
835 validateShelvingOrderNCNum(cNum);
836 }
837
838
839 private void updateInstanceData(RequestDocument requestDocument, BusinessObjectService businessObjectService) {
840 Map instanceMap = new HashMap();
841 instanceMap.put("instanceId", DocumentUniqueIDPrefix.getDocumentId(requestDocument.getUuid()));
842 InstanceRecord instanceRecord = businessObjectService.findByPrimaryKey(InstanceRecord.class, instanceMap);
843 if (instanceRecord != null) {
844 BibInstanceRecord bibInstanceRecord = new BibInstanceRecord();
845 bibInstanceRecord.setBibId(instanceRecord.getBibId());
846 bibInstanceRecord.setInstanceId(instanceRecord.getInstanceId());
847 businessObjectService.save(bibInstanceRecord);
848 }
849 List<RequestDocument> linkedRequestDocuments = requestDocument.getLinkedRequestDocuments();
850 for (RequestDocument linkedRequestDocument : linkedRequestDocuments) {
851 BibInstanceRecord bibInstanceRecord = new BibInstanceRecord();
852 bibInstanceRecord.setInstanceId(DocumentUniqueIDPrefix.getDocumentId(requestDocument.getUuid()));
853 bibInstanceRecord.setBibId(DocumentUniqueIDPrefix.getDocumentId(linkedRequestDocument.getUuid()));
854 businessObjectService.save(bibInstanceRecord);
855 }
856 }
857
858 private ResponseDocument buildResponseForBind(RequestDocument requestDocument) {
859 ResponseDocument responseDocument = new ResponseDocument();
860 responseDocument.setId(requestDocument.getId());
861 responseDocument.setCategory(requestDocument.getCategory());
862 responseDocument.setType(requestDocument.getType());
863 responseDocument.setFormat(requestDocument.getFormat());
864 responseDocument.setUuid(requestDocument.getUuid());
865 List<RequestDocument> linkedRequestDocuments = requestDocument.getLinkedRequestDocuments();
866 List<ResponseDocument> linkedResponseDocumentsList = new ArrayList<ResponseDocument>();
867 for (RequestDocument linkedRequestDocument : linkedRequestDocuments) {
868
869 ResponseDocument linkedResponseDocument = new ResponseDocument();
870 linkedResponseDocument.setCategory(linkedRequestDocument.getCategory());
871 linkedResponseDocument.setType(linkedRequestDocument.getType());
872 linkedResponseDocument.setFormat(linkedRequestDocument.getFormat());
873 linkedResponseDocument.setId(linkedRequestDocument.getId());
874 linkedRequestDocument.setUser(linkedRequestDocument.getUuid());
875 linkedResponseDocumentsList.add(linkedResponseDocument);
876
877 }
878 responseDocument.setLinkedDocuments(linkedResponseDocumentsList);
879
880
881 return responseDocument;
882 }
883
884 private void buildResponseWithLinkedDocument(RequestDocument requestDocument, ResponseDocument responseDocument) {
885 responseDocument.setId(requestDocument.getId());
886 responseDocument.setCategory(requestDocument.getCategory());
887 responseDocument.setType(requestDocument.getType());
888 responseDocument.setFormat(requestDocument.getFormat());
889 responseDocument.setUuid(requestDocument.getUuid());
890 responseDocument.setStatus("Success");
891 List<RequestDocument> linkedRequestDocuments = requestDocument.getLinkedRequestDocuments();
892 List<ResponseDocument> linkedResponseDocumentsList = new ArrayList<ResponseDocument>();
893 for (RequestDocument linkedRequestDocument : linkedRequestDocuments) {
894
895 ResponseDocument linkedResponseDocument = new ResponseDocument();
896 linkedResponseDocument.setCategory(linkedRequestDocument.getCategory());
897 linkedResponseDocument.setType(linkedRequestDocument.getType());
898 linkedResponseDocument.setFormat(linkedRequestDocument.getFormat());
899 linkedResponseDocument.setId(linkedRequestDocument.getId());
900 linkedResponseDocument.setUuid(linkedRequestDocument.getId());
901 linkedRequestDocument.setUser(linkedRequestDocument.getUuid());
902 linkedResponseDocument.setStatus("Success");
903 linkedResponseDocumentsList.add(linkedResponseDocument);
904
905 }
906 responseDocument.setLinkedDocuments(linkedResponseDocumentsList);
907 }
908
909
910 public void transferInstances(List<RequestDocument> requestDocuments, BusinessObjectService businessObjectService)
911 throws Exception {
912 LOG.debug("RdbmsWorkInstanceDocumentManager transferInstances");
913 Collection<InstanceRecord> instanceRecords = null;
914 String desBibIdentifier = requestDocuments.get(requestDocuments.size() - 1).getUuid();
915 LOG.debug("RdbmsWorkInstanceDocumentManager transferInstances desBibIdentifier " + desBibIdentifier);
916 Map instanceMap = new HashMap();
917 Map bibInstanceMap = new HashMap();
918 for (int i = 0; i < requestDocuments.size() - 1; i++) {
919 RequestDocument requestDocument = requestDocuments.get(i);
920 instanceMap.put("instanceId", DocumentUniqueIDPrefix.getDocumentId(requestDocument.getUuid()));
921 bibInstanceMap.put("instanceId", DocumentUniqueIDPrefix.getDocumentId(requestDocument.getUuid()));
922 List<BibInstanceRecord> bibInstanceRecordList = (List<BibInstanceRecord>) businessObjectService
923 .findMatching(BibInstanceRecord.class, bibInstanceMap);
924 if (bibInstanceRecordList.size() > 1) {
925
926 LOG.error(requestDocument.getUuid() + " is bounded with other bib and cant be transferred");
927 throw new Exception(requestDocument.getUuid() + " is bounded with other bib and cant be transferred");
928 }
929
930
931
932
933
934 InstanceRecord instanceRecord = businessObjectService.findByPrimaryKey(InstanceRecord.class, instanceMap);
935 instanceRecord.setBibId(DocumentUniqueIDPrefix.getDocumentId(desBibIdentifier));
936 businessObjectService.save(instanceRecord);
937 }
938 }
939
940 public void transferItems(List<RequestDocument> requestDocuments, BusinessObjectService businessObjectService)
941 throws Exception {
942 String destInstanceIdentifier = requestDocuments.get(requestDocuments.size() - 1).getUuid();
943 Map itemMap = new HashMap();
944 for (int i = 0; i < requestDocuments.size() - 1; i++) {
945 RequestDocument requestDocument = requestDocuments.get(i);
946 itemMap.put("ITEM_ID", DocumentUniqueIDPrefix.getDocumentId(requestDocument.getUuid()));
947 ItemRecord itemRecord = businessObjectService.findByPrimaryKey(ItemRecord.class, itemMap);
948
949 businessObjectService.save(itemRecord);
950 }
951 }
952
953 @Override
954 public ResponseDocument deleteVerify(RequestDocument requestDocument, Object object) throws Exception {
955
956 businessObjectService = (BusinessObjectService) object;
957 List<String> bibIdentifierList = new ArrayList<String>();
958 ResponseDocument responseDocument = new ResponseDocument();
959 Map instanceMap = new HashMap();
960 instanceMap.put("instanceId", DocumentUniqueIDPrefix.getDocumentId(requestDocument.getUuid()));
961 List<BibInstanceRecord> bibInstanceRecords = (List<BibInstanceRecord>) businessObjectService
962 .findMatching(BibInstanceRecord.class, instanceMap);
963 if (bibInstanceRecords.size() > 0) {
964 for (BibInstanceRecord bibInstanceRecord : bibInstanceRecords) {
965 bibIdentifierList.add(bibInstanceRecord.getBibId());
966 }
967
968
969 if (bibIdentifierList.size() > 1) {
970 responseDocument.setCategory(requestDocument.getCategory());
971 responseDocument.setType(requestDocument.getType());
972 responseDocument.setFormat(requestDocument.getFormat());
973 responseDocument.setUuid(requestDocument.getUuid());
974 responseDocument.setStatus("failure'");
975 responseDocument.setStatusMessage("Instance is bound with more than one bib. So deletion cannot be done");
976 return responseDocument;
977 }
978 boolean exists = checkInstancesOrItemsExistsInOLE(requestDocument.getUuid(), object);
979 if (exists) {
980 responseDocument.setId(requestDocument.getId());
981 responseDocument.setCategory(requestDocument.getCategory());
982 responseDocument.setType(requestDocument.getType());
983 responseDocument.setFormat(requestDocument.getFormat());
984 responseDocument.setUuid(requestDocument.getUuid());
985 responseDocument.setStatus("failure'");
986 responseDocument.setStatusMessage("Instances or Items in use. So deletion cannot be done");
987 return responseDocument;
988 }
989 String bibIdentifierValue = bibIdentifierList.get(0);
990 Map bibMap = new HashMap();
991 bibMap.put("bibId", bibIdentifierValue);
992 bibInstanceRecords = (List<BibInstanceRecord>) businessObjectService
993 .findMatching(BibInstanceRecord.class, bibMap);
994 List<String> instanceIdentifierList = new ArrayList<>();
995 for (BibInstanceRecord bibInstanceRecord : bibInstanceRecords) {
996 instanceIdentifierList.add(bibInstanceRecord.getInstanceId());
997 }
998 if (instanceIdentifierList.size() == 1) {
999 String prefix = DocumentUniqueIDPrefix.getPrefix(DocCategory.WORK.getCode(), DocType.BIB.getDescription(), DocFormat.MARC.getCode());
1000 requestDocument.setUuid(DocumentUniqueIDPrefix.getPrefixedId(prefix, bibIdentifierValue));
1001 requestDocument.setCategory(DocCategory.WORK.getCode());
1002 requestDocument.setType(DocType.BIB.getDescription());
1003 requestDocument.setFormat(DocFormat.MARC.getCode());
1004 responseDocument.setStatus("success");
1005 responseDocument.setStatusMessage("success");
1006 responseDocument = RdbmsWorkBibDocumentManager.getInstance().deleteVerify(requestDocument, businessObjectService);
1007 } else {
1008 responseDocument.setUuid(requestDocument.getUuid());
1009 responseDocument.setId(requestDocument.getId());
1010 responseDocument.setCategory(requestDocument.getCategory());
1011 responseDocument.setType(requestDocument.getType());
1012 responseDocument.setFormat(requestDocument.getFormat());
1013 responseDocument.setStatus("success");
1014 responseDocument.setStatusMessage("success");
1015 }
1016 } else {
1017 responseDocument.setUuid(requestDocument.getUuid());
1018 responseDocument.setId(requestDocument.getId());
1019 responseDocument.setCategory(requestDocument.getCategory());
1020 responseDocument.setType(requestDocument.getType());
1021 responseDocument.setFormat(requestDocument.getFormat());
1022 responseDocument.setStatus("success");
1023 responseDocument.setStatusMessage("success");
1024 }
1025
1026 return responseDocument;
1027
1028 }
1029
1030
1031 protected CallNumberTypeRecord saveCallNumberTypeRecord(ShelvingScheme scheme) {
1032
1033 Map callMap = new HashMap();
1034 callMap.put("code", scheme.getCodeValue());
1035 List<CallNumberTypeRecord> callNumberTypeRecords = (List<CallNumberTypeRecord>) getBusinessObjectService().findMatching(CallNumberTypeRecord.class, callMap);
1036 if (callNumberTypeRecords.size() == 0) {
1037 if (scheme.getCodeValue() != null && !"".equals(scheme.getCodeValue())) {
1038 CallNumberTypeRecord callNumberTypeRecord = new CallNumberTypeRecord();
1039 callNumberTypeRecord.setCode(scheme.getCodeValue());
1040 callNumberTypeRecord.setName(scheme.getFullValue());
1041 getBusinessObjectService().save(callNumberTypeRecord);
1042 return callNumberTypeRecord;
1043 } else
1044 return null;
1045 }
1046 return callNumberTypeRecords.get(0);
1047 }
1048
1049 protected String getLocation(Location location, StringBuffer locationLevel) {
1050 StringBuffer locationName = new StringBuffer("");
1051
1052 if (location != null && location.getLocationLevel() != null) {
1053 locationName = locationName.append(location.getLocationLevel().getName());
1054 locationLevel = locationLevel.append(location.getLocationLevel().getLevel());
1055
1056 if (location.getLocationLevel().getLocationLevel() != null) {
1057 locationName = locationName.append("/").append(location.getLocationLevel().getLocationLevel().getName());
1058 locationLevel = locationLevel.append("/").append(location.getLocationLevel().getLocationLevel().getLevel());
1059
1060 if (location.getLocationLevel().getLocationLevel().getLocationLevel() != null) {
1061 locationName = locationName.append("/").append(location.getLocationLevel().getLocationLevel().getLocationLevel().getName());
1062 locationLevel = locationLevel.append("/").append(location.getLocationLevel().getLocationLevel().getLocationLevel().getLevel());
1063
1064 if (location.getLocationLevel().getLocationLevel().getLocationLevel().getLocationLevel() != null) {
1065 locationName = locationName.append("/").append(location.getLocationLevel().getLocationLevel().getLocationLevel().getLocationLevel().getName());
1066 locationLevel = locationLevel.append("/").append(location.getLocationLevel().getLocationLevel().getLocationLevel().getLocationLevel().getLevel());
1067
1068 if (location.getLocationLevel().getLocationLevel().getLocationLevel().getLocationLevel().getLocationLevel() != null) {
1069 locationName = locationName.append("/").append(location.getLocationLevel().getLocationLevel().getLocationLevel().getLocationLevel().getLocationLevel().getName());
1070 locationLevel = locationLevel.append("/").append(location.getLocationLevel().getLocationLevel().getLocationLevel().getLocationLevel().getLocationLevel().getLevel());
1071 }
1072 }
1073 }
1074 }
1075 }
1076 return locationName.toString();
1077 }
1078
1079
1080 protected void saveExtentNoteRecord(String extOfOwnerShipID, List<Note> notes) {
1081 Map map = new HashMap();
1082 map.put("extOfOwnerShipID", extOfOwnerShipID);
1083 List<ExtentNoteRecord> extentNoteRecords = (List<ExtentNoteRecord>) getBusinessObjectService().findMatching(ExtentNoteRecord.class, map);
1084 if (notes != null && notes.size() > 0) {
1085 for (int i = 0; i < notes.size(); i++) {
1086 Note note = notes.get(i);
1087 if (note.getType() != null && ("public".equalsIgnoreCase(note.getType()) || "nonPublic".equalsIgnoreCase(note.getType()))) {
1088 ExtentNoteRecord noteRecord = new ExtentNoteRecord();
1089 if (i < extentNoteRecords.size()) {
1090 noteRecord = extentNoteRecords.get(i);
1091 }
1092
1093
1094 noteRecord.setType(note.getType());
1095 noteRecord.setNote(note.getValue());
1096 getBusinessObjectService().save(noteRecord);
1097 }
1098 }
1099
1100 if (extentNoteRecords.size() > notes.size()) {
1101 getBusinessObjectService().delete(extentNoteRecords.subList(notes.size() - 1, extentNoteRecords.size()));
1102 }
1103 }
1104
1105 }
1106
1107 protected void saveExtentOfOwnerShip(List<ExtentOfOwnership> extentOfOwnershipList, String holdingsId) {
1108
1109 Map map = new HashMap();
1110 map.put("holdingsId", holdingsId);
1111 List<ExtentOfOwnerShipRecord> extentOfOwnerShipRecords = (List<ExtentOfOwnerShipRecord>) getBusinessObjectService().findMatching(ExtentOfOwnerShipRecord.class, map);
1112 if (extentOfOwnershipList != null && extentOfOwnershipList.size() > 0) {
1113 for (int i = 0; i < extentOfOwnershipList.size(); i++) {
1114 ExtentOfOwnerShipRecord extentOfOwnerShipRecord = new ExtentOfOwnerShipRecord();
1115 ExtentOfOwnership extentOfOwnership = extentOfOwnershipList.get(i);
1116 if (i < extentOfOwnerShipRecords.size()) {
1117 extentOfOwnerShipRecord = extentOfOwnerShipRecords.get(i);
1118 }
1119 ExtentOfOwnerShipTypeRecord extentOfOwnerShipTypeRecord = saveExtentOfOwnerShipType(extentOfOwnership.getType());
1120 extentOfOwnerShipRecord.setExtOfOwnerShipTypeId(extentOfOwnerShipTypeRecord != null ? extentOfOwnerShipTypeRecord.getExtOfOwnerShipTypeId() : null);
1121 extentOfOwnerShipRecord.setText(extentOfOwnership.getTextualHoldings());
1122 extentOfOwnerShipRecord.setHoldingsId(holdingsId);
1123 getBusinessObjectService().save(extentOfOwnerShipRecord);
1124 List<Note> notes = extentOfOwnership.getNote();
1125
1126
1127
1128 }
1129
1130 if (extentOfOwnershipList.size() < extentOfOwnerShipRecords.size()) {
1131 getBusinessObjectService().delete(extentOfOwnerShipRecords.subList(extentOfOwnershipList.size() - 1, extentOfOwnerShipRecords.size()));
1132
1133 }
1134 }
1135
1136 }
1137
1138 protected ExtentOfOwnerShipTypeRecord saveExtentOfOwnerShipType(String type) {
1139 Map map = new HashMap();
1140 map.put("code", type);
1141 List<ExtentOfOwnerShipTypeRecord> extentOfOwnerShipTypeRecords = (List<ExtentOfOwnerShipTypeRecord>) getBusinessObjectService().findMatching(ExtentOfOwnerShipTypeRecord.class, map);
1142 if (extentOfOwnerShipTypeRecords.size() == 0) {
1143 if (type != null && !"".equals(type)) {
1144 ExtentOfOwnerShipTypeRecord extentOfOwnerShipTypeRecord = new ExtentOfOwnerShipTypeRecord();
1145 extentOfOwnerShipTypeRecord.setCode(type);
1146 extentOfOwnerShipTypeRecord.setName(type);
1147 getBusinessObjectService().save(extentOfOwnerShipTypeRecord);
1148 return extentOfOwnerShipTypeRecord;
1149 } else {
1150 return null;
1151 }
1152 }
1153 return extentOfOwnerShipTypeRecords.get(0);
1154 }
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179 protected void saveAccessUriRecord(List<Uri> uriList, String holdingsId) {
1180
1181 Map map = new HashMap();
1182 map.put("holdingsId", holdingsId);
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204 }
1205
1206
1207 protected ReceiptStatusRecord saveReceiptStatusRecord(String receiptStatus) {
1208 Map map = new HashMap();
1209 map.put("code", receiptStatus);
1210 List<ReceiptStatusRecord> receiptStatusRecords = (List<ReceiptStatusRecord>) getBusinessObjectService().findMatching(ReceiptStatusRecord.class, map);
1211 if (receiptStatusRecords.size() == 0) {
1212 if (receiptStatus != null && !"".equals(receiptStatus)) {
1213 ReceiptStatusRecord receiptStatusRecord = new ReceiptStatusRecord();
1214 receiptStatusRecord.setCode(receiptStatus);
1215 receiptStatusRecord.setName(receiptStatus);
1216 getBusinessObjectService().save(receiptStatusRecord);
1217 return receiptStatusRecord;
1218 } else {
1219 return null;
1220 }
1221 }
1222 return receiptStatusRecords.get(0);
1223 }
1224
1225 protected void saveHoldingNoteRecords(List<Note> noteList, String holdingsId) {
1226
1227 Map map = new HashMap();
1228 map.put("holdingsId", holdingsId);
1229 List<HoldingsNoteRecord> holdingsNoteRecordList = (List<HoldingsNoteRecord>) getBusinessObjectService().findMatching(HoldingsNoteRecord.class, map);
1230 if (noteList.size() > 0) {
1231 List<HoldingsNoteRecord> holdingsNoteRecords = new ArrayList<HoldingsNoteRecord>();
1232 for (int i = 0; i < noteList.size(); i++) {
1233 Note note = noteList.get(i);
1234 if (note.getType() != null && ("public".equalsIgnoreCase(note.getType()) || "nonPublic".equalsIgnoreCase(note.getType()))) {
1235 HoldingsNoteRecord holdingsNoteRecord = new HoldingsNoteRecord();
1236 if (i < holdingsNoteRecordList.size()) {
1237 holdingsNoteRecord = holdingsNoteRecordList.get(i);
1238 }
1239 holdingsNoteRecord.setType(note.getType());
1240 holdingsNoteRecord.setNote(note.getValue());
1241 holdingsNoteRecord.setHoldingsId(holdingsId);
1242 holdingsNoteRecords.add(holdingsNoteRecord);
1243 }
1244 if (holdingsNoteRecords.size() > 0) {
1245 getBusinessObjectService().save(holdingsNoteRecords);
1246 }
1247 }
1248
1249 if (noteList.size() < holdingsNoteRecordList.size()) {
1250 getBusinessObjectService().delete(holdingsNoteRecordList.subList(noteList.size() - 1, holdingsNoteRecordList.size()));
1251 }
1252 }
1253 }
1254
1255
1256 protected ItemTypeRecord saveItemTypeRecord(ItemType itemType) {
1257 Map map = new HashMap();
1258 map.put("code", itemType.getCodeValue());
1259 List<ItemTypeRecord> itemTypeRecords = (List<ItemTypeRecord>) getBusinessObjectService().findMatching(ItemTypeRecord.class, map);
1260 if (itemTypeRecords.size() == 0) {
1261 if (itemType.getCodeValue() != null && !"".equals(itemType.getCodeValue())) {
1262 ItemTypeRecord itemTypeRecord = new ItemTypeRecord();
1263 itemTypeRecord.setCode(itemType.getCodeValue());
1264 itemTypeRecord.setName(itemType.getFullValue());
1265 getBusinessObjectService().save(itemTypeRecord);
1266 return itemTypeRecord;
1267 } else {
1268 return null;
1269 }
1270 }
1271 return itemTypeRecords.get(0);
1272
1273 }
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292 protected StatisticalSearchRecord saveStatisticalSearchRecord(List<StatisticalSearchingCode> statisticalSearchingCodes) {
1293
1294 if (statisticalSearchingCodes.size() > 0) {
1295 Map map = new HashMap();
1296 map.put("code", statisticalSearchingCodes.get(0).getCodeValue());
1297 List<StatisticalSearchRecord> statisticalSearchRecords = (List<StatisticalSearchRecord>) getBusinessObjectService().findMatching(StatisticalSearchRecord.class, map);
1298 if (statisticalSearchRecords.size() == 0) {
1299 if (statisticalSearchingCodes.get(0).getCodeValue() != null && !"".equals(statisticalSearchingCodes.get(0).getCodeValue())) {
1300 StatisticalSearchRecord statisticalSearchRecord = new StatisticalSearchRecord();
1301 statisticalSearchRecord.setCode(statisticalSearchingCodes.get(0).getCodeValue());
1302 statisticalSearchRecord.setName(statisticalSearchingCodes.get(0).getFullValue());
1303 getBusinessObjectService().save(statisticalSearchRecord);
1304 return statisticalSearchRecord;
1305 } else {
1306 return null;
1307 }
1308 }
1309 return statisticalSearchRecords.get(0);
1310 }
1311 return null;
1312 }
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350 protected ItemStatusRecord saveItemStatusRecord(String itemStatus) {
1351 Map map = new HashMap();
1352 map.put("code", itemStatus);
1353 List<ItemStatusRecord> itemStatusRecords = (List<ItemStatusRecord>) getBusinessObjectService().findMatching(ItemStatusRecord.class, map);
1354 if (itemStatusRecords.size() == 0) {
1355 if (itemStatus != null && !"".equals(itemStatus)) {
1356 ItemStatusRecord itemStatusRecord = new ItemStatusRecord();
1357 itemStatusRecord.setCode(itemStatus);
1358 itemStatusRecord.setName(itemStatus);
1359 getBusinessObjectService().save(itemStatusRecord);
1360 return itemStatusRecord;
1361 } else {
1362 return null;
1363 }
1364 }
1365 return itemStatusRecords.get(0);
1366 }
1367
1368 protected HighDensityStorageRecord saveHighDensityStorageRecord(HighDensityStorage highDensityStorage) {
1369
1370 HighDensityStorageRecord highDensityStorageRecord = new HighDensityStorageRecord();
1371 highDensityStorageRecord.setRow(highDensityStorage.getRow());
1372 highDensityStorageRecord.setModule(highDensityStorage.getModule());
1373 highDensityStorageRecord.setShelf(highDensityStorage.getShelf());
1374 getBusinessObjectService().save(highDensityStorageRecord);
1375 return highDensityStorageRecord;
1376 }
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431 protected void saveFormerIdentifierRecords(List<FormerIdentifier> formerIdentifierList, String itemId) {
1432 Map map = new HashMap();
1433 map.put("itemId", itemId);
1434 List<FormerIdentifierRecord> formerIdentifierRecordList = (List<FormerIdentifierRecord>) getBusinessObjectService().findMatching(FormerIdentifierRecord.class, map);
1435 if (formerIdentifierList.size() > 0) {
1436 List<FormerIdentifierRecord> formerIdentifierRecords = new ArrayList<FormerIdentifierRecord>();
1437 for (int i = 0; i < formerIdentifierList.size(); i++) {
1438 FormerIdentifier formerIdentifier = formerIdentifierList.get(i);
1439 if (formerIdentifier.getIdentifier() != null && formerIdentifier.getIdentifier().getIdentifierValue() != null && !"".equals(formerIdentifier.getIdentifier().getIdentifierValue())) {
1440
1441 FormerIdentifierRecord formerIdentifierRecord = new FormerIdentifierRecord();
1442 if (i < formerIdentifierRecordList.size()) {
1443 formerIdentifierRecord = formerIdentifierRecordList.get(i);
1444 }
1445 formerIdentifierRecord.setType(formerIdentifier.getIdentifierType());
1446 if (formerIdentifier.getIdentifier() != null)
1447 formerIdentifierRecord.setValue(formerIdentifier.getIdentifier().getIdentifierValue());
1448 formerIdentifierRecord.setItemId(itemId);
1449 formerIdentifierRecords.add(formerIdentifierRecord);
1450 }
1451 }
1452 if (formerIdentifierRecords.size() > 0) {
1453 getBusinessObjectService().save(formerIdentifierRecords);
1454 }
1455
1456 if (formerIdentifierRecordList.size() > formerIdentifierList.size()) {
1457 getBusinessObjectService().delete(formerIdentifierRecordList.subList(formerIdentifierList.size() - 1, formerIdentifierRecordList.size()));
1458 }
1459 }
1460 }
1461
1462 protected void saveItemNoteRecord(List<Note> noteList, String itemId) {
1463
1464 Map map = new HashMap();
1465 map.put("itemId", itemId);
1466 List<ItemNoteRecord> itemNoteRecordList = (List<ItemNoteRecord>) getBusinessObjectService().findMatching(ItemNoteRecord.class, map);
1467
1468
1469 if (noteList.size() > 0) {
1470 List<ItemNoteRecord> itemNoteRecords = new ArrayList<ItemNoteRecord>();
1471 for (int i = 0; i < noteList.size(); i++) {
1472 Note note = noteList.get(i);
1473 if (note.getType() != null && ("public".equalsIgnoreCase(note.getType()) || "nonPublic".equalsIgnoreCase(note.getType()))) {
1474 ItemNoteRecord itemNoteRecord = new ItemNoteRecord();
1475 if (i < itemNoteRecordList.size()) {
1476 itemNoteRecord = itemNoteRecordList.get(i);
1477 }
1478 itemNoteRecord.setType(note.getType());
1479 itemNoteRecord.setNote(note.getValue());
1480 itemNoteRecord.setItemId(itemId);
1481 itemNoteRecords.add(itemNoteRecord);
1482 }
1483 }
1484 if (itemNoteRecords.size() > 0) {
1485 getBusinessObjectService().save(itemNoteRecords);
1486 }
1487
1488 if (noteList.size() < itemNoteRecordList.size()) {
1489 getBusinessObjectService().delete(itemNoteRecordList.subList(noteList.size() - 1, itemNoteRecordList.size()));
1490 }
1491
1492 }
1493 }
1494
1495 protected void saveDonorList(List<DonorInfo> donorslist, String itemId) {
1496 Map map = new HashMap();
1497 map.put("itemId", itemId);
1498 List<OLEItemDonorRecord> itemDonorRecordList = (List<OLEItemDonorRecord>) getBusinessObjectService().findMatching(OLEItemDonorRecord.class, map);
1499 if(itemDonorRecordList!=null && itemDonorRecordList.size() >= 0) {
1500 getBusinessObjectService().delete(itemDonorRecordList);
1501 }
1502 if (donorslist.size() > 0) {
1503 List<OLEItemDonorRecord> oleItemDonorRecords = new ArrayList<OLEItemDonorRecord>();
1504 for (int i = 0; i < donorslist.size(); i++) {
1505 DonorInfo donorinfo = donorslist.get(i);
1506 if (donorinfo.getDonorCode() != null ) {
1507 OLEItemDonorRecord oleItemDonorRecord = new OLEItemDonorRecord();
1508 oleItemDonorRecord.setDonorPublicDisplay(donorinfo.getDonorPublicDisplay());
1509 oleItemDonorRecord.setDonorCode(donorinfo.getDonorCode());
1510 oleItemDonorRecord.setDonorNote(donorinfo.getDonorNote());
1511 oleItemDonorRecord.setItemId(itemId);
1512 oleItemDonorRecords.add(oleItemDonorRecord);
1513 }
1514 }
1515 if (oleItemDonorRecords.size() > 0) {
1516 getBusinessObjectService().save(oleItemDonorRecords);
1517 }
1518 }
1519 }
1520
1521 protected void saveCheckInLocationRecord(List<CheckInLocation> checkInLocationList, String itemId) {
1522
1523 Map map = new HashMap();
1524 map.put("itemId", itemId);
1525 List<LocationsCheckinCountRecord> locationsCheckinCountRecordList = (List<LocationsCheckinCountRecord>) getBusinessObjectService().findMatching(LocationsCheckinCountRecord.class, map);
1526 if (locationsCheckinCountRecordList != null && locationsCheckinCountRecordList.size() > 0) {
1527 LocationsCheckinCountRecord locationsCheckinCountRecord = locationsCheckinCountRecordList.get(0);
1528 CheckInLocation checkInLocation = checkInLocationList.get(0);
1529 locationsCheckinCountRecord.setLocationCount(checkInLocation.getCount());
1530 locationsCheckinCountRecord.setLocationName(checkInLocation.getName());
1531 locationsCheckinCountRecord.setLocationInhouseCount(checkInLocation.getInHouseCount());
1532 getBusinessObjectService().save(locationsCheckinCountRecord);
1533 } else {
1534
1535 CheckInLocation checkInLocation = checkInLocationList.get(0);
1536 LocationsCheckinCountRecord locationsCheckinCountRecord = new LocationsCheckinCountRecord();
1537 locationsCheckinCountRecord.setLocationCount(checkInLocation.getCount());
1538 locationsCheckinCountRecord.setLocationName(checkInLocation.getName());
1539 locationsCheckinCountRecord.setLocationInhouseCount(checkInLocation.getInHouseCount());
1540 locationsCheckinCountRecord.setItemId(itemId);
1541 getBusinessObjectService().save(locationsCheckinCountRecord);
1542
1543 }
1544
1545 }
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616 protected Item buildItemContent(ItemRecord itemRecord) {
1617 Item item = new Item();
1618 item.setItemIdentifier(DocumentUniqueIDPrefix.getPrefixedId(itemRecord.getUniqueIdPrefix(), itemRecord.getItemId()));
1619 item.setPurchaseOrderLineItemIdentifier(itemRecord.getPurchaseOrderItemLineId());
1620 item.setVendorLineItemIdentifier(itemRecord.getVendorLineItemId());
1621 item.setFund(itemRecord.getFund());
1622 item.setPrice(itemRecord.getPrice());
1623 item.setBarcodeARSL(itemRecord.getBarCodeArsl());
1624 item.setCopyNumber(itemRecord.getCopyNumber());
1625 item.setEnumeration(itemRecord.getEnumeration());
1626 item.setChronology(itemRecord.getChronology());
1627 item.setNumberOfPieces(itemRecord.getNumberOfPieces());
1628 item.setCheckinNote(itemRecord.getCheckInNote());
1629 item.setLocation(getLocationDetails(itemRecord.getLocation(), itemRecord.getLocationLevel()));
1630 if (itemRecord.getFormerIdentifierRecords() != null) {
1631 List<FormerIdentifier> formerIdList = new ArrayList<FormerIdentifier>();
1632 for (FormerIdentifierRecord formerIdentifierRecord : itemRecord.getFormerIdentifierRecords()) {
1633 FormerIdentifier formerIdentifier = new FormerIdentifier();
1634 Identifier identifier = new Identifier();
1635 identifier.setIdentifierValue(formerIdentifierRecord.getValue());
1636 formerIdentifier.setIdentifier(identifier);
1637 formerIdList.add(formerIdentifier);
1638 item.setFormerIdentifier(formerIdList);
1639 }
1640 }
1641
1642 AccessInformation accessInformation = new AccessInformation();
1643 accessInformation.setBarcode(itemRecord.getBarCode());
1644 Uri itemuri = new Uri();
1645 itemuri.setValue(itemRecord.getUri());
1646 accessInformation.setUri(itemuri);
1647 item.setAccessInformation(accessInformation);
1648 CallNumber itemCallNumber = new CallNumber();
1649 itemCallNumber.setNumber(itemRecord.getCallNumber());
1650 itemCallNumber.setPrefix(itemRecord.getCallNumberPrefix());
1651 ShelvingScheme itemShelvingScheme = new ShelvingScheme();
1652 if (itemRecord.getCallNumberTypeRecord() != null) {
1653 itemShelvingScheme.setCodeValue(itemRecord.getCallNumberTypeRecord().getCode());
1654 itemShelvingScheme.setFullValue(itemRecord.getCallNumberTypeRecord().getName());
1655 itemCallNumber.setShelvingScheme(itemShelvingScheme);
1656 }
1657 ShelvingOrder itemShelvingOrder = new ShelvingOrder();
1658 itemShelvingOrder.setCodeValue(itemRecord.getShelvingOrder());
1659 itemShelvingOrder.setFullValue(itemRecord.getShelvingOrder());
1660 itemCallNumber.setShelvingOrder(itemShelvingOrder);
1661 item.setCallNumber(itemCallNumber);
1662
1663 List<Note> notes = new ArrayList<Note>();
1664 if (itemRecord.getItemNoteRecords() != null) {
1665 List<ItemNoteRecord> itemNoteRecords = itemRecord.getItemNoteRecords();
1666 for (ItemNoteRecord itemNoteRecord : itemNoteRecords) {
1667 Note note = new Note();
1668 note.setType(itemNoteRecord.getType());
1669 note.setValue(itemNoteRecord.getNote());
1670 notes.add(note);
1671 }
1672 item.setNote(notes);
1673 }
1674 List<DonorInfo> donorInfoList = new ArrayList<DonorInfo>();
1675 if (itemRecord.getDonorList() != null) {
1676 List<OLEItemDonorRecord> oleItemDonorRecordList = itemRecord.getDonorList();
1677 for (OLEItemDonorRecord oleItemDonorRecord : oleItemDonorRecordList) {
1678 DonorInfo donorInfo = new DonorInfo();
1679 donorInfo.setDonorCode(oleItemDonorRecord.getDonorCode());
1680 donorInfo.setDonorPublicDisplay(oleItemDonorRecord.getDonorPublicDisplay());
1681 donorInfo.setDonorNote(oleItemDonorRecord.getDonorNote());
1682 donorInfoList.add(donorInfo);
1683 }
1684 item.setDonorInfo(donorInfoList);
1685 }
1686 if (itemRecord.getItemStatusRecord() != null) {
1687 ItemStatus itemStatus = new ItemStatus();
1688 itemStatus.setCodeValue(itemRecord.getItemStatusRecord().getCode());
1689 itemStatus.setFullValue(itemRecord.getItemStatusRecord().getCode());
1690 item.setItemStatus(itemStatus);
1691 }
1692 if (itemRecord.getItemTypeRecord() != null) {
1693 ItemType itemType = new ItemType();
1694 itemType.setCodeValue(itemRecord.getItemTypeRecord().getCode());
1695 itemType.setFullValue(itemRecord.getItemTypeRecord().getName());
1696 item.setItemType(itemType);
1697 }
1698 if (itemRecord.getItemTempTypeRecord() != null) {
1699 ItemType itemType = new ItemType();
1700 itemType.setCodeValue(itemRecord.getItemTempTypeRecord().getCode());
1701 itemType.setFullValue(itemRecord.getItemTempTypeRecord().getName());
1702 item.setTemporaryItemType(itemType);
1703 }
1704 List<StatisticalSearchingCode> statisticalSearchingCodes = new ArrayList<StatisticalSearchingCode>();
1705 StatisticalSearchingCode statisticalSearchingCode = new StatisticalSearchingCode();
1706
1707
1708
1709
1710 statisticalSearchingCodes.add(statisticalSearchingCode);
1711 item.setStatisticalSearchingCode(statisticalSearchingCodes);
1712 HighDensityStorage highDensityStorage = new HighDensityStorage();
1713
1714 if (itemRecord.getHighDensityStorageRecord() != null) {
1715 HighDensityStorageRecord highDensityStorageRecord = itemRecord.getHighDensityStorageRecord();
1716 highDensityStorage.setModule(highDensityStorageRecord.getModule());
1717 highDensityStorage.setRow(highDensityStorageRecord.getRow());
1718 highDensityStorage.setShelf(highDensityStorageRecord.getShelf());
1719 highDensityStorage.setTray(highDensityStorageRecord.getTray());
1720 }
1721 item.setHighDensityStorage(highDensityStorage);
1722 if (itemRecord.getEffectiveDate() != null) {
1723
1724
1725 SimpleDateFormat format1 = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss");
1726 SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
1727 Date effectiveDate = null;
1728 try {
1729 effectiveDate = format2.parse(itemRecord.getEffectiveDate().toString());
1730 } catch (ParseException e) {
1731 LOG.error("format string to Date " + e);
1732 }
1733 item.setItemStatusEffectiveDate(format1.format(effectiveDate).toString());
1734 }
1735 if(itemRecord.getStaffOnlyFlag() != null) {
1736 item.setStaffOnlyFlag(itemRecord.getStaffOnlyFlag());
1737 }
1738 if(itemRecord.getFastAddFlag() != null) {
1739 item.setFastAddFlag(Boolean.valueOf(itemRecord.getFastAddFlag()));
1740 }
1741 List<LocationsCheckinCountRecord> locationsCheckinCountRecords = itemRecord.getLocationsCheckinCountRecords();
1742 if (locationsCheckinCountRecords != null && locationsCheckinCountRecords.size() > 0) {
1743
1744 NumberOfCirculations numberOfCirculations = new NumberOfCirculations();
1745 List<CheckInLocation> checkInLocations = new ArrayList<CheckInLocation>();
1746 for (LocationsCheckinCountRecord locationsCheckinCountRecord : locationsCheckinCountRecords) {
1747
1748 CheckInLocation checkInLocation = new CheckInLocation();
1749 checkInLocation.setCount(locationsCheckinCountRecord.getLocationCount());
1750 checkInLocation.setName(locationsCheckinCountRecord.getLocationName());
1751 checkInLocation.setInHouseCount(locationsCheckinCountRecord.getLocationInhouseCount());
1752 checkInLocations.add(checkInLocation);
1753 }
1754 numberOfCirculations.setCheckInLocation(checkInLocations);
1755 item.setNumberOfCirculations(numberOfCirculations);
1756 }
1757 if (itemRecord.getClaimsReturnedFlag() != null) {
1758 item.setClaimsReturnedFlag(Boolean.valueOf(itemRecord.getClaimsReturnedFlag()));
1759 }
1760
1761 if (itemRecord.getClaimsReturnedFlagCreateDate() != null) {
1762
1763 SimpleDateFormat format1 = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss");
1764 SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
1765 Date claimReturnCreateDate = null;
1766 try {
1767 claimReturnCreateDate = format2.parse(itemRecord.getClaimsReturnedFlagCreateDate().toString());
1768 } catch (ParseException e) {
1769 LOG.error("format string to Date " + e);
1770 }
1771 item.setClaimsReturnedFlagCreateDate(format1.format(claimReturnCreateDate).toString());
1772
1773
1774
1775
1776 }
1777
1778 if (itemRecord.getDueDateTime() != null) {
1779
1780
1781
1782
1783
1784
1785 SimpleDateFormat format1 = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
1786 SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
1787 Date dueDateTime = null;
1788 try {
1789 dueDateTime = format2.parse(itemRecord.getDueDateTime().toString());
1790 } catch (ParseException e) {
1791 LOG.error("format string to Date " + e);
1792 }
1793 item.setDueDateTime(format1.format(dueDateTime).toString());
1794
1795
1796
1797
1798 }
1799
1800 if(itemRecord.getClaimsReturnedNote() != null){
1801 item.setClaimsReturnedNote(itemRecord.getClaimsReturnedNote());
1802 }
1803 item.setProxyBorrower(itemRecord.getProxyBorrower()!=null?itemRecord.getProxyBorrower():"");
1804 item.setCurrentBorrower(itemRecord.getCurrentBorrower()!=null?itemRecord.getCurrentBorrower():"");
1805 item.setItemDamagedStatus(itemRecord.isItemDamagedStatus());
1806 if(itemRecord.getDamagedItemNote()!=null){
1807 item.setDamagedItemNote(itemRecord.getDamagedItemNote());
1808 }
1809 if(itemRecord.isMissingPieceFlag()){
1810 item.setMissingPieceFlag(itemRecord.isMissingPieceFlag());
1811 }
1812 if(itemRecord.getMissingPieceFlagNote()!=null){
1813 item.setMissingPieceFlagNote(itemRecord.getMissingPieceFlagNote());
1814 }
1815 if (itemRecord.getMissingPieceEffectiveDate() != null) {
1816
1817
1818 SimpleDateFormat format1 = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss");
1819 SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
1820 Date effectiveDate = null;
1821 try {
1822 effectiveDate = format2.parse(itemRecord.getMissingPieceEffectiveDate().toString());
1823 } catch (ParseException e) {
1824 LOG.error("format string to Date " + e);
1825 }
1826 item.setMissingPieceEffectiveDate(format1.format(effectiveDate).toString());
1827 } else {
1828 SimpleDateFormat df = new SimpleDateFormat("MM/dd/yyyy");
1829 String date=df.format(new Date());
1830 item.setMissingPieceEffectiveDate(date);
1831 }
1832 if(itemRecord.getMissingPiecesCount()!=null){
1833 item.setMissingPiecesCount(itemRecord.getMissingPiecesCount());
1834 }
1835
1836
1837 return item;
1838 }
1839
1840 public LocationLevel createLocationLevel(String locationName, String locationLevelName) {
1841 LocationLevel locationLevel = null;
1842 if (StringUtils.isNotEmpty(locationName ) && StringUtils.isNotEmpty(locationLevelName)) {
1843 String[] locations = locationName.split("/");
1844 String[] locationLevels = locationLevelName.split("/");
1845 String locName = "";
1846 String levelName = "";
1847 if (locations.length > 0 ) {
1848 locName = locations[0];
1849 levelName = locationLevels[0];
1850 if (locationName.contains("/")) {
1851 locationName = locationName.replaceFirst(locations[0] + "/", "");
1852 } else {
1853 locationName = locationName.replace(locations[0], "");
1854 }
1855
1856 if (locationLevelName.contains("/")) {
1857 locationLevelName = locationLevelName.replaceFirst(locationLevels[0] + "/", "");
1858 } else {
1859 locationLevelName = locationLevelName.replace(locationLevels[0], "");
1860 }
1861 if (locName != null && locations.length != 0) {
1862 locationLevel = new LocationLevel();
1863 locationLevel.setLevel(levelName);
1864 locationLevel.setName(locName);
1865 locationLevel.setLocationLevel(createLocationLevel(locationName, locationLevelName));
1866 }
1867 }
1868 }
1869 return locationLevel;
1870 }
1871
1872
1873 private Location getLocationDetails(String locationName, String locationLevelName) {
1874 Location location = new Location();
1875
1876 LocationLevel locationLevel = createLocationLevel(locationName, locationLevelName);
1877 location.setLocationLevel(locationLevel);
1878 return location;
1879 }
1880
1881 protected OleHoldings buildHoldingsContent(HoldingsRecord holdingsRecord) {
1882 OleHoldings oleHoldings = new OleHoldings();
1883
1884
1885
1886 oleHoldings.setHoldingsIdentifier(DocumentUniqueIDPrefix.getPrefixedId(holdingsRecord.getUniqueIdPrefix(), holdingsRecord.getHoldingsId()));
1887 if (holdingsRecord.getReceiptStatusRecord() != null) {
1888 ReceiptStatusRecord receiptStatusRecord = holdingsRecord.getReceiptStatusRecord();
1889 if (receiptStatusRecord != null) {
1890 oleHoldings.setReceiptStatus(receiptStatusRecord.getCode());
1891 }
1892 }
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903 if (holdingsRecord.getLocation() != null) {
1904 Location location = getLocationDetails(holdingsRecord.getLocation(), holdingsRecord.getLocationLevel());
1905 oleHoldings.setLocation(location);
1906 }
1907 CallNumber callNumber = new CallNumber();
1908 if (holdingsRecord.getCallNumberTypeRecord() != null) {
1909 callNumber.setNumber(holdingsRecord.getCallNumber());
1910 ShelvingScheme shelvingScheme = new ShelvingScheme();
1911 shelvingScheme.setCodeValue(holdingsRecord.getCallNumberTypeRecord().getCode());
1912 shelvingScheme.setFullValue(holdingsRecord.getCallNumberTypeRecord().getName());
1913 callNumber.setShelvingScheme(shelvingScheme);
1914 ShelvingOrder shelvingOrder = new ShelvingOrder();
1915 shelvingOrder.setCodeValue(holdingsRecord.getShelvingOrder());
1916 shelvingOrder.setFullValue(holdingsRecord.getShelvingOrder());
1917 callNumber.setShelvingOrder(shelvingOrder);
1918 callNumber.setPrefix(holdingsRecord.getCallNumberPrefix());
1919
1920 oleHoldings.setCallNumber(callNumber);
1921 }
1922 if (holdingsRecord.getCopyNumber() != null) {
1923 oleHoldings.setCopyNumber(holdingsRecord.getCopyNumber());
1924
1925 }
1926 if (holdingsRecord.getExtentOfOwnerShipRecords() != null && holdingsRecord.getExtentOfOwnerShipRecords().size() > 0) {
1927 List<ExtentOfOwnership> extentOfOwnerships = new ArrayList<ExtentOfOwnership>();
1928 for (ExtentOfOwnerShipRecord extentOfOwnerShipRecord : holdingsRecord.getExtentOfOwnerShipRecords()) {
1929 ExtentOfOwnership extentOfOwnership = new ExtentOfOwnership();
1930 if (extentOfOwnerShipRecord.getExtentOfOwnerShipTypeRecord() != null) {
1931 extentOfOwnership.setTextualHoldings(extentOfOwnerShipRecord.getText());
1932 extentOfOwnership.setType(extentOfOwnerShipRecord.getExtentOfOwnerShipTypeRecord().getCode());
1933 }
1934
1935 if (extentOfOwnerShipRecord.getExtentNoteRecords() != null && extentOfOwnerShipRecord.getExtentNoteRecords().size() > 0) {
1936 for (ExtentNoteRecord extentNoteRecord : extentOfOwnerShipRecord.getExtentNoteRecords()) {
1937 Note note = new Note();
1938 note.setType(extentNoteRecord.getType());
1939 note.setValue(extentNoteRecord.getNote());
1940 extentOfOwnership.getNote().add(note);
1941 }
1942 } else {
1943 Note note = new Note();
1944 extentOfOwnership.getNote().add(note);
1945 }
1946
1947 extentOfOwnerships.add(extentOfOwnership);
1948 }
1949 oleHoldings.setExtentOfOwnership(extentOfOwnerships);
1950 }
1951
1952
1953 if (holdingsRecord.getHoldingsNoteRecords() != null && holdingsRecord.getHoldingsNoteRecords().size() > 0) {
1954 List<HoldingsNoteRecord> holdingsNoteRecords = holdingsRecord.getHoldingsNoteRecords();
1955 if (holdingsNoteRecords != null && holdingsNoteRecords.size() > 0) {
1956 List<Note> notes = new ArrayList<Note>();
1957 for (HoldingsNoteRecord holdingsNoteRecord : holdingsNoteRecords) {
1958 Note note = new Note();
1959 note.setType(holdingsNoteRecord.getType());
1960 note.setValue(holdingsNoteRecord.getNote());
1961 notes.add(note);
1962 }
1963 oleHoldings.setNote(notes);
1964 }
1965 }
1966
1967
1968
1969
1970 return oleHoldings;
1971 }
1972
1973 public void updateShelvingOrder(Item item, OleHoldings oleHolding) throws OleDocStoreException {
1974 String callNumber = null;
1975 String shelvingScheme = null;
1976 if (item != null) {
1977 if (item.getCallNumber() == null) {
1978 item.setCallNumber(new CallNumber());
1979 }
1980
1981
1982
1983 if (!(item.getCallNumber().getNumber() != null && item.getCallNumber().getNumber().trim().length() > 0)) {
1984
1985 if (oleHolding != null && oleHolding.getCallNumber() != null && oleHolding.getCallNumber().getNumber() != null &&
1986 oleHolding.getCallNumber().getShelvingScheme() != null && oleHolding.getCallNumber().getShelvingScheme().getCodeValue() != null) {
1987 callNumber = oleHolding.getCallNumber().getNumber();
1988 shelvingScheme = oleHolding.getCallNumber().getShelvingScheme().getCodeValue();
1989 }
1990 } else {
1991
1992
1993 callNumber = item.getCallNumber().getNumber();
1994
1995 if (item.getCallNumber().getShelvingScheme() != null) {
1996 shelvingScheme = item.getCallNumber().getShelvingScheme().getCodeValue();
1997 }
1998 }
1999 String shelvingOrd = "";
2000 if (callNumber != null && callNumber.trim().length() > 0 && shelvingScheme != null && shelvingScheme.trim().length() > 0) {
2001 callNumber = appendItemInfoToCalNumber(item, callNumber);
2002
2003 boolean isValid = validateCallNumber(callNumber, shelvingScheme);
2004 if (isValid) {
2005 shelvingOrd = buildSortableCallNumber(callNumber, shelvingScheme);
2006 } else {
2007 shelvingOrd = callNumber;
2008 }
2009 if (item.getCallNumber().getShelvingOrder() == null) {
2010 item.getCallNumber().setShelvingOrder(new ShelvingOrder());
2011 }
2012 item.getCallNumber().getShelvingOrder().setFullValue(shelvingOrd);
2013 }
2014 }
2015 }
2016
2017
2018 protected void processCallNumber(OleHoldings oleHolding) throws OleDocStoreException {
2019 if (oleHolding != null && oleHolding.getCallNumber() != null) {
2020
2021 CallNumber cNum = oleHolding.getCallNumber();
2022 computeCallNumberType(cNum);
2023 if (cNum.getNumber() != null && cNum.getNumber().trim().length() > 0) {
2024
2025 boolean isValid = validateCallNumber(cNum.getNumber(), cNum.getShelvingScheme().getCodeValue());
2026 String value = "";
2027 if (isValid) {
2028 value = buildSortableCallNumber(cNum.getNumber(), cNum.getShelvingScheme().getCodeValue());
2029 } else {
2030 value = cNum.getNumber();
2031 }
2032 if (cNum.getShelvingOrder() == null) {
2033 cNum.setShelvingOrder(new ShelvingOrder());
2034 }
2035 cNum.getShelvingOrder().setFullValue(value);
2036 }
2037 }
2038 }
2039
2040
2041
2042
2043
2044
2045 public void computeCallNumberType(CallNumber callNumber) {
2046 Set<String> validCallNumberTypeSet = CallNumberType.validCallNumberTypeCodeSet;
2047 if (callNumber != null) {
2048 if (callNumber.getShelvingScheme() != null) {
2049 String callNumberTypeCode = callNumber.getShelvingScheme().getCodeValue();
2050 String callNumberTypeName = "";
2051
2052 if ((StringUtils.isNotEmpty(callNumberTypeCode)) && (validCallNumberTypeSet
2053 .contains(callNumberTypeCode))) {
2054 callNumberTypeName = CallNumberType.valueOf(callNumberTypeCode).getDescription();
2055 callNumber.getShelvingScheme().setFullValue(callNumberTypeName);
2056 }
2057 }
2058 }
2059 }
2060
2061 protected boolean validateCallNumber(String callNumber, String codeValue) throws OleDocStoreException {
2062 boolean isValid = false;
2063 if (StringUtils.isNotEmpty(callNumber) && StringUtils.isNotEmpty(codeValue)) {
2064 org.kuali.ole.utility.callnumber.CallNumber callNumberObj = CallNumberFactory.getInstance().getCallNumber(codeValue);
2065 if (callNumberObj != null) {
2066 isValid = callNumberObj.isValid(callNumber);
2067 }
2068 }
2069 return isValid;
2070 }
2071
2072 protected String buildSortableCallNumber(String callNumber, String codeValue) throws OleDocStoreException {
2073 String shelvingOrder = "";
2074 if (StringUtils.isNotEmpty(callNumber) && StringUtils.isNotEmpty(codeValue)) {
2075 org.kuali.ole.utility.callnumber.CallNumber callNumberObj = CallNumberFactory.getInstance().getCallNumber(codeValue);
2076 if (callNumberObj != null) {
2077 shelvingOrder = callNumberObj.getSortableKey(callNumber);
2078
2079 }
2080 }
2081 return shelvingOrder;
2082 }
2083
2084 private String appendItemInfoToCalNumber(Item item, String callNumber) {
2085 if (item.getEnumeration() != null && item.getEnumeration().trim().length() > 0) {
2086 callNumber = callNumber + " " + item.getEnumeration().trim();
2087 }
2088 if (item.getChronology() != null && item.getChronology().trim().length() > 0) {
2089 callNumber = callNumber + " " + item.getChronology().trim();
2090
2091 }
2092 if (item.getCopyNumber() != null && item.getCopyNumber().trim().length() > 0) {
2093 callNumber = callNumber + " " + item.getCopyNumber().trim();
2094 }
2095 return callNumber;
2096 }
2097
2098 private String resolveLinkingWithBib(Instance instance) {
2099
2100 if (ProcessParameters.BULK_INGEST_IS_LINKING_ENABLED) {
2101 for (FormerIdentifier frids : instance.getFormerResourceIdentifier()) {
2102 Identifier identifier = frids.getIdentifier();
2103 try {
2104 if (identifier.getIdentifierValue() != null
2105 && identifier.getIdentifierValue().trim().length() != 0) {
2106 List<SolrDocument> solrDocs = ServiceLocator.getIndexerService()
2107 .getSolrDocument("SystemControlNumber",
2108 "\"" + identifier
2109 .getIdentifierValue()
2110 + "\"");
2111 if (solrDocs != null && solrDocs.size() > 0) {
2112 for (SolrDocument solrDoc : solrDocs) {
2113 if (checkApplicability(identifier.getIdentifierValue(),
2114 solrDoc.getFieldValue("SystemControlNumber"))) {
2115 instance.getResourceIdentifier().clear();
2116 String bibUniqueId = (String) solrDoc.get("uniqueId");
2117 instance.getResourceIdentifier().add(solrDoc.getFieldValue("id").toString());
2118 return bibUniqueId;
2119 }
2120 }
2121 }
2122 }
2123 } catch (Exception e) {
2124 LOG.error("Exception (ignored) while linking instance with bib: ", e);
2125 }
2126 }
2127 }
2128 return null;
2129 }
2130
2131 private boolean checkApplicability(Object value, Object fieldValue) {
2132 if (fieldValue instanceof Collection) {
2133 for (Object object : (Collection) fieldValue) {
2134 if (object.equals(value)) {
2135 return true;
2136 }
2137 }
2138 return false;
2139 } else {
2140 return value.equals(fieldValue);
2141 }
2142 }
2143
2144 private XMLGregorianCalendar getGregorianCalendar(Date date) throws DatatypeConfigurationException {
2145 GregorianCalendar gregory = new GregorianCalendar();
2146 gregory.setTime(date);
2147 XMLGregorianCalendar dealCloseDate = DatatypeFactory.newInstance()
2148 .newXMLGregorianCalendar(gregory);
2149 return dealCloseDate;
2150 }
2151
2152 private void effectiveDateItem(Item item, ItemRecord itemRecord, String effectiveDateForItem) {
2153 DateFormat df = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a");
2154 Timestamp effectiveDate = null;
2155 try {
2156 if (!"".equals(item.getItemStatusEffectiveDate()) && item.getItemStatusEffectiveDate() != null) {
2157 effectiveDate = new Timestamp(df.parse(effectiveDateForItem).getTime());
2158 itemRecord.setEffectiveDate(effectiveDate);
2159 }
2160
2161 } catch (Exception e) {
2162 LOG.error("Effective Date for Item" + e);
2163 }
2164 }
2165
2166 private void claimsReturnsCreateDateItem(Item item, ItemRecord itemRecord, String claimReturnCreateDate) {
2167 DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
2168 Timestamp claimReturnCreateDate1 = null;
2169 try {
2170 if (!"".equals(item.getClaimsReturnedFlagCreateDate()) && item.getClaimsReturnedFlagCreateDate() != null) {
2171 claimReturnCreateDate1 = new Timestamp(df.parse(claimReturnCreateDate).getTime());
2172 itemRecord.setClaimsReturnedFlagCreateDate(claimReturnCreateDate1);
2173 }
2174 } catch (Exception e) {
2175 LOG.error("Effective Date for Item" + e);
2176 }
2177 }
2178
2179 private void dueDateTime(Item item, ItemRecord itemRecord, String dueDateTime) {
2180 DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
2181 Timestamp dueDateTime1 = null;
2182 try {
2183 if (!"".equals(item.getDueDateTime()) && item.getDueDateTime() != null) {
2184 dueDateTime1 = new Timestamp(df.parse(dueDateTime).getTime());
2185 itemRecord.setDueDateTime(dueDateTime1);
2186 }
2187 } catch (Exception e) {
2188 LOG.error("Effective Date for Item" + e);
2189 }
2190 }
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211 public void saveHoldingsRecordAdditonalAttributesForDate(HoldingsRecord holdingsRecord ,AdditionalAttributes additionalAttributes){
2212 if(additionalAttributes != null && additionalAttributes.getAttribute(AdditionalAttributes.HOLDINGS_CREATED_BY) != null){
2213 holdingsRecord.setCreatedBy(additionalAttributes.getAttribute(AdditionalAttributes.HOLDINGS_CREATED_BY));
2214 }
2215 try {
2216 if(additionalAttributes != null && additionalAttributes.getAttribute(AdditionalAttributes.HOLDINGS_DATE_ENTERED) != null){
2217
2218 DateFormat df = new SimpleDateFormat("yyyy-mm-dd HH:mm:ss");
2219 Timestamp createdDate = null;
2220 String createdDateForHoldings = additionalAttributes.getAttribute(AdditionalAttributes.HOLDINGS_DATE_ENTERED);
2221
2222 createdDate = new Timestamp(df.parse(createdDateForHoldings).getTime());
2223 holdingsRecord.setCreatedDate(createdDate);
2224 }
2225 } catch (Exception e) {
2226 LOG.error("Created Date for Holdings" + e);
2227 }
2228 }
2229 }