Subversion Repositories SmartDukaan

Rev

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

Rev 10195 Rev 11672
Line 5... Line 5...
5
 
5
 
6
 
6
 
7
import in.shop2020.datalogger.EventType;
7
import in.shop2020.datalogger.EventType;
8
import in.shop2020.logistics.DeliveryType;
8
import in.shop2020.logistics.DeliveryType;
9
import in.shop2020.logistics.ItemText;
9
import in.shop2020.logistics.ItemText;
-
 
10
import in.shop2020.logistics.LogisticsInfo;
10
import in.shop2020.logistics.LogisticsService;
11
import in.shop2020.logistics.LogisticsService;
-
 
12
import in.shop2020.logistics.LogisticsServiceException;
11
import in.shop2020.model.v1.catalog.Item;
13
import in.shop2020.model.v1.catalog.Item;
12
import in.shop2020.model.v1.user.UserContextService.Client;
14
import in.shop2020.model.v1.user.UserContextService.Client;
13
import in.shop2020.serving.cache.EhcacheWrapper;
15
import in.shop2020.serving.cache.EhcacheWrapper;
14
import in.shop2020.serving.services.ContentServingService;
16
import in.shop2020.serving.services.ContentServingService;
15
import in.shop2020.serving.utils.SnippetType;
17
import in.shop2020.serving.utils.SnippetType;
Line 17... Line 19...
17
import in.shop2020.thrift.clients.LogisticsClient;
19
import in.shop2020.thrift.clients.LogisticsClient;
18
import in.shop2020.thrift.clients.UserClient;
20
import in.shop2020.thrift.clients.UserClient;
19
import in.shop2020.utils.DataLogger;
21
import in.shop2020.utils.DataLogger;
20
 
22
 
21
import java.io.IOException;
23
import java.io.IOException;
-
 
24
import java.text.SimpleDateFormat;
22
import java.util.ArrayList;
25
import java.util.ArrayList;
-
 
26
import java.util.Calendar;
-
 
27
import java.util.GregorianCalendar;
23
import java.util.HashMap;
28
import java.util.HashMap;
24
import java.util.List;
29
import java.util.List;
25
import java.util.Map;
30
import java.util.Map;
26
 
31
 
27
import net.sf.ehcache.CacheManager;
32
import net.sf.ehcache.CacheManager;
Line 30... Line 35...
30
import org.apache.log4j.Logger;
35
import org.apache.log4j.Logger;
31
import org.apache.struts2.convention.annotation.Action;
36
import org.apache.struts2.convention.annotation.Action;
32
import org.apache.struts2.convention.annotation.Actions;
37
import org.apache.struts2.convention.annotation.Actions;
33
import org.apache.struts2.convention.annotation.Result;
38
import org.apache.struts2.convention.annotation.Result;
34
import org.apache.struts2.convention.annotation.Results;
39
import org.apache.struts2.convention.annotation.Results;
-
 
40
import org.apache.thrift.TException;
35
import org.json.JSONException;
41
import org.json.JSONException;
36
import org.json.JSONObject;
42
import org.json.JSONObject;
37
 
43
 
38
import com.google.gson.Gson;
44
import com.google.gson.Gson;
39
 
45
 
Line 49... Line 55...
49
})
55
})
50
public class EntityController extends BaseController {
56
public class EntityController extends BaseController {
51
		
57
		
52
	private static final long serialVersionUID = 1L;
58
	private static final long serialVersionUID = 1L;
53
	private static Logger log = Logger.getLogger(Class.class);
59
	private static Logger log = Logger.getLogger(Class.class);
54
	
-
 
-
 
60
	private Long firstItem =  0l;
55
	private static final String PRODUCT_PROERTIES_SNIPPET_KEY = "PRODUCT_PROPERTIES";
61
	private static final String PRODUCT_PROERTIES_SNIPPET_KEY = "PRODUCT_PROPERTIES";
56
	private static final String PRODUCT_SUMMARY_SNIPPET_KEY = "PRODUCT_SUMMARY";
62
	private static final String PRODUCT_SUMMARY_SNIPPET_KEY = "PRODUCT_SUMMARY";
57
	private static final String PRODUCT_SLIDEGUIDE_KEY = "SLIDEGUIDE";
63
	private static final String PRODUCT_SLIDEGUIDE_KEY = "SLIDEGUIDE";
58
    
-
 
-
 
64
    private String entityLogisticsEstimation = "[]";
59
	private static final String DEFAULT_PINCODE = "110001";
65
	private static final String DEFAULT_PINCODE = "110001";
60
	private String id;
66
	private String id;
61
	private String redirectUrl;
67
	private String redirectUrl;
62
	private long productId;
68
	private long productId;
63
	private boolean isMobile = false;
69
	private boolean isMobile = false;
64
	
70
	
65
	private Map<String, Double> discounts = new HashMap<String, Double>();
71
	private Map<String, Double> discounts = new HashMap<String, Double>();
66
	private Map<String, String> snippets;
72
	private Map<String, String> snippets;
67
	private static Map<Long, String> label = new HashMap<Long, String>();
73
	private static Map<Long, String> label = new HashMap<Long, String>();
-
 
74
	
-
 
75
	public static Map<Integer, String> businessDayToActualDateMap = new HashMap<Integer, String>();
-
 
76
	private Map<String, String> deliveryEstimate = new HashMap<String, String>();
-
 
77
	
68
	static{
78
	static{
69
		setRetargettingLabel();
79
		setRetargettingLabel();
70
	}
80
	}
71
	
81
	
72
	public EntityController(){
82
	public EntityController(){
Line 169... Line 179...
169
		
179
		
170
		} catch (Exception e) {
180
		} catch (Exception e) {
171
			log.warn("Unable to update the browsing history because of: ", e);
181
			log.warn("Unable to update the browsing history because of: ", e);
172
		}
182
		}
173
		
183
		
174
		DataLogger.logData(EventType.PRODUCT_VIEW, getSessionId(), userinfo.getUserId(), userinfo.getEmail(),
184
		DataLogger.logData(EventType.PRODUCT_VIEW, getSessionId(), userinfo.getUserId(), userinfo.getEmail(), userinfo.getPincode(), 
175
                productName, Long.toString(productId), StringUtils.substring(request.getHeader("referer"), 0, 500));
185
                productName, Long.toString(productId), StringUtils.substring(request.getHeader("referer"), 0, 500));			       
-
 
186
        
-
 
187
        try {
-
 
188
            CatalogClient catalogClientService = new CatalogClient();
-
 
189
            in.shop2020.model.v1.catalog.CatalogService.Client client = catalogClientService.getClient();
-
 
190
            
-
 
191
            getEntityLogisticsEstimation();
-
 
192
            getDeliveryEstimate( firstItem, userinfo.getPincode());
-
 
193
        } catch (Exception e1) {
-
 
194
            log.warn("Unable to get delivery estimates for "+ id);
-
 
195
        }
176
		return "show";
196
		return "show";
177
    }
197
    }
-
 
198
	
-
 
199
	/**
-
 
200
	 * 
-
 
201
	 * @return
-
 
202
	 */
-
 
203
	public void getDeliveryEstimate(Long itemId, String pincode){
-
 
204
		LogisticsClient logisticsServiceClient = null;
-
 
205
		String days = "-1";
-
 
206
		long businessDays = -1;
-
 
207
		boolean isCODAvailable=false;
-
 
208
		boolean isOTGAvailable=false;
-
 
209
		String codDays = "-1";
-
 
210
    	try {
-
 
211
			logisticsServiceClient = new LogisticsClient();
-
 
212
			LogisticsService.Client logisticsClient = logisticsServiceClient.getClient();
-
 
213
			LogisticsInfo logistincInfo = logisticsClient.getLogisticsEstimation(itemId, pincode, DeliveryType.PREPAID);
-
 
214
			
-
 
215
			if(logistincInfo.getDeliveryTime()!=-1L){
-
 
216
				days = getDeliveryDateString((int)logistincInfo.getDeliveryTime(), DeliveryType.PREPAID);
-
 
217
				if(logistincInfo.isCodAllowed()){
-
 
218
					codDays = getDeliveryDateString((int)(logistincInfo.getDeliveryTime()), DeliveryType.COD);
-
 
219
				}
-
 
220
			}
-
 
221
			businessDays = logistincInfo.getDeliveryTime();
-
 
222
			isCODAvailable = logistincInfo.isCodAllowed();
-
 
223
			isOTGAvailable = logistincInfo.isOtgAvailable();
-
 
224
			
-
 
225
			log.info("busines days = " + businessDays + "is COD avaialbale " + isCODAvailable + "is OTG available " + isOTGAvailable + " days "+days+" cod days "+codDays);
-
 
226
    	} catch (LogisticsServiceException e)	{
-
 
227
    		log.error("Unable to get estimate/COD availability for " + itemId, e);
-
 
228
		} catch(TException e)	{
-
 
229
			
-
 
230
		} catch (Exception e)	{
-
 
231
    		
-
 
232
		}
-
 
233
		deliveryEstimate.put("delivery_estimate", days);
-
 
234
		deliveryEstimate.put("cod_delivery_estimate", codDays);
-
 
235
		deliveryEstimate.put("is_cod_available_for_location", Boolean.toString(isCODAvailable));
-
 
236
		deliveryEstimate.put("on_time_guarantee", Boolean.toString(isOTGAvailable));
-
 
237
		deliveryEstimate.put("business_days", businessDays + "");        	
-
 
238
	}
-
 
239
	
-
 
240
	private  static String getDeliveryDateString(int days, DeliveryType type) throws TException {
-
 
241
    	Calendar now = new GregorianCalendar();
-
 
242
    	int hour = now.get(Calendar.HOUR_OF_DAY);
-
 
243
    	if(type == DeliveryType.COD && hour < 15){
-
 
244
			days = days + 1;
-
 
245
		}
-
 
246
    	if(businessDayToActualDateMap.containsKey(days)){
-
 
247
    		if(hour != 0){	
-
 
248
    			return businessDayToActualDateMap.get(days);
-
 
249
    		}
-
 
250
    		businessDayToActualDateMap.clear();
-
 
251
		}
-
 
252
    	
-
 
253
    	now.set(now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
-
 
254
    
-
 
255
    	LogisticsClient logisticsServiceClient = null;
-
 
256
		logisticsServiceClient = new LogisticsClient();
-
 
257
		LogisticsService.Client logisticsClient = logisticsServiceClient.getClient();
-
 
258
		
-
 
259
    	int newdays = (int) logisticsClient.adjustDeliveryDays(now.getTimeInMillis(), days);
-
 
260
    	now.add(Calendar.DAY_OF_MONTH, newdays);
-
 
261
    	
-
 
262
    	SimpleDateFormat dateformat = new SimpleDateFormat("EEE dd-MMM-yy");
-
 
263
    	if(newdays == 1){
-
 
264
    		businessDayToActualDateMap.put(days, "Tomorrow, " + dateformat.format(now.getTime()));
-
 
265
    	}else{
-
 
266
    		businessDayToActualDateMap.put(days, dateformat.format(now.getTime()));
-
 
267
    	}
-
 
268
    	return businessDayToActualDateMap.get(days);
-
 
269
	}
178
 
270
 
179
    /**
271
    /**
180
     * 
272
     * 
181
     * @param id
273
     * @param id
182
     */
274
     */
Line 293... Line 385...
293
    
385
    
294
    public Map<String, Double> getDiscounts()	{
386
    public Map<String, Double> getDiscounts()	{
295
    	return discounts;
387
    	return discounts;
296
    }
388
    }
297
    
389
    
298
    public String getEntityLogisticsEstimation(){
390
    public void setEntityLogisticsEstimation(){
299
    	List<ItemText> itemTexts = null; 
391
    	List<ItemText> itemTexts = null; 
300
    	try {
392
    	try {
301
    		LogisticsClient cl = new LogisticsClient();
393
    		LogisticsClient cl = new LogisticsClient();
302
            LogisticsService.Client client = cl.getClient();
394
            LogisticsService.Client client = cl.getClient();
303
            itemTexts = client.getEntityLogisticsEstimation(productId, DEFAULT_PINCODE, DeliveryType.PREPAID );
395
            itemTexts = client.getEntityLogisticsEstimation(productId, DEFAULT_PINCODE, DeliveryType.PREPAID );
304
            if(itemTexts!=null){
396
            if(itemTexts!=null){
305
            	List<Long> items = new ArrayList<Long>();
397
            	List<Long> items = new ArrayList<Long>();
306
            	for(ItemText itemText : itemTexts) {
398
            	for(ItemText itemText : itemTexts) {
307
            		items.add(itemText.getItemId());
399
            		items.add(itemText.getItemId());
308
            	}
400
            	}
-
 
401
            	firstItem = items.get(0);
309
            	return new Gson().toJson(items);
402
            	entityLogisticsEstimation = new Gson().toJson(items);
-
 
403
            	return;
310
            }
404
            }
311
        } catch (Exception e1) {
405
        } catch (Exception e1) {
312
            log.error("Unable to get items for productId: "+  productId, e1);
406
            log.error("Unable to get items for productId: "+  productId, e1);
313
        }
407
        }
314
        return "[]";
408
        entityLogisticsEstimation = "[]";
315
        
409
        
316
    }
410
    }
317
    
411
    
-
 
412
    public String getEntityLogisticsEstimation() {
-
 
413
    	return entityLogisticsEstimation;
-
 
414
    }
-
 
415
    
318
    private static void setRetargettingLabel() {
416
    private static void setRetargettingLabel() {
319
    	label.put((long) 1002160, "6EIBCKjf1wMQ6Pua0wM"); //Samsung Galaxy Y S5360
417
    	label.put((long) 1002160, "6EIBCKjf1wMQ6Pua0wM"); //Samsung Galaxy Y S5360
320
    	label.put((long) 1002106, "JFGVCKCt8gMQ6Pua0wM"); //Sony Ericsson Xperia Neo V MT11i
418
    	label.put((long) 1002106, "JFGVCKCt8gMQ6Pua0wM"); //Sony Ericsson Xperia Neo V MT11i
321
    	label.put((long) 1003230, "ArAYCJiu8gMQ6Pua0wM"); //Micromax Funbook Tab P300
419
    	label.put((long) 1003230, "ArAYCJiu8gMQ6Pua0wM"); //Micromax Funbook Tab P300
322
    	label.put((long) 1002151, "j0c_CJCv8gMQ6Pua0wM"); //HTC Explorer (Pico) A310e
420
    	label.put((long) 1002151, "j0c_CJCv8gMQ6Pua0wM"); //HTC Explorer (Pico) A310e
Line 334... Line 432...
334
 
432
 
335
    public String getEmiObject(){
433
    public String getEmiObject(){
336
    	return ProceedToPayController.getEmiSchemesInJSON();
434
    	return ProceedToPayController.getEmiSchemesInJSON();
337
    }
435
    }
338
 
436
 
-
 
437
    public String getDeliveryEstimate() {
-
 
438
    	return new Gson().toJson(this.deliveryEstimate);
-
 
439
    }
339
}
440
}
340
441