1 package org.kuali.ole.describe.controller;
2
3 import org.apache.commons.lang.StringUtils;
4 import org.apache.cxf.helpers.IOUtils;
5 import org.apache.log4j.Logger;
6 import org.apache.solr.client.solrj.SolrServerException;
7 import org.kuali.ole.OLEConstants;
8 import org.kuali.ole.OleEditorResponseHandler;
9 import org.kuali.ole.describe.bo.*;
10 import org.kuali.ole.describe.form.*;
11 import org.kuali.ole.describe.service.DiscoveryHelperService;
12 import org.kuali.ole.describe.service.DocstoreHelperService;
13 import org.kuali.ole.docstore.discovery.service.QueryService;
14 import org.kuali.ole.docstore.discovery.service.QueryServiceImpl;
15 import org.kuali.ole.docstore.model.bo.*;
16 import org.kuali.ole.docstore.model.enums.DocCategory;
17 import org.kuali.ole.docstore.model.enums.DocFormat;
18 import org.kuali.ole.docstore.model.enums.DocType;
19 import org.kuali.ole.docstore.model.xmlpojo.ingest.AdditionalAttributes;
20 import org.kuali.ole.docstore.model.xmlpojo.ingest.Request;
21 import org.kuali.ole.docstore.model.xmlpojo.ingest.Response;
22 import org.kuali.ole.docstore.model.xmlpojo.work.einstance.oleml.*;
23 import org.kuali.ole.docstore.model.xmlpojo.work.instance.oleml.Extension;
24 import org.kuali.ole.docstore.model.xstream.ingest.RequestHandler;
25 import org.kuali.ole.docstore.model.xstream.ingest.ResponseHandler;
26 import org.kuali.ole.describe.bo.InstanceEditorFormDataHandler;
27 import org.kuali.ole.describe.form.InstanceEditorForm;
28 import org.kuali.ole.describe.service.DiscoveryHelperService;
29 import org.kuali.ole.describe.service.DocstoreHelperService;
30 import org.kuali.ole.docstore.model.xstream.work.oleml.WorkEHoldingOlemlRecordProcessor;
31 import org.kuali.ole.docstore.model.xstream.work.oleml.WorkEInstanceOlemlRecordProcessor;
32 import org.kuali.ole.pojo.OleBibRecord;
33 import org.kuali.ole.pojo.OleEditorResponse;
34 import org.kuali.ole.select.businessobject.OleCopy;
35 import org.kuali.ole.select.document.OLEEResourceRecordDocument;
36 import org.kuali.ole.select.service.impl.OleExposedWebServiceImpl;
37 import org.kuali.ole.service.OLEEResourceSearchService;
38 import org.kuali.ole.service.impl.OLEEResourceSearchServiceImpl;
39 import org.kuali.ole.sys.context.SpringContext;
40 import org.kuali.rice.core.api.exception.RiceRuntimeException;
41 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
42 import org.kuali.rice.kim.api.identity.Person;
43 import org.kuali.rice.kim.api.identity.PersonService;
44 import org.kuali.rice.krad.service.*;
45 import org.kuali.rice.krad.util.GlobalVariables;
46 import org.kuali.rice.krad.util.KRADConstants;
47 import org.kuali.rice.krad.web.form.UifFormBase;
48 import org.springframework.validation.BindingResult;
49 import org.springframework.web.bind.annotation.ModelAttribute;
50 import org.springframework.web.servlet.ModelAndView;
51
52 import javax.servlet.http.HttpServletRequest;
53 import javax.servlet.http.HttpServletResponse;
54 import java.sql.Date;
55 import java.util.ArrayList;
56 import java.util.HashMap;
57 import java.util.List;
58 import java.util.Map;
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73 public class WorkEInstanceOlemlEditor
74 extends AbstractEditor
75 implements DocumentEditor {
76
77 private static final Logger LOG = Logger.getLogger(WorkEInstanceOlemlEditor.class);
78
79 private DocstoreHelperService docstoreHelperService;
80 private InstanceEditorFormDataHandler instanceEditorFormDataHandler;
81 private EInstanceFormDataHandler eInstanceFormDataHandler;
82 private DiscoveryHelperService discoveryHelperService;
83 private OLEEResourceSearchService oleEResourceSearchService;
84 private DocumentService documentService;
85
86
87 private static WorkEInstanceOlemlEditor workEInstanceOlemlEditor = new WorkEInstanceOlemlEditor();
88
89 public static WorkEInstanceOlemlEditor getInstance() {
90 return workEInstanceOlemlEditor;
91 }
92
93 public OLEEResourceSearchService getOleEResourceSearchService() {
94 if (oleEResourceSearchService == null) {
95 oleEResourceSearchService = GlobalResourceLoader.getService(OLEConstants.OLEEResourceRecord.ERESOURSE_SEARCH_SERVICE);
96 }
97 return oleEResourceSearchService;
98 }
99
100 public DocumentService getDocumentService() {
101 if (this.documentService == null) {
102 this.documentService = KRADServiceLocatorWeb.getDocumentService();
103 }
104 return this.documentService;
105 }
106
107 public void setDocumentService(DocumentService documentService) {
108 this.documentService = documentService;
109 }
110
111 private WorkEInstanceOlemlEditor() {
112 }
113
114 @Override
115 public EditorForm copy(EditorForm editorForm) {
116 loadDocument(editorForm);
117 editorForm.setDocId(null);
118 editorForm.setShowEditorFooter(false);
119 editorForm.setFromSearch(false);
120
121
122 GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_INFO, "info.einstance.copy.success");
123 return editorForm;
124 }
125
126 @Override
127 public EditorForm loadDocument(EditorForm editorForm) {
128 WorkEInstanceOlemlForm workEInstanceOlemlForm = new WorkEInstanceOlemlForm();
129 WorkEInstanceOlemlRecordProcessor workEInstanceOlemlRecordProcessor = new WorkEInstanceOlemlRecordProcessor();
130 WorkEHoldingOlemlRecordProcessor workEHoldingOlemlRecordProcessor = new WorkEHoldingOlemlRecordProcessor();
131 String docId = editorForm.getDocId();
132 String bibId = editorForm.getBibId();
133 String tokenId = editorForm.getTokenId();
134 workEInstanceOlemlForm.setTokenId(tokenId);
135 workEInstanceOlemlForm.setBibId(bibId);
136 String docType = editorForm.getDocType();
137 editorForm.setHasLink(true);
138 if ((StringUtils.isBlank(editorForm.getTitle()))) {
139 getTitleInfo(editorForm);
140 }
141 if (editorForm.isFromDublin()) {
142 editorForm.setHasLink(false);
143 }
144 if (editorForm.getTitle() != null && editorForm.getTitle().contains("<")) {
145 String title = org.apache.commons.lang.StringEscapeUtils.escapeHtml((editorForm.getTitle()));
146 editorForm.setTitle(title);
147 }
148 editorForm.setShowEditorFooter(false);
149 editorForm.setFromSearch(false);
150 String eResId = null;
151 workEInstanceOlemlForm.seteResourceId(editorForm.geteResourceId());
152 if (docId != null && docId.length() > 0) {
153 if (docType.equals(DocType.EINSTANCE.getCode())) {
154 try {
155
156 String docStoreData = getDocstoreHelperService().getDocstoreData(docId);
157 InstanceCollection instanceCollection = workEInstanceOlemlRecordProcessor.fromXML(docStoreData);
158 EInstance eInstance = instanceCollection.getEInstance().get(0);
159 EHoldings eHoldings = eInstance.getEHoldings();
160 if (eResId == null || eResId.length() == 0) {
161 eResId = eHoldings.getEResourceId();
162 }
163
164
165
166
167
168
169
170
171 getOleEResourceSearchService().getAccessLocationFromEInstance(eHoldings, workEInstanceOlemlForm);
172 getOleEResourceSearchService().getEResourcesFields(eResId, eHoldings, workEInstanceOlemlForm);
173 getOleEResourceSearchService().getEResourcesLicenseFields(eResId, workEInstanceOlemlForm);
174 workEInstanceOlemlForm.setSelectedEInstance(eInstance);
175 editorForm.setDocId(eInstance.getEHoldings().getHoldingsIdentifier());
176 editorForm.setDocType(DocType.EHOLDINGS.getCode());
177 workEInstanceOlemlForm.setInstanceId(docId);
178 workEInstanceOlemlForm.setSelectedEHoldings(eHoldings);
179 workEInstanceOlemlForm.getSelectedEHoldings().setStatusDate(new Date(System.currentTimeMillis()).toString());
180 } catch (Exception e) {
181
182 LOG.error("loadDocument EInstance Exception:" + e);
183
184 GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_INFO, "record.load.fail.message ");
185 return workEInstanceOlemlForm;
186 }
187 } else {
188 try {
189 String docStoreData = getDocstoreHelperService().getDocstoreData(docId);
190 EHoldings eHoldings = workEHoldingOlemlRecordProcessor.fromXML(docStoreData);
191 if (eResId == null || eResId.length() == 0) {
192 eResId = eHoldings.getEResourceId();
193 }
194
195
196
197
198
199
200
201
202 getOleEResourceSearchService().getAccessLocationFromEInstance(eHoldings, workEInstanceOlemlForm);
203 getOleEResourceSearchService().getEResourcesFields(eResId, eHoldings, workEInstanceOlemlForm);
204 getOleEResourceSearchService().getEResourcesLicenseFields(eResId, workEInstanceOlemlForm);
205 workEInstanceOlemlForm.setSelectedEHoldings(eHoldings);
206 workEInstanceOlemlForm.getSelectedEHoldings().setStatusDate(new Date(System.currentTimeMillis()).toString());
207 } catch (Exception e) {
208
209 LOG.error("loadDocument Instance Exception:" + e);
210
211 GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_INFO, "record.load.fail.message ");
212 return workEInstanceOlemlForm;
213 }
214
215 }
216 getEInstanceFormDataHandler().setLocationDetails(workEInstanceOlemlForm);
217
218 GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_INFO, "record.load.message");
219 } else {
220 EHoldings eHoldings = new EHoldings();
221 eHoldings.setStatusDate(new Date(System.currentTimeMillis()).toString());
222 getOleEResourceSearchService().getAccessLocationFromEInstance(eHoldings, workEInstanceOlemlForm);
223 getOleEResourceSearchService().getEResourcesFields(editorForm.geteResourceId(), eHoldings, workEInstanceOlemlForm);
224 getOleEResourceSearchService().getEResourcesLicenseFields(editorForm.geteResourceId(), workEInstanceOlemlForm);
225 workEInstanceOlemlForm.setSelectedEHoldings(eHoldings);
226 workEInstanceOlemlForm.setViewId("WorkEInstanceViewPage");
227
228 GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_INFO, "eholdings.record.new.load.message");
229 }
230 workEInstanceOlemlForm.setViewId("WorkEInstanceViewPage");
231 List<WorkBibDocument> workBibDocumentList = new ArrayList<>();
232 DocstoreHelperService docstoreHelperService = new DocstoreHelperService();
233 WorkBibDocument workBibDocument = new WorkBibDocument();
234 workBibDocument.setId(editorForm.getBibId());
235 workBibDocument = docstoreHelperService.getInfoForBibTree(workBibDocument);
236 workBibDocumentList.add(workBibDocument);
237 editorForm.setWorkBibDocumentList(workBibDocumentList);
238 workEInstanceOlemlForm.setIssn(workBibDocument.getIssn());
239 editorForm.setHeaderText("EInstance Editor (EHoldings) - OLEML Format");
240 if (workEInstanceOlemlForm.getTokenId() != null && !workEInstanceOlemlForm.getTokenId().isEmpty()) {
241 editorForm.setTokenId(workEInstanceOlemlForm.getTokenId());
242 }
243 return workEInstanceOlemlForm;
244 }
245
246 private void getTitleInfo(EditorForm editorForm) {
247 WorkBibDocument workBibDocument = new WorkBibDocument();
248 workBibDocument.setId(editorForm.getBibId());
249 QueryService queryService = QueryServiceImpl.getInstance();
250 WorkBibDocument document = null;
251 try {
252 document = queryService.buildBibDocumentInfo(workBibDocument);
253 } catch (Exception e) {
254 LOG.error("Failed to get Title / Author details : " + e.getMessage());
255 }
256 StringBuilder titleBuilder = new StringBuilder();
257 if (document != null) {
258 titleBuilder.append(document.getTitle());
259 titleBuilder.append("/");
260 if (document.getAuthor() != null) {
261
262 titleBuilder.append(document.getAuthor());
263 }
264 if (workBibDocument.getDocFormat().equalsIgnoreCase("dublinunq")) {
265 editorForm.setFromDublin(true);
266 }
267 editorForm.setTitle(org.apache.commons.lang.StringEscapeUtils.escapeHtml(titleBuilder.toString()));
268 }
269 }
270
271 @Override
272 public EditorForm saveDocument(EditorForm editorForm) {
273
274
275 WorkEInstanceOlemlForm workEInstanceOlemlForm = (WorkEInstanceOlemlForm) editorForm.getDocumentForm();
276 String responseFromDocstore = null;
277 String docId = editorForm.getDocId();
278 String docType = editorForm.getDocType();
279 String editorStatusMessage = "";
280
281 AdditionalAttributes additionalAttributes = new AdditionalAttributes();
282
283 if (docId != null && docId.length() > 0) {
284 EHoldings eHoldings = workEInstanceOlemlForm.getSelectedEHoldings();
285 getOleEResourceSearchService().getAccessLocationFromEInstance(eHoldings, workEInstanceOlemlForm);
286 String content = getEInstanceFormDataHandler().buildHoldingContent(eHoldings);
287 String responseXml = "";
288 try {
289 getOleEResourceSearchService().getEResourcesFields(editorForm.geteResourceId(), eHoldings, workEInstanceOlemlForm);
290 getOleEResourceSearchService().getEResourcesLicenseFields(editorForm.geteResourceId(), workEInstanceOlemlForm);
291 responseXml = getDocstoreHelperService().updateInstanceRecord(docId, docType, content, additionalAttributes);
292 Response response = new ResponseHandler().toObject(responseXml);
293 if (response.getStatus().equalsIgnoreCase("success")) {
294 workEInstanceOlemlForm.setDocId(response.getDocuments().get(0).getUuid());
295
296 editorStatusMessage = "Record updated successfully";
297 } else {
298 editorStatusMessage = response.getStatusMessage();
299
300 }
301 } catch (Exception e) {
302
303 LOG.error("saveDocument(docId != null) Exception:" + e);
304
305 return workEInstanceOlemlForm;
306
307 }
308 } else {
309 EInstance eInstance = new EInstance();
310 workEInstanceOlemlForm.setSelectedEInstance(eInstance);
311 eInstance.getResourceIdentifier().add(editorForm.getBibId());
312 EHoldings eHoldings = workEInstanceOlemlForm.getSelectedEHoldings();
313 getOleEResourceSearchService().getAccessLocationFromEInstance(eHoldings, workEInstanceOlemlForm);
314
315
316
317 String content = getEInstanceFormDataHandler().buildEInstanceRecordForDocStore(workEInstanceOlemlForm);
318 String reqXml = getDocstoreHelperService().buildRequestForIngest(DocCategory.WORK.getCode(), DocType.EINSTANCE.getCode(), DocFormat.OLEML.getCode(), content, null);
319 String responseXml = null;
320 try {
321 responseXml = getDocstoreHelperService().persistDocstore(reqXml, null);
322 } catch (Exception e) {
323
324 LOG.error("saveDocument(docId == null) Exception:" + e);
325
326 return workEInstanceOlemlForm;
327 }
328 Response response = new ResponseHandler().toObject(responseXml);
329 if (response.getStatus().equalsIgnoreCase("success")) {
330 editorForm.setInstanceId(response.getDocuments().get(0).getUuid());
331 workEInstanceOlemlForm.setInstanceId(response.getDocuments().get(0).getUuid());
332 editorForm.setDocId(response.getDocuments().get(0).getLinkedDocuments().get(0).getUuid());
333 editorForm.setDocType(DocType.EHOLDINGS.getCode());
334
335 editorStatusMessage = "Record created successfully";
336 processResponse(workEInstanceOlemlForm, editorForm.getInstanceId(), editorForm.getTokenId());
337 } else {
338 editorStatusMessage = response.getStatusMessage();
339
340 }
341
342
343
344 }
345 getEInstanceFormDataHandler().setLocationDetails(workEInstanceOlemlForm);
346
347 String eResId = editorForm.geteResourceId();
348 editorForm.seteResourceId(null);
349 WorkEInstanceOlemlForm newworkEInstanceOlemlForm = (WorkEInstanceOlemlForm) loadDocument(editorForm);
350 workEInstanceOlemlForm.setViewId("WorkEInstanceViewPage");
351 GlobalVariables.getMessageMap().getInfoMessages().clear();
352 GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_INFO, "docstore.response", editorStatusMessage);
353 if (eResId != null && !eResId.isEmpty()) {
354 Map<String, String> tempId = new HashMap<String, String>();
355 tempId.put(OLEConstants.OLEEResourceRecord.ERESOURCE_IDENTIFIER, eResId);
356 OLEEResourceRecordDocument tempDocument = (OLEEResourceRecordDocument) KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(OLEEResourceRecordDocument.class, tempId);
357 try {
358 Person principalPerson = SpringContext.getBean(PersonService.class).getPerson(GlobalVariables.getUserSession().getPerson().getPrincipalId());
359 tempDocument.setDocumentHeader(SpringContext.getBean(DocumentHeaderService.class).getDocumentHeaderById(tempDocument.getDocumentNumber()));
360 tempDocument.getDocumentHeader().setWorkflowDocument(KRADServiceLocatorWeb.getWorkflowDocumentService().loadWorkflowDocument(tempDocument.getDocumentNumber(), principalPerson));
361 if (tempDocument != null) {
362 try {
363 tempDocument.setSelectInstance(OLEConstants.OLEEResourceRecord.CREATE_NEW_INSTANCE);
364 tempDocument.seteInstanceFlag(true);
365 getOleEResourceSearchService().getNewInstance(tempDocument, tempDocument.getDocumentNumber());
366 getDocumentService().updateDocument(tempDocument);
367 } catch (Exception e) {
368 throw new RiceRuntimeException(
369 "Exception trying to save document: " + tempDocument
370 .getDocumentNumber(), e);
371 }
372 }
373 } catch (Exception e) {
374 throw new RiceRuntimeException(
375 "Exception trying to save document: " + tempDocument
376 .getDocumentNumber(), e);
377 }
378 }
379
380
381 return workEInstanceOlemlForm;
382 }
383
384
385 public void processResponse(WorkEInstanceOlemlForm workEInstanceOlemlForm, String instanceId, String tokenId) {
386 OleEditorResponse oleEditorResponse = new OleEditorResponse();
387 OleBibRecord oleBibRecord = new OleBibRecord();
388 oleBibRecord.setLinkedInstanceId(instanceId);
389 oleBibRecord.setBibUUID(workEInstanceOlemlForm.getBibId());
390 oleEditorResponse.setOleBibRecord(oleBibRecord);
391 oleEditorResponse.setTokenId(tokenId);
392 oleBibRecord.seteInstance(OLEConstants.E_INSTANCE);
393 OleEditorResponseHandler oleEditorResponseHandler = new OleEditorResponseHandler();
394 String editorResponseXMLForOLE = oleEditorResponseHandler.toXML(oleEditorResponse);
395 OleExposedWebServiceImpl oleExposedWebService = (OleExposedWebServiceImpl) SpringContext.getBean("oleExposedWebService");
396 oleExposedWebService.addDoctoreResponse(editorResponseXMLForOLE);
397 }
398
399 @Override
400 public EditorForm deleteDocument(EditorForm editorForm) {
401 return new WorkBibMarcForm();
402 }
403
404 @Override
405 public EditorForm createNewRecord(EditorForm editorForm, Request request) {
406
407 if (editorForm.getDocumentForm().getViewId().equalsIgnoreCase("WorkEInstanceViewPage")) {
408 editorForm.setNeedToCreateInstance(true);
409 }
410 editNewRecord(editorForm, request);
411 return editorForm.getDocumentForm();
412 }
413
414
415 @Override
416 public EditorForm editNewRecord(EditorForm editorForm, Request request) {
417 WorkEInstanceOlemlForm workEInstanceOlemlForm = new WorkEInstanceOlemlForm();
418 if ((editorForm.getDocumentForm() instanceof WorkInstanceOlemlForm)) {
419 workEInstanceOlemlForm = (WorkEInstanceOlemlForm) editorForm.getDocumentForm();
420 workEInstanceOlemlForm.setViewId(editorForm.getDocumentForm().getViewId());
421 }
422
423 workEInstanceOlemlForm.setDocCategory("work");
424 workEInstanceOlemlForm.setDocType("eInstance");
425 workEInstanceOlemlForm.setDocFormat("oleml");
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502 editorForm.setDocumentForm(workEInstanceOlemlForm);
503 return editorForm;
504 }
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544 protected UifFormBase createInitialForm(HttpServletRequest httpServletRequest) {
545 return new WorkInstanceOlemlForm();
546 }
547
548
549
550
551
552
553
554
555
556
557 public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
558 HttpServletRequest request, HttpServletResponse response) {
559 WorkInstanceOlemlForm instanceEditorForm = (WorkInstanceOlemlForm) form;
560
561
562 return null;
563 }
564
565
566
567
568
569
570
571
572
573
574
575 public ModelAndView load(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
576 HttpServletRequest request, HttpServletResponse response) {
577 WorkEInstanceOlemlForm workEInstanceOlemlForm = new WorkEInstanceOlemlForm();
578 workEInstanceOlemlForm.setHideFooter(false);
579 workEInstanceOlemlForm.setViewId("WorkEInstanceViewPage");
580 workEInstanceOlemlForm.setMessage("Please enter details for new Item record.");
581
582
583 String uuid = request.getParameter("uuid");
584 String docType = request.getParameter("docType");
585 String docFormat = request.getParameter("docFormat");
586 String docCategory = request.getParameter("docCategory");
587 if (null == uuid || StringUtils.isEmpty(uuid)) {
588 uuid = workEInstanceOlemlForm.getUuid();
589 }
590 workEInstanceOlemlForm.setExisting("true");
591 try {
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608 } catch (Exception e) {
609 StringBuffer instanceEditorErrorMessage = new StringBuffer(OLEConstants.INSTANCE_EDITOR_LOAD_FAILURE)
610 .append(" :: \n" + e.getMessage());
611
612 LOG.error(instanceEditorErrorMessage);
613
614 }
615 return null;
616 }
617
618
619
620
621
622
623
624
625
626
627 protected ModelAndView callSuper(BindingResult result, HttpServletRequest request, HttpServletResponse response,
628 InstanceEditorForm instanceEditorForm) {
629
630 return null;
631 }
632
633
634
635
636
637
638 private DocstoreHelperService getDocstoreHelperService() {
639 if (null == docstoreHelperService) {
640 return new DocstoreHelperService();
641 }
642 return docstoreHelperService;
643 }
644
645
646
647
648
649
650 public void setDocstoreHelperService(DocstoreHelperService docstoreHelperService) {
651 this.docstoreHelperService = docstoreHelperService;
652 }
653
654
655
656
657
658
659 private InstanceEditorFormDataHandler getInstanceEditorFormDataHandler() {
660 if (null == instanceEditorFormDataHandler) {
661 instanceEditorFormDataHandler = new InstanceEditorFormDataHandler();
662 }
663 return instanceEditorFormDataHandler;
664 }
665
666 private EInstanceFormDataHandler getEInstanceFormDataHandler() {
667 if (null == eInstanceFormDataHandler) {
668 eInstanceFormDataHandler = new EInstanceFormDataHandler();
669 }
670 return eInstanceFormDataHandler;
671 }
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695 public void setDiscoveryHelperService(DiscoveryHelperService discoveryHelperService) {
696 this.discoveryHelperService = discoveryHelperService;
697 }
698
699
700
701
702
703
704 public DiscoveryHelperService getDiscoveryHelperService() {
705 if (null == discoveryHelperService) {
706 return new DiscoveryHelperService();
707 }
708 return discoveryHelperService;
709 }
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740 @Override
741 public EditorForm showBibs(EditorForm editorForm) {
742 WorkEInstanceOlemlForm workEInstanceOlemlForm = new WorkEInstanceOlemlForm();
743 QueryService queryService = QueryServiceImpl.getInstance();
744 List<String> bibUUIDList = new ArrayList<String>();
745 String instanceId = "";
746 String docType = editorForm.getDocType();
747 List<WorkBibDocument> workBibDocumentList = new ArrayList<WorkBibDocument>();
748 try {
749
750 if ((docType.equalsIgnoreCase(DocType.INSTANCE.getCode()) || docType
751 .equalsIgnoreCase(DocType.HOLDINGS.getCode())) || (docType
752 .equalsIgnoreCase(DocType.ITEM.getCode()))) {
753 instanceId = editorForm.getInstanceId();
754 }
755 if (StringUtils.isNotEmpty(instanceId)) {
756 bibUUIDList = queryService.queryForBibs(instanceId);
757 }
758 DocstoreHelperService docstoreHelperService = new DocstoreHelperService();
759 if (bibUUIDList != null && bibUUIDList.size() > 0) {
760 for (String bibUUID : bibUUIDList) {
761 WorkBibDocument workBibDocument = new WorkBibDocument();
762 workBibDocument.setId(bibUUID);
763 workBibDocument = docstoreHelperService.getInfoForBibTree(workBibDocument);
764 workBibDocumentList.add(workBibDocument);
765 }
766 }
767
768 editorForm.setWorkBibDocumentList(workBibDocumentList);
769 } catch (SolrServerException e) {
770 LOG.error("Exception:" + e.getMessage(), e);
771 }
772 workEInstanceOlemlForm.setViewId("ShowBibViewPage");
773 return workEInstanceOlemlForm;
774 }
775
776 @Override
777 public EditorForm delete(EditorForm editorForm) throws Exception {
778 WorkEInstanceOlemlForm workEInstanceOlemlForm = new WorkEInstanceOlemlForm();
779 String operation = "delete";
780 BusinessObjectService boService = KRADServiceLocator.getBusinessObjectService();
781
782
783
784
785
786
787
788
789
790
791 String responseXml = getResponseFromDocStore(editorForm, editorForm.getDocId(), operation);
792 if (responseXml.contains("Success")) {
793 GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_INFO, "record.delete.message");
794 workEInstanceOlemlForm.setShowDeleteTree(false);
795 workEInstanceOlemlForm.setHasLink(false);
796 } else {
797 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, "record.delete.fail.message");
798 }
799 return workEInstanceOlemlForm;
800 }
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817 }