| 1372 |
vikas |
1 |
package in.shop2020.serving.controllers;
|
|
|
2 |
|
| 1614 |
rajveer |
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 |
|
| 1372 |
vikas |
22 |
public class BrowseHistoryController extends BaseController{
|
|
|
23 |
|
| 1614 |
rajveer |
24 |
private static Logger log = Logger.getLogger(Class.class);
|
| 1372 |
vikas |
25 |
private static final long serialVersionUID = -5508838941749125824L;
|
| 1614 |
rajveer |
26 |
private String id;
|
|
|
27 |
private String snippets="";
|
|
|
28 |
private List<String> items;
|
| 1372 |
vikas |
29 |
public String index() {
|
|
|
30 |
return "index";
|
| 1614 |
rajveer |
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");
|
| 1623 |
rajveer |
43 |
if(userinfo.getUserId() != -1){
|
|
|
44 |
updateHistory(historyItems);
|
|
|
45 |
}
|
| 1614 |
rajveer |
46 |
}
|
|
|
47 |
return "success";
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
public String getSnippets() throws Exception {
|
|
|
51 |
if(items != null){
|
|
|
52 |
for(String itemId: items){
|
|
|
53 |
snippets = snippets + FileUtils.read( Utils.EXPORT_ENTITIES_PATH + itemId + File.separator +"WidgetSnippet.html");
|
|
|
54 |
}
|
|
|
55 |
}
|
|
|
56 |
System.out.println(snippets);
|
|
|
57 |
return snippets;
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
public void setId(String id) {
|
|
|
61 |
this.id = id;
|
|
|
62 |
items = new ArrayList<String>();
|
|
|
63 |
StringTokenizer tokenizer = new StringTokenizer(id,"-");
|
|
|
64 |
while(tokenizer.hasMoreTokens()){
|
|
|
65 |
this.items.add(tokenizer.nextToken());
|
|
|
66 |
}
|
|
|
67 |
System.out.println("items are: " + items);
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
public String getId() {
|
|
|
71 |
return this.id;
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
private void updateHistory(String historyItems) {
|
|
|
75 |
UserContextServiceClient userServiceClient;
|
|
|
76 |
try {
|
|
|
77 |
userServiceClient = new UserContextServiceClient();
|
|
|
78 |
UserContextService.Client userClient = userServiceClient.getClient();
|
|
|
79 |
StringTokenizer tokenizer = new StringTokenizer(historyItems, "-");
|
|
|
80 |
|
|
|
81 |
while (tokenizer.hasMoreTokens()) {
|
|
|
82 |
long itemId = Long.parseLong(tokenizer.nextToken());
|
|
|
83 |
userClient.updateBrowseHistory(userinfo.getUserId(), itemId);
|
|
|
84 |
}
|
|
|
85 |
} catch (Exception e) {
|
|
|
86 |
e.printStackTrace();
|
|
|
87 |
}
|
|
|
88 |
}
|
| 1372 |
vikas |
89 |
}
|