Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

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