Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jacopocarlini committed Apr 11, 2024
2 parents 59070a8 + 59e47fe commit 83901cb
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 58 deletions.
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: gpd-payments-pull
description: Microservice pagopa-gpd-payments-pull
type: application
version: 0.15.0
appVersion: 1.0.8
version: 0.16.0
appVersion: 1.0.9
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 @@ -4,7 +4,7 @@ microservice-chart:
fullnameOverride: "gpd-payments-pull"
image:
repository: ghcr.io/pagopa/pagopa-gpd-payments-pull
tag: "1.0.8"
tag: "1.0.9"
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 @@ -4,7 +4,7 @@ microservice-chart:
fullnameOverride: "gpd-payments-pull"
image:
repository: ghcr.io/pagopa/pagopa-gpd-payments-pull
tag: "1.0.8"
tag: "1.0.9"
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 @@ -4,7 +4,7 @@ microservice-chart:
fullnameOverride: "gpd-payments-pull"
image:
repository: ghcr.io/pagopa/pagopa-gpd-payments-pull
tag: "1.0.8"
tag: "1.0.9"
pullPolicy: Always
livenessProbe:
httpGet:
Expand Down
12 changes: 7 additions & 5 deletions openapi/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"title": "gpd-payments-pull",
"description": "GPD Payments Pull Services",
"termsOfService": "https://www.pagopa.gov.it/",
"version": "1.0.8"
"version": "1.0.9"
},
"servers": [
{
Expand Down Expand Up @@ -237,7 +237,7 @@
"status": {
"allOf": [
{
"$ref": "#/components/schemas/TransferStatus"
"$ref": "#/components/schemas/PaymentOptionStatus"
},
{
"description": "Status of the OP"
Expand Down Expand Up @@ -422,10 +422,12 @@
}
}
},
"TransferStatus": {
"PaymentOptionStatus": {
"enum": [
"T_UNREPORTED",
"T_REPORTED"
"PO_UNPAID",
"PO_PAID",
"PO_PARTIALLY_REPORTED",
"PO_REPORTED"
],
"type": "string"
}
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>it.gov.pagopa</groupId>
<artifactId>gpd-payments-pull</artifactId>
<name>GPD Payments Pull Services</name>
<version>1.0.8</version>
<version>1.0.9</version>

<properties>
<jacoco.version>0.8.7</jacoco.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public class PaymentOption implements Serializable {
@Builder.Default
@OneToMany(
targetEntity = Transfer.class,
fetch = FetchType.EAGER,
fetch = FetchType.LAZY,
mappedBy = "paymentOption",
cascade = CascadeType.ALL,
orphanRemoval = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
import it.gov.pagopa.gpd.payments.pull.models.PaymentOption;
import it.gov.pagopa.gpd.payments.pull.models.enums.PaymentNoticeStatus;

import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
* Payment Notice mapping methods
*/
Expand All @@ -19,7 +24,7 @@ public class PaymentNoticeMapper {
* @return mapped PaymentNotice instance
*/
public static PaymentNotice manNotice(PaymentPosition paymentPosition) {
return PaymentNotice
PaymentNotice paymentNotice = PaymentNotice
.builder()
.iupd(paymentPosition.getIupd())
.debtorFullName(paymentPosition.getFullName())
Expand All @@ -32,55 +37,63 @@ public static PaymentNotice manNotice(PaymentPosition paymentPosition) {
.paFullName(paymentPosition.getCompanyName())
.publishDate(paymentPosition.getPublishDate())
.debtorType(paymentPosition.getType().toString())
.paymentOptions(paymentPosition.getPaymentOption().stream()
.map(item -> {
PaymentOption paymentOption = mapOption(item);
paymentOption.setSwitchToExpired(paymentOption.getSwitchToExpired());
return paymentOption;
}).toList())
.build();
List<PaymentOption> paymentOptions = new java.util.ArrayList<>(paymentPosition.getPaymentOption().stream()
.filter(item -> !item.getIsPartialPayment()).map(
item -> mapOptions(paymentPosition, Collections.singletonList(item))).toList());
if (paymentOptions.size() != paymentPosition.getPaymentOption().size()) {
paymentOptions.add(mapOptions(paymentPosition, paymentPosition.getPaymentOption().stream()
.filter(it.gov.pagopa.gpd.payments.pull.entity.PaymentOption::getIsPartialPayment).toList()));
}
paymentNotice.setPaymentOptions(paymentOptions);
return paymentNotice;
}

/**
* Maps a PaymentOption model, starting from PaymentOption entity and related entities
*
* @param paymentOption instance of PaymentOption entity to use as mapping source
* @param paymentPosition instance of PaymentOption entity to use as mapping source
* @return Mapped PaymentOption model instance
*/
public static PaymentOption mapOption(it.gov.pagopa.gpd.payments.pull.entity.PaymentOption paymentOption) {
public static PaymentOption mapOptions(
PaymentPosition paymentPosition,
List<it.gov.pagopa.gpd.payments.pull.entity.PaymentOption> paymentOptions) {
return PaymentOption
.builder()
.description(paymentOption.getDescription())
.amount(paymentOption.getAmount())
.dueDate(paymentOption.getDueDate())
.numberOfInstallments(paymentOption.getTransfer().size())
.isPartialPayment(paymentOption.getIsPartialPayment())
.switchToExpired(paymentOption.getPaymentPosition().getSwitchToExpired())
.installments(paymentOption.getTransfer().stream().map(item ->
mapInstallment(item)).toList())
.description(paymentOptions.get(0).getDescription())
.amount(paymentOptions.stream().map(
it.gov.pagopa.gpd.payments.pull.entity.PaymentOption::getAmount).reduce(0L, Long::sum))
.dueDate(paymentOptions.stream().map(it.gov.pagopa.gpd.payments.pull.entity.PaymentOption::getDueDate)
.max(LocalDateTime::compareTo).get())
.numberOfInstallments(paymentOptions.size())
.isPartialPayment(paymentOptions.get(0).getIsPartialPayment())
.switchToExpired(paymentPosition.getSwitchToExpired())
.installments(paymentOptions.stream().map(item ->
mapInstallment(item, paymentPosition)).toList())
.build();
}

/**
* Maps an Installment instance using Transfer data, and related entities
* Maps an Installment instance using PaymentOption data, and related entities
*
* @param transfer instance of Transfer entity
* @param paymentOption instance of PaymentOption entity
* @return mapped Installment instance
*/
public static Installment mapInstallment(Transfer transfer) {
public static Installment mapInstallment(
it.gov.pagopa.gpd.payments.pull.entity.PaymentOption paymentOption, PaymentPosition paymentPosition) {
return Installment.builder()
.nav(transfer.getPaymentOption().getNav())
.iuv(transfer.getIuv())
.paTaxCode(transfer.getOrganizationFiscalCode())
.paFullName(transfer.getPaymentOption().getPaymentPosition().getCompanyName()) //TODO: Missing name from option/transfer list
.amount(transfer.getAmount())
.description(transfer.getPaymentOption().getDescription()) //TODO: To define if remittance information to use
.dueDate(transfer.getPaymentOption().getDueDate())
.retentionDate(transfer.getPaymentOption().getRetentionDate())
.insertedDate(transfer.getInsertedDate())
.notificationFee(transfer.getPaymentOption().getNotificationFee())
.status(transfer.getStatus())
.lastUpdatedDate(transfer.getLastUpdatedDate())
.nav(paymentOption.getNav())
.iuv(paymentOption.getIuv())
.paTaxCode(paymentOption.getOrganizationFiscalCode())
.paFullName(paymentPosition.getCompanyName()) //TODO: Missing name from option/transfer list
.amount(paymentOption.getAmount())
.description(paymentOption.getDescription()) //TODO: To define if remittance information to use
.dueDate(paymentOption.getDueDate())
.retentionDate(paymentOption.getRetentionDate())
.insertedDate(paymentOption.getInsertedDate())
.notificationFee(paymentOption.getNotificationFee())
.status(paymentOption.getStatus())
.lastUpdatedDate(paymentOption.getLastUpdatedDate())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package it.gov.pagopa.gpd.payments.pull.models;

import io.quarkus.runtime.annotations.RegisterForReflection;
import it.gov.pagopa.gpd.payments.pull.models.enums.PaymentOptionStatus;
import it.gov.pagopa.gpd.payments.pull.models.enums.TransferStatus;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand Down Expand Up @@ -43,7 +44,7 @@ public class Installment implements Serializable {
@Schema(description = "corresponds to the SEND notification costs")
private long notificationFee;
@Schema(description = "Status of the OP", required = true)
private TransferStatus status;
private PaymentOptionStatus status;
@Schema(description = "OP update date", required = true)
private LocalDateTime lastUpdatedDate;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import org.junit.jupiter.api.Test;

import javax.inject.Inject;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
Expand All @@ -37,17 +39,20 @@ class PaymentNoticesServiceImplTest {

@Test
void getPaymentNoticesShouldReturnOK() {
doReturn(Uni.createFrom().item(Arrays.asList(createPaymentPosition(""),
createPaymentPosition("ACA_"))))
doReturn(Uni.createFrom().item(Arrays.asList(createPaymentPosition("", false),
createPaymentPosition("ACA_", false),
createPaymentPosition("PARTIAL_", true))))
.when(paymentPositionRepository).findPaymentPositionsByTaxCodeAndDueDate
(FISCAL_CODE, DUE_DATE, 50, 0);
List<PaymentNotice> response = assertDoesNotThrow(() ->
paymentNoticesService.getPaymentNotices(FISCAL_CODE, DUE_DATE, 50, 0))
.await().indefinitely();
assertNotNull(response);
assertEquals(1, response.size());
assertEquals(2, response.size());
assertEquals("iupd", response.get(0).getIupd());
assertEquals(1, response.get(0).getPaymentOptions().size());
assertEquals(1, response.get(1).getPaymentOptions().size());
assertEquals(2, response.get(1).getPaymentOptions().get(0).getInstallments().size());
verify(paymentPositionRepository).findPaymentPositionsByTaxCodeAndDueDate(
FISCAL_CODE, DUE_DATE, 50, 0);
}
Expand All @@ -68,7 +73,7 @@ void getPaymentNoticesShouldReturnExceptionOnRepositoryError() {

@Test
void getPaymentNoticesShouldReturnExceptionOnMappingError() {
PaymentPosition paymentPosition = createPaymentPosition("");
PaymentPosition paymentPosition = createPaymentPosition("", true);
paymentPosition.setPaymentOption(null);
doReturn(Uni.createFrom().item(Collections.singletonList(paymentPosition)))
.when(paymentPositionRepository).findPaymentPositionsByTaxCodeAndDueDate
Expand All @@ -81,23 +86,29 @@ void getPaymentNoticesShouldReturnExceptionOnMappingError() {
assertEquals(AppErrorCodeEnum.PPL_800, ((PaymentNoticeException) causes.get(causes.size()-1)).getErrorCode());
}

PaymentPosition createPaymentPosition(String prefix) {
PaymentPosition createPaymentPosition(String prefix, Boolean isPartialPayment) {
PaymentPosition paymentPosition = PaymentPosition.builder()
.iupd(prefix+"iupd")
.status(DebtPositionStatus.VALID)
.type(Type.F)
.build();

PaymentOption paymentOption = PaymentOption.builder()
List<PaymentOption> paymentOption = new ArrayList<>(
List.of(new PaymentOption[]{PaymentOption.builder()
.amount(100)
.isPartialPayment(false)
.build();
.dueDate(LocalDateTime.now())
.isPartialPayment(isPartialPayment)
.build()}));

if (isPartialPayment) {
paymentOption.add(PaymentOption.builder()
.amount(100)
.dueDate(LocalDateTime.now())
.isPartialPayment(true)
.build());
}

paymentOption.setTransfer(Collections.singletonList(
Transfer.builder().amount(100).paymentOption(paymentOption).build())
);
paymentOption.setPaymentPosition(paymentPosition);
paymentPosition.setPaymentOption(Collections.singletonList(paymentOption));
paymentPosition.setPaymentOption(paymentOption);

return paymentPosition;
}
Expand Down

0 comments on commit 83901cb

Please sign in to comment.