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