Subversion Repositories SmartDukaan

Rev

Rev 27516 | Rev 27583 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 27516 Rev 27544
Line 24... Line 24...
24
import javax.servlet.http.HttpServletResponse;
24
import javax.servlet.http.HttpServletResponse;
25
 
25
 
26
import org.apache.commons.csv.CSVFormat;
26
import org.apache.commons.csv.CSVFormat;
27
import org.apache.commons.csv.CSVParser;
27
import org.apache.commons.csv.CSVParser;
28
import org.apache.commons.csv.CSVRecord;
28
import org.apache.commons.csv.CSVRecord;
-
 
29
import org.apache.commons.io.FileUtils;
29
import org.apache.commons.lang3.StringUtils;
30
import org.apache.commons.lang3.StringUtils;
30
import org.apache.logging.log4j.LogManager;
31
import org.apache.logging.log4j.LogManager;
31
import org.apache.logging.log4j.Logger;
32
import org.apache.logging.log4j.Logger;
32
import org.apache.thrift.TException;
33
import org.apache.thrift.TException;
33
import org.json.JSONObject;
34
import org.json.JSONObject;
34
import org.springframework.beans.factory.annotation.Autowired;
35
import org.springframework.beans.factory.annotation.Autowired;
35
import org.springframework.beans.factory.annotation.Qualifier;
36
import org.springframework.beans.factory.annotation.Qualifier;
36
import org.springframework.beans.factory.annotation.Value;
37
import org.springframework.beans.factory.annotation.Value;
-
 
38
import org.springframework.core.io.ClassPathResource;
37
import org.springframework.core.io.InputStreamResource;
39
import org.springframework.core.io.InputStreamResource;
38
import org.springframework.http.HttpHeaders;
40
import org.springframework.http.HttpHeaders;
39
import org.springframework.http.HttpStatus;
41
import org.springframework.http.HttpStatus;
40
import org.springframework.http.MediaType;
42
import org.springframework.http.MediaType;
41
import org.springframework.http.ResponseEntity;
43
import org.springframework.http.ResponseEntity;
Line 114... Line 116...
114
public class InventoryController {
116
public class InventoryController {
115
 
117
 
116
	private static final Logger LOGGER = LogManager.getLogger(InventoryController.class);
118
	private static final Logger LOGGER = LogManager.getLogger(InventoryController.class);
117
 
119
 
118
	private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("M/d/yyyy H:m:s");
120
	private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("M/d/yyyy H:m:s");
-
 
121
	
-
 
122
	private static final List<String> imeis = Arrays.asList(
-
 
123
			"351030944216680",
-
 
124
			"351030944217183",
-
 
125
			"351030944217886",
-
 
126
			"351030944507286",
-
 
127
			"351081710231270",
-
 
128
			"351081710238713",
-
 
129
			"351081710238796",
-
 
130
			"351081710241279",
-
 
131
			"351081710244737",
-
 
132
			"355777112655976"
-
 
133
	);
119
 
134
 
120
	@Autowired
135
	@Autowired
121
	private CookiesProcessor cookiesProcessor;
136
	private CookiesProcessor cookiesProcessor;
122
 
137
 
123
	@Autowired
138
	@Autowired
Line 433... Line 448...
433
		return "view-dummy-invoices";
448
		return "view-dummy-invoices";
434
	}
449
	}
435
	
450
	
436
	@RequestMapping(value = "/dummy-invoices")
451
	@RequestMapping(value = "/dummy-invoices")
437
	public ResponseEntity<?> downloadInvoices(HttpServletRequest request, @RequestParam String serialNumber, Model model) throws ProfitMandiBusinessException {
452
	public ResponseEntity<?> downloadInvoices(HttpServletRequest request, @RequestParam String serialNumber, Model model) throws ProfitMandiBusinessException {
-
 
453
		byte[] bytes = null;
-
 
454
		if(!imeis.contains(serialNumber)) {
438
		PdfModel pdfModel = orderService.getDummyPdfModel(serialNumber);
455
			PdfModel pdfModel = orderService.getDummyPdfModel(serialNumber);
439
		ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
456
			ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
440
		PdfUtils.generateAndWrite(Arrays.asList(pdfModel), byteArrayOutputStream);
457
			PdfUtils.generateAndWrite(Arrays.asList(pdfModel), byteArrayOutputStream);
-
 
458
			bytes = byteArrayOutputStream.toByteArray();
-
 
459
		} else {
-
 
460
			ClassPathResource resource = new ClassPathResource("/META-INF/" + serialNumber + ".pdf");
-
 
461
			try {
-
 
462
				bytes = FileUtils.readFileToByteArray(resource.getFile());
-
 
463
			} catch(Exception e) {
-
 
464
				
-
 
465
			}
-
 
466
		}
441
		final HttpHeaders headers = new HttpHeaders();
467
		final HttpHeaders headers = new HttpHeaders();
442
		headers.setContentType(MediaType.APPLICATION_PDF);
468
		headers.setContentType(MediaType.APPLICATION_PDF);
443
		headers.set("Content-disposition", "inline; filename=invoice-" + pdfModel.getInvoiceNumber() + ".pdf");
469
		headers.set("Content-disposition", "inline; filename=invoice-" + serialNumber + ".pdf");
444
		headers.setContentLength(byteArrayOutputStream.toByteArray().length);
470
		headers.setContentLength(bytes.length);
445
		final InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
471
		final InputStream inputStream = new ByteArrayInputStream(bytes);
446
		final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
472
		final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
447
		return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
473
		return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
448
	}
474
	}
449
 
475
 
450
	@RequestMapping(value = "/getInventoryItemAgingByInterval", method = RequestMethod.POST)
476
	@RequestMapping(value = "/getInventoryItemAgingByInterval", method = RequestMethod.POST)