Skip to content

Commit

Permalink
[VAS-800] feat: Add new get creditor institution name API (#38)
Browse files Browse the repository at this point in the history
* [VAS-800] Added new api to retrieved creditor institution business names. Do some refactor and added javadoc

* [VAS-800] Added unit tests and fixed test packages

* [VAS-800] updated openapi

* [VAS-800] add constraint on body size and updated openapi

* [VAS-800] updated api definition, unit test and openapi

---------

Co-authored-by: giomella <[email protected]>
  • Loading branch information
gioelemella and giomella authored Mar 15, 2024
1 parent 1a7a7e8 commit 720d6f2
Show file tree
Hide file tree
Showing 28 changed files with 839 additions and 508 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ Spring Application that exposes a subset of the APIs to manage configuration for
needed by PagoPA SelfCare application.

- [pagoPa Api Config - SelfCare integration](#pagopa-api-config---selfcare-integration)
* [Api Documentation 📖](#api-documentation---)
* [Api Documentation 📖](#api-documentation-)
* [Technology Stack](#technology-stack)
* [Start Project Locally 🚀](#start-project-locally---)
* [Start Project Locally 🚀](#start-project-locally-)
+ [Prerequisites](#prerequisites)
+ [Run docker container](#run-docker-container)
* [Develop Locally 💻](#develop-locally---)
* [Develop Locally 💻](#develop-locally-)
+ [Prerequisites](#prerequisites-1)
+ [Run the project](#run-the-project)
+ [Spring Profiles](#spring-profiles)
+ [Testing 🧪](#testing---)
+ [Testing 🧪](#testing-)
- [Unit testing](#unit-testing)
- [Integration testing](#integration-testing)
- [Performance testing](#performance-testing)
* [Contributors 👥](#contributors---)
+ [Mainteiners](#mainteiners)
* [Contributors 👥](#contributors-)
+ [Maintainers](#maintainers)

---

Expand Down Expand Up @@ -69,11 +69,11 @@ from `./docker` directory

Start the springboot application with this command for local test:

`mvn spring-boot:run -Dspring-boot.run.profiles=local`
`mvn spring-boot:run -Dspring.profiles.active=local`

or, for H2 tests:

`mvn spring-boot:run -Dspring-boot.run.profiles=h2`
`mvn spring-boot:run -Dspring.profiles.active=h2`

Using the spring profile `local`, the Spring application connects to the H2 in-memory DB.
For access to H2 console, use this url: http://localhost:8080/h2-console/
Expand Down Expand Up @@ -111,6 +111,6 @@ install [k6](https://k6.io/) and then from `./performance-test/src`

Made with ❤️ by PagoPa S.p.A.

### Mainteiners
### Maintainers

See `CODEOWNERS` file
146 changes: 145 additions & 1 deletion openapi/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,131 @@
}
]
},
"/creditorinstitutions": {
"get": {
"tags": [
"Creditor Institutions"
],
"summary": "Get the list of creditor institution business names",
"description": "Return a list of business name and tax code of creditor institutions, given the provided list of creditor institution tax codes",
"operationId": "getCreditorInstitutionNamesFromTaxCodes",
"parameters": [
{
"name": "taxCodeList",
"in": "query",
"description": "List of Creditor Institution's tax code",
"required": true,
"schema": {
"maxItems": 10,
"minItems": 0,
"type": "array",
"items": {
"type": "string"
}
}
}
],
"responses": {
"200": {
"description": "OK",
"headers": {
"X-Request-Id": {
"description": "This header identifies the call",
"schema": {
"type": "string"
}
}
},
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/CreditorInstitutionInfo"
}
}
}
}
},
"401": {
"description": "Unauthorized",
"headers": {
"X-Request-Id": {
"description": "This header identifies the call",
"schema": {
"type": "string"
}
}
}
},
"404": {
"description": "Not Found",
"headers": {
"X-Request-Id": {
"description": "This header identifies the call",
"schema": {
"type": "string"
}
}
},
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ProblemJson"
}
}
}
},
"429": {
"description": "Too many requests",
"headers": {
"X-Request-Id": {
"description": "This header identifies the call",
"schema": {
"type": "string"
}
}
}
},
"500": {
"description": "Service unavailable",
"headers": {
"X-Request-Id": {
"description": "This header identifies the call",
"schema": {
"type": "string"
}
}
},
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ProblemJson"
}
}
}
}
},
"security": [
{
"ApiKey": []
},
{
"Authorization": []
}
]
},
"parameters": [
{
"name": "X-Request-Id",
"in": "header",
"description": "This header identifies the call, if not passed it is self-generated. This ID is returned in the response.",
"schema": {
"type": "string"
}
}
]
},
"/creditorinstitutions/{creditorInstitutionCode}/applicationcodes": {
"get": {
"tags": [
Expand Down Expand Up @@ -1723,6 +1848,25 @@
}
}
},
"CreditorInstitutionInfo": {
"required": [
"business_name",
"creditor_institution_code"
],
"type": "object",
"properties": {
"business_name": {
"type": "string",
"description": "The business name of the creditor institution",
"example": "Comune di Roma"
},
"creditor_institution_code": {
"type": "string",
"description": "The tax code of the creditor institution",
"example": "02438750586"
}
}
},
"BrokerDetails": {
"required": [
"broker_code",
Expand Down Expand Up @@ -2143,4 +2287,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,23 @@
import it.gov.pagopa.apiconfig.selfcareintegration.mapper.ConvertCanaliToChannelDetails;
import it.gov.pagopa.apiconfig.selfcareintegration.mapper.ConvertIbanMasterToIbanDetail;
import it.gov.pagopa.apiconfig.selfcareintegration.mapper.ConvertPaStazionePaToCreditorInstitutionDetail;
import it.gov.pagopa.apiconfig.selfcareintegration.mapper.ConvertPaToCreditorInstitutionInfo;
import it.gov.pagopa.apiconfig.selfcareintegration.model.channel.ChannelDetails;
import it.gov.pagopa.apiconfig.selfcareintegration.model.creditorinstitution.CreditorInstitutionDetail;
import it.gov.pagopa.apiconfig.selfcareintegration.model.creditorinstitution.CreditorInstitutionInfo;
import it.gov.pagopa.apiconfig.selfcareintegration.model.iban.IbanDetails;
import it.gov.pagopa.apiconfig.starter.entity.Canali;
import it.gov.pagopa.apiconfig.starter.entity.IbanMaster;
import it.gov.pagopa.apiconfig.starter.entity.Pa;
import it.gov.pagopa.apiconfig.starter.entity.PaStazionePa;
import org.modelmapper.ModelMapper;
import org.modelmapper.convention.MatchingStrategies;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
* Configuration class for model mapper definitions
*/
@Configuration
public class MappingsConfiguration {

Expand All @@ -23,16 +29,13 @@ ModelMapper modelMapper() {
mapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);

// insert here the new mappers
mapper
.createTypeMap(Canali.class, ChannelDetails.class)
.setConverter(new ConvertCanaliToChannelDetails());
mapper
.createTypeMap(IbanMaster.class, IbanDetails.class)
.setConverter(new ConvertIbanMasterToIbanDetail());
mapper
.createTypeMap(PaStazionePa.class, CreditorInstitutionDetail.class)
mapper.createTypeMap(Canali.class, ChannelDetails.class).setConverter(new ConvertCanaliToChannelDetails());
mapper.createTypeMap(IbanMaster.class, IbanDetails.class).setConverter(new ConvertIbanMasterToIbanDetail());
mapper.createTypeMap(PaStazionePa.class, CreditorInstitutionDetail.class)
.setConverter(new ConvertPaStazionePaToCreditorInstitutionDetail());

mapper.createTypeMap(Pa.class, CreditorInstitutionInfo.class).setConverter(new ConvertPaToCreditorInstitutionInfo());

return mapper;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
Expand All @@ -10,13 +11,11 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import it.gov.pagopa.apiconfig.selfcareintegration.model.ProblemJson;
import it.gov.pagopa.apiconfig.selfcareintegration.model.code.CIAssociatedCodeList;
import it.gov.pagopa.apiconfig.selfcareintegration.model.creditorinstitution.CreditorInstitutionInfo;
import it.gov.pagopa.apiconfig.selfcareintegration.model.station.StationDetailsList;
import it.gov.pagopa.apiconfig.selfcareintegration.service.CreditorInstitutionsService;
import javax.validation.Valid;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.Positive;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
Expand All @@ -27,14 +26,22 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.Positive;
import javax.validation.constraints.Size;
import java.util.List;

@RestController()
@RequestMapping(path = "/creditorinstitutions")
@Tag(name = "Creditor Institutions", description = "Everything about Creditor Institution")
@Validated
public class CreditorInstitutionController {

private final CreditorInstitutionsService creditorInstitutionsService;
private final CreditorInstitutionsService creditorInstitutionsService;

@Autowired
public CreditorInstitutionController(CreditorInstitutionsService creditorInstitutionsService) {
this.creditorInstitutionsService = creditorInstitutionsService;
}
Expand Down Expand Up @@ -259,4 +266,31 @@ public ResponseEntity<CIAssociatedCodeList> getSegregationCodesFromCreditorInsti
creditorInstitutionsService.getSegregationCodesFromCreditorInstitution(
creditorInstitutionCode, showUsedCodes, service));
}

/**
* Retrieve a list of creditor institution business names, given the provided list of creditor institution tax codes
*
* @param taxCodeList the list of creditor institution tax codes
* @return a list of {@link CreditorInstitutionInfo}, containing the business name and tax code of creditor institution
*/
@Operation(summary = "Get the list of creditor institution business names",
description = "Return a list of business name and tax code of creditor institutions, given the provided list of creditor institution tax codes",
security = {@SecurityRequirement(name = "ApiKey"), @SecurityRequirement(name = "Authorization")})
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK",
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
array = @ArraySchema(schema = @Schema(implementation = CreditorInstitutionInfo.class)))),
@ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema())),
@ApiResponse(responseCode = "404", description = "Not Found",
content = @Content(schema = @Schema(implementation = ProblemJson.class))),
@ApiResponse(responseCode = "429", description = "Too many requests", content = @Content(schema = @Schema())),
@ApiResponse(responseCode = "500", description = "Service unavailable",
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = ProblemJson.class)))})
@GetMapping(value = "", produces = {MediaType.APPLICATION_JSON_VALUE})
@Cacheable(value = "getCreditorInstitutionNamesFromTaxCodes")
public ResponseEntity<List<CreditorInstitutionInfo>> getCreditorInstitutionNamesFromTaxCodes(
@Parameter(description = "List of Creditor Institution's tax code") @RequestParam @Size(max = 10) List<String> taxCodeList
) {
return ResponseEntity.ok(this.creditorInstitutionsService.getCreditorInstitutionInfoList(taxCodeList));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@
import lombok.Getter;
import org.springframework.http.HttpStatus;

/**
* Enum defining the application errors
*/
@Getter
public enum AppError {
INTERNAL_SERVER_ERROR(
HttpStatus.INTERNAL_SERVER_ERROR, "Internal Server Error", "Something was wrong"),
HttpStatus.INTERNAL_SERVER_ERROR, "Internal Server Error", "Something was wrong: %s"),
CREDITOR_INSTITUTION_NOT_FOUND(
HttpStatus.NOT_FOUND,
"Creditor Institution not found",
"No Creditor Institution found with code: %s"),
MULTIPLE_CREDITOR_INSTITUTIONS_NOT_FOUND(
HttpStatus.NOT_FOUND,
"Creditor Institutions not found",
"No Creditor Institutions found with codes: %s"),

BROKER_NOT_FOUND(HttpStatus.NOT_FOUND, "Broker not found", "No Broker found with code: %s"),
UNKNOWN(null, null, null);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package it.gov.pagopa.apiconfig.selfcareintegration.mapper;

import it.gov.pagopa.apiconfig.selfcareintegration.model.creditorinstitution.CreditorInstitutionInfo;
import it.gov.pagopa.apiconfig.starter.entity.Pa;
import org.modelmapper.Converter;
import org.modelmapper.spi.MappingContext;

import javax.validation.Valid;

/**
* Converter class, define how to map the {@link Pa} entity into the {@link CreditorInstitutionInfo} model
*/
public class ConvertPaToCreditorInstitutionInfo implements Converter<Pa, CreditorInstitutionInfo> {

@Override
public CreditorInstitutionInfo convert(MappingContext<Pa, CreditorInstitutionInfo> context) {
@Valid Pa pa = context.getSource();
return CreditorInstitutionInfo.builder()
.creditorInstitutionCode(pa.getIdDominio())
.businessName(pa.getRagioneSociale() != null ? pa.getRagioneSociale() : "")
.build();
}
}
Loading

0 comments on commit 720d6f2

Please sign in to comment.