Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SELC-5268 feat: added PDND authentication to infocamere API #213

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
260 changes: 0 additions & 260 deletions connector/rest/docs/openapi/pdnd-v2.json

This file was deleted.

48 changes: 5 additions & 43 deletions connector/rest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,48 +53,10 @@
<artifactId>caffeine</artifactId>
<version>3.1.8</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.14.1</version>
</dependency>
</dependencies>
<build>
<plugins>

<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>6.3.0</version>
<executions>
<execution>
<id>selfcare-pdnd</id>
<goals>
<goal>generate</goal>
</goals>
<phase>process-resources</phase>
<configuration>
<inputSpec>${project.basedir}/docs/openapi/pdnd-v2.json</inputSpec>
<generatorName>spring</generatorName>
<library>spring-cloud</library>
<modelNameSuffix />
<generateApiTests>false</generateApiTests>
<generateModelTests>false</generateModelTests>
<configOptions>
<generateForOpenFeign>true</generateForOpenFeign>
<basePackage>${project.groupId}.user_registry.generated.openapi.v1</basePackage>
<modelPackage>${project.groupId}.user_registry.generated.openapi.v1.dto</modelPackage>
<apiPackage>${project.groupId}.user_registry.generated.openapi.v1.api</apiPackage>
<configPackage>${project.groupId}.user_registry.generated.openapi.v1.config</configPackage>
<additionalModelTypeAnnotations>@lombok.Builder; @lombok.NoArgsConstructor; @lombok.AllArgsConstructor</additionalModelTypeAnnotations>
<dateLibrary>java8</dateLibrary>
<delegatePattern>true</delegatePattern>
<interfaceOnly>true</interfaceOnly>
<annotationLibrary>none</annotationLibrary>
<documentationProvider>source</documentationProvider>
<openApiNullable>false</openApiNullable>
<skipDefaultInterface>false</skipDefaultInterface>
<useTags>true</useTags>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
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.model.*;
import it.pagopa.selfcare.party.registry_proxy.connector.rest.config.PDNDInfoCamereRestClientConfig;
import it.pagopa.selfcare.party.registry_proxy.connector.rest.model.ClientCredentialsResponse;
import it.pagopa.selfcare.party.registry_proxy.connector.rest.model.PDNDImpresa;
import it.pagopa.selfcare.party.registry_proxy.connector.rest.model.mapper.PDNDBusinessMapper;
import it.pagopa.selfcare.party.registry_proxy.connector.rest.service.TokenProvider;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
Expand All @@ -21,18 +24,24 @@ public class PDNDInfoCamereConnectorImpl implements PDNDInfoCamereConnector {

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

public PDNDInfoCamereConnectorImpl(PDNDInfoCamereRestClient pdndInfoCamereRestClient, PDNDBusinessMapper pdndBusinessMapper) {
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");
List<PDNDImpresa> result = pdndInfoCamereRestClient.retrieveInstitutionsPdndByDescription(description);
ClientCredentialsResponse tokenResponse = tokenProvider.getTokenPdnd(pdndInfoCamereRestClientConfig.getPdndSecretValue());
String bearer = "Bearer " + tokenResponse.getAccessToken();
List<PDNDImpresa> result = pdndInfoCamereRestClient.retrieveInstitutionsPdndByDescription(description, bearer);
return pdndBusinessMapper.toPDNDBusinesses(result);
}

Expand All @@ -46,12 +55,14 @@ public List<PDNDBusiness> fallbackRetrieveInstitutionByDescription(RuntimeExcept
@Retry(name = "retryServiceUnavailable")
public PDNDBusiness retrieveInstitutionPdndByTaxCode(String taxCode) {
Assert.hasText(taxCode, "TaxCode is required");
PDNDImpresa result = pdndInfoCamereRestClient.retrieveInstitutionPdndByTaxCode(taxCode).get(0);
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()));
log.error(String.format(ERROR_PDND_INFO_CAMERE_REST_CLIENT_MESSAGE, e.getMessage()), e);
throw new ResourceNotFoundException("");
}

Expand Down
Loading
Loading