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());
458 rajveer 77
    	params.put(PageContentKeys.ITEM_COUNT, new Long(userinfo.getTotalItems()).toString());
387 rajveer 78
 
449 rajveer 79
    	htmlSnippets = pageManager.getPageContents(PageEnum.PRODUCT_PAGE, params);
80
 
81
 
387 rajveer 82
    	System.out.println(htmlSnippets);
449 rajveer 83
    	// To update the browse history of the user
84
    	try {
85
			WidgetServiceClient widgetServiceClient = new WidgetServiceClient();
86
			Client client = widgetServiceClient.getClient();
87
			long item_id = Long.parseLong(id);
88
			boolean isSessionId = userinfo.isSessionId();
89
			long user_id = 0;
90
			if(userinfo.isLoggedIn())
91
				user_id = userinfo.getUserId();
92
			else
93
				user_id = userinfo.getSessionId();
94
			client.updateBrowseHistory(user_id, item_id, isSessionId);
95
 
96
		} catch (Exception e) {
97
			// TODO Auto-generated catch block
98
			e.printStackTrace();
99
		}
100
 
317 ashish 101
    	/*
102
    	String contextPath = this.servletContext.getContextPath();
103
    	log.info("contextPath=" + contextPath);
104
 
105
    	String realPath = this.servletContext.getRealPath("/");
106
    	log.info("realPath=" + realPath);
107
 
108
    	String path = this.servletContext.getRealPath(
109
    			"/WEB-INF/testdir/test.txt");
110
 
111
    	log.info("path=" + path);
112
 
113
    	FileReader fr = new FileReader(new File(path));
114
    	LineNumberReader lnr = new LineNumberReader(fr);
115
 
116
    	String line = lnr.readLine();
117
    	log.info("line=" + line);
118
    	*/
119
        return new DefaultHttpHeaders("show");
120
    }
121
 
122
    /**
123
     * 
124
     * @param id
125
     */
126
    public void setId(String id) {
127
        this.id = id;
128
    }
129
 
130
	/* (non-Javadoc)
131
	 * @see com.opensymphony.xwork2.ModelDriven#getModel()
132
	 */
133
	@Override
134
	public Object getModel() {
388 rajveer 135
		System.out.println(" getModer  is called");
136
		return htmlSnippets;
137
		//return this.id;
317 ashish 138
	}
139
 
140
	/**
141
	 * 
142
	 */
143
	@Override
144
	public void setServletContext(ServletContext servletContext) {
145
		this.servletContext = servletContext;
146
	}
375 ashish 147
 
387 rajveer 148
	public Map<String,String> getHtmlSnippets(){
388 rajveer 149
		System.out.println(" getHtmlSnippets  is called");
387 rajveer 150
		return htmlSnippets;
375 ashish 151
	}
388 rajveer 152
 
449 rajveer 153
	public String getHeaderSnippet(){
154
		return htmlSnippets.get("HEADER");
388 rajveer 155
	}
317 ashish 156
 
449 rajveer 157
	public String getSlideGuideSnippet(){
388 rajveer 158
		return htmlSnippets.get("SLIDE_GUIDE");
159
	}
160
 
449 rajveer 161
	public String getMainMenuSnippet(){
162
		return htmlSnippets.get("MAIN_MENU");
388 rajveer 163
	}
449 rajveer 164
 
165
	public String getSearchBarSnippet(){
166
		return htmlSnippets.get("SEARCH_BAR");
167
	}
168
 
169
	public String getProductSummarySnippet(){
170
		return htmlSnippets.get("PRODUCT_SUMMARY");
171
	}
172
 
173
	public String getSocialUtilsSnippet(){
174
		return htmlSnippets.get("SOCIAL_UTILS"); 
175
	}
176
 
177
	public String getLocatorSnippet(){
178
		return htmlSnippets.get("LOCATOR");
179
	}
180
 
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
 
388 rajveer 193
 
449 rajveer 194
	public String getRecommendationsSnippet(){
195
		return htmlSnippets.get("RECOMMENDATIONS");
196
	}
197
 
198
	public String getSimilarProductsSnippet(){
199
		return htmlSnippets.get("SIMILAR_PRODUCTS");
200
	}
201
 
202
	public String getAccessoriesSnippet(){
203
		return htmlSnippets.get("ACCESSORIES");
204
	}
205
 
206
	public String getFooterSnippet(){
207
		return htmlSnippets.get("FOOTER");
208
	}
209
 
210
	public String getJsFileSnippet(){
211
		return htmlSnippets.get("JS_FILES");
212
	}
213
 
214
	public String getCssFileSnippet(){
215
		return htmlSnippets.get("CSS_FILES");
216
	}
217
 
317 ashish 218
}