| Line 4... |
Line 4... |
| 4 |
import java.util.HashMap;
|
4 |
import java.util.HashMap;
|
| 5 |
import java.util.Map;
|
5 |
import java.util.Map;
|
| 6 |
|
6 |
|
| 7 |
import in.shop2020.model.v1.catalog.InventoryService.Client;
|
7 |
import in.shop2020.model.v1.catalog.InventoryService.Client;
|
| 8 |
import in.shop2020.model.v1.catalog.Warehouse;
|
8 |
import in.shop2020.model.v1.catalog.Warehouse;
|
| - |
|
9 |
import in.shop2020.support.models.BillingUpdate;
|
| 9 |
import in.shop2020.support.models.InventoryUpdate;
|
10 |
import in.shop2020.support.models.InventoryUpdate;
|
| 10 |
import in.shop2020.support.models.Update;
|
11 |
import in.shop2020.support.models.Update;
|
| 11 |
import in.shop2020.thrift.clients.CatalogClient;
|
12 |
import in.shop2020.thrift.clients.CatalogClient;
|
| - |
|
13 |
import in.shop2020.thrift.clients.TransactionClient;
|
| 12 |
import in.shop2020.utils.ConfigClientKeys;
|
14 |
import in.shop2020.utils.ConfigClientKeys;
|
| 13 |
|
15 |
|
| 14 |
import org.apache.struts2.rest.DefaultHttpHeaders;
|
16 |
import org.apache.struts2.rest.DefaultHttpHeaders;
|
| 15 |
import org.apache.struts2.rest.HttpHeaders;
|
17 |
import org.apache.struts2.rest.HttpHeaders;
|
| 16 |
import org.slf4j.Logger;
|
18 |
import org.slf4j.Logger;
|
| Line 71... |
Line 73... |
| 71 |
//The history client is used to update the inventory history on the processing system.
|
73 |
//The history client is used to update the inventory history on the processing system.
|
| 72 |
CatalogClient historyCatalogServiceClient = new CatalogClient(
|
74 |
CatalogClient historyCatalogServiceClient = new CatalogClient(
|
| 73 |
ConfigClientKeys.inventory_history_service_server_host.toString(),
|
75 |
ConfigClientKeys.inventory_history_service_server_host.toString(),
|
| 74 |
ConfigClientKeys.inventory_history_service_server_port.toString());
|
76 |
ConfigClientKeys.inventory_history_service_server_port.toString());
|
| 75 |
Client historyClient = historyCatalogServiceClient.getClient();
|
77 |
Client historyClient = historyCatalogServiceClient.getClient();
|
| - |
|
78 |
|
| - |
|
79 |
//The snapshot client is used to update the inventory snapshot for production systems.
|
| 76 |
|
80 |
TransactionClient transactionClient = new TransactionClient();
|
| - |
|
81 |
in.shop2020.model.v1.order.TransactionService.Client tClient = transactionClient.getClient();
|
| - |
|
82 |
|
| 77 |
Long warehouseId = Long.parseLong(inventoryUpdate.getwarehouseId());
|
83 |
Long warehouseId = Long.parseLong(inventoryUpdate.getwarehouseId());
|
| 78 |
String timestamp = inventoryUpdate.getCurrentTimestamp();
|
84 |
String timestamp = inventoryUpdate.getCurrentTimestamp();
|
| 79 |
Map<String, Long> availability = new HashMap<String, Long>();
|
85 |
Map<String, Long> availability = new HashMap<String, Long>();
|
| 80 |
List<Update> updates = inventoryUpdate.getUpdates();
|
86 |
List<Update> updates = inventoryUpdate.getUpdates();
|
| 81 |
for(Update update: updates){
|
87 |
for(Update update: updates){
|
| Line 84... |
Line 90... |
| 84 |
if(availability.containsKey(key)){
|
90 |
if(availability.containsKey(key)){
|
| 85 |
quantity = quantity + availability.get(key);
|
91 |
quantity = quantity + availability.get(key);
|
| 86 |
}
|
92 |
}
|
| 87 |
availability.put(key, quantity);
|
93 |
availability.put(key, quantity);
|
| 88 |
}
|
94 |
}
|
| - |
|
95 |
|
| 89 |
//Update the snapshot before the history since that is more important.
|
96 |
//Update the snapshot before the history since that is more important.
|
| 90 |
snapshotClient.updateInventory(warehouseId, timestamp, availability);
|
97 |
snapshotClient.updateInventory(warehouseId, timestamp, availability);
|
| 91 |
historyClient.updateInventoryHistory(warehouseId, timestamp, availability);
|
98 |
historyClient.updateInventoryHistory(warehouseId, timestamp, availability);
|
| - |
|
99 |
|
| - |
|
100 |
List<BillingUpdate> billingUpdates = inventoryUpdate.getBillingUpdates();
|
| - |
|
101 |
if(billingUpdates!=null){
|
| - |
|
102 |
for(BillingUpdate billingUpdate: billingUpdates){
|
| - |
|
103 |
tClient.addInvoiceNumber(Long.parseLong(billingUpdate.getOrderId()), billingUpdate.getInvoiceNumber());
|
| - |
|
104 |
}
|
| - |
|
105 |
}
|
| - |
|
106 |
|
| 92 |
} catch (Exception e) {
|
107 |
} catch (Exception e) {
|
| 93 |
logger.error("Unable to update inventory", e);
|
108 |
logger.error("Unable to update inventory", e);
|
| 94 |
}
|
109 |
}
|
| 95 |
|
110 |
|
| 96 |
return new DefaultHttpHeaders("psuccess");
|
111 |
return new DefaultHttpHeaders("psuccess");
|