Subversion Repositories SmartDukaan

Rev

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

Rev 5231 Rev 5237
Line 41... Line 41...
41
    private static Logger logger = LoggerFactory.getLogger(UpdatesController.class);
41
    private static Logger logger = LoggerFactory.getLogger(UpdatesController.class);
42
    
42
    
43
	private InventoryUpdate inventoryUpdate = new InventoryUpdate();
43
	private InventoryUpdate inventoryUpdate = new InventoryUpdate();
44
	private String timestampAndItemIds;
44
	private String timestampAndItemIds;
45
	
45
	
-
 
46
	private Map<Long, String> hotspotMappings = new HashMap<Long, String>();
-
 
47
 
46
	private int errorCode = 0;
48
	private int errorCode = 0;
47
	private String errorMessage;
49
	private String errorMessage;
48
	private boolean fullPlbSync = false;
50
	private boolean fullPlbSync = false;
49
	private String id;
51
	private String id;
50
	
52
	
Line 71... Line 73...
71
			timestampAndItemIds = warehouse.getVendorString();
73
			timestampAndItemIds = warehouse.getVendorString();
72
 
74
 
73
			client = catalogServiceClient.getClient();
75
			client = catalogServiceClient.getClient();
74
			List<String> itemKeys = client.getItemKeysToBeProcessed(warehouseId);
76
			List<String> itemKeys = client.getItemKeysToBeProcessed(warehouseId);
75
			if (fullPlbSync) {
77
			if (fullPlbSync) {
-
 
78
			    loadHotspotMappings();
76
			    itemKeys = new ArrayList<String>();
79
			    itemKeys = new ArrayList<String>();
77
			    client = catalogServiceClient.getClient();
80
			    client = catalogServiceClient.getClient();
78
			    List<Item> items = client.getAllItems(true);
81
			    List<Item> items = client.getAllItems(true);
79
			    for (Item item : items) {
82
			    for (Item item : items) {
80
			        if (ItemType.NON_SERIALIZED.equals(item.getType())) {
83
			        if (ItemType.NON_SERIALIZED.equals(item.getType())) {
81
			            continue;
84
			            continue;
82
			        }
85
			        }
83
 
86
 
84
			        client = catalogServiceClient.getClient();
-
 
85
			        List<VendorItemMapping> mappings = client.getVendorItemMappings(item.getId());
-
 
86
			        if (mappings != null) {
-
 
87
			            for (VendorItemMapping mapping : mappings) {
-
 
88
			                if (mapping.getVendorId() == 1) {
87
			        if (hotspotMappings.containsKey(item.getId())) {
89
			                    itemKeys.add(mapping.getItemKey());
88
			            itemKeys.add(hotspotMappings.get(item.getId()));
90
			                    break;
-
 
91
			                }
-
 
92
			            }
-
 
93
			        }
89
			        }
94
			    }
90
			    }
95
			}
91
			}
96
 
92
 
97
			if (!itemKeys.isEmpty()) {
93
			if (!itemKeys.isEmpty()) {
Line 104... Line 100...
104
		}
100
		}
105
		return new DefaultHttpHeaders("lsuccess");
101
		return new DefaultHttpHeaders("lsuccess");
106
	}
102
	}
107
	
103
	
108
	/**
104
	/**
-
 
105
     * 
-
 
106
     */
-
 
107
    private void loadHotspotMappings() {
-
 
108
        try {
-
 
109
            Client snapshotClient = new CatalogClient().getClient();
-
 
110
            for (VendorItemMapping mapping : snapshotClient
-
 
111
                    .getAllVendorItemMappings()) {
-
 
112
                if (mapping.getVendorId() == 1) {
-
 
113
                    hotspotMappings.put(mapping.getItemId(),
-
 
114
                            mapping.getItemKey());
-
 
115
                }
-
 
116
            }
-
 
117
        } catch (Exception e) {
-
 
118
            logger.error("Could not load vendor item mappings", e);
-
 
119
        }
-
 
120
    }
-
 
121
 
-
 
122
    /**
109
	 * Stores the inventory updates on the history and the production server.
123
	 * Stores the inventory updates on the history and the production server.
110
	 * @return
124
	 * @return
111
	 */
125
	 */
112
	public HttpHeaders create(){
126
	public HttpHeaders create(){
113
		logger.info(inventoryUpdate.toString());
127
		logger.info(inventoryUpdate.toString());
Line 184... Line 198...
184
	}
198
	}
185
 
199
 
186
    private void sendMailForPLBMismatches(Long warehouseId, Map<String, PLBDetails> currentInventory)
200
    private void sendMailForPLBMismatches(Long warehouseId, Map<String, PLBDetails> currentInventory)
187
            throws InventoryServiceException, TException, MessagingException {
201
            throws InventoryServiceException, TException, MessagingException {
188
        if (fullPlbSync) {
202
        if (fullPlbSync) {
-
 
203
            loadHotspotMappings();
189
            Map<Item, PLBDetails> mismatches = new HashMap<Item, PLBDetails>();
204
            Map<Item, PLBDetails> mismatches = new HashMap<Item, PLBDetails>();
190
            Client snapshotClient = new CatalogClient().getClient();
205
            Client snapshotClient = new CatalogClient().getClient();
191
            List<Item> items = snapshotClient.getAllItems(true);
206
            List<Item> items = snapshotClient.getAllItems(true);
192
            for (Item item : items) {
207
            for (Item item : items) {
193
                if (ItemType.NON_SERIALIZED.equals(item.getType())) {
208
                if (ItemType.NON_SERIALIZED.equals(item.getType())) {
194
                    continue;
209
                    continue;
195
                }
210
                }
196
 
211
 
197
                snapshotClient = new CatalogClient().getClient();
212
                if (hotspotMappings.containsKey(item.getId())) {
198
                List<VendorItemMapping> mappings = snapshotClient.getVendorItemMappings(item.getId());
-
 
199
                if (mappings != null) {
-
 
200
                    for (VendorItemMapping mapping : mappings) {
213
                    PLBDetails plbDetails = currentInventory
201
                        if (mapping.getVendorId() == 1) {
214
                            .get(hotspotMappings.get(item.getId()));
202
                            PLBDetails plbDetails = currentInventory.get(mapping.getItemKey());
215
                    Long currentSnapshotAvailibility = item.getItemInventory()
203
                            Long currentSnapshotAvailibility = item.getItemInventory().getAvailability().get(warehouseId);
216
                            .getAvailability().get(warehouseId);
204
                            if ((currentSnapshotAvailibility == null || currentSnapshotAvailibility.equals(0)) &&
217
                    if ((currentSnapshotAvailibility == null || currentSnapshotAvailibility.equals(0)) && 
205
                                (plbDetails == null || plbDetails.getQuantity().equals(0)))
218
                        (plbDetails == null || plbDetails.getQuantity().equals(0)))
206
                            {
219
                    {
207
                                continue;
220
                        continue;
208
                            }
221
                    }
209
 
222
 
210
                            if (currentSnapshotAvailibility == null || plbDetails == null ||
223
                    if (currentSnapshotAvailibility == null || plbDetails == null ||
211
                                !currentSnapshotAvailibility.equals(plbDetails.getQuantity().longValue()))
224
                        !currentSnapshotAvailibility.equals(plbDetails.getQuantity().longValue()))
212
                            {
225
                    {
213
                                mismatches.put(item, plbDetails);
226
                        mismatches.put(item, plbDetails);
214
                            }
-
 
215
                        }
-
 
216
                    }
227
                    }
217
                }
228
                }
218
            }
229
            }
219
 
230
 
220
            String subject = mismatches.size() + " mismatches with PLB sync for warehouse id: " + warehouseId;
231
            String subject = mismatches.size() + " mismatches with PLB sync for warehouse id: " + warehouseId;