View Javadoc

1   package org.kuali.ole.select.controller;
2   
3   import org.kuali.ole.select.bo.OleGloballyProtectedField;
4   import org.kuali.ole.service.OleGloballyProtectedFieldService;
5   import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
6   import org.kuali.rice.krad.maintenance.MaintenanceDocument;
7   import org.kuali.rice.krad.maintenance.MaintenanceUtils;
8   import org.kuali.rice.krad.service.KRADServiceLocator;
9   import org.kuali.rice.krad.web.controller.MaintenanceDocumentController;
10  import org.kuali.rice.krad.web.form.MaintenanceDocumentForm;
11  import org.springframework.stereotype.Controller;
12  import org.springframework.validation.BindingResult;
13  import org.springframework.web.bind.annotation.ModelAttribute;
14  import org.springframework.web.bind.annotation.RequestMapping;
15  import org.springframework.web.servlet.ModelAndView;
16  
17  import javax.servlet.http.HttpServletRequest;
18  import javax.servlet.http.HttpServletResponse;
19  
20  /**
21   * OleBibProtectedFieldController is the controller class for Bib Protected Field Maintenance Document.
22   */
23  @Controller
24  @RequestMapping(value = "/oleGloballyProtectedFieldMaintenance")
25  public class OleGloballyProtectedFieldController extends MaintenanceDocumentController {
26  
27  
28      @Override
29      protected OleGloballyProtectedFieldService getMaintenanceDocumentService() {
30          return GlobalResourceLoader.getService("oleGloballyProtectedFieldService");
31      }
32  
33      /**
34       * This method invokes setupMaintenanceForDelete method to populate the document for deleting.
35       *
36       * @param form
37       * @param result
38       * @param request
39       * @param response
40       * @return ModelAndView
41       * @throws Exception
42       */
43      @RequestMapping(params = "methodToCall=" + "maintenanceDelete")
44      public ModelAndView maintenanceDelete(@ModelAttribute("KualiForm") MaintenanceDocumentForm form, BindingResult result,
45                                            HttpServletRequest request, HttpServletResponse response) throws Exception {
46          setupMaintenanceForDelete(form, request, "Delete");
47          return getUIFModelAndView(form);
48      }
49  
50      /**
51       * This method populates confirmation to delete the document.
52       *
53       * @param form
54       * @param request
55       * @param maintenanceAction
56       */
57      protected void setupMaintenanceForDelete(MaintenanceDocumentForm form, HttpServletRequest request, String maintenanceAction) {
58          MaintenanceDocument document = form.getDocument();
59          OleGloballyProtectedFieldService maintenanceDocumentService = getMaintenanceDocumentService();
60          if (document == null) {
61              document = maintenanceDocumentService.setupNewMaintenanceDocument(form.getDataObjectClassName(), form.getDocTypeName(),
62                      maintenanceAction);
63              form.setDocument(document);
64              form.setDocTypeName(document.getDocumentHeader().getWorkflowDocument().getDocumentTypeName());
65          }
66  
67          form.setMaintenanceAction(maintenanceAction);
68          maintenanceDocumentService.setupMaintenanceObjectForDelete(document, maintenanceAction, request.getParameterMap());
69          MaintenanceUtils.checkForLockingDocument(document, false);
70      }
71  
72      /**
73       * This method invokes deleteAttachment method to delete attachment and set the error accordingly ..
74       *
75       * @param form
76       * @param result
77       * @param request
78       * @param response
79       * @return ModelAndView
80       * @throws Exception
81       */
82      @RequestMapping(params = "methodToCall=" + "deleteDocument")
83      public ModelAndView deleteDocument(@ModelAttribute("KualiForm") MaintenanceDocumentForm form, BindingResult result,
84                                         HttpServletRequest request, HttpServletResponse response) throws Exception {
85          MaintenanceDocument document = form.getDocument();
86          if (document.getDocumentDataObject() != null) {
87              OleGloballyProtectedField oleGloballyProtectedField = (OleGloballyProtectedField) document.getDocumentDataObject();
88              KRADServiceLocator.getBusinessObjectService().delete(oleGloballyProtectedField);
89          }
90          return close(form, result, request, response);
91      }
92  
93  }