Rev 507 | Blame | Last modification | View Log | RSS feed
/****/package in.shop2020.serving.controllers;import in.shop2020.model.v1.user.Address;import in.shop2020.model.v1.user.UserContext;import in.shop2020.model.v1.user.UserPrimaryInfo;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.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 MyaccountController extends BaseControllerimplements ParameterAware {/****/private static Log log = LogFactory.getLog(MyaccountController.class);private Map<String,String> htmlSnippets;/****/private Map<String, String[]> reqparams;private String id;private int action;public MyaccountController() {super();}// POST /myaccountpublic String create() {log.info("MyAccountController.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()){userId = (new Long(this.userinfo.getUserId())).toString();Map<PageContentKeys, String> params = new HashMap<PageContentKeys, String>();params.put(PageContentKeys.CUSTOMER_ID, userId);params.put(PageContentKeys.ITEM_COUNT, userinfo.getTotalItems()+"");htmlSnippets = PageManager.getPageManager().getPageContents(PageEnum.MY_ACCOUNT_PAGE, params);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 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{UserContext context = new UserContext();UserPrimaryInfo primaryInfo = new UserPrimaryInfo();UserState userState = new UserState();primaryInfo.setPassword(password);primaryInfo.setEmail(email);userState.setIsLoggedIn(true);context.setPrimaryInfo(primaryInfo);context.setUserState(userState);context = userClient.createContext(context, false);long userId = context.getId();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);long timestamp = (new Date()).getTime();if(userClient.addAddressForUser(address, userId, timestamp, false)){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");}}