Subversion Repositories SmartDukaan

Rev

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