View Javadoc
1   package org.kuali.ole.batch.controller;
2   
3   import org.apache.commons.io.IOUtils;
4   import org.apache.log4j.Logger;
5   import org.kuali.ole.batch.form.OLEDeliverNoticeForm;
6   import org.kuali.ole.batch.service.OLEDeliverNoticeService;
7   import org.kuali.rice.krad.web.controller.UifControllerBase;
8   import org.kuali.rice.krad.web.form.UifFormBase;
9   import org.springframework.stereotype.Controller;
10  import org.springframework.validation.BindingResult;
11  import org.springframework.web.bind.annotation.ModelAttribute;
12  import org.springframework.web.bind.annotation.RequestMapping;
13  import org.springframework.web.servlet.ModelAndView;
14  
15  import javax.servlet.http.HttpServletRequest;
16  import javax.servlet.http.HttpServletResponse;
17  import java.io.File;
18  import java.io.FileInputStream;
19  import java.io.InputStream;
20  
21  /**
22   * Created with IntelliJ IDEA.
23   * User: maheswarang
24   * Date: 8/7/13
25   * Time: 8:15 PM
26   * To change this template use File | Settings | File Templates.
27   */
28  @Controller
29  @RequestMapping(value = "/oleDeliverNoticeController")
30  public class OLEDeliverNoticeController extends UifControllerBase {
31      private static final Logger LOG = Logger.getLogger(OLEDeliverNoticeController.class);
32      @Override
33      protected OLEDeliverNoticeForm createInitialForm(HttpServletRequest request) {
34          return new OLEDeliverNoticeForm();
35      }
36  
37  
38      @Override
39      @RequestMapping(params = "methodToCall=start")
40      public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
41                                HttpServletRequest request, HttpServletResponse response) {
42        OLEDeliverNoticeForm oleDeliverNoticeForm = (OLEDeliverNoticeForm)form;
43          OLEDeliverNoticeService oleNoticeService = new OLEDeliverNoticeService();
44          oleDeliverNoticeForm =  oleNoticeService.populateOLEDeliverNoticeForm(oleDeliverNoticeForm);
45          return getUIFModelAndView(oleDeliverNoticeForm, "OLEDeliverNoticeViewPage");
46  
47      }
48  
49      @RequestMapping(params = "methodToCall=downloadAttachment")
50      public ModelAndView downloadAttachment(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
51                                             HttpServletRequest request, HttpServletResponse response) throws Exception {
52          String filePath = request.getParameter("filePath");
53          String fileName=request.getParameter("fileName");
54          LOG.info("File Path : " +filePath);
55          File file=new File(filePath);
56          response.setContentType("application/octet-stream");
57          response.setHeader("Content-disposition", "attachment; filename=" + fileName);
58          response.setHeader("Expires", "0");
59          response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
60          response.setHeader("Pragma", "public");
61          response.setContentLength((int) file.length());
62          InputStream fis = new FileInputStream(file);
63          IOUtils.copy(fis, response.getOutputStream());
64          response.getOutputStream().flush();
65          return null;
66      }
67  
68  
69  }