Skip to content

Commit

Permalink
fix: removed circuitBreaker and retry logic (#237)
Browse files Browse the repository at this point in the history
Co-authored-by: [email protected] <Aiap1955?^@#>
  • Loading branch information
gianmarcoplutino and [email protected] authored Nov 4, 2024
1 parent e8ee96b commit 8c78be9
Show file tree
Hide file tree
Showing 5 changed files with 263 additions and 297 deletions.
11 changes: 0 additions & 11 deletions app/src/main/resources/config/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,6 @@ resilience4j:
circuit-breaker-aspect-order: 1
instances:
geotaxCircuitbreaker:
wait-duration-in-open-state: 1m
permitted-number-of-calls-in-half-open-state: 3
sliding-window-type: count-based
sliding-window-size: 3
minimum-number-of-calls: 3
slow-call-duration-threshold: 10s
slow-call-rate-threshold: 60
failure-rate-threshold: 60
ignore-exceptions:
- it.pagopa.selfcare.party.registry_proxy.connector.exception.ResourceNotFoundException
pdndInfoCamereCircuitbreaker:
wait-duration-in-open-state: 1m
permitted-number-of-calls-in-half-open-state: 3
sliding-window-type: count-based
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package it.pagopa.selfcare.party.registry_proxy.connector.rest;

import io.github.resilience4j.circuitbreaker.annotation.CircuitBreaker;
import io.github.resilience4j.retry.annotation.Retry;
import it.pagopa.selfcare.party.registry_proxy.connector.api.PDNDInfoCamereConnector;
import it.pagopa.selfcare.party.registry_proxy.connector.exception.ResourceNotFoundException;
import it.pagopa.selfcare.party.registry_proxy.connector.model.nationalregistriespdnd.PDNDBusiness;
import it.pagopa.selfcare.party.registry_proxy.connector.rest.client.PDNDInfoCamereRestClient;
import it.pagopa.selfcare.party.registry_proxy.connector.rest.config.PDNDInfoCamereRestClientConfig;
Expand All @@ -20,50 +17,42 @@
@Slf4j
@Service
public class PDNDInfoCamereConnectorImpl implements PDNDInfoCamereConnector {
public static final String ERROR_PDND_INFO_CAMERE_REST_CLIENT_MESSAGE = "Error pdnd-infocamere rest client, message: %s";

private final PDNDInfoCamereRestClient pdndInfoCamereRestClient;
private final PDNDBusinessMapper pdndBusinessMapper;
private final TokenProvider tokenProvider;
private final PDNDInfoCamereRestClientConfig pdndInfoCamereRestClientConfig;

public PDNDInfoCamereConnectorImpl(PDNDInfoCamereRestClient pdndInfoCamereRestClient, PDNDBusinessMapper pdndBusinessMapper, TokenProvider tokenProvider, PDNDInfoCamereRestClientConfig pdndInfoCamereRestClientConfig) {
this.pdndInfoCamereRestClient = pdndInfoCamereRestClient;
this.pdndBusinessMapper = pdndBusinessMapper;
this.tokenProvider = tokenProvider;
this.pdndInfoCamereRestClientConfig = pdndInfoCamereRestClientConfig;
}

@Override
@CircuitBreaker(name = "pdndInfoCamereCircuitbreaker", fallbackMethod = "fallbackRetrieveInstitutionByDescription")
@Retry(name = "retryServiceUnavailable")
public List<PDNDBusiness> retrieveInstitutionsPdndByDescription(String description) {
Assert.hasText(description, "Description is required");
ClientCredentialsResponse tokenResponse = tokenProvider.getTokenPdnd(pdndInfoCamereRestClientConfig.getPdndSecretValue());
String bearer = "Bearer " + tokenResponse.getAccessToken();
List<PDNDImpresa> result = pdndInfoCamereRestClient.retrieveInstitutionsPdndByDescription(description, bearer);
return pdndBusinessMapper.toPDNDBusinesses(result);
}

public List<PDNDBusiness> fallbackRetrieveInstitutionByDescription(RuntimeException e) {
log.error(String.format(ERROR_PDND_INFO_CAMERE_REST_CLIENT_MESSAGE, e.getMessage()));
return List.of();
}

@Override
@CircuitBreaker(name = "pdndInfoCamereCircuitbreaker", fallbackMethod = "fallbackRetrieveInstitutionByTaxCode")
@Retry(name = "retryServiceUnavailable")
public PDNDBusiness retrieveInstitutionPdndByTaxCode(String taxCode) {
Assert.hasText(taxCode, "TaxCode is required");
ClientCredentialsResponse tokenResponse = tokenProvider.getTokenPdnd(pdndInfoCamereRestClientConfig.getPdndSecretValue());
String bearer = "Bearer " + tokenResponse.getAccessToken();
PDNDImpresa result = pdndInfoCamereRestClient.retrieveInstitutionPdndByTaxCode(taxCode, bearer).get(0);
return pdndBusinessMapper.toPDNDBusiness(result);
}

public PDNDBusiness fallbackRetrieveInstitutionByTaxCode(RuntimeException e) {
log.error(String.format(ERROR_PDND_INFO_CAMERE_REST_CLIENT_MESSAGE, e.getMessage()), e);
throw new ResourceNotFoundException("");
}

private final PDNDInfoCamereRestClient pdndInfoCamereRestClient;
private final PDNDBusinessMapper pdndBusinessMapper;
private final TokenProvider tokenProvider;
private final PDNDInfoCamereRestClientConfig pdndInfoCamereRestClientConfig;

public PDNDInfoCamereConnectorImpl(
PDNDInfoCamereRestClient pdndInfoCamereRestClient,
PDNDBusinessMapper pdndBusinessMapper,
TokenProvider tokenProvider,
PDNDInfoCamereRestClientConfig pdndInfoCamereRestClientConfig) {
this.pdndInfoCamereRestClient = pdndInfoCamereRestClient;
this.pdndBusinessMapper = pdndBusinessMapper;
this.tokenProvider = tokenProvider;
this.pdndInfoCamereRestClientConfig = pdndInfoCamereRestClientConfig;
}

@Override
public List<PDNDBusiness> retrieveInstitutionsPdndByDescription(String description) {
Assert.hasText(description, "Description is required");
ClientCredentialsResponse tokenResponse =
tokenProvider.getTokenPdnd(pdndInfoCamereRestClientConfig.getPdndSecretValue());
String bearer = "Bearer " + tokenResponse.getAccessToken();
List<PDNDImpresa> result =
pdndInfoCamereRestClient.retrieveInstitutionsPdndByDescription(description, bearer);
return pdndBusinessMapper.toPDNDBusinesses(result);
}

@Override
public PDNDBusiness retrieveInstitutionPdndByTaxCode(String taxCode) {
Assert.hasText(taxCode, "TaxCode is required");
ClientCredentialsResponse tokenResponse =
tokenProvider.getTokenPdnd(pdndInfoCamereRestClientConfig.getPdndSecretValue());
String bearer = "Bearer " + tokenResponse.getAccessToken();
PDNDImpresa result =
pdndInfoCamereRestClient.retrieveInstitutionPdndByTaxCode(taxCode, bearer).get(0);
return pdndBusinessMapper.toPDNDBusiness(result);
}
}
Original file line number Diff line number Diff line change
@@ -1,44 +1,51 @@
package it.pagopa.selfcare.party.registry_proxy.connector.rest.model;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Objects;
import lombok.Data;

@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class PDNDImpresa {

@JsonProperty("ProgressivoImpresa")
private long progressivoImpresa;
@JsonProperty("ProgressivoImpresa")
private long progressivoImpresa;

@JsonProperty("CodiceFiscale")
private String businessTaxId;
@JsonProperty("CodiceFiscale")
private String businessTaxId;

@JsonProperty("Denominazione")
private String businessName;
@JsonProperty("Denominazione")
private String businessName;

@JsonProperty("NaturaGiuridica")
private String legalNature;
@JsonProperty("NaturaGiuridica")
private String legalNature;

@JsonProperty("DescNaturaGiuridica")
private String legalNatureDescription;
@JsonProperty("DescNaturaGiuridica")
private String legalNatureDescription;

@JsonProperty("Cciaa")
private String cciaa;
@JsonProperty("Cciaa")
private String cciaa;

@JsonProperty("NRea")
private String nRea;
@JsonProperty("NRea")
private String nRea;

@JsonProperty("StatoImpresa")
private String businessStatus;
@JsonProperty("StatoImpresa")
private String businessStatus;

@JsonProperty("IndirizzoSedeLegale")
private PDNDSedeImpresa businessAddress;
@JsonProperty("IndirizzoSedeLegale")
private PDNDSedeImpresa businessAddress;

@JsonProperty("PEC")
private String digitalAddress;


public String getAddress() {
return businessAddress.getToponimoSede() + " " + businessAddress.getViaSede() + " " + businessAddress.getNcivicoSede();
}
@JsonProperty("PEC")
private String digitalAddress;

public String getAddress() {
if (Objects.nonNull(businessAddress)) {
return businessAddress.getToponimoSede()
+ " "
+ businessAddress.getViaSede()
+ " "
+ businessAddress.getNcivicoSede();
} else return "";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@

@Data
public class PDNDSedeImpresa {
@JsonProperty("ComuneSede")
private String city;
@JsonProperty("ComuneSede")
private String city;

@JsonProperty("ProvinciaSede")
private String county;
@JsonProperty("ProvinciaSede")
private String county;

@JsonProperty("CapSede")
private String zipCode;
@JsonProperty("CapSede")
private String zipCode;

@JsonProperty("ToponimoSede")
private String toponimoSede;
@JsonProperty("ToponimoSede")
private String toponimoSede;

@JsonProperty("ViaSede")
private String viaSede;
@JsonProperty("ViaSede")
private String viaSede;

@JsonProperty("NcivicoSede")
private String ncivicoSede;
@JsonProperty("NcivicoSede")
private String ncivicoSede;
}
Loading

0 comments on commit 8c78be9

Please sign in to comment.