| 23781 |
ashik.ali |
1 |
package com.spice.profitmandi.service.user;
|
| 21525 |
amit.gupta |
2 |
|
| 22845 |
amit.gupta |
3 |
import java.time.LocalDateTime;
|
| 23204 |
ashik.ali |
4 |
import java.util.HashMap;
|
| 23984 |
govind |
5 |
import java.util.HashSet;
|
|
|
6 |
import java.util.List;
|
| 23204 |
ashik.ali |
7 |
import java.util.Map;
|
| 22845 |
amit.gupta |
8 |
|
| 21525 |
amit.gupta |
9 |
import org.hibernate.Criteria;
|
|
|
10 |
import org.hibernate.Session;
|
|
|
11 |
import org.hibernate.SessionFactory;
|
|
|
12 |
import org.hibernate.criterion.Restrictions;
|
|
|
13 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 23781 |
ashik.ali |
14 |
import org.springframework.beans.factory.annotation.Qualifier;
|
| 21525 |
amit.gupta |
15 |
import org.springframework.stereotype.Component;
|
| 22038 |
amit.gupta |
16 |
import org.springframework.transaction.annotation.Transactional;
|
| 21525 |
amit.gupta |
17 |
|
| 23204 |
ashik.ali |
18 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
|
|
19 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 24099 |
amit.gupta |
20 |
import com.spice.profitmandi.common.util.DesEncrypter;
|
| 22020 |
ashik.ali |
21 |
import com.spice.profitmandi.dao.entity.dtr.ActivationCode;
|
| 21729 |
ashik.ali |
22 |
import com.spice.profitmandi.dao.entity.dtr.Retailer;
|
| 23781 |
ashik.ali |
23 |
import com.spice.profitmandi.dao.entity.dtr.Role;
|
| 21729 |
ashik.ali |
24 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
| 23273 |
ashik.ali |
25 |
import com.spice.profitmandi.dao.entity.dtr.UserAccount;
|
| 23204 |
ashik.ali |
26 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
|
|
27 |
import com.spice.profitmandi.dao.enumuration.dtr.AccountType;
|
|
|
28 |
import com.spice.profitmandi.dao.enumuration.dtr.RoleType;
|
|
|
29 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 21729 |
ashik.ali |
30 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
|
| 23781 |
ashik.ali |
31 |
import com.spice.profitmandi.dao.repository.dtr.RoleRepository;
|
| 23204 |
ashik.ali |
32 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
| 21729 |
ashik.ali |
33 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
| 23204 |
ashik.ali |
34 |
import com.spice.profitmandi.dao.repository.dtr.UserRoleRepository;
|
| 21525 |
amit.gupta |
35 |
import com.spice.profitmandi.thrift.clients.TransactionClient;
|
|
|
36 |
|
|
|
37 |
import in.shop2020.model.v1.order.TransactionService;
|
|
|
38 |
|
|
|
39 |
@Component
|
| 22038 |
amit.gupta |
40 |
@Transactional(rollbackFor=Throwable.class)
|
| 21525 |
amit.gupta |
41 |
public class UserServiceImpl implements UserService {
|
|
|
42 |
|
|
|
43 |
@Autowired
|
| 22931 |
ashik.ali |
44 |
private SessionFactory sessionFactory;
|
| 21525 |
amit.gupta |
45 |
|
|
|
46 |
@Autowired
|
| 23781 |
ashik.ali |
47 |
@Qualifier(value = "userRepository")
|
| 23204 |
ashik.ali |
48 |
private UserRepository userRepository;
|
| 21525 |
amit.gupta |
49 |
|
|
|
50 |
@Autowired
|
| 24099 |
amit.gupta |
51 |
@Qualifier(value = "userUserRepository")
|
|
|
52 |
private com.spice.profitmandi.dao.repository.user.UserRepository userUserRepository;
|
|
|
53 |
|
|
|
54 |
@Autowired
|
| 23204 |
ashik.ali |
55 |
private RetailerRepository retailerRepo;
|
| 21525 |
amit.gupta |
56 |
|
| 23204 |
ashik.ali |
57 |
@Autowired
|
|
|
58 |
private FofoStoreRepository fofoStoreRepository;
|
|
|
59 |
|
|
|
60 |
@Autowired
|
|
|
61 |
private UserAccountRepository userAccountRepository;
|
|
|
62 |
|
|
|
63 |
@Autowired
|
|
|
64 |
private UserRoleRepository userRoleRepository;
|
|
|
65 |
|
| 23781 |
ashik.ali |
66 |
@Autowired
|
|
|
67 |
private RoleRepository roleRepository;
|
|
|
68 |
|
| 24099 |
amit.gupta |
69 |
private static final DesEncrypter encrypter = new DesEncrypter("saholic");
|
|
|
70 |
|
|
|
71 |
|
| 23204 |
ashik.ali |
72 |
@SuppressWarnings("deprecation")
|
| 21525 |
amit.gupta |
73 |
@Override
|
|
|
74 |
public boolean updateActivation(int userId, int retailerId, String activationCode) throws Throwable {
|
|
|
75 |
|
|
|
76 |
TransactionClient transactionServiceClient = new TransactionClient();
|
|
|
77 |
TransactionService.Client tsc = transactionServiceClient.getClient();
|
|
|
78 |
boolean registered = tsc.registerRsa(retailerId, activationCode);
|
|
|
79 |
|
|
|
80 |
Session session = sessionFactory.getCurrentSession();
|
|
|
81 |
|
|
|
82 |
if(!registered){
|
|
|
83 |
Criteria cr = session.createCriteria(ActivationCode.class);
|
|
|
84 |
cr.add(Restrictions.eq("code", activationCode)).add(Restrictions.eq("status", true));
|
|
|
85 |
ActivationCode code = (ActivationCode)cr.uniqueResult();
|
|
|
86 |
if(code==null) {
|
|
|
87 |
return false;
|
|
|
88 |
} else {
|
|
|
89 |
registered=true;
|
|
|
90 |
code.setStatus(false);
|
|
|
91 |
session.update(code);
|
|
|
92 |
}
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
if(registered) {
|
| 23204 |
ashik.ali |
96 |
User user = userRepository.selectById(userId);
|
| 21525 |
amit.gupta |
97 |
user.setActivated(true);
|
| 22845 |
amit.gupta |
98 |
user.setActivationTime(LocalDateTime.now());
|
| 21525 |
amit.gupta |
99 |
user.setReferrer(activationCode);
|
|
|
100 |
session.update(user);
|
|
|
101 |
|
|
|
102 |
Retailer retailer = retailerRepo.selectById(retailerId);
|
|
|
103 |
retailer.setActive(true);
|
|
|
104 |
session.update(retailer);
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
return registered;
|
|
|
108 |
}
|
| 22845 |
amit.gupta |
109 |
|
|
|
110 |
|
|
|
111 |
@Override
|
|
|
112 |
public boolean createActivationCode(int userId) throws Throwable {
|
|
|
113 |
// TODO Auto-generated method stub
|
|
|
114 |
return false;
|
|
|
115 |
}
|
| 23204 |
ashik.ali |
116 |
|
|
|
117 |
@Override
|
|
|
118 |
public Map<String, String> getEmailsAndFofoStoreCodeByUserId(int userId) throws ProfitMandiBusinessException {
|
|
|
119 |
User user = userRepository.selectById(userId);
|
| 23273 |
ashik.ali |
120 |
UserAccount userAccount = userAccountRepository.selectByUserIdType(userId, AccountType.saholic);
|
| 23781 |
ashik.ali |
121 |
Role role = roleRepository.selectByName(RoleType.FOFO.toString());
|
| 23204 |
ashik.ali |
122 |
Map<String, String> map = new HashMap<>();
|
|
|
123 |
map.put(ProfitMandiConstants.EMAIL_ID, user.getEmailId());
|
|
|
124 |
map.put(ProfitMandiConstants.SECONDRY_EMAIL_ID, user.getSecondryEmailId());
|
| 23781 |
ashik.ali |
125 |
userRoleRepository.selectByUserIdAndRoleId(userId, role.getId());
|
| 23273 |
ashik.ali |
126 |
FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(userAccount.getAccountKey());
|
| 23204 |
ashik.ali |
127 |
map.put(ProfitMandiConstants.CODE, fofoStore.getCode());
|
|
|
128 |
return map;
|
|
|
129 |
}
|
| 23984 |
govind |
130 |
|
|
|
131 |
|
|
|
132 |
@Override
|
|
|
133 |
public Map<Integer, String> getAllUseUserIdEmailIdMap(List<Integer> userIds) {
|
|
|
134 |
Map<Integer, String> userIdEmailIdMap=new HashMap<>();
|
|
|
135 |
List<User> users=userRepository.selectAllByIds(new HashSet<>(userIds));
|
|
|
136 |
for(User user:users)
|
|
|
137 |
{
|
|
|
138 |
userIdEmailIdMap.put(user.getId(),user.getEmailId());
|
|
|
139 |
}
|
|
|
140 |
return userIdEmailIdMap;
|
|
|
141 |
}
|
| 24099 |
amit.gupta |
142 |
|
|
|
143 |
|
|
|
144 |
@Override
|
|
|
145 |
public User authenticate(String emailMobile, String password) throws ProfitMandiBusinessException {
|
|
|
146 |
User user = userRepository.selectByEmailIdOrMobileNumber(emailMobile);
|
|
|
147 |
if(!user.getPassword().equals(encrypter.decrypt(password))) {
|
|
|
148 |
throw new ProfitMandiBusinessException("Username Password", emailMobile, "Invalid Username or Password");
|
|
|
149 |
}
|
|
|
150 |
return user;
|
|
|
151 |
}
|
|
|
152 |
|
|
|
153 |
|
|
|
154 |
@Override
|
|
|
155 |
public boolean resetPassword(String emailMobile, String password) throws ProfitMandiBusinessException {
|
|
|
156 |
User user = userRepository.selectByEmailIdOrMobileNumber(emailMobile);
|
|
|
157 |
user.setPassword(encrypter.encrypt(password));
|
|
|
158 |
userRepository.persist(user);
|
|
|
159 |
return true;
|
|
|
160 |
}
|
| 23781 |
ashik.ali |
161 |
|
| 21525 |
amit.gupta |
162 |
}
|