Subversion Repositories SmartDukaan

Rev

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

Rev 7351 Rev 7382
Line 1... Line 1...
1
package in.shop2020.support.controllers;
1
package in.shop2020.support.controllers;
2
 
2
 
3
import java.util.ArrayList;
3
import java.util.ArrayList;
4
import java.util.Arrays;
4
import java.util.Arrays;
-
 
5
import java.util.Collection;
5
import java.util.List;
6
import java.util.List;
6
 
7
 
7
import in.shop2020.model.v1.catalog.CatalogServiceException;
8
import in.shop2020.model.v1.catalog.CatalogServiceException;
8
import in.shop2020.model.v1.catalog.Item;
9
import in.shop2020.model.v1.catalog.Item;
9
import in.shop2020.model.v1.catalog.StorePricing;
10
import in.shop2020.model.v1.catalog.StorePricing;
Line 20... Line 21...
20
import org.apache.struts2.interceptor.ServletRequestAware;
21
import org.apache.struts2.interceptor.ServletRequestAware;
21
import org.apache.struts2.interceptor.ServletResponseAware;
22
import org.apache.struts2.interceptor.ServletResponseAware;
22
import org.apache.thrift.TException;
23
import org.apache.thrift.TException;
23
import org.slf4j.Logger;
24
import org.slf4j.Logger;
24
import org.slf4j.LoggerFactory;
25
import org.slf4j.LoggerFactory;
-
 
26
import com.opensymphony.xwork2.ActionSupport;
25
 
27
 
26
 
28
 
27
@InterceptorRefs({
29
@InterceptorRefs({
28
    @InterceptorRef("defaultStack"),
30
    @InterceptorRef("defaultStack"),
29
    @InterceptorRef("login")
31
    @InterceptorRef("login")
30
})
32
})
31
@Results({
33
@Results({
32
    @Result(name="authfail", type="redirectAction", params = {"actionName" , "reports"})
34
    @Result(name="authfail", type="redirectAction", params = {"actionName" , "reports"})
33
})
35
})
34
public class StoreAdminController implements ServletRequestAware, ServletResponseAware {
36
public class StoreAdminController extends ActionSupport implements ServletRequestAware, ServletResponseAware {
35
 
37
 
-
 
38
	private static final long serialVersionUID = 1L;
36
	private static Logger logger = LoggerFactory.getLogger(StoreAdminController.class);
39
	private static Logger logger = LoggerFactory.getLogger(StoreAdminController.class);
37
	private HttpServletRequest request;
40
	private HttpServletRequest request;
38
	private HttpServletResponse response;
41
	private HttpServletResponse response;
39
	private String itemString;
42
	private String itemString;
40
	private String id;
43
	private String id;
Line 48... Line 51...
48
	
51
	
49
 
52
 
50
	private long freebieItemId;
53
	private long freebieItemId;
51
	private String bestDealText;
54
	private String bestDealText;
52
	private boolean activeonstore;
55
	private boolean activeonstore;
-
 
56
	private boolean allcolors;
53
	
57
	
54
	public String index()	{
58
	public String index()	{
55
		return "index";
59
		return "index";
56
	}
60
	}
57
	
61
	
Line 62... Line 66...
62
	public String create() {
66
	public String create() {
63
		StorePricing sp = new StorePricing(itemId, recommendedPrice, minPrice, maxPrice, minAdvancePrice, absoluteMinPrice, freebieItemId, bestDealText);
67
		StorePricing sp = new StorePricing(itemId, recommendedPrice, minPrice, maxPrice, minAdvancePrice, absoluteMinPrice, freebieItemId, bestDealText);
64
		try	{
68
		try	{
65
			CatalogClient csc = new CatalogClient();
69
			CatalogClient csc = new CatalogClient();
66
			in.shop2020.model.v1.catalog.CatalogService.Client catalogClient= csc.getClient();
70
			in.shop2020.model.v1.catalog.CatalogService.Client catalogClient= csc.getClient();
67
			catalogClient.updateStorePricing(sp);
71
			catalogClient.updateStorePricing(sp, allcolors);
68
			Item item = getItem(itemId);
72
			Item item = getItem(itemId);
69
			if(item.isActiveOnStore() != isActiveonstore()){
73
			if(item.isActiveOnStore() != isActiveonstore()){
70
				item.setActiveOnStore(isActiveonstore());
74
				item.setActiveOnStore(isActiveonstore());
71
				catalogClient.updateItem(item);
75
				catalogClient.updateItem(item);
72
			}
76
			}
-
 
77
			addActionError("Pricing successfully updated");
73
		} catch (TException e) {
78
		} catch (TException e) {
74
			logger.error("", e);
79
			logger.error("", e);
75
		} catch (CatalogServiceException e) {
80
		} catch (CatalogServiceException e) {
76
			// TODO Auto-generated catch block
-
 
77
			e.printStackTrace();
81
			e.printStackTrace();
-
 
82
			addActionError("Unable to update pricing because: " + e.getMessage());
78
		}
83
		}
-
 
84
		setId(Long.toString(itemId));
79
		return "index";
85
		return "index";
80
	}
86
	}
81
	
87
	
-
 
88
	public Collection<String> getMessages(){
-
 
89
		return getActionErrors();
-
 
90
	}
-
 
91
 
82
	public List<Item> searchItem(){
92
	public List<Item> searchItem(){
83
		List<Item> items = null;
93
		List<Item> items = null;
84
		if(itemString != null){
94
		if(itemString != null){
85
			try{
95
			try{
86
				CatalogClient csc = new CatalogClient();
96
				CatalogClient csc = new CatalogClient();
Line 88... Line 98...
88
				List<String> searchTerms = Arrays.asList(itemString.split(" "));
98
				List<String> searchTerms = Arrays.asList(itemString.split(" "));
89
				items = catalogClient.searchItemsInRange(searchTerms, 0, 50);
99
				items = catalogClient.searchItemsInRange(searchTerms, 0, 50);
90
			}catch (Exception e) {
100
			}catch (Exception e) {
91
				logger.error("", e);
101
				logger.error("", e);
92
			}
102
			}
-
 
103
		}else if(id == null)
-
 
104
			{
-
 
105
				try{
-
 
106
					CatalogClient csc = new CatalogClient();
-
 
107
					in.shop2020.model.v1.catalog.CatalogService.Client catalogClient= csc.getClient();
-
 
108
					items = catalogClient.getLatestArrivals();
-
 
109
				}catch (Exception e) {
-
 
110
					logger.error("", e);
-
 
111
				}
93
		}
112
			}
94
		return items;
113
		return items;
95
	}
114
	}
96
	
115
	
97
 
116
 
98
	public StorePricing getStorePricing(){
117
	public StorePricing getStorePricing(){
Line 155... Line 174...
155
		
174
		
156
	public String getProductNameFromItem(Item item)	{
175
	public String getProductNameFromItem(Item item)	{
157
		return ModelUtils.extractProductNameFromItem(item);
176
		return ModelUtils.extractProductNameFromItem(item);
158
	}
177
	}
159
	
178
	
-
 
179
	public String getItemString(){
-
 
180
		return this.itemString;	
-
 
181
	}
-
 
182
	
160
	public void setItemString(String itemString){
183
	public void setItemString(String itemString){
161
		this.itemString = itemString;
184
		this.itemString = itemString;
162
	}
185
	}
163
	
186
	
164
	public void setId(String id){
187
	public void setId(String id){
165
 		this.id = id;
188
 		this.id = id;
166
	}
189
	}
167
 
190
 
-
 
191
	public String getId(){
-
 
192
 		return this.id;
-
 
193
	}
-
 
194
	
168
	public void setItemId(long itemId) {
195
	public void setItemId(long itemId) {
169
		this.itemId = itemId;
196
		this.itemId = itemId;
170
	}
197
	}
171
 
198
 
172
	public long getItemId() {
199
	public long getItemId() {
Line 238... Line 265...
238
	}
265
	}
239
 
266
 
240
	public void setAbsoluteMinPrice(double absoluteMinPrice) {
267
	public void setAbsoluteMinPrice(double absoluteMinPrice) {
241
		this.absoluteMinPrice = absoluteMinPrice;
268
		this.absoluteMinPrice = absoluteMinPrice;
242
	}
269
	}
-
 
270
 
-
 
271
	public void setAllcolors(String allcolors) {
-
 
272
		if(allcolors.equals("on")){
-
 
273
			this.allcolors = true;
-
 
274
		}else{
-
 
275
			this.allcolors = false;
-
 
276
		}
-
 
277
	}
-
 
278
 
-
 
279
	public boolean isAllcolors() {
-
 
280
		return allcolors;
-
 
281
	}
243
	
282
	
244
}
283
}
245
284