Rev 569 | Rev 650 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
/****/package in.shop2020.serving.controllers;import in.shop2020.model.v1.user.Address;import in.shop2020.model.v1.user.User;import in.shop2020.model.v1.user.UserState;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 java.io.UnsupportedEncodingException;import java.util.Date;import java.util.HashMap;import java.util.Map;import org.apache.juli.logging.Log;import org.apache.juli.logging.LogFactory;import org.apache.struts2.convention.annotation.Result;import org.apache.struts2.convention.annotation.Results;import org.apache.struts2.interceptor.ParameterAware;import org.apache.struts2.rest.DefaultHttpHeaders;import org.apache.struts2.rest.HttpHeaders;/*** @author rajveer**/public class CompletedordersController extends BaseControllerimplements ParameterAware {/****/private static Log log = LogFactory.getLog(CompletedordersController.class);private Map<String,String> htmlSnippets = new HashMap<String, String>();/****/private Map<String, String[]> reqparams;private String id;private int action;public CompletedordersController() {super();}// POST /myaccountpublic String create() {log.info("CompletedordersController.create");log.info("action type is " + this.reqparams.get("action"));action = Integer.parseInt(this.reqparams.get("action")[0]);try {if(addUpdateUserDetails(action)){return "success";}else{return "failure";}} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}return "failure";}// GET /testpublic HttpHeaders index() throws UnsupportedEncodingException {log.info("this.request=" + this.request);String userId = "";if(this.userinfo.isLoggedIn()){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("MYACCOUNT_HEADER", pageLoader.getMyaccountHeaderHtml());htmlSnippets.put("MYACCOUNT_DETAILS", pageLoader.getCompletedOrdersHtml(userinfo.getUserId()));htmlSnippets.put("CUSTOMER_SERVICE", pageLoader.getCustomerServiceHtml());htmlSnippets.put("MY_RESEARCH", pageLoader.getMyResearchHtml(userinfo.getUserId(), true));htmlSnippets.put("BROWSE_HISTORY", pageLoader.getBrowseHistoryHtml(userinfo.getUserId(), true));htmlSnippets.put("FOOTER", pageLoader.getFooterHtml());htmlSnippets.put("JS_FILES", "");htmlSnippets.put("CSS_FILES", "");return new DefaultHttpHeaders("index").disableCaching();}else{return new DefaultHttpHeaders("login").disableCaching();}}public HttpHeaders show(){log.info("this.id=" + this.id);log.info("this.id=" + userinfo.getTotalItems());Map<PageContentKeys, String> params = new HashMap<PageContentKeys, String>();params.put(PageContentKeys.CUSTOMER_ID, id);params.put(PageContentKeys.ITEM_COUNT, userinfo.getTotalItems()+"");htmlSnippets = PageManager.getPageManager().getPageContents(PageEnum.MY_ACCOUNT_PAGE, params);return new DefaultHttpHeaders("index").disableCaching();}public String getHeaderSnippet(){return htmlSnippets.get("HEADER");}public String getMainMenuSnippet(){return htmlSnippets.get("MAIN_MENU");}public String getSearchBarSnippet(){return htmlSnippets.get("SEARCH_BAR");}public String getCustomerServiceSnippet(){return htmlSnippets.get("CUSTOMER_SERVICE");}public String getMyaccountHeaderSnippet(){return htmlSnippets.get("MYACCOUNT_HEADER");}public String getMyaccountDetailsSnippet(){return htmlSnippets.get("MYACCOUNT_DETAILS");}public String getMyResearchSnippet(){return htmlSnippets.get("MY_RESEARCH");}public String getBrowseHistorySnippet(){return htmlSnippets.get("BROWSE_HISTORY");}public String getFooterSnippet(){return htmlSnippets.get("FOOTER");}public String getJsFileSnippet(){return htmlSnippets.get("JS_FILES");}public String getCssFileSnippet(){return htmlSnippets.get("CSS_FILES");}/**** @param id*/public void setId(String id) {this.id = id;}public boolean logoutUser(int userId) throws Exception{UserContextServiceClient userContextServiceClient = null;in.shop2020.model.v1.user.UserContextService.Client userClient = null;userContextServiceClient = new UserContextServiceClient();userClient = userContextServiceClient.getClient();userClient.setUserAsLoggedOut(userId, (new Date()).getTime());return true;}public boolean addUpdateUserDetails(int action) throws Exception{UserContextServiceClient userContextServiceClient = null;in.shop2020.model.v1.user.UserContextService.Client userClient = null;userContextServiceClient = new UserContextServiceClient();userClient = userContextServiceClient.getClient();switch (action) {case 1:String email = this.reqparams.get("email")[0];String password = this.reqparams.get("password")[0];if(userClient.userExists(email)){return false;}else{User user = new User();user.setPassword(password);user.setEmail(email);user = userClient.createUser(user);long userId = user.getUserId();userClient.setUserAsLoggedIn(userId, (new Date()).getTime());this.userinfo.setUserId(userId);this.userinfo.setEmail(email);this.userinfo.setLoggedIn(true);return true;}//add addresscase 2:long userId = Long.parseLong(this.reqparams.get("user_id")[0]);String name = this.reqparams.get("name")[0];String line1 = this.reqparams.get("line1")[0];String line2 = this.reqparams.get("line2")[0];String landmark = this.reqparams.get("landmark")[0];String city = this.reqparams.get("city")[0];String state = this.reqparams.get("state")[0];String pin = this.reqparams.get("pin")[0];String country = this.reqparams.get("country")[0];String phone = this.reqparams.get("phone")[0];Address address = new Address();address.setName(name);address.setLine1(line1);address.setLine2(line2);address.setLandmark(landmark);address.setCity(city);address.setState(state);address.setPin(pin);address.setCountry(country);address.setPhone(phone);if(userClient.addAddressForUser(userId, address, false)>0){return true;}else{return false;}case 3:break;default:break;}return false;}/****/// @Override// public void setServletRequest(HttpServletRequest request) {// this.request = request;// }@Overridepublic void setParameters(Map<String, String[]> reqmap) {log.info("setParameters:" + reqmap);this.reqparams = reqmap;}public String getMyAccountSnippets(){return htmlSnippets.get("My_ACCOUNT");}public String getMyOrdersSnippets(){return htmlSnippets.get("My_ORDERS");}}