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;
375 ashish 8
import in.shop2020.serving.pages.PageContentKeys;
9
import in.shop2020.serving.pages.PageEnum;
10
import in.shop2020.serving.pages.PageManager;
449 rajveer 11
import in.shop2020.thrift.clients.WidgetServiceClient;
375 ashish 12
 
317 ashish 13
import java.io.IOException;
375 ashish 14
import java.util.HashMap;
15
import java.util.Map;
317 ashish 16
 
17
import javax.servlet.ServletContext;
18
 
19
import org.apache.juli.logging.Log;
20
import org.apache.juli.logging.LogFactory;
21
import org.apache.struts2.convention.annotation.Result;
22
import org.apache.struts2.convention.annotation.Results;
23
import org.apache.struts2.rest.DefaultHttpHeaders;
24
import org.apache.struts2.rest.HttpHeaders;
25
import org.apache.struts2.util.ServletContextAware;
26
 
27
import com.opensymphony.xwork2.ModelDriven;
28
 
29
/**
30
 * 
31
 * @author naveen
32
 *
33
 */
34
@Results({
35
    @Result(name="success", type="redirectAction", params = {"actionName" , 
36
    		"entity"})
37
})
38
public class EntityController extends BaseController 
39
	implements  ModelDriven<Object>, ServletContextAware  {
40
 
375 ashish 41
	private PageManager pageManager = null;
42
 
317 ashish 43
	/**
44
	 * 
45
	 */
46
	private static Log log = LogFactory.getLog(EntityController.class);
47
 
48
	/**
49
	 * 
50
	 */
51
	@SuppressWarnings("unused")
52
	private ServletContext servletContext = null;
53
 
54
	/**
55
	 * 
56
	 */
57
	private String id;
375 ashish 58
 
387 rajveer 59
	private Map<String,String> htmlSnippets;
375 ashish 60
 
61
 
62
	public EntityController(){
63
		super();
64
		pageManager = PageManager.getPageManager();
65
	}
317 ashish 66
    // GET /entity/1000001
67
    public HttpHeaders show() throws SecurityException, IOException {
68
    	log.info("id=" + id);
375 ashish 69
    	Map<PageContentKeys, String> params = new HashMap<PageContentKeys, String>();
449 rajveer 70
 
375 ashish 71
    	params.put(PageContentKeys.ENTITY_ID, id);
449 rajveer 72
    	params.put(PageContentKeys.USER_ID, new Long(userinfo.getUserId()).toString());
73
    	params.put(PageContentKeys.CART_ID, new Long(userinfo.getCartId()).toString());
74
    	params.put(PageContentKeys.SESSION_ID, new Long(userinfo.getSessionId()).toString());
75
    	params.put(PageContentKeys.USER_NAME, userinfo.getNameOfUser());
458 rajveer 76
    	params.put(PageContentKeys.ITEM_COUNT, new Long(userinfo.getTotalItems()).toString());
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
}