generated from pagopa/template-java-spring-microservice
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from pagopa/fix-iban-list-model
fixing mapping to new model
- Loading branch information
Showing
14 changed files
with
212 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...t/gov/pagopa/apiconfig/selfcareintegration/mapper/ConvertIbanMasterToIbanDetailsTemp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
100 changes: 100 additions & 0 deletions
100
src/main/java/it/gov/pagopa/apiconfig/selfcareintegration/model/iban/IbanEnhanced.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/main/java/it/gov/pagopa/apiconfig/selfcareintegration/util/Constants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...ain/java/it/gov/pagopa/apiconfig/selfcareintegration/util/OffsetDateTimeDeserializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |