Rev 590 | Blame | Last modification | View Log | RSS feed
/****/package in.shop2020.serving.controllers;import in.shop2020.serving.pages.PageContentKeys;import in.shop2020.serving.pages.PageEnum;import in.shop2020.serving.pages.PageManager;import in.shop2020.serving.services.PageLoaderHandler;import in.shop2020.thrift.clients.UserContextServiceClient;import in.shop2020.model.v1.user.UserContextService.Client;import java.io.IOException;import java.util.HashMap;import java.util.Map;import java.util.StringTokenizer;import javax.servlet.ServletContext;import org.apache.juli.logging.Log;import org.apache.juli.logging.LogFactory;import org.apache.struts2.convention.annotation.Action;import org.apache.struts2.convention.annotation.Actions;import org.apache.struts2.convention.annotation.Result;import org.apache.struts2.convention.annotation.Results;import org.apache.struts2.rest.DefaultHttpHeaders;import org.apache.struts2.rest.HttpHeaders;import org.apache.struts2.util.ServletContextAware;import com.opensymphony.xwork2.ModelDriven;/**** @author naveen**/@Results({@Result(name="success", location="/entity-show")})public class EntityController extends BaseControllerimplements ModelDriven<Object>, ServletContextAware {private PageManager pageManager = null;/****/private static Log log = LogFactory.getLog(EntityController.class);/****/@SuppressWarnings("unused")private ServletContext servletContext = null;/****/private String id;private long productId;private Map<String,String> htmlSnippets = new HashMap<String, String>();;public EntityController(){super();pageManager = PageManager.getPageManager();}// GET /entity/1000001@Actions({@Action("/mobiles"),@Action("/books"),@Action("/mobile"),@Action("/entity")})public HttpHeaders show() throws SecurityException, IOException {log.info("id=" + id);PageLoaderHandler pageLoader = new PageLoaderHandler();htmlSnippets.put("HEADER", pageLoader.getHeaderHtml(this.userinfo.isLoggedIn(), this.userinfo.getNameOfUser()));htmlSnippets.put("MAIN_MENU", pageLoader.getMainMenuHtml());htmlSnippets.put("SEARCH_BAR", pageLoader.getSearchBarHtml(userinfo.getTotalItems(), 0));htmlSnippets.put("PRODUCT_SUMMARY", pageLoader.getProductSummaryHtml(productId));htmlSnippets.put("SOCIAL_UTILS", pageLoader.getSocialUtilsHtml(productId));htmlSnippets.put("SLIDE_GUIDE", pageLoader.getSlideGuideHtml(productId));htmlSnippets.put("LOCATOR", pageLoader.getLocatorHtml());htmlSnippets.put("REVIEWS", pageLoader.getReviewsHtml(productId));htmlSnippets.put("CUSTOMER_SERVICE", pageLoader.getCustomerServiceHtml());htmlSnippets.put("MY_RESEARCH", pageLoader.getMyResearchHtml(userinfo.getUserId(), true));htmlSnippets.put("RECOMMENDATIONS", pageLoader.getRecommendationsHtml());htmlSnippets.put("SIMILAR_PRODUCTS", pageLoader.getSimilarProductsHtml(productId));htmlSnippets.put("ACCESSORIES", pageLoader.getAccessoriesHtml(productId));htmlSnippets.put("FOOTER", pageLoader.getFooterHtml());htmlSnippets.put("JS_FILES", "");htmlSnippets.put("CSS_FILES", "");try {UserContextServiceClient userServiceClient = new UserContextServiceClient();Client client = userServiceClient.getClient();long item_id = Long.parseLong(id);boolean isSessionId = userinfo.isSessionId();long user_id = userinfo.getUserId();client.updateBrowseHistory(user_id, item_id, isSessionId);} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}return new DefaultHttpHeaders("show");}/**** @param id*/public void setId(String id) {StringTokenizer tokenizer = new StringTokenizer(id,"-");while(tokenizer.hasMoreTokens()){this.id = tokenizer.nextToken();}this.productId = Long.parseLong(id);}/* (non-Javadoc)* @see com.opensymphony.xwork2.ModelDriven#getModel()*/@Overridepublic Object getModel() {System.out.println(" getModer is called");return htmlSnippets;//return this.id;}/****/@Overridepublic void setServletContext(ServletContext servletContext) {this.servletContext = servletContext;}public Map<String,String> getHtmlSnippets(){System.out.println(" getHtmlSnippets is called");return htmlSnippets;}public String getHeaderSnippet(){return htmlSnippets.get("HEADER");}public String getSlideGuideSnippet(){return htmlSnippets.get("SLIDE_GUIDE");}public String getMainMenuSnippet(){return htmlSnippets.get("MAIN_MENU");}public String getSearchBarSnippet(){return htmlSnippets.get("SEARCH_BAR");}public String getProductSummarySnippet(){return htmlSnippets.get("PRODUCT_SUMMARY");}public String getSocialUtilsSnippet(){return htmlSnippets.get("SOCIAL_UTILS");}public String getLocatorSnippet(){return htmlSnippets.get("LOCATOR");}public String getReviewsSnippet(){return htmlSnippets.get("REVIEWS");}public String getCustomerServiceSnippet(){return htmlSnippets.get("CUSTOMER_SERVICE");}public String getMyResearchSnippet(){return htmlSnippets.get("MY_RESEARCH");}public String getRecommendationsSnippet(){return htmlSnippets.get("RECOMMENDATIONS");}public String getSimilarProductsSnippet(){return htmlSnippets.get("SIMILAR_PRODUCTS");}public String getAccessoriesSnippet(){return htmlSnippets.get("ACCESSORIES");}public String getFooterSnippet(){return htmlSnippets.get("FOOTER");}public String getJsFileSnippet(){return htmlSnippets.get("JS_FILES");}public String getCssFileSnippet(){return htmlSnippets.get("CSS_FILES");}}