Skip to content

Commit

Permalink
[VAS-800] Added new api to retrieved creditor institution business na…
Browse files Browse the repository at this point in the history
…mes. Do some refactor and added javadoc
  • Loading branch information
giomella committed Mar 14, 2024
1 parent 7c67403 commit d3d8bf1
Show file tree
Hide file tree
Showing 7 changed files with 290 additions and 154 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
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,31 +11,39 @@
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;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
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.NotEmpty;
import javax.validation.constraints.Positive;
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 +268,30 @@ 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 = "403", description = "Forbidden", 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)))})
@PostMapping(value = "", produces = {MediaType.APPLICATION_JSON_VALUE})
@Cacheable(value = "getCreditorInstitutionNamesFromTaxCodes")
public ResponseEntity<List<CreditorInstitutionInfo>> getCreditorInstitutionNamesFromTaxCodes(@RequestBody @NotEmpty 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();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package it.gov.pagopa.apiconfig.selfcareintegration.model.creditorinstitution;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

/**
* Model that represent the name and tax code of a creditor institution
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ToString
@JsonInclude(JsonInclude.Include.NON_NULL)
public class CreditorInstitutionInfo {

@JsonProperty("business_name")
@Schema(example = "Comune di Roma", description = "The business name of the creditor institution", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull
private String businessName;

@JsonProperty("creditor_institution_code")
@Schema(example = "02438750586", description = "The tax code of the creditor institution", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank
private String creditorInstitutionCode;
}
Loading

0 comments on commit d3d8bf1

Please sign in to comment.