| 650 |
rajveer |
1 |
package in.shop2020.serving.controllers;
|
|
|
2 |
|
| 762 |
rajveer |
3 |
import in.shop2020.model.v1.user.WidgetException;
|
| 651 |
rajveer |
4 |
import in.shop2020.model.v1.user.UserContextService.Client;
|
|
|
5 |
import in.shop2020.serving.utils.FileUtils;
|
| 650 |
rajveer |
6 |
import in.shop2020.serving.utils.Utils;
|
| 651 |
rajveer |
7 |
import in.shop2020.thrift.clients.UserContextServiceClient;
|
| 650 |
rajveer |
8 |
|
| 651 |
rajveer |
9 |
import java.io.File;
|
| 650 |
rajveer |
10 |
import java.util.StringTokenizer;
|
|
|
11 |
|
|
|
12 |
import org.apache.juli.logging.Log;
|
|
|
13 |
import org.apache.juli.logging.LogFactory;
|
| 762 |
rajveer |
14 |
import org.apache.thrift.TException;
|
| 650 |
rajveer |
15 |
|
|
|
16 |
public class MyresearchController extends BaseController{
|
| 651 |
rajveer |
17 |
|
|
|
18 |
private UserContextServiceClient userServiceClient = null;
|
|
|
19 |
private Client client;
|
| 650 |
rajveer |
20 |
|
| 651 |
rajveer |
21 |
public MyresearchController(){
|
|
|
22 |
super();
|
|
|
23 |
try {
|
|
|
24 |
userServiceClient = new UserContextServiceClient();
|
|
|
25 |
} catch (Exception e) {
|
|
|
26 |
e.printStackTrace();
|
|
|
27 |
}
|
|
|
28 |
client = userServiceClient.getClient();
|
|
|
29 |
}
|
|
|
30 |
|
|
|
31 |
|
| 650 |
rajveer |
32 |
private static Log log = LogFactory.getLog(MyresearchController.class);
|
|
|
33 |
|
|
|
34 |
private String htmlSnippet = null;
|
| 651 |
rajveer |
35 |
|
| 650 |
rajveer |
36 |
//Handle /myresearch/{id}
|
| 651 |
rajveer |
37 |
public String create() throws Exception{
|
| 650 |
rajveer |
38 |
log.info("list of item ids is " + this.request.getParameter("productid"));
|
|
|
39 |
String itemIds = this.request.getParameter("productid");
|
| 651 |
rajveer |
40 |
if(userinfo.isLoggedIn()){
|
|
|
41 |
StringTokenizer tokenizer = new StringTokenizer(itemIds,"_");
|
|
|
42 |
while(tokenizer.hasMoreTokens()){
|
|
|
43 |
long entity_id = Long.parseLong(tokenizer.nextToken());
|
|
|
44 |
boolean isNew = client.updateMyResearch(userinfo.getUserId(), entity_id);
|
|
|
45 |
if(isNew){
|
|
|
46 |
htmlSnippet = htmlSnippet + FileUtils.read( Utils.EXPORT_ENTITIES_PATH + entity_id + File.separator +"WidgetSnippet.html");
|
|
|
47 |
}
|
|
|
48 |
}
|
| 650 |
rajveer |
49 |
}
|
|
|
50 |
|
| 651 |
rajveer |
51 |
return "success";
|
| 650 |
rajveer |
52 |
}
|
|
|
53 |
|
| 651 |
rajveer |
54 |
public String destroy(){
|
| 650 |
rajveer |
55 |
log.info("list of item ids is " + this.request.getParameter("productid"));
|
|
|
56 |
String itemIds = this.request.getParameter("productid");
|
|
|
57 |
if(itemIds == null){
|
| 651 |
rajveer |
58 |
return "failure";
|
| 650 |
rajveer |
59 |
}
|
|
|
60 |
long itemId = 0;
|
|
|
61 |
StringTokenizer tokenizer = new StringTokenizer(itemIds,"_");
|
|
|
62 |
while(tokenizer.hasMoreTokens()){
|
|
|
63 |
itemId = Long.parseLong(tokenizer.nextToken());
|
| 762 |
rajveer |
64 |
deleteFromMyResearch(userinfo.getUserId(), itemId);
|
| 650 |
rajveer |
65 |
}
|
| 651 |
rajveer |
66 |
return "success";
|
| 650 |
rajveer |
67 |
}
|
|
|
68 |
|
| 762 |
rajveer |
69 |
private void deleteFromMyResearch(long userId, long itemId) {
|
|
|
70 |
|
|
|
71 |
try {
|
|
|
72 |
UserContextServiceClient userServiceClient = new UserContextServiceClient();
|
|
|
73 |
in.shop2020.model.v1.user.UserContextService.Client userClient = userServiceClient.getClient();
|
|
|
74 |
userClient.deleteItemFromMyResearch(userId, itemId);
|
|
|
75 |
} catch (WidgetException e) {
|
|
|
76 |
e.printStackTrace();
|
|
|
77 |
} catch (TException e) {
|
|
|
78 |
e.printStackTrace();
|
|
|
79 |
} catch (Exception e) {
|
|
|
80 |
e.printStackTrace();
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
}
|
| 650 |
rajveer |
84 |
public String getHtmlSnippet(){
|
|
|
85 |
if(htmlSnippet == null){
|
|
|
86 |
htmlSnippet = "1";
|
|
|
87 |
}
|
|
|
88 |
return htmlSnippet;
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
}
|