| Line 7... |
Line 7... |
| 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.InventoryUpdate;
|
9 |
import in.shop2020.support.models.InventoryUpdate;
|
| 10 |
import in.shop2020.support.models.Update;
|
10 |
import in.shop2020.support.models.Update;
|
| 11 |
import in.shop2020.thrift.clients.CatalogClient;
|
11 |
import in.shop2020.thrift.clients.CatalogClient;
|
| - |
|
12 |
import in.shop2020.utils.ConfigClientKeys;
|
| 12 |
|
13 |
|
| 13 |
import org.apache.struts2.rest.DefaultHttpHeaders;
|
14 |
import org.apache.struts2.rest.DefaultHttpHeaders;
|
| 14 |
import org.apache.struts2.rest.HttpHeaders;
|
15 |
import org.apache.struts2.rest.HttpHeaders;
|
| 15 |
import org.slf4j.Logger;
|
16 |
import org.slf4j.Logger;
|
| 16 |
import org.slf4j.LoggerFactory;
|
17 |
import org.slf4j.LoggerFactory;
|
| Line 54... |
Line 55... |
| 54 |
logger.error("Error getting the warehouse or setting the timestamp", e);
|
55 |
logger.error("Error getting the warehouse or setting the timestamp", e);
|
| 55 |
}
|
56 |
}
|
| 56 |
return new DefaultHttpHeaders("lsuccess");
|
57 |
return new DefaultHttpHeaders("lsuccess");
|
| 57 |
}
|
58 |
}
|
| 58 |
|
59 |
|
| - |
|
60 |
/**
|
| - |
|
61 |
* Stores the inventory updates on the history and the production server.
|
| - |
|
62 |
* @return
|
| 59 |
|
63 |
*/
|
| 60 |
public HttpHeaders create(){
|
64 |
public HttpHeaders create(){
|
| 61 |
logger.info(inventoryUpdate.toString());
|
65 |
logger.info(inventoryUpdate.toString());
|
| 62 |
// need to store all data from object to service
|
- |
|
| 63 |
CatalogClient catalogServiceClient;
|
- |
|
| 64 |
Client client;
|
- |
|
| 65 |
try {
|
66 |
try {
|
| - |
|
67 |
//The snapshot client is used to update the inventory snapshot for production systems.
|
| 66 |
catalogServiceClient = new CatalogClient();
|
68 |
CatalogClient snapshotCatalogServiceClient = new CatalogClient();
|
| - |
|
69 |
Client snapshotClient = snapshotCatalogServiceClient.getClient();
|
| - |
|
70 |
|
| - |
|
71 |
//The history client is used to update the inventory history on the processing system.
|
| - |
|
72 |
CatalogClient historyCatalogServiceClient = new CatalogClient(
|
| - |
|
73 |
ConfigClientKeys.inventory_history_service_server_host.toString(),
|
| - |
|
74 |
ConfigClientKeys.inventory_history_service_server_port.toString());
|
| 67 |
client = catalogServiceClient.getClient();
|
75 |
Client historyClient = historyCatalogServiceClient.getClient();
|
| - |
|
76 |
|
| 68 |
Long warehouseId = Long.parseLong(inventoryUpdate.getwarehouseId());
|
77 |
Long warehouseId = Long.parseLong(inventoryUpdate.getwarehouseId());
|
| 69 |
String timestamp = inventoryUpdate.getCurrentTimestamp();
|
78 |
String timestamp = inventoryUpdate.getCurrentTimestamp();
|
| 70 |
Map<String, Long> availability = new HashMap<String, Long>();
|
79 |
Map<String, Long> availability = new HashMap<String, Long>();
|
| 71 |
List<Update> updates = inventoryUpdate.getUpdates();
|
80 |
List<Update> updates = inventoryUpdate.getUpdates();
|
| 72 |
for(Update update: updates){
|
81 |
for(Update update: updates){
|
| Line 75... |
Line 84... |
| 75 |
if(availability.containsKey(key)){
|
84 |
if(availability.containsKey(key)){
|
| 76 |
quantity = quantity + availability.get(key);
|
85 |
quantity = quantity + availability.get(key);
|
| 77 |
}
|
86 |
}
|
| 78 |
availability.put(key, quantity);
|
87 |
availability.put(key, quantity);
|
| 79 |
}
|
88 |
}
|
| - |
|
89 |
//Update the snapshot before the history since that is more important.
|
| 80 |
client.updateInventory(warehouseId, timestamp, availability);
|
90 |
snapshotClient.updateInventory(warehouseId, timestamp, availability);
|
| 81 |
|
- |
|
| - |
|
91 |
historyClient.updateInventoryHistory(warehouseId, timestamp, availability);
|
| 82 |
} catch (Exception e) {
|
92 |
} catch (Exception e) {
|
| 83 |
logger.error("Unable to update inventory", e);
|
93 |
logger.error("Unable to update inventory", e);
|
| 84 |
}
|
94 |
}
|
| 85 |
|
95 |
|
| 86 |
return new DefaultHttpHeaders("psuccess");
|
96 |
return new DefaultHttpHeaders("psuccess");
|