Subversion Repositories SmartDukaan

Rev

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

Rev 5684 Rev 5690
Line 28... Line 28...
28
 
28
 
29
import org.apache.commons.lang.StringUtils;
29
import org.apache.commons.lang.StringUtils;
30
import org.apache.struts2.rest.DefaultHttpHeaders;
30
import org.apache.struts2.rest.DefaultHttpHeaders;
31
import org.apache.struts2.rest.HttpHeaders;
31
import org.apache.struts2.rest.HttpHeaders;
32
import org.apache.thrift.TException;
32
import org.apache.thrift.TException;
-
 
33
import org.apache.thrift.transport.TTransportException;
33
import org.slf4j.Logger;
34
import org.slf4j.Logger;
34
import org.slf4j.LoggerFactory;
35
import org.slf4j.LoggerFactory;
35
 
36
 
36
import com.opensymphony.xwork2.ModelDriven;
37
import com.opensymphony.xwork2.ModelDriven;
37
 
38
 
Line 51... Line 52...
51
 
52
 
52
	private int errorCode = 0;
53
	private int errorCode = 0;
53
	private String errorMessage;
54
	private String errorMessage;
54
	private boolean fullPlbSync = false;
55
	private boolean fullPlbSync = false;
55
	private String id;
56
	private String id;
-
 
57
 
-
 
58
    private Client snapshotClient;
56
	
59
	
57
	
60
	
58
	public UpdatesController(){
61
	public UpdatesController(){
59
		
62
		
60
	}
63
	}
Line 112... Line 115...
112
	/**
115
	/**
113
     * @return
116
     * @return
114
     */
117
     */
115
    private ItemInventory fetchInventory(long itemId) {
118
    private ItemInventory fetchInventory(long itemId) {
116
        try {
119
        try {
117
            Client snapshotClient = new CatalogClient().getClient();
-
 
118
            return snapshotClient.getItemInventoryByItemId(itemId);
120
            return snapshotClient.getItemInventoryByItemId(itemId);
119
        } catch (Exception e) {
121
        } catch (Exception e) {
120
            logger.error("Could not fetch all items. Retrying.", e);
122
            logger.error("Could not fetch all items. Retrying.", e);
-
 
123
            try {
-
 
124
                snapshotClient = new CatalogClient().getClient();
121
            return fetchInventory(itemId);
125
                return fetchInventory(itemId);
-
 
126
            } catch (TTransportException e1) {
-
 
127
                logger.error("Could not create client", e);
-
 
128
                return null;
-
 
129
            }
122
        }
130
        }
123
    }
131
    }
124
 
132
 
125
    /**
133
    /**
126
     * 
134
     * 
127
     */
135
     */
128
    private void loadHotspotMappings() {
136
    private void loadHotspotMappings() {
129
        try {
137
        try {
130
            Client snapshotClient = new CatalogClient().getClient();
-
 
131
            for (VendorItemMapping mapping : snapshotClient.getAllVendorItemMappings()) {
138
            for (VendorItemMapping mapping : snapshotClient.getAllVendorItemMappings()) {
132
                if (mapping.getVendorId() == 1) {
139
                if (mapping.getVendorId() == 1) {
133
                    hotspotMappings.put(mapping.getItemId(),
140
                    hotspotMappings.put(mapping.getItemId(),
134
                            mapping.getItemKey().trim().toLowerCase());
141
                            mapping.getItemKey().trim().toLowerCase());
135
                }
142
                }
Line 141... Line 148...
141
                Thread.sleep(30000 * Long.parseLong(inventoryUpdate.getwarehouseId()));
148
                Thread.sleep(30000 * Long.parseLong(inventoryUpdate.getwarehouseId()));
142
            } catch (Exception e1) {
149
            } catch (Exception e1) {
143
                logger.error("Could not sleep.", e1);
150
                logger.error("Could not sleep.", e1);
144
            }
151
            }
145
 
152
 
-
 
153
            try {
-
 
154
                snapshotClient = new CatalogClient().getClient();
146
            loadHotspotMappings();
155
                loadHotspotMappings();
-
 
156
            } catch (TTransportException e1) {
-
 
157
                logger.error("Could not create client", e);
-
 
158
            }
147
        }
159
        }
148
    }
160
    }
149
 
161
 
150
    /**
162
    /**
151
	 * Stores the inventory updates on the history and the production server.
163
	 * Stores the inventory updates on the history and the production server.
Line 226... Line 238...
226
	}
238
	}
227
 
239
 
228
    private void sendMailForPLBMismatches(Long warehouseId, Map<String, PLBDetails> currentInventory)
240
    private void sendMailForPLBMismatches(Long warehouseId, Map<String, PLBDetails> currentInventory)
229
            throws InventoryServiceException, TException, MessagingException {
241
            throws InventoryServiceException, TException, MessagingException {
230
        if (fullPlbSync) {
242
        if (fullPlbSync) {
-
 
243
            snapshotClient = new CatalogClient().getClient();
231
            loadHotspotMappings();
244
            loadHotspotMappings();
232
            Map<Item, PLBDetails> mismatches = new HashMap<Item, PLBDetails>();
245
            Map<Item, PLBDetails> mismatches = new HashMap<Item, PLBDetails>();
233
            List<Item> items = fetchItems();
246
            List<Item> items = fetchItems();
234
            for (Item item : items) {
247
            for (Item item : items) {
235
                if (hotspotMappings.containsKey(item.getId())) {
248
                if (hotspotMappings.containsKey(item.getId())) {
236
                    PLBDetails plbDetails = currentInventory
-
 
237
                            .get(hotspotMappings.get(item.getId()).trim().toLowerCase());
249
                    PLBDetails plbDetails = currentInventory.get(hotspotMappings.get(item.getId()).trim().toLowerCase());
238
                    Long currentSnapshotAvailability = fetchInventory(item.getId()).getAvailability().get(warehouseId);
250
                    Long currentSnapshotAvailability = fetchInventory(item.getId()).getAvailability().get(warehouseId);
239
                    if ((currentSnapshotAvailability == null || currentSnapshotAvailability.equals(0l)) && 
251
                    if ((currentSnapshotAvailability == null || currentSnapshotAvailability.equals(0l)) && 
240
                        (plbDetails == null || plbDetails.getQuantity().longValue() == 0))
252
                        (plbDetails == null || plbDetails.getQuantity().longValue() == 0))
241
                    {
253
                    {
242
                        continue;
254
                        continue;