Subversion Repositories SmartDukaan

Rev

Rev 33552 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 33552 Rev 35281
Line 21... Line 21...
21
import org.apache.commons.io.IOUtils;
21
import org.apache.commons.io.IOUtils;
22
import org.apache.http.entity.ContentType;
22
import org.apache.http.entity.ContentType;
23
import org.apache.logging.log4j.LogManager;
23
import org.apache.logging.log4j.LogManager;
24
import org.apache.logging.log4j.Logger;
24
import org.apache.logging.log4j.Logger;
25
import org.springframework.beans.factory.annotation.Autowired;
25
import org.springframework.beans.factory.annotation.Autowired;
-
 
26
import org.springframework.beans.factory.annotation.Value;
26
import org.springframework.core.io.InputStreamResource;
27
import org.springframework.core.io.InputStreamResource;
27
import org.springframework.http.HttpHeaders;
28
import org.springframework.http.HttpHeaders;
28
import org.springframework.http.HttpStatus;
29
import org.springframework.http.HttpStatus;
29
import org.springframework.http.MediaType;
30
import org.springframework.http.MediaType;
30
import org.springframework.http.ResponseEntity;
31
import org.springframework.http.ResponseEntity;
Line 68... Line 69...
68
    private CookiesProcessor cookiesProcessor;
69
    private CookiesProcessor cookiesProcessor;
69
 
70
 
70
    @Autowired
71
    @Autowired
71
    private InvoiceService invoiceService;
72
    private InvoiceService invoiceService;
72
 
73
 
-
 
74
 
-
 
75
    @Value("${prod}")
-
 
76
    private boolean isProd;
-
 
77
 
-
 
78
 
73
    @RequestMapping(value = "/purchase", method = RequestMethod.GET)
79
    @RequestMapping(value = "/purchase", method = RequestMethod.GET)
74
    public String purchase(HttpServletRequest request) throws Exception {
80
    public String purchase(HttpServletRequest request) throws Exception {
75
        return "purchase";
81
        return "purchase";
76
    }
82
    }
77
 
83
 
Line 185... Line 191...
185
 
191
 
186
                final HttpHeaders headers = new HttpHeaders();
192
                final HttpHeaders headers = new HttpHeaders();
187
 
193
 
188
                if (invoiceNumbers.size() == 1) {
194
                if (invoiceNumbers.size() == 1) {
189
                    Order order = invoiceOrdersMap.get(invoiceNumbers.get(0)).get(0);
195
                    Order order = invoiceOrdersMap.get(invoiceNumbers.get(0)).get(0);
-
 
196
                    InputStreamResource isr = null;
-
 
197
                    if (isProd) {
190
                    File invoiceFile = invoiceService.getInvoiceFile(order);
198
                        isr = new InputStreamResource(new FileInputStream(invoiceService.getInvoiceFile(order)));
-
 
199
                    } else {
-
 
200
                        ByteArrayInputStream in = new ByteArrayInputStream(invoiceService.getInvoiceStream(invoiceOrdersMap.get(order.getInvoiceNumber())).toByteArray());
-
 
201
                        isr = new InputStreamResource(in);
-
 
202
                    }
191
 
203
 
192
                    headers.setContentType(MediaType.APPLICATION_PDF);
204
                    headers.setContentType(MediaType.APPLICATION_PDF);
193
                    headers.set("Content-Type", "application/pdf");
205
                    headers.set("Content-Type", "application/pdf");
194
                    headers.set("Content-disposition", "inline; filename=" + invoiceNumber + ".pdf");
206
                    headers.set("Content-disposition", "inline; filename=" + invoiceNumber + ".pdf");
195
                    InputStreamResource is = new InputStreamResource(new FileInputStream(invoiceFile));
-
 
196
                    return new ResponseEntity<>(is, headers, HttpStatus.OK);
207
                    return new ResponseEntity<>(isr, headers, HttpStatus.OK);
197
 
208
 
198
                } else {
209
                } else {
199
 
210
 
200
                    ByteArrayOutputStream fos = new ByteArrayOutputStream();
211
                    ByteArrayOutputStream fos = new ByteArrayOutputStream();
201
                    ZipOutputStream zipOut = new ZipOutputStream(fos);
212
                    ZipOutputStream zipOut = new ZipOutputStream(fos);