Subversion Repositories SmartDukaan

Rev

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

Rev 3126 Rev 3830
Line 1... Line 1...
1
/**
1
/**
2
 * 
2
 * 
3
 */
3
 */
4
package in.shop2020.serving.controllers;
4
package in.shop2020.serving.controllers;
5
 
5
 
-
 
6
import java.util.HashMap;
-
 
7
import java.util.Map;
6
import java.util.StringTokenizer;
8
import java.util.StringTokenizer;
7
 
9
 
8
import in.shop2020.logistics.LogisticsService.Client;
10
import in.shop2020.logistics.LogisticsService.Client;
9
import in.shop2020.logistics.LogisticsServiceException;
11
import in.shop2020.logistics.LogisticsServiceException;
10
import in.shop2020.thrift.clients.LogisticsClient;
12
import in.shop2020.thrift.clients.LogisticsClient;
Line 12... Line 14...
12
import org.apache.log4j.Logger;
14
import org.apache.log4j.Logger;
13
import org.apache.struts2.rest.DefaultHttpHeaders;
15
import org.apache.struts2.rest.DefaultHttpHeaders;
14
import org.apache.struts2.rest.HttpHeaders;
16
import org.apache.struts2.rest.HttpHeaders;
15
import org.apache.thrift.TException;
17
import org.apache.thrift.TException;
16
 
18
 
-
 
19
import com.google.gson.Gson;
-
 
20
 
17
/**
21
/**
18
 * @author rajveer
22
 * @author rajveer
19
 *
23
 *
20
 */
24
 */
21
public class EstimateController extends BaseController {
25
public class EstimateController extends BaseController {
Line 25... Line 29...
25
	private static Logger log = Logger.getLogger(Class.class);	
29
	private static Logger log = Logger.getLogger(Class.class);	
26
	private String id;
30
	private String id;
27
	private long itemId;
31
	private long itemId;
28
	private String pincode;
32
	private String pincode;
29
	private long days = -1;
33
	private long days = -1;
-
 
34
	private boolean isCODAvailable;
-
 
35
	private Map<String, String> response = new HashMap<String, String>();
-
 
36
	
30
	public EstimateController() {
37
	public EstimateController() {
31
		super();
38
		super();
32
	}
39
	}
33
    
40
    
34
    // GET /logout
41
    // GET /logout
Line 36... Line 43...
36
    	LogisticsClient logisticsServiceClient = null;
43
    	LogisticsClient logisticsServiceClient = null;
37
    	try {
44
    	try {
38
			logisticsServiceClient = new LogisticsClient();
45
			logisticsServiceClient = new LogisticsClient();
39
			Client logisticsClient = logisticsServiceClient.getClient();
46
			Client logisticsClient = logisticsServiceClient.getClient();
40
			days = logisticsClient.getLogisticsEstimation(itemId, pincode).getDeliveryTime();
47
			days = logisticsClient.getLogisticsEstimation(itemId, pincode).getDeliveryTime();
-
 
48
			isCODAvailable = logisticsClient.isCodAllowed(pincode);
41
			
49
			
42
    	}catch (LogisticsServiceException e) {
50
    	} catch (LogisticsServiceException e)	{
43
    		days = -1;
51
    		days = -1;
-
 
52
    		isCODAvailable = false;
44
    		log.error("Unable to get estimate for " + itemId, e);
53
    		log.error("Unable to get estimate/COD availability for " + itemId, e);
-
 
54
    		
45
		}catch(TException e){
55
		} catch(TException e)	{
46
			
56
			
47
		}
-
 
48
    	catch (Exception e) {
57
		} catch (Exception e)	{
49
    		
58
    		
50
		}
59
		}
-
 
60
		response.put("delivery_estimate", Long.toString(days));
-
 
61
		response.put("is_cod_available_for_location", Boolean.toString(isCODAvailable));
-
 
62
		
51
    	return new DefaultHttpHeaders("index");
63
    	return new DefaultHttpHeaders("index");
52
    }
64
    }
53
        
65
    
54
    /**
66
    /**
55
     * 
67
     * 
56
     * @param id
68
     * @param id
57
     */
69
     */
58
    public void setId(String id) {
70
    public void setId(String id) {
Line 60... Line 72...
60
        StringTokenizer tokenizer = new StringTokenizer(this.id, "_");
72
        StringTokenizer tokenizer = new StringTokenizer(this.id, "_");
61
        this.pincode = tokenizer.nextToken();
73
        this.pincode = tokenizer.nextToken();
62
        this.itemId = Long.parseLong(tokenizer.nextToken());
74
        this.itemId = Long.parseLong(tokenizer.nextToken());
63
    }
75
    }
64
 
76
 
65
    public long getEstimatedTime() {
77
    public String getResponseJSONString() {
-
 
78
    	Gson gson = new Gson();
66
    	return days;
79
    	return gson.toJson(response);
67
    }
80
    }
68
}
81
}
69
82