added logging methods in helper
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.billpaymentservice.bbps.util;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
@@ -11,11 +12,15 @@ import com.billpaymentservice.bbps.dto.ResponseModel;
|
||||
import com.billpaymentservice.bbps.entites.BBPSMastersData;
|
||||
import com.billpaymentservice.bbps.exception.CustomException;
|
||||
import com.billpaymentservice.bbps.repository.BBPSMasterDataRepo;
|
||||
import com.billpaymentservice.bbps.repository.InboundTraceLogRepository;
|
||||
import com.billpaymentservice.bbps.dto.request.BillerDetailRequest;
|
||||
import com.billpaymentservice.bbps.dto.request.MerchantRequestModel;
|
||||
import com.billpaymentservice.bbps.entites.BBPSMerchantValidation;
|
||||
import com.billpaymentservice.bbps.entites.InboundTraceLog;
|
||||
import com.billpaymentservice.bbps.entites.OutboundTraceLog;
|
||||
import com.billpaymentservice.bbps.exception.CustomException;
|
||||
import com.billpaymentservice.bbps.repository.MerchantRepository;
|
||||
import com.billpaymentservice.bbps.repository.OutboundTraceLogRepository;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
@@ -23,6 +28,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
public class Helper {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(Helper.class);
|
||||
private final InboundTraceLogRepository inboundTraceLogRepository;
|
||||
private final OutboundTraceLogRepository outboundTraceLogRepository;
|
||||
|
||||
private static final String CHARACTERS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
private static final SecureRandom secureRandom = new SecureRandom();
|
||||
@@ -31,8 +38,11 @@ public class Helper {
|
||||
private final BBPSMasterDataRepo bbpsMasterDataRepo;
|
||||
|
||||
// Constructor Injection
|
||||
public Helper(BBPSMasterDataRepo bbpsMasterDataRepo) {
|
||||
public Helper(BBPSMasterDataRepo bbpsMasterDataRepo, InboundTraceLogRepository inboundTraceLogRepository,
|
||||
OutboundTraceLogRepository outboundTraceLogRepository) {
|
||||
this.bbpsMasterDataRepo = bbpsMasterDataRepo;
|
||||
this.inboundTraceLogRepository = inboundTraceLogRepository;
|
||||
this.outboundTraceLogRepository = outboundTraceLogRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,64 +84,6 @@ public class Helper {
|
||||
}).start();
|
||||
}
|
||||
|
||||
// public boolean isMerchantValidAndActive(MerchantRequestModel requestModel) {
|
||||
//
|
||||
// if (requestModel == null) {
|
||||
// LOGGER.warn("MerchantRequestModel or MID is null");
|
||||
// throw new CustomException("Invalid request: MID is required");
|
||||
// }
|
||||
//
|
||||
// // Fetch merchant details
|
||||
// BBPSMastersData merchantValidation = bbpsMasterDataRepo.findByMid(requestModel.getMid());
|
||||
//
|
||||
// if (merchantValidation == null) {
|
||||
// LOGGER.warn("Merchant not found for MID: {}", requestModel.getMid());
|
||||
// throw new CustomException("Merchant not found");
|
||||
// }
|
||||
//
|
||||
// if (merchantValidation.getApiKey() == null && merchantValidation.getSecreteKey() == null) {
|
||||
//
|
||||
// throw new CustomException("Merchant inactive");
|
||||
// }
|
||||
//
|
||||
// if (!Boolean.TRUE.equals(merchantValidation.getIsActive())) {
|
||||
// LOGGER.warn("Merchant inactive for MID: {}", requestModel.getMid());
|
||||
// throw new CustomException("Merchant inactive");
|
||||
// }
|
||||
//
|
||||
// LOGGER.info("Merchant is valid and active for MID: {}", requestModel.getMid());
|
||||
// return true;
|
||||
// }
|
||||
|
||||
// public String validateMerchant(String mid) {
|
||||
//
|
||||
// if (mid == null) {
|
||||
// LOGGER.warn("MerchantRequestModel or MID is null");
|
||||
// return "Mid is required";
|
||||
// }
|
||||
//
|
||||
// // Fetch merchant details
|
||||
// BBPSMastersData merchantValidation = bbpsMasterDataRepo.findByMid(mid);
|
||||
//
|
||||
// if (merchantValidation == null) {
|
||||
// LOGGER.warn("Merchant not found for MID: {}", mid);
|
||||
// return "Merchant not found by id";
|
||||
// }
|
||||
//
|
||||
// if (merchantValidation.getApiKey() == null && merchantValidation.getSecreteKey() == null) {
|
||||
// LOGGER.warn("Merchant BBPS service is not active MID: {}", mid);
|
||||
// return "Merchant BBPS Service is not active by mid";
|
||||
// }
|
||||
//
|
||||
// if (!Boolean.TRUE.equals(merchantValidation.getIsActive())) {
|
||||
// LOGGER.warn("Merchant inactive for MID: {}", mid);
|
||||
// return "Merchant is inactive";
|
||||
// }
|
||||
//
|
||||
// LOGGER.info("Merchant is valid and active for MID: {}", mid);
|
||||
// return "Valid"; // Success message
|
||||
// }
|
||||
|
||||
public void validateMerchant(String mid) {
|
||||
if (mid == null || mid == "") {
|
||||
LOGGER.warn("MerchantRequestModel or MID is null");
|
||||
@@ -181,5 +133,56 @@ public class Helper {
|
||||
return "{}"; // or "N/A" depending on your needs
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------- Trace helper methods ---------- */
|
||||
|
||||
public InboundTraceLog createInboundLog(String requestId, String txnId, String apiName, String mid,
|
||||
String httpMethod, String requestPayload) {
|
||||
if(inboundTraceLogRepository.findByRequestId(requestId) != null) {
|
||||
throw new CustomException("Duplicate Request ID: " + requestId);
|
||||
}
|
||||
InboundTraceLog inboundLog = new InboundTraceLog(requestId, txnId, apiName, mid == null ? "N/A" : mid,
|
||||
"BBPS_ORG", httpMethod, requestPayload == null ? "N/A" : requestPayload);
|
||||
inboundTraceLogRepository.save(inboundLog);
|
||||
return inboundLog;
|
||||
}
|
||||
|
||||
public void updateInboundLogSuccess(InboundTraceLog inboundLog, String responsePayload, String responseCode) {
|
||||
if (inboundLog == null)
|
||||
return;
|
||||
inboundLog.setResponsePayload(responsePayload);
|
||||
inboundLog.setResponseCode(responseCode);
|
||||
inboundLog.setStatus("SUCCESS");
|
||||
inboundLog.setResponseTime(LocalDateTime.now());
|
||||
inboundTraceLogRepository.save(inboundLog);
|
||||
}
|
||||
|
||||
public void updateInboundLogFailure(InboundTraceLog inboundLog, String responsePayload, String responseCode) {
|
||||
if (inboundLog == null)
|
||||
return;
|
||||
inboundLog.setResponsePayload(responsePayload);
|
||||
inboundLog.setResponseCode(responseCode);
|
||||
inboundLog.setStatus("FAILED");
|
||||
inboundLog.setResponseTime(LocalDateTime.now());
|
||||
inboundTraceLogRepository.save(inboundLog);
|
||||
}
|
||||
|
||||
public OutboundTraceLog createOutboundLog(String txnId, String requestId, String apiName, String url,
|
||||
String httpMethod, String requestPayload) {
|
||||
OutboundTraceLog outboundLog = new OutboundTraceLog(txnId, requestId, apiName, url, httpMethod,
|
||||
requestPayload == null ? "N/A" : requestPayload);
|
||||
outboundTraceLogRepository.save(outboundLog);
|
||||
return outboundLog;
|
||||
}
|
||||
|
||||
public void updateOutboundLogResponse(OutboundTraceLog outboundLog, String responsePayload) {
|
||||
if (outboundLog == null)
|
||||
return;
|
||||
outboundLog.setResponsePayload(responsePayload);
|
||||
outboundLog.setResponseReceiveTime(LocalDateTime.now());
|
||||
outboundTraceLogRepository.save(outboundLog);
|
||||
}
|
||||
|
||||
/* ---------- End helpers ---------- */
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user