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.OLEClaimNoticeForm;
6   import org.kuali.ole.batch.service.OLEClaimNoticeService;
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   * To change this template use File | Settings | File Templates.
24   */
25  @Controller
26  @RequestMapping(value = "/oleClaimNoticeController")
27  public class OLEClaimNoticeController extends UifControllerBase {
28      private static final Logger LOG = Logger.getLogger(OLEClaimNoticeController.class);
29      @Override
30      protected OLEClaimNoticeForm createInitialForm(HttpServletRequest request) {
31          return new OLEClaimNoticeForm();
32      }
33  
34  
35      @Override
36      @RequestMapping(params = "methodToCall=start")
37      public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
38                                HttpServletRequest request, HttpServletResponse response) {
39        OLEClaimNoticeForm oleClaimNoticeForm = (OLEClaimNoticeForm)form;
40          OLEClaimNoticeService oleNoticeService = new OLEClaimNoticeService();
41          oleClaimNoticeForm =  oleNoticeService.populateOLEClaimNoticeForm(oleClaimNoticeForm);
42          return getUIFModelAndView(oleClaimNoticeForm, "OLEClaimNoticeViewPage");
43  
44      }
45  
46      @RequestMapping(params = "methodToCall=downloadAttachment")
47      public ModelAndView downloadAttachment(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
48                                             HttpServletRequest request, HttpServletResponse response) throws Exception {
49          String filePath = request.getParameter("filePath");
50          String fileName=request.getParameter("fileName");
51          LOG.info("File Path : " +filePath);
52          File file=new File(filePath);
53          response.setContentType("application/octet-stream");
54          response.setHeader("Content-disposition", "attachment; filename=" + fileName);
55          response.setHeader("Expires", "0");
56          response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
57          response.setHeader("Pragma", "public");
58          response.setContentLength((int) file.length());
59          InputStream fis = new FileInputStream(file);
60          IOUtils.copy(fis, response.getOutputStream());
61          response.getOutputStream().flush();
62          return null;
63      }
64  
65  
66  }