added poll back
This commit is contained in:
@@ -8,9 +8,12 @@ import com.billpaymentservice.bbps.dto.request.FetchBillRequest;
|
||||
import com.billpaymentservice.bbps.dto.response.BillDataResponse;
|
||||
import com.billpaymentservice.bbps.dto.response.BillerDataResponse;
|
||||
import com.billpaymentservice.bbps.dto.response.FetchBillResponse;
|
||||
import com.billpaymentservice.bbps.entites.BeneficiaryDetails;
|
||||
import com.billpaymentservice.bbps.exception.CustomException;
|
||||
import com.billpaymentservice.bbps.repository.BeneficiaryDetailsRepository;
|
||||
import com.billpaymentservice.bbps.service.AgentService;
|
||||
import com.billpaymentservice.bbps.util.BBPSConstant;
|
||||
import com.billpaymentservice.bbps.util.Helper;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
@@ -25,29 +28,42 @@ import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestClient;
|
||||
import org.springframework.web.servlet.function.ServerRequest.Headers;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class AgentServiceImpl implements AgentService {
|
||||
|
||||
@Value("${agent.data.url}")
|
||||
private String agentDtaUrl;
|
||||
|
||||
private final RestClient restClient;
|
||||
private final HttpService httpService;// ✅ injected from config
|
||||
|
||||
private final RestClient restClient;
|
||||
private final HttpService httpService;
|
||||
private final Helper helper;
|
||||
private final BeneficiaryDetailsRepository beneficiaryDetailsRepository;
|
||||
|
||||
public AgentServiceImpl(RestClient restClient,HttpService httpService,Helper helper, BeneficiaryDetailsRepository beneficiaryDetailsRepository) {
|
||||
this.restClient=restClient;
|
||||
this.httpService=httpService;
|
||||
this.helper=helper;
|
||||
this.beneficiaryDetailsRepository=beneficiaryDetailsRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseModel initiateBillFetch(FetchBillRequest fetchBillRequest) {
|
||||
String url = agentDtaUrl+BBPSConstant.BILL_FETCH_INTI;
|
||||
System.out.println(url);
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("x-digiledge-key", fetchBillRequest.getDigiledgeKey());
|
||||
headers.set("agentId", fetchBillRequest.getAgentId());
|
||||
headers.set("tenantId", fetchBillRequest.getTenantId());
|
||||
|
||||
BeneficiaryDetails headersData=beneficiaryDetailsRepository.findByOrgId("ORG001");
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("x-digiledge-key",headersData.getXDigiledgeKey());
|
||||
headers.set("agentId", headersData.getAgentId());
|
||||
headers.set("tenantId", headersData.getTenantId());
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
|
||||
|
||||
|
||||
ResponseModel responseModel = new ResponseModel();
|
||||
|
||||
try {
|
||||
@@ -69,7 +85,7 @@ public class AgentServiceImpl implements AgentService {
|
||||
|
||||
// ✅ Convert JSON string → Map
|
||||
Map<String, Object> dataMap = objectMapper.readValue(responseData, new TypeReference<Map<String, Object>>() {});
|
||||
|
||||
|
||||
// ✅ Validate generalResp
|
||||
if (!dataMap.containsKey("genericResponse")) {
|
||||
throw new CustomException("Invalid response structure from BBPS");
|
||||
@@ -78,6 +94,19 @@ public class AgentServiceImpl implements AgentService {
|
||||
// ✅ Convert to your custom DTO
|
||||
FetchBillResponse fetchBillResponse = objectMapper.convertValue(dataMap, FetchBillResponse.class);
|
||||
GeneralResponse generalResponse = fetchBillResponse.getGenericResponse();
|
||||
//
|
||||
//start a new thread here
|
||||
helper.startPolling(fetchBillResponse,
|
||||
res -> {
|
||||
BillFetchByBillIdRequest pollReq = new BillFetchByBillIdRequest();
|
||||
pollReq.setBillId(res.getBillId());
|
||||
return fetchBillById(pollReq);
|
||||
},
|
||||
3, // interval in seconds
|
||||
15 // total time in seconds
|
||||
);
|
||||
|
||||
|
||||
|
||||
// ✅ Build final ResponseModel
|
||||
responseModel = new ResponseModel(
|
||||
@@ -103,11 +132,13 @@ public class AgentServiceImpl implements AgentService {
|
||||
String billId = billFetchByBillIdRequest.getBillId();
|
||||
String fullUrl = agentDtaUrl + BBPSConstant.BILL_FETCH_BY_ID+billId;
|
||||
System.out.print(fullUrl);
|
||||
|
||||
|
||||
BeneficiaryDetails headersData=beneficiaryDetailsRepository.findByOrgId("ORG001");
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("x-digiledge-key", billFetchByBillIdRequest.getDigiledgeKey());
|
||||
headers.set("agentId", billFetchByBillIdRequest.getAgentId());
|
||||
headers.set("tenantId", billFetchByBillIdRequest.getTenantId());
|
||||
headers.set("x-digiledge-key",headersData.getXDigiledgeKey());
|
||||
headers.set("agentId", headersData.getAgentId());
|
||||
headers.set("tenantId", headersData.getTenantId());
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
|
||||
Map<String, String> responseMap = httpService.getRequest(fullUrl,headers);
|
||||
|
||||
Reference in New Issue
Block a user