Subversion Repositories SmartDukaan

Rev

Rev 569 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 569 Rev 595
Line 3... Line 3...
3
 */
3
 */
4
package in.shop2020.serving.controllers;
4
package in.shop2020.serving.controllers;
5
 
5
 
6
import in.shop2020.model.v1.user.Address;
6
import in.shop2020.model.v1.user.Address;
7
import in.shop2020.model.v1.user.AddressType;
7
import in.shop2020.model.v1.user.AddressType;
-
 
8
import in.shop2020.model.v1.user.Sex;
8
import in.shop2020.model.v1.user.User;
9
import in.shop2020.model.v1.user.User;
9
import in.shop2020.model.v1.user.UserState;
10
import in.shop2020.model.v1.user.UserState;
10
import in.shop2020.serving.pages.PageContentKeys;
11
import in.shop2020.serving.pages.PageContentKeys;
11
import in.shop2020.serving.pages.PageEnum;
12
import in.shop2020.serving.pages.PageEnum;
12
import in.shop2020.serving.pages.PageManager;
13
import in.shop2020.serving.pages.PageManager;
-
 
14
import in.shop2020.serving.services.PageLoaderHandler;
13
import in.shop2020.serving.utils.Utils;
15
import in.shop2020.serving.utils.Utils;
14
import in.shop2020.thrift.clients.UserContextServiceClient;
16
import in.shop2020.thrift.clients.UserContextServiceClient;
15
 
17
 
16
import java.io.UnsupportedEncodingException;
18
import java.io.UnsupportedEncodingException;
17
import java.util.Date;
19
import java.util.Date;
Line 23... Line 25...
23
import org.apache.struts2.convention.annotation.Result;
25
import org.apache.struts2.convention.annotation.Result;
24
import org.apache.struts2.convention.annotation.Results;
26
import org.apache.struts2.convention.annotation.Results;
25
import org.apache.struts2.interceptor.ParameterAware;
27
import org.apache.struts2.interceptor.ParameterAware;
26
import org.apache.struts2.rest.DefaultHttpHeaders;
28
import org.apache.struts2.rest.DefaultHttpHeaders;
27
import org.apache.struts2.rest.HttpHeaders;
29
import org.apache.struts2.rest.HttpHeaders;
-
 
30
import org.apache.velocity.VelocityContext;
28
 
31
 
29
/**
32
/**
30
 * @author rajveer
33
 * @author rajveer
31
 *
34
 *
32
 */
35
 */
33
 
36
 
-
 
37
@Results({
-
 
38
    @Result(name="success", type="redirectAction", 
-
 
39
    		params = {"actionName" , "personal-details"})
-
 
40
})
-
 
41
 
34
public class PersonalDetailsController extends BaseController 
42
public class PersonalDetailsController extends BaseController {
35
	implements ParameterAware {
-
 
36
 
43
 
37
	
44
	
38
	/**
45
	/**
39
	 * 
46
	 * 
40
	 */
47
	 */
41
	private static Log log = LogFactory.getLog(PersonalDetailsController.class);
48
	private static Log log = LogFactory.getLog(PersonalDetailsController.class);
42
	
49
	
43
	private Map<String,String> htmlSnippets;
50
	private Map<String,String> htmlSnippets = new HashMap<String, String>();
-
 
51
	
-
 
52
	private Map<String,String> velocityParams = new HashMap<String, String>();
44
	/**
53
	/**
45
	 * 
54
	 * 
46
	 */
55
	 */
47
	
56
	
48
	
-
 
49
	private Map<String, String[]> reqparams;
-
 
50
	
-
 
51
	private String id;
-
 
52
	
-
 
53
	private int action;
-
 
54
	
-
 
55
	
-
 
56
	public PersonalDetailsController() {
57
	public PersonalDetailsController() {
57
		super();
58
		super();
58
	}
59
	}
59
	
60
	
60
    // POST /logindetails
61
    // POST /logindetails
61
    public String create() {
62
    public String create() {
62
    	log.info("PersonaldetailsController.create");
63
    	log.info("PersonaldetailsController.create");
63
 
64
 
64
		
-
 
65
		String name = this.request.getParameter("txtName");
-
 
66
		String dateOfBirth = this.request.getParameter("dateOfBirth");
-
 
67
		String sex = this.request.getParameter("sex");
-
 
68
		String communicationEmail = this.request.getParameter("txtCommEmail");
-
 
69
		String subscribeNewsletter = this.request.getParameter("subscribe");
-
 
70
		
-
 
71
		if(this.userinfo.isLoggedIn()){
65
		if(this.userinfo.isLoggedIn()){
-
 
66
			String name = this.request.getParameter("txtName");
-
 
67
			String dateOfBirth = this.request.getParameter("dateOfBirth");
-
 
68
			String sex = this.request.getParameter("sex");
-
 
69
			String communicationEmail = this.request.getParameter("txtCommEmail");
-
 
70
			String subscribeNewsletter = this.request.getParameter("subscribe");
-
 
71
			String phone = this.request.getParameter("txtPhone");
-
 
72
			
72
			if(Utils.UpdatePersonalDetails(userinfo.getUserId(), name, dateOfBirth,sex,communicationEmail,subscribeNewsletter))
73
			if(Utils.UpdatePersonalDetails(userinfo.getUserId(), name, phone, dateOfBirth, sex,communicationEmail,subscribeNewsletter))
73
			{
74
			{	
-
 
75
				addActionMessage("Your personal details updated");
74
				return "success";
76
				return "success";
75
			}
77
			}
76
    	}
78
    	}
-
 
79
		addActionError("Unable to update your personal details");
77
		return "failure";
80
		return "success";
78
    }
81
    }
79
 
82
 
80
    
83
    
81
    // GET /test
84
    // GET /test
82
    public HttpHeaders index() throws UnsupportedEncodingException {
85
    public String index() throws UnsupportedEncodingException {
83
    	log.info("this.request=" + this.request);
86
    	log.info("this.request=" + this.request);
84
    	
87
    	
85
    	String userId = "";
88
    	
86
    	
89
    	
87
    	if(this.userinfo.isLoggedIn()){
90
    	if(this.userinfo.isLoggedIn()){
88
    		userId = (new Long(this.userinfo.getUserId())).toString();
91
    		long userId = this.userinfo.getUserId();
89
			Map<PageContentKeys, String> params = new HashMap<PageContentKeys, String>();
92
    		PageLoaderHandler pageLoader = new PageLoaderHandler();
-
 
93
    		
-
 
94
    		
-
 
95
    		htmlSnippets.put("HEADER", pageLoader.getHeaderHtml(this.userinfo.isLoggedIn(), this.userinfo.getNameOfUser()));
-
 
96
    		htmlSnippets.put("MAIN_MENU", pageLoader.getMainMenuHtml());
-
 
97
    		
90
			params.put(PageContentKeys.CUSTOMER_ID, userId);
98
    		htmlSnippets.put("MAIN_MENU", pageLoader.getMainMenuHtml());
91
			params.put(PageContentKeys.ITEM_COUNT, userinfo.getTotalItems()+"");
99
    		htmlSnippets.put("SEARCH_BAR", pageLoader.getSearchBarHtml(userinfo.getTotalItems(), 0));
92
			params.put(PageContentKeys.USER_NAME, userinfo.getNameOfUser());
100
    		htmlSnippets.put("MYACCOUNT_HEADER", pageLoader.getMyaccountHeaderHtml());
93
			params.put(PageContentKeys.IS_LOGGED_IN, userinfo.isLoggedIn()+"");
101
    		htmlSnippets.put("PERSONAL_DETAILS", pageLoader.getPersonalDetailsHtml(userinfo.getUserId()));
94
			
-
 
-
 
102
    		htmlSnippets.put("CUSTOMER_SERVICE", pageLoader.getCustomerServiceHtml());
95
			htmlSnippets = PageManager.getPageManager().getPageContents(PageEnum.PERSONAL_DETAILS_PAGE, params);
103
    		htmlSnippets.put("MY_RESEARCH", pageLoader.getMyResearchHtml(userinfo.getUserId(), true));
-
 
104
    		htmlSnippets.put("BROWSE_HISTORY", pageLoader.getBrowseHistoryHtml(userinfo.getUserId(), userinfo.isLoggedIn()));
96
			return new DefaultHttpHeaders("index").disableCaching();
105
    		htmlSnippets.put("FOOTER", pageLoader.getFooterHtml());
-
 
106
			return "index";
97
    	
107
    	
98
    	}else{
108
    	}else{
99
    		return new DefaultHttpHeaders("login").disableCaching();
109
    		return "failure";
100
    	}
110
    	}
101
    	
111
    	
102
    }
112
    }
103
    
113
    
-
 
114
    
-
 
115
    public Map<String, String> getVelocityParams(){
-
 
116
    	UserContextServiceClient userContextServiceClient = null;
-
 
117
		in.shop2020.model.v1.user.UserContextService.Client userClient = null;
-
 
118
		try{
-
 
119
			User user = null;
-
 
120
			userContextServiceClient = new UserContextServiceClient();
-
 
121
			userClient = userContextServiceClient.getClient();
-
 
122
			user = userClient.getUserById(userinfo.getUserId());
-
 
123
			
-
 
124
			velocityParams.put("email", user.getCommunicationEmail());
-
 
125
			velocityParams.put("sex", user.getSex().getValue()+"");
-
 
126
			velocityParams.put("name", user.getName());
-
 
127
			velocityParams.put("phone", user.getMobileNumber());
-
 
128
			velocityParams.put("dateOfBirth", user.getDateOfBirth());
-
 
129
		}catch (Exception e){
-
 
130
			e.printStackTrace();
-
 
131
		}
-
 
132
		return velocityParams;
-
 
133
	}
-
 
134
    
104
    public String getHeaderSnippet(){
135
    public String getHeaderSnippet(){
105
		return htmlSnippets.get("HEADER");
136
		return htmlSnippets.get("HEADER");
106
	}
137
	}
107
	
138
	
108
	public String getMainMenuSnippet(){
139
	public String getMainMenuSnippet(){
Line 127... Line 158...
127
	}
158
	}
128
	
159
	
129
	public String getMyResearchSnippet(){
160
	public String getMyResearchSnippet(){
130
		return htmlSnippets.get("MY_RESEARCH");
161
		return htmlSnippets.get("MY_RESEARCH");
131
	}
162
	}
-
 
163
	
-
 
164
	public String getBrowseHistorySnippet(){
-
 
165
		return htmlSnippets.get("BROWSE_HISTORY");
132
				
166
	}
-
 
167
	
133
	public String getFooterSnippet(){
168
	public String getFooterSnippet(){
134
		return htmlSnippets.get("FOOTER");
169
		return htmlSnippets.get("FOOTER");
135
	}
170
	}
136
	
171
	
137
	public String getJsFileSnippet(){
172
	public String getJsFileSnippet(){
Line 139... Line 174...
139
	}
174
	}
140
	
175
	
141
	public String getCssFileSnippet(){
176
	public String getCssFileSnippet(){
142
		return htmlSnippets.get("CSS_FILES");
177
		return htmlSnippets.get("CSS_FILES");
143
	}
178
	}
144
	
-
 
145
    /**
-
 
146
     * 
-
 
147
     * @param id
-
 
148
     */
-
 
149
    public void setId(String id) {
-
 
150
        this.id = id;
-
 
151
    }
-
 
152
 
-
 
153
    
-
 
154
    /**
-
 
155
     * 
-
 
156
     */
-
 
157
//    @Override
-
 
158
//	public void setServletRequest(HttpServletRequest request) {
-
 
159
//		this.request = request;
-
 
160
//	}
-
 
161
 
-
 
162
    
-
 
163
	@Override
-
 
164
	public void setParameters(Map<String, String[]> reqmap) {
-
 
165
		log.info("setParameters:" + reqmap);
-
 
166
		
-
 
167
		this.reqparams = reqmap;
-
 
168
	}
-
 
169
 
179
 
170
}
180
}