001package org.kuali.ole.batch.controller; 002 003import org.apache.commons.io.IOUtils; 004import org.apache.log4j.Logger; 005import org.kuali.ole.batch.form.OLEDeliverNoticeForm; 006import org.kuali.ole.batch.service.OLEDeliverNoticeService; 007import org.kuali.rice.krad.web.controller.UifControllerBase; 008import org.kuali.rice.krad.web.form.UifFormBase; 009import org.springframework.stereotype.Controller; 010import org.springframework.validation.BindingResult; 011import org.springframework.web.bind.annotation.ModelAttribute; 012import org.springframework.web.bind.annotation.RequestMapping; 013import org.springframework.web.servlet.ModelAndView; 014 015import javax.servlet.http.HttpServletRequest; 016import javax.servlet.http.HttpServletResponse; 017import java.io.File; 018import java.io.FileInputStream; 019import java.io.InputStream; 020 021/** 022 * Created with IntelliJ IDEA. 023 * User: maheswarang 024 * Date: 8/7/13 025 * Time: 8:15 PM 026 * To change this template use File | Settings | File Templates. 027 */ 028@Controller 029@RequestMapping(value = "/oleDeliverNoticeController") 030public class OLEDeliverNoticeController extends UifControllerBase { 031 private static final Logger LOG = Logger.getLogger(OLEDeliverNoticeController.class); 032 @Override 033 protected OLEDeliverNoticeForm createInitialForm(HttpServletRequest request) { 034 return new OLEDeliverNoticeForm(); 035 } 036 037 038 @Override 039 @RequestMapping(params = "methodToCall=start") 040 public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, 041 HttpServletRequest request, HttpServletResponse response) { 042 OLEDeliverNoticeForm oleDeliverNoticeForm = (OLEDeliverNoticeForm)form; 043 OLEDeliverNoticeService oleNoticeService = new OLEDeliverNoticeService(); 044 oleDeliverNoticeForm = oleNoticeService.populateOLEDeliverNoticeForm(oleDeliverNoticeForm); 045 return getUIFModelAndView(oleDeliverNoticeForm, "OLEDeliverNoticeViewPage"); 046 047 } 048 049 @RequestMapping(params = "methodToCall=downloadAttachment") 050 public ModelAndView downloadAttachment(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, 051 HttpServletRequest request, HttpServletResponse response) throws Exception { 052 String filePath = request.getParameter("filePath"); 053 String fileName=request.getParameter("fileName"); 054 LOG.info("File Path : " +filePath); 055 File file=new File(filePath); 056 response.setContentType("application/octet-stream"); 057 response.setHeader("Content-disposition", "attachment; filename=" + fileName); 058 response.setHeader("Expires", "0"); 059 response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); 060 response.setHeader("Pragma", "public"); 061 response.setContentLength((int) file.length()); 062 InputStream fis = new FileInputStream(file); 063 IOUtils.copy(fis, response.getOutputStream()); 064 response.getOutputStream().flush(); 065 return null; 066 } 067 068 069}