| 23612 |
amit.gupta |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
|
|
3 |
import java.io.IOException;
|
| 26063 |
amit.gupta |
4 |
import java.util.Map;
|
| 23612 |
amit.gupta |
5 |
|
|
|
6 |
import javax.servlet.http.HttpServletRequest;
|
|
|
7 |
|
|
|
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;
|
| 26063 |
amit.gupta |
20 |
import org.springframework.web.bind.annotation.RequestBody;
|
| 23612 |
amit.gupta |
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;
|
| 23784 |
ashik.ali |
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 |
|
| 26063 |
amit.gupta |
50 |
@RequestMapping(value = "/reports/{projectName}/{fileName}")
|
| 23764 |
amit.gupta |
51 |
public ResponseEntity<?> fetchReport(HttpServletRequest request, @PathVariable String fileName,
|
| 26063 |
amit.gupta |
52 |
@PathVariable ReporticoProject projectName, @RequestBody(required=false) Map<String, String> paramsMap)
|
| 23764 |
amit.gupta |
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())) {
|
| 26063 |
amit.gupta |
57 |
response = getAdminReportFile(loginDetails.getEmailId(), projectName, fileName + ".xml", paramsMap);
|
| 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 |
|
| 26063 |
amit.gupta |
70 |
private HttpResponse getAdminReportFile(String email, ReporticoProject projectName, String fileName, Map<String, String> reportParams) throws ProfitMandiBusinessException, IOException{
|
|
|
71 |
return reporticoService.getReportFile(projectName, fileName, reportParams);
|
|
|
72 |
}
|
|
|
73 |
|
| 23822 |
amit.gupta |
74 |
@RequestMapping(value = "/reports", method = RequestMethod.GET)
|
| 23764 |
amit.gupta |
75 |
public String reports(Model model) throws ProfitMandiBusinessException, UnsupportedOperationException, IOException {
|
| 23637 |
amit.gupta |
76 |
model.addAttribute("reporticoProjectMap", ReporticoProject.reporticoProjectMap);
|
|
|
77 |
return "reports";
|
|
|
78 |
}
|
| 23612 |
amit.gupta |
79 |
}
|