| 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 |
}
|
| 650 |
rajveer |
65 |
}
|
| 651 |
rajveer |
66 |
return "success";
|
| 650 |
rajveer |
67 |
}
|
|
|
68 |
|
| 1614 |
rajveer |
69 |
@Action(value="deletefromresearch",interceptorRefs={@InterceptorRef("createuser"),@InterceptorRef("myDefault")})
|
| 651 |
rajveer |
70 |
public String destroy(){
|
| 650 |
rajveer |
71 |
log.info("list of item ids is " + this.request.getParameter("productid"));
|
|
|
72 |
String itemIds = this.request.getParameter("productid");
|
|
|
73 |
if(itemIds == null){
|
| 651 |
rajveer |
74 |
return "failure";
|
| 650 |
rajveer |
75 |
}
|
|
|
76 |
long itemId = 0;
|
|
|
77 |
StringTokenizer tokenizer = new StringTokenizer(itemIds,"_");
|
|
|
78 |
while(tokenizer.hasMoreTokens()){
|
|
|
79 |
itemId = Long.parseLong(tokenizer.nextToken());
|
| 762 |
rajveer |
80 |
deleteFromMyResearch(userinfo.getUserId(), itemId);
|
| 650 |
rajveer |
81 |
}
|
| 651 |
rajveer |
82 |
return "success";
|
| 650 |
rajveer |
83 |
}
|
|
|
84 |
|
| 762 |
rajveer |
85 |
private void deleteFromMyResearch(long userId, long itemId) {
|
|
|
86 |
|
|
|
87 |
try {
|
|
|
88 |
UserContextServiceClient userServiceClient = new UserContextServiceClient();
|
|
|
89 |
in.shop2020.model.v1.user.UserContextService.Client userClient = userServiceClient.getClient();
|
|
|
90 |
userClient.deleteItemFromMyResearch(userId, itemId);
|
|
|
91 |
} catch (WidgetException e) {
|
|
|
92 |
e.printStackTrace();
|
|
|
93 |
} catch (TException e) {
|
|
|
94 |
e.printStackTrace();
|
|
|
95 |
} catch (Exception e) {
|
|
|
96 |
e.printStackTrace();
|
|
|
97 |
}
|
|
|
98 |
}
|
| 1033 |
varun.gupt |
99 |
|
| 1703 |
rajveer |
100 |
|
| 650 |
rajveer |
101 |
public String getHtmlSnippet(){
|
| 1032 |
varun.gupt |
102 |
if(htmlSnippet == "") {
|
| 1643 |
rajveer |
103 |
htmlSnippet = "0";
|
| 650 |
rajveer |
104 |
}
|
|
|
105 |
return htmlSnippet;
|
| 1032 |
varun.gupt |
106 |
}
|
|
|
107 |
}
|