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