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();
95
			long user_id = 0;
96
			if(userinfo.isLoggedIn())
97
				user_id = userinfo.getUserId();
98
			else
555 chandransh 99
				user_id = userinfo.getUserId();
449 rajveer 100
			client.updateBrowseHistory(user_id, item_id, isSessionId);
101
 
102
		} catch (Exception e) {
103
			// TODO Auto-generated catch block
104
			e.printStackTrace();
105
		}
106
 
317 ashish 107
    	/*
108
    	String contextPath = this.servletContext.getContextPath();
109
    	log.info("contextPath=" + contextPath);
110
 
111
    	String realPath = this.servletContext.getRealPath("/");
112
    	log.info("realPath=" + realPath);
113
 
114
    	String path = this.servletContext.getRealPath(
115
    			"/WEB-INF/testdir/test.txt");
116
 
117
    	log.info("path=" + path);
118
 
119
    	FileReader fr = new FileReader(new File(path));
120
    	LineNumberReader lnr = new LineNumberReader(fr);
121
 
122
    	String line = lnr.readLine();
123
    	log.info("line=" + line);
124
    	*/
125
        return new DefaultHttpHeaders("show");
126
    }
127
 
128
    /**
129
     * 
130
     * @param id
131
     */
132
    public void setId(String id) {
507 rajveer 133
    	StringTokenizer tokenizer = new StringTokenizer(id,"-");
134
    	while(tokenizer.hasMoreTokens()){
135
    		this.id = tokenizer.nextToken();
136
    	}
317 ashish 137
    }
138
 
139
	/* (non-Javadoc)
140
	 * @see com.opensymphony.xwork2.ModelDriven#getModel()
141
	 */
142
	@Override
143
	public Object getModel() {
388 rajveer 144
		System.out.println(" getModer  is called");
145
		return htmlSnippets;
146
		//return this.id;
317 ashish 147
	}
148
 
149
	/**
150
	 * 
151
	 */
152
	@Override
153
	public void setServletContext(ServletContext servletContext) {
154
		this.servletContext = servletContext;
155
	}
375 ashish 156
 
387 rajveer 157
	public Map<String,String> getHtmlSnippets(){
388 rajveer 158
		System.out.println(" getHtmlSnippets  is called");
387 rajveer 159
		return htmlSnippets;
375 ashish 160
	}
388 rajveer 161
 
449 rajveer 162
	public String getHeaderSnippet(){
163
		return htmlSnippets.get("HEADER");
388 rajveer 164
	}
317 ashish 165
 
449 rajveer 166
	public String getSlideGuideSnippet(){
388 rajveer 167
		return htmlSnippets.get("SLIDE_GUIDE");
168
	}
169
 
449 rajveer 170
	public String getMainMenuSnippet(){
171
		return htmlSnippets.get("MAIN_MENU");
388 rajveer 172
	}
449 rajveer 173
 
174
	public String getSearchBarSnippet(){
175
		return htmlSnippets.get("SEARCH_BAR");
176
	}
177
 
178
	public String getProductSummarySnippet(){
179
		return htmlSnippets.get("PRODUCT_SUMMARY");
180
	}
181
 
182
	public String getSocialUtilsSnippet(){
183
		return htmlSnippets.get("SOCIAL_UTILS"); 
184
	}
185
 
186
	public String getLocatorSnippet(){
187
		return htmlSnippets.get("LOCATOR");
188
	}
189
 
190
	public String getReviewsSnippet(){
191
		return htmlSnippets.get("REVIEWS");
192
	}
193
 
194
	public String getCustomerServiceSnippet(){
195
		return htmlSnippets.get("CUSTOMER_SERVICE");
196
	}
197
 
198
	public String getMyResearchSnippet(){
199
		return htmlSnippets.get("MY_RESEARCH");
200
	}
201
 
388 rajveer 202
 
449 rajveer 203
	public String getRecommendationsSnippet(){
204
		return htmlSnippets.get("RECOMMENDATIONS");
205
	}
206
 
207
	public String getSimilarProductsSnippet(){
208
		return htmlSnippets.get("SIMILAR_PRODUCTS");
209
	}
210
 
211
	public String getAccessoriesSnippet(){
212
		return htmlSnippets.get("ACCESSORIES");
213
	}
214
 
215
	public String getFooterSnippet(){
216
		return htmlSnippets.get("FOOTER");
217
	}
218
 
219
	public String getJsFileSnippet(){
220
		return htmlSnippets.get("JS_FILES");
221
	}
222
 
223
	public String getCssFileSnippet(){
224
		return htmlSnippets.get("CSS_FILES");
225
	}
226
 
317 ashish 227
}