Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
507 rajveer 1
package in.shop2020.serving.controllers;
2
 
3
import in.shop2020.logistics.LogisticsService.Client;
4
import in.shop2020.logistics.ShipmentStatusInfo;
5
import in.shop2020.logistics.ShipmentUpdate;
6
import in.shop2020.model.v1.user.Address;
7
import in.shop2020.serving.pages.PageContentKeys;
8
import in.shop2020.serving.pages.PageEnum;
9
import in.shop2020.serving.pages.PageManager;
10
import in.shop2020.serving.utils.Utils;
11
import in.shop2020.thrift.clients.LogisticsServiceClient;
12
 
13
import java.io.UnsupportedEncodingException;
14
import java.util.HashMap;
15
import java.util.List;
16
import java.util.Map;
17
import java.util.StringTokenizer;
18
 
19
import org.apache.juli.logging.Log;
20
import org.apache.juli.logging.LogFactory;
21
import org.apache.struts2.rest.DefaultHttpHeaders;
22
import org.apache.struts2.rest.HttpHeaders;
23
 
24
public class ShipmentController extends BaseController{
25
 
26
	/**
27
	 * 
28
	 */
29
	private static Log log = LogFactory.getLog(ShipmentController.class);
30
 
31
 
32
 
33
	//id is in format xyz where xyz is abc is entityid
34
	private String id;
35
 
36
	//private String customer_id;
37
 
38
	private String entity_id;
39
	private String htmlSnippet;
40
    // GET /test
41
    public HttpHeaders index() throws UnsupportedEncodingException {
42
    	log.info("this.request=" + this.request);
43
 
44
        return new DefaultHttpHeaders("show")
45
            .disableCaching();
46
    }
47
 
48
 
49
	//Handle /myresearch/{id}
50
	public HttpHeaders create(){
51
		log.info("list of item ids is " + this.request.getParameter("productid"));
52
		String itemIds = this.request.getParameter("productid");
53
		if(itemIds == null){
54
			itemIds = "1000008_1000005";
55
		}
56
    	//log.info("list of item ids is " + this.request.getParameter("productid"));
57
    	//String itemIds = this.reqparams.get("productid")[0];
58
 
59
 
60
		//getFields();
61
		if(userinfo.isLoggedIn()){
62
			Map<PageContentKeys, String> params = new HashMap<PageContentKeys, String>();
63
			params.put(PageContentKeys.ENTITY_ID, itemIds);
64
			params.put(PageContentKeys.CUSTOMER_ID, userinfo.getUserId()+"");
65
			htmlSnippet = PageManager.getPageManager().getPageContents(PageEnum.MY_RESEARCH_PAGE, params).get("HTML");
66
		}else{
67
			htmlSnippet = "0";
68
		}
69
		//return new DefaultHttpHeaders("index").disableCaching();
70
		return new DefaultHttpHeaders("success");
71
	}
72
 
73
	public HttpHeaders destroy(){
74
		log.info("list of item ids is " + this.request.getParameter("productid"));
75
		String itemIds = this.request.getParameter("productid");
76
		if(itemIds == null){
77
			itemIds = "1000008_1000005";
78
		}
79
		long itemId = 0;
80
		StringTokenizer tokenizer = new StringTokenizer(itemIds,"_");
81
		while(tokenizer.hasMoreTokens()){
82
			itemId = Long.parseLong(tokenizer.nextToken());
83
			Utils.deleteFromMyResearch(userinfo.getUserId(), itemId);	
84
		}
85
		return new DefaultHttpHeaders("success");
86
	}
87
 
88
	public String getHtmlSnippet(){
89
		if(htmlSnippet.compareTo("")==0){
90
			htmlSnippet = "1";
91
		}
92
		return htmlSnippet;
93
	}
94
 
95
	public Address  getAddress(){
96
		Address address = null;
97
		return address;
98
	}
99
 
100
	public List<ShipmentUpdate> getUpdates(){
101
		List<ShipmentUpdate> updates = null;
102
		try {
103
			LogisticsServiceClient logisticsServiceClient = new LogisticsServiceClient();
104
			Client logisticsClient = logisticsServiceClient.getClient();
105
			updates = logisticsClient.getShipmentInfo(this.id).getUpdates();
106
		} catch (Exception e) {
107
			// TODO Auto-generated catch block
108
			e.printStackTrace();
109
		}
110
		return updates;
111
	}
112
 
113
 
114
    /**
115
     * 
116
     * @param id
117
     */
118
    public void setId(String id) {
119
        this.id = id;
120
    }
121
 
122
}