Subversion Repositories SmartDukaan

Rev

Rev 569 | Rev 620 | 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.AddressType;
import in.shop2020.model.v1.user.Sex;
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.serving.utils.Utils;
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;
import org.apache.velocity.VelocityContext;

/**
 * @author rajveer
 *
 */

@Results({
    @Result(name="success", type="redirectAction", 
                params = {"actionName" , "personal-details"})
})

public class PersonalDetailsController extends BaseController {

        
        /**
         * 
         */
        private static Log log = LogFactory.getLog(PersonalDetailsController.class);
        
        private Map<String,String> htmlSnippets = new HashMap<String, String>();
        
        private Map<String,String> velocityParams = new HashMap<String, String>();
        /**
         * 
         */
        
        public PersonalDetailsController() {
                super();
        }
        
    // POST /logindetails
    public String create() {
        log.info("PersonaldetailsController.create");

                if(this.userinfo.isLoggedIn()){
                        String name = this.request.getParameter("txtName");
                        String dateOfBirth = this.request.getParameter("dateOfBirth");
                        String sex = this.request.getParameter("sex");
                        String communicationEmail = this.request.getParameter("txtCommEmail");
                        String subscribeNewsletter = this.request.getParameter("subscribe");
                        String phone = this.request.getParameter("txtPhone");
                        
                        if(Utils.UpdatePersonalDetails(userinfo.getUserId(), name, phone, dateOfBirth, sex,communicationEmail,subscribeNewsletter))
                        {       
                                addActionMessage("Your personal details updated");
                                return "success";
                        }
        }
                addActionError("Unable to update your personal details");
                return "success";
    }

    
    // GET /test
    public String index() throws UnsupportedEncodingException {
        log.info("this.request=" + this.request);
        
        
        
        if(this.userinfo.isLoggedIn()){
                long userId = this.userinfo.getUserId();
                PageLoaderHandler pageLoader = new PageLoaderHandler();
                
                
                htmlSnippets.put("HEADER", pageLoader.getHeaderHtml(this.userinfo.isLoggedIn(), this.userinfo.getNameOfUser()));
                htmlSnippets.put("MAIN_MENU", pageLoader.getMainMenuHtml());
                
                htmlSnippets.put("MAIN_MENU", pageLoader.getMainMenuHtml());
                htmlSnippets.put("SEARCH_BAR", pageLoader.getSearchBarHtml(userinfo.getTotalItems(), 0));
                htmlSnippets.put("MYACCOUNT_HEADER", pageLoader.getMyaccountHeaderHtml());
                htmlSnippets.put("PERSONAL_DETAILS", pageLoader.getPersonalDetailsHtml(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(), userinfo.isLoggedIn()));
                htmlSnippets.put("FOOTER", pageLoader.getFooterHtml());
                        return "index";
        
        }else{
                return "failure";
        }
        
    }
    
    
    public Map<String, String> getVelocityParams(){
        UserContextServiceClient userContextServiceClient = null;
                in.shop2020.model.v1.user.UserContextService.Client userClient = null;
                try{
                        User user = null;
                        userContextServiceClient = new UserContextServiceClient();
                        userClient = userContextServiceClient.getClient();
                        user = userClient.getUserById(userinfo.getUserId());
                        
                        velocityParams.put("email", user.getCommunicationEmail());
                        velocityParams.put("sex", user.getSex().getValue()+"");
                        velocityParams.put("name", user.getName());
                        velocityParams.put("phone", user.getMobileNumber());
                        velocityParams.put("dateOfBirth", user.getDateOfBirth());
                }catch (Exception e){
                        e.printStackTrace();
                }
                return velocityParams;
        }
    
    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 getPersonalDetailsSnippet(){
                return htmlSnippets.get("PERSONAL_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");
        }

}