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