Rev 23764 | Rev 23766 | Go to most recent revision | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | RSS feed
package com.spice.profitmandi.web.controller;import java.io.ByteArrayInputStream;import java.io.IOException;import java.io.InputStream;import javax.servlet.http.HttpServletRequest;import org.apache.http.Header;import org.apache.http.HttpResponse;import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.core.io.InputStreamResource;import org.springframework.core.io.InputStreamSource;import org.springframework.http.HttpHeaders;import org.springframework.http.HttpStatus;import org.springframework.http.MediaType;import org.springframework.http.ResponseEntity;import org.springframework.stereotype.Controller;import org.springframework.transaction.annotation.Transactional;import org.springframework.ui.Model;import org.springframework.web.bind.annotation.PathVariable;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import com.spice.profitmandi.common.enumuration.ReporticoProject;import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;import com.spice.profitmandi.common.services.ReporticoService;import com.spice.profitmandi.web.model.LoginDetails;import com.spice.profitmandi.web.util.CookiesProcessor;@Controller@Transactional(rollbackFor = Throwable.class)public class ReportsController {@Autowiredprivate CookiesProcessor cookiesProcessor;@Autowiredprivate ReporticoService reporticoService;private static final Logger log = LogManager.getLogger(OrderController.class);@RequestMapping(value = "/reports/{projectName}/{fileName}", method = RequestMethod.GET)public ResponseEntity<?> fetchReport(HttpServletRequest request, @PathVariable String fileName,@PathVariable ReporticoProject projectName)throws ProfitMandiBusinessException, UnsupportedOperationException, IOException {LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);HttpResponse response;if (loginDetails.isAdmin()) {response = reporticoService.getReportFile(projectName, fileName + ".xml");} else {response = reporticoService.getReportFile(loginDetails.getFofoId(), projectName, fileName + ".xml");}HttpHeaders headers = new HttpHeaders();InputStreamResource is = new InputStreamResource(response.getEntity().getContent());headers.set("Content-Type", "application/vnd.ms-excel");headers.set("Content-disposition","inline; filename=report-" + is.getFilename() + ".csv");headers.setContentLength(is.contentLength());return new ResponseEntity<InputStreamResource>(is, headers, HttpStatus.OK);}@RequestMapping(value = "/reports/", method = RequestMethod.GET)public String reports(Model model) throws ProfitMandiBusinessException, UnsupportedOperationException, IOException {model.addAttribute("reporticoProjectMap", ReporticoProject.reporticoProjectMap);return "reports";}}