| 21525 |
amit.gupta |
1 |
package com.spice.profitmandi.service;
|
|
|
2 |
|
| 22845 |
amit.gupta |
3 |
import java.time.LocalDateTime;
|
|
|
4 |
|
| 21525 |
amit.gupta |
5 |
import org.hibernate.Criteria;
|
|
|
6 |
import org.hibernate.Session;
|
|
|
7 |
import org.hibernate.SessionFactory;
|
|
|
8 |
import org.hibernate.criterion.Restrictions;
|
|
|
9 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
10 |
import org.springframework.stereotype.Component;
|
| 22038 |
amit.gupta |
11 |
import org.springframework.transaction.annotation.Transactional;
|
| 21525 |
amit.gupta |
12 |
|
| 22020 |
ashik.ali |
13 |
import com.spice.profitmandi.dao.entity.dtr.ActivationCode;
|
| 21729 |
ashik.ali |
14 |
import com.spice.profitmandi.dao.entity.dtr.Retailer;
|
|
|
15 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
|
|
16 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
|
|
|
17 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
| 21525 |
amit.gupta |
18 |
import com.spice.profitmandi.thrift.clients.TransactionClient;
|
|
|
19 |
|
|
|
20 |
import in.shop2020.model.v1.order.TransactionService;
|
|
|
21 |
|
|
|
22 |
@Component
|
| 22038 |
amit.gupta |
23 |
@Transactional(rollbackFor=Throwable.class)
|
| 21525 |
amit.gupta |
24 |
public class UserServiceImpl implements UserService {
|
|
|
25 |
|
|
|
26 |
@Autowired
|
|
|
27 |
SessionFactory sessionFactory;
|
|
|
28 |
|
|
|
29 |
@Autowired
|
|
|
30 |
UserRepository userRepo;
|
|
|
31 |
|
|
|
32 |
@Autowired
|
|
|
33 |
RetailerRepository retailerRepo;
|
|
|
34 |
|
|
|
35 |
|
|
|
36 |
@Override
|
|
|
37 |
public boolean updateActivation(int userId, int retailerId, String activationCode) throws Throwable {
|
|
|
38 |
|
|
|
39 |
TransactionClient transactionServiceClient = new TransactionClient();
|
|
|
40 |
TransactionService.Client tsc = transactionServiceClient.getClient();
|
|
|
41 |
boolean registered = tsc.registerRsa(retailerId, activationCode);
|
|
|
42 |
|
|
|
43 |
Session session = sessionFactory.getCurrentSession();
|
|
|
44 |
|
|
|
45 |
if(!registered){
|
|
|
46 |
Criteria cr = session.createCriteria(ActivationCode.class);
|
|
|
47 |
cr.add(Restrictions.eq("code", activationCode)).add(Restrictions.eq("status", true));
|
|
|
48 |
ActivationCode code = (ActivationCode)cr.uniqueResult();
|
|
|
49 |
if(code==null) {
|
|
|
50 |
return false;
|
|
|
51 |
} else {
|
|
|
52 |
registered=true;
|
|
|
53 |
code.setStatus(false);
|
|
|
54 |
session.update(code);
|
|
|
55 |
}
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
if(registered) {
|
|
|
59 |
User user = userRepo.selectById(userId);
|
|
|
60 |
user.setActivated(true);
|
| 22845 |
amit.gupta |
61 |
user.setActivationTime(LocalDateTime.now());
|
| 21525 |
amit.gupta |
62 |
user.setReferrer(activationCode);
|
|
|
63 |
session.update(user);
|
|
|
64 |
|
|
|
65 |
Retailer retailer = retailerRepo.selectById(retailerId);
|
|
|
66 |
retailer.setActive(true);
|
|
|
67 |
session.update(retailer);
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
return registered;
|
|
|
71 |
}
|
| 22845 |
amit.gupta |
72 |
|
|
|
73 |
|
|
|
74 |
@Override
|
|
|
75 |
public boolean createActivationCode(int userId) throws Throwable {
|
|
|
76 |
// TODO Auto-generated method stub
|
|
|
77 |
return false;
|
|
|
78 |
}
|
| 21525 |
amit.gupta |
79 |
}
|