Subversion Repositories SmartDukaan

Rev

Rev 7365 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
7283 kshitij.so 1
package in.shop2020.support.controllers;
2
 
3
import java.util.List;
4
import java.util.Map;
5
 
6
import javax.servlet.ServletRequest;
7
import javax.servlet.http.HttpServletRequest;
8
 
9
import in.shop2020.model.v1.catalog.Amazonlisted;
10
import in.shop2020.model.v1.catalog.CatalogServiceException;
11
import in.shop2020.model.v1.catalog.Item;
12
import in.shop2020.model.v1.inventory.AmazonInventorySnapshot;
13
import in.shop2020.model.v1.catalog.CatalogService.Client;
14
import in.shop2020.model.v1.inventory.InventoryServiceException;
15
import in.shop2020.thrift.clients.CatalogClient;
16
import in.shop2020.thrift.clients.InventoryClient;
17
 
18
import org.apache.struts2.convention.annotation.Result;
19
import org.apache.struts2.convention.annotation.Results;
20
import org.apache.struts2.interceptor.ServletRequestAware;
21
import org.apache.thrift.TException;
22
import org.apache.thrift.transport.TTransportException;
23
import org.slf4j.Logger;
24
import org.slf4j.LoggerFactory;
25
 
26
import com.opensymphony.xwork2.ValidationAwareSupport;
27
 
28
@SuppressWarnings("serial")
29
@Results({
30
	@Result(name = "redirect", location = "${url}", type = "redirect") })
31
	public class AmazonListController extends ValidationAwareSupport implements ServletRequestAware {
32
 
33
	private static Logger logger = LoggerFactory.getLogger(AmazonListController.class);
34
 
35
	private ServletRequest request;
36
	private String url;
37
	private String id;
38
	private String itemId;
39
	private String isFba;
40
	private String isNonFba;
41
	private String isInventoryOverride;
42
	private String fbaPrice;
43
	private String sellingPrice;
44
	private String saholicPrice;
45
 
46
	public String index() {
47
		return "index";
48
	}
49
 
50
 
51
	public List<Amazonlisted> fetchItems() throws TException {
52
		Client CatalogClient = new CatalogClient().getClient();
53
		return CatalogClient.getAllAmazonListedItems();
54
 
55
	}
56
 
57
	public Amazonlisted fetchItemDetail() throws NumberFormatException, TException { 
58
		Client CatalogClient = new CatalogClient().getClient();
59
		return CatalogClient.getAmazonItemDetails(Long.valueOf(id));
60
 
61
	}
62
 
63
	public Item getSaholicItem() throws NumberFormatException, CatalogServiceException, TException { 
64
		Client CatalogClient = new CatalogClient().getClient();
65
		return CatalogClient.getItem(Long.valueOf(id));
66
	}
67
 
68
 
69
	public String update() throws NumberFormatException, TException{
70
		Client CatalogClient = new CatalogClient().getClient();
71
		if ( Double.valueOf(fbaPrice) > Double.valueOf(saholicPrice) || Double.valueOf(sellingPrice) > Double.valueOf(saholicPrice) ) {
72
		addActionError("Failed To Do Changes");
73
		}
74
		else {
75
		CatalogClient.updateAmazonItemDetails(Long.valueOf(itemId),Double.valueOf(fbaPrice),Double.valueOf(sellingPrice),Boolean.valueOf(isFba),Boolean.valueOf(isNonFba),Boolean.valueOf(isInventoryOverride));
76
		}
77
		setUrl("/amazon-list/");
78
		return "redirect";
79
 
80
	}
81
 
82
	public Map<Long, Long> getAvailableItemInventory(String itemId) throws NumberFormatException, InventoryServiceException, TException{
83
		InventoryClient inventoryServiceClient = new InventoryClient();
84
		in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
85
		in.shop2020.model.v1.inventory.ItemInventory thriftItemInventory = inventoryClient.getItemInventoryByItemId(Long.valueOf(itemId));
86
		return thriftItemInventory.getAvailability();
87
 
88
	}
89
 
90
	public Map<Long, Long> getReservedItemInventory(String itemId) throws NumberFormatException, InventoryServiceException, TException{
91
		InventoryClient inventoryServiceClient = new InventoryClient();
92
		in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
93
		in.shop2020.model.v1.inventory.ItemInventory thriftItemInventory = inventoryClient.getItemInventoryByItemId(Long.valueOf(itemId));
94
		return thriftItemInventory.getReserved();
95
 
96
	}
97
 
98
	public String getWarehouseName(String warehouseId) throws NumberFormatException, TException { 
99
		InventoryClient inventoryServiceClient = new InventoryClient();
100
		return inventoryServiceClient.getClient().getWarehouseName(Long.valueOf(warehouseId));
101
	}
102
 
103
	public AmazonInventorySnapshot getInventoryForAmazonItem(String itemId) throws NumberFormatException, TException {
104
		InventoryClient inventoryServiceClient = new InventoryClient();
105
		return inventoryServiceClient.getClient().getAmazonInventoryForItem(Long.valueOf(itemId));
106
	}
107
 
108
	public String edit() {
109
		return "edit";
110
	}
111
 
112
	public String show() {
113
		return "show";
114
	}
115
 
116
	public String editNew() {
117
		return "editNew";
118
	}
119
 
120
 
121
 
122
	public void setId(String id) {
123
		this.id = id;
124
	}
125
 
126
	public void setUrl(String url) {
127
		this.url = url;
128
	}
129
 
130
	public String getUrl() {
131
		return url;
132
	}
133
 
134
	public String getId() {
135
		return id;
136
	}
137
 
138
	public void setItemId(String itemId) {
139
		this.itemId = itemId;
140
	}
141
 
142
	public String getItemId() {
143
		return itemId;
144
	}
145
 
146
	public void setIsFba(String isFba) {
147
		this.isFba = isFba;
148
	}
149
 
150
	public String getIsFba() {
151
		return isFba;
152
	}
153
 
154
	public void setIsNonFba(String isNonFba) {
155
		this.isNonFba = isNonFba;
156
	}
157
 
158
	public String getIsNonFba() {
159
		return isNonFba;
160
	}
161
 
162
	public void setIsInventoryOverride(String isInventoryOverride) {
163
		this.isInventoryOverride = isInventoryOverride;
164
	}
165
 
166
	public String getIsInventoryOverride() {
167
		return isInventoryOverride;
168
	}
169
 
170
	public void setSellingPrice(String sellingPrice) {
171
		this.sellingPrice = sellingPrice;
172
	}
173
 
174
	public String getSellingPrice() {
175
		return sellingPrice;
176
	}
177
 
178
	public void setFbaPrice(String fbaPrice) {
179
		this.fbaPrice = fbaPrice;
180
	}
181
 
182
	public String getFbaPrice() {
183
		return fbaPrice;
184
	}
185
 
186
	public void setSaholicPrice(String saholicPrice) {
187
		this.saholicPrice = saholicPrice;
188
	}
189
 
190
	public String getSaholicPrice() {
191
		return saholicPrice;
192
	}
193
 
194
	@Override
195
	public void setServletRequest(HttpServletRequest request) {
196
		this.request = request;
197
 
198
	}
199
 
200
	public static void main(String[] args) throws NumberFormatException, InventoryServiceException, TException {
201
		AmazonListController call = new AmazonListController();
202
		//System.out.println(call.getItemReservedInventory("5"));
203
	}
204
}