| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.web.controller;
|
1 |
package com.spice.profitmandi.web.controller;
|
| 2 |
|
2 |
|
| 3 |
import java.io.ByteArrayInputStream;
|
- |
|
| 4 |
import java.io.IOException;
|
3 |
import java.io.IOException;
|
| 5 |
import java.io.InputStream;
|
- |
|
| 6 |
|
4 |
|
| 7 |
import javax.servlet.http.HttpServletRequest;
|
5 |
import javax.servlet.http.HttpServletRequest;
|
| 8 |
|
6 |
|
| 9 |
import org.apache.http.Header;
|
- |
|
| 10 |
import org.apache.http.HttpResponse;
|
7 |
import org.apache.http.HttpResponse;
|
| 11 |
import org.apache.logging.log4j.LogManager;
|
8 |
import org.apache.logging.log4j.LogManager;
|
| 12 |
import org.apache.logging.log4j.Logger;
|
9 |
import org.apache.logging.log4j.Logger;
|
| 13 |
import org.springframework.beans.factory.annotation.Autowired;
|
10 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 14 |
import org.springframework.core.io.InputStreamResource;
|
11 |
import org.springframework.core.io.InputStreamResource;
|
| 15 |
import org.springframework.core.io.InputStreamSource;
|
- |
|
| 16 |
import org.springframework.http.HttpHeaders;
|
12 |
import org.springframework.http.HttpHeaders;
|
| 17 |
import org.springframework.http.HttpStatus;
|
13 |
import org.springframework.http.HttpStatus;
|
| 18 |
import org.springframework.http.MediaType;
|
- |
|
| 19 |
import org.springframework.http.ResponseEntity;
|
14 |
import org.springframework.http.ResponseEntity;
|
| 20 |
import org.springframework.stereotype.Controller;
|
15 |
import org.springframework.stereotype.Controller;
|
| 21 |
import org.springframework.transaction.annotation.Transactional;
|
16 |
import org.springframework.transaction.annotation.Transactional;
|
| 22 |
import org.springframework.ui.Model;
|
17 |
import org.springframework.ui.Model;
|
| 23 |
import org.springframework.web.bind.annotation.PathVariable;
|
18 |
import org.springframework.web.bind.annotation.PathVariable;
|
| Line 25... |
Line 20... |
| 25 |
import org.springframework.web.bind.annotation.RequestMethod;
|
20 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 26 |
|
21 |
|
| 27 |
import com.spice.profitmandi.common.enumuration.ReporticoProject;
|
22 |
import com.spice.profitmandi.common.enumuration.ReporticoProject;
|
| 28 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
23 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 29 |
import com.spice.profitmandi.common.services.ReporticoService;
|
24 |
import com.spice.profitmandi.common.services.ReporticoService;
|
| - |
|
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;
|
| 30 |
import com.spice.profitmandi.web.model.LoginDetails;
|
28 |
import com.spice.profitmandi.web.model.LoginDetails;
|
| 31 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
29 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| 32 |
|
30 |
|
| 33 |
@Controller
|
31 |
@Controller
|
| 34 |
@Transactional(rollbackFor = Throwable.class)
|
32 |
@Transactional(rollbackFor=Throwable.class)
|
| 35 |
public class ReportsController {
|
33 |
public class ReportsController {
|
| 36 |
|
34 |
|
| 37 |
@Autowired
|
35 |
@Autowired
|
| - |
|
36 |
private RoleRepository roleRepository;
|
| - |
|
37 |
|
| - |
|
38 |
@Autowired
|
| 38 |
private CookiesProcessor cookiesProcessor;
|
39 |
private CookiesProcessor cookiesProcessor;
|
| 39 |
|
40 |
|
| 40 |
@Autowired
|
41 |
@Autowired
|
| 41 |
private ReporticoService reporticoService;
|
42 |
private ReporticoService reporticoService;
|
| 42 |
|
43 |
|
| 43 |
private static final Logger log = LogManager.getLogger(OrderController.class);
|
44 |
private static final Logger log = LogManager.getLogger(OrderController.class);
|
| 44 |
|
45 |
|
| Line 46... |
Line 47... |
| 46 |
public ResponseEntity<?> fetchReport(HttpServletRequest request, @PathVariable String fileName,
|
47 |
public ResponseEntity<?> fetchReport(HttpServletRequest request, @PathVariable String fileName,
|
| 47 |
@PathVariable ReporticoProject projectName)
|
48 |
@PathVariable ReporticoProject projectName)
|
| 48 |
throws ProfitMandiBusinessException, UnsupportedOperationException, IOException {
|
49 |
throws ProfitMandiBusinessException, UnsupportedOperationException, IOException {
|
| 49 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
50 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 50 |
HttpResponse response;
|
51 |
HttpResponse response;
|
| - |
|
52 |
Role role = roleRepository.selectByName(RoleType.FOFO_ADMIN.toString());
|
| 51 |
if (loginDetails.isAdmin()) {
|
53 |
if (loginDetails.getRoleIds().contains(role.getId())) {
|
| 52 |
response = reporticoService.getReportFile(projectName, fileName + ".xml");
|
54 |
response = reporticoService.getReportFile(projectName, fileName + ".xml");
|
| 53 |
} else {
|
55 |
} else {
|
| 54 |
response = reporticoService.getReportFile(loginDetails.getFofoId(), projectName, fileName + ".xml");
|
56 |
response = reporticoService.getReportFile(loginDetails.getFofoId(), projectName, fileName + ".xml");
|
| 55 |
}
|
57 |
}
|
| 56 |
HttpHeaders headers = new HttpHeaders();
|
58 |
HttpHeaders headers = new HttpHeaders();
|