Subversion Repositories SmartDukaan

Rev

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

Rev 4765 Rev 4987
Line 1... Line 1...
1
package in.shop2020.support.controllers;
1
package in.shop2020.support.controllers;
2
 
2
 
3
import java.util.List;
-
 
4
import java.util.HashMap;
-
 
5
import java.util.Map;
-
 
6
 
-
 
7
import in.shop2020.model.v1.catalog.InventoryService.Client;
3
import in.shop2020.model.v1.catalog.InventoryService.Client;
8
import in.shop2020.model.v1.catalog.Warehouse;
4
import in.shop2020.model.v1.catalog.Warehouse;
9
import in.shop2020.support.models.BillingUpdate;
5
import in.shop2020.support.models.BillingUpdate;
10
import in.shop2020.support.models.InventoryUpdate;
6
import in.shop2020.support.models.InventoryUpdate;
-
 
7
import in.shop2020.support.models.PLBDetails;
11
import in.shop2020.support.models.Update;
8
import in.shop2020.support.models.Update;
12
import in.shop2020.thrift.clients.CatalogClient;
9
import in.shop2020.thrift.clients.CatalogClient;
13
import in.shop2020.thrift.clients.TransactionClient;
10
import in.shop2020.thrift.clients.TransactionClient;
14
import in.shop2020.utils.ConfigClientKeys;
11
import in.shop2020.utils.ConfigClientKeys;
15
 
12
 
-
 
13
import java.util.HashMap;
-
 
14
import java.util.List;
-
 
15
import java.util.Map;
-
 
16
 
16
import org.apache.struts2.rest.DefaultHttpHeaders;
17
import org.apache.struts2.rest.DefaultHttpHeaders;
17
import org.apache.struts2.rest.HttpHeaders;
18
import org.apache.struts2.rest.HttpHeaders;
18
import org.slf4j.Logger;
19
import org.slf4j.Logger;
19
import org.slf4j.LoggerFactory;
20
import org.slf4j.LoggerFactory;
20
 
21
 
21
import com.opensymphony.xwork2.ModelDriven;
22
import com.opensymphony.xwork2.ModelDriven;
22
 
23
 
23
public class UpdatesController implements ModelDriven<InventoryUpdate>{
24
public class UpdatesController implements ModelDriven<InventoryUpdate>{
24
 
25
 
-
 
26
    /**
-
 
27
     * 
-
 
28
     */
-
 
29
    private static final String FIELD_DELIMITER = "~#~#~#";
-
 
30
 
25
    private static Logger logger = LoggerFactory.getLogger(UpdatesController.class);
31
    private static Logger logger = LoggerFactory.getLogger(UpdatesController.class);
26
    
32
    
27
	private InventoryUpdate inventoryUpdate = new InventoryUpdate();
33
	private InventoryUpdate inventoryUpdate = new InventoryUpdate();
28
	private String timestamp;
34
	private String timestampAndItemIds;
29
	
35
	
30
	private int errorCode = 0;
36
	private int errorCode = 0;
31
	private String errorMessage;
37
	private String errorMessage;
32
	
38
	
33
	private String id;
39
	private String id;
Line 50... Line 56...
50
		try {
56
		try {
51
			catalogServiceClient = new CatalogClient();
57
			catalogServiceClient = new CatalogClient();
52
			client = catalogServiceClient.getClient();
58
			client = catalogServiceClient.getClient();
53
			long warehouseId = Long.parseLong(getId());
59
			long warehouseId = Long.parseLong(getId());
54
			Warehouse warehouse = client.getWarehouse(warehouseId);
60
			Warehouse warehouse = client.getWarehouse(warehouseId);
55
			setTimestamp(warehouse.getVendorString());
61
			timestampAndItemIds = warehouse.getVendorString();
-
 
62
			
-
 
63
			List<String> itemKeys = client.getItemKeysToBeProcessed(warehouseId);
-
 
64
			if (!itemKeys.isEmpty()) {
-
 
65
			    for (String itemKey : itemKeys) {
-
 
66
			        timestampAndItemIds += FIELD_DELIMITER + itemKey;
-
 
67
			    }
-
 
68
			}
56
		} catch (Exception e) {
69
		} catch (Exception e) {
57
			logger.error("Error getting the warehouse or setting the timestamp", e);
70
			logger.error("Error getting the warehouse or setting the timestamp", e);
58
		}
71
		}
59
		return new DefaultHttpHeaders("lsuccess");
72
		return new DefaultHttpHeaders("lsuccess");
60
	}
73
	}
Line 101... Line 114...
101
			if(billingUpdates!=null){
114
			if(billingUpdates!=null){
102
				for(BillingUpdate billingUpdate: billingUpdates){
115
				for(BillingUpdate billingUpdate: billingUpdates){
103
					tClient.addInvoiceNumber(Long.parseLong(billingUpdate.getOrderId()), billingUpdate.getInvoiceNumber(), billingUpdate.getColor());
116
					tClient.addInvoiceNumber(Long.parseLong(billingUpdate.getOrderId()), billingUpdate.getInvoiceNumber(), billingUpdate.getColor());
104
				}
117
				}
105
			}
118
			}
-
 
119
 
-
 
120
			List<PLBDetails> plbDetails = inventoryUpdate.getPlbDetails();
-
 
121
			if (plbDetails != null) {
-
 
122
			    for (PLBDetails plbDetail : plbDetails) {
-
 
123
			        try {
-
 
124
                        snapshotClient.resetAvailability(
-
 
125
                                plbDetail.getItemKey(), 1,
-
 
126
                                plbDetail.getQuantity(), warehouseId);
-
 
127
                        snapshotClient.markMissedInventoryUpdatesAsProcessed(
-
 
128
                                plbDetail.getItemKey(), warehouseId);
-
 
129
                    } catch (Exception e) {
-
 
130
                        logger.error("Could not reset availability of: " + plbDetail.getItemKey(), e);
-
 
131
                    }
-
 
132
			    }
106
			
133
			}
107
		} catch (Exception e) {
134
		} catch (Exception e) {
108
			logger.error("Unable to update inventory", e);
135
			logger.error("Unable to update inventory", e);
109
		}
136
		}
110
		
137
		
111
		return new DefaultHttpHeaders("psuccess");
138
		return new DefaultHttpHeaders("psuccess");
Line 134... Line 161...
134
 
161
 
135
	public void setInventoryUpdate(InventoryUpdate inventoryUpdate) {
162
	public void setInventoryUpdate(InventoryUpdate inventoryUpdate) {
136
		this.inventoryUpdate = inventoryUpdate;
163
		this.inventoryUpdate = inventoryUpdate;
137
	}
164
	}
138
 
165
 
139
	public void setTimestamp(String timestamp) {
166
	public void setTimestampAndItemIds(String timestampAndItemIds) {
140
		this.timestamp = timestamp;
167
		this.timestampAndItemIds = timestampAndItemIds;
141
	}
168
	}
142
 
169
 
143
	public String getTimestamp() {
170
	public String getTimestampAndItemIds() {
144
		return timestamp;
171
		return timestampAndItemIds;
145
	}	
172
	}	
146
}
173
}