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

fixing mapping to new model #51

Merged
merged 5 commits into from
May 31, 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
4 changes: 2 additions & 2 deletions helm/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ apiVersion: v2
name: pagopa-api-config-selfcare-integration
description: Microservice that manages requests from selfcare
type: application
version: 1.87.0
appVersion: 1.10.13
version: 1.89.0
appVersion: 1.10.13-2-fix-iban-list-model
dependencies:
- name: microservice-chart
version: 2.8.0
Expand Down
2 changes: 1 addition & 1 deletion helm/values-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ microservice-chart: &microservice-chart
envSecret: {}
image:
repository: ghcr.io/pagopa/pagopa-api-config-selfcare-integration
tag: "1.10.13"
tag: "1.10.13-2-fix-iban-list-model"
pullPolicy: Always
livenessProbe:
httpGet:
Expand Down
2 changes: 1 addition & 1 deletion helm/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ microservice-chart: &microservice-chart
envSecret: {}
image:
repository: ghcr.io/pagopa/pagopa-api-config-selfcare-integration
tag: "1.10.13"
tag: "1.10.13-2-fix-iban-list-model"
pullPolicy: Always
livenessProbe:
httpGet:
Expand Down
2 changes: 1 addition & 1 deletion helm/values-uat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ microservice-chart: &microservice-chart
envSecret: {}
image:
repository: ghcr.io/pagopa/pagopa-api-config-selfcare-integration
tag: "1.10.13"
tag: "1.10.13-2-fix-iban-list-model"
pullPolicy: Always
livenessProbe:
httpGet:
Expand Down
2 changes: 1 addition & 1 deletion openapi/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"title": "API-Config - SelfCare Integration",
"description": "Spring application exposes APIs for SelfCare",
"termsOfService": "https://www.pagopa.gov.it/",
"version": "1.10.13"
"version": "1.10.13-2-fix-iban-list-model"
},
"servers": [
{
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<groupId>it.gov.pagopa.api-config</groupId>
<artifactId>selfcareintegration</artifactId>
<version>1.10.13</version>
<version>1.10.13-2-fix-iban-list-model</version>
<name>API-Config - SelfCare Integration</name>
<description>Spring application exposes APIs for SelfCare</description>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package it.gov.pagopa.apiconfig.selfcareintegration.config;

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.mapper.*;
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.selfcareintegration.model.iban.IbanEnhanced;
import it.gov.pagopa.apiconfig.starter.entity.Canali;
import it.gov.pagopa.apiconfig.starter.entity.IbanMaster;
import it.gov.pagopa.apiconfig.starter.entity.Pa;
Expand Down Expand Up @@ -35,6 +33,7 @@ ModelMapper modelMapper() {
.setConverter(new ConvertPaStazionePaToCreditorInstitutionDetail());

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

return mapper;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import it.gov.pagopa.apiconfig.selfcareintegration.model.ProblemJson;
import it.gov.pagopa.apiconfig.selfcareintegration.model.iban.IbansList;
import it.gov.pagopa.apiconfig.selfcareintegration.model.iban.IbansListTemp;
import it.gov.pagopa.apiconfig.selfcareintegration.model.iban.IbansEnhanced;
import it.gov.pagopa.apiconfig.selfcareintegration.service.IbansService;
import java.util.List;
import javax.validation.Valid;
Expand Down Expand Up @@ -139,7 +139,7 @@ public ResponseEntity<IbansList> getIbans(
content =
@Content(
mediaType = MediaType.APPLICATION_JSON_VALUE,
schema = @Schema(implementation = IbansListTemp.class))),
schema = @Schema(implementation = IbansEnhanced.class))),
@ApiResponse(
responseCode = "400",
description = "Bad Request",
Expand Down Expand Up @@ -174,7 +174,7 @@ public ResponseEntity<IbansList> getIbans(
@GetMapping(
value = "/{creditorinstitutioncode}/list",
produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<IbansListTemp> getIbans(
public ResponseEntity<IbansEnhanced> getIbans(
@Size(max = 50)
@Parameter(
description = "The fiscal code of the Organization.",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package it.gov.pagopa.apiconfig.selfcareintegration.mapper;

import it.gov.pagopa.apiconfig.selfcareintegration.model.iban.IbanEnhanced;
import it.gov.pagopa.apiconfig.selfcareintegration.model.iban.IbanLabel;
import it.gov.pagopa.apiconfig.starter.entity.Iban;
import it.gov.pagopa.apiconfig.starter.entity.IbanAttributeMaster;
import it.gov.pagopa.apiconfig.starter.entity.IbanMaster;
import org.modelmapper.Converter;
import org.modelmapper.spi.MappingContext;

import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.util.List;

public class ConvertIbanMasterToIbanDetailsTemp implements Converter<IbanMaster, IbanEnhanced> {

@Override
public IbanEnhanced convert(MappingContext<IbanMaster, IbanEnhanced> context) {
IbanMaster src = context.getSource();

List<IbanLabel> labels = src.getIbanAttributesMasters().stream()
.map(IbanAttributeMaster::getIbanAttribute)
.map(label -> IbanLabel.builder()
.name(label.getAttributeName())
.description(label.getAttributeDescription())
.build())
.toList();

Iban iban = src.getIban();
return IbanEnhanced.builder()
.ciOwnerFiscalCode(src.getPa().getIdDominio())
.companyName(src.getPa().getRagioneSociale())
.ibanValue(iban.getIban())
.publicationDate(OffsetDateTime.ofInstant(src.getInsertedDate().toInstant(), ZoneId.of("UTC")))
.validityDate(OffsetDateTime.ofInstant(src.getValidityDate().toInstant(), ZoneId.of("UTC")))
.dueDate(OffsetDateTime.ofInstant(iban.getDueDate().toInstant(), ZoneId.of("UTC")))
.description(src.getDescription())
.labels(labels)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package it.gov.pagopa.apiconfig.selfcareintegration.model.iban;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.ser.OffsetDateTimeSerializer;
import io.swagger.v3.oas.annotations.media.Schema;
import it.gov.pagopa.apiconfig.selfcareintegration.util.Constants;
import it.gov.pagopa.apiconfig.selfcareintegration.util.OffsetDateTimeDeserializer;
import lombok.*;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import java.time.OffsetDateTime;
import java.util.List;

/**
* Iban detail
*/
@Data
@Builder(toBuilder = true)
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class IbanEnhanced {

@JsonProperty("iban")
@Schema(example = "IT99C0222211111000000000000", required = true, description = "The iban code")
@Pattern(regexp = "[a-zA-Z]{2}\\d{2}[a-zA-Z0-9]{1,30}", message = "IBAN code not valid")
@Size(max = 35)
@NotNull
private String ibanValue;

@JsonProperty(value = "ci_owner", access = JsonProperty.Access.READ_ONLY)
@Schema(
example = "77777777777",
required = true,
description = "Fiscal code of the Creditor Institution who owns the iban")
@Size(max = 11)
private String ciOwnerFiscalCode;

@JsonProperty(value = "company_name", access = JsonProperty.Access.READ_ONLY)
@Schema(example = "Comune di Firenze", description = "The Creditor Institution company name")
@Size(max = 100)
private String companyName;

@JsonProperty("description")
@Schema(
example = "Riscossione Tributi",
required = false,
description = "The description the Creditor Institution gives to the iban about its usage")
@Size(max = 300)
private String description;

@JsonProperty("is_active")
@Schema(example = "true", required = true, description = "True if the iban is active")
@NotNull
private boolean isActive;

@JsonProperty("validity_date")
@JsonFormat(pattern = Constants.DateTimeFormat.DATE_TIME_FORMAT)
@JsonSerialize(using = OffsetDateTimeSerializer.class)
@JsonDeserialize(using = OffsetDateTimeDeserializer.class)
@Schema(
example = "2023-04-01T13:49:19.897Z",
required = true,
description = "The date the Creditor Institution wants the iban to be used for its payments")
@NotNull
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
private OffsetDateTime validityDate;

@JsonProperty(value = "publication_date", access = JsonProperty.Access.READ_ONLY)
@JsonFormat(pattern = Constants.DateTimeFormat.DATE_TIME_FORMAT)
@JsonSerialize(using = OffsetDateTimeSerializer.class)
@Schema(
example = "2023-06-01T23:59:59.999Z",
required = true,
description = "The date on which the iban has been inserted in the system")
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
private OffsetDateTime publicationDate;

@JsonProperty(value = "due_date")
@JsonFormat(pattern = Constants.DateTimeFormat.DATE_TIME_FORMAT)
@JsonSerialize(using = OffsetDateTimeSerializer.class)
@JsonDeserialize(using = OffsetDateTimeDeserializer.class)
@Schema(
example = "2023-12-31T23:59:59.999Z",
required = true,
description = "The date on which the iban will expire")
@NotNull
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
private OffsetDateTime dueDate;

@JsonProperty("labels")
@Schema(description = "The labels array associated with the iban")
private List<IbanLabel> labels;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class IbansListTemp {
public class IbansEnhanced {

@JsonProperty("ibans")
@JsonProperty("ibans_enhanced")
@NotNull
@Schema(description = "List of IBANs associated to the passed creditor institutions")
private List<IbanDetails> ibans;
private List<IbanEnhanced> ibanEnhancedList;

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import it.gov.pagopa.apiconfig.selfcareintegration.exception.AppError;
import it.gov.pagopa.apiconfig.selfcareintegration.exception.AppException;
import it.gov.pagopa.apiconfig.selfcareintegration.model.iban.IbanDetails;
import it.gov.pagopa.apiconfig.selfcareintegration.model.iban.IbanEnhanced;
import it.gov.pagopa.apiconfig.selfcareintegration.model.iban.IbansList;
import it.gov.pagopa.apiconfig.selfcareintegration.model.iban.IbansListTemp;
import it.gov.pagopa.apiconfig.selfcareintegration.model.iban.IbansEnhanced;
import it.gov.pagopa.apiconfig.selfcareintegration.repository.ExtendedIbanMasterRepository;
import it.gov.pagopa.apiconfig.selfcareintegration.util.Utility;
import it.gov.pagopa.apiconfig.starter.entity.IbanMaster;
Expand Down Expand Up @@ -53,7 +54,7 @@ public IbansList getIbans(@NotEmpty List<String> creditorInstitutions, @NotNull
.build();
}

public IbansListTemp getIbansList(@NotNull String organizationFiscalCode, String label) {
public IbansEnhanced getIbansList(@NotNull String organizationFiscalCode, String label) {
Pa pa = getPaIfExists(organizationFiscalCode);

List<IbanMaster> ibanMasters;
Expand All @@ -63,19 +64,19 @@ public IbansListTemp getIbansList(@NotNull String organizationFiscalCode, String
ibanMasters = extendedIbanMasterRepository.findByFkPaAndLabel(pa.getObjId(), label);
}

List<IbanDetails> ibanDetailsList = ibanMasters.stream()
.map(elem -> modelMapper.map(elem, IbanDetails.class))
List<IbanEnhanced> ibanDetailsList = ibanMasters.stream()
.map(elem -> modelMapper.map(elem, IbanEnhanced.class))
.collect(Collectors.toList());

if(ibanDetailsList.isEmpty() && (("ACA").equals(label) || ("0201138TS").equals(label))) {
IbanMaster lastPublishedIban = getLastPublishedIban(pa);
if(lastPublishedIban != null) {
ibanDetailsList.add(modelMapper.map(lastPublishedIban, IbanDetails.class));
ibanDetailsList.add(modelMapper.map(lastPublishedIban, IbanEnhanced.class));
}
}

return IbansListTemp.builder()
.ibans(ibanDetailsList)
return IbansEnhanced.builder()
.ibanEnhancedList(ibanDetailsList)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
package it.gov.pagopa.apiconfig.selfcareintegration.util;

import lombok.experimental.UtilityClass;

public class Constants {

@UtilityClass
public static class DateTimeFormat {
public static final String DATE_TIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
}

public static final String HEADER_REQUEST_ID = "X-Request-Id";

public static final String DATE_TIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package it.gov.pagopa.apiconfig.selfcareintegration.util;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;

import java.io.IOException;
import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;

/**
* This class permits to deserialize a date, encapsulated in {@code OffsetDateTime} object, from a
* JSON body request using Jackson deserializer.
*/
public class OffsetDateTimeDeserializer extends JsonDeserializer<OffsetDateTime> {

private final DateTimeFormatter dateFormatter =
new DateTimeFormatterBuilder()
.append(DateTimeFormatter.ISO_LOCAL_DATE_TIME)
.optionalStart()
.appendOffset("+HH:MM", "+00:00")
.optionalEnd() // for '+00:00' offset
.optionalStart()
.appendOffset("+HHMM", "+0000")
.optionalEnd() // for '+0000' offset
.optionalStart()
.appendOffset("+HH", "+00")
.optionalEnd() // for '+00' offset
.optionalStart()
.appendPattern("X")
.optionalEnd() // for 'Z' offset
.toFormatter();

@Override
public OffsetDateTime deserialize(JsonParser parser, DeserializationContext context)
throws IOException {
return OffsetDateTime.parse(parser.getText(), dateFormatter);
}
}
Loading