| 650 |
rajveer |
1 |
package in.shop2020.serving.controllers;
|
|
|
2 |
|
| 1614 |
rajveer |
3 |
import in.shop2020.model.v1.user.UserContextService;
|
| 762 |
rajveer |
4 |
import in.shop2020.model.v1.user.WidgetException;
|
| 651 |
rajveer |
5 |
import in.shop2020.model.v1.user.UserContextService.Client;
|
|
|
6 |
import in.shop2020.serving.utils.FileUtils;
|
| 650 |
rajveer |
7 |
import in.shop2020.serving.utils.Utils;
|
| 651 |
rajveer |
8 |
import in.shop2020.thrift.clients.UserContextServiceClient;
|
| 650 |
rajveer |
9 |
|
| 651 |
rajveer |
10 |
import java.io.File;
|
| 786 |
rajveer |
11 |
import java.io.IOException;
|
| 650 |
rajveer |
12 |
import java.util.StringTokenizer;
|
|
|
13 |
|
| 832 |
rajveer |
14 |
import org.apache.log4j.Logger;
|
| 1614 |
rajveer |
15 |
import org.apache.struts2.convention.annotation.Action;
|
|
|
16 |
import org.apache.struts2.convention.annotation.InterceptorRef;
|
|
|
17 |
import org.apache.struts2.convention.annotation.InterceptorRefs;
|
|
|
18 |
import org.apache.struts2.convention.annotation.Result;
|
|
|
19 |
import org.apache.struts2.convention.annotation.Results;
|
| 762 |
rajveer |
20 |
import org.apache.thrift.TException;
|
| 650 |
rajveer |
21 |
|
| 1614 |
rajveer |
22 |
@Results({
|
|
|
23 |
@Result(name="failure", location="myresearch-failure.vm"),
|
|
|
24 |
@Result(name="success", location="myresearch-success.vm")
|
|
|
25 |
})
|
| 650 |
rajveer |
26 |
public class MyresearchController extends BaseController{
|
| 651 |
rajveer |
27 |
|
|
|
28 |
private UserContextServiceClient userServiceClient = null;
|
|
|
29 |
private Client client;
|
| 650 |
rajveer |
30 |
|
| 651 |
rajveer |
31 |
public MyresearchController(){
|
|
|
32 |
super();
|
|
|
33 |
try {
|
|
|
34 |
userServiceClient = new UserContextServiceClient();
|
| 1386 |
vikas |
35 |
client = userServiceClient.getClient();
|
| 651 |
rajveer |
36 |
} catch (Exception e) {
|
|
|
37 |
e.printStackTrace();
|
|
|
38 |
}
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
|
| 832 |
rajveer |
42 |
private static Logger log = Logger.getLogger(Class.class);
|
| 650 |
rajveer |
43 |
|
| 815 |
rajveer |
44 |
private String htmlSnippet = "";
|
| 1372 |
vikas |
45 |
|
| 1614 |
rajveer |
46 |
@Action(value="myresearch",interceptorRefs={@InterceptorRef("myDefault")})
|
| 1372 |
vikas |
47 |
public String index() {
|
|
|
48 |
return "index";
|
|
|
49 |
}
|
|
|
50 |
|
| 650 |
rajveer |
51 |
//Handle /myresearch/{id}
|
| 1614 |
rajveer |
52 |
@Action(value="addtoresearch",interceptorRefs={@InterceptorRef("createuser"),@InterceptorRef("myDefault")})
|
| 786 |
rajveer |
53 |
public String create() throws WidgetException, TException, IOException {
|
| 650 |
rajveer |
54 |
log.info("list of item ids is " + this.request.getParameter("productid"));
|
|
|
55 |
String itemIds = this.request.getParameter("productid");
|
| 1614 |
rajveer |
56 |
if(userinfo.getUserId() != -1){
|
| 651 |
rajveer |
57 |
StringTokenizer tokenizer = new StringTokenizer(itemIds,"_");
|
|
|
58 |
while(tokenizer.hasMoreTokens()){
|
|
|
59 |
long entity_id = Long.parseLong(tokenizer.nextToken());
|
|
|
60 |
boolean isNew = client.updateMyResearch(userinfo.getUserId(), entity_id);
|
|
|
61 |
if(isNew){
|
|
|
62 |
htmlSnippet = htmlSnippet + FileUtils.read( Utils.EXPORT_ENTITIES_PATH + entity_id + File.separator +"WidgetSnippet.html");
|
|
|
63 |
}
|
|
|
64 |
}
|
| 1614 |
rajveer |
65 |
if (this.request.getParameter("historyitems") != null) {
|
|
|
66 |
String historyItems = this.request.getParameter("productid");
|
|
|
67 |
updateHistory(historyItems);
|
|
|
68 |
}
|
|
|
69 |
|
| 650 |
rajveer |
70 |
}
|
| 651 |
rajveer |
71 |
return "success";
|
| 650 |
rajveer |
72 |
}
|
|
|
73 |
|
| 1614 |
rajveer |
74 |
@Action(value="deletefromresearch",interceptorRefs={@InterceptorRef("createuser"),@InterceptorRef("myDefault")})
|
| 651 |
rajveer |
75 |
public String destroy(){
|
| 650 |
rajveer |
76 |
log.info("list of item ids is " + this.request.getParameter("productid"));
|
|
|
77 |
String itemIds = this.request.getParameter("productid");
|
|
|
78 |
if(itemIds == null){
|
| 651 |
rajveer |
79 |
return "failure";
|
| 650 |
rajveer |
80 |
}
|
|
|
81 |
long itemId = 0;
|
|
|
82 |
StringTokenizer tokenizer = new StringTokenizer(itemIds,"_");
|
|
|
83 |
while(tokenizer.hasMoreTokens()){
|
|
|
84 |
itemId = Long.parseLong(tokenizer.nextToken());
|
| 762 |
rajveer |
85 |
deleteFromMyResearch(userinfo.getUserId(), itemId);
|
| 650 |
rajveer |
86 |
}
|
| 651 |
rajveer |
87 |
return "success";
|
| 650 |
rajveer |
88 |
}
|
|
|
89 |
|
| 762 |
rajveer |
90 |
private void deleteFromMyResearch(long userId, long itemId) {
|
|
|
91 |
|
|
|
92 |
try {
|
|
|
93 |
UserContextServiceClient userServiceClient = new UserContextServiceClient();
|
|
|
94 |
in.shop2020.model.v1.user.UserContextService.Client userClient = userServiceClient.getClient();
|
|
|
95 |
userClient.deleteItemFromMyResearch(userId, itemId);
|
|
|
96 |
} catch (WidgetException e) {
|
|
|
97 |
e.printStackTrace();
|
|
|
98 |
} catch (TException e) {
|
|
|
99 |
e.printStackTrace();
|
|
|
100 |
} catch (Exception e) {
|
|
|
101 |
e.printStackTrace();
|
|
|
102 |
}
|
|
|
103 |
}
|
| 1033 |
varun.gupt |
104 |
|
| 1614 |
rajveer |
105 |
private void updateHistory(String historyItems) {
|
|
|
106 |
UserContextServiceClient userServiceClient;
|
|
|
107 |
try {
|
|
|
108 |
userServiceClient = new UserContextServiceClient();
|
|
|
109 |
UserContextService.Client userClient = userServiceClient.getClient();
|
|
|
110 |
StringTokenizer tokenizer = new StringTokenizer(historyItems, "_");
|
|
|
111 |
|
|
|
112 |
while (tokenizer.hasMoreTokens()) {
|
|
|
113 |
long itemId = Long.parseLong(tokenizer.nextToken());
|
|
|
114 |
userClient.updateBrowseHistory(userinfo.getUserId(), itemId);
|
|
|
115 |
}
|
|
|
116 |
} catch (Exception e) {
|
|
|
117 |
e.printStackTrace();
|
|
|
118 |
}
|
|
|
119 |
}
|
|
|
120 |
|
|
|
121 |
|
| 650 |
rajveer |
122 |
public String getHtmlSnippet(){
|
| 1032 |
varun.gupt |
123 |
if(htmlSnippet == "") {
|
| 1643 |
rajveer |
124 |
htmlSnippet = "0";
|
| 650 |
rajveer |
125 |
}
|
|
|
126 |
return htmlSnippet;
|
| 1032 |
varun.gupt |
127 |
}
|
|
|
128 |
}
|