Skip to content

Commit

Permalink
[VAS-1063] feat: get notice institutions api (#406)
Browse files Browse the repository at this point in the history
Co-authored-by: giomella <giomella@emeal.nttdata.com>
  • Loading branch information
alessio-cialini and gioelemella authored May 29, 2024
1 parent 9cce196 commit ea0efdf
Show file tree
Hide file tree
Showing 17 changed files with 10,793 additions and 11,634 deletions.
22,009 changes: 10,417 additions & 11,592 deletions openapi/openapi.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import it.pagopa.selfcare.pagopa.backoffice.config.feign.ApiConfigSelfcareIntFeignConfig;
import it.pagopa.selfcare.pagopa.backoffice.model.connector.channel.ChannelDetailsList;
import it.pagopa.selfcare.pagopa.backoffice.model.connector.channel.PspChannels;
import it.pagopa.selfcare.pagopa.backoffice.model.connector.creditorinstitution.AvailableCodes;
import it.pagopa.selfcare.pagopa.backoffice.model.connector.creditorinstitution.BrokerCreditorInstitutionDetails;
import it.pagopa.selfcare.pagopa.backoffice.model.connector.creditorinstitution.CreditorInstitutionAssociatedCodeList;
import it.pagopa.selfcare.pagopa.backoffice.model.connector.station.StationDetailsList;
import it.pagopa.selfcare.pagopa.backoffice.model.iban.IbansList;
import it.pagopa.selfcare.pagopa.backoffice.model.institutions.client.CreditorInstitutionInfo;
Expand Down Expand Up @@ -48,8 +48,9 @@ ChannelDetailsList getChannelDetailsListByBroker(
@GetMapping(value = "/creditorinstitutions/{ci-tax-code}/segregationcodes", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
@Valid
CreditorInstitutionAssociatedCodeList getCreditorInstitutionSegregationCodes(
@PathVariable("ci-tax-code") String creditorInstitutionCode
AvailableCodes getCreditorInstitutionSegregationCodes(
@PathVariable("ci-tax-code") String creditorInstitutionCode,
@RequestParam String targetCITaxCode
);


Expand Down Expand Up @@ -82,4 +83,8 @@ BrokerCreditorInstitutionDetails getCreditorInstitutionsAssociatedToBroker(
@GetMapping(value = "/creditorinstitutions", produces = MediaType.APPLICATION_JSON_VALUE)
@Valid
List<CreditorInstitutionInfo> getCreditorInstitutionInfo(@RequestParam List<String> taxCodeList);

@GetMapping(value = "/creditorinstitutions/stations/{station-code}", produces = MediaType.APPLICATION_JSON_VALUE)
@Valid
List<String> getStationCreditorInstitutions(@PathVariable(value = "station-code") String stationCode);
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package it.pagopa.selfcare.pagopa.backoffice.client;

import it.pagopa.selfcare.pagopa.backoffice.config.feign.InstitutionsFeignClientConfig;
import it.pagopa.selfcare.pagopa.backoffice.model.notices.InstitutionUploadData;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@FeignClient(name = "institutions", url = "${rest-client.institutions.base-url}",
Expand All @@ -13,8 +13,13 @@ public interface InstitutionsClient {

@PostMapping(value = "/institutions/data", consumes = {
MediaType.MULTIPART_FORM_DATA_VALUE})
public void updateInstitutions(
void updateInstitutions(
@RequestPart("institutions-data") String institutionsDataContent,
@RequestPart(value = "file") MultipartFile logo);

@GetMapping(value = "/data/{taxCode}", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
InstitutionUploadData getInstitutionData(
@PathVariable(name = "taxCode") String taxCode);

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package it.pagopa.selfcare.pagopa.backoffice.config;

import it.pagopa.selfcare.pagopa.backoffice.mapper.*;
import it.pagopa.selfcare.pagopa.backoffice.model.creditorinstituions.CreditorInstitutionInfo;
import it.pagopa.selfcare.pagopa.backoffice.model.creditorinstituions.CreditorInstitutionView;
import it.pagopa.selfcare.pagopa.backoffice.model.iban.Iban;
import it.pagopa.selfcare.pagopa.backoffice.model.iban.IbanCreateApiconfig;
Expand Down Expand Up @@ -33,6 +34,7 @@ ModelMapper modelMapper() {
mapper.createTypeMap(DelegationExternal.class, CIBrokerDelegationResource.class).setConverter(new ConvertDelegationExternalToCIBrokerDelegationResource());
mapper.createTypeMap(CreditorInstitutionView.class, CIBrokerStationResource.class).setConverter(new ConvertCreditorInstitutionViewToCIBrokerStationResource());
mapper.createTypeMap(Institution.class, InstitutionDetail.class).setConverter(new InstitutionToInstitutionDetail());
mapper.createTypeMap(DelegationExternal.class, CreditorInstitutionInfo.class).setConverter(new ConvertDelegationExternalToCreditorInstitutionInfo());

return mapper;
}
Expand Down
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 @@ -14,6 +15,7 @@
import it.pagopa.selfcare.pagopa.backoffice.model.creditorinstituions.CreditorInstitutionContactsResource;
import it.pagopa.selfcare.pagopa.backoffice.model.creditorinstituions.CreditorInstitutionDetailsResource;
import it.pagopa.selfcare.pagopa.backoffice.model.creditorinstituions.CreditorInstitutionDto;
import it.pagopa.selfcare.pagopa.backoffice.model.creditorinstituions.CreditorInstitutionInfo;
import it.pagopa.selfcare.pagopa.backoffice.model.creditorinstituions.CreditorInstitutionStationDto;
import it.pagopa.selfcare.pagopa.backoffice.model.creditorinstituions.CreditorInstitutionStationEditResource;
import it.pagopa.selfcare.pagopa.backoffice.model.creditorinstituions.CreditorInstitutionsResource;
Expand All @@ -39,6 +41,7 @@
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;

@Slf4j
@RestController
Expand Down Expand Up @@ -109,9 +112,10 @@ public CreditorInstitutionDetailsResource getCreditorInstitutionDetails(
@Operation(summary = "Get the available creditor institution's segregation code", security = {@SecurityRequirement(name = "JWT")})
@OpenApiTableMetadata
public AvailableCodes getCreditorInstitutionSegregationCodes(
@Parameter(description = "Creditor institution's tax code") @PathVariable("ci-tax-code") String ciTaxCode
@Parameter(description = "Creditor institution's tax code that own the station") @PathVariable("ci-tax-code") String ciTaxCode,
@Parameter(description = "Tax code of the creditor institution that will be associated to the station") @RequestParam @NotBlank String targetCITaxCode
) {
return this.ciService.getCreditorInstitutionSegregationCodes(ciTaxCode);
return this.ciService.getCreditorInstitutionSegregationCodes(ciTaxCode, targetCITaxCode);
}

@PostMapping(value = "/{ci-tax-code}/station", produces = {MediaType.APPLICATION_JSON_VALUE})
Expand Down Expand Up @@ -239,7 +243,7 @@ public BrokerAndEcDetailsResource getBrokerAndEcDetails(
* Retrieve the operative table and the payment contacts list of the creditor institution with the provided
* tax code and institution's id
*
* @param ciTaxCode creditor institution's tax code
* @param ciTaxCode creditor institution's tax code
* @param institutionId creditor institution's identifier
* @return the creditor institution's contacts
*/
Expand All @@ -262,4 +266,36 @@ public CreditorInstitutionContactsResource getCreditorInstitutionContacts(
) {
return ciService.getCreditorInstitutionContacts(ciTaxCode, institutionId);
}


/**
* Retrieve the list of creditor institutions that can be associated to the specified station of the specified broker
*
* @param stationCode station's code
* @param brokerId identifier of the broker that own the station
* @return the list of creditor institution's
*/
@GetMapping(value = "/stations/{station-code}")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK",
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
array = @ArraySchema(schema = @Schema(implementation = CreditorInstitutionInfo.class)))),
@ApiResponse(responseCode = "400", description = "Bad Request",
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = ProblemJson.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)))
})
@ResponseStatus(HttpStatus.OK)
@Operation(summary = "Get the list of Creditor Institutions that can be associated to the station", security = {@SecurityRequirement(name = "JWT")})
@OpenApiTableMetadata
public List<CreditorInstitutionInfo> getAvailableCreditorInstitutionsForStation(
@Parameter(description = "Station's code") @PathVariable("station-code") String stationCode,
@Parameter(description = "Broker's unique id") @RequestParam String brokerId
) {
return this.ciService.getAvailableCreditorInstitutionsForStation(stationCode, brokerId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,49 @@ public void updateInstitutions(
schema = @Schema(implementation = InstitutionUploadData.class))
@Valid @NotNull @RequestPart("institutions-data") String institutionsDataContent,
@Parameter(description = "logo file to upload", required = true)
@Valid @NotNull @RequestParam(value = "file", required = false) MultipartFile logo
@Valid @NotNull @RequestPart(value = "file") MultipartFile logo
) {
institutionsService.uploadInstitutionsData(institutionsDataContent, logo);
}

/**
* Retrieving institution data, related to the provided taxCode
* @param taxCode institution data to be used retrieval
* @return institution data
*/
@Operation(summary = "getInstitutionData",
description = "Retrieves saved institution data and logo on the related storage," +
" to be used in the payment notice generation process",
security = {@SecurityRequirement(name = "ApiKey")})
@OpenApiTableMetadata(readWriteIntense = OpenApiTableMetadata.ReadWrite.WRITE,
external = true, internal = false)
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK",
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
schema = @Schema(implementation = ProblemJson.class))),
@ApiResponse(responseCode = "400", description = "Bad Request",
content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
schema = @Schema(implementation = ProblemJson.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)))
})
@GetMapping(value = "/institutions/data/{taxCode}", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public InstitutionUploadData getInstitutionData(
@Parameter(description = "tax code of the CI to use for retrieval")
@PathVariable(name = "taxCode") String taxCode) {
return institutionsService.getInstitutionData(taxCode);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public StationDetailResource getStation(

@GetMapping(value = "/{station-code}/creditor-institutions")
@ResponseStatus(HttpStatus.OK)
@Operation(summary = "Get Creditor Institutions By Station Code", security = {@SecurityRequirement(name = "JWT")})
@Operation(summary = "Get a paginated list of Creditor Institutions associated to a station", security = {@SecurityRequirement(name = "JWT")})
@OpenApiTableMetadata
public CreditorInstitutionsResource getCreditorInstitutionsByStationCode(
@Parameter(description = "Station Code") @PathVariable("station-code") String stationCode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ public enum AppError {
"Exception has been thrown while managing the logo file passed as input," +
" could not create either the working directory or the file"),

INSTITUTION_NOT_FOUND(HttpStatus.NOT_FOUND, "Institution Not Found",
"Required institution data has not been found on the storage"),

INSTITUTION_RETRIEVE_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "Error while retrieving Institution data",
"Unexpected error occurred while retrieving institution data"),

UNKNOWN(null, null, null);

public final HttpStatus httpStatus;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package it.pagopa.selfcare.pagopa.backoffice.mapper;

import it.pagopa.selfcare.pagopa.backoffice.model.creditorinstituions.CreditorInstitutionInfo;
import it.pagopa.selfcare.pagopa.backoffice.model.institutions.DelegationExternal;
import org.modelmapper.Converter;
import org.modelmapper.spi.MappingContext;

/**
* Converter class that specify how to convert a {@link DelegationExternal} instance to a {@link CreditorInstitutionInfo} instance
*/
public class ConvertDelegationExternalToCreditorInstitutionInfo implements Converter<DelegationExternal, CreditorInstitutionInfo> {

@Override
public CreditorInstitutionInfo convert(MappingContext<DelegationExternal, CreditorInstitutionInfo> context) {
DelegationExternal model = context.getSource();

return CreditorInstitutionInfo.builder()
.businessName(model.getInstitutionName())
.ciTaxCode(model.getTaxCode())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package it.pagopa.selfcare.pagopa.backoffice.model.creditorinstituions;

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 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
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("ci_tax_code")
@Schema(example = "02438750586", description = "The tax code of the creditor institution", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank
private String ciTaxCode;
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static RoleType fromSelfcareRole(String institutionCode, String role) {
return Arrays.stream(RoleType.values())
.filter(elem -> role != null && elem.selfcareRole.contains(role))
.findFirst()
.orElseThrow(() -> new AppException(AppError.SELFCARE_ROLE_NOT_FOUND, deNull(institutionCode), deNull(role)));
.orElseThrow(() -> new AppException(AppError.SELFCARE_ROLE_NOT_FOUND, deNull(role), deNull(institutionCode)));
}

}
Loading

0 comments on commit ea0efdf

Please sign in to comment.