Subversion Repositories SmartDukaan

Rev

Rev 23652 | Rev 23764 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
23612 amit.gupta 1
package com.spice.profitmandi.web.controller;
2
 
3
import java.io.IOException;
4
 
5
import javax.servlet.http.HttpServletRequest;
6
 
7
import org.apache.http.Header;
8
import org.apache.http.HttpResponse;
23654 amit.gupta 9
import org.apache.logging.log4j.LogManager;
10
import org.apache.logging.log4j.Logger;
23637 amit.gupta 11
import org.springframework.beans.factory.annotation.Autowired;
23612 amit.gupta 12
import org.springframework.core.io.InputStreamResource;
13
import org.springframework.http.HttpHeaders;
14
import org.springframework.http.HttpStatus;
15
import org.springframework.http.ResponseEntity;
16
import org.springframework.stereotype.Controller;
23637 amit.gupta 17
import org.springframework.transaction.annotation.Transactional;
18
import org.springframework.ui.Model;
23612 amit.gupta 19
import org.springframework.web.bind.annotation.PathVariable;
20
import org.springframework.web.bind.annotation.RequestMapping;
21
import org.springframework.web.bind.annotation.RequestMethod;
22
 
23
import com.spice.profitmandi.common.enumuration.ReporticoProject;
24
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
25
import com.spice.profitmandi.common.services.ReporticoService;
26
import com.spice.profitmandi.web.model.LoginDetails;
27
import com.spice.profitmandi.web.util.CookiesProcessor;
28
 
29
@Controller
23637 amit.gupta 30
@Transactional(rollbackFor=Throwable.class)
23612 amit.gupta 31
public class ReportsController {
32
 
23637 amit.gupta 33
	@Autowired
23612 amit.gupta 34
	private CookiesProcessor cookiesProcessor;  
23652 amit.gupta 35
 
36
	@Autowired 
37
	private ReporticoService reporticoService;
23654 amit.gupta 38
 
39
	private static final Logger log = LogManager.getLogger(OrderController.class);
23612 amit.gupta 40
 
41
	@RequestMapping(value = "/reports/{projectName}/{fileName}", method = RequestMethod.GET)
23637 amit.gupta 42
	public ResponseEntity<?> fetchReport(HttpServletRequest request, @PathVariable String fileName, @PathVariable ReporticoProject projectName) throws ProfitMandiBusinessException, UnsupportedOperationException, IOException{
23612 amit.gupta 43
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
44
		HttpResponse response;
45
		if(loginDetails.isAdmin()) {
23652 amit.gupta 46
			response = reporticoService.getReportFile(projectName, fileName  + ".xml");
23612 amit.gupta 47
		} else {
23652 amit.gupta 48
			response = reporticoService.getReportFile(loginDetails.getFofoId(), projectName, fileName  + ".xml");
23612 amit.gupta 49
		}
50
		HttpHeaders headers = new HttpHeaders();
51
		for (Header header : response.getAllHeaders()) {
23654 amit.gupta 52
			log.info("Header name - {}, value - {}", header.getName(), header.getValue());
23612 amit.gupta 53
			headers.add(header.getName(), header.getValue());
54
		}
55
		return new ResponseEntity<InputStreamResource>(new InputStreamResource(response.getEntity().getContent()), headers, HttpStatus.OK);
56
	}
23637 amit.gupta 57
 
58
	@RequestMapping(value = "/reports/", method = RequestMethod.GET)
59
	public String reports(Model model) throws ProfitMandiBusinessException, UnsupportedOperationException, IOException{
60
		model.addAttribute("reporticoProjectMap", ReporticoProject.reporticoProjectMap);
61
		return "reports";
62
	}
23612 amit.gupta 63
}