Subversion Repositories SmartDukaan

Rev

Rev 7365 | Rev 7461 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
7283 kshitij.so 1
package in.shop2020.support.controllers;
2
 
7365 kshitij.so 3
import java.util.HashMap;
7283 kshitij.so 4
import java.util.List;
5
import java.util.Map;
6
 
7
import javax.servlet.ServletRequest;
8
import javax.servlet.http.HttpServletRequest;
9
 
10
import in.shop2020.model.v1.catalog.Amazonlisted;
11
import in.shop2020.model.v1.catalog.CatalogServiceException;
12
import in.shop2020.model.v1.catalog.Item;
13
import in.shop2020.model.v1.inventory.AmazonInventorySnapshot;
14
import in.shop2020.model.v1.catalog.CatalogService.Client;
15
import in.shop2020.model.v1.inventory.InventoryServiceException;
16
import in.shop2020.thrift.clients.CatalogClient;
17
import in.shop2020.thrift.clients.InventoryClient;
7365 kshitij.so 18
import in.shop2020.thrift.clients.LogisticsClient;
19
import in.shop2020.logistics.DeliveryType;
20
import in.shop2020.logistics.LogisticsInfo;
21
import in.shop2020.logistics.LogisticsServiceException;
22
import in.shop2020.logistics.PickUpType;
7283 kshitij.so 23
 
7365 kshitij.so 24
import org.apache.commons.lang.xwork.StringUtils;
7283 kshitij.so 25
import org.apache.struts2.convention.annotation.Result;
26
import org.apache.struts2.convention.annotation.Results;
27
import org.apache.struts2.interceptor.ServletRequestAware;
28
import org.apache.thrift.TException;
29
import org.apache.thrift.transport.TTransportException;
30
import org.slf4j.Logger;
31
import org.slf4j.LoggerFactory;
32
 
33
import com.opensymphony.xwork2.ValidationAwareSupport;
34
 
35
@SuppressWarnings("serial")
36
@Results({
37
	@Result(name = "redirect", location = "${url}", type = "redirect") })
38
	public class AmazonListController extends ValidationAwareSupport implements ServletRequestAware {
39
 
40
	private static Logger logger = LoggerFactory.getLogger(AmazonListController.class);
41
 
42
	private ServletRequest request;
43
	private String url;
44
	private String id;
45
	private String itemId;
46
	private String isFba;
47
	private String isNonFba;
48
	private String isInventoryOverride;
49
	private String fbaPrice;
50
	private String sellingPrice;
51
	private String saholicPrice;
7365 kshitij.so 52
	private String isTime;
53
	private String handlingTime;
54
	private String customHandlingTime;
7283 kshitij.so 55
 
56
	public String index() {
57
		return "index";
58
	}
59
 
60
 
61
	public List<Amazonlisted> fetchItems() throws TException {
7408 kshitij.so 62
		Client CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
7283 kshitij.so 63
		return CatalogClient.getAllAmazonListedItems();
64
	}
65
 
7408 kshitij.so 66
	public Amazonlisted fetchItemDetail() throws NumberFormatException, TException {
67
		Client CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
7283 kshitij.so 68
		return CatalogClient.getAmazonItemDetails(Long.valueOf(id));
69
	}
70
 
7408 kshitij.so 71
	public Item getSaholicItem(String id) throws NumberFormatException, CatalogServiceException, TException {
72
		Client CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
7283 kshitij.so 73
		return CatalogClient.getItem(Long.valueOf(id));
74
	}
7365 kshitij.so 75
 
76
 
77
 
7283 kshitij.so 78
	public String update() throws NumberFormatException, TException{
7408 kshitij.so 79
		Client CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
7283 kshitij.so 80
		if ( Double.valueOf(fbaPrice) > Double.valueOf(saholicPrice) || Double.valueOf(sellingPrice) > Double.valueOf(saholicPrice) ) {
7365 kshitij.so 81
			addActionError("Failed To Do Changes");
7283 kshitij.so 82
		}
83
		else {
7365 kshitij.so 84
			boolean flag=false;
85
			long delay = Long.valueOf(handlingTime);
86
			if ( Boolean.valueOf(isTime)) {
87
				flag = true;
88
				delay = Long.valueOf(customHandlingTime);
89
			}
90
 
91
			CatalogClient.updateAmazonItemDetails(Long.valueOf(itemId),Double.valueOf(fbaPrice),Double.valueOf(sellingPrice),Boolean.valueOf(isFba),Boolean.valueOf(isNonFba),Boolean.valueOf(isInventoryOverride),delay,flag);
7283 kshitij.so 92
		}
93
		setUrl("/amazon-list/");
94
		return "redirect";
95
 
96
	}
97
 
98
	public Map<Long, Long> getAvailableItemInventory(String itemId) throws NumberFormatException, InventoryServiceException, TException{
99
		InventoryClient inventoryServiceClient = new InventoryClient();
100
		in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
101
		in.shop2020.model.v1.inventory.ItemInventory thriftItemInventory = inventoryClient.getItemInventoryByItemId(Long.valueOf(itemId));
102
		return thriftItemInventory.getAvailability();
103
 
104
	}
105
 
106
	public Map<Long, Long> getReservedItemInventory(String itemId) throws NumberFormatException, InventoryServiceException, TException{
107
		InventoryClient inventoryServiceClient = new InventoryClient();
108
		in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
109
		in.shop2020.model.v1.inventory.ItemInventory thriftItemInventory = inventoryClient.getItemInventoryByItemId(Long.valueOf(itemId));
110
		return thriftItemInventory.getReserved();
111
 
112
	}
113
 
114
	public String getWarehouseName(String warehouseId) throws NumberFormatException, TException { 
115
		InventoryClient inventoryServiceClient = new InventoryClient();
116
		return inventoryServiceClient.getClient().getWarehouseName(Long.valueOf(warehouseId));
117
	}
118
 
119
	public AmazonInventorySnapshot getInventoryForAmazonItem(String itemId) throws NumberFormatException, TException {
120
		InventoryClient inventoryServiceClient = new InventoryClient();
7365 kshitij.so 121
		try { 
122
			return inventoryServiceClient.getClient().getAmazonInventoryForItem(Long.valueOf(itemId));
123
		}
124
		catch (Exception e){
125
			return null;
126
		}
7283 kshitij.so 127
	}
128
 
7365 kshitij.so 129
	public Long getTimetoShip(String itemId) throws LogisticsServiceException, TException{
130
		LogisticsClient logisticsClient = new LogisticsClient();
131
		return logisticsClient.getClient().getLogisticsInfo("110001", Long.valueOf(itemId), DeliveryType.COD, PickUpType.COURIER).getShippingTime();
132
 
133
	}
134
 
135
	public  Map<Long, String> getAliveItemMap() throws TException{
7408 kshitij.so 136
		Client CatalogClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
7365 kshitij.so 137
		List<Item> itemList = CatalogClient.getAllAliveItems();
138
		Map<Long, String> itemMap = new HashMap<Long, String>();
139
		for (Item o : itemList) {
140
			itemMap.put((Long) o.getId(), (String) o.getBrand()+" "+o.getModelName()+" "+o.getModelNumber()+" "+o.getColor());
141
		}
142
		return itemMap;
143
	}
144
 
7283 kshitij.so 145
	public String edit() {
146
		return "edit";
147
	}
148
 
149
	public String show() {
150
		return "show";
151
	}
152
 
153
	public String editNew() {
154
		return "editNew";
155
	}
156
 
157
 
158
 
159
	public void setId(String id) {
160
		this.id = id;
161
	}
162
 
163
	public void setUrl(String url) {
164
		this.url = url;
165
	}
166
 
167
	public String getUrl() {
168
		return url;
169
	}
170
 
171
	public String getId() {
172
		return id;
173
	}
174
 
175
	public void setItemId(String itemId) {
176
		this.itemId = itemId;
177
	}
178
 
179
	public String getItemId() {
180
		return itemId;
181
	}
182
 
183
	public void setIsFba(String isFba) {
184
		this.isFba = isFba;
185
	}
186
 
187
	public String getIsFba() {
188
		return isFba;
189
	}
190
 
191
	public void setIsNonFba(String isNonFba) {
192
		this.isNonFba = isNonFba;
193
	}
194
 
195
	public String getIsNonFba() {
196
		return isNonFba;
197
	}
198
 
199
	public void setIsInventoryOverride(String isInventoryOverride) {
200
		this.isInventoryOverride = isInventoryOverride;
201
	}
202
 
203
	public String getIsInventoryOverride() {
204
		return isInventoryOverride;
205
	}
206
 
207
	public void setSellingPrice(String sellingPrice) {
208
		this.sellingPrice = sellingPrice;
209
	}
210
 
211
	public String getSellingPrice() {
212
		return sellingPrice;
213
	}
214
 
215
	public void setFbaPrice(String fbaPrice) {
216
		this.fbaPrice = fbaPrice;
217
	}
218
 
219
	public String getFbaPrice() {
220
		return fbaPrice;
221
	}
7365 kshitij.so 222
 
7283 kshitij.so 223
	public void setSaholicPrice(String saholicPrice) {
224
		this.saholicPrice = saholicPrice;
225
	}
226
 
227
	public String getSaholicPrice() {
228
		return saholicPrice;
229
	}
230
 
7365 kshitij.so 231
	public void setIsTime(String isTime){
232
		this.isTime = isTime;
233
	}
234
 
235
	String getIsTime(){
236
		return isTime;
237
	}
238
 
239
	public void setHandlingTime(String handlingTime){
240
		this.handlingTime = handlingTime;
241
	}
242
 
243
	String getHandlingTime(){
244
		return handlingTime;
245
	}
246
 
247
	public void setCustomHandlingTime(String customHandlingTime){
248
		this.customHandlingTime = customHandlingTime;
249
	}
250
 
251
	String getCustomHandlingTime(){
252
		return customHandlingTime;
253
	}
254
 
7283 kshitij.so 255
	@Override
256
	public void setServletRequest(HttpServletRequest request) {
257
		this.request = request;
258
 
259
	}
260
 
261
	public static void main(String[] args) throws NumberFormatException, InventoryServiceException, TException {
262
		AmazonListController call = new AmazonListController();
7365 kshitij.so 263
		System.out.println(call.getInventoryForAmazonItem("5"));
7283 kshitij.so 264
	}
265
}