1 package org.kuali.ole.docstore.document;
2
3 import org.apache.commons.lang.StringUtils;
4 import org.apache.solr.common.SolrDocument;
5 import org.kuali.ole.docstore.OleDocStoreException;
6 import org.kuali.ole.docstore.model.enums.DocCategory;
7 import org.kuali.ole.docstore.model.enums.DocFormat;
8 import org.kuali.ole.docstore.model.enums.DocType;
9 import org.kuali.ole.docstore.model.xmlpojo.ingest.*;
10 import org.kuali.ole.docstore.model.xmlpojo.work.instance.oleml.*;
11 import org.kuali.ole.docstore.model.xstream.work.instance.oleml.WorkHoldingOlemlRecordProcessor;
12 import org.kuali.ole.docstore.model.xstream.work.instance.oleml.WorkInstanceOlemlRecordProcessor;
13 import org.kuali.ole.docstore.model.xstream.work.instance.oleml.WorkItemOlemlRecordProcessor;
14 import org.kuali.ole.docstore.model.xstream.work.instance.oleml.WorkSourceHoldingOlemlRecordProcessor;
15 import org.kuali.ole.docstore.process.ProcessParameters;
16 import org.kuali.ole.docstore.repository.WorkBibNodeManager;
17 import org.kuali.ole.docstore.repository.WorkInstanceNodeManager;
18 import org.kuali.ole.docstore.service.BeanLocator;
19 import org.kuali.ole.docstore.service.ServiceLocator;
20 import org.kuali.ole.docstore.util.ItemExistsException;
21 import org.kuali.ole.pojo.OleException;
22 import org.kuali.ole.utility.callnumber.CallNumberFactory;
23 import org.kuali.ole.utility.callnumber.CallNumberType;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26
27 import javax.jcr.Node;
28 import javax.jcr.NodeIterator;
29 import javax.jcr.RepositoryException;
30 import javax.jcr.Session;
31 import java.io.FileNotFoundException;
32 import java.util.*;
33
34 import static org.kuali.ole.docstore.process.ProcessParameters.FILE;
35
36
37
38
39
40
41
42
43
44 public class WorkInstanceDocumentManager
45 extends AbstractDocumentManager {
46
47 private static WorkInstanceDocumentManager ourInstance = null;
48 private WorkInstanceOlemlRecordProcessor olemlProcessor = new WorkInstanceOlemlRecordProcessor();
49 private static final Logger LOG = LoggerFactory
50 .getLogger(WorkInstanceDocumentManager.class);
51
52 public static WorkInstanceDocumentManager getInstance() {
53 if (null == ourInstance) {
54 ourInstance = new WorkInstanceDocumentManager();
55 }
56 return ourInstance;
57 }
58
59 protected WorkInstanceDocumentManager() {
60 super();
61 this.nodeManager = WorkInstanceNodeManager.getInstance();
62 }
63
64 @Override
65 public void modifyDocumentContent(RequestDocument document, String nodeIdentifier, String parentNodeIdentifier) {
66
67
68 if (document.getContent().getContentObject() instanceof OleHoldings) {
69 ((OleHoldings) document.getContent().getContentObject()).setHoldingsIdentifier(nodeIdentifier);
70 document.getContent()
71 .setContent(olemlProcessor.toXML((OleHoldings) document.getContent().getContentObject()));
72 }
73 else if (document.getContent().getContentObject() instanceof SourceHoldings) {
74 ((SourceHoldings) document.getContent().getContentObject()).setHoldingsIdentifier(nodeIdentifier);
75 document.getContent()
76 .setContent(olemlProcessor.toXML((SourceHoldings) document.getContent().getContentObject()));
77 }
78 else if (document.getContent().getContentObject() instanceof Item) {
79 ((Item) document.getContent().getContentObject()).setItemIdentifier(nodeIdentifier);
80 document.getContent().setContent(olemlProcessor.toXML((Item) document.getContent().getContentObject()));
81 }
82 else if (document.getContent().getContentObject() instanceof Instance) {
83 Instance inst = ((Instance) document.getContent().getContentObject());
84 inst.setInstanceIdentifier(parentNodeIdentifier);
85 InstanceCollection instanceCollection = new InstanceCollection();
86 ArrayList<Instance> oleinsts = new ArrayList<Instance>();
87 oleinsts.add(inst);
88 instanceCollection.setInstance((oleinsts));
89 document.getContent().setContent(olemlProcessor.toXML(instanceCollection));
90 }
91 }
92
93 @Override
94 public Node storeDocument(RequestDocument requestDocument, Session session, ResponseDocument responseDocument) throws OleDocStoreException {
95 Node fileNode = null;
96 String validateMsg = null;
97 try {
98 AdditionalAttributes additionalAttributes = requestDocument.getAdditionalAttributes();
99 modifyAdditionalAttributes(requestDocument, null);
100
101
102 Node parentNode = nodeManager.getParentNode(requestDocument, session);
103 String fileName = requestDocument.getFormat() + FILE;
104
105
106 fileNode = nodeManager.createFileNode(requestDocument, fileName, parentNode, session);
107
108 if (isVersioningEnabled()) {
109 nodeManager.enableVersioning(fileNode);
110 }
111 if (requestDocument.getContent().getContentObject() != null) {
112 InstanceCollection instColl = (InstanceCollection) requestDocument.getContent().getContentObject();
113 for (Instance inst : instColl.getInstance()) {
114 List<String> resIdList = new ArrayList<String>();
115 resIdList.addAll(inst.getResourceIdentifier());
116 for (String resId : inst.getResourceIdentifier()) {
117 if (resId != null && resId.length() > 0) {
118 try{
119 Node bibNode = nodeManager.getNodeByUUID(session,resId);
120 WorkBibNodeManager bibNodeManager = WorkBibNodeManager.getInstance();
121 bibNodeManager.linkNodes(bibNode, fileNode, session);
122 }
123 catch(Exception e){
124 resIdList.remove(resId);
125 }
126 }
127 }
128 inst.setResourceIdentifier(resIdList);
129 }
130 }
131 buildResponseDocument(requestDocument,session,responseDocument);
132 if(validateMsg != null)
133 {
134 LOG.debug("in if validation message not null-->"+validateMsg);
135 responseDocument.setStatusMessage(validateMsg);
136 }
137 else
138 {
139
140 responseDocument.setStatusMessage("Document ingested successfully.");
141 }
142 }
143
144 catch (Exception e) {
145 throw new OleDocStoreException(e);
146 }
147 return fileNode;
148 }
149
150 @Override
151 protected void modifyContent(RequestDocument reqDoc, Session session, Node nodeByUUID) throws RepositoryException, FileNotFoundException, OleDocStoreException {
152 setIdentifierValueInContent(reqDoc);
153 RequestDocument linkReqInfo = new RequestDocument();
154 if (reqDoc.getLinkedRequestDocuments() != null && reqDoc.getLinkedRequestDocuments().size() > 0) {
155 for (Iterator<RequestDocument> linkIterator = reqDoc.getLinkedRequestDocuments().iterator(); linkIterator
156 .hasNext(); ) {
157 linkReqInfo = linkIterator.next();
158 if (linkReqInfo != null && linkReqInfo.getId() != null && linkReqInfo.getType().equalsIgnoreCase(
159 DocType.INSTANCE.getCode())) {
160 if(nodeByUUID.hasProperty("instanceIdentifier")){
161 String instanceIds = nodeByUUID.getProperty("instanceIdentifier").getString() + "," + linkReqInfo.getId();
162 nodeByUUID.setProperty("instanceIdentifier" , instanceIds);
163 }
164 else{
165 nodeByUUID.setProperty("instanceIdentifier", linkReqInfo.getId());
166 }
167 }
168 }
169 }
170 }
171
172 @Override
173 protected void addNewRecordsToDocStore(RequestDocument requestDocument, Session session)
174 throws OleDocStoreException {
175 if (requestDocument.getContent().getContent() == null && requestDocument.getId() != null) {
176 for (RequestDocument linkedItemDocument : requestDocument.getLinkedRequestDocuments()) {
177 if (DocType.ITEM.getDescription().equalsIgnoreCase(linkedItemDocument.getType())
178 && linkedItemDocument.getContent().getContent() != null) {
179 nodeManager.ingestItemRecForInstance(linkedItemDocument, requestDocument.getId(), session);
180 }
181 }
182 }
183 }
184
185
186
187
188
189
190
191
192
193
194
195
196
197 @Override
198 public ResponseDocument bind(RequestDocument requestDocument, Session session, String operation) throws OleDocStoreException, RepositoryException, OleException, FileNotFoundException {
199 List<RequestDocument> requestDocumentList = new ArrayList<RequestDocument>();
200 String bindFail = "binding failed";
201 try {
202
203
204 updatePropertiesOfInstanceNode(requestDocument, session, operation);
205 updatePropertiesOfBibNodes(requestDocument, session, operation);
206 getContent(requestDocument, session);
207
208
209
210
211
212 updateContentXmlOfInstance(requestDocument, session);
213
214
215
216
217
218 } catch (Exception e) {
219 LOG.info(
220 "Document was updated in indexer but not in docStore, trying to rollback the changes from indexer",
221 e);
222
223 LOG.info(bindFail, e);
224 throw new OleDocStoreException(bindFail, e);
225 }
226 return buildResponseForBind(requestDocument);
227 }
228
229
230 @Override
231 public ResponseDocument unbind(RequestDocument requestDocument, Session session, String operation) throws OleDocStoreException, RepositoryException, OleException, FileNotFoundException {
232 List<RequestDocument> requestDocumentList = new ArrayList<RequestDocument>();
233 String bindFail = "unbinding failed";
234 try {
235
236
237 updatePropertiesOfInstanceNode(requestDocument, session, operation);
238 updatePropertiesOfBibNodes(requestDocument, session, operation);
239 getContent(requestDocument, session);
240
241
242
243
244
245 updateContentXmlOfInstance(requestDocument, session);
246
247
248
249
250
251 } catch (Exception e) {
252 LOG.info(
253 "Document was updated in indexer but not in docStore, trying to rollback the changes from indexer",
254 e);
255
256 LOG.info(bindFail, e);
257 throw new OleDocStoreException(bindFail, e);
258 }
259 return buildResponseForBind(requestDocument);
260 }
261
262 @Override
263 public List<ResponseDocument> deleteVerify(List<RequestDocument> requestDocument, Session session) {
264 return null;
265 }
266
267 @Override
268 public ResponseDocument deleteVerify(RequestDocument requestDocument, Session session) throws Exception {
269
270 List<String> instanceIdentifierList = new ArrayList<String>();
271 ResponseDocument responseDocument = new ResponseDocument();
272 Node instanceNode = session.getNodeByIdentifier(requestDocument.getUuid());
273 String bibIdentifier = instanceNode.getProperty("bibIdentifier").getString();
274 String[] bibIds = bibIdentifier.split(",");
275 if(bibIds.length>1){
276 responseDocument.setCategory(requestDocument.getCategory());
277 responseDocument.setType(requestDocument.getType());
278 responseDocument.setFormat(requestDocument.getFormat());
279 responseDocument.setUuid(requestDocument.getUuid());
280 responseDocument.setStatus("failure'");
281 responseDocument.setStatusMessage("Instance is bound with more than one bib. So deletion cannot be done");
282 return responseDocument;
283 }
284 boolean exists= checkInstancesOrItemsExistsInOLE(requestDocument.getUuid(),session);
285 if(exists){
286 responseDocument.setId(requestDocument.getId());
287 responseDocument.setCategory(requestDocument.getCategory());
288 responseDocument.setType(requestDocument.getType());
289 responseDocument.setFormat(requestDocument.getFormat());
290 responseDocument.setUuid(requestDocument.getUuid());
291 responseDocument.setStatus("failure'");
292 responseDocument.setStatusMessage("Instances or Items in use. So deletion cannot be done");
293 return responseDocument;
294 }
295 String instanceIdentifier = "";
296 String bibIdentifierValue=bibIds[0];
297 Node bibUUID = session.getNodeByIdentifier(bibIdentifierValue);
298 instanceIdentifier = bibUUID.getProperty("instanceIdentifier").getString();
299 String[] instanceIds = instanceIdentifier.split(",");
300 for (String instanceId : instanceIds) {
301 instanceIdentifierList.add(instanceId);
302 }
303 if(instanceIdentifierList.size()==1){
304 responseDocument.setUuid(bibIdentifierValue);
305 responseDocument.setCategory(DocCategory.WORK.getCode());
306 responseDocument.setType(DocType.BIB.getDescription());
307 responseDocument.setFormat(DocFormat.MARC.getCode());
308 responseDocument.setStatus("success");
309 responseDocument.setStatusMessage("success");
310
311 }
312 else{
313 responseDocument.setUuid(requestDocument.getUuid());
314 responseDocument.setId(requestDocument.getId());
315 responseDocument.setCategory(requestDocument.getCategory());
316 responseDocument.setType(requestDocument.getType());
317 responseDocument.setFormat(requestDocument.getFormat());
318 responseDocument.setStatus("success");
319 responseDocument.setStatusMessage("success");
320 }
321 return responseDocument;
322 }
323 @Override
324 public ResponseDocument delete(RequestDocument requestDocument, Session session) throws Exception {
325 DocumentManager documentManager = null;
326 ResponseDocument responseDocument = new ResponseDocument();
327 ResponseDocument responseDocumentFromDeleteVerify = deleteVerify(requestDocument, session);
328
329 String status = responseDocumentFromDeleteVerify.getStatus();
330 if (status.equalsIgnoreCase("success")) {
331 if (responseDocumentFromDeleteVerify.getCategory().equalsIgnoreCase("work")
332 && responseDocumentFromDeleteVerify.getFormat().equalsIgnoreCase("marc") && responseDocumentFromDeleteVerify.getType()
333 .equalsIgnoreCase(
334 "bibliographic")) {
335 RequestDocument requestDocumentForBib= prepareRequestDocument(responseDocumentFromDeleteVerify);
336 documentManager = BeanLocator.getDocumentManagerFactory().getDocumentManager(requestDocumentForBib);
337 responseDocument = documentManager.delete(requestDocumentForBib, session);
338 }
339 else if (responseDocumentFromDeleteVerify.getCategory().equalsIgnoreCase("work")
340 && responseDocumentFromDeleteVerify.getFormat().equalsIgnoreCase("oleml") && responseDocumentFromDeleteVerify.getType()
341 .equalsIgnoreCase(
342 "instance")) {
343
344
345 List<String> instanceIdentifierList = new ArrayList<String>();
346 instanceIdentifierList.add(requestDocument.getUuid());
347 deLinkInstanceFromBib(requestDocument.getUuid(), session);
348 deleteFromRepository(instanceIdentifierList, session);
349 }
350 }
351
352 return responseDocument;
353 }
354 private void deLinkInstanceFromBib(String instanceIdentifier,Session session) throws Exception{
355 List<String> instanceIdentifierList = new ArrayList<String>();
356 Node instanceNode= session.getNodeByIdentifier(instanceIdentifier);
357 String bibIdentifier=instanceNode.getProperty("bibIdentifier").getString();
358 Node bibNode=session.getNodeByIdentifier(bibIdentifier);
359 String instanceIdentifiers=bibNode.getProperty("instanceIdentifier").getString();
360 String[] instanceIds = instanceIdentifiers.split(",");
361 StringBuffer instaceIdentifiersStringBuffer=new StringBuffer();
362 if(instanceIds.length>1){
363 for (String instanceId : instanceIds) {
364 if(!instanceId.equalsIgnoreCase(instanceIdentifier)){
365 instaceIdentifiersStringBuffer.append(instanceId);
366 instaceIdentifiersStringBuffer.append(",");
367 }
368 }
369 }
370 String modifierInstanceIdentifiers= instaceIdentifiersStringBuffer.toString();
371 String modified= modifierInstanceIdentifiers.substring(0, modifierInstanceIdentifiers.length() - 1);
372 bibNode.setProperty("instanceIdentifier",modified);
373
374
375
376 }
377
378
379
380
381
382
383
384
385 private ResponseDocument buildResponseForBind(RequestDocument requestDocument) {
386 ResponseDocument responseDocument = new ResponseDocument();
387 responseDocument.setId(requestDocument.getId());
388 responseDocument.setCategory(requestDocument.getCategory());
389 responseDocument.setType(requestDocument.getType());
390 responseDocument.setFormat(requestDocument.getFormat());
391 responseDocument.setUuid(requestDocument.getUuid());
392 List<RequestDocument> linkedRequestDocuments = requestDocument.getLinkedRequestDocuments();
393 List<ResponseDocument> linkedResponseDocumentsList = new ArrayList<ResponseDocument>();
394 for (RequestDocument linkedRequestDocument : linkedRequestDocuments) {
395
396 ResponseDocument linkedResponseDocument = new ResponseDocument();
397 linkedResponseDocument.setCategory(linkedRequestDocument.getCategory());
398 linkedResponseDocument.setType(linkedRequestDocument.getType());
399 linkedResponseDocument.setFormat(linkedRequestDocument.getFormat());
400 linkedResponseDocument.setId(linkedRequestDocument.getId());
401 linkedRequestDocument.setUser(linkedRequestDocument.getUuid());
402 linkedResponseDocumentsList.add(linkedResponseDocument);
403
404 }
405 responseDocument.setLinkedDocuments(linkedResponseDocumentsList);
406
407
408 return responseDocument;
409 }
410
411
412
413
414
415
416
417
418
419 private void updatePropertiesOfInstanceNode(RequestDocument requestDocument, Session session, String operation) throws RepositoryException, OleDocStoreException, OleException {
420 if (operation.equalsIgnoreCase("bind")) {
421 LOG.debug("requestDocument.getUuid()-->" + requestDocument.getUuid());
422 Node nodeByUUID = session.getNodeByIdentifier(requestDocument.getUuid());
423 StringBuilder bibIdentifierList = new StringBuilder();
424 LOG.info("bib id-->" + nodeByUUID.getProperty("bibIdentifier").getString());
425 String bibIdentifier = nodeByUUID.getProperty("bibIdentifier").getString();
426 bibIdentifierList.append(bibIdentifier);
427 List<RequestDocument> linkedRequestDocuments = requestDocument.getLinkedRequestDocuments();
428 for (RequestDocument linkedRequestDocument : linkedRequestDocuments) {
429
430 bibIdentifierList.append(",");
431 bibIdentifierList.append(linkedRequestDocument.getUuid());
432 }
433 LOG.info("bibIdentifierList-->" + bibIdentifierList.toString());
434 nodeByUUID.setProperty("bibIdentifier", bibIdentifierList.toString());
435
436
437 } else if (operation.equalsIgnoreCase("unbind")) {
438 Node nodeByUUID = session.getNodeByIdentifier(requestDocument.getUuid());
439 List<String> bibIdentifierList = new ArrayList<String>();
440 String bibIdentifier = nodeByUUID.getProperty("bibIdentifier").getString();
441 String[] bibIdentifierSplitter = bibIdentifier.split(",");
442 for (String bibId : bibIdentifierSplitter) {
443 bibIdentifierList.add(bibId);
444
445 }
446 List<RequestDocument> linkedRequestDocuments = requestDocument.getLinkedRequestDocuments();
447 for (RequestDocument linkedRequestDocument : linkedRequestDocuments) {
448 if (bibIdentifierList.contains(linkedRequestDocument.getUuid())) {
449 bibIdentifierList.remove(linkedRequestDocument.getUuid());
450 }
451
452 }
453 LOG.info("bibIdentifierList after removing the bibids-->" + bibIdentifierList.toString());
454 nodeByUUID.setProperty("bibIdentifier", bibIdentifierList.toString());
455
456
457 }
458
459 }
460
461
462
463
464
465
466 private void getContent(RequestDocument requestDocument, Session session) throws OleDocStoreException {
467 DocumentManager documentManager = BeanLocator.getDocumentManagerFactory().getDocumentManager(requestDocument);
468 ResponseDocument responseDocument = documentManager.checkout(requestDocument, session);
469 requestDocument.setContent(responseDocument.getContent());
470 List<RequestDocument> linkedRequestDocuments = requestDocument.getLinkedRequestDocuments();
471
472 for (RequestDocument linkedRequestDocument : linkedRequestDocuments) {
473 DocumentManager documentManagerForLink = BeanLocator.getDocumentManagerFactory().getDocumentManager(linkedRequestDocument);
474 linkedRequestDocument.setContent(documentManagerForLink.checkout(linkedRequestDocument, session).getContent());
475
476 }
477 }
478
479
480
481
482
483
484
485
486 private void updatePropertiesOfBibNodes(RequestDocument requestDocument, Session session, String operation) throws RepositoryException, OleException {
487 List<RequestDocument> linkedReqDocs = requestDocument.getLinkedRequestDocuments();
488 for (RequestDocument linkedReqDoc : linkedReqDocs) {
489 if (operation.equalsIgnoreCase("bind")) {
490
491 Node nodeByUUID = null;
492 StringBuilder instanceIdentifierList = new StringBuilder();
493 nodeByUUID = session.getNodeByIdentifier(linkedReqDoc.getUuid());
494 String instanceIdentifier = nodeByUUID.getProperty("instanceIdentifier").getString();
495 LOG.debug("instanceIdentifier id-->" + instanceIdentifier);
496 instanceIdentifierList.append(instanceIdentifier);
497 instanceIdentifierList.append(",");
498 instanceIdentifierList.append(requestDocument.getUuid());
499 LOG.info("instanceIdentifierList-->" + instanceIdentifierList.toString());
500 nodeByUUID.setProperty("instanceIdentifier", instanceIdentifierList.toString());
501 } else if (operation.equalsIgnoreCase("unbind")) {
502 Node nodeByUUID = null;
503 List<String> instanceIdentifierList = new ArrayList<String>();
504 nodeByUUID = session.getNodeByIdentifier(linkedReqDoc.getUuid());
505 String instanceIdentifier = nodeByUUID.getProperty("instanceIdentifier").getString();
506 LOG.debug("instanceIdentifier id-->" + instanceIdentifier);
507 String[] instanceIdentifierSplitter = instanceIdentifier.split(",");
508 for (String instanceId : instanceIdentifierSplitter) {
509 instanceIdentifierList.add(instanceId);
510 }
511 if (instanceIdentifierList.contains(requestDocument.getUuid())) {
512 instanceIdentifierList.remove(requestDocument.getUuid());
513 }
514
515 LOG.info("instanceIdentifierList after remove-->" + instanceIdentifierList.toString());
516 nodeByUUID.setProperty("instanceIdentifier", instanceIdentifierList.toString());
517
518 }
519 }
520 }
521
522
523
524
525
526
527
528
529
530 private void updateContentXmlOfInstance(RequestDocument requestDocument, Session session) throws RepositoryException, OleException, FileNotFoundException, OleDocStoreException {
531 Node nodeByUUID = session.getNodeByIdentifier(requestDocument.getUuid());
532 String content = checkOutContent(nodeByUUID, DocType.INSTANCE.getCode(), "chuntley");
533 nodeByUUID.setProperty("jcr:data", content);
534 List<RequestDocument> linkedRequestDocuments = requestDocument.getLinkedRequestDocuments();
535 for (RequestDocument linkedRequestDocument : linkedRequestDocuments) {
536 Node linkNodeByUUID = session.getNodeByIdentifier(linkedRequestDocument.getUuid());
537 LOG.info("link getIdentifier-->" + linkNodeByUUID.getIdentifier());
538 String linkContent = checkOutContent(linkNodeByUUID, DocType.BIB.getDescription(), "chuntley");
539 linkNodeByUUID.getNode("jcr:content").setProperty("jcr:data", linkContent);
540 }
541 }
542
543 @Override
544 protected String checkOutContent(Node nodeByUUID, String format, String user)
545 throws RepositoryException, OleDocStoreException, FileNotFoundException {
546 String content = null;
547 if (nodeByUUID.getName().equalsIgnoreCase(ProcessParameters.NODE_INSTANCE)) {
548 content = nodeManager.getInstanceData(nodeByUUID);
549 }
550 else {
551 content = nodeManager.getData(nodeByUUID);
552 }
553 return content;
554 }
555
556
557
558
559
560
561
562
563
564 public List<RequestDocument> getParsedHoldingsNItemDocuments(RequestDocument instanceDoc,
565 List<String> linkedBibIds) throws OleDocStoreException {
566 List<RequestDocument> parsedItemNHoldingsDocuments = new ArrayList<RequestDocument>();
567 if (instanceDoc != null && DocCategory.WORK.isEqualTo(instanceDoc.getCategory()) && DocType.INSTANCE.isEqualTo(
568 instanceDoc.getType()) && DocFormat.OLEML.isEqualTo(instanceDoc.getFormat())) {
569 String docContent = instanceDoc.getContent().getContent();
570 InstanceCollection instanceCollection = olemlProcessor.fromXML(docContent);
571 instanceDoc.getContent().setContentObject(instanceCollection);
572
573 if (instanceCollection.getInstance() != null && instanceCollection.getInstance().size() > 0) {
574 Instance instance = instanceCollection.getInstance().get(0);
575 resolveLinkingWithBib(instance);
576
577 if (instance.getResourceIdentifier().size() == 1) {
578 if (instance.getResourceIdentifier().get(0) == null || ""
579 .equals(instance.getResourceIdentifier().get(0))) {
580 instance.getResourceIdentifier().remove(0);
581 }
582 }
583 if (linkedBibIds != null && linkedBibIds.size() > 0) {
584 for (String likedBibId : linkedBibIds) {
585 instance.getResourceIdentifier().add(likedBibId);
586 }
587 }
588 parsedItemNHoldingsDocuments.add(generateInstanceDocument(instance));
589
590 OleHoldings oleHolding = instance.getOleHoldings();
591 processCallNumber(oleHolding);
592 RequestDocument rdHol = (RequestDocument) instanceDoc.clone();
593 Content content = new Content();
594 content.setContent(olemlProcessor.toXML(oleHolding));
595 content.setContentObject(oleHolding);
596 rdHol.setContent(content);
597 if (oleHolding != null && oleHolding.getExtension() != null) {
598 rdHol.setAdditionalAttributes(getFirstAdditionalAttributes(oleHolding.getExtension()));
599 }
600 parsedItemNHoldingsDocuments.add(rdHol);
601
602 SourceHoldings sourceHoldings = instance.getSourceHoldings();
603 RequestDocument rdSrcHol = (RequestDocument) instanceDoc.clone();
604 Content sourceHolContent = new Content();
605 sourceHolContent.setContent(olemlProcessor.toXML(sourceHoldings));
606 sourceHolContent.setContentObject(sourceHoldings);
607 rdSrcHol.setContent(sourceHolContent);
608 if (sourceHoldings != null && sourceHoldings.getExtension() != null) {
609 rdSrcHol.setAdditionalAttributes(getFirstAdditionalAttributes(sourceHoldings.getExtension()));
610 }
611 parsedItemNHoldingsDocuments.add(rdSrcHol);
612
613 if (instance.getItems() == null) {
614 instance.setItems(new Items());
615 }
616 if (instance.getItems().getItem() == null ) {
617 instance.getItems().getItem().add(new Item());
618 }
619 if (instance.getItems().getItem() != null && instance.getItems().getItem().size() == 0) {
620 instance.getItems().getItem().add(new Item());
621 }
622 for (Item oleItem : instance.getItems().getItem()) {
623 RequestDocument rdItm = (RequestDocument) instanceDoc.clone();
624 if(oleItem.getCallNumber() != null){
625 computeCallNumberType(oleItem.getCallNumber());
626 }
627 updateShelvingOrder(oleItem, oleHolding);
628 Content itemContent = new Content();
629 itemContent.setContent(olemlProcessor.toXML(oleItem));
630 itemContent.setContentObject(oleItem);
631 rdItm.setContent(itemContent);
632 if (oleItem != null && oleItem.getExtension() != null) {
633 rdItm.setAdditionalAttributes(getFirstAdditionalAttributes(oleItem.getExtension()));
634 }
635 parsedItemNHoldingsDocuments.add(rdItm);
636 }
637 }
638 }
639 return parsedItemNHoldingsDocuments;
640 }
641
642 protected void processCallNumber(OleHoldings oleHolding) throws OleDocStoreException {
643 if (oleHolding != null && oleHolding.getCallNumber() != null) {
644
645 CallNumber cNum = oleHolding.getCallNumber();
646 computeCallNumberType(cNum);
647 if (cNum.getNumber() != null && cNum.getNumber().trim().length() > 0) {
648
649 boolean isValid = validateCallNumber(cNum.getNumber(), cNum.getShelvingScheme().getCodeValue());
650 String value = "";
651 if (isValid) {
652 value = buildSortableCallNumber(cNum.getNumber(), cNum.getShelvingScheme().getCodeValue());
653 }
654 else {
655 value = cNum.getNumber();
656 }
657 if (cNum.getShelvingOrder() == null) {
658 cNum.setShelvingOrder(new ShelvingOrder());
659 }
660 cNum.getShelvingOrder().setFullValue(value);
661 }
662 }
663 }
664
665 public void validateCallNumber(CallNumber cNum) throws OleDocStoreException {
666 validateCNumNCNumType(cNum);
667 validateShelvingOrderNCNum(cNum);
668 }
669
670 private void validateShelvingOrderNCNum(CallNumber cNum) throws OleDocStoreException {
671 if (cNum.getShelvingOrder() != null && cNum.getShelvingOrder().getFullValue() != null &&
672 cNum.getShelvingOrder().getFullValue().trim().length() > 0) {
673 if (!(cNum.getNumber() != null && cNum.getNumber().length() > 0)) {
674 throw new OleDocStoreException("Shelving order value is available, so please enter call number information");
675 }
676 }
677 }
678
679
680
681
682
683
684 private void validateCNumNCNumType(CallNumber cNum) throws OleDocStoreException {
685 String callNumber = "";
686 String callNumberType = "";
687
688 if (cNum != null) {
689 callNumber = cNum.getNumber();
690 if (cNum.getShelvingScheme() != null) {
691 callNumberType = cNum.getShelvingScheme().getCodeValue();
692 }
693 }
694
695 if (StringUtils.isNotEmpty(callNumber)) {
696
697 if ((callNumberType == null) || (callNumberType.length() == 0) || (callNumberType.equals("#"))) {
698 throw new OleDocStoreException("Please enter valid call number type value in call number information ");
699 }
700 }
701 }
702
703 public void validateCallNumber(CallNumber itemCNum, OleHoldings holdings) throws OleDocStoreException {
704
705 if ((itemCNum.getNumber() != null && itemCNum.getNumber().length() > 0)) {
706 validateCNumNCNumType(itemCNum);
707 validateShelvingOrderNCNum(itemCNum);
708 }
709
710 else if (holdings != null) {
711 if (holdings.getCallNumber() != null) {
712 CallNumber holCNum = holdings.getCallNumber();
713 validateCNumNCNumType(holCNum);
714
715 if (itemCNum.getShelvingOrder() != null && itemCNum.getShelvingOrder().getFullValue() != null &&
716 itemCNum.getShelvingOrder().getFullValue().trim().length() > 0) {
717 if (!(holCNum.getNumber() != null && holCNum.getNumber().length() > 0)) {
718 throw new OleDocStoreException("Shelving order value is available, Please enter call number information");
719 }
720 }
721 }
722
723 else if (itemCNum.getShelvingOrder() != null && itemCNum.getShelvingOrder().getFullValue() != null &&
724 itemCNum.getShelvingOrder().getFullValue().trim().length() > 0) {
725 throw new OleDocStoreException("Shelving order value is available, Please enter call number information");
726 }
727
728 }
729 }
730
731 public void updateShelvingOrder(Item item, OleHoldings oleHolding) throws OleDocStoreException {
732 String callNumber = null;
733 String shelvingScheme = null;
734 if (item != null) {
735 if (item.getCallNumber() == null) {
736 item.setCallNumber(new CallNumber());
737 }
738
739
740
741 if (!(item.getCallNumber().getNumber() != null && item.getCallNumber().getNumber().trim().length() > 0)) {
742
743 if (oleHolding != null && oleHolding.getCallNumber() != null && oleHolding.getCallNumber().getNumber() != null &&
744 oleHolding.getCallNumber().getShelvingScheme() != null && oleHolding.getCallNumber().getShelvingScheme().getCodeValue() != null) {
745 callNumber = oleHolding.getCallNumber().getNumber();
746 shelvingScheme = oleHolding.getCallNumber().getShelvingScheme().getCodeValue();
747 }
748 } else {
749
750
751 callNumber = item.getCallNumber().getNumber();
752
753 if(item.getCallNumber().getShelvingScheme() != null){
754 shelvingScheme = item.getCallNumber().getShelvingScheme().getCodeValue();
755 }
756 }
757 String shelvingOrd = "";
758 if (callNumber != null && callNumber.trim().length() > 0 && shelvingScheme != null && shelvingScheme.trim().length() > 0) {
759 callNumber = appendItemInfoToCalNumber(item, callNumber);
760
761 boolean isValid = validateCallNumber(callNumber, shelvingScheme);
762 if (isValid) {
763 shelvingOrd = buildSortableCallNumber(callNumber, shelvingScheme);
764 } else {
765 shelvingOrd = callNumber;
766 }
767 if (item.getCallNumber().getShelvingOrder() == null) {
768 item.getCallNumber().setShelvingOrder(new ShelvingOrder());
769 }
770 item.getCallNumber().getShelvingOrder().setFullValue(shelvingOrd);
771 }
772 }
773 }
774
775 private String appendItemInfoToCalNumber(Item item, String callNumber) {
776 if (item.getEnumeration() != null && item.getEnumeration().trim().length() > 0) {
777 callNumber = callNumber +" "+ item.getEnumeration().trim();
778 }
779 if (item.getChronology() != null && item.getChronology().trim().length() > 0) {
780 callNumber = callNumber +" "+ item.getChronology().trim();
781
782 }
783 if (item.getCopyNumber() != null && item.getCopyNumber().trim().length() > 0) {
784 callNumber = callNumber +" "+ item.getCopyNumber().trim();
785 }
786 return callNumber;
787 }
788
789 protected boolean validateCallNumber(String callNumber, String codeValue) throws OleDocStoreException {
790 boolean isValid = false;
791 if (StringUtils.isNotEmpty(callNumber) && StringUtils.isNotEmpty(codeValue)) {
792 org.kuali.ole.utility.callnumber.CallNumber callNumberObj = CallNumberFactory.getInstance().getCallNumber(codeValue);
793 if (callNumberObj != null) {
794 isValid = callNumberObj.isValid(callNumber);
795 }
796 }
797 return isValid;
798 }
799
800 protected String buildSortableCallNumber(String callNumber, String codeValue) throws OleDocStoreException {
801 String shelvingOrder = "";
802 if(StringUtils.isNotEmpty(callNumber) && StringUtils.isNotEmpty(codeValue)){
803 org.kuali.ole.utility.callnumber.CallNumber callNumberObj = CallNumberFactory.getInstance().getCallNumber(codeValue);
804 if(callNumberObj != null){
805 shelvingOrder = callNumberObj.getSortableKey(callNumber);
806
807 }
808 }
809 return shelvingOrder;
810 }
811
812 private RequestDocument generateInstanceDocument(Instance instance) {
813 InstanceCollection instanceCollection = new InstanceCollection();
814 List<Instance> instances = new ArrayList<Instance>();
815 instanceCollection.setInstance(instances);
816 Instance inst = new Instance();
817 instances.add(inst);
818 inst.setInstanceIdentifier(instance.getInstanceIdentifier());
819 inst.setResourceIdentifier(instance.getResourceIdentifier());
820 inst.setFormerResourceIdentifier(instance.getFormerResourceIdentifier());
821 inst.setExtension(instance.getExtension());
822 String cont = olemlProcessor.toXML(instanceCollection);
823 RequestDocument requestDocument = new RequestDocument();
824 requestDocument.setCategory(DocCategory.WORK.getCode());
825 requestDocument.setType(DocType.INSTANCE.getCode());
826 requestDocument.setFormat(DocFormat.OLEML.getCode());
827 requestDocument.setContent(new Content());
828 requestDocument.getContent().setContent(cont);
829 requestDocument.getContent().setContentObject(inst);
830 return requestDocument;
831 }
832
833 private void resolveLinkingWithBib(Instance instance) {
834 if (ProcessParameters.BULK_INGEST_IS_LINKING_ENABLED) {
835
836 for (FormerIdentifier frids : instance.getFormerResourceIdentifier()) {
837 Identifier identifier = frids.getIdentifier();
838 try {
839 if (identifier.getIdentifierValue() != null
840 && identifier.getIdentifierValue().trim().length() != 0) {
841 List<SolrDocument> solrDocs = ServiceLocator.getIndexerService()
842 .getSolrDocument("SystemControlNumber",
843 "\"" + identifier
844 .getIdentifierValue()
845 + "\"");
846 if (solrDocs != null && solrDocs.size() > 0) {
847 for (SolrDocument solrDoc : solrDocs) {
848 if (checkApplicability(identifier.getIdentifierValue(),
849 solrDoc.getFieldValue("SystemControlNumber"))) {
850 instance.getResourceIdentifier().add(solrDoc.getFieldValue("id").toString());
851 }
852 }
853 }
854 }
855 } catch (Exception e) {
856 }
857 }
858 }
859 }
860
861 private boolean checkApplicability(Object value, Object fieldValue) {
862 if (fieldValue instanceof Collection) {
863 for (Object object : (Collection) fieldValue) {
864 if (object.equals(value)) {
865 return true;
866 }
867 }
868 return false;
869 } else {
870 return value.equals(fieldValue);
871 }
872 }
873
874
875
876
877
878
879
880 private AdditionalAttributes getFirstAdditionalAttributes(Extension extension) {
881 if (extension != null && extension.getContent() != null) {
882 for (Object obj : extension.getContent()) {
883 if (obj instanceof AdditionalAttributes) {
884 return (AdditionalAttributes) obj;
885 }
886 }
887 }
888 return null;
889 }
890
891 private void setIdentifierValueInContent(RequestDocument reqDoc) {
892 if (reqDoc.getType().equalsIgnoreCase(DocType.ITEM.getDescription())) {
893 WorkItemOlemlRecordProcessor recordProcessor = new WorkItemOlemlRecordProcessor();
894 Item item = recordProcessor.fromXML(reqDoc.getContent().getContent());
895 item.setItemIdentifier(reqDoc.getId());
896 reqDoc.getContent().setContent(recordProcessor.toXML(item));
897 }
898 if (reqDoc.getType().equalsIgnoreCase(DocType.HOLDINGS.getDescription())) {
899 WorkHoldingOlemlRecordProcessor recordProcessor = new WorkHoldingOlemlRecordProcessor();
900 OleHoldings holdings = recordProcessor.fromXML(reqDoc.getContent().getContent());
901 holdings.setHoldingsIdentifier(reqDoc.getId());
902 reqDoc.getContent().setContent(recordProcessor.toXML(holdings));
903 }
904 if (reqDoc.getType().equalsIgnoreCase(DocType.SOURCEHOLDINGS.getDescription())) {
905 WorkSourceHoldingOlemlRecordProcessor recordProcessor = new WorkSourceHoldingOlemlRecordProcessor();
906 SourceHoldings sourceHoldings = recordProcessor.fromXML(reqDoc.getContent().getContent());
907 sourceHoldings.setHoldingsIdentifier(reqDoc.getId());
908 reqDoc.getContent().setContent(recordProcessor.toXML(sourceHoldings));
909 }
910 }
911
912 public ResponseDocument buildResponseDocument(RequestDocument requestDocument) {
913 ResponseDocument responseDocument = new ResponseDocument();
914 responseDocument.setId(requestDocument.getId());
915 responseDocument.setCategory(requestDocument.getCategory());
916 responseDocument.setType(requestDocument.getType());
917 responseDocument.setFormat(requestDocument.getFormat());
918 responseDocument.setUuid(requestDocument.getUuid());
919 if ((requestDocument.getLinkedRequestDocuments() != null) && (requestDocument.getLinkedRequestDocuments().size()
920 > 0) || requestDocument.getType()
921 .equals(DocType.INSTANCE
922 .getCode())) {
923 buildInstanceComponentResponseDocuments(requestDocument, responseDocument);
924 }
925 buildLinkedResponseDocuments(requestDocument, responseDocument);
926 return responseDocument;
927 }
928
929 public ResponseDocument buildResponseDocument(RequestDocument requestDocument, Session session) {
930 ResponseDocument responseDocument = new ResponseDocument();
931 responseDocument.setId(requestDocument.getId());
932 responseDocument.setCategory(requestDocument.getCategory());
933 responseDocument.setType(requestDocument.getType());
934 responseDocument.setFormat(requestDocument.getFormat());
935 responseDocument.setUuid(requestDocument.getUuid());
936 String category = requestDocument.getCategory();
937 String type = requestDocument.getType();
938 Node node = null;
939 try {
940 node = session.getNodeByIdentifier(requestDocument.getUuid());
941 } catch (RepositoryException e) {
942 LOG.info("Failed to get node:" + e.getMessage(), e);
943 }
944
945 if (node != null) {
946 try {
947 AdditionalAttributes additionalAttributes = requestDocument.getAdditionalAttributes();
948 if (additionalAttributes != null && category.equals(DocCategory.WORK.getDescription()) && type
949 .equals(DocType.BIB.getDescription())) {
950 Collection<String> attributeNames = additionalAttributes.getAttributeNames();
951 if (attributeNames != null && attributeNames.size() > 0) {
952 for (Iterator<String> iterator = attributeNames.iterator(); iterator.hasNext(); ) {
953 String attributeName = iterator.next();
954 if (node.hasProperty(attributeName)) {
955 additionalAttributes
956 .setAttribute(attributeName, node.getProperty(attributeName).getString());
957 }
958 }
959 }
960 responseDocument.setAdditionalAttributes(additionalAttributes);
961 }
962 } catch (RepositoryException e) {
963 LOG.info("Failed to get node property:" + e.getMessage(), e);
964 }
965 }
966
967 buildLinkedResponseDocuments(requestDocument, responseDocument);
968 return responseDocument;
969 }
970
971 private void buildInstanceComponentResponseDocuments(RequestDocument requestDocument,
972 ResponseDocument responseDocument) {
973 if (requestDocument.getContent().getContent() == null) {
974 return;
975 }
976 InstanceCollection instanceCollection = (InstanceCollection) requestDocument.getContent().getContentObject();
977 ResponseDocument linkedInstanceDocument = null;
978 ResponseDocument linkedInstanceItemDocument = null;
979 ResponseDocument linkedInstanceSrHoldingDoc = null;
980 requestDocument.getContent().setContent("");
981 List<ResponseDocument> linkInstanceDocs = new ArrayList<ResponseDocument>();
982 for (Instance oleInstance : instanceCollection.getInstance()) {
983
984 linkedInstanceDocument = new ResponseDocument();
985 setResponseParameters(linkedInstanceDocument, requestDocument);
986 linkedInstanceDocument.setUuid(oleInstance.getOleHoldings().getHoldingsIdentifier());
987 linkedInstanceDocument.setType("holdings");
988 linkInstanceDocs.add(linkedInstanceDocument);
989
990
991 linkedInstanceSrHoldingDoc = new ResponseDocument();
992 setResponseParameters(linkedInstanceSrHoldingDoc, requestDocument);
993 if (oleInstance.getSourceHoldings() != null
994 && oleInstance.getSourceHoldings().getHoldingsIdentifier() != null) {
995 linkedInstanceSrHoldingDoc.setUuid(oleInstance.getSourceHoldings().getHoldingsIdentifier());
996 linkedInstanceSrHoldingDoc.setType("sourceHoldings");
997 linkInstanceDocs.add(linkedInstanceSrHoldingDoc);
998 }
999
1000
1001 for (Iterator<Item> itemIterator = oleInstance.getItems().getItem().iterator(); itemIterator.hasNext(); ) {
1002 Item oleItem = itemIterator.next();
1003 linkedInstanceItemDocument = new ResponseDocument();
1004 setResponseParameters(linkedInstanceItemDocument, requestDocument);
1005 linkedInstanceItemDocument.setUuid(oleItem.getItemIdentifier());
1006 linkedInstanceItemDocument.setType("item");
1007 linkInstanceDocs.add(linkedInstanceItemDocument);
1008 }
1009 }
1010 responseDocument.setLinkedDocuments(linkInstanceDocs);
1011 }
1012
1013
1014
1015
1016
1017
1018
1019 protected void buildLinkedResponseDocuments(RequestDocument requestDocument, ResponseDocument responseDocument) {
1020 if ((null == requestDocument.getLinkedRequestDocuments()) || (requestDocument.getLinkedRequestDocuments().size()
1021 == 0)) {
1022 return;
1023 }
1024 for (RequestDocument linkedItemDocument : requestDocument.getLinkedRequestDocuments()) {
1025 if (DocType.ITEM.getDescription().equalsIgnoreCase(linkedItemDocument.getType())
1026 && linkedItemDocument.getContent().getContent() != null) {
1027 ResponseDocument linkedItemResponseDocument = new ResponseDocument();
1028 setResponseParameters(linkedItemResponseDocument, requestDocument);
1029 linkedItemResponseDocument.setUuid(linkedItemDocument.getUuid());
1030 linkedItemResponseDocument.setType("item");
1031 linkedItemResponseDocument.setContent(new Content(""));
1032 responseDocument.getLinkedDocuments().add(linkedItemResponseDocument);
1033 }
1034 }
1035 }
1036
1037 public void transferItems(List<RequestDocument> requestDocuments, Session session) throws Exception {
1038 LOG.debug("in WorkInstanceDocumentManager transferItems");
1039 List<String> itemIdentifierList = new ArrayList<String>();
1040 String destInstanceIdentifier = requestDocuments.get(requestDocuments.size() - 1).getUuid();
1041 String destPath = "";
1042 for (int i = 0; i < requestDocuments.size() - 1; i++) {
1043 itemIdentifierList.add(requestDocuments.get(i).getUuid());
1044 }
1045 LOG.debug("WorkInstanceDocumentManager transferItems itemIdentifierList "+itemIdentifierList);
1046
1047
1048 boolean isExists=false;
1049 LOG.debug("isExists "+isExists);
1050 if(isExists){
1051 LOG.debug("in isExists");
1052 throw new ItemExistsException("One of the Items to be Transfered is Loaned or In use in OLE");
1053 }
1054 LOG.debug("after isExists");
1055 Node instanceNode = session.getNodeByIdentifier(destInstanceIdentifier);
1056 NodeIterator instanceNodeIterator = instanceNode.getNodes();
1057
1058 while (instanceNodeIterator.hasNext()) {
1059 Node node = instanceNodeIterator.nextNode();
1060 if (node.getName().equalsIgnoreCase("holdingsNode")) {
1061 destPath = node.getPath() + "/itemFile";
1062 break;
1063 }
1064 }
1065 for (String itemIdentifier : itemIdentifierList) {
1066 String sourcePath = session.getNodeByIdentifier(itemIdentifier).getPath();
1067 session.move(sourcePath, destPath);
1068 }
1069
1070 }
1071
1072 public void transferInstances(List<RequestDocument> requestDocuments, Session session) throws Exception {
1073 List<String> instanceIdentifiersList = new ArrayList<String>();
1074 for (int i = 0; i < requestDocuments.size() - 1; i++) {
1075 instanceIdentifiersList.add(requestDocuments.get(i).getUuid());
1076 }
1077 WorkInstanceNodeManager workInstanceNodeManager = WorkInstanceNodeManager.getInstance();
1078 InstanceCollection instanceCollection = null;
1079 String desBibIdentifier = requestDocuments.get(requestDocuments.size() - 1).getUuid();
1080 for (String instanceIdentifier : instanceIdentifiersList) {
1081 Node instanceNode = nodeManager.getNodeByUUID(session, instanceIdentifier);
1082 String instanceXMLContent = workInstanceNodeManager.getXMLOnlyForInstanceType(instanceNode);
1083 instanceCollection = olemlProcessor.fromXML(instanceXMLContent);
1084 List<Instance> instanceList = instanceCollection.getInstance();
1085 List<String> instanceIdentifiers = new ArrayList<String>();
1086 instanceIdentifiers.add(desBibIdentifier);
1087 instanceList.get(0).setResourceIdentifier(instanceIdentifiers);
1088 String backToXML = olemlProcessor.toXML(instanceCollection);
1089 byte[] bytes = convertContentToBytes(backToXML);
1090 NodeIterator nodeIterator = instanceNode.getNodes();
1091 Node node = null;
1092
1093 while (nodeIterator.hasNext()) {
1094 node = nodeIterator.nextNode();
1095 if (node.getName().equalsIgnoreCase("instanceFile")) {
1096 updateContentToNode(new RequestDocument(), session, bytes, node);
1097 }
1098 }
1099 }
1100 }
1101
1102 private byte[] convertContentToBytes(String xmlContent) throws OleDocStoreException {
1103 String charset = "UTF-8";
1104 byte[] documentBytes = null;
1105 try {
1106 if (xmlContent != null) {
1107 documentBytes = xmlContent.getBytes(charset);
1108 }
1109 } catch (Exception e) {
1110
1111 throw new OleDocStoreException(e.getMessage());
1112 }
1113 return documentBytes;
1114 }
1115
1116 @Override
1117 public void validateInput(RequestDocument requestDocument, Session session, List<String> fieldValues) throws OleDocStoreException {
1118 String content = requestDocument.getContent().getContent();
1119 if (content == null) {
1120 if (requestDocument.getLinkedRequestDocuments().size() > 0) {
1121 List<RequestDocument> linkedRequestDocuments = requestDocument.getLinkedRequestDocuments();
1122 for (RequestDocument linkedRequestDocument : linkedRequestDocuments) {
1123 if (linkedRequestDocument.getType().equalsIgnoreCase(DocType.ITEM.getCode())) {
1124 WorkItemDocumentManager.getInstance().validateNewItem(linkedRequestDocument, session, fieldValues, requestDocument.getId());
1125 }
1126 }
1127 }
1128 } else {
1129 WorkInstanceOlemlRecordProcessor instProcessor = new WorkInstanceOlemlRecordProcessor();
1130 InstanceCollection instanceCollection = instProcessor.fromXML(content);
1131 List<Instance> instanceList = instanceCollection.getInstance();
1132 for (Instance instance : instanceList) {
1133 if (instance.getOleHoldings() != null) {
1134 OleHoldings oleHoldings = instance.getOleHoldings();
1135 WorkHoldingsDocumentManager.getInstance().validateHoldings(oleHoldings);
1136 }
1137 if (instance.getItems() != null) {
1138 Items items = instance.getItems();
1139 List<Item> itemList = items.getItem();
1140 if (itemList.size() > 0) {
1141 for (Item item : itemList) {
1142 WorkItemDocumentManager.getInstance().itemBarcodeValidation(item, fieldValues, null);
1143 if (item.getCallNumber() != null) {
1144 CallNumber callNumber = item.getCallNumber();
1145 if (instance.getOleHoldings() != null) {
1146 OleHoldings oleHoldings = instance.getOleHoldings();
1147 validateCallNumber(callNumber, oleHoldings);
1148 } else {
1149 validateCallNumber(callNumber, null);
1150 }
1151 }
1152 }
1153 }
1154 }
1155 }
1156 }
1157 }
1158
1159
1160
1161
1162
1163
1164 public void computeCallNumberType(CallNumber callNumber) {
1165 Set<String> validCallNumberTypeSet = CallNumberType.validCallNumberTypeCodeSet;
1166 if (callNumber != null) {
1167 if (callNumber.getShelvingScheme() != null) {
1168 String callNumberTypeCode = callNumber.getShelvingScheme().getCodeValue();
1169 String callNumberTypeName = "";
1170
1171 if ((StringUtils.isNotEmpty(callNumberTypeCode)) && (validCallNumberTypeSet
1172 .contains(callNumberTypeCode))) {
1173 callNumberTypeName = CallNumberType.valueOf(callNumberTypeCode).getDescription();
1174 callNumber.getShelvingScheme().setFullValue(callNumberTypeName);
1175 }
1176 }
1177 }
1178 }
1179 }