Subversion Repositories SmartDukaan

Rev

Rev 30202 | Rev 30546 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 30202 Rev 30295
Line 1... Line 1...
1
package com.spice.profitmandi.web.controller;
1
package com.spice.profitmandi.web.controller;
2
 
2
 
3
import java.io.IOException;
-
 
4
import java.io.UnsupportedEncodingException;
-
 
5
import java.time.LocalDate;
-
 
6
import java.time.LocalDateTime;
-
 
7
import java.time.YearMonth;
-
 
8
import java.time.ZoneOffset;
-
 
9
import java.util.ArrayList;
-
 
10
import java.util.Base64;
-
 
11
import java.util.HashMap;
-
 
12
import java.util.HashSet;
-
 
13
import java.util.List;
-
 
14
import java.util.Map;
-
 
15
import java.util.Set;
-
 
16
import java.util.stream.Collectors;
-
 
17
 
-
 
18
import javax.mail.MessagingException;
-
 
19
import javax.mail.internet.InternetAddress;
-
 
20
import javax.mail.internet.MimeMessage;
-
 
21
import javax.servlet.http.HttpServletRequest;
-
 
22
 
-
 
23
import org.apache.http.client.ClientProtocolException;
-
 
24
import org.apache.logging.log4j.LogManager;
-
 
25
import org.apache.logging.log4j.Logger;
-
 
26
import org.springframework.beans.factory.annotation.Autowired;
-
 
27
import org.springframework.beans.factory.annotation.Value;
-
 
28
import org.springframework.http.MediaType;
-
 
29
import org.springframework.http.ResponseEntity;
-
 
30
import org.springframework.mail.javamail.JavaMailSender;
-
 
31
import org.springframework.mail.javamail.MimeMessageHelper;
-
 
32
import org.springframework.stereotype.Controller;
-
 
33
import org.springframework.transaction.annotation.Transactional;
-
 
34
import org.springframework.web.bind.annotation.PathVariable;
-
 
35
import org.springframework.web.bind.annotation.RequestBody;
-
 
36
import org.springframework.web.bind.annotation.RequestMapping;
-
 
37
import org.springframework.web.bind.annotation.RequestMethod;
-
 
38
import org.springframework.web.bind.annotation.RequestParam;
-
 
39
 
-
 
40
import com.fasterxml.jackson.annotation.JsonProperty;
3
import com.fasterxml.jackson.annotation.JsonProperty;
41
import com.fasterxml.jackson.databind.ObjectMapper;
4
import com.fasterxml.jackson.databind.ObjectMapper;
42
import com.google.gson.Gson;
-
 
43
import com.spice.profitmandi.common.ResponseCodeHolder;
5
import com.spice.profitmandi.common.ResponseCodeHolder;
44
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
6
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
45
import com.spice.profitmandi.common.model.CustomRetailer;
-
 
46
import com.spice.profitmandi.common.model.GoogleLoginRequest;
-
 
47
import com.spice.profitmandi.common.model.ProfitMandiConstants;
-
 
48
import com.spice.profitmandi.common.model.RegisteredUserInfo;
-
 
49
import com.spice.profitmandi.common.model.UserInfo;
7
import com.spice.profitmandi.common.model.*;
50
import com.spice.profitmandi.common.util.JWTUtil;
8
import com.spice.profitmandi.common.util.JWTUtil;
-
 
9
import com.spice.profitmandi.common.util.Utils;
51
import com.spice.profitmandi.common.web.client.RestClient;
10
import com.spice.profitmandi.common.web.client.RestClient;
52
import com.spice.profitmandi.common.web.util.ResponseSender;
11
import com.spice.profitmandi.common.web.util.ResponseSender;
53
import com.spice.profitmandi.dao.entity.auth.AuthUser;
12
import com.spice.profitmandi.dao.entity.auth.AuthUser;
54
import com.spice.profitmandi.dao.entity.catalog.FocusedModelByPassRequest;
-
 
55
import com.spice.profitmandi.dao.entity.dtr.MobileAppSetting;
-
 
56
import com.spice.profitmandi.dao.entity.dtr.Retailer;
-
 
57
import com.spice.profitmandi.dao.entity.dtr.Role;
-
 
58
import com.spice.profitmandi.dao.entity.dtr.User;
13
import com.spice.profitmandi.dao.entity.dtr.*;
59
import com.spice.profitmandi.dao.entity.dtr.UserAccount;
-
 
60
import com.spice.profitmandi.dao.entity.dtr.UserRole;
-
 
61
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
14
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
62
import com.spice.profitmandi.dao.entity.fofo.PartnerOnBoardingPanel;
15
import com.spice.profitmandi.dao.entity.fofo.PartnerOnBoardingPanel;
63
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
16
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
64
import com.spice.profitmandi.dao.entity.user.Address;
17
import com.spice.profitmandi.dao.entity.user.Address;
65
import com.spice.profitmandi.dao.entity.user.Promoter;
18
import com.spice.profitmandi.dao.entity.user.Promoter;
66
import com.spice.profitmandi.dao.entity.user.Refferal;
19
import com.spice.profitmandi.dao.entity.user.Refferal;
67
import com.spice.profitmandi.dao.enumuration.catalog.ByPassRequestStatus;
-
 
68
import com.spice.profitmandi.dao.enumuration.dtr.RefferalStatus;
20
import com.spice.profitmandi.dao.enumuration.dtr.RefferalStatus;
69
import com.spice.profitmandi.dao.enumuration.dtr.RoleType;
21
import com.spice.profitmandi.dao.enumuration.dtr.RoleType;
70
import com.spice.profitmandi.dao.enumuration.dtr.StoreTimeline;
-
 
71
import com.spice.profitmandi.dao.enumuration.transaction.PartnerOnBoardingStatus;
22
import com.spice.profitmandi.dao.enumuration.transaction.PartnerOnBoardingStatus;
72
import com.spice.profitmandi.dao.model.CreateRefferalRequest;
23
import com.spice.profitmandi.dao.model.CreateRefferalRequest;
73
import com.spice.profitmandi.dao.model.DateRangeModel;
24
import com.spice.profitmandi.dao.model.DateRangeModel;
74
import com.spice.profitmandi.dao.model.OnBoardingTimelineModel;
-
 
75
import com.spice.profitmandi.dao.model.UserCart;
25
import com.spice.profitmandi.dao.model.UserCart;
76
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
26
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
77
import com.spice.profitmandi.dao.repository.cs.CsService;
27
import com.spice.profitmandi.dao.repository.cs.CsService;
78
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
-
 
79
import com.spice.profitmandi.dao.repository.dtr.MobileAppSettingsRepository;
-
 
80
import com.spice.profitmandi.dao.repository.dtr.PartnerOnBoardingPanelRepository;
-
 
81
import com.spice.profitmandi.dao.repository.dtr.RefferalRepository;
-
 
82
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
-
 
83
import com.spice.profitmandi.dao.repository.dtr.RoleRepository;
-
 
84
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
-
 
85
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
28
import com.spice.profitmandi.dao.repository.dtr.*;
86
import com.spice.profitmandi.dao.repository.dtr.UserRoleRepository;
-
 
87
import com.spice.profitmandi.dao.repository.fofo.PartnerTypeChangeService;
29
import com.spice.profitmandi.dao.repository.fofo.PartnerTypeChangeService;
88
import com.spice.profitmandi.dao.repository.user.AddressRepository;
30
import com.spice.profitmandi.dao.repository.user.AddressRepository;
89
import com.spice.profitmandi.dao.repository.user.PromoterRepository;
31
import com.spice.profitmandi.dao.repository.user.PromoterRepository;
90
import com.spice.profitmandi.service.AuthService;
32
import com.spice.profitmandi.service.AuthService;
91
import com.spice.profitmandi.service.authentication.RoleManager;
33
import com.spice.profitmandi.service.authentication.RoleManager;
Line 97... Line 39...
97
import com.spice.profitmandi.web.processor.GoogleLoginProcessor;
39
import com.spice.profitmandi.web.processor.GoogleLoginProcessor;
98
import com.spice.profitmandi.web.req.RefferalEarning;
40
import com.spice.profitmandi.web.req.RefferalEarning;
99
import com.spice.profitmandi.web.req.RefferalEarningModel;
41
import com.spice.profitmandi.web.req.RefferalEarningModel;
100
import com.spice.profitmandi.web.req.UserRequest;
42
import com.spice.profitmandi.web.req.UserRequest;
101
import com.spice.profitmandi.web.res.Partner;
43
import com.spice.profitmandi.web.res.Partner;
102
 
-
 
103
import io.swagger.annotations.ApiImplicitParam;
44
import io.swagger.annotations.ApiImplicitParam;
104
import io.swagger.annotations.ApiImplicitParams;
45
import io.swagger.annotations.ApiImplicitParams;
-
 
46
import org.apache.http.client.ClientProtocolException;
-
 
47
import org.apache.logging.log4j.LogManager;
-
 
48
import org.apache.logging.log4j.Logger;
-
 
49
import org.springframework.beans.factory.annotation.Autowired;
-
 
50
import org.springframework.beans.factory.annotation.Value;
-
 
51
import org.springframework.http.MediaType;
-
 
52
import org.springframework.http.ResponseEntity;
-
 
53
import org.springframework.mail.javamail.JavaMailSender;
-
 
54
import org.springframework.mail.javamail.MimeMessageHelper;
-
 
55
import org.springframework.stereotype.Controller;
-
 
56
import org.springframework.transaction.annotation.Transactional;
-
 
57
import org.springframework.web.bind.annotation.*;
-
 
58
 
-
 
59
import javax.mail.MessagingException;
-
 
60
import javax.mail.internet.InternetAddress;
-
 
61
import javax.mail.internet.MimeMessage;
-
 
62
import javax.servlet.http.HttpServletRequest;
-
 
63
import java.io.IOException;
-
 
64
import java.io.UnsupportedEncodingException;
-
 
65
import java.time.LocalDate;
-
 
66
import java.time.LocalDateTime;
-
 
67
import java.time.YearMonth;
-
 
68
import java.time.ZoneOffset;
-
 
69
import java.util.*;
-
 
70
import java.util.stream.Collectors;
105
 
71
 
106
/**
72
/**
107
 * @author ashikali
73
 * @author ashikali
108
 *
-
 
109
 */
74
 */
110
@Controller
75
@Controller
111
@Transactional(rollbackFor = Throwable.class)
76
@Transactional(rollbackFor = Throwable.class)
112
public class UserController {
77
public class UserController {
113
 
78
 
Line 188... Line 153...
188
	@Autowired
153
	@Autowired
189
	JavaMailSender mailSender;
154
	JavaMailSender mailSender;
190
 
155
 
191
	@RequestMapping(value = ProfitMandiConstants.URL_USER_GOOGLE_LOGIN, method = RequestMethod.POST)
156
	@RequestMapping(value = ProfitMandiConstants.URL_USER_GOOGLE_LOGIN, method = RequestMethod.POST)
192
	public ResponseEntity<?> googleLogin(HttpServletRequest request, @RequestBody GoogleLoginRequest googleLoginRequest)
157
	public ResponseEntity<?> googleLogin(HttpServletRequest request, @RequestBody GoogleLoginRequest googleLoginRequest)
193
			throws ProfitMandiBusinessException {
158
			throws Exception {
194
		return responseSender.ok(googleLoginProcessor.process(googleLoginRequest.getToken()));
159
		String email = googleLoginProcessor.process(googleLoginRequest.getToken());
-
 
160
		return responseSender.ok(getAuthTokenMap(email));
-
 
161
	}
-
 
162
 
-
 
163
	private Map<String, Object> getAuthTokenMap(String email) throws Exception {
-
 
164
		String name = authService.getNameByEmailId(email);
-
 
165
 
-
 
166
		Map<String, Object> responseMap = new HashMap<>(2);
-
 
167
		LOGGER.info("User Name from getNameByEmailId({}) is {}", email, name);
-
 
168
		if (name != null) {
-
 
169
			User registeredUser = null;
-
 
170
			AuthUser authUser = authRepository.selectByGmailId(email);
-
 
171
 
-
 
172
			if (authRepository.selectByGmailId(email) != null) {
-
 
173
				registeredUser = userRepository.selectByEmailId(authUser.getEmailId());
-
 
174
			} else if (promoterRepository.isExistByEmailId(email)) {
-
 
175
				Promoter promoter = promoterRepository.selectByEmailId(email);
-
 
176
				int userId = userAccountRepository.selectUserIdByRetailerId(promoter.getRetailerId());
-
 
177
				registeredUser = userRepository.selectById(userId);
-
 
178
			} else if (userRepository.isExistBySecondryEmailId(email)) {
-
 
179
				registeredUser = userRepository.selectBySecondryEmailId(email);
-
 
180
			}
-
 
181
			LOGGER.info("4");
-
 
182
			List<Integer> roleIds = userRoleRepository.selectRoleIdsByUserId(registeredUser.getId());
-
 
183
			String[] roleTypes = new String[roleIds.size()];
-
 
184
			int index = 0;
-
 
185
			for (int roleId : roleIds) {
-
 
186
				roleTypes[index++] = String.valueOf(roleId);
-
 
187
			}
-
 
188
			int retailerId;
-
 
189
			try {
-
 
190
				retailerId = userAccountRepository.selectRetailerIdByUserId(registeredUser.getId());
-
 
191
			} catch (Exception e) {
-
 
192
				Set<Integer> authUserPartnerSet = csService.getAuthUserPartnerIdMapping().get(authUser.getEmailId());
-
 
193
				if (authUserPartnerSet != null && authUserPartnerSet.size() > 0) {
-
 
194
					retailerId = authUserPartnerSet.stream().findFirst().get();
-
 
195
					FofoStore fs = fofoStoreRepository.selectByRetailerId(retailerId);
-
 
196
					retailerId = ProfitMandiConstants.WAREHOUSE_NSSPL_PARTNER_MAP.get(fs.getWarehouseId());
-
 
197
				} else {
-
 
198
					com.spice.profitmandi.dao.entity.user.User user = userUserRepository.selectByEmailId(Utils.SYSTEM_PARTNER);
-
 
199
					retailerId = user.getId();
-
 
200
				}
-
 
201
			}
-
 
202
			responseMap.put(ProfitMandiConstants.TOKEN,
-
 
203
					JWTUtil.create(email, registeredUser.getId(), retailerId, roleTypes));
-
 
204
			LOGGER.info(
-
 
205
					"Param value for email, registeredUser.getId(), retailerId, roleTypes are {}, {}, {} and {}",
-
 
206
					email, registeredUser.getId(), retailerId, Arrays.asList(roleTypes));
-
 
207
			responseMap.put(ProfitMandiConstants.REGISTERED, true);
-
 
208
			return responseMap;
-
 
209
		}
-
 
210
 
-
 
211
		User user = null;
-
 
212
		try {
-
 
213
			user = userRepository.selectByEmailId(email);
-
 
214
		} catch (ProfitMandiBusinessException profitMandiBusinessException) {
-
 
215
 
-
 
216
		}
-
 
217
		if (user == null) {
-
 
218
			try {
-
 
219
				user = userRepository.selectByEmailId(email);
-
 
220
			} catch (ProfitMandiBusinessException profitMandiBusinessException) {
-
 
221
				responseMap.put(ProfitMandiConstants.TOKEN, JWTUtil.create(email));
-
 
222
				responseMap.put(ProfitMandiConstants.REGISTERED, false);
-
 
223
			}
-
 
224
		} else {
-
 
225
			List<Integer> roleIds = userRoleRepository.selectRoleIdsByUserId(user.getId());
-
 
226
			int retailerId = userAccountRepository.selectRetailerIdByUserId(user.getId());
-
 
227
			String[] roleTypes = new String[roleIds.size()];
-
 
228
			int index = 0;
-
 
229
			for (int roleId : roleIds) {
-
 
230
				roleTypes[index++] = String.valueOf(roleId);
-
 
231
			}
-
 
232
			responseMap.put(ProfitMandiConstants.TOKEN, JWTUtil.create(user.getId(), retailerId, roleTypes));
-
 
233
			responseMap.put(ProfitMandiConstants.REGISTERED, true);
-
 
234
		}
-
 
235
 
-
 
236
		return responseMap;
195
	}
237
	}
196
 
238
 
197
	@RequestMapping(value = "/store/token/{storeCode}", method = RequestMethod.GET)
239
	@RequestMapping(value = "/store/token/{storeCode}", method = RequestMethod.GET)
198
	public ResponseEntity<?> googleLogin(HttpServletRequest request, @PathVariable String storeCode)
240
	public ResponseEntity<?> googleLogin(HttpServletRequest request, @PathVariable String storeCode)
199
			throws ProfitMandiBusinessException {
241
			throws ProfitMandiBusinessException {
Line 208... Line 250...
208
		return responseSender.ok(JWTUtil.isExpired(token));
250
		return responseSender.ok(JWTUtil.isExpired(token));
209
	}
251
	}
210
 
252
 
211
	@RequestMapping(value = ProfitMandiConstants.URL_USER_DETAIL_BY_TOKEN, method = RequestMethod.GET)
253
	@RequestMapping(value = ProfitMandiConstants.URL_USER_DETAIL_BY_TOKEN, method = RequestMethod.GET)
212
	@ApiImplicitParams({
254
	@ApiImplicitParams({
213
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
255
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
214
	public ResponseEntity<?> tokenInfo(HttpServletRequest request) throws Throwable {
256
	public ResponseEntity<?> tokenInfo(HttpServletRequest request) throws Throwable {
215
		Map<String, Object> responseMap = new HashMap<>();
257
		Map<String, Object> responseMap = new HashMap<>();
216
		UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
258
		UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
217
		User user = null;
259
		User user = null;
218
		if (userInfo.getUserId() > -1) {
260
		if (userInfo.getUserId() > -1) {
Line 341... Line 383...
341
		return ri;
383
		return ri;
342
	}
384
	}
343
 
385
 
344
	@RequestMapping(value = ProfitMandiConstants.URL_USER, method = RequestMethod.POST)
386
	@RequestMapping(value = ProfitMandiConstants.URL_USER, method = RequestMethod.POST)
345
	@ApiImplicitParams({
387
	@ApiImplicitParams({
346
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
388
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
347
	public ResponseEntity<?> createUser(HttpServletRequest request, @RequestBody UserRequest userRequest)
389
	public ResponseEntity<?> createUser(HttpServletRequest request, @RequestBody UserRequest userRequest)
348
			throws ProfitMandiBusinessException {
390
			throws ProfitMandiBusinessException {
349
		LOGGER.info("requested url : " + request.getRequestURL().toString());
391
		LOGGER.info("requested url : " + request.getRequestURL().toString());
350
		User user = new User();
392
		User user = new User();
351
		user.setFirstName(userRequest.getFirstName());
393
		user.setFirstName(userRequest.getFirstName());
Line 381... Line 423...
381
		return responseSender.ok(userRepository.selectById(id));
423
		return responseSender.ok(userRepository.selectById(id));
382
	}
424
	}
383
 
425
 
384
	@RequestMapping(value = ProfitMandiConstants.URL_USER_MOBILE_NUMBER, method = RequestMethod.GET)
426
	@RequestMapping(value = ProfitMandiConstants.URL_USER_MOBILE_NUMBER, method = RequestMethod.GET)
385
	public ResponseEntity<?> getByMobileNumber(HttpServletRequest request,
427
	public ResponseEntity<?> getByMobileNumber(HttpServletRequest request,
386
			@RequestParam(name = "mobileNumber") String mobileNumber) throws ProfitMandiBusinessException {
428
											   @RequestParam(name = "mobileNumber") String mobileNumber) throws ProfitMandiBusinessException {
387
		LOGGER.info("requested url : " + request.getRequestURL().toString());
429
		LOGGER.info("requested url : " + request.getRequestURL().toString());
388
		return responseSender.ok(userRepository.selectByMobileNumber(mobileNumber));
430
		return responseSender.ok(userRepository.selectByMobileNumber(mobileNumber));
389
	}
431
	}
390
 
432
 
391
	@ApiImplicitParams({
433
	@ApiImplicitParams({
392
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
434
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
393
	@RequestMapping(value = ProfitMandiConstants.URL_USER_ACTIVATE, method = RequestMethod.POST)
435
	@RequestMapping(value = ProfitMandiConstants.URL_USER_ACTIVATE, method = RequestMethod.POST)
394
	public ResponseEntity<?> activateUser(HttpServletRequest request,
436
	public ResponseEntity<?> activateUser(HttpServletRequest request,
395
			@RequestParam(name = "activationCode") String activationCode) throws Throwable {
437
										  @RequestParam(name = "activationCode") String activationCode) throws Throwable {
396
		int userId = (int) request.getAttribute("userId");
438
		int userId = (int) request.getAttribute("userId");
397
		UserCart uc = userAccountRepository.getUserCart(userId);
439
		UserCart uc = userAccountRepository.getUserCart(userId);
398
		return responseSender.ok(userService.updateActivation(userId, uc.getUserId(), activationCode));
440
		return responseSender.ok(userService.updateActivation(userId, uc.getUserId(), activationCode));
399
	}
441
	}
400
 
442
 
401
	/*
443
	/*
402
	 * @ApiImplicitParams({
444
	 * @ApiImplicitParams({
403
	 * 
445
	 *
404
	 * @ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true,
446
	 * @ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true,
405
	 * dataType = "string", paramType = "header") })
447
	 * dataType = "string", paramType = "header") })
406
	 * 
448
	 *
407
	 * @RequestMapping(value = ProfitMandiConstants.URL_USER_NOTIFICATIONS, method =
449
	 * @RequestMapping(value = ProfitMandiConstants.URL_USER_NOTIFICATIONS, method =
408
	 * RequestMethod.GET) public ResponseEntity<?>
450
	 * RequestMethod.GET) public ResponseEntity<?>
409
	 * getNofitications(HttpServletRequest request,
451
	 * getNofitications(HttpServletRequest request,
410
	 * 
452
	 *
411
	 * @RequestParam(name = "androidId") String androidId, @RequestParam(name =
453
	 * @RequestParam(name = "androidId") String androidId, @RequestParam(name =
412
	 * "pageNumber") int pageNumber,
454
	 * "pageNumber") int pageNumber,
413
	 * 
455
	 *
414
	 * @RequestParam(name = "pageSize") int pageSize) throws
456
	 * @RequestParam(name = "pageSize") int pageSize) throws
415
	 * ProfitMandiBusinessException { int userId = (int)
457
	 * ProfitMandiBusinessException { int userId = (int)
416
	 * request.getAttribute("userId"); String restResponse = null; Map<String,
458
	 * request.getAttribute("userId"); String restResponse = null; Map<String,
417
	 * String> params = new HashMap<>();
459
	 * String> params = new HashMap<>();
418
	 * 
460
	 *
419
	 * String uri = "/getAllNotifications"; params.put("user_id", userId + "");
461
	 * String uri = "/getAllNotifications"; params.put("user_id", userId + "");
420
	 * params.put("android_id", androidId); params.put("limit", pageSize + "");
462
	 * params.put("android_id", androidId); params.put("limit", pageSize + "");
421
	 * params.put("offset", "" + ((pageNumber - 1) * pageSize)); try { restResponse
463
	 * params.put("offset", "" + ((pageNumber - 1) * pageSize)); try { restResponse
422
	 * = restClient.get(SchemeType.HTTP, nodeHost, nodePort, uri, params); } catch
464
	 * = restClient.get(SchemeType.HTTP, nodeHost, nodePort, uri, params); } catch
423
	 * (HttpHostConnectException e) { throw new ProfitMandiBusinessException("", "",
465
	 * (HttpHostConnectException e) { throw new ProfitMandiBusinessException("", "",
424
	 * "Could not Connect to host"); }
466
	 * "Could not Connect to host"); }
425
	 * 
467
	 *
426
	 * JsonArray result_json = Json.parse(restResponse).asArray();
468
	 * JsonArray result_json = Json.parse(restResponse).asArray();
427
	 * 
469
	 *
428
	 * List<Notification> notifications = new ArrayList<>();
470
	 * List<Notification> notifications = new ArrayList<>();
429
	 * 
471
	 *
430
	 * for (JsonValue j : result_json) {
472
	 * for (JsonValue j : result_json) {
431
	 * notifications.add(toNotifiaction(j.asObject())); }
473
	 * notifications.add(toNotifiaction(j.asObject())); }
432
	 * 
474
	 *
433
	 * return responseSender.ok(notifications); }
475
	 * return responseSender.ok(notifications); }
434
	 * 
476
	 *
435
	 * private Notification toNotifiaction(JsonObject jsonObject) { Notification n =
477
	 * private Notification toNotifiaction(JsonObject jsonObject) { Notification n =
436
	 * (Notification) (new Gson().fromJson(jsonObject.toString(),
478
	 * (Notification) (new Gson().fromJson(jsonObject.toString(),
437
	 * Notification.class)); if (n.getStatus().equals("opened") ||
479
	 * Notification.class)); if (n.getStatus().equals("opened") ||
438
	 * n.getStatus().equals("referrer") || n.getStatus().equals("seen")) {
480
	 * n.getStatus().equals("referrer") || n.getStatus().equals("seen")) {
439
	 * n.setSeen(true); } return n; }
481
	 * n.setSeen(true); } return n; }
440
	 */
482
	 */
441
 
483
 
442
	@RequestMapping(value = ProfitMandiConstants.URL_USER_IS_EXIST_MOBILE_NUMBER, method = RequestMethod.GET)
484
	@RequestMapping(value = ProfitMandiConstants.URL_USER_IS_EXIST_MOBILE_NUMBER, method = RequestMethod.GET)
443
	public ResponseEntity<?> isMobileNumberExist(HttpServletRequest request,
485
	public ResponseEntity<?> isMobileNumberExist(HttpServletRequest request,
444
			@RequestParam(name = "mobileNumber") String mobileNumber) {
486
												 @RequestParam(name = "mobileNumber") String mobileNumber) {
445
		LOGGER.info("requested url : " + request.getRequestURL().toString());
487
		LOGGER.info("requested url : " + request.getRequestURL().toString());
446
		return responseSender.ok(userRepository.isExistByMobileNumber(mobileNumber));
488
		return responseSender.ok(userRepository.isExistByMobileNumber(mobileNumber));
447
	}
489
	}
448
 
490
 
449
	@RequestMapping(value = ProfitMandiConstants.URL_USER_EMAIL_ID, method = RequestMethod.GET)
491
	@RequestMapping(value = ProfitMandiConstants.URL_USER_EMAIL_ID, method = RequestMethod.GET)
Line 464... Line 506...
464
		LOGGER.info("requested url : " + request.getRequestURL().toString());
506
		LOGGER.info("requested url : " + request.getRequestURL().toString());
465
		return responseSender.ok(userRoleRepository.selectRolesByUserId(id));
507
		return responseSender.ok(userRoleRepository.selectRolesByUserId(id));
466
	}
508
	}
467
 
509
 
468
	@ApiImplicitParams({
510
	@ApiImplicitParams({
469
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
511
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
470
	@RequestMapping(value = ProfitMandiConstants.URL_USER_SECONDRY_EMAIL_ID_AND_FOFO_STORE_CODE, method = RequestMethod.GET)
512
	@RequestMapping(value = ProfitMandiConstants.URL_USER_SECONDRY_EMAIL_ID_AND_FOFO_STORE_CODE, method = RequestMethod.GET)
471
	public ResponseEntity<?> getSecondryEmailAndStoreCode(HttpServletRequest request)
513
	public ResponseEntity<?> getSecondryEmailAndStoreCode(HttpServletRequest request)
472
			throws ProfitMandiBusinessException {
514
			throws ProfitMandiBusinessException {
473
		LOGGER.info("requested url : " + request.getRequestURL().toString());
515
		LOGGER.info("requested url : " + request.getRequestURL().toString());
474
		int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
516
		int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
475
		return responseSender.ok(userService.getEmailsAndFofoStoreCodeByUserId(userId));
517
		return responseSender.ok(userService.getEmailsAndFofoStoreCodeByUserId(userId));
476
	}
518
	}
477
 
519
 
478
	@ApiImplicitParams({
520
	@ApiImplicitParams({
479
			@ApiImplicitParam(name = "Auth-Token", value = "-Token", required = true, dataType = "string", paramType = "header") })
521
			@ApiImplicitParam(name = "Auth-Token", value = "-Token", required = true, dataType = "string", paramType = "header")})
480
	@RequestMapping(value = ProfitMandiConstants.URL_USER_SECONDRY_EMAIL_ID, method = RequestMethod.PUT)
522
	@RequestMapping(value = ProfitMandiConstants.URL_USER_SECONDRY_EMAIL_ID, method = RequestMethod.PUT)
481
	public ResponseEntity<?> updateSecondryEmailId(HttpServletRequest request,
523
	public ResponseEntity<?> updateSecondryEmailId(HttpServletRequest request,
482
			@RequestParam(name = ProfitMandiConstants.SECONDRY_EMAIL_ID) String secondryEmailId) throws Throwable {
524
												   @RequestParam(name = ProfitMandiConstants.SECONDRY_EMAIL_ID) String secondryEmailId) throws Throwable {
483
		int userId = (int) request.getAttribute("userId");
525
		int userId = (int) request.getAttribute("userId");
484
		User user = userRepository.selectById(userId);
526
		User user = userRepository.selectById(userId);
485
		user.setSecondryEmailId(secondryEmailId);
527
		user.setSecondryEmailId(secondryEmailId);
486
		userRepository.persist(user);
528
		userRepository.persist(user);
487
		return responseSender.ok(ResponseCodeHolder.getMessage("USR_OK_1001"));
529
		return responseSender.ok(ResponseCodeHolder.getMessage("USR_OK_1001"));
488
	}
530
	}
489
 
531
 
490
	@RequestMapping(value = ProfitMandiConstants.URL_ADMIN_TOKEN, method = RequestMethod.POST)
532
	@RequestMapping(value = ProfitMandiConstants.URL_ADMIN_TOKEN, method = RequestMethod.POST)
491
	public ResponseEntity<?> getAdminToken(HttpServletRequest request,
533
	public ResponseEntity<?> getAdminToken(HttpServletRequest request,
492
			@RequestParam(name = "adminToken") String adminToken, @RequestParam(name = "emailId") String emailId) {
534
										   @RequestParam(name = "adminToken") String adminToken, @RequestParam(name = "emailId") String emailId) throws Exception {
493
		LOGGER.info("requested url : " + request.getRequestURL().toString());
535
		LOGGER.info("requested url : " + request.getRequestURL().toString());
494
		if (!adminToken.equals(validAdminToken)) {
536
		if (!adminToken.equals(validAdminToken)) {
495
			return responseSender.forbidden(null);
537
			return responseSender.forbidden(null);
496
		}
538
		}
497
 
539
 
498
		Map<String, Object> responseMap = new HashMap<>(2);
-
 
499
		User user = null;
-
 
500
		try {
-
 
501
			user = userRepository.selectByEmailId(emailId);
-
 
502
		} catch (ProfitMandiBusinessException profitMandiBusinessException) {
-
 
503
 
-
 
504
		}
-
 
505
 
-
 
506
		if (user == null) {
-
 
507
			try {
-
 
508
				user = userRepository.selectBySecondryEmailId(emailId);
-
 
509
			} catch (ProfitMandiBusinessException profitMandiBusinessException) {
-
 
510
 
-
 
511
			}
-
 
512
		}
-
 
513
		if (user != null) {
-
 
514
			int retailerId = 0;
-
 
515
			try {
-
 
516
				retailerId = userAccountRepository.selectRetailerIdByUserId(user.getId());
-
 
517
			} catch (ProfitMandiBusinessException e) {
-
 
518
				// TODO Auto-generated catch block
-
 
519
				e.printStackTrace();
-
 
520
			}
-
 
521
			List<Integer> roleIds = userRoleRepository.selectRoleIdsByUserId(user.getId());
-
 
522
			String[] roleIdsString = new String[roleIds.size()];
-
 
523
			int index = 0;
-
 
524
			for (int roleId : roleIds) {
-
 
525
				roleIdsString[index++] = String.valueOf(roleId);
-
 
526
			}
-
 
527
			responseMap.put(ProfitMandiConstants.TOKEN, JWTUtil.create(user.getId(), retailerId, roleIdsString));
-
 
528
			responseMap.put(ProfitMandiConstants.REGISTERED, true);
-
 
529
		} else {
-
 
530
			responseMap.put(ProfitMandiConstants.TOKEN, JWTUtil.create(emailId));
-
 
531
			responseMap.put(ProfitMandiConstants.REGISTERED, false);
-
 
532
		}
-
 
533
		return responseSender.ok(responseMap);
540
		return responseSender.ok(this.getAuthTokenMap(emailId));
534
 
541
 
535
	}
542
	}
536
 
543
 
537
	@RequestMapping(value = "/mobileappsettings")
544
	@RequestMapping(value = "/mobileappsettings")
538
	public ResponseEntity<?> mobileAppSettings(HttpServletRequest request, @RequestParam(name = "t") int timestamp,
545
	public ResponseEntity<?> mobileAppSettings(HttpServletRequest request, @RequestParam(name = "t") int timestamp,
539
			@RequestParam(name = "imeinumber") String imeinumber)
546
											   @RequestParam(name = "imeinumber") String imeinumber)
540
			throws ProfitMandiBusinessException, ClientProtocolException, IOException {
547
			throws ProfitMandiBusinessException, ClientProtocolException, IOException {
541
 
548
 
542
		final String uri = "http://192.168.158.89/mobileappsettings?t=" + timestamp + "&imeinumber=" + imeinumber;
549
		final String uri = "http://192.168.158.89/mobileappsettings?t=" + timestamp + "&imeinumber=" + imeinumber;
543
		final String BASIC_AUTH = "Basic " + Base64.getEncoder().encodeToString("dtr:dtr18Feb2015".getBytes());
550
		final String BASIC_AUTH = "Basic " + Base64.getEncoder().encodeToString("dtr:dtr18Feb2015".getBytes());
544
		Map<String, String> headers = new HashMap<>();
551
		Map<String, String> headers = new HashMap<>();
Line 551... Line 558...
551
		}
558
		}
552
	}
559
	}
553
 
560
 
554
	@RequestMapping(value = "/mobileappsettings1", method = RequestMethod.POST)
561
	@RequestMapping(value = "/mobileappsettings1", method = RequestMethod.POST)
555
	public ResponseEntity<?> mobileAppSettings1(HttpServletRequest request, @RequestParam(name = "t") int timestamp,
562
	public ResponseEntity<?> mobileAppSettings1(HttpServletRequest request, @RequestParam(name = "t") int timestamp,
556
			@RequestParam(name = "imeinumber") String imeinumber)
563
												@RequestParam(name = "imeinumber") String imeinumber)
557
			throws ProfitMandiBusinessException, ClientProtocolException, IOException {
564
			throws ProfitMandiBusinessException, ClientProtocolException, IOException {
558
		LocalDateTime settingsLastUpdated = LocalDateTime.ofEpochSecond(timestamp, 0, ZoneOffset.ofHoursMinutes(5, 30));
565
		LocalDateTime settingsLastUpdated = LocalDateTime.ofEpochSecond(timestamp, 0, ZoneOffset.ofHoursMinutes(5, 30));
559
		List<MobileAppSetting> mobileAppSettings = mobileAppSettingsRepository.getSettingAftera(settingsLastUpdated);
566
		List<MobileAppSetting> mobileAppSettings = mobileAppSettingsRepository.getSettingAftera(settingsLastUpdated);
560
 
567
 
561
		List<MobileAppSettingsWrapper> mobileSettingsWrappersList = mobileAppSettings.stream()
568
		List<MobileAppSettingsWrapper> mobileSettingsWrappersList = mobileAppSettings.stream()
Line 566... Line 573...
566
		return responseSender.ok(objectMapper.writeValueAsString(wrapper));
573
		return responseSender.ok(objectMapper.writeValueAsString(wrapper));
567
	}
574
	}
568
 
575
 
569
	@RequestMapping(value = "/getPartners", method = RequestMethod.GET)
576
	@RequestMapping(value = "/getPartners", method = RequestMethod.GET)
570
	@ApiImplicitParams({
577
	@ApiImplicitParams({
571
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
578
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
572
	public ResponseEntity<?> getPartners(HttpServletRequest request, @RequestParam(name = "gmailId") String gmailId,
579
	public ResponseEntity<?> getPartners(HttpServletRequest request, @RequestParam(name = "gmailId") String gmailId,
573
			@RequestParam(value = "offset") int offset, @RequestParam(value = "limit") int limit)
580
										 @RequestParam(value = "offset") int offset, @RequestParam(value = "limit") int limit)
574
			throws ProfitMandiBusinessException {
581
			throws ProfitMandiBusinessException {
575
		AuthUser authUser = authRepository.selectByGmailId(gmailId);
582
		AuthUser authUser = authRepository.selectByGmailId(gmailId);
576
 
583
 
577
		Map<String, Set<String>> storeGuyMap = csService.getAuthUserPartnerEmailMapping();
584
		Map<String, Set<String>> storeGuyMap = csService.getAuthUserPartnerEmailMapping();
578
 
585
 
Line 601... Line 608...
601
		return responseSender.ok(partners);
608
		return responseSender.ok(partners);
602
	}
609
	}
603
 
610
 
604
	@RequestMapping(value = "/user/refferal", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
611
	@RequestMapping(value = "/user/refferal", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
605
	@ApiImplicitParams({
612
	@ApiImplicitParams({
606
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
613
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
607
	public ResponseEntity<?> RefferalUser(HttpServletRequest request,
614
	public ResponseEntity<?> RefferalUser(HttpServletRequest request,
608
			@RequestBody CreateRefferalRequest createRefferalRequest) throws Exception {
615
										  @RequestBody CreateRefferalRequest createRefferalRequest) throws Exception {
609
		Refferal refferal = new Refferal();
616
		Refferal refferal = new Refferal();
610
		refferal.setFirstName(createRefferalRequest.getFirstName());
617
		refferal.setFirstName(createRefferalRequest.getFirstName());
611
		refferal.setLastName(createRefferalRequest.getLastName());
618
		refferal.setLastName(createRefferalRequest.getLastName());
612
		refferal.setMobile(createRefferalRequest.getMobile());
619
		refferal.setMobile(createRefferalRequest.getMobile());
613
		refferal.setState(createRefferalRequest.getState());
620
		refferal.setState(createRefferalRequest.getState());
Line 666... Line 673...
666
 
673
 
667
		String subject = "Referral Validate Request for " + refferal.getRefereeEmail();
674
		String subject = "Referral Validate Request for " + refferal.getRefereeEmail();
668
		String messageText = this.getMessageForReferral(refferal);
675
		String messageText = this.getMessageForReferral(refferal);
669
		MimeMessage message = mailSender.createMimeMessage();
676
		MimeMessage message = mailSender.createMimeMessage();
670
		MimeMessageHelper helper = new MimeMessageHelper(message, true);
677
		MimeMessageHelper helper = new MimeMessageHelper(message, true);
671
		String[] email = { "kamini.sharma@smartdukaan.com", "tarun.verma@smartdukaan.com", "sm@smartdukaan.com" };
678
		String[] email = {"kamini.sharma@smartdukaan.com", "tarun.verma@smartdukaan.com", "sm@smartdukaan.com"};
672
		helper.setSubject(subject);
679
		helper.setSubject(subject);
673
		helper.setText(messageText, true);
680
		helper.setText(messageText, true);
674
		helper.setTo(email);
681
		helper.setTo(email);
675
		InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smartdukaan Alerts");
682
		InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smartdukaan Alerts");
676
		helper.setFrom(senderAddress);
683
		helper.setFrom(senderAddress);
Line 708... Line 715...
708
		return sb.toString();
715
		return sb.toString();
709
	}
716
	}
710
 
717
 
711
	@RequestMapping(value = "/user/refferalAmount", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
718
	@RequestMapping(value = "/user/refferalAmount", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
712
	@ApiImplicitParams({
719
	@ApiImplicitParams({
713
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
720
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
714
	public ResponseEntity<?> RefferalAmount(HttpServletRequest request, @RequestParam String refereeEmail)
721
	public ResponseEntity<?> RefferalAmount(HttpServletRequest request, @RequestParam String refereeEmail)
715
			throws Exception {
722
			throws Exception {
716
		LocalDateTime ldt = LocalDate.now().atStartOfDay().withDayOfMonth(16);
723
		LocalDateTime ldt = LocalDate.now().atStartOfDay().withDayOfMonth(16);
717
		DateRangeModel drm = new DateRangeModel();
724
		DateRangeModel drm = new DateRangeModel();
718
		List<RefferalEarningModel> refferAmountModel = new ArrayList<RefferalEarningModel>();
725
		List<RefferalEarningModel> refferAmountModel = new ArrayList<RefferalEarningModel>();
Line 841... Line 848...
841
		re.setRefferalEarningModel(refferAmountModel);
848
		re.setRefferalEarningModel(refferAmountModel);
842
		return responseSender.ok(re);
849
		return responseSender.ok(re);
843
	}
850
	}
844
 
851
 
845
	private RefferalEarningModel refferAmountEarning(long pendingRefferalValue, long confirmedRefferalValue,
852
	private RefferalEarningModel refferAmountEarning(long pendingRefferalValue, long confirmedRefferalValue,
846
			YearMonth yearMonth) {
853
													 YearMonth yearMonth) {
847
		RefferalEarningModel rfm = new RefferalEarningModel();
854
		RefferalEarningModel rfm = new RefferalEarningModel();
848
		rfm.setYearMonth(yearMonth);
855
		rfm.setYearMonth(yearMonth);
849
		rfm.setPendingRefferal(pendingRefferalValue);
856
		rfm.setPendingRefferal(pendingRefferalValue);
850
		rfm.setApprovedRefferal(confirmedRefferalValue);
857
		rfm.setApprovedRefferal(confirmedRefferalValue);
851
		long estimateRefferalValue = pendingRefferalValue + confirmedRefferalValue;
858
		long estimateRefferalValue = pendingRefferalValue + confirmedRefferalValue;
Line 857... Line 864...
857
		return rfm;
864
		return rfm;
858
	}
865
	}
859
 
866
 
860
	@RequestMapping(value = "/user/getReferals", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
867
	@RequestMapping(value = "/user/getReferals", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
861
	@ApiImplicitParams({
868
	@ApiImplicitParams({
862
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
869
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
863
	public ResponseEntity<?> getReferals(HttpServletRequest request, @RequestParam RefferalStatus status)
870
	public ResponseEntity<?> getReferals(HttpServletRequest request, @RequestParam RefferalStatus status)
864
			throws Exception {
871
			throws Exception {
865
		int userId = (int) request.getAttribute("userId");
872
		int userId = (int) request.getAttribute("userId");
866
 
873
 
867
		User user = userRepository.selectById(userId);
874
		User user = userRepository.selectById(userId);
Line 871... Line 878...
871
		return responseSender.ok(refferals);
878
		return responseSender.ok(refferals);
872
	}
879
	}
873
 
880
 
874
	@RequestMapping(value = "/user/partnerTarget", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
881
	@RequestMapping(value = "/user/partnerTarget", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
875
	@ApiImplicitParams({
882
	@ApiImplicitParams({
876
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
883
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
877
	public ResponseEntity<?> PartnerTarget(HttpServletRequest request) throws Exception {
884
	public ResponseEntity<?> PartnerTarget(HttpServletRequest request) throws Exception {
878
		int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
885
		int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
879
		int retailerId = userAccountRepository.selectRetailerIdByUserId(userId);
886
		int retailerId = userAccountRepository.selectRetailerIdByUserId(userId);
880
		PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(retailerId, LocalDate.now());
887
		PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(retailerId, LocalDate.now());
881
 
888
 
882
		return responseSender.ok(partnerType);
889
		return responseSender.ok(partnerType);
883
	}
890
	}
884
 
891
 
885
	@RequestMapping(value = "/user/authUser", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
892
	@RequestMapping(value = "/user/authUser", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
886
	@ApiImplicitParams({
893
	@ApiImplicitParams({
887
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
894
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
888
	public ResponseEntity<?> authUserDetail(HttpServletRequest request, @RequestParam int userId) throws Exception {
895
	public ResponseEntity<?> authUserDetail(HttpServletRequest request, @RequestParam int userId) throws Exception {
889
		User user = userRepository.selectById(userId);
896
		User user = userRepository.selectById(userId);
890
		AuthUser authUser = authRepository.selectByEmailOrMobile(user.getEmailId());
897
		AuthUser authUser = authRepository.selectByEmailOrMobile(user.getEmailId());
891
		return responseSender.ok(authUser);
898
		return responseSender.ok(authUser);
892
	}
899
	}