| 22111 |
ashik.ali |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
|
|
3 |
import javax.servlet.http.HttpServletRequest;
|
|
|
4 |
|
|
|
5 |
import org.slf4j.Logger;
|
|
|
6 |
import org.slf4j.LoggerFactory;
|
| 22162 |
amit.gupta |
7 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 22196 |
amit.gupta |
8 |
import org.springframework.http.HttpHeaders;
|
|
|
9 |
import org.springframework.http.HttpStatus;
|
|
|
10 |
import org.springframework.http.MediaType;
|
|
|
11 |
import org.springframework.http.ResponseEntity;
|
| 22111 |
ashik.ali |
12 |
import org.springframework.stereotype.Controller;
|
|
|
13 |
import org.springframework.ui.Model;
|
|
|
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 |
|
| 22193 |
amit.gupta |
18 |
import com.spice.profitmandi.dao.model.FofoForm;
|
| 22111 |
ashik.ali |
19 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
|
|
20 |
|
| 22196 |
amit.gupta |
21 |
import in.shop2020.dtrapi.utils.FofoDocumentsGenerator;
|
|
|
22 |
|
| 22111 |
ashik.ali |
23 |
@Controller
|
|
|
24 |
public class FofoController {
|
|
|
25 |
|
|
|
26 |
private static final Logger LOGGER = LoggerFactory.getLogger(FofoController.class);
|
|
|
27 |
|
| 22162 |
amit.gupta |
28 |
|
|
|
29 |
@Autowired
|
|
|
30 |
Mongo mongoClient;
|
|
|
31 |
|
| 22196 |
amit.gupta |
32 |
@Autowired
|
|
|
33 |
FofoDocumentsGenerator generator;
|
| 22162 |
amit.gupta |
34 |
|
| 22196 |
amit.gupta |
35 |
|
| 22111 |
ashik.ali |
36 |
@RequestMapping(value = "/fofo", method = RequestMethod.GET)
|
|
|
37 |
public String getAll(HttpServletRequest request, Model model) throws Exception{
|
| 22162 |
amit.gupta |
38 |
model.addAttribute("fofoForms", mongoClient.getFofoForms(0, 50));
|
| 22111 |
ashik.ali |
39 |
return "fofo-index";
|
|
|
40 |
}
|
|
|
41 |
|
| 22196 |
amit.gupta |
42 |
@RequestMapping(value = "/fofo/{fofoId}/file-display", method = RequestMethod.GET)
|
|
|
43 |
public ResponseEntity<byte[]> displayDocs(HttpServletRequest request, @PathVariable(name = "fofoId") int fofoId) throws Exception{
|
|
|
44 |
HttpHeaders headers = new HttpHeaders();
|
|
|
45 |
headers.setContentType(MediaType.parseMediaType("application/pdf"));
|
|
|
46 |
String filename = "output.pdf";
|
|
|
47 |
headers.setContentDispositionFormData(filename, filename);
|
|
|
48 |
headers.setCacheControl("must-revalidate, post-check=0, pre-check=0");
|
|
|
49 |
byte[] contents = generator.getDocumentStream(fofoId);
|
|
|
50 |
ResponseEntity<byte[]> response = new ResponseEntity<byte[]>(contents, headers, HttpStatus.OK);
|
|
|
51 |
return response;
|
|
|
52 |
}
|
|
|
53 |
|
| 22111 |
ashik.ali |
54 |
@RequestMapping(value = "/fofo/{fofoId}/edit", method = RequestMethod.GET)
|
|
|
55 |
public String editFofoForm(HttpServletRequest request, @PathVariable(name = "fofoId") int fofoId, Model model) throws Exception{
|
| 22193 |
amit.gupta |
56 |
FofoForm ff = mongoClient.getFofoForm(fofoId);
|
|
|
57 |
model.addAttribute("fofoForm", mongoClient.getFofoFormJsonStringByFofoId(fofoId));
|
|
|
58 |
model.addAttribute("email", ff.getRegisteredEmail1());
|
| 22191 |
amit.gupta |
59 |
return "fofo-form";
|
| 22111 |
ashik.ali |
60 |
}
|
|
|
61 |
}
|