Subversion Repositories SmartDukaan

Rev

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

Rev 1372 Rev 1614
Line 1... Line 1...
1
package in.shop2020.serving.controllers;
1
package in.shop2020.serving.controllers;
2
 
2
 
-
 
3
import in.shop2020.model.v1.user.UserContextService;
-
 
4
import in.shop2020.model.v1.user.WidgetException;
-
 
5
import in.shop2020.serving.utils.FileUtils;
-
 
6
import in.shop2020.serving.utils.Utils;
-
 
7
import in.shop2020.thrift.clients.UserContextServiceClient;
-
 
8
 
-
 
9
import java.io.File;
-
 
10
import java.io.IOException;
-
 
11
import java.util.ArrayList;
-
 
12
import java.util.HashMap;
-
 
13
import java.util.List;
-
 
14
import java.util.Map;
-
 
15
import java.util.StringTokenizer;
-
 
16
 
-
 
17
import org.apache.log4j.Logger;
-
 
18
import org.apache.struts2.convention.annotation.Action;
-
 
19
import org.apache.struts2.convention.annotation.InterceptorRef;
-
 
20
import org.apache.thrift.TException;
-
 
21
 
3
public class BrowseHistoryController extends BaseController{
22
public class BrowseHistoryController extends BaseController{
4
 
23
 
-
 
24
	private static Logger log = Logger.getLogger(Class.class);
5
	private static final long serialVersionUID = -5508838941749125824L;
25
	private static final long serialVersionUID = -5508838941749125824L;
6
 
-
 
-
 
26
	private String id;
-
 
27
	private String snippets="";
-
 
28
	private List<String> items;
7
	public String index() {
29
	public String index() {
8
		return "index";
30
		return "index";
-
 
31
	}
-
 
32
	
-
 
33
	//browse-hostory/a_b_c
-
 
34
	public String show() {
-
 
35
		return "show";
-
 
36
	}
-
 
37
 
-
 
38
	//Handle /browse-history/{id}
-
 
39
	public String create(){
-
 
40
		log.info("list of item ids is " + this.request.getParameter("historyitems"));
-
 
41
		if (this.request.getParameter("historyitems") != null) {
-
 
42
			String historyItems = this.request.getParameter("historyitems");
-
 
43
			updateHistory(historyItems);
-
 
44
		}
-
 
45
		return "success";
-
 
46
	}
-
 
47
 
-
 
48
    public String getSnippets() throws Exception {
-
 
49
    	if(items != null){
-
 
50
	    	for(String itemId: items){
-
 
51
				snippets = snippets + FileUtils.read( Utils.EXPORT_ENTITIES_PATH + itemId + File.separator +"WidgetSnippet.html");
-
 
52
			}
-
 
53
    	}
-
 
54
    	System.out.println(snippets);
-
 
55
		return snippets;
-
 
56
    }
-
 
57
 
-
 
58
    public void setId(String id) {
-
 
59
    	this.id = id;
-
 
60
    	items = new ArrayList<String>();
-
 
61
    	StringTokenizer tokenizer = new StringTokenizer(id,"-");
-
 
62
    	while(tokenizer.hasMoreTokens()){
-
 
63
    		this.items.add(tokenizer.nextToken());
-
 
64
    	}
-
 
65
    	System.out.println("items are: " + items);
-
 
66
    }
-
 
67
    
-
 
68
    public String getId() {
-
 
69
    	return this.id;
-
 
70
    }
-
 
71
 
-
 
72
    private void updateHistory(String historyItems) {
-
 
73
		UserContextServiceClient userServiceClient;
-
 
74
		try {
-
 
75
			userServiceClient = new UserContextServiceClient();
-
 
76
			UserContextService.Client userClient = userServiceClient.getClient();
-
 
77
			StringTokenizer tokenizer = new StringTokenizer(historyItems, "-");
-
 
78
		
-
 
79
			while (tokenizer.hasMoreTokens()) {
-
 
80
				long itemId = Long.parseLong(tokenizer.nextToken());
-
 
81
				userClient.updateBrowseHistory(userinfo.getUserId(), itemId);
-
 
82
			}	
-
 
83
		} catch (Exception e) {
-
 
84
			e.printStackTrace();
-
 
85
		}
9
	}	
86
	}
10
}
87
}
11
88