| 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.Header;
|
|
|
8 |
import org.apache.http.HttpResponse;
|
|
|
9 |
import org.springframework.core.io.InputStreamResource;
|
|
|
10 |
import org.springframework.http.HttpHeaders;
|
|
|
11 |
import org.springframework.http.HttpStatus;
|
|
|
12 |
import org.springframework.http.ResponseEntity;
|
|
|
13 |
import org.springframework.stereotype.Controller;
|
|
|
14 |
import org.springframework.web.bind.annotation.PathVariable;
|
|
|
15 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
16 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
17 |
|
|
|
18 |
import com.spice.profitmandi.common.enumuration.ReporticoProject;
|
|
|
19 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
|
|
20 |
import com.spice.profitmandi.common.services.ReporticoService;
|
|
|
21 |
import com.spice.profitmandi.web.model.LoginDetails;
|
|
|
22 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
|
|
23 |
|
|
|
24 |
@Controller
|
|
|
25 |
public class ReportsController {
|
|
|
26 |
|
|
|
27 |
private CookiesProcessor cookiesProcessor;
|
|
|
28 |
|
|
|
29 |
@RequestMapping(value = "/reports/{projectName}/{fileName}", method = RequestMethod.GET)
|
|
|
30 |
public ResponseEntity<?> updateTest(HttpServletRequest request, @PathVariable String fileName, @PathVariable ReporticoProject reporticoProject) throws ProfitMandiBusinessException, UnsupportedOperationException, IOException{
|
|
|
31 |
ReporticoService rs = new ReporticoService();
|
|
|
32 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
33 |
HttpResponse response;
|
|
|
34 |
if(loginDetails.isAdmin()) {
|
|
|
35 |
response = rs.getReportFile(reporticoProject, fileName + ".xml");
|
|
|
36 |
} else {
|
|
|
37 |
response = rs.getReportFile(loginDetails.getFofoId(), reporticoProject, fileName + ".xml");
|
|
|
38 |
}
|
|
|
39 |
HttpHeaders headers = new HttpHeaders();
|
|
|
40 |
for (Header header : response.getAllHeaders()) {
|
|
|
41 |
headers.add(header.getName(), header.getValue());
|
|
|
42 |
}
|
|
|
43 |
return new ResponseEntity<InputStreamResource>(new InputStreamResource(response.getEntity().getContent()), headers, HttpStatus.OK);
|
|
|
44 |
}
|
|
|
45 |
}
|