Rev 23637 | Rev 23654 | 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.IOException;import javax.servlet.http.HttpServletRequest;import org.apache.http.Header;import org.apache.http.HttpResponse;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.core.io.InputStreamResource;import org.springframework.http.HttpHeaders;import org.springframework.http.HttpStatus;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;@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();for (Header header : response.getAllHeaders()) {headers.add(header.getName(), header.getValue());}return new ResponseEntity<InputStreamResource>(new InputStreamResource(response.getEntity().getContent()), 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";}}