adding FetchbillByBillId
This commit is contained in:
@@ -1,14 +1,74 @@
|
||||
package com.billpaymentservice.bbps.serviceImpl;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.billpaymentservice.bbps.dto.BillerDAO;
|
||||
import com.billpaymentservice.bbps.dto.GeneralResp;
|
||||
import com.billpaymentservice.bbps.dto.request.BillerDetailRequest;
|
||||
import com.billpaymentservice.bbps.dto.response.BillerDataResponse;
|
||||
import com.billpaymentservice.bbps.exception.CustomException;
|
||||
import com.billpaymentservice.bbps.service.MasterDataService;
|
||||
import com.billpaymentservice.bbps.serviceImpl.HttpService;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
public class MasterDataServiceImpl implements MasterDataService {
|
||||
|
||||
@Override
|
||||
public BillerDataResponse getBillerByBillerId(BillerDetailRequest billerDetailRequest) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Service
|
||||
public class MasterDataServiceImpl implements MasterDataService {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(MasterDataServiceImpl.class);
|
||||
private final HttpService httpService;
|
||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||
@Value("${bbps.billerDataFetch.url}")
|
||||
private String billerDataFetchUrl;
|
||||
|
||||
// Inject HttpService
|
||||
public MasterDataServiceImpl(HttpService httpService) {
|
||||
this.httpService = httpService;
|
||||
}
|
||||
@Override
|
||||
public BillerDataResponse getBillerByBillerId(BillerDetailRequest billerDetailRequest) {
|
||||
|
||||
|
||||
String billerId = billerDetailRequest.getBillerId();
|
||||
String url = billerDataFetchUrl + billerId;
|
||||
|
||||
Map<String, String> responseMap = httpService.getRequest(url);
|
||||
String responseData = responseMap.get("data");
|
||||
log.info("data is :{}",responseData);
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
try {
|
||||
Map<String, Object> dataMap = objectMapper.readValue(responseData, new TypeReference<Map<String,Object>>() {});
|
||||
if (!dataMap.containsKey("generalResp")) {
|
||||
throw new CustomException(
|
||||
String.valueOf(dataMap.get("statusCode")),
|
||||
String.valueOf(dataMap.get("status")),
|
||||
String.valueOf(dataMap.get("message")),
|
||||
String.valueOf(dataMap.get("remarks")));
|
||||
}
|
||||
BillerDataResponse responseWrapper = objectMapper.convertValue(dataMap, BillerDataResponse.class);
|
||||
return responseWrapper;
|
||||
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error("Error parsing responseData JSON: {}", e.getMessage());
|
||||
throw new CustomException("Invalid JSON received from API");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user