Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
SELC-5227 feat: added Infocamere PDND API call in party-registry client
Browse files Browse the repository at this point in the history
  • Loading branch information
empassaro committed Jul 13, 2024
1 parent 09b493e commit e499943
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ public interface PartyRegistryProxyConnector {
SaResource getSAFromAnac(String taxId);

ASResource getASFromIvass(String ivassCode);

InfocamerePdndInstitution getInfocamerePdndInstitution(String taxCode);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package it.pagopa.selfcare.mscore.model.institution;

import lombok.Data;

@Data
public class InfocamerePdndInstitution {
private String businessTaxId;
private String businessName;
private String legalNature;
private String legalNatureDescription;
private String cciaa;
private String nRea;
private String businessStatus;
private String city;
private String county;
private String zipCode;
private String address;
private String digitalAddress;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
import it.pagopa.selfcare.commons.base.logging.LogUtils;
import it.pagopa.selfcare.mscore.api.PartyRegistryProxyConnector;
import it.pagopa.selfcare.mscore.connector.rest.client.PartyRegistryProxyRestClient;
import it.pagopa.selfcare.mscore.connector.rest.mapper.AooMapper;
import it.pagopa.selfcare.mscore.connector.rest.mapper.AsMapper;
import it.pagopa.selfcare.mscore.connector.rest.mapper.SaMapper;
import it.pagopa.selfcare.mscore.connector.rest.mapper.UoMapper;
import it.pagopa.selfcare.mscore.connector.rest.mapper.*;
import it.pagopa.selfcare.mscore.connector.rest.model.InfocamerePdndResponse;
import it.pagopa.selfcare.mscore.connector.rest.model.geotaxonomy.GeographicTaxonomiesResponse;
import it.pagopa.selfcare.mscore.connector.rest.model.registryproxy.*;
import it.pagopa.selfcare.mscore.exception.MsCoreException;
Expand Down Expand Up @@ -38,13 +36,15 @@ public class PartyRegistryProxyConnectorImpl implements PartyRegistryProxyConnec

private final SaMapper saMapper;
private final AsMapper asMapper;
private final InfocamereMapper infocamereMapper;

public PartyRegistryProxyConnectorImpl(PartyRegistryProxyRestClient restClient, AooMapper aooMapper, UoMapper uoMapper, SaMapper saMapper, AsMapper asMapper) {
public PartyRegistryProxyConnectorImpl(PartyRegistryProxyRestClient restClient, AooMapper aooMapper, UoMapper uoMapper, SaMapper saMapper, AsMapper asMapper, InfocamereMapper infocamereMapper) {
this.restClient = restClient;
this.aooMapper = aooMapper;
this.uoMapper = uoMapper;
this.saMapper = saMapper;
this.asMapper = asMapper;
this.infocamereMapper = infocamereMapper;
}

@Override
Expand Down Expand Up @@ -197,6 +197,22 @@ public ASResource getASFromIvass(String ivassCode) {
}
}

@Override
public InfocamerePdndInstitution getInfocamerePdndInstitution(String taxCode) {
try {
if (taxCode.matches("\\w*")) {
log.debug("getInfocamerePdndInstitution = {}", taxCode);
}
Assert.hasText(taxCode, "taxCode is required");
InfocamerePdndResponse result = restClient.getInfocamerePdndInstitutionByTaxCode(taxCode);
return infocamereMapper.toInstitution(result);
} catch (ResourceNotFoundException e) {
throw new ResourceNotFoundException(String.format(CREATE_INSTITUTION_NOT_FOUND.getMessage(), taxCode), CREATE_INSTITUTION_NOT_FOUND.getCode());
} catch (FeignException e) {
throw new MsCoreException(e.getMessage(), String.valueOf(e.status()));
}
}

private GeographicTaxonomies toGeoTaxonomies(GeographicTaxonomiesResponse result) {
GeographicTaxonomies geographicTaxonomies = new GeographicTaxonomies();
geographicTaxonomies.setDescription(result.getDescription());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package it.pagopa.selfcare.mscore.connector.rest.client;

import it.pagopa.selfcare.mscore.connector.rest.model.InfocamerePdndResponse;
import it.pagopa.selfcare.mscore.connector.rest.model.geotaxonomy.GeographicTaxonomiesResponse;
import it.pagopa.selfcare.mscore.connector.rest.model.registryproxy.*;
import it.pagopa.selfcare.mscore.model.institution.NationalRegistriesProfessionalAddress;
Expand Down Expand Up @@ -44,4 +45,8 @@ public interface PartyRegistryProxyRestClient extends InsuranceCompaniesApi {
@ResponseBody
PdndResponse getSaByTaxId(@PathVariable(value = "taxId") String taxId);

@GetMapping(value = "${rest-client.party-registry-proxy.infocamere.pdnd.getInstitutionByTaxCode.path}", consumes = APPLICATION_JSON_VALUE)
@ResponseBody
InfocamerePdndResponse getInfocamerePdndInstitutionByTaxCode(@PathVariable(value = "taxCode") String taxCode);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package it.pagopa.selfcare.mscore.connector.rest.mapper;

import it.pagopa.selfcare.mscore.connector.rest.model.InfocamerePdndResponse;
import it.pagopa.selfcare.mscore.model.institution.InfocamerePdndInstitution;
import org.mapstruct.Mapper;

@Mapper(componentModel = "spring")
public interface InfocamereMapper {
InfocamerePdndInstitution toInstitution(InfocamerePdndResponse response);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package it.pagopa.selfcare.mscore.connector.rest.model;

import lombok.Data;

@Data
public class InfocamerePdndResponse {
private String businessTaxId;
private String businessName;
private String legalNature;
private String legalNatureDescription;
private String cciaa;
private String nRea;
private String businessStatus;
private String city;
private String county;
private String zipCode;
private String address;
private String digitalAddress;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ rest-client.party-registry-proxy.geo-taxonomies.getByCode.path=/geotaxonomies/{g
rest-client.party-registry-proxy.aoo.getByCode.path=/aoo/{aooId}
rest-client.party-registry-proxy.uo.getByCode.path=/uo/{uoId}
rest-client.party-registry-proxy.sa.getByTaxId.path=/stations/{taxId}
rest-client.party-registry-proxy.infocamere.pdnd.getInstitutionByTaxCode.path=/infocamere-pdnd/institution/{taxCode}

feign.client.config.party-registry-proxy.requestInterceptors[0]=it.pagopa.selfcare.commons.connector.rest.interceptor.AuthorizationHeaderInterceptor
feign.client.config.party-registry-proxy.requestInterceptors[1]=it.pagopa.selfcare.commons.connector.rest.interceptor.PartyTraceIdInterceptor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import feign.FeignException;
import it.pagopa.selfcare.mscore.connector.rest.client.PartyRegistryProxyRestClient;
import it.pagopa.selfcare.mscore.connector.rest.mapper.*;
import it.pagopa.selfcare.mscore.connector.rest.model.InfocamerePdndResponse;
import it.pagopa.selfcare.mscore.connector.rest.model.geotaxonomy.GeographicTaxonomiesResponse;
import it.pagopa.selfcare.mscore.connector.rest.model.registryproxy.*;
import it.pagopa.selfcare.mscore.constant.Origin;
Expand Down Expand Up @@ -48,11 +49,14 @@ class PartyRegistryProxyConnectorImplTest {
private SaMapper saMapper = new SaMapperImpl();
@Spy
private AsMapper asMapper = new AsMapperImpl();
@Spy
private InfocamereMapper infocamereMapper = new InfocamereMapperImpl();

private final static AooResponse aooResponse;
private final static UoResponse uoResponse;
private final static PdndResponse pdndResponse;
private final static InsuranceCompanyResource asResponse;
private final static InfocamerePdndResponse infocamerePdndResponse;

static {
aooResponse = new AooResponse();
Expand All @@ -66,6 +70,7 @@ class PartyRegistryProxyConnectorImplTest {
uoResponse.setOrigin(Origin.IPA);
pdndResponse = mockInstance(new PdndResponse());
asResponse = mockInstance(new InsuranceCompanyResource());
infocamerePdndResponse = mockInstance(new InfocamerePdndResponse());
}

/**
Expand Down Expand Up @@ -587,5 +592,43 @@ void shouldThrowResourceNotFoundExceptionWhenIvassCodeNotFound() {

assertThrows(ResourceNotFoundException.class, () -> partyRegistryProxyConnectorImpl.getASFromIvass(ivassCode));
}

@Test
void getInfocamerePdndInstitution() {
//given
String taxCode = "taxCode";
when(partyRegistryProxyRestClient.getInfocamerePdndInstitutionByTaxCode(anyString())).thenReturn(infocamerePdndResponse);
//when
InfocamerePdndInstitution result = partyRegistryProxyConnectorImpl.getInfocamerePdndInstitution(taxCode);
//then
checkNotNullFields(result);
verify(partyRegistryProxyRestClient, times(1)).getInfocamerePdndInstitutionByTaxCode(taxCode);
}

@Test
void getInfocamerePdndInstitutionNotFound() {
//given
String taxCode = "taxCode";
when(partyRegistryProxyRestClient.getInfocamerePdndInstitutionByTaxCode(anyString())).thenThrow(ResourceNotFoundException.class);

//when
Executable executable = () -> partyRegistryProxyConnectorImpl.getInfocamerePdndInstitution(taxCode);
//then
assertThrows(ResourceNotFoundException.class, executable);
verify(partyRegistryProxyRestClient, times(1)).getInfocamerePdndInstitutionByTaxCode(taxCode);
}

@Test
void getInfocamerePdndInstitutionFeignException() {
//given
String taxCode = "taxCode";
when(partyRegistryProxyRestClient.getInfocamerePdndInstitutionByTaxCode(anyString())).thenThrow(FeignException.class);

//when
Executable executable = () -> partyRegistryProxyConnectorImpl.getInfocamerePdndInstitution(taxCode);
//then
assertThrows(MsCoreException.class, executable);
verify(partyRegistryProxyRestClient, times(1)).getInfocamerePdndInstitutionByTaxCode(taxCode);
}
}

0 comments on commit e499943

Please sign in to comment.