| Line 8... |
Line 8... |
| 8 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
8 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| 9 |
import com.spice.profitmandi.service.inventory.PurchaseService;
|
9 |
import com.spice.profitmandi.service.inventory.PurchaseService;
|
| 10 |
import com.spice.profitmandi.service.transaction.invoicing.InvoiceService;
|
10 |
import com.spice.profitmandi.service.transaction.invoicing.InvoiceService;
|
| 11 |
import com.spice.profitmandi.web.model.LoginDetails;
|
11 |
import com.spice.profitmandi.web.model.LoginDetails;
|
| 12 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
12 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| - |
|
13 |
import org.apache.commons.io.IOUtils;
|
| 13 |
import org.apache.http.HttpResponse;
|
14 |
import org.apache.http.HttpResponse;
|
| - |
|
15 |
import org.apache.http.entity.ContentType;
|
| 14 |
import org.apache.logging.log4j.LogManager;
|
16 |
import org.apache.logging.log4j.LogManager;
|
| 15 |
import org.apache.logging.log4j.Logger;
|
17 |
import org.apache.logging.log4j.Logger;
|
| 16 |
import org.springframework.beans.factory.annotation.Autowired;
|
18 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 17 |
import org.springframework.core.io.ByteArrayResource;
|
- |
|
| 18 |
import org.springframework.core.io.InputStreamResource;
|
19 |
import org.springframework.core.io.InputStreamResource;
|
| 19 |
import org.springframework.http.HttpHeaders;
|
20 |
import org.springframework.http.HttpHeaders;
|
| 20 |
import org.springframework.http.HttpStatus;
|
21 |
import org.springframework.http.HttpStatus;
|
| 21 |
import org.springframework.http.MediaType;
|
22 |
import org.springframework.http.MediaType;
|
| 22 |
import org.springframework.http.ResponseEntity;
|
23 |
import org.springframework.http.ResponseEntity;
|
| Line 27... |
Line 28... |
| 27 |
import org.springframework.web.bind.annotation.RequestMapping;
|
28 |
import org.springframework.web.bind.annotation.RequestMapping;
|
| 28 |
import org.springframework.web.bind.annotation.RequestMethod;
|
29 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 29 |
import org.springframework.web.bind.annotation.RequestParam;
|
30 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 30 |
|
31 |
|
| 31 |
import javax.servlet.http.HttpServletRequest;
|
32 |
import javax.servlet.http.HttpServletRequest;
|
| - |
|
33 |
import java.io.ByteArrayInputStream;
|
| 32 |
import java.io.ByteArrayOutputStream;
|
34 |
import java.io.ByteArrayOutputStream;
|
| 33 |
import java.io.File;
|
35 |
import java.io.File;
|
| - |
|
36 |
import java.io.InputStream;
|
| 34 |
import java.time.LocalDateTime;
|
37 |
import java.time.LocalDateTime;
|
| 35 |
import java.util.*;
|
38 |
import java.util.*;
|
| 36 |
import java.util.stream.Collectors;
|
39 |
import java.util.stream.Collectors;
|
| 37 |
import java.util.zip.ZipEntry;
|
40 |
import java.util.zip.ZipEntry;
|
| 38 |
import java.util.zip.ZipOutputStream;
|
41 |
import java.util.zip.ZipOutputStream;
|
| Line 135... |
Line 138... |
| 135 |
List<Order> orders = invoiceOrdersMap.get(invoice);
|
138 |
List<Order> orders = invoiceOrdersMap.get(invoice);
|
| 136 |
String invoicePath = this.getInvoicePath(orders.get(0));
|
139 |
String invoicePath = this.getInvoicePath(orders.get(0));
|
| 137 |
HttpResponse response = restClient.getResponse("http://50.116.3.101/" + invoicePath, null, headersMap);
|
140 |
HttpResponse response = restClient.getResponse("http://50.116.3.101/" + invoicePath, null, headersMap);
|
| 138 |
ZipEntry zipEntry = new ZipEntry(invoice + ".pdf");
|
141 |
ZipEntry zipEntry = new ZipEntry(invoice + ".pdf");
|
| 139 |
zipOut.putNextEntry(zipEntry);
|
142 |
zipOut.putNextEntry(zipEntry);
|
| 140 |
int contentLength = (int) response.getEntity().getContentLength();
|
143 |
IOUtils.copy(response.getEntity().getContent(), zipOut);
|
| 141 |
byte[] bytes = new byte[contentLength];
|
- |
|
| 142 |
response.getEntity().getContent().read(bytes);
|
144 |
response.getEntity().getContent().close();
|
| 143 |
zipOut.write(bytes);
|
- |
|
| 144 |
zipOut.closeEntry();
|
145 |
zipOut.closeEntry();
|
| 145 |
}
|
146 |
}
|
| 146 |
byte[] byteArray = fos.toByteArray();
|
147 |
byte[] byteArray = fos.toByteArray();
|
| 147 |
headers.set("Content-Type", "application/octet-stream");
|
148 |
headers.set("Content-Type", ContentType.APPLICATION_OCTET_STREAM.getMimeType());
|
| 148 |
headers.set("Content-disposition", "attachment; filename=invoices.zip");
|
149 |
headers.set("Content-disposition", "attachment; filename=invoices.zip");
|
| 149 |
headers.setContentLength(byteArray.length);
|
150 |
headers.setContentLength(byteArray.length);
|
| 150 |
zipOut.close();
|
151 |
zipOut.close();
|
| 151 |
fos.close();
|
152 |
final InputStream inputStream = new ByteArrayInputStream(fos.toByteArray());
|
| 152 |
return new ResponseEntity<>(new ByteArrayResource(byteArray), headers, HttpStatus.OK);
|
153 |
return new ResponseEntity<>(new InputStreamResource(inputStream), headers, HttpStatus.OK);
|
| 153 |
}
|
154 |
}
|
| 154 |
}
|
155 |
}
|
| 155 |
|
156 |
|
| 156 |
}
|
157 |
}
|
| 157 |
} else {
|
158 |
} else {
|