| 23612 |
amit.gupta |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
|
|
3 |
import java.io.IOException;
|
| 26298 |
tejbeer |
4 |
import java.util.ArrayList;
|
| 26164 |
amit.gupta |
5 |
import java.util.HashMap;
|
| 26298 |
tejbeer |
6 |
import java.util.List;
|
| 26063 |
amit.gupta |
7 |
import java.util.Map;
|
| 23612 |
amit.gupta |
8 |
|
|
|
9 |
import javax.servlet.http.HttpServletRequest;
|
|
|
10 |
|
|
|
11 |
import org.apache.http.HttpResponse;
|
| 23654 |
amit.gupta |
12 |
import org.apache.logging.log4j.LogManager;
|
|
|
13 |
import org.apache.logging.log4j.Logger;
|
| 23637 |
amit.gupta |
14 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 23612 |
amit.gupta |
15 |
import org.springframework.core.io.InputStreamResource;
|
|
|
16 |
import org.springframework.http.HttpHeaders;
|
|
|
17 |
import org.springframework.http.HttpStatus;
|
|
|
18 |
import org.springframework.http.ResponseEntity;
|
|
|
19 |
import org.springframework.stereotype.Controller;
|
| 23637 |
amit.gupta |
20 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
21 |
import org.springframework.ui.Model;
|
| 23612 |
amit.gupta |
22 |
import org.springframework.web.bind.annotation.PathVariable;
|
| 26063 |
amit.gupta |
23 |
import org.springframework.web.bind.annotation.RequestBody;
|
| 23612 |
amit.gupta |
24 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
25 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
26 |
|
|
|
27 |
import com.spice.profitmandi.common.enumuration.ReporticoProject;
|
|
|
28 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
|
|
29 |
import com.spice.profitmandi.common.services.ReporticoService;
|
| 26298 |
tejbeer |
30 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
|
|
31 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
|
|
32 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
| 23784 |
ashik.ali |
33 |
import com.spice.profitmandi.dao.repository.dtr.RoleRepository;
|
| 23798 |
amit.gupta |
34 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| 23612 |
amit.gupta |
35 |
import com.spice.profitmandi.web.model.LoginDetails;
|
|
|
36 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
|
|
37 |
|
|
|
38 |
@Controller
|
| 26298 |
tejbeer |
39 |
@Transactional(rollbackFor = Throwable.class)
|
| 23612 |
amit.gupta |
40 |
public class ReportsController {
|
| 26298 |
tejbeer |
41 |
|
| 23637 |
amit.gupta |
42 |
@Autowired
|
| 23784 |
ashik.ali |
43 |
private RoleRepository roleRepository;
|
| 26298 |
tejbeer |
44 |
|
| 23764 |
amit.gupta |
45 |
@Autowired
|
| 26298 |
tejbeer |
46 |
private CookiesProcessor cookiesProcessor;
|
|
|
47 |
|
| 23784 |
ashik.ali |
48 |
@Autowired
|
| 23652 |
amit.gupta |
49 |
private ReporticoService reporticoService;
|
| 23764 |
amit.gupta |
50 |
|
| 23798 |
amit.gupta |
51 |
@Autowired
|
|
|
52 |
private RoleManager roleManager;
|
| 26298 |
tejbeer |
53 |
|
|
|
54 |
@Autowired
|
|
|
55 |
private CsService csService;
|
|
|
56 |
|
|
|
57 |
@Autowired
|
|
|
58 |
private AuthRepository authRepository;
|
|
|
59 |
|
| 23654 |
amit.gupta |
60 |
private static final Logger log = LogManager.getLogger(OrderController.class);
|
| 23612 |
amit.gupta |
61 |
|
| 26063 |
amit.gupta |
62 |
@RequestMapping(value = "/reports/{projectName}/{fileName}")
|
| 23764 |
amit.gupta |
63 |
public ResponseEntity<?> fetchReport(HttpServletRequest request, @PathVariable String fileName,
|
| 26298 |
tejbeer |
64 |
@PathVariable ReporticoProject projectName, @RequestBody(required = false) Map<String, String> paramsMap)
|
| 23764 |
amit.gupta |
65 |
throws ProfitMandiBusinessException, UnsupportedOperationException, IOException {
|
| 23612 |
amit.gupta |
66 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
67 |
HttpResponse response;
|
| 26298 |
tejbeer |
68 |
if (roleManager.isAdmin(loginDetails.getRoleIds())) {
|
|
|
69 |
|
|
|
70 |
if (fileName.equalsIgnoreCase("LeadsReport")) {
|
|
|
71 |
if (paramsMap == null) {
|
|
|
72 |
paramsMap = new HashMap<String, String>();
|
|
|
73 |
}
|
| 26460 |
amit.gupta |
74 |
Map<Integer, List<Integer>> mapping = csService.getL2L1Mapping();
|
| 26298 |
tejbeer |
75 |
|
|
|
76 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
|
|
77 |
|
|
|
78 |
List<Integer> authIds = mapping.get(authUser.getId());
|
|
|
79 |
if (authIds == null) {
|
|
|
80 |
authIds = new ArrayList<>();
|
|
|
81 |
}
|
|
|
82 |
authIds.add(authUser.getId());
|
|
|
83 |
|
|
|
84 |
paramsMap.put("authId", authIds + "");
|
|
|
85 |
}
|
| 23612 |
amit.gupta |
86 |
} else {
|
| 26298 |
tejbeer |
87 |
if (paramsMap == null) {
|
| 26164 |
amit.gupta |
88 |
paramsMap = new HashMap<String, String>();
|
|
|
89 |
}
|
| 26298 |
tejbeer |
90 |
|
| 26158 |
amit.gupta |
91 |
paramsMap.put("MANUAL_fofoId", loginDetails.getFofoId() + "");
|
| 26298 |
tejbeer |
92 |
|
| 23612 |
amit.gupta |
93 |
}
|
| 26298 |
tejbeer |
94 |
response = getAdminReportFile(loginDetails.getEmailId(), projectName, fileName + ".xml", paramsMap);
|
| 23612 |
amit.gupta |
95 |
HttpHeaders headers = new HttpHeaders();
|
| 23764 |
amit.gupta |
96 |
InputStreamResource is = new InputStreamResource(response.getEntity().getContent());
|
| 23765 |
amit.gupta |
97 |
headers.set("Content-Type", "application/vnd.ms-excel");
|
| 26298 |
tejbeer |
98 |
headers.set("Content-disposition", "inline; filename=report-" + fileName + ".csv");
|
| 23766 |
amit.gupta |
99 |
headers.setContentLength(response.getEntity().getContentLength());
|
| 23764 |
amit.gupta |
100 |
return new ResponseEntity<InputStreamResource>(is, headers, HttpStatus.OK);
|
| 23612 |
amit.gupta |
101 |
}
|
| 23637 |
amit.gupta |
102 |
|
| 26298 |
tejbeer |
103 |
private HttpResponse getAdminReportFile(String email, ReporticoProject projectName, String fileName,
|
|
|
104 |
Map<String, String> reportParams) throws ProfitMandiBusinessException, IOException {
|
| 26063 |
amit.gupta |
105 |
return reporticoService.getReportFile(projectName, fileName, reportParams);
|
|
|
106 |
}
|
|
|
107 |
|
| 23822 |
amit.gupta |
108 |
@RequestMapping(value = "/reports", method = RequestMethod.GET)
|
| 23764 |
amit.gupta |
109 |
public String reports(Model model) throws ProfitMandiBusinessException, UnsupportedOperationException, IOException {
|
| 23637 |
amit.gupta |
110 |
model.addAttribute("reporticoProjectMap", ReporticoProject.reporticoProjectMap);
|
|
|
111 |
return "reports";
|
|
|
112 |
}
|
| 23612 |
amit.gupta |
113 |
}
|