Subversion Repositories SmartDukaan

Rev

Rev 637 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 637 Rev 650
Line 1... Line 1...
1
/**
1
/**
2
 * 
2
 * 
3
 */
3
 */
4
package in.shop2020.serving.controllers;
4
package in.shop2020.serving.controllers;
5
 
5
 
6
import in.shop2020.serving.pages.PageContentKeys;
-
 
7
import in.shop2020.serving.pages.PageEnum;
-
 
8
import in.shop2020.serving.pages.PageManager;
-
 
9
import in.shop2020.serving.services.PageLoaderHandler;
-
 
-
 
6
 
10
import in.shop2020.thrift.clients.UserContextServiceClient;
7
import in.shop2020.thrift.clients.UserContextServiceClient;
11
import in.shop2020.model.v1.user.UserContextService.Client;
8
import in.shop2020.model.v1.user.UserContextService.Client;
12
 
9
 
13
import java.io.IOException;
10
import java.io.IOException;
14
import java.util.HashMap;
-
 
15
import java.util.Map;
11
import java.util.Map;
16
import java.util.StringTokenizer;
12
import java.util.StringTokenizer;
17
 
13
 
18
import javax.servlet.ServletContext;
-
 
19
 
-
 
20
import org.apache.juli.logging.Log;
14
import org.apache.juli.logging.Log;
21
import org.apache.juli.logging.LogFactory;
15
import org.apache.juli.logging.LogFactory;
22
import org.apache.struts2.convention.annotation.Action;
16
import org.apache.struts2.convention.annotation.Action;
23
import org.apache.struts2.convention.annotation.Actions;
17
import org.apache.struts2.convention.annotation.Actions;
24
import org.apache.struts2.convention.annotation.Result;
-
 
25
import org.apache.struts2.convention.annotation.Results;
-
 
26
import org.apache.struts2.rest.DefaultHttpHeaders;
-
 
27
import org.apache.struts2.rest.HttpHeaders;
-
 
28
import org.apache.struts2.util.ServletContextAware;
-
 
29
 
-
 
30
import com.opensymphony.xwork2.ModelDriven;
-
 
31
 
18
 
32
/**
19
/**
33
 * 
20
 * 
34
 * @author naveen
21
 * @author rajveer
35
 *
22
 *
36
 */
23
 */
37
@Results({
-
 
38
	@Result(name="success", location="/entity-show")
-
 
39
})
24
 
40
public class EntityController extends BaseController 
25
public class EntityController extends BaseController {
41
	implements  ModelDriven<Object>, ServletContextAware  {
-
 
42
		  
26
		
43
	private PageManager pageManager = null;
27
	private static final long serialVersionUID = 1L;
44
	
28
 
45
	/**
-
 
46
	 * 
-
 
47
	 */
-
 
48
	private static Log log = LogFactory.getLog(EntityController.class);
29
	private static Log log = LogFactory.getLog(EntityController.class);
49
	
30
	
50
	/**
31
	/**
51
	 * 
32
	 * 
52
	 */
33
	 */
53
	@SuppressWarnings("unused")
-
 
54
	private ServletContext servletContext = null;
-
 
55
	
-
 
56
	/**
-
 
57
	 * 
-
 
58
	 */
-
 
59
	private String id;
34
	private String id;
60
	
35
	
61
	private long productId;
36
	private long productId;
62
	
37
	
63
	private Map<String,String> htmlSnippets = new HashMap<String, String>();;
-
 
64
	
-
 
65
	
-
 
66
	public EntityController(){
38
	public EntityController(){
67
		super();
39
		super();
68
		pageManager = PageManager.getPageManager();
-
 
69
	}
40
	}
70
 
41
 
71
	// GET /entity/1000001
42
	// GET /entity/1000001
72
	@Actions({
43
	@Actions({
73
		@Action("/mobiles"),
44
		@Action("/mobiles"),
74
		@Action("/books"),
45
		@Action("/books"),
75
		@Action("/mobile"),
46
		@Action("/mobile"),
76
		@Action("/entity")
47
		@Action("/entity")
77
	})
48
	})
78
    public HttpHeaders show() throws SecurityException, IOException {
49
    public String show() throws SecurityException, IOException {
79
    	log.info("id=" + id);
50
    	log.info("id=" + id);
80
 
51
 
81
    	htmlSnippets.put("HEADER", pageLoader.getHeaderHtml(this.userinfo.isLoggedIn(), this.userinfo.getNameOfUser()));
-
 
82
		htmlSnippets.put("MAIN_MENU", pageLoader.getMainMenuHtml());
-
 
83
		htmlSnippets.put("SEARCH_BAR", pageLoader.getSearchBarHtml(userinfo.getTotalItems(), 0));
-
 
84
		
-
 
85
		
-
 
86
		htmlSnippets.put("PRODUCT_SUMMARY", pageLoader.getProductSummaryHtml(productId));
52
    	htmlSnippets.put("PRODUCT_SUMMARY", pageLoader.getProductSummaryHtml(productId));
87
		htmlSnippets.put("SOCIAL_UTILS", pageLoader.getSocialUtilsHtml(productId));
53
		htmlSnippets.put("SOCIAL_UTILS", pageLoader.getSocialUtilsHtml(productId));
88
		htmlSnippets.put("SLIDE_GUIDE", pageLoader.getSlideGuideHtml(productId));
54
		htmlSnippets.put("SLIDE_GUIDE", pageLoader.getSlideGuideHtml(productId));
89
		htmlSnippets.put("LOCATOR", pageLoader.getLocatorHtml());
-
 
90
		htmlSnippets.put("REVIEWS", pageLoader.getReviewsHtml(productId));
-
 
91
		
-
 
92
		htmlSnippets.put("CUSTOMER_SERVICE", pageLoader.getCustomerServiceHtml());
-
 
93
		htmlSnippets.put("MY_RESEARCH", pageLoader.getMyResearchHtml(userinfo.getUserId(), userinfo.isLoggedIn()));
-
 
94
		htmlSnippets.put("BROWSE_HISTORY", pageLoader.getBrowseHistoryHtml(userinfo.getUserId(), userinfo.isLoggedIn()));
-
 
95
		htmlSnippets.put("RECOMMENDATIONS", pageLoader.getRecommendationsHtml());
55
		htmlSnippets.put("RECOMMENDATIONS", pageLoader.getRecommendationsHtml());
96
		htmlSnippets.put("SIMILAR_PRODUCTS", pageLoader.getSimilarProductsHtml(productId));
56
		htmlSnippets.put("SIMILAR_PRODUCTS", pageLoader.getSimilarProductsHtml(productId));
97
		htmlSnippets.put("ACCESSORIES", pageLoader.getAccessoriesHtml(productId));
57
		htmlSnippets.put("ACCESSORIES", pageLoader.getAccessoriesHtml(productId));
98
		htmlSnippets.put("FOOTER", pageLoader.getFooterHtml());
58
		htmlSnippets.put("LOCATOR", pageLoader.getLocatorHtml());
99
		htmlSnippets.put("JS_FILES", "");
59
		htmlSnippets.put("REVIEWS", pageLoader.getReviewsHtml(productId));
100
		htmlSnippets.put("CSS_FILES", "");
-
 
101
	
60
	
102
    	try {
61
		try {
103
			UserContextServiceClient userServiceClient = new UserContextServiceClient();
62
			UserContextServiceClient userServiceClient = new UserContextServiceClient();
104
			Client client = userServiceClient.getClient();
63
			Client client = userServiceClient.getClient();
105
			long item_id = Long.parseLong(id);
64
			long item_id = Long.parseLong(id);
106
			boolean isSessionId = userinfo.isSessionId();
65
			boolean isSessionId = userinfo.isSessionId();
107
			long user_id = userinfo.getUserId();
66
			long user_id = userinfo.getUserId();
108
			client.updateBrowseHistory(user_id, item_id, isSessionId);
67
			client.updateBrowseHistory(user_id, item_id, isSessionId);
109
			
68
		
110
		} catch (Exception e) {
69
		} catch (Exception e) {
111
			// TODO Auto-generated catch block
70
			// TODO Auto-generated catch block
112
			e.printStackTrace();
71
			e.printStackTrace();
113
		}
72
		}
114
    	
73
    	
115
    	return new DefaultHttpHeaders("show");
74
    	return "show";
116
    }
75
    }
117
    
76
    
118
    /**
77
    /**
119
     * 
78
     * 
120
     * @param id
79
     * @param id
Line 125... Line 84...
125
    		this.id = tokenizer.nextToken();
84
    		this.id = tokenizer.nextToken();
126
    	}
85
    	}
127
    	this.productId = Long.parseLong(id);
86
    	this.productId = Long.parseLong(id);
128
    }
87
    }
129
 
88
 
130
	/* (non-Javadoc)
-
 
131
	 * @see com.opensymphony.xwork2.ModelDriven#getModel()
-
 
132
	 */
-
 
133
	@Override
-
 
134
	public Object getModel() {
-
 
135
		System.out.println(" getModer  is called");
-
 
136
		return htmlSnippets;
-
 
137
		//return this.id;
-
 
138
	}
-
 
139
	
-
 
140
	/**
-
 
141
	 * 
-
 
142
	 */
-
 
143
	@Override
-
 
144
	public void setServletContext(ServletContext servletContext) {
-
 
145
		this.servletContext = servletContext;
-
 
146
	}
-
 
147
	
-
 
148
	public Map<String,String> getHtmlSnippets(){
89
	public Map<String,String> getHtmlSnippets(){
149
		System.out.println(" getHtmlSnippets  is called");
90
		System.out.println(" getHtmlSnippets  is called");
150
		return htmlSnippets;
91
		return htmlSnippets;
151
	}
92
	}
152
	
93
	
153
	public String getHeaderSnippet(){
-
 
154
		return htmlSnippets.get("HEADER");
-
 
155
	}
-
 
156
 
-
 
157
	public String getSlideGuideSnippet(){
94
	public String getSlideGuideSnippet(){
158
		return htmlSnippets.get("SLIDE_GUIDE");
95
		return htmlSnippets.get("SLIDE_GUIDE");
159
	}
96
	}
160
 
97
 
161
	public String getMainMenuSnippet(){
-
 
162
		return htmlSnippets.get("MAIN_MENU");
-
 
163
	}
-
 
164
	
-
 
165
	public String getSearchBarSnippet(){
-
 
166
		return htmlSnippets.get("SEARCH_BAR");
-
 
167
	}
-
 
168
    		
-
 
169
	public String getProductSummarySnippet(){
98
	public String getProductSummarySnippet(){
170
		return htmlSnippets.get("PRODUCT_SUMMARY");
99
		return htmlSnippets.get("PRODUCT_SUMMARY");
171
	}
100
	}
172
	
101
	
173
	public String getSocialUtilsSnippet(){
102
	public String getSocialUtilsSnippet(){
Line 176... Line 105...
176
	
105
	
177
	public String getLocatorSnippet(){
106
	public String getLocatorSnippet(){
178
		return htmlSnippets.get("LOCATOR");
107
		return htmlSnippets.get("LOCATOR");
179
	}
108
	}
180
	
109
	
181
	public String getReviewsSnippet(){
-
 
182
		return htmlSnippets.get("REVIEWS");
-
 
183
	}
-
 
184
	
-
 
185
	public String getCustomerServiceSnippet(){
-
 
186
		return htmlSnippets.get("CUSTOMER_SERVICE");
-
 
187
	}
-
 
188
	
-
 
189
	public String getMyResearchSnippet(){
-
 
190
		return htmlSnippets.get("MY_RESEARCH");
-
 
191
	}
-
 
192
 
-
 
193
	public String getBrowseHistorySnippet(){
-
 
194
		return htmlSnippets.get("BROWSE_HISTORY");
-
 
195
	}
-
 
196
 
-
 
197
	public String getRecommendationsSnippet(){
110
	public String getRecommendationsSnippet(){
198
		return htmlSnippets.get("RECOMMENDATIONS");
111
		return htmlSnippets.get("RECOMMENDATIONS");
199
	}
112
	}
200
 
113
	
201
	public String getSimilarProductsSnippet(){
114
	public String getSimilarProductsSnippet(){
202
		return htmlSnippets.get("SIMILAR_PRODUCTS");
115
		return htmlSnippets.get("SIMILAR_PRODUCTS");
203
	}
116
	}
204
			
117
	
205
	public String getAccessoriesSnippet(){
118
	public String getAccessoriesSnippet(){
206
		return htmlSnippets.get("ACCESSORIES");
119
		return htmlSnippets.get("ACCESSORIES");
207
	}
120
	}
208
	 
-
 
209
	public String getFooterSnippet(){
-
 
210
		return htmlSnippets.get("FOOTER");
-
 
211
	}
-
 
212
 
-
 
213
	public String getJsFileSnippet(){
-
 
214
		return htmlSnippets.get("JS_FILES");
-
 
215
	}
-
 
216
	
121
	
217
	public String getCssFileSnippet(){
122
	public String getReviewsSnippet(){
218
		return htmlSnippets.get("CSS_FILES");
123
		return htmlSnippets.get("REVIEWS");
219
	}
124
	}
220
	
125
	
221
}
126
}