| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.web.controller;
|
1 |
package com.spice.profitmandi.web.controller;
|
| 2 |
|
2 |
|
| 3 |
import java.lang.reflect.Type;
|
3 |
import java.lang.reflect.Type;
|
| 4 |
import java.time.LocalDateTime;
|
4 |
import java.time.LocalDateTime;
|
| - |
|
5 |
import java.time.ZoneOffset;
|
| 5 |
import java.util.ArrayList;
|
6 |
import java.util.ArrayList;
|
| - |
|
7 |
import java.util.Arrays;
|
| 6 |
import java.util.HashMap;
|
8 |
import java.util.HashMap;
|
| 7 |
import java.util.HashSet;
|
9 |
import java.util.HashSet;
|
| 8 |
import java.util.List;
|
10 |
import java.util.List;
|
| 9 |
import java.util.Map;
|
11 |
import java.util.Map;
|
| 10 |
import java.util.Set;
|
12 |
import java.util.Set;
|
| 11 |
import java.util.stream.Collectors;
|
13 |
import java.util.stream.Collectors;
|
| 12 |
|
14 |
|
| 13 |
import javax.servlet.http.Cookie;
|
15 |
import javax.servlet.http.Cookie;
|
| 14 |
import javax.servlet.http.HttpServletRequest;
|
16 |
import javax.servlet.http.HttpServletRequest;
|
| 15 |
import javax.servlet.http.HttpServletResponse;
|
17 |
import javax.servlet.http.HttpServletResponse;
|
| - |
|
18 |
import javax.transaction.Transactional;
|
| 16 |
|
19 |
|
| 17 |
import org.apache.http.NameValuePair;
|
20 |
import org.apache.http.NameValuePair;
|
| 18 |
import org.apache.http.client.utils.URLEncodedUtils;
|
21 |
import org.apache.http.client.utils.URLEncodedUtils;
|
| 19 |
import org.apache.http.message.BasicNameValuePair;
|
22 |
import org.apache.http.message.BasicNameValuePair;
|
| 20 |
import org.apache.logging.log4j.LogManager;
|
23 |
import org.apache.logging.log4j.LogManager;
|
| 21 |
import org.apache.logging.log4j.Logger;
|
24 |
import org.apache.logging.log4j.Logger;
|
| 22 |
import org.springframework.beans.factory.annotation.Autowired;
|
25 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 23 |
import org.springframework.beans.factory.annotation.Value;
|
26 |
import org.springframework.beans.factory.annotation.Value;
|
| 24 |
import org.springframework.stereotype.Controller;
|
27 |
import org.springframework.stereotype.Controller;
|
| 25 |
import org.springframework.transaction.annotation.Transactional;
|
- |
|
| 26 |
import org.springframework.ui.Model;
|
28 |
import org.springframework.ui.Model;
|
| 27 |
import org.springframework.ui.ModelMap;
|
29 |
import org.springframework.ui.ModelMap;
|
| 28 |
import org.springframework.web.bind.annotation.ModelAttribute;
|
30 |
import org.springframework.web.bind.annotation.ModelAttribute;
|
| 29 |
import org.springframework.web.bind.annotation.PostMapping;
|
31 |
import org.springframework.web.bind.annotation.PostMapping;
|
| 30 |
import org.springframework.web.bind.annotation.RequestBody;
|
32 |
import org.springframework.web.bind.annotation.RequestBody;
|
| Line 44... |
Line 46... |
| 44 |
import com.spice.profitmandi.dao.entity.dtr.Role;
|
46 |
import com.spice.profitmandi.dao.entity.dtr.Role;
|
| 45 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
47 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
| 46 |
import com.spice.profitmandi.dao.entity.dtr.UserAccount;
|
48 |
import com.spice.profitmandi.dao.entity.dtr.UserAccount;
|
| 47 |
import com.spice.profitmandi.dao.entity.dtr.UserRole;
|
49 |
import com.spice.profitmandi.dao.entity.dtr.UserRole;
|
| 48 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
50 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| - |
|
51 |
import com.spice.profitmandi.dao.entity.user.Device;
|
| 49 |
import com.spice.profitmandi.dao.enumuration.dtr.AccountType;
|
52 |
import com.spice.profitmandi.dao.enumuration.dtr.AccountType;
|
| 50 |
import com.spice.profitmandi.dao.enumuration.dtr.RoleType;
|
53 |
import com.spice.profitmandi.dao.enumuration.dtr.RoleType;
|
| 51 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
54 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
| - |
|
55 |
import com.spice.profitmandi.dao.repository.catalog.DeviceRepository;
|
| 52 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
56 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 53 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
|
57 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
|
| 54 |
import com.spice.profitmandi.dao.repository.dtr.RoleRepository;
|
58 |
import com.spice.profitmandi.dao.repository.dtr.RoleRepository;
|
| 55 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
59 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
| 56 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
60 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
| Line 72... |
Line 76... |
| 72 |
@Autowired
|
76 |
@Autowired
|
| 73 |
private GoogleTokenUtil googleTokenUtil;
|
77 |
private GoogleTokenUtil googleTokenUtil;
|
| 74 |
|
78 |
|
| 75 |
@Autowired
|
79 |
@Autowired
|
| 76 |
private RoleManager roleManager;
|
80 |
private RoleManager roleManager;
|
| - |
|
81 |
|
| - |
|
82 |
@Autowired
|
| - |
|
83 |
private DeviceRepository deviceRepository;
|
| 77 |
|
84 |
|
| 78 |
@Autowired
|
85 |
@Autowired
|
| 79 |
private RetailerRepository retailerRepository;
|
86 |
private RetailerRepository retailerRepository;
|
| 80 |
|
87 |
|
| 81 |
@Autowired
|
88 |
@Autowired
|
| Line 152... |
Line 159... |
| 152 |
if (roleManager.isAdmin(fofoDetails.getRoleIds())) {
|
159 |
if (roleManager.isAdmin(fofoDetails.getRoleIds())) {
|
| 153 |
if (emailId.equals("")) {
|
160 |
if (emailId.equals("")) {
|
| 154 |
model.addAttribute("authToken", getToken(fofoDetails.getEmailId()));
|
161 |
model.addAttribute("authToken", getToken(fofoDetails.getEmailId()));
|
| 155 |
} else {
|
162 |
} else {
|
| 156 |
model.addAttribute("authToken", getToken(emailId));
|
163 |
model.addAttribute("authToken", getToken(emailId));
|
| - |
|
164 |
model.addAttribute("androidId", getAndroidId(emailId));
|
| 157 |
}
|
165 |
}
|
| 158 |
}
|
166 |
}
|
| 159 |
return "mobileapp";
|
167 |
return "mobileapp";
|
| 160 |
}
|
168 |
}
|
| 161 |
|
169 |
|
| - |
|
170 |
private String getAndroidId(String emailId) throws Exception {
|
| - |
|
171 |
User user = userRepository.selectByEmailId(emailId);
|
| - |
|
172 |
List<Device> devices = deviceRepository.selectByUserIdAndModifiedTimestamp(Arrays.asList(user.getId()), LocalDateTime.now().minusYears(2), LocalDateTime.now());
|
| - |
|
173 |
Device device = devices.stream().sorted((x,y)->
|
| - |
|
174 |
(int)(
|
| - |
|
175 |
y.getModified().toEpochSecond(ZoneOffset.ofHours(5))
|
| - |
|
176 |
-x.getModified().toEpochSecond(ZoneOffset.ofHours(5))
|
| - |
|
177 |
)
|
| - |
|
178 |
).findFirst().get();
|
| - |
|
179 |
return device.getAndroidId();
|
| - |
|
180 |
}
|
| - |
|
181 |
|
| 162 |
private String getToken(String emailId) throws Exception {
|
182 |
private String getToken(String emailId) throws Exception {
|
| 163 |
List<NameValuePair> nameValuePairs = new ArrayList<>();
|
183 |
List<NameValuePair> nameValuePairs = new ArrayList<>();
|
| 164 |
nameValuePairs.add(new BasicNameValuePair("adminToken", "ecip$stgMay2014"));
|
184 |
nameValuePairs.add(new BasicNameValuePair("adminToken", "ecip$stgMay2014"));
|
| 165 |
nameValuePairs.add(new BasicNameValuePair("emailId", emailId));
|
185 |
nameValuePairs.add(new BasicNameValuePair("emailId", emailId));
|
| 166 |
String queryString = URLEncodedUtils.format(nameValuePairs, "UTF-8");
|
186 |
String queryString = URLEncodedUtils.format(nameValuePairs, "UTF-8");
|