View Javadoc

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   * Created with IntelliJ IDEA.
34   * User: PP7788
35   * Date: 12/6/12
36   * Time: 4:34 PM
37   * To change this template use File | Settings | File Templates.
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      * Load a (new or existing) document in the editor.
104      *
105      * @param form
106      * @param result
107      * @param request
108      * @param response
109      * @return
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         // get the document details from request and set them in the form.
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         // Identify the document editor to be used for the requested document.
141         DocumentEditor documentEditor = DocumentEditorFactory.getInstance()
142                                                              .getDocumentEditor(docCategory, docType, docFormat);
143 
144         // TODO: Need to save the editorForm in the session.
145         // Get documentList from session.
146         List<WorkBibDocument> workBibDocumentList = (List) request.getSession().getAttribute("treeDocumentList");
147         if (null != workBibDocumentList) {
148             ((EditorForm) form).setWorkBibDocumentList(workBibDocumentList);
149         }
150         EditorForm documentForm = null;
151         //get request object fromm session and build new work bib marc record.
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             // Send the input through one (request)form and get the output through another (response) form.
165             documentForm = documentEditor.loadDocument((EditorForm) form);
166         }
167 
168         // Set the output (response) form containing document info into the current form.
169         ((EditorForm) form).setDocumentForm(documentForm);
170         // Set documentlist to session.
171         request.getSession().setAttribute("treeDocumentList", ((EditorForm) form).getWorkBibDocumentList());
172 
173         // Build or update left pane data (tree structure of documents)
174         getEditorFormDataHandler().buildLeftPaneData((EditorForm) form);
175 
176         // Return the next view to be shown to user.
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             //instanceEditorForm.setInstance(editorForm.getInstance());
201             //instanceEditorForm.setUuid(editorForm.getInstance().getInstanceIdentifier());
202             //editor = new WorkInstanceOlemlEditor();
203             //instanceEditorForm.setSelectedItem(editorForm.getInstance().getItems().getItem().get(hdnIndex));
204             //return getUIFModelAndView(editorForm, "WorkItemViewPage");
205             //ModelAndView modelAndView = editor.load(form, result, request, response);
206             //return modelAndView;
207             return null;
208         } else {
209             //editorForm.setSelectedHolding(editorForm.getInstance().getOleHoldings());
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         // get request object from session
234         Request req = (Request) request.getSession().getAttribute("requestObject");
235         // Get documentList from session.
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             // call instance editor
242             DocumentEditor documentEditor = DocumentEditorFactory.getInstance()
243                                                                  .getDocumentEditor("work", "item", "oleml");
244             // set item record to display on item tab
245             editorForm = documentEditor.createNewRecord((EditorForm) form, req);
246             editorForm.setNeedToCreateInstance("false");
247 
248         }
249         else {
250             // call bib editor to store bib data
251             DocumentEditor documentEditor = DocumentEditorFactory.getInstance()
252                                                                  .getDocumentEditor("work", "bibliographic", "marc");
253             // update request object with modified marc data.
254             documentEditor.editNewRecord(editorForm, req);
255             // call instance editor and set holding record to display on holding tab
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         // Set the output (response) form containing document info into the current form.
264         ((EditorForm) form).setDocumentForm(editorForm);
265         // Set documentlist to session.
266         request.getSession().setAttribute("treeDocumentList", ((EditorForm) form).getWorkBibDocumentList());
267 
268         // Build or update left pane data (tree structure of documents)
269         getEditorFormDataHandler().buildLeftPaneData((EditorForm) form);
270 
271         // Return the next view to be shown to user.
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             // get the document details from request and set them in the form.
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             // Identify the document editor to be used for the requested document.
345             DocumentEditor documentEditor = DocumentEditorFactory.getInstance()
346                                                                  .getDocumentEditor(docCategory, docType, docFormat);
347 
348             // TODO: Need to save the editorForm in the session.
349             // Get documentList from session.
350             List<WorkBibDocument> workBibDocumentList = (List) request.getSession().getAttribute("treeDocumentList");
351             if (null != workBibDocumentList) {
352                 ((EditorForm) form).setWorkBibDocumentList(workBibDocumentList);
353             }
354 
355             // Send the input through one (request)form and get the output through another (response) form.
356             EditorForm documentForm = documentEditor.saveDocument((EditorForm) form);
357 
358             // Set the output (response) form containing document info into the current form.
359             ((EditorForm) form).setDocumentForm(documentForm);
360             // Set documentlist to session.
361             request.getSession().setAttribute("treeDocumentList", ((EditorForm) form).getWorkBibDocumentList());
362 
363             // Build or update left pane data (tree structure of documents)
364             getEditorFormDataHandler().buildLeftPaneData((EditorForm) form);
365 
366         }
367 
368         // Return the next view to be shown to user.
369         ModelAndView modelAndView = getUIFModelAndView(form, ((EditorForm) form).getDocumentForm().getViewId());
370         return modelAndView;
371     }
372 
373     /**
374      * This method will add the controlField record based on the selected Line index and updates the component.
375      *
376      * @param form
377      * @param result
378      * @param request
379      * @param response
380      * @return ModelAndView
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      * This method will remove the controlField based on the index position and updates the component.
401      *
402      * @param form
403      * @param result
404      * @param request
405      * @param response
406      * @return ModelAndView
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      * This method will add the datField record based on the selected Line index and updates the component.
427      *
428      * @param form
429      * @param result
430      * @param request
431      * @param response
432      * @return ModelAndView
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      * This method will remove the dataField based on the index position and updates the component.
453      *
454      * @param form
455      * @param result
456      * @param request
457      * @param response
458      * @return ModelAndView
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     private UifFormBase buildUifForm (HttpServletRequest httpServletRequest) {
479         UifFormBase uifFormBase = null;
480 
481         String docType = httpServletRequest.getParameter("docType");
482         String docFormat = httpServletRequest.getParameter("docFormat");
483         if ("bibliographic".equalsIgnoreCase(docType)) {
484             if ("marc".equalsIgnoreCase(docFormat)) {
485                 LOG.info("Inside EditorController createInitialForm if bibliographic marc");
486                 editor = new WorkBibMarcEditor();
487                 uifFormBase = editor.createInitialForm(httpServletRequest);
488             } else if ("dublin".equalsIgnoreCase(docFormat)) {
489                 editor = new WorkBibDublinEditor();
490                 uifFormBase = editor.createInitialForm(httpServletRequest);
491             }
492         } else if ("instance".equalsIgnoreCase(docType)) {
493             if ("oleml".equalsIgnoreCase(docFormat)) {
494                 editor = new WorkInstanceOlemlEditor();
495                 uifFormBase = editor.createInitialForm(httpServletRequest);
496             }
497         } else if ("holdings".equalsIgnoreCase(docType) || "item".equalsIgnoreCase(docType)) {
498             if ("oleml".equalsIgnoreCase(docFormat)) {
499                 editor = new WorkInstanceOlemlEditor();
500                 uifFormBase = editor.createInitialForm(httpServletRequest);
501             }
502         }
503         return uifFormBase;
504 
505     }
506 */
507 
508     /**
509      * Gets the docstoreHelperService attribute.
510      *
511      * @return DocstoreHelperService
512      */
513     private DocstoreHelperService getDocstoreHelperService() {
514         if (null == docstoreHelperService) {
515             return new DocstoreHelperService();
516         }
517         return docstoreHelperService;
518     }
519 
520     /**
521      * DeleteVerify a  document in the editor.
522      * @param form
523      * @param result
524      * @param request
525      * @param response
526      * @return
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         // get the document details from request and set them in the form.
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         //List<String> uuidList  = new ArrayList<String>();
552         EditorForm editorForm = (EditorForm) form;
553         //uuidList.add(docId);
554 
555 /*        DocumentSelectionTree dst = new DocumentSelectionTree();
556         LOG.info("get uud list from form-->"+editorForm.getUuidList());
557         Node<DocumentTreeNode, String> rootNode = dst.add(editorForm.getUuidList());
558 
559          editorForm.getDocTree().setRootElement(rootNode);*/
560 
561         return getUIFModelAndView(editorForm,documentForm.getViewId());
562 /*
563         System.out.println("delete verify method is executed-----1");
564 
565         ((EditorForm) form).setDocCategory(docCategory);
566         ((EditorForm) form).setDocType(docType);
567         ((EditorForm) form).setDocFormat(docFormat);
568         ((EditorForm) form).setDocId(docId);
569 
570         // Identify the document editor to be used for the requested document.
571         DocumentEditor documentEditor = DocumentEditorFactory.getInstance().getDocumentEditor(docCategory, docType, docFormat);
572         System.out.println("delete verify method is executed-----2");
573         //EditorForm documentForm = null;
574         EditorForm documentForm = documentEditor.deleteVerify((EditorForm) form);
575         ((EditorForm) form).setDocumentForm(documentForm);
576 
577         try {
578             documentForm = documentEditor.deleteVerify((EditorForm) form);
579             modelAndView =getUIFModelAndView(form,documentForm.getViewId());
580             System.out.println("delete verify method is executed-----3");
581         }catch (Exception e) {
582             modelAndView =getUIFModelAndView(form,"WorkBibEditorViewPage");
583             System.out.println("delete verify method is executed-----4");
584         }
585         System.out.println("delete verify method is executed-----5");
586         return modelAndView;
587 */
588     }
589 
590     /**
591      * Delete a  document in the editor.
592      * @param form
593      * @param result
594      * @param request
595      * @param response
596      * @return
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         // get the document details from request and set them in the form.
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 /*        ((EditorForm) form).setDocCategory(docCategory);
624         ((EditorForm) form).setDocType(docType);
625         ((EditorForm) form).setDocFormat(docFormat);
626         ((EditorForm) form).setUuid(docId);*/
627 
628         // Identify the document editor to be used for the requested document.
629         DocumentEditor documentEditor = DocumentEditorFactory.getInstance().getDocumentEditor(docCategory, docType, docFormat);
630 
631         EditorForm documentForm  = documentEditor.delete((EditorForm)form);
632 
633  /*       //boolean hasLinks = delete();
634         try {
635 
636             modelAndView =getUIFModelAndView(form,"deleteConfirmation");
637         } catch (Exception e) {
638             modelAndView =getUIFModelAndView(form,"");
639             e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
640         }*/
641         // Send the input through one (request)form and get the output through another (response) form.
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 }