| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.web.controller;
|
1 |
package com.spice.profitmandi.web.controller;
|
| 2 |
|
2 |
|
| 3 |
import java.io.IOException;
|
3 |
import java.io.IOException;
|
| - |
|
4 |
import java.util.ArrayList;
|
| 4 |
import java.util.HashMap;
|
5 |
import java.util.HashMap;
|
| - |
|
6 |
import java.util.List;
|
| 5 |
import java.util.Map;
|
7 |
import java.util.Map;
|
| 6 |
|
8 |
|
| 7 |
import javax.servlet.http.HttpServletRequest;
|
9 |
import javax.servlet.http.HttpServletRequest;
|
| 8 |
|
10 |
|
| 9 |
import org.apache.http.HttpResponse;
|
11 |
import org.apache.http.HttpResponse;
|
| Line 23... |
Line 25... |
| 23 |
import org.springframework.web.bind.annotation.RequestMethod;
|
25 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 24 |
|
26 |
|
| 25 |
import com.spice.profitmandi.common.enumuration.ReporticoProject;
|
27 |
import com.spice.profitmandi.common.enumuration.ReporticoProject;
|
| 26 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
28 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 27 |
import com.spice.profitmandi.common.services.ReporticoService;
|
29 |
import com.spice.profitmandi.common.services.ReporticoService;
|
| - |
|
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;
|
| 28 |
import com.spice.profitmandi.dao.repository.dtr.RoleRepository;
|
33 |
import com.spice.profitmandi.dao.repository.dtr.RoleRepository;
|
| 29 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
34 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| 30 |
import com.spice.profitmandi.web.model.LoginDetails;
|
35 |
import com.spice.profitmandi.web.model.LoginDetails;
|
| 31 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
36 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| 32 |
|
37 |
|
| 33 |
@Controller
|
38 |
@Controller
|
| 34 |
@Transactional(rollbackFor=Throwable.class)
|
39 |
@Transactional(rollbackFor = Throwable.class)
|
| 35 |
public class ReportsController {
|
40 |
public class ReportsController {
|
| 36 |
|
41 |
|
| 37 |
@Autowired
|
42 |
@Autowired
|
| 38 |
private RoleRepository roleRepository;
|
43 |
private RoleRepository roleRepository;
|
| 39 |
|
44 |
|
| 40 |
@Autowired
|
45 |
@Autowired
|
| 41 |
private CookiesProcessor cookiesProcessor;
|
46 |
private CookiesProcessor cookiesProcessor;
|
| 42 |
|
47 |
|
| 43 |
@Autowired
|
48 |
@Autowired
|
| 44 |
private ReporticoService reporticoService;
|
49 |
private ReporticoService reporticoService;
|
| 45 |
|
50 |
|
| 46 |
@Autowired
|
51 |
@Autowired
|
| 47 |
private RoleManager roleManager;
|
52 |
private RoleManager roleManager;
|
| - |
|
53 |
|
| - |
|
54 |
@Autowired
|
| - |
|
55 |
private CsService csService;
|
| 48 |
|
56 |
|
| - |
|
57 |
@Autowired
|
| - |
|
58 |
private AuthRepository authRepository;
|
| - |
|
59 |
|
| 49 |
private static final Logger log = LogManager.getLogger(OrderController.class);
|
60 |
private static final Logger log = LogManager.getLogger(OrderController.class);
|
| 50 |
|
61 |
|
| 51 |
@RequestMapping(value = "/reports/{projectName}/{fileName}")
|
62 |
@RequestMapping(value = "/reports/{projectName}/{fileName}")
|
| 52 |
public ResponseEntity<?> fetchReport(HttpServletRequest request, @PathVariable String fileName,
|
63 |
public ResponseEntity<?> fetchReport(HttpServletRequest request, @PathVariable String fileName,
|
| 53 |
@PathVariable ReporticoProject projectName, @RequestBody(required=false) Map<String, String> paramsMap)
|
64 |
@PathVariable ReporticoProject projectName, @RequestBody(required = false) Map<String, String> paramsMap)
|
| 54 |
throws ProfitMandiBusinessException, UnsupportedOperationException, IOException {
|
65 |
throws ProfitMandiBusinessException, UnsupportedOperationException, IOException {
|
| 55 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
66 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 56 |
HttpResponse response;
|
67 |
HttpResponse response;
|
| 57 |
if (roleManager.isAdmin(loginDetails.getRoleIds())) {
|
68 |
if (roleManager.isAdmin(loginDetails.getRoleIds())) {
|
| - |
|
69 |
|
| - |
|
70 |
if (fileName.equalsIgnoreCase("LeadsReport")) {
|
| - |
|
71 |
if (paramsMap == null) {
|
| - |
|
72 |
paramsMap = new HashMap<String, String>();
|
| - |
|
73 |
}
|
| - |
|
74 |
Map<Integer, List<Integer>> mapping = csService.getL1L2Mapping();
|
| - |
|
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 |
}
|
| 58 |
} else {
|
86 |
} else {
|
| 59 |
if(paramsMap==null) {
|
87 |
if (paramsMap == null) {
|
| 60 |
paramsMap = new HashMap<String, String>();
|
88 |
paramsMap = new HashMap<String, String>();
|
| 61 |
}
|
89 |
}
|
| - |
|
90 |
|
| 62 |
paramsMap.put("MANUAL_fofoId", loginDetails.getFofoId() + "");
|
91 |
paramsMap.put("MANUAL_fofoId", loginDetails.getFofoId() + "");
|
| - |
|
92 |
|
| 63 |
}
|
93 |
}
|
| 64 |
response = getAdminReportFile(loginDetails.getEmailId(), projectName, fileName + ".xml", paramsMap);
|
94 |
response = getAdminReportFile(loginDetails.getEmailId(), projectName, fileName + ".xml", paramsMap);
|
| 65 |
HttpHeaders headers = new HttpHeaders();
|
95 |
HttpHeaders headers = new HttpHeaders();
|
| 66 |
InputStreamResource is = new InputStreamResource(response.getEntity().getContent());
|
96 |
InputStreamResource is = new InputStreamResource(response.getEntity().getContent());
|
| 67 |
headers.set("Content-Type", "application/vnd.ms-excel");
|
97 |
headers.set("Content-Type", "application/vnd.ms-excel");
|
| 68 |
headers.set("Content-disposition",
|
- |
|
| 69 |
"inline; filename=report-" + fileName + ".csv");
|
98 |
headers.set("Content-disposition", "inline; filename=report-" + fileName + ".csv");
|
| 70 |
headers.setContentLength(response.getEntity().getContentLength());
|
99 |
headers.setContentLength(response.getEntity().getContentLength());
|
| 71 |
return new ResponseEntity<InputStreamResource>(is, headers, HttpStatus.OK);
|
100 |
return new ResponseEntity<InputStreamResource>(is, headers, HttpStatus.OK);
|
| 72 |
}
|
101 |
}
|
| 73 |
|
102 |
|
| 74 |
private HttpResponse getAdminReportFile(String email, ReporticoProject projectName, String fileName, Map<String, String> reportParams) throws ProfitMandiBusinessException, IOException{
|
103 |
private HttpResponse getAdminReportFile(String email, ReporticoProject projectName, String fileName,
|
| - |
|
104 |
Map<String, String> reportParams) throws ProfitMandiBusinessException, IOException {
|
| 75 |
return reporticoService.getReportFile(projectName, fileName, reportParams);
|
105 |
return reporticoService.getReportFile(projectName, fileName, reportParams);
|
| 76 |
}
|
106 |
}
|
| 77 |
|
107 |
|
| 78 |
@RequestMapping(value = "/reports", method = RequestMethod.GET)
|
108 |
@RequestMapping(value = "/reports", method = RequestMethod.GET)
|
| 79 |
public String reports(Model model) throws ProfitMandiBusinessException, UnsupportedOperationException, IOException {
|
109 |
public String reports(Model model) throws ProfitMandiBusinessException, UnsupportedOperationException, IOException {
|