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 - 5220] feat: added PDND InfoCamere endpoint retrieveInstitutionsByDescription #207

Merged
merged 7 commits into from
Jul 9, 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
121 changes: 121 additions & 0 deletions app/src/main/resources/swagger/api-docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
}, {
"name" : "infocamere",
"description" : "Info Camere Controller"
}, {
"name" : "infocamere PDND",
"description" : "PDND Info Camere Controller"
}, {
"name" : "institution",
"description" : "Institution operations"
Expand Down Expand Up @@ -1212,6 +1215,82 @@
} ]
}
},
"/infocamere-pdnd/institutions" : {
"get" : {
"tags" : [ "infocamere PDND" ],
"summary" : "Get institutions by institution description",
"description" : "Get the list of companies represented by description of the institutions passed as a parameter",
"operationId" : "institutionsPdndByDescriptionUsingGET",
"parameters" : [ {
"name" : "description",
"in" : "query",
"description" : "swagger.api.info-camere-pdnd.institutions.description}",
"required" : true,
"style" : "form",
"schema" : {
"type" : "string"
}
} ],
"responses" : {
"200" : {
"description" : "OK",
"content" : {
"application/json" : {
"schema" : {
"type" : "array",
"items" : {
"$ref" : "#/components/schemas/PDNDBusinessResource"
}
}
}
}
},
"400" : {
"description" : "Bad Request",
"content" : {
"application/problem+json" : {
"schema" : {
"$ref" : "#/components/schemas/Problem"
}
}
}
},
"401" : {
"description" : "Unauthorized",
"content" : {
"application/problem+json" : {
"schema" : {
"$ref" : "#/components/schemas/Problem"
}
}
}
},
"404" : {
"description" : "Not Found",
"content" : {
"application/problem+json" : {
"schema" : {
"$ref" : "#/components/schemas/Problem"
}
}
}
},
"500" : {
"description" : "Internal Server Error",
"content" : {
"application/problem+json" : {
"schema" : {
"$ref" : "#/components/schemas/Problem"
}
}
}
}
},
"security" : [ {
"bearerAuth" : [ "global" ]
} ]
}
},
"/stations" : {
"get" : {
"tags" : [ "stations" ],
Expand Down Expand Up @@ -1981,6 +2060,48 @@
}
}
},
"PDNDBusinessResource" : {
"title" : "PDNDBusinessResource",
"type" : "object",
"properties" : {
"address" : {
"type" : "string"
},
"businessName" : {
"type" : "string"
},
"businessStatus" : {
"type" : "string"
},
"businessTaxId" : {
"type" : "string"
},
"cciaa" : {
"type" : "string"
},
"city" : {
"type" : "string"
},
"county" : {
"type" : "string"
},
"digitalAddress" : {
"type" : "string"
},
"legalNature" : {
"type" : "string"
},
"legalNatureDescription" : {
"type" : "string"
},
"nrea" : {
"type" : "string"
},
"zipCode" : {
"type" : "string"
}
}
},
"Problem" : {
"title" : "Problem",
"required" : [ "status", "title" ],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ class SwaggerConfigTest {
@MockBean
private UOService uoService;

@MockBean
private PDNDNationalRegistriesService pdndNationalRegistriesService;

@Autowired
WebApplicationContext context;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package it.pagopa.selfcare.party.registry_proxy.connector.api;

import it.pagopa.selfcare.party.registry_proxy.connector.model.nationalregistriespdnd.PDNDBusiness;

import java.util.List;

public interface PDNDNationalRegistriesConnector {

List<PDNDBusiness> retrieveInstitutionsPdndByDescription(String description);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package it.pagopa.selfcare.party.registry_proxy.connector.model.nationalregistriespdnd;

import lombok.Data;

@Data
public class PDNDBusiness {
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;
}
4 changes: 4 additions & 0 deletions connector/rest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-circuitbreaker-resilience4j</artifactId>
</dependency>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
</dependency>

</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
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.PDNDNationalRegistriesConnector;
import it.pagopa.selfcare.party.registry_proxy.connector.model.nationalregistriespdnd.PDNDBusiness;
import it.pagopa.selfcare.party.registry_proxy.connector.rest.client.PDNDNationalRegistriesRestClient;
import it.pagopa.selfcare.party.registry_proxy.connector.rest.model.*;
import it.pagopa.selfcare.party.registry_proxy.connector.rest.model.mapper.PDNDBusinessMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.util.List;

@Slf4j
@Service
public class PDNDNationalRegistriesConnectorImpl implements PDNDNationalRegistriesConnector {
public static final String ERROR_PDND_NATIONAL_REGISTRIES_REST_CLIENT_MESSAGE = "Error pdnd-national-registries rest client, message: %s";

private final PDNDNationalRegistriesRestClient pdndNationalRegistriesRestClient;
private final PDNDBusinessMapper pdndBusinessMapper;

public PDNDNationalRegistriesConnectorImpl(PDNDNationalRegistriesRestClient pdndNationalRegistriesRestClient, PDNDBusinessMapper pdndBusinessMapper) {
this.pdndNationalRegistriesRestClient = pdndNationalRegistriesRestClient;
this.pdndBusinessMapper = pdndBusinessMapper;
}

@Override
@CircuitBreaker(name = "pdndNationalRegistriesCircuitbreaker", fallbackMethod = "fallbackRetrieveInstitutionByDescription")
@Retry(name = "retryServiceUnavailable")
public List<PDNDBusiness> retrieveInstitutionsPdndByDescription(String description) {
Assert.hasText(description, "Description is required");
List<PDNDImpresa> result = pdndNationalRegistriesRestClient.retrieveInstitutionsPdndByDescription(description);
return pdndBusinessMapper.toPDNDBusiness(result);
}

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

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package it.pagopa.selfcare.party.registry_proxy.connector.rest.client;

import it.pagopa.selfcare.party.registry_proxy.connector.rest.model.*;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;

@FeignClient(name = "${rest-client.pdnd-national-registries.serviceCode}", url = "${rest-client.pdnd-national-registries.base-url}")
public interface PDNDNationalRegistriesRestClient {

@GetMapping(value = "${rest-client.pdnd-national-registries.getDescription.path}", consumes = APPLICATION_JSON_VALUE)
@ResponseBody
List<PDNDImpresa> retrieveInstitutionsPdndByDescription(@RequestParam String description);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package it.pagopa.selfcare.party.registry_proxy.connector.rest.config;

import it.pagopa.selfcare.commons.connector.rest.config.RestClientBaseConfig;
import it.pagopa.selfcare.party.registry_proxy.connector.rest.client.PDNDNationalRegistriesRestClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.PropertySource;

@Configuration
@Import(RestClientBaseConfig.class)
@EnableFeignClients(clients = PDNDNationalRegistriesRestClient.class)
@PropertySource("classpath:config/pdnd-national-registries-rest-client.properties")
public class PDNDNationalRegistriesRestClientConfig {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package it.pagopa.selfcare.party.registry_proxy.connector.rest.model;

import lombok.Data;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlType;

@Data
@XmlRootElement(name = "Impresa", namespace = "http://it.registroimprese.pcad.ws")
@XmlType(propOrder = {
"businessTaxId",
"businessName",
"legalNature",
"legalNatureDescription",
"cciaa",
"nRea",
"businessStatus",
"provinciaSede",
"comuneSede",
"toponimoSede",
"viaSede",
"ncivicoSede",
"capSede",
"digitalAddress"
})
public class PDNDImpresa {

@XmlElement(name = "CodiceFiscale")
private String businessTaxId;

@XmlElement(name = "Denominazione")
private String businessName;

@XmlElement(name = "NaturaGiuridica")
private String legalNature;

@XmlElement(name = "DescNaturaGiuridica")
private String legalNatureDescription;

@XmlElement(name = "Cciaa")
private String cciaa;

@XmlElement(name = "NRea")
private String nRea;

@XmlElement(name = "StatoImpresa")
private String businessStatus;

@XmlElement(name = "ComuneSede")
private String city;

@XmlElement(name = "ProvinciaSede")
private String county;

@XmlElement(name = "CapSede")
private String zipCode;

@XmlElement(name = "PEC")
private String digitalAddress;

private String toponimoSede;
private String viaSede;
private String ncivicoSede;

@XmlElement(name = "ToponimoSede")
public String getToponimoSede() {
return toponimoSede;
}

public void setToponimoSede(String toponimoSede) {
this.toponimoSede = toponimoSede;
}

@XmlElement(name = "ViaSede")
public String getViaSede() {
return viaSede;
}

public void setViaSede(String viaSede) {
this.viaSede = viaSede;
}

@XmlElement(name = "NcivicoSede")
public String getNcivicoSede() {
return ncivicoSede;
}

public void setNcivicoSede(String ncivicoSede) {
this.ncivicoSede = ncivicoSede;
}

@XmlTransient
public String getAddress() {
return toponimoSede + " " + viaSede + " " + ncivicoSede;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package it.pagopa.selfcare.party.registry_proxy.connector.rest.model.mapper;

import it.pagopa.selfcare.party.registry_proxy.connector.model.nationalregistriespdnd.PDNDBusiness;
import it.pagopa.selfcare.party.registry_proxy.connector.rest.model.PDNDImpresa;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

import java.util.List;

@Mapper(componentModel = "spring")
public interface PDNDBusinessMapper {

@Mapping(source = "getAddress", target = "address")
List<PDNDBusiness> toPDNDBusiness(List<PDNDImpresa> pdndImpresaList);

}
Loading
Loading