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