generated from pagopa/template-payments-java-repository
-
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.
fix: Externalize debt position duedate extraction (#118)
- Loading branch information
1 parent
e32012e
commit a4b43d5
Showing
2 changed files
with
25 additions
and
11 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
23 changes: 23 additions & 0 deletions
23
src/main/java/it/gov/pagopa/payhub/activities/util/DebtPositionUtilities.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,23 @@ | ||
package it.gov.pagopa.payhub.activities.util; | ||
|
||
import it.gov.pagopa.pu.debtposition.dto.generated.DebtPositionDTO; | ||
import it.gov.pagopa.pu.debtposition.dto.generated.InstallmentDTO; | ||
|
||
import java.time.OffsetDateTime; | ||
import java.util.Comparator; | ||
import java.util.Objects; | ||
|
||
public class DebtPositionUtilities { | ||
private DebtPositionUtilities(){} | ||
|
||
/** It will return the min dueDate of all active installments */ | ||
public static OffsetDateTime calcDebtPositionNextDueDate(DebtPositionDTO debtPositionDTO){ | ||
return debtPositionDTO.getPaymentOptions().stream() | ||
.flatMap(po ->po.getInstallments().stream()) | ||
.filter(i -> InstallmentDTO.StatusEnum.UNPAID.equals(i.getStatus())) | ||
.map(InstallmentDTO::getDueDate) | ||
.filter(Objects::nonNull) | ||
.min(Comparator.naturalOrder()) | ||
.orElse(null); | ||
} | ||
} |