| 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.HttpResponse;
|
| 23654 |
amit.gupta |
8 |
import org.apache.logging.log4j.LogManager;
|
|
|
9 |
import org.apache.logging.log4j.Logger;
|
| 23637 |
amit.gupta |
10 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 23612 |
amit.gupta |
11 |
import org.springframework.core.io.InputStreamResource;
|
|
|
12 |
import org.springframework.http.HttpHeaders;
|
|
|
13 |
import org.springframework.http.HttpStatus;
|
|
|
14 |
import org.springframework.http.ResponseEntity;
|
|
|
15 |
import org.springframework.stereotype.Controller;
|
| 23637 |
amit.gupta |
16 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
17 |
import org.springframework.ui.Model;
|
| 23612 |
amit.gupta |
18 |
import org.springframework.web.bind.annotation.PathVariable;
|
|
|
19 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
20 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
21 |
|
|
|
22 |
import com.spice.profitmandi.common.enumuration.ReporticoProject;
|
|
|
23 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
|
|
24 |
import com.spice.profitmandi.common.services.ReporticoService;
|
| 23784 |
ashik.ali |
25 |
import com.spice.profitmandi.dao.entity.dtr.Role;
|
|
|
26 |
import com.spice.profitmandi.dao.enumuration.dtr.RoleType;
|
|
|
27 |
import com.spice.profitmandi.dao.repository.dtr.RoleRepository;
|
| 23798 |
amit.gupta |
28 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| 23612 |
amit.gupta |
29 |
import com.spice.profitmandi.web.model.LoginDetails;
|
|
|
30 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
|
|
31 |
|
|
|
32 |
@Controller
|
| 23784 |
ashik.ali |
33 |
@Transactional(rollbackFor=Throwable.class)
|
| 23612 |
amit.gupta |
34 |
public class ReportsController {
|
| 23784 |
ashik.ali |
35 |
|
| 23637 |
amit.gupta |
36 |
@Autowired
|
| 23784 |
ashik.ali |
37 |
private RoleRepository roleRepository;
|
|
|
38 |
|
| 23764 |
amit.gupta |
39 |
@Autowired
|
| 23784 |
ashik.ali |
40 |
private CookiesProcessor cookiesProcessor;
|
|
|
41 |
|
|
|
42 |
@Autowired
|
| 23652 |
amit.gupta |
43 |
private ReporticoService reporticoService;
|
| 23764 |
amit.gupta |
44 |
|
| 23798 |
amit.gupta |
45 |
@Autowired
|
|
|
46 |
private RoleManager roleManager;
|
|
|
47 |
|
| 23654 |
amit.gupta |
48 |
private static final Logger log = LogManager.getLogger(OrderController.class);
|
| 23612 |
amit.gupta |
49 |
|
|
|
50 |
@RequestMapping(value = "/reports/{projectName}/{fileName}", method = RequestMethod.GET)
|
| 23764 |
amit.gupta |
51 |
public ResponseEntity<?> fetchReport(HttpServletRequest request, @PathVariable String fileName,
|
|
|
52 |
@PathVariable ReporticoProject projectName)
|
|
|
53 |
throws ProfitMandiBusinessException, UnsupportedOperationException, IOException {
|
| 23612 |
amit.gupta |
54 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
55 |
HttpResponse response;
|
| 23798 |
amit.gupta |
56 |
if (roleManager.isAdmin(loginDetails.getRoleIds())) {
|
| 23764 |
amit.gupta |
57 |
response = reporticoService.getReportFile(projectName, fileName + ".xml");
|
| 23612 |
amit.gupta |
58 |
} else {
|
| 23764 |
amit.gupta |
59 |
response = reporticoService.getReportFile(loginDetails.getFofoId(), projectName, fileName + ".xml");
|
| 23612 |
amit.gupta |
60 |
}
|
|
|
61 |
HttpHeaders headers = new HttpHeaders();
|
| 23764 |
amit.gupta |
62 |
InputStreamResource is = new InputStreamResource(response.getEntity().getContent());
|
| 23765 |
amit.gupta |
63 |
headers.set("Content-Type", "application/vnd.ms-excel");
|
|
|
64 |
headers.set("Content-disposition",
|
| 23766 |
amit.gupta |
65 |
"inline; filename=report-" + fileName + ".csv");
|
|
|
66 |
headers.setContentLength(response.getEntity().getContentLength());
|
| 23764 |
amit.gupta |
67 |
return new ResponseEntity<InputStreamResource>(is, headers, HttpStatus.OK);
|
| 23612 |
amit.gupta |
68 |
}
|
| 23637 |
amit.gupta |
69 |
|
| 23822 |
amit.gupta |
70 |
@RequestMapping(value = "/reports", method = RequestMethod.GET)
|
| 23764 |
amit.gupta |
71 |
public String reports(Model model) throws ProfitMandiBusinessException, UnsupportedOperationException, IOException {
|
| 23637 |
amit.gupta |
72 |
model.addAttribute("reporticoProjectMap", ReporticoProject.reporticoProjectMap);
|
|
|
73 |
return "reports";
|
|
|
74 |
}
|
| 23612 |
amit.gupta |
75 |
}
|