1 package org.kuali.ole.describe.controller;
2
3 import org.apache.log4j.Logger;
4 import org.kuali.ole.OLEConstants;
5 import org.kuali.ole.describe.bo.EditorFormDataHandler;
6 import org.kuali.ole.describe.form.EditorForm;
7 import org.kuali.ole.describe.form.WorkBibMarcForm;
8 import org.kuali.ole.describe.form.WorkInstanceOlemlForm;
9 import org.kuali.ole.docstore.model.bo.WorkBibDocument;
10 import org.kuali.ole.docstore.model.bo.WorkInstanceDocument;
11 import org.kuali.ole.docstore.model.enums.DocFormat;
12 import org.kuali.ole.docstore.model.enums.DocType;
13 import org.kuali.ole.docstore.model.xmlpojo.ingest.Request;
14 import org.kuali.ole.editor.service.DiscoveryHelperService;
15 import org.kuali.ole.editor.service.DocstoreHelperService;
16 import org.kuali.rice.krad.web.controller.UifControllerBase;
17 import org.kuali.rice.krad.web.form.UifFormBase;
18 import org.springframework.stereotype.Controller;
19 import org.springframework.validation.BindingResult;
20 import org.springframework.web.bind.annotation.ModelAttribute;
21 import org.springframework.web.bind.annotation.RequestMapping;
22 import org.springframework.web.servlet.ModelAndView;
23
24 import javax.servlet.http.HttpServletRequest;
25 import javax.servlet.http.HttpServletResponse;
26 import java.io.IOException;
27 import java.util.ArrayList;
28 import java.util.Iterator;
29 import java.util.List;
30 import java.util.Map;
31
32
33
34
35
36
37
38
39
40 @Controller
41 @RequestMapping(value = "/editorcontroller")
42
43 public class EditorController extends UifControllerBase {
44
45 private DocumentEditor editor;
46 private EditorFormDataHandler editorFormDataHandler;
47 private DiscoveryHelperService discoveryHelperService;
48 private boolean isFormInitialized = false;
49 private DocstoreHelperService docstoreHelperService;
50
51
52 private static final Logger LOG = Logger.getLogger(EditorController.class);
53
54 @Override
55 protected UifFormBase createInitialForm(HttpServletRequest httpServletRequest) {
56 UifFormBase uifFormBase = null;
57 uifFormBase = new EditorForm();
58 return uifFormBase;
59 }
60
61 @Override
62 @RequestMapping(params = "methodToCall=start")
63 public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
64 HttpServletRequest request, HttpServletResponse response) {
65
66 if (!isFormInitialized) {
67 super.start(form, result, request, response);
68 isFormInitialized = true;
69 }
70 EditorForm editorForm = (EditorForm) form;
71 ModelAndView modelAndView = null;
72
73 String docCategory = request.getParameter("docCategory");
74 String docType = request.getParameter("docType");
75 String docFormat = request.getParameter("docFormat");
76 String editable = request.getParameter("editable");
77
78 if (null == editable || editable.length() > 0) {
79 editable = "true";
80 }
81
82 ((EditorForm) form).setEditable(editable);
83 ((EditorForm) form).setDocCategory(docCategory);
84 ((EditorForm) form).setDocType(docType);
85 ((EditorForm) form).setDocFormat(docFormat);
86
87 if (docFormat.equals(DocFormat.MARC.getCode())) {
88 editorForm.setDocumentForm(new WorkBibMarcForm());
89 modelAndView = getUIFModelAndView(form, "WorkBibEditorViewPage");
90 }
91 else if (docType.equals(DocType.INSTANCE.getCode()) || docType.equals(DocType.INSTANCE.getCode())) {
92 editorForm.setDocumentForm(new WorkInstanceOlemlForm());
93 modelAndView = getUIFModelAndView(form, "WorkHoldingsViewPage");
94 }
95 else if (docType.equals(DocType.ITEM.getCode())) {
96 editorForm.setDocumentForm(new WorkInstanceOlemlForm());
97 modelAndView = getUIFModelAndView(form, "WorkItemViewPage");
98 }
99 return modelAndView;
100 }
101
102
103
104
105
106
107
108
109
110
111 @RequestMapping(params = "methodToCall=load")
112 public ModelAndView load(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
113 HttpServletRequest request, HttpServletResponse response) {
114 if (!isFormInitialized) {
115 super.start(form, result, request, response);
116 isFormInitialized = true;
117 }
118
119
120 String docCategory = request.getParameter("docCategory");
121 String docType = request.getParameter("docType");
122 String docFormat = request.getParameter("docFormat");
123 String docId = request.getParameter("docId");
124 String bibId = request.getParameter("bibId");
125 String instanceId = request.getParameter("instanceId");
126 String editable = request.getParameter("editable");
127
128 if ((null == editable) || (editable.length() == 0)) {
129 editable = "true";
130 }
131
132 ((EditorForm) form).setEditable(editable);
133 ((EditorForm) form).setDocCategory(docCategory);
134 ((EditorForm) form).setDocType(docType);
135 ((EditorForm) form).setDocFormat(docFormat);
136 ((EditorForm) form).setDocId(docId);
137 ((EditorForm) form).setBibId(bibId);
138 ((EditorForm) form).setInstanceId(instanceId);
139
140
141 DocumentEditor documentEditor = DocumentEditorFactory.getInstance()
142 .getDocumentEditor(docCategory, docType, docFormat);
143
144
145
146 List<WorkBibDocument> workBibDocumentList = (List) request.getSession().getAttribute("treeDocumentList");
147 if (null != workBibDocumentList) {
148 ((EditorForm) form).setWorkBibDocumentList(workBibDocumentList);
149 }
150 EditorForm documentForm = null;
151
152 if (request.getSession() != null && request.getSession().getAttribute("requestObject") != null) {
153 Request req = (Request) request.getSession().getAttribute("requestObject");
154 if (docId != null && docId.length() > 0 && !docId.equalsIgnoreCase("null")) {
155 ((EditorForm) form).setShowLeftPane("false");
156 }
157 else {
158 ((EditorForm) form).setShowLeftPane("false");
159 ((EditorForm) form).setShowEditorFooter("false");
160 }
161 documentForm = documentEditor.createNewRecord((EditorForm) form, req);
162 }
163 else {
164
165 documentForm = documentEditor.loadDocument((EditorForm) form);
166 }
167
168
169 ((EditorForm) form).setDocumentForm(documentForm);
170
171 request.getSession().setAttribute("treeDocumentList", ((EditorForm) form).getWorkBibDocumentList());
172
173
174 getEditorFormDataHandler().buildLeftPaneData((EditorForm) form);
175
176
177 ModelAndView modelAndView = getUIFModelAndView(form, documentForm.getViewId());
178 return modelAndView;
179 }
180
181 @RequestMapping(params = "methodToCall=updateLeftPane")
182 public ModelAndView updateLeftPane(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
183 HttpServletRequest request, HttpServletResponse response) {
184 EditorForm editorForm = (EditorForm) form;
185 String hiddenVal = editorForm.getHdnUuid();
186 int hdnIndex = editorForm.getHdnIndex();
187 DiscoveryHelperService discoveryHelperService = getDiscoveryHelperService();
188 List responseFromSOLR = discoveryHelperService.getResponseFromSOLR("id", hiddenVal);
189 String docType = null;
190 for (Iterator iterator = responseFromSOLR.iterator(); iterator.hasNext(); ) {
191 Map map = (Map) iterator.next();
192 if (map.containsKey(OLEConstants.DOC_TYPE)) {
193 String list = (String) map.get(OLEConstants.DOC_TYPE);
194 docType = list;
195 break;
196 }
197 }
198 if ((docType.toString().equals(OLEConstants.ITEM_DOC_TYPE))) {
199 WorkInstanceOlemlForm instanceEditorForm = new WorkInstanceOlemlForm();
200
201
202
203
204
205
206
207 return null;
208 } else {
209
210 return getUIFModelAndView(editorForm, "WorkHoldingsViewPage");
211 }
212 }
213
214 public DiscoveryHelperService getDiscoveryHelperService() {
215 if (null == discoveryHelperService) {
216 return new DiscoveryHelperService();
217 }
218 return discoveryHelperService;
219 }
220
221 public EditorFormDataHandler getEditorFormDataHandler() {
222 if (null == editorFormDataHandler) {
223 editorFormDataHandler = new EditorFormDataHandler();
224 }
225 return editorFormDataHandler;
226 }
227
228 @RequestMapping(params = "methodToCall=EditNewInstance")
229 public ModelAndView EditNewInstance(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
230 HttpServletRequest request, HttpServletResponse response) {
231
232 EditorForm editorForm = (EditorForm) form;
233
234 Request req = (Request) request.getSession().getAttribute("requestObject");
235
236 List<WorkBibDocument> workBibDocumentList = (List) request.getSession().getAttribute("treeDocumentList");
237 if (null != workBibDocumentList) {
238 ((EditorForm) form).setWorkBibDocumentList(workBibDocumentList);
239 }
240 if (editorForm.getDocumentForm().getViewId().equalsIgnoreCase("WorkHoldingsViewPage")) {
241
242 DocumentEditor documentEditor = DocumentEditorFactory.getInstance()
243 .getDocumentEditor("work", "item", "oleml");
244
245 editorForm = documentEditor.createNewRecord((EditorForm) form, req);
246 editorForm.setNeedToCreateInstance("false");
247
248 }
249 else {
250
251 DocumentEditor documentEditor = DocumentEditorFactory.getInstance()
252 .getDocumentEditor("work", "bibliographic", "marc");
253
254 documentEditor.editNewRecord(editorForm, req);
255
256 documentEditor = DocumentEditorFactory.getInstance().getDocumentEditor("work", "instance", "oleml");
257 ((EditorForm) form).setDocCategory("work");
258 ((EditorForm) form).setDocType("instance");
259 ((EditorForm) form).setDocFormat("oleml");
260 editorForm = documentEditor.createNewRecord((EditorForm) form, req);
261 }
262
263
264 ((EditorForm) form).setDocumentForm(editorForm);
265
266 request.getSession().setAttribute("treeDocumentList", ((EditorForm) form).getWorkBibDocumentList());
267
268
269 getEditorFormDataHandler().buildLeftPaneData((EditorForm) form);
270
271
272 ModelAndView modelAndView = getUIFModelAndView(form, editorForm.getViewId());
273 return modelAndView;
274
275 }
276
277 @RequestMapping(params = "methodToCall=save")
278 public ModelAndView save(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
279 HttpServletRequest request, HttpServletResponse response) {
280
281 if (request.getSession() != null && request.getSession().getAttribute("requestObject") != null
282 && ((EditorForm) form).getDocId() == null) {
283 Request req = (Request) request.getSession().getAttribute("requestObject");
284 DocumentEditor documentEditor = DocumentEditorFactory.getInstance()
285 .getDocumentEditor("work", "instance", "oleml");
286 documentEditor.editNewRecord((EditorForm) form, req);
287 String responseFromDocstore = documentEditor.saveDocument(req);
288 if (responseFromDocstore.contains("success")) {
289 request.getSession().setAttribute("responseString", responseFromDocstore);
290 try {
291 response.sendRedirect(request.getContextPath()
292 + "/kr-krad/importBibController?viewId=ImportBibView&methodToCall=viewRecordNext");
293 }
294 catch (IOException e) {
295 ((EditorForm) form).getDocumentForm()
296 .setMessage("Problem in navigating to Import bib Process" + e.getMessage());
297 }
298 }
299 else {
300 ((EditorForm) form).getDocumentForm().setMessage(responseFromDocstore.toString());
301 }
302 }
303 else {
304 if (!isFormInitialized) {
305 super.start(form, result, request, response);
306 isFormInitialized = true;
307 }
308
309
310 String docCategory = request.getParameter("docCategory");
311 String docType = request.getParameter("docType");
312 String docFormat = request.getParameter("docFormat");
313 String docId = request.getParameter("docId");
314 String bibId = request.getParameter("bibId");
315 String instanceId = request.getParameter("instanceId");
316
317 String editable = request.getParameter("editable");
318
319 if ((null == editable) || (editable.length() == 0)) {
320 editable = "true";
321 }
322 if (docCategory == null || docCategory.length() == 0) {
323 docCategory = ((EditorForm) form).getDocCategory();
324 }
325 if (docType == null || docType.length() == 0) {
326 docType = ((EditorForm) form).getDocType();
327 }
328
329 if (docFormat == null || docFormat.length() == 0) {
330 docFormat = ((EditorForm) form).getDocFormat();
331 }
332 if (docId == null || docId.length() == 0) {
333 docId = ((EditorForm) form).getDocId();
334 }
335
336 ((EditorForm) form).setEditable(editable);
337 ((EditorForm) form).setDocCategory(docCategory);
338 ((EditorForm) form).setDocType(docType);
339 ((EditorForm) form).setDocFormat(docFormat);
340 ((EditorForm) form).setDocId(docId);
341 ((EditorForm) form).setBibId(bibId);
342 ((EditorForm) form).setInstanceId(instanceId);
343
344
345 DocumentEditor documentEditor = DocumentEditorFactory.getInstance()
346 .getDocumentEditor(docCategory, docType, docFormat);
347
348
349
350 List<WorkBibDocument> workBibDocumentList = (List) request.getSession().getAttribute("treeDocumentList");
351 if (null != workBibDocumentList) {
352 ((EditorForm) form).setWorkBibDocumentList(workBibDocumentList);
353 }
354
355
356 EditorForm documentForm = documentEditor.saveDocument((EditorForm) form);
357
358
359 ((EditorForm) form).setDocumentForm(documentForm);
360
361 request.getSession().setAttribute("treeDocumentList", ((EditorForm) form).getWorkBibDocumentList());
362
363
364 getEditorFormDataHandler().buildLeftPaneData((EditorForm) form);
365
366 }
367
368
369 ModelAndView modelAndView = getUIFModelAndView(form, ((EditorForm) form).getDocumentForm().getViewId());
370 return modelAndView;
371 }
372
373
374
375
376
377
378
379
380
381
382 @RequestMapping(params = "methodToCall=addControlField")
383 public ModelAndView addControlField(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
384 HttpServletRequest request, HttpServletResponse response) {
385 if (!isFormInitialized) {
386 super.start(form, result, request, response);
387 isFormInitialized = true;
388 }
389 String docCategory = request.getParameter("docCategory");
390 String docType = request.getParameter("docType");
391 String docFormat = request.getParameter("docFormat");
392 DocumentEditor documentEditor = DocumentEditorFactory.getInstance()
393 .getDocumentEditor(docCategory, docType, docFormat);
394 EditorForm editorForm = (EditorForm) form;
395 editorForm = documentEditor.addORDeleteFields(editorForm, request);
396 return super.updateComponent(editorForm, result, request, response);
397 }
398
399
400
401
402
403
404
405
406
407
408 @RequestMapping(params = "methodToCall=removeControlField")
409 public ModelAndView removeControlField(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
410 HttpServletRequest request, HttpServletResponse response) {
411 if (!isFormInitialized) {
412 super.start(form, result, request, response);
413 isFormInitialized = true;
414 }
415 String docCategory = request.getParameter("docCategory");
416 String docType = request.getParameter("docType");
417 String docFormat = request.getParameter("docFormat");
418 DocumentEditor documentEditor = DocumentEditorFactory.getInstance()
419 .getDocumentEditor(docCategory, docType, docFormat);
420 EditorForm editorForm = (EditorForm) form;
421 editorForm = documentEditor.addORDeleteFields(editorForm, request);
422 return super.updateComponent(editorForm, result, request, response);
423 }
424
425
426
427
428
429
430
431
432
433
434 @RequestMapping(params = "methodToCall=addDataField")
435 public ModelAndView addDataField(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
436 HttpServletRequest request, HttpServletResponse response) {
437 if (!isFormInitialized) {
438 super.start(form, result, request, response);
439 isFormInitialized = true;
440 }
441 String docCategory = request.getParameter("docCategory");
442 String docType = request.getParameter("docType");
443 String docFormat = request.getParameter("docFormat");
444 DocumentEditor documentEditor = DocumentEditorFactory.getInstance()
445 .getDocumentEditor(docCategory, docType, docFormat);
446 EditorForm editorForm = (EditorForm) form;
447 editorForm = documentEditor.addORDeleteFields(editorForm, request);
448 return super.updateComponent(editorForm, result, request, response);
449 }
450
451
452
453
454
455
456
457
458
459
460 @RequestMapping(params = "methodToCall=removeDataField")
461 public ModelAndView removeDataField(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
462 HttpServletRequest request, HttpServletResponse response) {
463 if (!isFormInitialized) {
464 super.start(form, result, request, response);
465 isFormInitialized = true;
466 }
467 String docCategory = request.getParameter("docCategory");
468 String docType = request.getParameter("docType");
469 String docFormat = request.getParameter("docFormat");
470 DocumentEditor documentEditor = DocumentEditorFactory.getInstance()
471 .getDocumentEditor(docCategory, docType, docFormat);
472 EditorForm editorForm = (EditorForm) form;
473 editorForm = documentEditor.addORDeleteFields(editorForm, request);
474 return super.updateComponent(editorForm, result, request, response);
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
503
504
505
506
507
508
509
510
511
512
513 private DocstoreHelperService getDocstoreHelperService() {
514 if (null == docstoreHelperService) {
515 return new DocstoreHelperService();
516 }
517 return docstoreHelperService;
518 }
519
520
521
522
523
524
525
526
527
528 @RequestMapping(params = "methodToCall=deleteVerify")
529 public ModelAndView deleteVerify(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
530 HttpServletRequest request, HttpServletResponse response) throws Exception {
531 ModelAndView modelAndView = null;
532 if (!isFormInitialized) {
533 super.start(form, result, request, response);
534 isFormInitialized = true;
535 }
536
537
538 String docCategory = request.getParameter("docCategory");
539 String docType = request.getParameter("docType");
540 String docFormat = request.getParameter("docFormat");
541 String docId = request.getParameter("docId");
542 ((EditorForm) form).setDocCategory(docCategory);
543 ((EditorForm) form).setDocType(docType);
544 ((EditorForm) form).setDocFormat(docFormat);
545 ((EditorForm) form).setDocId(docId);
546
547
548 DocumentEditor documentEditor = DocumentEditorFactory.getInstance().getDocumentEditor(docCategory, docType, docFormat);
549 EditorForm documentForm = documentEditor.deleteVerify((EditorForm) form);
550 LOG.info("view id-->"+documentForm.getViewId());
551
552 EditorForm editorForm = (EditorForm) form;
553
554
555
556
557
558
559
560
561 return getUIFModelAndView(editorForm,documentForm.getViewId());
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588 }
589
590
591
592
593
594
595
596
597
598 @RequestMapping(params = "methodToCall=delete")
599 public ModelAndView delete(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
600 HttpServletRequest request, HttpServletResponse response) throws Exception {
601 ModelAndView modelAndView = null;
602 EditorForm editorForm = (EditorForm) form;
603 if (!isFormInitialized) {
604 super.start(form, result, request, response);
605 isFormInitialized = true;
606 }
607
608
609 String docCategory = ((EditorForm) form).getDocCategory();
610 String docType = ((EditorForm) form).getDocType();
611 String docFormat = ((EditorForm) form).getDocFormat();
612 String docId = ((EditorForm) form).getDocId();
613
614
615
616
617 LOG.info("docCategory-->"+docCategory);
618 LOG.info("docType-->"+docType);
619 LOG.info("docFormat-->"+docFormat);
620 LOG.info("uuid-->"+docId);
621
622
623
624
625
626
627
628
629 DocumentEditor documentEditor = DocumentEditorFactory.getInstance().getDocumentEditor(docCategory, docType, docFormat);
630
631 EditorForm documentForm = documentEditor.delete((EditorForm)form);
632
633
634
635
636
637
638
639
640
641
642
643 return getUIFModelAndView(editorForm,documentForm.getViewId());
644 }
645
646 private boolean delete()
647 {
648 boolean hasLinks = false;
649 EditorForm editorForm = new EditorForm();
650 List<String> uuidList = new ArrayList<String>();
651 uuidList.add(editorForm.getDocId());
652 DocstoreHelperService docstoreHelperService = new DocstoreHelperService();
653 List<WorkBibDocument> workBibDocumentList = new ArrayList<WorkBibDocument>();
654 for (String bibUuid : uuidList) {
655 WorkBibDocument workBibDocument = new WorkBibDocument();
656 workBibDocument.setId(bibUuid);
657 workBibDocumentList.add(docstoreHelperService.getInfoForBibTree(workBibDocument));
658 }
659 for (WorkBibDocument workBibDocument : workBibDocumentList) {
660 workBibDocument.getWorkInstanceDocumentList();
661 List<WorkInstanceDocument> workInstanceDocuments = workBibDocument.getWorkInstanceDocumentList();
662 if (workInstanceDocuments != null && workInstanceDocuments.size() > 0) {
663 for (WorkInstanceDocument workInstanceDocument : workInstanceDocuments) {
664 if (workInstanceDocument.getItemDocumentList().size() > 0) {
665 hasLinks = true;
666 }
667 }
668 }
669 }
670 return hasLinks;
671 }
672
673
674
675
676
677 }