| 22111 |
ashik.ali |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
|
|
3 |
import javax.servlet.http.HttpServletRequest;
|
|
|
4 |
|
| 23568 |
govind |
5 |
import org.apache.logging.log4j.Logger;
|
|
|
6 |
import org.apache.logging.log4j.LogManager;
|
| 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 |
|
| 23568 |
govind |
27 |
private static final Logger LOGGER = LogManager.getLogger(FofoController.class);
|
| 22162 |
amit.gupta |
28 |
|
|
|
29 |
@Autowired
|
| 22927 |
ashik.ali |
30 |
private Mongo mongoClient;
|
| 22162 |
amit.gupta |
31 |
|
| 22196 |
amit.gupta |
32 |
@Autowired
|
| 22927 |
ashik.ali |
33 |
private FofoDocumentsGenerator generator;
|
| 22162 |
amit.gupta |
34 |
|
| 22111 |
ashik.ali |
35 |
@RequestMapping(value = "/fofo", method = RequestMethod.GET)
|
| 22927 |
ashik.ali |
36 |
public String getAll(HttpServletRequest request, Model model) throws Throwable {
|
| 22162 |
amit.gupta |
37 |
model.addAttribute("fofoForms", mongoClient.getFofoForms(0, 50));
|
| 22111 |
ashik.ali |
38 |
return "fofo-index";
|
|
|
39 |
}
|
|
|
40 |
|
| 22196 |
amit.gupta |
41 |
@RequestMapping(value = "/fofo/{fofoId}/file-display", method = RequestMethod.GET)
|
| 22927 |
ashik.ali |
42 |
public ResponseEntity<byte[]> displayDocs(HttpServletRequest request, @PathVariable(name = "fofoId") int fofoId) throws Throwable{
|
| 22196 |
amit.gupta |
43 |
HttpHeaders headers = new HttpHeaders();
|
|
|
44 |
headers.setContentType(MediaType.parseMediaType("application/pdf"));
|
|
|
45 |
String filename = "output.pdf";
|
|
|
46 |
headers.setContentDispositionFormData(filename, filename);
|
|
|
47 |
headers.setCacheControl("must-revalidate, post-check=0, pre-check=0");
|
|
|
48 |
byte[] contents = generator.getDocumentStream(fofoId);
|
|
|
49 |
ResponseEntity<byte[]> response = new ResponseEntity<byte[]>(contents, headers, HttpStatus.OK);
|
|
|
50 |
return response;
|
|
|
51 |
}
|
|
|
52 |
|
| 22111 |
ashik.ali |
53 |
@RequestMapping(value = "/fofo/{fofoId}/edit", method = RequestMethod.GET)
|
|
|
54 |
public String editFofoForm(HttpServletRequest request, @PathVariable(name = "fofoId") int fofoId, Model model) throws Exception{
|
| 22193 |
amit.gupta |
55 |
FofoForm ff = mongoClient.getFofoForm(fofoId);
|
|
|
56 |
model.addAttribute("fofoForm", mongoClient.getFofoFormJsonStringByFofoId(fofoId));
|
|
|
57 |
model.addAttribute("email", ff.getRegisteredEmail1());
|
| 22191 |
amit.gupta |
58 |
return "fofo-form";
|
| 22111 |
ashik.ali |
59 |
}
|
| 23366 |
ashik.ali |
60 |
|
| 22111 |
ashik.ali |
61 |
}
|