| Line 9... |
Line 9... |
| 9 |
import java.util.List;
|
9 |
import java.util.List;
|
| 10 |
import java.util.Map;
|
10 |
import java.util.Map;
|
| 11 |
import java.util.Set;
|
11 |
import java.util.Set;
|
| 12 |
|
12 |
|
| 13 |
import org.apache.commons.io.FileUtils;
|
13 |
import org.apache.commons.io.FileUtils;
|
| 14 |
import org.apache.logging.log4j.Logger;
|
- |
|
| 15 |
import org.apache.logging.log4j.LogManager;
|
14 |
import org.apache.logging.log4j.LogManager;
|
| - |
|
15 |
import org.apache.logging.log4j.Logger;
|
| 16 |
import org.springframework.beans.factory.annotation.Autowired;
|
16 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 17 |
import org.springframework.stereotype.Component;
|
17 |
import org.springframework.stereotype.Component;
|
| 18 |
|
18 |
|
| 19 |
import com.google.gson.Gson;
|
19 |
import com.google.gson.Gson;
|
| 20 |
import com.google.gson.reflect.TypeToken;
|
20 |
import com.google.gson.reflect.TypeToken;
|
| Line 23... |
Line 23... |
| 23 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
23 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 24 |
import com.spice.profitmandi.common.util.FileUtil;
|
24 |
import com.spice.profitmandi.common.util.FileUtil;
|
| 25 |
import com.spice.profitmandi.dao.entity.dtr.Document;
|
25 |
import com.spice.profitmandi.dao.entity.dtr.Document;
|
| 26 |
import com.spice.profitmandi.dao.entity.dtr.Retailer;
|
26 |
import com.spice.profitmandi.dao.entity.dtr.Retailer;
|
| 27 |
import com.spice.profitmandi.dao.entity.dtr.RetailerRegisteredAddress;
|
27 |
import com.spice.profitmandi.dao.entity.dtr.RetailerRegisteredAddress;
|
| - |
|
28 |
import com.spice.profitmandi.dao.entity.dtr.Role;
|
| 28 |
import com.spice.profitmandi.dao.entity.dtr.Shop;
|
29 |
import com.spice.profitmandi.dao.entity.dtr.Shop;
|
| 29 |
import com.spice.profitmandi.dao.entity.dtr.ShopAddress;
|
30 |
import com.spice.profitmandi.dao.entity.dtr.ShopAddress;
|
| 30 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
31 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
| 31 |
import com.spice.profitmandi.dao.entity.dtr.UserAccount;
|
32 |
import com.spice.profitmandi.dao.entity.dtr.UserAccount;
|
| 32 |
import com.spice.profitmandi.dao.entity.dtr.UserRole;
|
33 |
import com.spice.profitmandi.dao.entity.dtr.UserRole;
|
| Line 43... |
Line 44... |
| 43 |
import com.spice.profitmandi.dao.enumuration.fofo.PaymentOptionType;
|
44 |
import com.spice.profitmandi.dao.enumuration.fofo.PaymentOptionType;
|
| 44 |
import com.spice.profitmandi.dao.repository.dtr.DocumentRepository;
|
45 |
import com.spice.profitmandi.dao.repository.dtr.DocumentRepository;
|
| 45 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
46 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
| 46 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRegisteredAddressRepository;
|
47 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRegisteredAddressRepository;
|
| 47 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
|
48 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
|
| - |
|
49 |
import com.spice.profitmandi.dao.repository.dtr.RoleRepository;
|
| 48 |
import com.spice.profitmandi.dao.repository.dtr.ShopAddressRepository;
|
50 |
import com.spice.profitmandi.dao.repository.dtr.ShopAddressRepository;
|
| 49 |
import com.spice.profitmandi.dao.repository.dtr.ShopRepository;
|
51 |
import com.spice.profitmandi.dao.repository.dtr.ShopRepository;
|
| 50 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
52 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
| 51 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
53 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
| 52 |
import com.spice.profitmandi.dao.repository.dtr.UserRoleRepository;
|
54 |
import com.spice.profitmandi.dao.repository.dtr.UserRoleRepository;
|
| Line 110... |
Line 112... |
| 110 |
|
112 |
|
| 111 |
@Autowired
|
113 |
@Autowired
|
| 112 |
private PaymentOptionRepository paymentOptionRepository;
|
114 |
private PaymentOptionRepository paymentOptionRepository;
|
| 113 |
|
115 |
|
| 114 |
@Autowired
|
116 |
@Autowired
|
| - |
|
117 |
private RoleRepository roleRepository;
|
| - |
|
118 |
|
| - |
|
119 |
@Autowired
|
| 115 |
private Mongo mongoClient;
|
120 |
private Mongo mongoClient;
|
| 116 |
|
121 |
|
| 117 |
|
122 |
|
| 118 |
private static final Logger LOGGER = LogManager.getLogger(MigrationUtil.class);
|
123 |
private static final Logger LOGGER = LogManager.getLogger(MigrationUtil.class);
|
| 119 |
|
124 |
|
| Line 190... |
Line 195... |
| 190 |
}
|
195 |
}
|
| 191 |
}
|
196 |
}
|
| 192 |
return userIds;
|
197 |
return userIds;
|
| 193 |
}
|
198 |
}
|
| 194 |
|
199 |
|
| 195 |
public void migrateUserToRetailer(){
|
200 |
public void migrateUserToRetailer() throws ProfitMandiBusinessException{
|
| 196 |
|
201 |
|
| 197 |
List<UserAccount> saholicUserAccounts = userAccountRepository.selectAllSaholicByUserIds(new HashSet<>(userRepository.selectIdAll()));
|
202 |
List<UserAccount> saholicUserAccounts = userAccountRepository.selectAllSaholicByUserIds(new HashSet<>(userRepository.selectIdAll()));
|
| 198 |
if(saholicUserAccounts.isEmpty()){
|
203 |
if(saholicUserAccounts.isEmpty()){
|
| 199 |
return;
|
204 |
return;
|
| 200 |
}
|
205 |
}
|
| Line 217... |
Line 222... |
| 217 |
Set<Integer> userIds = this.toUserIds(saholicUserAccounts, retailerIds);
|
222 |
Set<Integer> userIds = this.toUserIds(saholicUserAccounts, retailerIds);
|
| 218 |
|
223 |
|
| 219 |
if(userIds.isEmpty()){
|
224 |
if(userIds.isEmpty()){
|
| 220 |
return;
|
225 |
return;
|
| 221 |
}
|
226 |
}
|
| - |
|
227 |
|
| - |
|
228 |
Role roleRetailer = roleRepository.selectByName(RoleType.RETAILER.toString());
|
| - |
|
229 |
|
| 222 |
List<Integer> foundRetailerRoleUserIds = userRoleRepository.selectUserIdsByUserIdsAndRoleType(userIds, RoleType.RETAILER);
|
230 |
List<Integer> foundRetailerRoleUserIds = userRoleRepository.selectUserIdsByUserIdsAndRoleId(userIds, roleRetailer.getId());
|
| 223 |
|
231 |
|
| 224 |
Set<Integer> notFoundRetailerRoleUserIds = new HashSet<>(userIds);
|
232 |
Set<Integer> notFoundRetailerRoleUserIds = new HashSet<>(userIds);
|
| 225 |
notFoundRetailerRoleUserIds.removeAll(foundRetailerRoleUserIds);
|
233 |
notFoundRetailerRoleUserIds.removeAll(foundRetailerRoleUserIds);
|
| 226 |
|
234 |
|
| - |
|
235 |
|
| - |
|
236 |
|
| 227 |
for(int userId : notFoundRetailerRoleUserIds){
|
237 |
for(int userId : notFoundRetailerRoleUserIds){
|
| 228 |
UserRole retailerRole = new UserRole();
|
238 |
UserRole retailerRole = new UserRole();
|
| 229 |
retailerRole.setRoleType(RoleType.RETAILER);
|
239 |
retailerRole.setRoleId(roleRetailer.getId());
|
| 230 |
retailerRole.setUserId(userId);
|
240 |
retailerRole.setUserId(userId);
|
| 231 |
try {
|
241 |
try {
|
| 232 |
userRoleRepository.persist(retailerRole);
|
242 |
userRoleRepository.persist(retailerRole);
|
| 233 |
LOGGER.info("UserId {} with Retailer Role migrated", userId);
|
243 |
LOGGER.info("UserId {} with Retailer Role migrated", userId);
|
| 234 |
} catch (ProfitMandiBusinessException e) {
|
244 |
} catch (ProfitMandiBusinessException e) {
|
| 235 |
e.printStackTrace();
|
245 |
e.printStackTrace();
|
| 236 |
}
|
246 |
}
|
| 237 |
}
|
247 |
}
|
| 238 |
|
248 |
|
| - |
|
249 |
Role roleUser = roleRepository.selectByName(RoleType.USER.toString());
|
| - |
|
250 |
|
| 239 |
List<Integer> foundUserRoleUserIds = userRoleRepository.selectUserIdsByUserIdsAndRoleType(userIds, RoleType.USER);
|
251 |
List<Integer> foundUserRoleUserIds = userRoleRepository.selectUserIdsByUserIdsAndRoleId(userIds, roleUser.getId());
|
| 240 |
|
252 |
|
| 241 |
Set<Integer> notFoundUserRoleUserIds = new HashSet<>(userIds);
|
253 |
Set<Integer> notFoundUserRoleUserIds = new HashSet<>(userIds);
|
| 242 |
notFoundUserRoleUserIds.removeAll(foundUserRoleUserIds);
|
254 |
notFoundUserRoleUserIds.removeAll(foundUserRoleUserIds);
|
| 243 |
|
255 |
|
| - |
|
256 |
|
| 244 |
for(int userId : notFoundUserRoleUserIds){
|
257 |
for(int userId : notFoundUserRoleUserIds){
|
| 245 |
UserRole userRole = new UserRole();
|
258 |
UserRole userRole = new UserRole();
|
| 246 |
userRole.setRoleType(RoleType.USER);
|
259 |
userRole.setRoleId(roleUser.getId());
|
| 247 |
userRole.setUserId(userId);
|
260 |
userRole.setUserId(userId);
|
| 248 |
try {
|
261 |
try {
|
| 249 |
userRoleRepository.persist(userRole);
|
262 |
userRoleRepository.persist(userRole);
|
| 250 |
LOGGER.info("UserId {} with User Role migrated", userId);
|
263 |
LOGGER.info("UserId {} with User Role migrated", userId);
|
| 251 |
} catch (ProfitMandiBusinessException e) {
|
264 |
} catch (ProfitMandiBusinessException e) {
|
| Line 388... |
Line 401... |
| 388 |
cartUserAccounts.setType(AccountType.cartId);
|
401 |
cartUserAccounts.setType(AccountType.cartId);
|
| 389 |
cartUserAccounts.setUserId(user.getId());
|
402 |
cartUserAccounts.setUserId(user.getId());
|
| 390 |
userAccountRepository.persist(cartUserAccounts);
|
403 |
userAccountRepository.persist(cartUserAccounts);
|
| 391 |
}
|
404 |
}
|
| 392 |
|
405 |
|
| - |
|
406 |
Role roleUser = roleRepository.selectByName(RoleType.USER.toString());
|
| 393 |
|
407 |
|
| 394 |
UserRole userRole = null;
|
408 |
UserRole userRole = null;
|
| - |
|
409 |
|
| 395 |
try{
|
410 |
try{
|
| 396 |
userRole = userRoleRepository.selectByUserIdAndRoleType(user.getId(), RoleType.USER);
|
411 |
userRole = userRoleRepository.selectByUserIdAndRoleId(user.getId(), roleUser.getId());
|
| 397 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
412 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
| - |
|
413 |
Role role = roleRepository.selectByName(RoleType.USER.toString());
|
| 398 |
userRole = new UserRole();
|
414 |
userRole = new UserRole();
|
| 399 |
userRole.setRoleType(RoleType.USER);
|
415 |
userRole.setRoleId(role.getId());
|
| 400 |
userRole.setUserId(user.getId());
|
416 |
userRole.setUserId(user.getId());
|
| 401 |
userRoleRepository.persist(userRole);
|
417 |
userRoleRepository.persist(userRole);
|
| 402 |
}
|
418 |
}
|
| 403 |
|
419 |
|
| - |
|
420 |
Role roleRetailer = roleRepository.selectByName(RoleType.RETAILER.toString());
|
| - |
|
421 |
|
| 404 |
UserRole retailerRole = null;
|
422 |
UserRole retailerRole = null;
|
| 405 |
try{
|
423 |
try{
|
| 406 |
retailerRole = userRoleRepository.selectByUserIdAndRoleType(user.getId(), RoleType.RETAILER);
|
424 |
retailerRole = userRoleRepository.selectByUserIdAndRoleId(user.getId(), roleRetailer.getId());
|
| 407 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
425 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
| - |
|
426 |
Role role = roleRepository.selectByName(RoleType.RETAILER.toString());
|
| 408 |
retailerRole = new UserRole();
|
427 |
retailerRole = new UserRole();
|
| 409 |
retailerRole.setRoleType(RoleType.RETAILER);
|
428 |
retailerRole.setRoleId(role.getId());
|
| 410 |
retailerRole.setUserId(user.getId());
|
429 |
retailerRole.setUserId(user.getId());
|
| 411 |
userRoleRepository.persist(retailerRole);
|
430 |
userRoleRepository.persist(retailerRole);
|
| 412 |
}
|
431 |
}
|
| 413 |
|
432 |
|
| - |
|
433 |
Role roleFofo = roleRepository.selectByName(RoleType.FOFO.toString());
|
| - |
|
434 |
|
| 414 |
UserRole fofoRole = null;
|
435 |
UserRole fofoRole = null;
|
| 415 |
try{
|
436 |
try{
|
| 416 |
fofoRole = userRoleRepository.selectByUserIdAndRoleType(user.getId(), RoleType.FOFO);
|
437 |
fofoRole = userRoleRepository.selectByUserIdAndRoleId(user.getId(), roleFofo.getId());
|
| 417 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
438 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
| - |
|
439 |
Role role = roleRepository.selectByName(RoleType.FOFO.toString());
|
| 418 |
fofoRole = new UserRole();
|
440 |
fofoRole = new UserRole();
|
| 419 |
fofoRole.setRoleType(RoleType.FOFO);
|
441 |
fofoRole.setRoleId(role.getId());
|
| 420 |
fofoRole.setUserId(user.getId());
|
442 |
fofoRole.setUserId(user.getId());
|
| 421 |
userRoleRepository.persist(fofoRole);
|
443 |
userRoleRepository.persist(fofoRole);
|
| 422 |
}
|
444 |
}
|
| 423 |
|
445 |
|
| 424 |
List<Integer> paymentOptionIds = fofoPartnerPaymentOptionRepository.selectPaymentOptionIdsByFofoId(retailer.getId());
|
446 |
List<Integer> paymentOptionIds = fofoPartnerPaymentOptionRepository.selectPaymentOptionIdsByFofoId(retailer.getId());
|