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