| Line 9... |
Line 9... |
| 9 |
import java.text.DecimalFormat;
|
9 |
import java.text.DecimalFormat;
|
| 10 |
import java.util.Date;
|
10 |
import java.util.Date;
|
| 11 |
import java.util.List;
|
11 |
import java.util.List;
|
| 12 |
|
12 |
|
| 13 |
import org.apache.thrift.TException;
|
13 |
import org.apache.thrift.TException;
|
| - |
|
14 |
import org.slf4j.Logger;
|
| - |
|
15 |
import org.slf4j.LoggerFactory;
|
| 14 |
|
16 |
|
| 15 |
import com.itextpdf.text.Document;
|
17 |
import com.itextpdf.text.Document;
|
| 16 |
import com.itextpdf.text.DocumentException;
|
18 |
import com.itextpdf.text.DocumentException;
|
| 17 |
import com.itextpdf.text.Element;
|
19 |
import com.itextpdf.text.Element;
|
| 18 |
import com.itextpdf.text.Font;
|
20 |
import com.itextpdf.text.Font;
|
| Line 37... |
Line 39... |
| 37 |
import in.shop2020.thrift.clients.CatalogServiceClient;
|
39 |
import in.shop2020.thrift.clients.CatalogServiceClient;
|
| 38 |
import in.shop2020.thrift.clients.LogisticsServiceClient;
|
40 |
import in.shop2020.thrift.clients.LogisticsServiceClient;
|
| 39 |
import in.shop2020.thrift.clients.TransactionServiceClient;
|
41 |
import in.shop2020.thrift.clients.TransactionServiceClient;
|
| 40 |
|
42 |
|
| 41 |
public class ManifestGenerator {
|
43 |
public class ManifestGenerator {
|
| - |
|
44 |
|
| - |
|
45 |
private static Logger logger = LoggerFactory.getLogger(ManifestGenerator.class);
|
| - |
|
46 |
|
| 42 |
private TransactionServiceClient tsc = null;
|
47 |
private TransactionServiceClient tsc = null;
|
| 43 |
private CatalogServiceClient csc = null;
|
48 |
private CatalogServiceClient csc = null;
|
| 44 |
private LogisticsServiceClient lsc = null;
|
49 |
private LogisticsServiceClient lsc = null;
|
| 45 |
private DecimalFormat weightFormat = new DecimalFormat("0.000");
|
50 |
private DecimalFormat weightFormat = new DecimalFormat("0.000");
|
| 46 |
public ManifestGenerator() {
|
51 |
public ManifestGenerator() {
|
| 47 |
try {
|
52 |
try {
|
| 48 |
tsc = new TransactionServiceClient();
|
53 |
tsc = new TransactionServiceClient();
|
| 49 |
csc = new CatalogServiceClient();
|
54 |
csc = new CatalogServiceClient();
|
| 50 |
lsc = new LogisticsServiceClient();
|
55 |
lsc = new LogisticsServiceClient();
|
| 51 |
} catch (Exception e) {
|
56 |
} catch (Exception e) {
|
| 52 |
e.printStackTrace();
|
57 |
logger.error("Error while initializing one of the thrift clients", e);
|
| 53 |
}
|
58 |
}
|
| 54 |
}
|
59 |
}
|
| 55 |
|
60 |
|
| 56 |
public ByteArrayOutputStream generateManifestFile(long warehouseId, long providerId) {
|
61 |
public ByteArrayOutputStream generateManifestFile(long warehouseId, long providerId, boolean isCod) {
|
| 57 |
ByteArrayOutputStream baosPDF = null;
|
62 |
ByteArrayOutputStream baosPDF = null;
|
| 58 |
in.shop2020.model.v1.order.TransactionService.Client txnClient = tsc.getClient();
|
63 |
in.shop2020.model.v1.order.TransactionService.Client txnClient = tsc.getClient();
|
| 59 |
in.shop2020.model.v1.catalog.InventoryService.Client inventoryClient = csc.getClient();
|
64 |
in.shop2020.model.v1.catalog.InventoryService.Client inventoryClient = csc.getClient();
|
| 60 |
in.shop2020.logistics.LogisticsService.Client logisticsClient = lsc.getClient();
|
65 |
in.shop2020.logistics.LogisticsService.Client logisticsClient = lsc.getClient();
|
| 61 |
|
66 |
|
| Line 64... |
Line 69... |
| 64 |
Provider provider = null;
|
69 |
Provider provider = null;
|
| 65 |
try {
|
70 |
try {
|
| 66 |
orders = txnClient.getAllOrders(OrderStatus.BILLED, 0L, new Date().getTime(), warehouseId);
|
71 |
orders = txnClient.getAllOrders(OrderStatus.BILLED, 0L, new Date().getTime(), warehouseId);
|
| 67 |
warehouse = inventoryClient.getWarehouse(warehouseId);
|
72 |
warehouse = inventoryClient.getWarehouse(warehouseId);
|
| 68 |
provider = logisticsClient.getProvider(providerId);
|
73 |
provider = logisticsClient.getProvider(providerId);
|
| 69 |
} catch (TException e1) {
|
74 |
} catch (TException e) {
|
| 70 |
e1.printStackTrace();
|
75 |
logger.error("Error getting information from one of the Thrift Services: ", e);
|
| 71 |
return baosPDF;
|
76 |
return baosPDF;
|
| 72 |
} catch (InventoryServiceException e) {
|
77 |
} catch (InventoryServiceException e) {
|
| 73 |
e.printStackTrace();
|
78 |
logger.error("Error getting warehouse info from the catalog service: ", e);
|
| 74 |
return baosPDF;
|
79 |
return baosPDF;
|
| 75 |
} catch (LogisticsServiceException e) {
|
80 |
} catch (LogisticsServiceException e) {
|
| 76 |
e.printStackTrace();
|
81 |
logger.error("Error getting provider info from the logistics service: ", e);
|
| 77 |
return baosPDF;
|
82 |
return baosPDF;
|
| 78 |
} catch (TransactionServiceException e) {
|
83 |
} catch (TransactionServiceException e) {
|
| 79 |
e.printStackTrace();
|
84 |
logger.error("Error getting orders from the transaction service: ", e);
|
| 80 |
return baosPDF;
|
85 |
return baosPDF;
|
| 81 |
}
|
86 |
}
|
| 82 |
|
87 |
|
| 83 |
try {
|
88 |
try {
|
| 84 |
baosPDF = new ByteArrayOutputStream();
|
89 |
baosPDF = new ByteArrayOutputStream();
|
| Line 116... |
Line 121... |
| 116 |
int serialNo = 0;
|
121 |
int serialNo = 0;
|
| 117 |
for(int i=0; i < orders.size();i++){
|
122 |
for(int i=0; i < orders.size();i++){
|
| 118 |
Order order = orders.get(i);
|
123 |
Order order = orders.get(i);
|
| 119 |
if(order.getLogistics_provider_id()!=providerId)
|
124 |
if(order.getLogistics_provider_id()!=providerId)
|
| 120 |
continue;
|
125 |
continue;
|
| - |
|
126 |
if(order.isCod() != isCod)
|
| - |
|
127 |
continue;
|
| 121 |
//TODO: These are exactly the orders which will be shipped now. Shouldn't we change their status to be SHIPPED?
|
128 |
//TODO: These are exactly the orders which will be shipped now. Shouldn't we change their status to be SHIPPED?
|
| 122 |
serialNo++;
|
129 |
serialNo++;
|
| 123 |
List<LineItem> lineItems = order.getLineitems();
|
130 |
List<LineItem> lineItems = order.getLineitems();
|
| 124 |
double weight = 0;
|
131 |
double weight = 0;
|
| 125 |
for(LineItem lineItem: lineItems)
|
132 |
for(LineItem lineItem: lineItems)
|
| Line 135... |
Line 142... |
| 135 |
ordersTable.addCell(new Phrase(order.getCustomer_state(), helvetica8));
|
142 |
ordersTable.addCell(new Phrase(order.getCustomer_state(), helvetica8));
|
| 136 |
}
|
143 |
}
|
| 137 |
|
144 |
|
| 138 |
table.addCell(logoCell);
|
145 |
table.addCell(logoCell);
|
| 139 |
table.addCell(addressCell);
|
146 |
table.addCell(addressCell);
|
| - |
|
147 |
if(isCod)
|
| - |
|
148 |
table.addCell(new Phrase("PAYMODE: COD", helvetica8));
|
| - |
|
149 |
else
|
| 140 |
table.addCell(new Phrase("PAYMODE: Prepaid", helvetica8));
|
150 |
table.addCell(new Phrase("PAYMODE: Prepaid", helvetica8));
|
| 141 |
table.addCell(new Phrase("Courier Name: " + provider.getName(), helvetica8));
|
151 |
table.addCell(new Phrase("Courier Name: " + provider.getName(), helvetica8));
|
| 142 |
table.addCell(new Phrase("Pick up Date: " + DateFormat.getDateInstance(DateFormat.MEDIUM).format(new Date()), helvetica8));
|
152 |
table.addCell(new Phrase("Pick up Date: " + DateFormat.getDateInstance(DateFormat.MEDIUM).format(new Date()), helvetica8));
|
| 143 |
table.addCell(ordersTable);
|
153 |
table.addCell(ordersTable);
|
| 144 |
table.setWidthPercentage(90.0f);
|
154 |
table.setWidthPercentage(90.0f);
|
| 145 |
|
155 |
|
| 146 |
document.add(table);
|
156 |
document.add(table);
|
| 147 |
document.close();
|
157 |
document.close();
|
| 148 |
baosPDF.close();
|
158 |
baosPDF.close();
|
| 149 |
} catch (DocumentException e) {
|
159 |
} catch (DocumentException e) {
|
| 150 |
e.printStackTrace();
|
160 |
logger.error("Error while creating the manifest file", e);
|
| 151 |
} catch (MalformedURLException e) {
|
161 |
} catch (MalformedURLException e) {
|
| 152 |
e.printStackTrace();
|
162 |
logger.error("Error while creating the manifest file", e);
|
| 153 |
} catch (IOException e) {
|
163 |
} catch (IOException e) {
|
| 154 |
e.printStackTrace();
|
164 |
logger.error("Error while creating the manifest file", e);
|
| 155 |
}
|
165 |
}
|
| 156 |
|
166 |
|
| 157 |
return baosPDF;
|
167 |
return baosPDF;
|
| 158 |
}
|
168 |
}
|
| 159 |
|
169 |
|
| 160 |
public static void main(String[] args) throws IOException {
|
170 |
public static void main(String[] args) throws IOException {
|
| 161 |
ManifestGenerator manifestGenerator = new ManifestGenerator();
|
171 |
ManifestGenerator manifestGenerator = new ManifestGenerator();
|
| 162 |
ByteArrayOutputStream baos = manifestGenerator.generateManifestFile(1, 1);
|
172 |
ByteArrayOutputStream baos = manifestGenerator.generateManifestFile(1, 1, true);
|
| 163 |
File f = new File("/home/ashish/Downloads/manifest-1-2.pdf");
|
173 |
File f = new File("/home/ashish/Downloads/manifest-1-2.pdf");
|
| 164 |
FileOutputStream fos = new FileOutputStream(f);
|
174 |
FileOutputStream fos = new FileOutputStream(f);
|
| 165 |
baos.writeTo(fos);
|
175 |
baos.writeTo(fos);
|
| 166 |
}
|
176 |
}
|
| 167 |
}
|
177 |
}
|