|
|
|
@@ -3,7 +3,7 @@ package com.billpaymentservice.bbps.util;
|
|
|
|
|
import java.security.SecureRandom;
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.Random;
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
@@ -11,6 +11,7 @@ import org.springframework.http.HttpHeaders;
|
|
|
|
|
import org.springframework.http.MediaType;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
|
|
import com.billpaymentservice.bbps.dto.UserDetailsDTO;
|
|
|
|
|
import com.billpaymentservice.bbps.dto.auth.RegisterRequest;
|
|
|
|
|
import com.billpaymentservice.bbps.entites.BBPSMastersData;
|
|
|
|
|
import com.billpaymentservice.bbps.entites.BharatConnectMaster;
|
|
|
|
@@ -24,6 +25,7 @@ import com.billpaymentservice.bbps.repository.BillValidationRepository;
|
|
|
|
|
import com.billpaymentservice.bbps.repository.BillerDataRepository;
|
|
|
|
|
import com.billpaymentservice.bbps.repository.InboundTraceLogRepository;
|
|
|
|
|
import com.billpaymentservice.bbps.repository.OutboundTraceLogRepository;
|
|
|
|
|
import com.billpaymentservice.bbps.repository.UserRepository;
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
|
|
|
|
|
@Component
|
|
|
|
@@ -32,6 +34,7 @@ public class Helper {
|
|
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(Helper.class);
|
|
|
|
|
private final InboundTraceLogRepository inboundTraceLogRepository;
|
|
|
|
|
private final OutboundTraceLogRepository outboundTraceLogRepository;
|
|
|
|
|
private final UserRepository userRepository;
|
|
|
|
|
|
|
|
|
|
private static final String CHARACTERS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
|
|
|
private static final SecureRandom secureRandom = new SecureRandom();
|
|
|
|
@@ -40,12 +43,13 @@ public class Helper {
|
|
|
|
|
|
|
|
|
|
// Constructor Injection
|
|
|
|
|
public Helper(BBPSMasterDataRepo bbpsMasterDataRepo, InboundTraceLogRepository inboundTraceLogRepository,
|
|
|
|
|
|
|
|
|
|
OutboundTraceLogRepository outboundTraceLogRepository, BillerDataRepository billerDataRepository,
|
|
|
|
|
BillMasterRepository billMasterRepository, BillValidationRepository billValidationRepository) {
|
|
|
|
|
BillMasterRepository billMasterRepository, BillValidationRepository billValidationRepository,
|
|
|
|
|
UserRepository userRepository) {
|
|
|
|
|
this.inboundTraceLogRepository = inboundTraceLogRepository;
|
|
|
|
|
this.outboundTraceLogRepository = outboundTraceLogRepository;
|
|
|
|
|
this.bbpsMasterDataRepo = bbpsMasterDataRepo;
|
|
|
|
|
this.userRepository = userRepository;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@@ -174,23 +178,47 @@ public class Helper {
|
|
|
|
|
public UserEntity createNewUser(RegisterRequest request) {
|
|
|
|
|
UserEntity user = new UserEntity();
|
|
|
|
|
|
|
|
|
|
// user.setId(generateUserId());
|
|
|
|
|
// user.setId(generateUserId());
|
|
|
|
|
user.setMobile(request.getMobile());
|
|
|
|
|
user.setName(request.getName());
|
|
|
|
|
user.setEmail(request.getEmail());
|
|
|
|
|
user.setMid(request.getMid());
|
|
|
|
|
user.setCreateDateTime(new Date());
|
|
|
|
|
// Generate a unique userId (UUID)
|
|
|
|
|
String uniqueUserId = generateUniqueUserId();
|
|
|
|
|
user.setUserId(uniqueUserId);
|
|
|
|
|
|
|
|
|
|
return user;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public <T> T convertJsonToObject(String json, Class<T> clazz) {
|
|
|
|
|
try {
|
|
|
|
|
return objectMapper.readValue(json, clazz);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
throw new CustomException("Invalid JSON from payment API", "FAILED", 400, json);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Object mapUserToUserDetailsDTO(UserEntity user) {
|
|
|
|
|
if (user != null) {
|
|
|
|
|
return UserDetailsDTO.builder().userId(user.getUserId() != null ? user.getUserId() : null) // Set null if
|
|
|
|
|
.userEmailId(user.getEmail() != null ? user.getEmail() : null)
|
|
|
|
|
.userMobNo(user.getMobile() != null ? user.getMobile() : null)
|
|
|
|
|
.userName(user.getName() != null ? user.getName() : null).build();
|
|
|
|
|
}
|
|
|
|
|
return null; // or handle accordingly if user is null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public <T> T convertJsonToObject(String json, Class<T> clazz) {
|
|
|
|
|
try {
|
|
|
|
|
return objectMapper.readValue(json, clazz);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
throw new CustomException("Invalid JSON from payment API", "FAILED", 400, json);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String generateUniqueUserId() {
|
|
|
|
|
String userId = UUID.randomUUID().toString(); // Generate UUID
|
|
|
|
|
|
|
|
|
|
// Check if the userId already exists in the database (theoretically rare but
|
|
|
|
|
// can happen)
|
|
|
|
|
while (userRepository.existsByUserId(userId)) {
|
|
|
|
|
// If it exists, generate a new one
|
|
|
|
|
userId = UUID.randomUUID().toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return userId;
|
|
|
|
|
}
|
|
|
|
|
}
|