Subversion Repositories SmartDukaan

Rev

Rev 1386 | Rev 1643 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1386 Rev 1614
Line 1... Line 1...
1
package in.shop2020.serving.controllers;
1
package in.shop2020.serving.controllers;
2
 
2
 
-
 
3
import in.shop2020.model.v1.user.UserContextService;
3
import in.shop2020.model.v1.user.WidgetException;
4
import in.shop2020.model.v1.user.WidgetException;
4
import in.shop2020.model.v1.user.UserContextService.Client;
5
import in.shop2020.model.v1.user.UserContextService.Client;
5
import in.shop2020.serving.utils.FileUtils;
6
import in.shop2020.serving.utils.FileUtils;
6
import in.shop2020.serving.utils.Utils;
7
import in.shop2020.serving.utils.Utils;
7
import in.shop2020.thrift.clients.UserContextServiceClient;
8
import in.shop2020.thrift.clients.UserContextServiceClient;
Line 9... Line 10...
9
import java.io.File;
10
import java.io.File;
10
import java.io.IOException;
11
import java.io.IOException;
11
import java.util.StringTokenizer;
12
import java.util.StringTokenizer;
12
 
13
 
13
import org.apache.log4j.Logger;
14
import org.apache.log4j.Logger;
-
 
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;
14
import org.apache.thrift.TException;
20
import org.apache.thrift.TException;
15
 
21
 
-
 
22
@Results({
-
 
23
	@Result(name="failure", location="myresearch-failure.vm"),
-
 
24
	@Result(name="success", location="myresearch-success.vm")
-
 
25
})
16
public class MyresearchController extends BaseController{
26
public class MyresearchController extends BaseController{
17
 
27
 
18
	private UserContextServiceClient userServiceClient = null;
28
	private UserContextServiceClient userServiceClient = null;
19
	private Client client;
29
	private Client client;
20
	
30
	
Line 31... Line 41...
31
		
41
		
32
	private static Logger log = Logger.getLogger(Class.class);
42
	private static Logger log = Logger.getLogger(Class.class);
33
	
43
	
34
	private String htmlSnippet = "";
44
	private String htmlSnippet = "";
35
 
45
 
-
 
46
	@Action(value="myresearch",interceptorRefs={@InterceptorRef("myDefault")})
36
	public String index() {
47
	public String index() {
37
		return "index";
48
		return "index";
38
	}
49
	}
39
	
50
	
40
	//Handle /myresearch/{id}
51
	//Handle /myresearch/{id}
-
 
52
	@Action(value="addtoresearch",interceptorRefs={@InterceptorRef("createuser"),@InterceptorRef("myDefault")})
41
	public String create() throws WidgetException, TException, IOException {
53
	public String create() throws WidgetException, TException, IOException {
42
		log.info("list of item ids is " + this.request.getParameter("productid"));
54
		log.info("list of item ids is " + this.request.getParameter("productid"));
43
		String itemIds = this.request.getParameter("productid");
55
		String itemIds = this.request.getParameter("productid");
44
		if(userinfo.isLoggedIn()){
56
		if(userinfo.getUserId() != -1){
45
			StringTokenizer tokenizer = new StringTokenizer(itemIds,"_");
57
			StringTokenizer tokenizer = new StringTokenizer(itemIds,"_");
46
			while(tokenizer.hasMoreTokens()){
58
			while(tokenizer.hasMoreTokens()){
47
				long entity_id = Long.parseLong(tokenizer.nextToken());
59
				long entity_id = Long.parseLong(tokenizer.nextToken());
48
				boolean isNew = client.updateMyResearch(userinfo.getUserId(), entity_id);
60
				boolean isNew = client.updateMyResearch(userinfo.getUserId(), entity_id);
49
				if(isNew){
61
				if(isNew){
50
					htmlSnippet = htmlSnippet + FileUtils.read( Utils.EXPORT_ENTITIES_PATH + entity_id + File.separator +"WidgetSnippet.html");
62
					htmlSnippet = htmlSnippet + FileUtils.read( Utils.EXPORT_ENTITIES_PATH + entity_id + File.separator +"WidgetSnippet.html");
51
				}
63
				}
52
			}
64
			}
-
 
65
			if (this.request.getParameter("historyitems") != null) {
-
 
66
				String historyItems = this.request.getParameter("productid");
-
 
67
				updateHistory(historyItems);
-
 
68
			}
-
 
69
 
53
		}
70
		}
54
		
-
 
55
		return "success";
71
		return "success";
56
	}
72
	}
57
	
73
	
-
 
74
	@Action(value="deletefromresearch",interceptorRefs={@InterceptorRef("createuser"),@InterceptorRef("myDefault")})
58
	public String destroy(){
75
	public String destroy(){
59
		log.info("list of item ids is " + this.request.getParameter("productid"));
76
		log.info("list of item ids is " + this.request.getParameter("productid"));
60
		String itemIds = this.request.getParameter("productid");
77
		String itemIds = this.request.getParameter("productid");
61
		if(itemIds == null){
78
		if(itemIds == null){
62
			return "failure";
79
			return "failure";
Line 83... Line 100...
83
		} catch (Exception e) {
100
		} catch (Exception e) {
84
			e.printStackTrace();
101
			e.printStackTrace();
85
		}
102
		}
86
	}
103
	}
87
	
104
	
-
 
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
 
88
	public String getHtmlSnippet(){
122
	public String getHtmlSnippet(){
89
		if(htmlSnippet == "")	{
123
		if(htmlSnippet == "")	{
90
			htmlSnippet = userinfo.isLoggedIn() ? "1" : "0";
124
			htmlSnippet = userinfo.isLoggedIn() ? "1" : "0";
91
		}
125
		}
92
		return htmlSnippet;
126
		return htmlSnippet;