Done ticket GEPAFINBE-174

This commit is contained in:
nisha
2025-02-26 12:45:38 +05:30
parent 073436247c
commit 3eafa0b710
9 changed files with 128 additions and 2 deletions

View File

@@ -0,0 +1,59 @@
package net.gepafin.tendermanagement.dao;
import feign.FeignException;
import net.gepafin.tendermanagement.constants.GepafinConstant;
import net.gepafin.tendermanagement.model.request.EmailConfig;
import net.gepafin.tendermanagement.service.feignClient.PecFeignService;
import net.gepafin.tendermanagement.util.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import java.net.URI;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@Component
public class PecDao {
public final Logger log = LoggerFactory.getLogger(PecDao.class);
@Autowired
private PecFeignService pecFeignService;
@Autowired
private EmailNotificationDao emailNotificationDao;
public Map<String, Object> getUsageDetails(Long hubId) {
EmailConfig emailConfig = emailNotificationDao.retrieveEmailConfig(hubId);
Map<String, Object> responseBody = new HashMap<>();
try {
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set(GepafinConstant.AUTHORIZATION, "Bearer " + emailConfig.getAuthToken());
headers.set("x-username", emailConfig.getUsername());
headers.set("x-password", emailConfig.getPassword());
headers.add(org.apache.http.HttpHeaders.USER_AGENT, "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0");
URI baseUrl = URI.create(GepafinConstant.PEC_SERVICE_URL+GepafinConstant.PEC_SERVICE_INBOX_MAIL);
ResponseEntity<Object> response = pecFeignService.getUsageDetails(baseUrl,headers);
if (response.getStatusCode() == HttpStatus.OK && response.hasBody()) {
log.info("Successfully fetched usage and limit");
responseBody = (Map<String, Object>) response.getBody();
}
} catch (FeignException ex) {
}
return responseBody;
}
}