From 2e3064dba03d59353e167dcc8987f0329fdc973e Mon Sep 17 00:00:00 2001 From: pagopa-github-bot Date: Wed, 31 Jan 2024 15:17:19 +0000 Subject: [PATCH 01/15] [PAGOPA-1488] renewal debt positions: first CRON JOB impl --- helm/Chart.yaml | 4 +- helm/values-dev.yaml | 2 +- helm/values-prod.yaml | 2 +- helm/values-uat.yaml | 2 +- openapi/openapi_external.json | 2 +- openapi/openapi_external_massive.json | 2 +- openapi/openapi_internal.json | 2 +- openapi/openapi_send.json | 2 +- pom.xml | 2 +- .../debtposition/config/SchedulerConfig.java | 2 - .../debtposition/entity/PaymentOption.java | 4 + .../entity/PaymentOptionMetadata.java | 4 + .../debtposition/entity/PaymentPosition.java | 5 + .../pagopa/debtposition/entity/Transfer.java | 4 + .../debtposition/entity/TransferMetadata.java | 4 + .../scheduler/HistoricizationScheduler.java | 92 +++++++++++++++++++ .../debtposition/scheduler/Scheduler.java | 4 + src/main/resources/application-h2.properties | 5 + src/main/resources/application.properties | 7 ++ src/test/resources/application.properties | 5 + 20 files changed, 144 insertions(+), 12 deletions(-) create mode 100644 src/main/java/it/gov/pagopa/debtposition/scheduler/HistoricizationScheduler.java diff --git a/helm/Chart.yaml b/helm/Chart.yaml index cb601502..b070b6cc 100644 --- a/helm/Chart.yaml +++ b/helm/Chart.yaml @@ -2,8 +2,8 @@ apiVersion: v2 name: pagopa-gpd-core description: micro-service to manage Creditor Institution debtor positions type: application -version: 0.84.0 -appVersion: 0.11.0 +version: 0.85.0 +appVersion: 0.11.1 dependencies: - name: microservice-chart version: 2.4.0 diff --git a/helm/values-dev.yaml b/helm/values-dev.yaml index 541c28a5..d6b34ada 100644 --- a/helm/values-dev.yaml +++ b/helm/values-dev.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-debt-position - tag: "0.11.0" + tag: "0.11.1" pullPolicy: Always livenessProbe: httpGet: diff --git a/helm/values-prod.yaml b/helm/values-prod.yaml index 3bbd05c4..09f3507f 100644 --- a/helm/values-prod.yaml +++ b/helm/values-prod.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-debt-position - tag: "0.11.0" + tag: "0.11.1" pullPolicy: Always livenessProbe: httpGet: diff --git a/helm/values-uat.yaml b/helm/values-uat.yaml index b3556a42..f1d9e376 100644 --- a/helm/values-uat.yaml +++ b/helm/values-uat.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-debt-position - tag: "0.11.0" + tag: "0.11.1" pullPolicy: Always livenessProbe: httpGet: diff --git a/openapi/openapi_external.json b/openapi/openapi_external.json index 7104fe0b..f435a06a 100644 --- a/openapi/openapi_external.json +++ b/openapi/openapi_external.json @@ -4,7 +4,7 @@ "title": "PagoPA API Debt Position", "description": "Progetto Gestione Posizioni Debitorie", "termsOfService": "https://www.pagopa.gov.it/", - "version": "0.11.0" + "version": "0.11.1" }, "servers": [ { diff --git a/openapi/openapi_external_massive.json b/openapi/openapi_external_massive.json index fefa81a5..658ef220 100644 --- a/openapi/openapi_external_massive.json +++ b/openapi/openapi_external_massive.json @@ -4,7 +4,7 @@ "title": "PagoPA API Debt Position", "description": "Progetto Gestione Posizioni Debitorie", "termsOfService": "https://www.pagopa.gov.it/", - "version": "0.11.0" + "version": "0.11.1" }, "servers": [ { diff --git a/openapi/openapi_internal.json b/openapi/openapi_internal.json index cc6bf852..5a1c5dec 100644 --- a/openapi/openapi_internal.json +++ b/openapi/openapi_internal.json @@ -4,7 +4,7 @@ "title": "PagoPA API Debt Position", "description": "Progetto Gestione Posizioni Debitorie", "termsOfService": "https://www.pagopa.gov.it/", - "version": "0.11.0" + "version": "0.11.1" }, "servers": [ { diff --git a/openapi/openapi_send.json b/openapi/openapi_send.json index c4312d56..a4986d4d 100644 --- a/openapi/openapi_send.json +++ b/openapi/openapi_send.json @@ -4,7 +4,7 @@ "title": "PagoPA API Debt Position", "description": "Progetto Gestione Posizioni Debitorie", "termsOfService": "https://www.pagopa.gov.it/", - "version": "0.11.0" + "version": "0.11.1" }, "servers": [ { diff --git a/pom.xml b/pom.xml index 63c0d8c6..32d2202a 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ it.gov.pagopa.debtposition gpd - 0.11.0 + 0.11.1 Gestione Posizioni Debitorie Progetto Gestione Posizioni Debitorie diff --git a/src/main/java/it/gov/pagopa/debtposition/config/SchedulerConfig.java b/src/main/java/it/gov/pagopa/debtposition/config/SchedulerConfig.java index 03de0521..6bd1b6fe 100644 --- a/src/main/java/it/gov/pagopa/debtposition/config/SchedulerConfig.java +++ b/src/main/java/it/gov/pagopa/debtposition/config/SchedulerConfig.java @@ -1,6 +1,5 @@ package it.gov.pagopa.debtposition.config; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableScheduling; @@ -8,7 +7,6 @@ @Configuration @EnableScheduling @EnableAsync -@ConditionalOnProperty(name = "cron.job.schedule.enabled", matchIfMissing = true) public class SchedulerConfig { } diff --git a/src/main/java/it/gov/pagopa/debtposition/entity/PaymentOption.java b/src/main/java/it/gov/pagopa/debtposition/entity/PaymentOption.java index 72cd70eb..f25f9a84 100644 --- a/src/main/java/it/gov/pagopa/debtposition/entity/PaymentOption.java +++ b/src/main/java/it/gov/pagopa/debtposition/entity/PaymentOption.java @@ -24,6 +24,9 @@ import javax.persistence.UniqueConstraint; import javax.validation.constraints.NotNull; +import com.fasterxml.jackson.annotation.JsonIdentityInfo; +import com.fasterxml.jackson.annotation.ObjectIdGenerators; + import it.gov.pagopa.debtposition.model.enumeration.PaymentOptionStatus; import lombok.AllArgsConstructor; import lombok.Builder; @@ -49,6 +52,7 @@ columnNames = {"iuv", "organization_fiscal_code"}) }, indexes = @Index(name = "payment_option_payment_position_id_idx", columnList = "payment_position_id")) +@JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class, property="@paymentOptionId") public class PaymentOption implements Serializable { /** diff --git a/src/main/java/it/gov/pagopa/debtposition/entity/PaymentOptionMetadata.java b/src/main/java/it/gov/pagopa/debtposition/entity/PaymentOptionMetadata.java index c20b4c19..7844e148 100644 --- a/src/main/java/it/gov/pagopa/debtposition/entity/PaymentOptionMetadata.java +++ b/src/main/java/it/gov/pagopa/debtposition/entity/PaymentOptionMetadata.java @@ -15,6 +15,9 @@ import javax.persistence.UniqueConstraint; import javax.validation.constraints.NotNull; +import com.fasterxml.jackson.annotation.JsonIdentityInfo; +import com.fasterxml.jackson.annotation.ObjectIdGenerators; + import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -32,6 +35,7 @@ @AllArgsConstructor @Entity @Builder +@JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class, property="@paymentOptionMetadataId") public class PaymentOptionMetadata implements Serializable { diff --git a/src/main/java/it/gov/pagopa/debtposition/entity/PaymentPosition.java b/src/main/java/it/gov/pagopa/debtposition/entity/PaymentPosition.java index e42d09f8..c563b47a 100644 --- a/src/main/java/it/gov/pagopa/debtposition/entity/PaymentPosition.java +++ b/src/main/java/it/gov/pagopa/debtposition/entity/PaymentPosition.java @@ -10,6 +10,10 @@ import javax.persistence.*; import javax.validation.constraints.NotNull; + +import com.fasterxml.jackson.annotation.JsonIdentityInfo; +import com.fasterxml.jackson.annotation.ObjectIdGenerators; + import java.io.Serializable; import java.time.LocalDateTime; import java.util.ArrayList; @@ -32,6 +36,7 @@ }, indexes = @Index(name = "payment_position_status_validity_date_idx", columnList = "status, validity_date") ) +@JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class, property="@paymentPositionId") public class PaymentPosition implements Serializable { diff --git a/src/main/java/it/gov/pagopa/debtposition/entity/Transfer.java b/src/main/java/it/gov/pagopa/debtposition/entity/Transfer.java index fc372e19..9e903b20 100644 --- a/src/main/java/it/gov/pagopa/debtposition/entity/Transfer.java +++ b/src/main/java/it/gov/pagopa/debtposition/entity/Transfer.java @@ -23,6 +23,9 @@ import javax.persistence.UniqueConstraint; import javax.validation.constraints.NotNull; +import com.fasterxml.jackson.annotation.JsonIdentityInfo; +import com.fasterxml.jackson.annotation.ObjectIdGenerators; + import it.gov.pagopa.debtposition.model.enumeration.TransferStatus; import lombok.AllArgsConstructor; import lombok.Builder; @@ -50,6 +53,7 @@ columnNames = {"iuv", "organization_fiscal_code", "transfer_id"}) }, indexes = @Index(name = "transfer_payment_option_id_idx", columnList = "payment_option_id")) +@JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class, property="@transferId") public class Transfer implements Serializable { /** diff --git a/src/main/java/it/gov/pagopa/debtposition/entity/TransferMetadata.java b/src/main/java/it/gov/pagopa/debtposition/entity/TransferMetadata.java index 89860724..69611579 100644 --- a/src/main/java/it/gov/pagopa/debtposition/entity/TransferMetadata.java +++ b/src/main/java/it/gov/pagopa/debtposition/entity/TransferMetadata.java @@ -15,6 +15,9 @@ import javax.persistence.UniqueConstraint; import javax.validation.constraints.NotNull; +import com.fasterxml.jackson.annotation.JsonIdentityInfo; +import com.fasterxml.jackson.annotation.ObjectIdGenerators; + import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -32,6 +35,7 @@ @AllArgsConstructor @Entity @Builder +@JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class, property="@transferMetadataId") public class TransferMetadata implements Serializable { /** diff --git a/src/main/java/it/gov/pagopa/debtposition/scheduler/HistoricizationScheduler.java b/src/main/java/it/gov/pagopa/debtposition/scheduler/HistoricizationScheduler.java new file mode 100644 index 00000000..3533bf6d --- /dev/null +++ b/src/main/java/it/gov/pagopa/debtposition/scheduler/HistoricizationScheduler.java @@ -0,0 +1,92 @@ +package it.gov.pagopa.debtposition.scheduler; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.stream.Collectors; + +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.PersistenceUnit; +import javax.transaction.Transactional; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.scheduling.annotation.Async; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; + +import it.gov.pagopa.debtposition.entity.PaymentPosition; +import it.gov.pagopa.debtposition.repository.PaymentPositionRepository; +import lombok.extern.slf4j.Slf4j; + +@Component +@Slf4j +@ConditionalOnProperty(name = "cron.job.schedule.historicization.enabled", matchIfMissing = true) +public class HistoricizationScheduler { + + private static final String LOG_BASE_HEADER_INFO = "[OperationType: %s] - [ClassMethod: %s] - [MethodParamsToLog: %s]"; + private static final String CRON_JOB = "CRON JOB"; + private static final String METHOD = "manageDebtPositionsToHistoricize"; + private Thread threadOfExecution; + + @Value("${cron.job.schedule.extraction.history.query:SELECT pp FROM PaymentPosition pp WHERE pp.status IN ('PAID', 'REPORTED', 'INVALID', 'EXPIRED') AND pp.lastUpdatedDate < ?1}") + private String extractionQuery; + @Value("${cron.job.schedule.extraction.history.query.interval:1}") + private byte extractionInterval; + + @Autowired + private PaymentPositionRepository paymentPositionRepository; + @PersistenceUnit + private EntityManagerFactory emf; + + + @Scheduled(cron = "${cron.job.schedule.expression.historicization.debt.positions}") + @Async + @Transactional + public void manageDebtPositionsToHistoricize() throws JsonProcessingException { + log.info(String.format(LOG_BASE_HEADER_INFO, CRON_JOB, METHOD, "Running at " + DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(LocalDateTime.now()))); + EntityManager em = emf.createEntityManager(); + LocalDateTime ldt = LocalDateTime.now().minusYears(extractionInterval); + List ppList = em.createQuery(extractionQuery, PaymentPosition.class).setParameter(1,ldt).getResultList(); + log.info(String.format(LOG_BASE_HEADER_INFO, CRON_JOB, METHOD, "Number of extracted rows to historicize: " + ppList.size())); + + Map> ppListByOrganizationFiscalCode = ppList.stream() + .collect(Collectors.groupingBy(p -> p.getOrganizationFiscalCode(), Collectors.mapping((PaymentPosition p) -> p, Collectors.toList()))); + + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.registerModule(new JavaTimeModule()); + + for (Entry> entry : ppListByOrganizationFiscalCode.entrySet()) { + List organizationPpList = ppListByOrganizationFiscalCode.get(entry.getKey()); + for (PaymentPosition pp: organizationPpList) { + pp.getPaymentOption().forEach(po -> { + // TODO write on azure table storage 'table1' to persist the debt position info + //System.out.print("["); + //System.out.print(entry.getKey() +","+po.getIuv()+","+po.getPaymentDate()+","+pp.getIupd()); + //System.out.print("]"); + }); + // TODO write on azure table storage 'table2' to persist the debt position json + //System.out.print("("); + //System.out.print(entry.getKey() +","+pp.getIupd()+","+objectMapper.writeValueAsString(pp)); + //System.out.print(")"); + } + log.info(String.format(LOG_BASE_HEADER_INFO, CRON_JOB, METHOD, "historicized n. "+organizationPpList.size()+" debt positions for the organization fiscal code: " +entry.getKey())); + } + + // historicized debt positions are removed + //paymentPositionRepository.deleteAll(ppList); + log.info(String.format(LOG_BASE_HEADER_INFO, CRON_JOB, METHOD, "deleted historicized debt positions")); + } + + public Thread getThreadOfExecution() { + return this.threadOfExecution; + } +} diff --git a/src/main/java/it/gov/pagopa/debtposition/scheduler/Scheduler.java b/src/main/java/it/gov/pagopa/debtposition/scheduler/Scheduler.java index 60069e6e..7bfc5474 100644 --- a/src/main/java/it/gov/pagopa/debtposition/scheduler/Scheduler.java +++ b/src/main/java/it/gov/pagopa/debtposition/scheduler/Scheduler.java @@ -4,6 +4,7 @@ import it.gov.pagopa.debtposition.repository.PaymentPositionRepository; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; @@ -15,6 +16,7 @@ @Component @Slf4j +@ConditionalOnProperty(name = "cron.job.schedule.enabled", matchIfMissing = true) public class Scheduler { private static final String LOG_BASE_HEADER_INFO = "[OperationType: %s] - [ClassMethod: %s] - [MethodParamsToLog: %s]"; @@ -34,6 +36,7 @@ public void changeDebtPositionStatusToValid() { this.threadOfExecution = Thread.currentThread(); } + @Scheduled(cron = "${cron.job.schedule.expression.expired.status}") @Async @Transactional @@ -44,6 +47,7 @@ public void changeDebtPositionStatusToExpired() { log.info(String.format(LOG_BASE_HEADER_INFO, CRON_JOB, "changeDebtPositionStatusToExpired", "Number of updated rows " + numAffectedRows)); this.threadOfExecution = Thread.currentThread(); } + public Thread getThreadOfExecution() { return this.threadOfExecution; diff --git a/src/main/resources/application-h2.properties b/src/main/resources/application-h2.properties index cf4f51f3..b232f88c 100644 --- a/src/main/resources/application-h2.properties +++ b/src/main/resources/application-h2.properties @@ -36,6 +36,11 @@ cron.job.schedule.enabled=false cron.job.schedule.expression.valid.status=*/35 * * * * * cron.job.schedule.expression.expired.status=*/35 * * * * * +cron.job.schedule.historicization.enabled=true +cron.job.schedule.expression.historicization.debt.positions=*/55 * * * * * +cron.job.schedule.extraction.history.query =SELECT pp FROM PaymentPosition pp WHERE pp.status IN ('PAID', 'REPORTED', 'INVALID', 'EXPIRED') AND pp.lastUpdatedDate < ?1 +cron.job.schedule.extraction.history.query.interval=0 + # Flyway settings spring.flyway.schemas=apd diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index f6b2f4f5..0085b842 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -34,6 +34,13 @@ cron.job.schedule.enabled = ${CRON_JOB_SCHEDULE_ENABLED} cron.job.schedule.expression.valid.status = ${CRON_JOB_SCHEDULE_EXPRESSION_TO_VALID} cron.job.schedule.expression.expired.status = ${CRON_JOB_SCHEDULE_EXPRESSION_TO_EXPIRED} +cron.job.schedule.historicization.enabled = ${CRON_JOB_SCHEDULE_HISTORICIZATION_ENABLED} +cron.job.schedule.expression.historicization.debt.positions = ${CRON_JOB_SCHEDULE_EXPRESSION_HISTORICIZATION_DEBT_POS} +cron.job.schedule.extraction.history.query = ${CRON_JOB_SCHEDULE_EXTRACTION_HISTORY_QUERY} +# The time, in years, to be subtracted from the current date to decide how old, the debt positions to be historicized, must be (default 1 year) +cron.job.schedule.extraction.history.query.interval = ${CRON_JOB_SCHEDULE_EXTRACTION_HISTORY_QUERY_INTERVAL} + + # Max num. of days for the recovery of debt positions max.days.interval = ${MAX_DAYS_INTERVAL:#{'30'}} diff --git a/src/test/resources/application.properties b/src/test/resources/application.properties index 8488c216..d92bcab5 100644 --- a/src/test/resources/application.properties +++ b/src/test/resources/application.properties @@ -31,6 +31,11 @@ cron.job.schedule.enabled=false cron.job.schedule.expression.valid.status=*/35 * * * * * cron.job.schedule.expression.expired.status =*/55 * * * * * +cron.job.schedule.historicization.enabled=false +cron.job.schedule.expression.historicization.debt.positions=*/55 * * * * * +cron.job.schedule.extraction.history.query =SELECT pp FROM PaymentPosition pp WHERE pp.status IN ('PAID', 'REPORTED', 'INVALID', 'EXPIRED') AND pp.lastUpdatedDate < ?1 +cron.job.schedule.extraction.history.query.interval=0 + # Max num. of days for the recovery of debt positions max.days.interval = 30 From fcb1cf89d8eadba5c246b2763873468ee4567ec9 Mon Sep 17 00:00:00 2001 From: pagopa-github-bot Date: Wed, 31 Jan 2024 15:17:19 +0000 Subject: [PATCH 02/15] [PAGOPA-1488] renewal debt positions: writing on azure table --- helm/Chart.yaml | 4 +- helm/values-dev.yaml | 2 +- helm/values-prod.yaml | 2 +- helm/values-uat.yaml | 2 +- openapi/openapi_external.json | 2 +- openapi/openapi_external_massive.json | 2 +- openapi/openapi_internal.json | 2 +- openapi/openapi_send.json | 2 +- pom.xml | 16 +- .../debtposition/config/SchedulerConfig.java | 2 - .../debtposition/entity/PaymentOption.java | 4 + .../entity/PaymentOptionMetadata.java | 4 + .../debtposition/entity/PaymentPosition.java | 5 + .../pagopa/debtposition/entity/Transfer.java | 4 + .../debtposition/entity/TransferMetadata.java | 4 + .../scheduler/HistoricizationScheduler.java | 148 ++++++++++++++++++ .../debtposition/scheduler/Scheduler.java | 4 + src/main/resources/application-h2.properties | 10 ++ src/main/resources/application.properties | 11 ++ src/test/resources/application.properties | 10 ++ 20 files changed, 228 insertions(+), 12 deletions(-) create mode 100644 src/main/java/it/gov/pagopa/debtposition/scheduler/HistoricizationScheduler.java diff --git a/helm/Chart.yaml b/helm/Chart.yaml index cb601502..b070b6cc 100644 --- a/helm/Chart.yaml +++ b/helm/Chart.yaml @@ -2,8 +2,8 @@ apiVersion: v2 name: pagopa-gpd-core description: micro-service to manage Creditor Institution debtor positions type: application -version: 0.84.0 -appVersion: 0.11.0 +version: 0.85.0 +appVersion: 0.11.1 dependencies: - name: microservice-chart version: 2.4.0 diff --git a/helm/values-dev.yaml b/helm/values-dev.yaml index 541c28a5..d6b34ada 100644 --- a/helm/values-dev.yaml +++ b/helm/values-dev.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-debt-position - tag: "0.11.0" + tag: "0.11.1" pullPolicy: Always livenessProbe: httpGet: diff --git a/helm/values-prod.yaml b/helm/values-prod.yaml index 3bbd05c4..09f3507f 100644 --- a/helm/values-prod.yaml +++ b/helm/values-prod.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-debt-position - tag: "0.11.0" + tag: "0.11.1" pullPolicy: Always livenessProbe: httpGet: diff --git a/helm/values-uat.yaml b/helm/values-uat.yaml index b3556a42..f1d9e376 100644 --- a/helm/values-uat.yaml +++ b/helm/values-uat.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-debt-position - tag: "0.11.0" + tag: "0.11.1" pullPolicy: Always livenessProbe: httpGet: diff --git a/openapi/openapi_external.json b/openapi/openapi_external.json index 7104fe0b..f435a06a 100644 --- a/openapi/openapi_external.json +++ b/openapi/openapi_external.json @@ -4,7 +4,7 @@ "title": "PagoPA API Debt Position", "description": "Progetto Gestione Posizioni Debitorie", "termsOfService": "https://www.pagopa.gov.it/", - "version": "0.11.0" + "version": "0.11.1" }, "servers": [ { diff --git a/openapi/openapi_external_massive.json b/openapi/openapi_external_massive.json index fefa81a5..658ef220 100644 --- a/openapi/openapi_external_massive.json +++ b/openapi/openapi_external_massive.json @@ -4,7 +4,7 @@ "title": "PagoPA API Debt Position", "description": "Progetto Gestione Posizioni Debitorie", "termsOfService": "https://www.pagopa.gov.it/", - "version": "0.11.0" + "version": "0.11.1" }, "servers": [ { diff --git a/openapi/openapi_internal.json b/openapi/openapi_internal.json index cc6bf852..5a1c5dec 100644 --- a/openapi/openapi_internal.json +++ b/openapi/openapi_internal.json @@ -4,7 +4,7 @@ "title": "PagoPA API Debt Position", "description": "Progetto Gestione Posizioni Debitorie", "termsOfService": "https://www.pagopa.gov.it/", - "version": "0.11.0" + "version": "0.11.1" }, "servers": [ { diff --git a/openapi/openapi_send.json b/openapi/openapi_send.json index c4312d56..a4986d4d 100644 --- a/openapi/openapi_send.json +++ b/openapi/openapi_send.json @@ -4,7 +4,7 @@ "title": "PagoPA API Debt Position", "description": "Progetto Gestione Posizioni Debitorie", "termsOfService": "https://www.pagopa.gov.it/", - "version": "0.11.0" + "version": "0.11.1" }, "servers": [ { diff --git a/pom.xml b/pom.xml index 63c0d8c6..0bb89f20 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ it.gov.pagopa.debtposition gpd - 0.11.0 + 0.11.1 Gestione Posizioni Debitorie Progetto Gestione Posizioni Debitorie @@ -21,6 +21,8 @@ 2.13.1 8.5.10 3.1.8 + 12.3.18 + 1.45.1 @@ -55,6 +57,18 @@ springdoc-openapi-ui ${springdoc-version} + + + com.azure + azure-core + ${azure.core.version} + + + com.azure + azure-data-tables + ${azure.data.table.version} + + org.springframework.boot spring-boot-devtools diff --git a/src/main/java/it/gov/pagopa/debtposition/config/SchedulerConfig.java b/src/main/java/it/gov/pagopa/debtposition/config/SchedulerConfig.java index 03de0521..6bd1b6fe 100644 --- a/src/main/java/it/gov/pagopa/debtposition/config/SchedulerConfig.java +++ b/src/main/java/it/gov/pagopa/debtposition/config/SchedulerConfig.java @@ -1,6 +1,5 @@ package it.gov.pagopa.debtposition.config; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableScheduling; @@ -8,7 +7,6 @@ @Configuration @EnableScheduling @EnableAsync -@ConditionalOnProperty(name = "cron.job.schedule.enabled", matchIfMissing = true) public class SchedulerConfig { } diff --git a/src/main/java/it/gov/pagopa/debtposition/entity/PaymentOption.java b/src/main/java/it/gov/pagopa/debtposition/entity/PaymentOption.java index 72cd70eb..f25f9a84 100644 --- a/src/main/java/it/gov/pagopa/debtposition/entity/PaymentOption.java +++ b/src/main/java/it/gov/pagopa/debtposition/entity/PaymentOption.java @@ -24,6 +24,9 @@ import javax.persistence.UniqueConstraint; import javax.validation.constraints.NotNull; +import com.fasterxml.jackson.annotation.JsonIdentityInfo; +import com.fasterxml.jackson.annotation.ObjectIdGenerators; + import it.gov.pagopa.debtposition.model.enumeration.PaymentOptionStatus; import lombok.AllArgsConstructor; import lombok.Builder; @@ -49,6 +52,7 @@ columnNames = {"iuv", "organization_fiscal_code"}) }, indexes = @Index(name = "payment_option_payment_position_id_idx", columnList = "payment_position_id")) +@JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class, property="@paymentOptionId") public class PaymentOption implements Serializable { /** diff --git a/src/main/java/it/gov/pagopa/debtposition/entity/PaymentOptionMetadata.java b/src/main/java/it/gov/pagopa/debtposition/entity/PaymentOptionMetadata.java index c20b4c19..7844e148 100644 --- a/src/main/java/it/gov/pagopa/debtposition/entity/PaymentOptionMetadata.java +++ b/src/main/java/it/gov/pagopa/debtposition/entity/PaymentOptionMetadata.java @@ -15,6 +15,9 @@ import javax.persistence.UniqueConstraint; import javax.validation.constraints.NotNull; +import com.fasterxml.jackson.annotation.JsonIdentityInfo; +import com.fasterxml.jackson.annotation.ObjectIdGenerators; + import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -32,6 +35,7 @@ @AllArgsConstructor @Entity @Builder +@JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class, property="@paymentOptionMetadataId") public class PaymentOptionMetadata implements Serializable { diff --git a/src/main/java/it/gov/pagopa/debtposition/entity/PaymentPosition.java b/src/main/java/it/gov/pagopa/debtposition/entity/PaymentPosition.java index e42d09f8..c563b47a 100644 --- a/src/main/java/it/gov/pagopa/debtposition/entity/PaymentPosition.java +++ b/src/main/java/it/gov/pagopa/debtposition/entity/PaymentPosition.java @@ -10,6 +10,10 @@ import javax.persistence.*; import javax.validation.constraints.NotNull; + +import com.fasterxml.jackson.annotation.JsonIdentityInfo; +import com.fasterxml.jackson.annotation.ObjectIdGenerators; + import java.io.Serializable; import java.time.LocalDateTime; import java.util.ArrayList; @@ -32,6 +36,7 @@ }, indexes = @Index(name = "payment_position_status_validity_date_idx", columnList = "status, validity_date") ) +@JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class, property="@paymentPositionId") public class PaymentPosition implements Serializable { diff --git a/src/main/java/it/gov/pagopa/debtposition/entity/Transfer.java b/src/main/java/it/gov/pagopa/debtposition/entity/Transfer.java index fc372e19..9e903b20 100644 --- a/src/main/java/it/gov/pagopa/debtposition/entity/Transfer.java +++ b/src/main/java/it/gov/pagopa/debtposition/entity/Transfer.java @@ -23,6 +23,9 @@ import javax.persistence.UniqueConstraint; import javax.validation.constraints.NotNull; +import com.fasterxml.jackson.annotation.JsonIdentityInfo; +import com.fasterxml.jackson.annotation.ObjectIdGenerators; + import it.gov.pagopa.debtposition.model.enumeration.TransferStatus; import lombok.AllArgsConstructor; import lombok.Builder; @@ -50,6 +53,7 @@ columnNames = {"iuv", "organization_fiscal_code", "transfer_id"}) }, indexes = @Index(name = "transfer_payment_option_id_idx", columnList = "payment_option_id")) +@JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class, property="@transferId") public class Transfer implements Serializable { /** diff --git a/src/main/java/it/gov/pagopa/debtposition/entity/TransferMetadata.java b/src/main/java/it/gov/pagopa/debtposition/entity/TransferMetadata.java index 89860724..69611579 100644 --- a/src/main/java/it/gov/pagopa/debtposition/entity/TransferMetadata.java +++ b/src/main/java/it/gov/pagopa/debtposition/entity/TransferMetadata.java @@ -15,6 +15,9 @@ import javax.persistence.UniqueConstraint; import javax.validation.constraints.NotNull; +import com.fasterxml.jackson.annotation.JsonIdentityInfo; +import com.fasterxml.jackson.annotation.ObjectIdGenerators; + import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -32,6 +35,7 @@ @AllArgsConstructor @Entity @Builder +@JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class, property="@transferMetadataId") public class TransferMetadata implements Serializable { /** diff --git a/src/main/java/it/gov/pagopa/debtposition/scheduler/HistoricizationScheduler.java b/src/main/java/it/gov/pagopa/debtposition/scheduler/HistoricizationScheduler.java new file mode 100644 index 00000000..504a250c --- /dev/null +++ b/src/main/java/it/gov/pagopa/debtposition/scheduler/HistoricizationScheduler.java @@ -0,0 +1,148 @@ +package it.gov.pagopa.debtposition.scheduler; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.stream.Collectors; + +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.PersistenceUnit; +import javax.transaction.Transactional; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.scheduling.annotation.Async; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import com.azure.data.tables.TableClient; +import com.azure.data.tables.TableClientBuilder; +import com.azure.data.tables.models.TableEntity; +import com.azure.data.tables.models.TableErrorCode; +import com.azure.data.tables.models.TableServiceException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; + +import it.gov.pagopa.debtposition.entity.PaymentOption; +import it.gov.pagopa.debtposition.entity.PaymentPosition; +import it.gov.pagopa.debtposition.repository.PaymentPositionRepository; +import lombok.extern.slf4j.Slf4j; + +@Component +@Slf4j +@ConditionalOnProperty(name = "cron.job.schedule.historicization.enabled", matchIfMissing = true) +public class HistoricizationScheduler { + + private static final String LOG_BASE_HEADER_INFO = "[OperationType: %s] - [ClassMethod: %s] - [MethodParamsToLog: %s]"; + private static final String CRON_JOB = "CRON JOB"; + private static final String METHOD = "manageDebtPositionsToHistoricize"; + private Thread threadOfExecution; + private TableClient tableClient; + + @Value("${cron.job.schedule.extraction.history.query:SELECT pp FROM PaymentPosition pp WHERE pp.status IN ('PAID', 'REPORTED', 'INVALID', 'EXPIRED') AND pp.lastUpdatedDate < ?1}") + private String extractionQuery; + @Value("${cron.job.schedule.extraction.history.query.interval:365}") + private short extractionInterval; + @Value("${azure.archive.storage.connection}") + private String archiveStorageConnection; + @Value("${azure.archive.storage.table.po:pagopadweugpsarchivesapaymentoptiontable}") + private String archiveStoragePOTable; + @Value("${azure.archive.storage.table.pp:pagopadweugpsarchivesapaymentpositiontable}") + private String archiveStoragePPTable; + + @Autowired + private PaymentPositionRepository paymentPositionRepository; + @PersistenceUnit + private EntityManagerFactory emf; + + + @Scheduled(cron = "${cron.job.schedule.expression.historicization.debt.positions}") + @Async + @Transactional + public void manageDebtPositionsToHistoricize() throws JsonProcessingException, TableServiceException { + log.info(String.format(LOG_BASE_HEADER_INFO, CRON_JOB, METHOD, "Running at " + DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(LocalDateTime.now()))); + EntityManager em = emf.createEntityManager(); + LocalDateTime ldt = LocalDateTime.now().minusDays(extractionInterval); + List ppList = em.createQuery(extractionQuery, PaymentPosition.class).setParameter(1,ldt).getResultList(); + log.info(String.format(LOG_BASE_HEADER_INFO, CRON_JOB, METHOD, "Number of extracted rows to historicize: " + ppList.size())); + + Map> ppListByOrganizationFiscalCode = ppList.stream() + .collect(Collectors.groupingBy(p -> p.getOrganizationFiscalCode(), Collectors.mapping((PaymentPosition p) -> p, Collectors.toList()))); + + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.registerModule(new JavaTimeModule()); + + for (Entry> entry : ppListByOrganizationFiscalCode.entrySet()) { + List organizationPpList = ppListByOrganizationFiscalCode.get(entry.getKey()); + for (PaymentPosition pp: organizationPpList) { + pp.getPaymentOption().forEach(po -> { + // write on azure table storage to persist the PO debt position info + this.saveToPOTable(entry.getKey(), pp, po); + }); + // write on azure table storage to persist the PP debt position info and json + this.saveToPPTable(entry.getKey(), pp, objectMapper); + } + log.info(String.format(LOG_BASE_HEADER_INFO, CRON_JOB, METHOD, "historicized n. "+organizationPpList.size()+" debt positions for the organization fiscal code: " +entry.getKey())); + } + + // historicized debt positions are removed + //paymentPositionRepository.deleteAll(ppList); + log.info(String.format(LOG_BASE_HEADER_INFO, CRON_JOB, METHOD, "deleted historicized debt positions")); + } + + public Thread getThreadOfExecution() { + return this.threadOfExecution; + } + + private void saveToPOTable(String organizationFiscalCode, PaymentPosition pp, PaymentOption po) { + tableClient = new TableClientBuilder() + .connectionString(archiveStorageConnection) + .tableName(archiveStoragePOTable) + .buildClient(); + TableEntity tableEntity = new TableEntity(organizationFiscalCode, po.getIuv()); + try { + Map properties = new HashMap<>(); + properties.put("PaymentDate", po.getPaymentDate()); + properties.put("IUPD", pp.getIupd()); + tableEntity.setProperties(properties); + tableClient.createEntity(tableEntity); + } catch (TableServiceException e) { + if (e.getValue().getErrorCode() == TableErrorCode.ENTITY_ALREADY_EXISTS) { + tableClient.updateEntity(tableEntity); + } else { + log.error(String.format(LOG_BASE_HEADER_INFO, CRON_JOB, "saveToPOTable", + "error while storing the table information [organizationFiscalCode="+organizationFiscalCode+", iuv="+po.getIuv()+"]"), e); + throw e; + } + } + } + + private void saveToPPTable(String organizationFiscalCode, PaymentPosition pp, ObjectMapper objectMapper) + throws JsonProcessingException { + tableClient = new TableClientBuilder() + .connectionString(archiveStorageConnection) + .tableName(archiveStoragePPTable) + .buildClient(); + TableEntity tableEntity = new TableEntity(organizationFiscalCode, pp.getIupd()); + try { + Map properties = new HashMap<>(); + properties.put("PaymentPosition", objectMapper.writeValueAsString(pp)); + tableEntity.setProperties(properties); + tableClient.createEntity(tableEntity); + } catch (TableServiceException e) { + if (e.getValue().getErrorCode() == TableErrorCode.ENTITY_ALREADY_EXISTS) { + tableClient.updateEntity(tableEntity); + } else { + log.error(String.format(LOG_BASE_HEADER_INFO, CRON_JOB, "saveToPPTable", + "error while storing the table information [organizationFiscalCode="+organizationFiscalCode+", iupd="+pp.getIupd()+"]"), e); + throw e; + } + } + } +} diff --git a/src/main/java/it/gov/pagopa/debtposition/scheduler/Scheduler.java b/src/main/java/it/gov/pagopa/debtposition/scheduler/Scheduler.java index 60069e6e..7bfc5474 100644 --- a/src/main/java/it/gov/pagopa/debtposition/scheduler/Scheduler.java +++ b/src/main/java/it/gov/pagopa/debtposition/scheduler/Scheduler.java @@ -4,6 +4,7 @@ import it.gov.pagopa.debtposition.repository.PaymentPositionRepository; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; @@ -15,6 +16,7 @@ @Component @Slf4j +@ConditionalOnProperty(name = "cron.job.schedule.enabled", matchIfMissing = true) public class Scheduler { private static final String LOG_BASE_HEADER_INFO = "[OperationType: %s] - [ClassMethod: %s] - [MethodParamsToLog: %s]"; @@ -34,6 +36,7 @@ public void changeDebtPositionStatusToValid() { this.threadOfExecution = Thread.currentThread(); } + @Scheduled(cron = "${cron.job.schedule.expression.expired.status}") @Async @Transactional @@ -44,6 +47,7 @@ public void changeDebtPositionStatusToExpired() { log.info(String.format(LOG_BASE_HEADER_INFO, CRON_JOB, "changeDebtPositionStatusToExpired", "Number of updated rows " + numAffectedRows)); this.threadOfExecution = Thread.currentThread(); } + public Thread getThreadOfExecution() { return this.threadOfExecution; diff --git a/src/main/resources/application-h2.properties b/src/main/resources/application-h2.properties index cf4f51f3..8690ff3d 100644 --- a/src/main/resources/application-h2.properties +++ b/src/main/resources/application-h2.properties @@ -36,6 +36,16 @@ cron.job.schedule.enabled=false cron.job.schedule.expression.valid.status=*/35 * * * * * cron.job.schedule.expression.expired.status=*/35 * * * * * +cron.job.schedule.historicization.enabled=true +cron.job.schedule.expression.historicization.debt.positions=*/55 * * * * * +cron.job.schedule.extraction.history.query =SELECT pp FROM PaymentPosition pp WHERE pp.status IN ('PAID', 'REPORTED', 'INVALID', 'EXPIRED') AND pp.lastUpdatedDate < ?1 +# The time, in days, to be subtracted from the current date to decide how old, the debt positions to be historicized, must be (default 365 days) +cron.job.schedule.extraction.history.query.interval=0 + +azure.archive.storage.connection=DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1;TableEndpoint=http://127.0.0.1:10002/devstoreaccount1; +azure.archive.storage.table.po=pagopadweugpsarchivesapaymentoptiontable +azure.archive.storage.table.pp=pagopadweugpsarchivesapaymentpositiontable + # Flyway settings spring.flyway.schemas=apd diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index f6b2f4f5..1f317cb2 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -34,6 +34,17 @@ cron.job.schedule.enabled = ${CRON_JOB_SCHEDULE_ENABLED} cron.job.schedule.expression.valid.status = ${CRON_JOB_SCHEDULE_EXPRESSION_TO_VALID} cron.job.schedule.expression.expired.status = ${CRON_JOB_SCHEDULE_EXPRESSION_TO_EXPIRED} +cron.job.schedule.historicization.enabled = ${CRON_JOB_SCHEDULE_HISTORICIZATION_ENABLED} +cron.job.schedule.expression.historicization.debt.positions = ${CRON_JOB_SCHEDULE_EXPRESSION_HISTORICIZATION_DEBT_POS} +cron.job.schedule.extraction.history.query = ${CRON_JOB_SCHEDULE_EXTRACTION_HISTORY_QUERY} +# The time, in days, to be subtracted from the current date to decide how old, the debt positions to be historicized, must be (default 365 days) +cron.job.schedule.extraction.history.query.interval = ${CRON_JOB_SCHEDULE_EXTRACTION_HISTORY_QUERY_INTERVAL} + +azure.archive.storage.connection=${ARCHIVE_SA_CONNECTION_STRING} +azure.archive.storage.table.po=${ARCHIVE_SA_PO_TABLE} +azure.archive.storage.table.pp=${ARCHIVE_SA_PP_TABLE} + + # Max num. of days for the recovery of debt positions max.days.interval = ${MAX_DAYS_INTERVAL:#{'30'}} diff --git a/src/test/resources/application.properties b/src/test/resources/application.properties index 8488c216..fda594a3 100644 --- a/src/test/resources/application.properties +++ b/src/test/resources/application.properties @@ -31,6 +31,16 @@ cron.job.schedule.enabled=false cron.job.schedule.expression.valid.status=*/35 * * * * * cron.job.schedule.expression.expired.status =*/55 * * * * * +cron.job.schedule.historicization.enabled=false +cron.job.schedule.expression.historicization.debt.positions=*/55 * * * * * +cron.job.schedule.extraction.history.query =SELECT pp FROM PaymentPosition pp WHERE pp.status IN ('PAID', 'REPORTED', 'INVALID', 'EXPIRED') AND pp.lastUpdatedDate < ?1 +# The time, in days, to be subtracted from the current date to decide how old, the debt positions to be historicized, must be (default 365 days) +cron.job.schedule.extraction.history.query.interval=0 + +azure.archive.storage.connection=DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1;TableEndpoint=http://127.0.0.1:10002/devstoreaccount1; +azure.archive.storage.table.po=pagopadweugpsarchivesapaymentoptiontable +azure.archive.storage.table.pp=pagopadweugpsarchivesapaymentpositiontable + # Max num. of days for the recovery of debt positions max.days.interval = 30 From a91b57c112d3f26de568911301be4a047a346c56 Mon Sep 17 00:00:00 2001 From: aacitelli Date: Wed, 7 Feb 2024 12:22:19 +0100 Subject: [PATCH 03/15] [PAGOPA-1488] renewal debt positions: typo --- .../pagopa/debtposition/scheduler/HistoricizationScheduler.java | 2 +- .../java/it/gov/pagopa/debtposition/scheduler/Scheduler.java | 2 +- src/main/resources/application-h2.properties | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/it/gov/pagopa/debtposition/scheduler/HistoricizationScheduler.java b/src/main/java/it/gov/pagopa/debtposition/scheduler/HistoricizationScheduler.java index 71cbf33b..a1c3b013 100644 --- a/src/main/java/it/gov/pagopa/debtposition/scheduler/HistoricizationScheduler.java +++ b/src/main/java/it/gov/pagopa/debtposition/scheduler/HistoricizationScheduler.java @@ -39,7 +39,7 @@ @Component @Slf4j -@ConditionalOnProperty(prefix = "archiving-service", name = "cron.job.schedule.historicization.enabled", matchIfMissing = true) +@ConditionalOnProperty(name = "cron.job.schedule.historicization.enabled", matchIfMissing = true) @NoArgsConstructor public class HistoricizationScheduler { diff --git a/src/main/java/it/gov/pagopa/debtposition/scheduler/Scheduler.java b/src/main/java/it/gov/pagopa/debtposition/scheduler/Scheduler.java index 053e8065..7bfc5474 100644 --- a/src/main/java/it/gov/pagopa/debtposition/scheduler/Scheduler.java +++ b/src/main/java/it/gov/pagopa/debtposition/scheduler/Scheduler.java @@ -16,7 +16,7 @@ @Component @Slf4j -@ConditionalOnProperty(prefix = "status-change-service", name = "cron.job.schedule.enabled", matchIfMissing = true) +@ConditionalOnProperty(name = "cron.job.schedule.enabled", matchIfMissing = true) public class Scheduler { private static final String LOG_BASE_HEADER_INFO = "[OperationType: %s] - [ClassMethod: %s] - [MethodParamsToLog: %s]"; diff --git a/src/main/resources/application-h2.properties b/src/main/resources/application-h2.properties index 18d02f08..414fb54b 100644 --- a/src/main/resources/application-h2.properties +++ b/src/main/resources/application-h2.properties @@ -14,7 +14,7 @@ management.health.readinessState.enabled=true management.metrics.distribution.percentiles.http.server.requests=0.5, 0.9, 0.95, 0.99 # Database settings -spring.datasource.url=jdbc:h2:mem:db;MODE=PostgreSQL;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;INIT=CREATE SCHEMA IF NOT EXISTS APD\\;SET SCHEMA APD +spring.datasource.url=jdbc:h2:mem:db;MODE=PostgreSQL;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;INIT=CREATE SCHEMA IF NOT EXISTS APD\\;SET SCHEMA APD\\;CREATE TABLE IF NOT EXISTS APD.shedlock (name VARCHAR(64),lock_until TIMESTAMP(3) NULL,locked_at TIMESTAMP(3) NULL,locked_by VARCHAR(255),PRIMARY KEY (name)) spring.datasource.username=sa spring.datasource.password=sa spring.datasource.driver-class-name=org.h2.Driver From 93fed17acbb3f2b969d757e0fb27e62d0b5ef54d Mon Sep 17 00:00:00 2001 From: aacitelli Date: Wed, 7 Feb 2024 12:22:19 +0100 Subject: [PATCH 04/15] [PAGOPA-1488] renewal debt positions: sonar issue --- .../debtposition/scheduler/HistoricizationScheduler.java | 8 ++++---- .../it/gov/pagopa/debtposition/scheduler/Scheduler.java | 2 +- src/main/resources/application-h2.properties | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/it/gov/pagopa/debtposition/scheduler/HistoricizationScheduler.java b/src/main/java/it/gov/pagopa/debtposition/scheduler/HistoricizationScheduler.java index 71cbf33b..ec104d14 100644 --- a/src/main/java/it/gov/pagopa/debtposition/scheduler/HistoricizationScheduler.java +++ b/src/main/java/it/gov/pagopa/debtposition/scheduler/HistoricizationScheduler.java @@ -39,7 +39,7 @@ @Component @Slf4j -@ConditionalOnProperty(prefix = "archiving-service", name = "cron.job.schedule.historicization.enabled", matchIfMissing = true) +@ConditionalOnProperty(name = "cron.job.schedule.historicization.enabled", matchIfMissing = true) @NoArgsConstructor public class HistoricizationScheduler { @@ -179,10 +179,10 @@ private void archivesDebtPositions(List ppList) throws JsonProc for (Entry> entry : ppListByOrganizationFiscalCode.entrySet()) { List organizationPpList = ppListByOrganizationFiscalCode.get(entry.getKey()); for (PaymentPosition pp: organizationPpList) { - pp.getPaymentOption().forEach(po -> { + pp.getPaymentOption().forEach(po -> // write on azure table storage to persist the PO debt position info - this.saveToPOTable(entry.getKey(), pp, po); - }); + this.saveToPOTable(entry.getKey(), pp, po) + ); // write on azure table storage to persist the PP debt position info and json this.saveToPPTable(entry.getKey(), pp, objectMapper); } diff --git a/src/main/java/it/gov/pagopa/debtposition/scheduler/Scheduler.java b/src/main/java/it/gov/pagopa/debtposition/scheduler/Scheduler.java index 053e8065..7bfc5474 100644 --- a/src/main/java/it/gov/pagopa/debtposition/scheduler/Scheduler.java +++ b/src/main/java/it/gov/pagopa/debtposition/scheduler/Scheduler.java @@ -16,7 +16,7 @@ @Component @Slf4j -@ConditionalOnProperty(prefix = "status-change-service", name = "cron.job.schedule.enabled", matchIfMissing = true) +@ConditionalOnProperty(name = "cron.job.schedule.enabled", matchIfMissing = true) public class Scheduler { private static final String LOG_BASE_HEADER_INFO = "[OperationType: %s] - [ClassMethod: %s] - [MethodParamsToLog: %s]"; diff --git a/src/main/resources/application-h2.properties b/src/main/resources/application-h2.properties index 18d02f08..414fb54b 100644 --- a/src/main/resources/application-h2.properties +++ b/src/main/resources/application-h2.properties @@ -14,7 +14,7 @@ management.health.readinessState.enabled=true management.metrics.distribution.percentiles.http.server.requests=0.5, 0.9, 0.95, 0.99 # Database settings -spring.datasource.url=jdbc:h2:mem:db;MODE=PostgreSQL;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;INIT=CREATE SCHEMA IF NOT EXISTS APD\\;SET SCHEMA APD +spring.datasource.url=jdbc:h2:mem:db;MODE=PostgreSQL;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;INIT=CREATE SCHEMA IF NOT EXISTS APD\\;SET SCHEMA APD\\;CREATE TABLE IF NOT EXISTS APD.shedlock (name VARCHAR(64),lock_until TIMESTAMP(3) NULL,locked_at TIMESTAMP(3) NULL,locked_by VARCHAR(255),PRIMARY KEY (name)) spring.datasource.username=sa spring.datasource.password=sa spring.datasource.driver-class-name=org.h2.Driver From 52460726b85b64c94a473017b7187241a49f0152 Mon Sep 17 00:00:00 2001 From: pagopa-github-bot Date: Mon, 12 Feb 2024 08:25:12 +0000 Subject: [PATCH 05/15] Bump to version 0.11.1-1-PAGOPA-1488-renewal-debt-positions [skip ci] --- helm/Chart.yaml | 4 ++-- helm/values-dev.yaml | 2 +- helm/values-prod.yaml | 2 +- helm/values-uat.yaml | 2 +- openapi/openapi_external.json | 2 +- openapi/openapi_external_massive.json | 2 +- openapi/openapi_internal.json | 2 +- openapi/openapi_send.json | 2 +- pom.xml | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/helm/Chart.yaml b/helm/Chart.yaml index b070b6cc..3d97c171 100644 --- a/helm/Chart.yaml +++ b/helm/Chart.yaml @@ -2,8 +2,8 @@ apiVersion: v2 name: pagopa-gpd-core description: micro-service to manage Creditor Institution debtor positions type: application -version: 0.85.0 -appVersion: 0.11.1 +version: 0.86.0 +appVersion: 0.11.1-1-PAGOPA-1488-renewal-debt-positions dependencies: - name: microservice-chart version: 2.4.0 diff --git a/helm/values-dev.yaml b/helm/values-dev.yaml index 13d74074..65d73bf5 100644 --- a/helm/values-dev.yaml +++ b/helm/values-dev.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-debt-position - tag: "0.11.1" + tag: "0.11.1-1-PAGOPA-1488-renewal-debt-positions" pullPolicy: Always livenessProbe: httpGet: diff --git a/helm/values-prod.yaml b/helm/values-prod.yaml index 4ecede5e..0e77f1ee 100644 --- a/helm/values-prod.yaml +++ b/helm/values-prod.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-debt-position - tag: "0.11.1" + tag: "0.11.1-1-PAGOPA-1488-renewal-debt-positions" pullPolicy: Always livenessProbe: httpGet: diff --git a/helm/values-uat.yaml b/helm/values-uat.yaml index e8fce721..3049f17d 100644 --- a/helm/values-uat.yaml +++ b/helm/values-uat.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-debt-position - tag: "0.11.1" + tag: "0.11.1-1-PAGOPA-1488-renewal-debt-positions" pullPolicy: Always livenessProbe: httpGet: diff --git a/openapi/openapi_external.json b/openapi/openapi_external.json index f435a06a..72ded529 100644 --- a/openapi/openapi_external.json +++ b/openapi/openapi_external.json @@ -4,7 +4,7 @@ "title": "PagoPA API Debt Position", "description": "Progetto Gestione Posizioni Debitorie", "termsOfService": "https://www.pagopa.gov.it/", - "version": "0.11.1" + "version": "0.11.1-1-PAGOPA-1488-renewal-debt-positions" }, "servers": [ { diff --git a/openapi/openapi_external_massive.json b/openapi/openapi_external_massive.json index 658ef220..2fafb8ba 100644 --- a/openapi/openapi_external_massive.json +++ b/openapi/openapi_external_massive.json @@ -4,7 +4,7 @@ "title": "PagoPA API Debt Position", "description": "Progetto Gestione Posizioni Debitorie", "termsOfService": "https://www.pagopa.gov.it/", - "version": "0.11.1" + "version": "0.11.1-1-PAGOPA-1488-renewal-debt-positions" }, "servers": [ { diff --git a/openapi/openapi_internal.json b/openapi/openapi_internal.json index 5a1c5dec..c018be20 100644 --- a/openapi/openapi_internal.json +++ b/openapi/openapi_internal.json @@ -4,7 +4,7 @@ "title": "PagoPA API Debt Position", "description": "Progetto Gestione Posizioni Debitorie", "termsOfService": "https://www.pagopa.gov.it/", - "version": "0.11.1" + "version": "0.11.1-1-PAGOPA-1488-renewal-debt-positions" }, "servers": [ { diff --git a/openapi/openapi_send.json b/openapi/openapi_send.json index a4986d4d..5a9409be 100644 --- a/openapi/openapi_send.json +++ b/openapi/openapi_send.json @@ -4,7 +4,7 @@ "title": "PagoPA API Debt Position", "description": "Progetto Gestione Posizioni Debitorie", "termsOfService": "https://www.pagopa.gov.it/", - "version": "0.11.1" + "version": "0.11.1-1-PAGOPA-1488-renewal-debt-positions" }, "servers": [ { diff --git a/pom.xml b/pom.xml index 9fc08857..4e85d607 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ it.gov.pagopa.debtposition gpd - 0.11.1 + 0.11.1-1-PAGOPA-1488-renewal-debt-positions Gestione Posizioni Debitorie Progetto Gestione Posizioni Debitorie From db72d979ca05ffd0342fe60f2a86bcd2f2bb26d5 Mon Sep 17 00:00:00 2001 From: pagopa-github-bot Date: Mon, 12 Feb 2024 08:31:42 +0000 Subject: [PATCH 06/15] Bump to version 0.11.1-2-PAGOPA-1488-renewal-debt-positions [skip ci] --- helm/Chart.yaml | 4 ++-- helm/values-dev.yaml | 2 +- helm/values-prod.yaml | 2 +- helm/values-uat.yaml | 2 +- openapi/openapi_external.json | 2 +- openapi/openapi_external_massive.json | 2 +- openapi/openapi_internal.json | 2 +- openapi/openapi_send.json | 2 +- pom.xml | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/helm/Chart.yaml b/helm/Chart.yaml index 3d97c171..32870362 100644 --- a/helm/Chart.yaml +++ b/helm/Chart.yaml @@ -2,8 +2,8 @@ apiVersion: v2 name: pagopa-gpd-core description: micro-service to manage Creditor Institution debtor positions type: application -version: 0.86.0 -appVersion: 0.11.1-1-PAGOPA-1488-renewal-debt-positions +version: 0.87.0 +appVersion: 0.11.1-2-PAGOPA-1488-renewal-debt-positions dependencies: - name: microservice-chart version: 2.4.0 diff --git a/helm/values-dev.yaml b/helm/values-dev.yaml index 65d73bf5..3b5fc886 100644 --- a/helm/values-dev.yaml +++ b/helm/values-dev.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-debt-position - tag: "0.11.1-1-PAGOPA-1488-renewal-debt-positions" + tag: "0.11.1-2-PAGOPA-1488-renewal-debt-positions" pullPolicy: Always livenessProbe: httpGet: diff --git a/helm/values-prod.yaml b/helm/values-prod.yaml index 0e77f1ee..0a19f328 100644 --- a/helm/values-prod.yaml +++ b/helm/values-prod.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-debt-position - tag: "0.11.1-1-PAGOPA-1488-renewal-debt-positions" + tag: "0.11.1-2-PAGOPA-1488-renewal-debt-positions" pullPolicy: Always livenessProbe: httpGet: diff --git a/helm/values-uat.yaml b/helm/values-uat.yaml index 3049f17d..4b8bf118 100644 --- a/helm/values-uat.yaml +++ b/helm/values-uat.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-debt-position - tag: "0.11.1-1-PAGOPA-1488-renewal-debt-positions" + tag: "0.11.1-2-PAGOPA-1488-renewal-debt-positions" pullPolicy: Always livenessProbe: httpGet: diff --git a/openapi/openapi_external.json b/openapi/openapi_external.json index 72ded529..f7668ced 100644 --- a/openapi/openapi_external.json +++ b/openapi/openapi_external.json @@ -4,7 +4,7 @@ "title": "PagoPA API Debt Position", "description": "Progetto Gestione Posizioni Debitorie", "termsOfService": "https://www.pagopa.gov.it/", - "version": "0.11.1-1-PAGOPA-1488-renewal-debt-positions" + "version": "0.11.1-2-PAGOPA-1488-renewal-debt-positions" }, "servers": [ { diff --git a/openapi/openapi_external_massive.json b/openapi/openapi_external_massive.json index 2fafb8ba..3d5da14b 100644 --- a/openapi/openapi_external_massive.json +++ b/openapi/openapi_external_massive.json @@ -4,7 +4,7 @@ "title": "PagoPA API Debt Position", "description": "Progetto Gestione Posizioni Debitorie", "termsOfService": "https://www.pagopa.gov.it/", - "version": "0.11.1-1-PAGOPA-1488-renewal-debt-positions" + "version": "0.11.1-2-PAGOPA-1488-renewal-debt-positions" }, "servers": [ { diff --git a/openapi/openapi_internal.json b/openapi/openapi_internal.json index c018be20..99c3e9f2 100644 --- a/openapi/openapi_internal.json +++ b/openapi/openapi_internal.json @@ -4,7 +4,7 @@ "title": "PagoPA API Debt Position", "description": "Progetto Gestione Posizioni Debitorie", "termsOfService": "https://www.pagopa.gov.it/", - "version": "0.11.1-1-PAGOPA-1488-renewal-debt-positions" + "version": "0.11.1-2-PAGOPA-1488-renewal-debt-positions" }, "servers": [ { diff --git a/openapi/openapi_send.json b/openapi/openapi_send.json index 5a9409be..690d085b 100644 --- a/openapi/openapi_send.json +++ b/openapi/openapi_send.json @@ -4,7 +4,7 @@ "title": "PagoPA API Debt Position", "description": "Progetto Gestione Posizioni Debitorie", "termsOfService": "https://www.pagopa.gov.it/", - "version": "0.11.1-1-PAGOPA-1488-renewal-debt-positions" + "version": "0.11.1-2-PAGOPA-1488-renewal-debt-positions" }, "servers": [ { diff --git a/pom.xml b/pom.xml index 4e85d607..7449fe8c 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ it.gov.pagopa.debtposition gpd - 0.11.1-1-PAGOPA-1488-renewal-debt-positions + 0.11.1-2-PAGOPA-1488-renewal-debt-positions Gestione Posizioni Debitorie Progetto Gestione Posizioni Debitorie From 4f5f11dc928aa55a7619731806e3f6782ba26e3e Mon Sep 17 00:00:00 2001 From: pagopa-github-bot Date: Mon, 12 Feb 2024 09:05:15 +0000 Subject: [PATCH 07/15] Bump to version 0.11.1-3-PAGOPA-1488-renewal-debt-positions [skip ci] --- helm/Chart.yaml | 4 ++-- helm/values-dev.yaml | 2 +- helm/values-prod.yaml | 2 +- helm/values-uat.yaml | 2 +- openapi/openapi_external.json | 2 +- openapi/openapi_external_massive.json | 2 +- openapi/openapi_internal.json | 2 +- openapi/openapi_send.json | 2 +- pom.xml | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/helm/Chart.yaml b/helm/Chart.yaml index 32870362..6846adca 100644 --- a/helm/Chart.yaml +++ b/helm/Chart.yaml @@ -2,8 +2,8 @@ apiVersion: v2 name: pagopa-gpd-core description: micro-service to manage Creditor Institution debtor positions type: application -version: 0.87.0 -appVersion: 0.11.1-2-PAGOPA-1488-renewal-debt-positions +version: 0.88.0 +appVersion: 0.11.1-3-PAGOPA-1488-renewal-debt-positions dependencies: - name: microservice-chart version: 2.4.0 diff --git a/helm/values-dev.yaml b/helm/values-dev.yaml index 3b5fc886..70707721 100644 --- a/helm/values-dev.yaml +++ b/helm/values-dev.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-debt-position - tag: "0.11.1-2-PAGOPA-1488-renewal-debt-positions" + tag: "0.11.1-3-PAGOPA-1488-renewal-debt-positions" pullPolicy: Always livenessProbe: httpGet: diff --git a/helm/values-prod.yaml b/helm/values-prod.yaml index 0a19f328..b2bc3579 100644 --- a/helm/values-prod.yaml +++ b/helm/values-prod.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-debt-position - tag: "0.11.1-2-PAGOPA-1488-renewal-debt-positions" + tag: "0.11.1-3-PAGOPA-1488-renewal-debt-positions" pullPolicy: Always livenessProbe: httpGet: diff --git a/helm/values-uat.yaml b/helm/values-uat.yaml index 4b8bf118..138c4939 100644 --- a/helm/values-uat.yaml +++ b/helm/values-uat.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-debt-position - tag: "0.11.1-2-PAGOPA-1488-renewal-debt-positions" + tag: "0.11.1-3-PAGOPA-1488-renewal-debt-positions" pullPolicy: Always livenessProbe: httpGet: diff --git a/openapi/openapi_external.json b/openapi/openapi_external.json index f7668ced..4ec6f328 100644 --- a/openapi/openapi_external.json +++ b/openapi/openapi_external.json @@ -4,7 +4,7 @@ "title": "PagoPA API Debt Position", "description": "Progetto Gestione Posizioni Debitorie", "termsOfService": "https://www.pagopa.gov.it/", - "version": "0.11.1-2-PAGOPA-1488-renewal-debt-positions" + "version": "0.11.1-3-PAGOPA-1488-renewal-debt-positions" }, "servers": [ { diff --git a/openapi/openapi_external_massive.json b/openapi/openapi_external_massive.json index 3d5da14b..1b11a56d 100644 --- a/openapi/openapi_external_massive.json +++ b/openapi/openapi_external_massive.json @@ -4,7 +4,7 @@ "title": "PagoPA API Debt Position", "description": "Progetto Gestione Posizioni Debitorie", "termsOfService": "https://www.pagopa.gov.it/", - "version": "0.11.1-2-PAGOPA-1488-renewal-debt-positions" + "version": "0.11.1-3-PAGOPA-1488-renewal-debt-positions" }, "servers": [ { diff --git a/openapi/openapi_internal.json b/openapi/openapi_internal.json index 99c3e9f2..3744615b 100644 --- a/openapi/openapi_internal.json +++ b/openapi/openapi_internal.json @@ -4,7 +4,7 @@ "title": "PagoPA API Debt Position", "description": "Progetto Gestione Posizioni Debitorie", "termsOfService": "https://www.pagopa.gov.it/", - "version": "0.11.1-2-PAGOPA-1488-renewal-debt-positions" + "version": "0.11.1-3-PAGOPA-1488-renewal-debt-positions" }, "servers": [ { diff --git a/openapi/openapi_send.json b/openapi/openapi_send.json index 690d085b..71e2815b 100644 --- a/openapi/openapi_send.json +++ b/openapi/openapi_send.json @@ -4,7 +4,7 @@ "title": "PagoPA API Debt Position", "description": "Progetto Gestione Posizioni Debitorie", "termsOfService": "https://www.pagopa.gov.it/", - "version": "0.11.1-2-PAGOPA-1488-renewal-debt-positions" + "version": "0.11.1-3-PAGOPA-1488-renewal-debt-positions" }, "servers": [ { diff --git a/pom.xml b/pom.xml index 7449fe8c..73208f49 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ it.gov.pagopa.debtposition gpd - 0.11.1-2-PAGOPA-1488-renewal-debt-positions + 0.11.1-3-PAGOPA-1488-renewal-debt-positions Gestione Posizioni Debitorie Progetto Gestione Posizioni Debitorie From 870db999ae5fc88b600a6476a2260b29151d47c0 Mon Sep 17 00:00:00 2001 From: aacitelli Date: Mon, 12 Feb 2024 10:39:44 +0100 Subject: [PATCH 08/15] [PAGOPA-1488] renewal debt positions: debug log --- .../it/gov/pagopa/debtposition/config/SchedulerConfig.java | 5 ++++- .../debtposition/scheduler/HistoricizationScheduler.java | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/it/gov/pagopa/debtposition/config/SchedulerConfig.java b/src/main/java/it/gov/pagopa/debtposition/config/SchedulerConfig.java index a299978b..e92bce5d 100644 --- a/src/main/java/it/gov/pagopa/debtposition/config/SchedulerConfig.java +++ b/src/main/java/it/gov/pagopa/debtposition/config/SchedulerConfig.java @@ -3,6 +3,7 @@ import javax.sql.DataSource; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.EnableAsync; @@ -17,9 +18,11 @@ @EnableAsync @EnableSchedulerLock(defaultLockAtMostFor = "${cron.job.schedule.history.shedlock.defaultlockatmostfor}") public class SchedulerConfig { + @Value("${spring.jpa.properties.hibernate.default_schema:apd}") + private String defaultSchema; @Bean public LockProvider lockProvider(DataSource dataSource) { - return new JdbcTemplateLockProvider(dataSource, "apd.shedlock"); + return new JdbcTemplateLockProvider(dataSource, defaultSchema+".shedlock"); } } diff --git a/src/main/java/it/gov/pagopa/debtposition/scheduler/HistoricizationScheduler.java b/src/main/java/it/gov/pagopa/debtposition/scheduler/HistoricizationScheduler.java index 3f41caa5..05fbfc96 100644 --- a/src/main/java/it/gov/pagopa/debtposition/scheduler/HistoricizationScheduler.java +++ b/src/main/java/it/gov/pagopa/debtposition/scheduler/HistoricizationScheduler.java @@ -97,7 +97,7 @@ public void manageDebtPositionsToHistoricize() throws JsonProcessingException, T int numOfPages = (int)Math.ceil((float)countResult/pageSize); for (int pageNumber=0; pageNumber ppList) throws JsonProc // write on azure table storage to persist the PP debt position info and json this.upsertPPTable(entry.getKey(), pp, objectMapper); } - log.info(String.format(LOG_BASE_HEADER_INFO, CRON_JOB, "archivesDebtPositions", "historicized n. "+organizationPpList.size()+" debt positions for the organization fiscal code: " +entry.getKey())); + log.debug(String.format(LOG_BASE_HEADER_INFO, CRON_JOB, "archivesDebtPositions", "historicized n. "+organizationPpList.size()+" debt positions for the organization fiscal code: " +entry.getKey())); } } } From 345ae5c9d6e8f36bbd45679ca2fa60764293ca6e Mon Sep 17 00:00:00 2001 From: aacitelli Date: Mon, 12 Feb 2024 11:39:34 +0100 Subject: [PATCH 09/15] Merge branch 'PAGOPA-1488-renewal-debt-positions' of https://github.com/pagopa/pagopa-debt-position.git into PAGOPA-1488-renewal-debt-positions --- .../debtposition/config/SchedulerConfig.java | 2 - .../debtposition/entity/PaymentOption.java | 4 + .../entity/PaymentOptionMetadata.java | 4 + .../debtposition/entity/PaymentPosition.java | 5 + .../pagopa/debtposition/entity/Transfer.java | 4 + .../debtposition/entity/TransferMetadata.java | 4 + .../scheduler/HistoricizationScheduler.java | 148 ++++++++++++++++++ .../debtposition/scheduler/Scheduler.java | 4 + src/main/resources/application-h2.properties | 10 ++ src/main/resources/application.properties | 11 ++ src/test/resources/application.properties | 10 ++ 11 files changed, 204 insertions(+), 2 deletions(-) create mode 100644 src/main/java/it/gov/pagopa/debtposition/scheduler/HistoricizationScheduler.java diff --git a/src/main/java/it/gov/pagopa/debtposition/config/SchedulerConfig.java b/src/main/java/it/gov/pagopa/debtposition/config/SchedulerConfig.java index 03de0521..6bd1b6fe 100644 --- a/src/main/java/it/gov/pagopa/debtposition/config/SchedulerConfig.java +++ b/src/main/java/it/gov/pagopa/debtposition/config/SchedulerConfig.java @@ -1,6 +1,5 @@ package it.gov.pagopa.debtposition.config; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableScheduling; @@ -8,7 +7,6 @@ @Configuration @EnableScheduling @EnableAsync -@ConditionalOnProperty(name = "cron.job.schedule.enabled", matchIfMissing = true) public class SchedulerConfig { } diff --git a/src/main/java/it/gov/pagopa/debtposition/entity/PaymentOption.java b/src/main/java/it/gov/pagopa/debtposition/entity/PaymentOption.java index 72cd70eb..f25f9a84 100644 --- a/src/main/java/it/gov/pagopa/debtposition/entity/PaymentOption.java +++ b/src/main/java/it/gov/pagopa/debtposition/entity/PaymentOption.java @@ -24,6 +24,9 @@ import javax.persistence.UniqueConstraint; import javax.validation.constraints.NotNull; +import com.fasterxml.jackson.annotation.JsonIdentityInfo; +import com.fasterxml.jackson.annotation.ObjectIdGenerators; + import it.gov.pagopa.debtposition.model.enumeration.PaymentOptionStatus; import lombok.AllArgsConstructor; import lombok.Builder; @@ -49,6 +52,7 @@ columnNames = {"iuv", "organization_fiscal_code"}) }, indexes = @Index(name = "payment_option_payment_position_id_idx", columnList = "payment_position_id")) +@JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class, property="@paymentOptionId") public class PaymentOption implements Serializable { /** diff --git a/src/main/java/it/gov/pagopa/debtposition/entity/PaymentOptionMetadata.java b/src/main/java/it/gov/pagopa/debtposition/entity/PaymentOptionMetadata.java index c20b4c19..7844e148 100644 --- a/src/main/java/it/gov/pagopa/debtposition/entity/PaymentOptionMetadata.java +++ b/src/main/java/it/gov/pagopa/debtposition/entity/PaymentOptionMetadata.java @@ -15,6 +15,9 @@ import javax.persistence.UniqueConstraint; import javax.validation.constraints.NotNull; +import com.fasterxml.jackson.annotation.JsonIdentityInfo; +import com.fasterxml.jackson.annotation.ObjectIdGenerators; + import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -32,6 +35,7 @@ @AllArgsConstructor @Entity @Builder +@JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class, property="@paymentOptionMetadataId") public class PaymentOptionMetadata implements Serializable { diff --git a/src/main/java/it/gov/pagopa/debtposition/entity/PaymentPosition.java b/src/main/java/it/gov/pagopa/debtposition/entity/PaymentPosition.java index e42d09f8..c563b47a 100644 --- a/src/main/java/it/gov/pagopa/debtposition/entity/PaymentPosition.java +++ b/src/main/java/it/gov/pagopa/debtposition/entity/PaymentPosition.java @@ -10,6 +10,10 @@ import javax.persistence.*; import javax.validation.constraints.NotNull; + +import com.fasterxml.jackson.annotation.JsonIdentityInfo; +import com.fasterxml.jackson.annotation.ObjectIdGenerators; + import java.io.Serializable; import java.time.LocalDateTime; import java.util.ArrayList; @@ -32,6 +36,7 @@ }, indexes = @Index(name = "payment_position_status_validity_date_idx", columnList = "status, validity_date") ) +@JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class, property="@paymentPositionId") public class PaymentPosition implements Serializable { diff --git a/src/main/java/it/gov/pagopa/debtposition/entity/Transfer.java b/src/main/java/it/gov/pagopa/debtposition/entity/Transfer.java index fc372e19..9e903b20 100644 --- a/src/main/java/it/gov/pagopa/debtposition/entity/Transfer.java +++ b/src/main/java/it/gov/pagopa/debtposition/entity/Transfer.java @@ -23,6 +23,9 @@ import javax.persistence.UniqueConstraint; import javax.validation.constraints.NotNull; +import com.fasterxml.jackson.annotation.JsonIdentityInfo; +import com.fasterxml.jackson.annotation.ObjectIdGenerators; + import it.gov.pagopa.debtposition.model.enumeration.TransferStatus; import lombok.AllArgsConstructor; import lombok.Builder; @@ -50,6 +53,7 @@ columnNames = {"iuv", "organization_fiscal_code", "transfer_id"}) }, indexes = @Index(name = "transfer_payment_option_id_idx", columnList = "payment_option_id")) +@JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class, property="@transferId") public class Transfer implements Serializable { /** diff --git a/src/main/java/it/gov/pagopa/debtposition/entity/TransferMetadata.java b/src/main/java/it/gov/pagopa/debtposition/entity/TransferMetadata.java index 89860724..69611579 100644 --- a/src/main/java/it/gov/pagopa/debtposition/entity/TransferMetadata.java +++ b/src/main/java/it/gov/pagopa/debtposition/entity/TransferMetadata.java @@ -15,6 +15,9 @@ import javax.persistence.UniqueConstraint; import javax.validation.constraints.NotNull; +import com.fasterxml.jackson.annotation.JsonIdentityInfo; +import com.fasterxml.jackson.annotation.ObjectIdGenerators; + import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -32,6 +35,7 @@ @AllArgsConstructor @Entity @Builder +@JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class, property="@transferMetadataId") public class TransferMetadata implements Serializable { /** diff --git a/src/main/java/it/gov/pagopa/debtposition/scheduler/HistoricizationScheduler.java b/src/main/java/it/gov/pagopa/debtposition/scheduler/HistoricizationScheduler.java new file mode 100644 index 00000000..504a250c --- /dev/null +++ b/src/main/java/it/gov/pagopa/debtposition/scheduler/HistoricizationScheduler.java @@ -0,0 +1,148 @@ +package it.gov.pagopa.debtposition.scheduler; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.stream.Collectors; + +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.PersistenceUnit; +import javax.transaction.Transactional; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.scheduling.annotation.Async; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import com.azure.data.tables.TableClient; +import com.azure.data.tables.TableClientBuilder; +import com.azure.data.tables.models.TableEntity; +import com.azure.data.tables.models.TableErrorCode; +import com.azure.data.tables.models.TableServiceException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; + +import it.gov.pagopa.debtposition.entity.PaymentOption; +import it.gov.pagopa.debtposition.entity.PaymentPosition; +import it.gov.pagopa.debtposition.repository.PaymentPositionRepository; +import lombok.extern.slf4j.Slf4j; + +@Component +@Slf4j +@ConditionalOnProperty(name = "cron.job.schedule.historicization.enabled", matchIfMissing = true) +public class HistoricizationScheduler { + + private static final String LOG_BASE_HEADER_INFO = "[OperationType: %s] - [ClassMethod: %s] - [MethodParamsToLog: %s]"; + private static final String CRON_JOB = "CRON JOB"; + private static final String METHOD = "manageDebtPositionsToHistoricize"; + private Thread threadOfExecution; + private TableClient tableClient; + + @Value("${cron.job.schedule.extraction.history.query:SELECT pp FROM PaymentPosition pp WHERE pp.status IN ('PAID', 'REPORTED', 'INVALID', 'EXPIRED') AND pp.lastUpdatedDate < ?1}") + private String extractionQuery; + @Value("${cron.job.schedule.extraction.history.query.interval:365}") + private short extractionInterval; + @Value("${azure.archive.storage.connection}") + private String archiveStorageConnection; + @Value("${azure.archive.storage.table.po:pagopadweugpsarchivesapaymentoptiontable}") + private String archiveStoragePOTable; + @Value("${azure.archive.storage.table.pp:pagopadweugpsarchivesapaymentpositiontable}") + private String archiveStoragePPTable; + + @Autowired + private PaymentPositionRepository paymentPositionRepository; + @PersistenceUnit + private EntityManagerFactory emf; + + + @Scheduled(cron = "${cron.job.schedule.expression.historicization.debt.positions}") + @Async + @Transactional + public void manageDebtPositionsToHistoricize() throws JsonProcessingException, TableServiceException { + log.info(String.format(LOG_BASE_HEADER_INFO, CRON_JOB, METHOD, "Running at " + DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(LocalDateTime.now()))); + EntityManager em = emf.createEntityManager(); + LocalDateTime ldt = LocalDateTime.now().minusDays(extractionInterval); + List ppList = em.createQuery(extractionQuery, PaymentPosition.class).setParameter(1,ldt).getResultList(); + log.info(String.format(LOG_BASE_HEADER_INFO, CRON_JOB, METHOD, "Number of extracted rows to historicize: " + ppList.size())); + + Map> ppListByOrganizationFiscalCode = ppList.stream() + .collect(Collectors.groupingBy(p -> p.getOrganizationFiscalCode(), Collectors.mapping((PaymentPosition p) -> p, Collectors.toList()))); + + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.registerModule(new JavaTimeModule()); + + for (Entry> entry : ppListByOrganizationFiscalCode.entrySet()) { + List organizationPpList = ppListByOrganizationFiscalCode.get(entry.getKey()); + for (PaymentPosition pp: organizationPpList) { + pp.getPaymentOption().forEach(po -> { + // write on azure table storage to persist the PO debt position info + this.saveToPOTable(entry.getKey(), pp, po); + }); + // write on azure table storage to persist the PP debt position info and json + this.saveToPPTable(entry.getKey(), pp, objectMapper); + } + log.info(String.format(LOG_BASE_HEADER_INFO, CRON_JOB, METHOD, "historicized n. "+organizationPpList.size()+" debt positions for the organization fiscal code: " +entry.getKey())); + } + + // historicized debt positions are removed + //paymentPositionRepository.deleteAll(ppList); + log.info(String.format(LOG_BASE_HEADER_INFO, CRON_JOB, METHOD, "deleted historicized debt positions")); + } + + public Thread getThreadOfExecution() { + return this.threadOfExecution; + } + + private void saveToPOTable(String organizationFiscalCode, PaymentPosition pp, PaymentOption po) { + tableClient = new TableClientBuilder() + .connectionString(archiveStorageConnection) + .tableName(archiveStoragePOTable) + .buildClient(); + TableEntity tableEntity = new TableEntity(organizationFiscalCode, po.getIuv()); + try { + Map properties = new HashMap<>(); + properties.put("PaymentDate", po.getPaymentDate()); + properties.put("IUPD", pp.getIupd()); + tableEntity.setProperties(properties); + tableClient.createEntity(tableEntity); + } catch (TableServiceException e) { + if (e.getValue().getErrorCode() == TableErrorCode.ENTITY_ALREADY_EXISTS) { + tableClient.updateEntity(tableEntity); + } else { + log.error(String.format(LOG_BASE_HEADER_INFO, CRON_JOB, "saveToPOTable", + "error while storing the table information [organizationFiscalCode="+organizationFiscalCode+", iuv="+po.getIuv()+"]"), e); + throw e; + } + } + } + + private void saveToPPTable(String organizationFiscalCode, PaymentPosition pp, ObjectMapper objectMapper) + throws JsonProcessingException { + tableClient = new TableClientBuilder() + .connectionString(archiveStorageConnection) + .tableName(archiveStoragePPTable) + .buildClient(); + TableEntity tableEntity = new TableEntity(organizationFiscalCode, pp.getIupd()); + try { + Map properties = new HashMap<>(); + properties.put("PaymentPosition", objectMapper.writeValueAsString(pp)); + tableEntity.setProperties(properties); + tableClient.createEntity(tableEntity); + } catch (TableServiceException e) { + if (e.getValue().getErrorCode() == TableErrorCode.ENTITY_ALREADY_EXISTS) { + tableClient.updateEntity(tableEntity); + } else { + log.error(String.format(LOG_BASE_HEADER_INFO, CRON_JOB, "saveToPPTable", + "error while storing the table information [organizationFiscalCode="+organizationFiscalCode+", iupd="+pp.getIupd()+"]"), e); + throw e; + } + } + } +} diff --git a/src/main/java/it/gov/pagopa/debtposition/scheduler/Scheduler.java b/src/main/java/it/gov/pagopa/debtposition/scheduler/Scheduler.java index 60069e6e..7bfc5474 100644 --- a/src/main/java/it/gov/pagopa/debtposition/scheduler/Scheduler.java +++ b/src/main/java/it/gov/pagopa/debtposition/scheduler/Scheduler.java @@ -4,6 +4,7 @@ import it.gov.pagopa.debtposition.repository.PaymentPositionRepository; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; @@ -15,6 +16,7 @@ @Component @Slf4j +@ConditionalOnProperty(name = "cron.job.schedule.enabled", matchIfMissing = true) public class Scheduler { private static final String LOG_BASE_HEADER_INFO = "[OperationType: %s] - [ClassMethod: %s] - [MethodParamsToLog: %s]"; @@ -34,6 +36,7 @@ public void changeDebtPositionStatusToValid() { this.threadOfExecution = Thread.currentThread(); } + @Scheduled(cron = "${cron.job.schedule.expression.expired.status}") @Async @Transactional @@ -44,6 +47,7 @@ public void changeDebtPositionStatusToExpired() { log.info(String.format(LOG_BASE_HEADER_INFO, CRON_JOB, "changeDebtPositionStatusToExpired", "Number of updated rows " + numAffectedRows)); this.threadOfExecution = Thread.currentThread(); } + public Thread getThreadOfExecution() { return this.threadOfExecution; diff --git a/src/main/resources/application-h2.properties b/src/main/resources/application-h2.properties index cf4f51f3..8690ff3d 100644 --- a/src/main/resources/application-h2.properties +++ b/src/main/resources/application-h2.properties @@ -36,6 +36,16 @@ cron.job.schedule.enabled=false cron.job.schedule.expression.valid.status=*/35 * * * * * cron.job.schedule.expression.expired.status=*/35 * * * * * +cron.job.schedule.historicization.enabled=true +cron.job.schedule.expression.historicization.debt.positions=*/55 * * * * * +cron.job.schedule.extraction.history.query =SELECT pp FROM PaymentPosition pp WHERE pp.status IN ('PAID', 'REPORTED', 'INVALID', 'EXPIRED') AND pp.lastUpdatedDate < ?1 +# The time, in days, to be subtracted from the current date to decide how old, the debt positions to be historicized, must be (default 365 days) +cron.job.schedule.extraction.history.query.interval=0 + +azure.archive.storage.connection=DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1;TableEndpoint=http://127.0.0.1:10002/devstoreaccount1; +azure.archive.storage.table.po=pagopadweugpsarchivesapaymentoptiontable +azure.archive.storage.table.pp=pagopadweugpsarchivesapaymentpositiontable + # Flyway settings spring.flyway.schemas=apd diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index f6b2f4f5..1f317cb2 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -34,6 +34,17 @@ cron.job.schedule.enabled = ${CRON_JOB_SCHEDULE_ENABLED} cron.job.schedule.expression.valid.status = ${CRON_JOB_SCHEDULE_EXPRESSION_TO_VALID} cron.job.schedule.expression.expired.status = ${CRON_JOB_SCHEDULE_EXPRESSION_TO_EXPIRED} +cron.job.schedule.historicization.enabled = ${CRON_JOB_SCHEDULE_HISTORICIZATION_ENABLED} +cron.job.schedule.expression.historicization.debt.positions = ${CRON_JOB_SCHEDULE_EXPRESSION_HISTORICIZATION_DEBT_POS} +cron.job.schedule.extraction.history.query = ${CRON_JOB_SCHEDULE_EXTRACTION_HISTORY_QUERY} +# The time, in days, to be subtracted from the current date to decide how old, the debt positions to be historicized, must be (default 365 days) +cron.job.schedule.extraction.history.query.interval = ${CRON_JOB_SCHEDULE_EXTRACTION_HISTORY_QUERY_INTERVAL} + +azure.archive.storage.connection=${ARCHIVE_SA_CONNECTION_STRING} +azure.archive.storage.table.po=${ARCHIVE_SA_PO_TABLE} +azure.archive.storage.table.pp=${ARCHIVE_SA_PP_TABLE} + + # Max num. of days for the recovery of debt positions max.days.interval = ${MAX_DAYS_INTERVAL:#{'30'}} diff --git a/src/test/resources/application.properties b/src/test/resources/application.properties index 8488c216..fda594a3 100644 --- a/src/test/resources/application.properties +++ b/src/test/resources/application.properties @@ -31,6 +31,16 @@ cron.job.schedule.enabled=false cron.job.schedule.expression.valid.status=*/35 * * * * * cron.job.schedule.expression.expired.status =*/55 * * * * * +cron.job.schedule.historicization.enabled=false +cron.job.schedule.expression.historicization.debt.positions=*/55 * * * * * +cron.job.schedule.extraction.history.query =SELECT pp FROM PaymentPosition pp WHERE pp.status IN ('PAID', 'REPORTED', 'INVALID', 'EXPIRED') AND pp.lastUpdatedDate < ?1 +# The time, in days, to be subtracted from the current date to decide how old, the debt positions to be historicized, must be (default 365 days) +cron.job.schedule.extraction.history.query.interval=0 + +azure.archive.storage.connection=DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1;TableEndpoint=http://127.0.0.1:10002/devstoreaccount1; +azure.archive.storage.table.po=pagopadweugpsarchivesapaymentoptiontable +azure.archive.storage.table.pp=pagopadweugpsarchivesapaymentpositiontable + # Max num. of days for the recovery of debt positions max.days.interval = 30 From 2b468e30d3aa3c025104794e3761d94ac2b27586 Mon Sep 17 00:00:00 2001 From: aacitelli Date: Mon, 12 Feb 2024 11:45:18 +0100 Subject: [PATCH 10/15] rebase --- .../scheduler/HistoricizationScheduler.java | 128 ++++++++++++------ src/main/resources/application-h2.properties | 7 +- 2 files changed, 92 insertions(+), 43 deletions(-) diff --git a/src/main/java/it/gov/pagopa/debtposition/scheduler/HistoricizationScheduler.java b/src/main/java/it/gov/pagopa/debtposition/scheduler/HistoricizationScheduler.java index 504a250c..ec104d14 100644 --- a/src/main/java/it/gov/pagopa/debtposition/scheduler/HistoricizationScheduler.java +++ b/src/main/java/it/gov/pagopa/debtposition/scheduler/HistoricizationScheduler.java @@ -32,23 +32,39 @@ import it.gov.pagopa.debtposition.entity.PaymentOption; import it.gov.pagopa.debtposition.entity.PaymentPosition; import it.gov.pagopa.debtposition.repository.PaymentPositionRepository; +import lombok.Getter; +import lombok.NoArgsConstructor; import lombok.extern.slf4j.Slf4j; +import net.javacrumbs.shedlock.spring.annotation.SchedulerLock; @Component @Slf4j @ConditionalOnProperty(name = "cron.job.schedule.historicization.enabled", matchIfMissing = true) +@NoArgsConstructor public class HistoricizationScheduler { - private static final String LOG_BASE_HEADER_INFO = "[OperationType: %s] - [ClassMethod: %s] - [MethodParamsToLog: %s]"; + private static final String LOG_BASE_HEADER_INFO = "[OperationType: %s] - [ClassMethod: %s] - [MethodParamsToLog: %s]"; private static final String CRON_JOB = "CRON JOB"; private static final String METHOD = "manageDebtPositionsToHistoricize"; + @Getter private Thread threadOfExecution; - private TableClient tableClient; + + + // extraction params @Value("${cron.job.schedule.extraction.history.query:SELECT pp FROM PaymentPosition pp WHERE pp.status IN ('PAID', 'REPORTED', 'INVALID', 'EXPIRED') AND pp.lastUpdatedDate < ?1}") private String extractionQuery; @Value("${cron.job.schedule.extraction.history.query.interval:365}") private short extractionInterval; + // extraction params: pagination mode + @Value("${cron.job.schedule.extraction.history.query.paginated:true}") + private boolean paginationMode; + @Value("${cron.job.schedule.extraction.history.query.count:SELECT count(pp.id) FROM PaymentPosition pp WHERE pp.status IN ('PAID', 'REPORTED', 'INVALID', 'EXPIRED') AND pp.lastUpdatedDate < ?1}") + private String countExtractionQuery; + @Value("${cron.job.schedule.extraction.history.query.page.size:100000}") + private int pageSize; + + // azure storage params @Value("${azure.archive.storage.connection}") private String archiveStorageConnection; @Value("${azure.archive.storage.table.po:pagopadweugpsarchivesapaymentoptiontable}") @@ -61,50 +77,57 @@ public class HistoricizationScheduler { @PersistenceUnit private EntityManagerFactory emf; - + public HistoricizationScheduler(PaymentPositionRepository paymentPositionRepository) { + super(); + this.paymentPositionRepository = paymentPositionRepository; + } + @Scheduled(cron = "${cron.job.schedule.expression.historicization.debt.positions}") + @SchedulerLock(name = "HistoricizationScheduler_manageDebtPositionsToHistoricize", lockAtMostFor = "180m", lockAtLeastFor = "15m") @Async @Transactional public void manageDebtPositionsToHistoricize() throws JsonProcessingException, TableServiceException { log.info(String.format(LOG_BASE_HEADER_INFO, CRON_JOB, METHOD, "Running at " + DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(LocalDateTime.now()))); - EntityManager em = emf.createEntityManager(); + EntityManager em = this.getEntityManager(); LocalDateTime ldt = LocalDateTime.now().minusDays(extractionInterval); - List ppList = em.createQuery(extractionQuery, PaymentPosition.class).setParameter(1,ldt).getResultList(); - log.info(String.format(LOG_BASE_HEADER_INFO, CRON_JOB, METHOD, "Number of extracted rows to historicize: " + ppList.size())); - - Map> ppListByOrganizationFiscalCode = ppList.stream() - .collect(Collectors.groupingBy(p -> p.getOrganizationFiscalCode(), Collectors.mapping((PaymentPosition p) -> p, Collectors.toList()))); - - ObjectMapper objectMapper = new ObjectMapper(); - objectMapper.registerModule(new JavaTimeModule()); - - for (Entry> entry : ppListByOrganizationFiscalCode.entrySet()) { - List organizationPpList = ppListByOrganizationFiscalCode.get(entry.getKey()); - for (PaymentPosition pp: organizationPpList) { - pp.getPaymentOption().forEach(po -> { - // write on azure table storage to persist the PO debt position info - this.saveToPOTable(entry.getKey(), pp, po); - }); - // write on azure table storage to persist the PP debt position info and json - this.saveToPPTable(entry.getKey(), pp, objectMapper); - } - log.info(String.format(LOG_BASE_HEADER_INFO, CRON_JOB, METHOD, "historicized n. "+organizationPpList.size()+" debt positions for the organization fiscal code: " +entry.getKey())); - } - - // historicized debt positions are removed - //paymentPositionRepository.deleteAll(ppList); - log.info(String.format(LOG_BASE_HEADER_INFO, CRON_JOB, METHOD, "deleted historicized debt positions")); + List ppList; + if (paginationMode) { + long countResult = em.createQuery(countExtractionQuery, Long.class).setParameter(1,ldt).getSingleResult(); + int numOfPages = (int)Math.ceil((float)countResult/pageSize); + for (int pageNumber=0; pageNumber properties = new HashMap<>(); @@ -114,6 +137,8 @@ private void saveToPOTable(String organizationFiscalCode, PaymentPosition pp, Pa tableClient.createEntity(tableEntity); } catch (TableServiceException e) { if (e.getValue().getErrorCode() == TableErrorCode.ENTITY_ALREADY_EXISTS) { + log.warn(String.format(LOG_BASE_HEADER_INFO, CRON_JOB, "saveToPOTable", + TableErrorCode.ENTITY_ALREADY_EXISTS + " managed error while storing the table information [organizationFiscalCode="+organizationFiscalCode+", iuv="+po.getIuv()+"]"), e); tableClient.updateEntity(tableEntity); } else { log.error(String.format(LOG_BASE_HEADER_INFO, CRON_JOB, "saveToPOTable", @@ -123,12 +148,8 @@ private void saveToPOTable(String organizationFiscalCode, PaymentPosition pp, Pa } } - private void saveToPPTable(String organizationFiscalCode, PaymentPosition pp, ObjectMapper objectMapper) - throws JsonProcessingException { - tableClient = new TableClientBuilder() - .connectionString(archiveStorageConnection) - .tableName(archiveStoragePPTable) - .buildClient(); + public void saveToPPTable(String organizationFiscalCode, PaymentPosition pp, ObjectMapper objectMapper) throws JsonProcessingException { + TableClient tableClient = this.getTableClient(archiveStorageConnection, archiveStoragePPTable); TableEntity tableEntity = new TableEntity(organizationFiscalCode, pp.getIupd()); try { Map properties = new HashMap<>(); @@ -137,6 +158,8 @@ private void saveToPPTable(String organizationFiscalCode, PaymentPosition pp, Ob tableClient.createEntity(tableEntity); } catch (TableServiceException e) { if (e.getValue().getErrorCode() == TableErrorCode.ENTITY_ALREADY_EXISTS) { + log.warn(String.format(LOG_BASE_HEADER_INFO, CRON_JOB, "saveToPPTable", + TableErrorCode.ENTITY_ALREADY_EXISTS + " managed error while storing the table information [organizationFiscalCode="+organizationFiscalCode+", iupd="+pp.getIupd()+"]"), e); tableClient.updateEntity(tableEntity); } else { log.error(String.format(LOG_BASE_HEADER_INFO, CRON_JOB, "saveToPPTable", @@ -145,4 +168,25 @@ private void saveToPPTable(String organizationFiscalCode, PaymentPosition pp, Ob } } } + + private void archivesDebtPositions(List ppList) throws JsonProcessingException { + Map> ppListByOrganizationFiscalCode = ppList.stream() + .collect(Collectors.groupingBy(p -> p.getOrganizationFiscalCode(), Collectors.mapping((PaymentPosition p) -> p, Collectors.toList()))); + + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.registerModule(new JavaTimeModule()); + + for (Entry> entry : ppListByOrganizationFiscalCode.entrySet()) { + List organizationPpList = ppListByOrganizationFiscalCode.get(entry.getKey()); + for (PaymentPosition pp: organizationPpList) { + pp.getPaymentOption().forEach(po -> + // write on azure table storage to persist the PO debt position info + this.saveToPOTable(entry.getKey(), pp, po) + ); + // write on azure table storage to persist the PP debt position info and json + this.saveToPPTable(entry.getKey(), pp, objectMapper); + } + log.info(String.format(LOG_BASE_HEADER_INFO, CRON_JOB, "archivesDebtPositions", "historicized n. "+organizationPpList.size()+" debt positions for the organization fiscal code: " +entry.getKey())); + } + } } diff --git a/src/main/resources/application-h2.properties b/src/main/resources/application-h2.properties index 8690ff3d..414fb54b 100644 --- a/src/main/resources/application-h2.properties +++ b/src/main/resources/application-h2.properties @@ -14,7 +14,7 @@ management.health.readinessState.enabled=true management.metrics.distribution.percentiles.http.server.requests=0.5, 0.9, 0.95, 0.99 # Database settings -spring.datasource.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS APD +spring.datasource.url=jdbc:h2:mem:db;MODE=PostgreSQL;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;INIT=CREATE SCHEMA IF NOT EXISTS APD\\;SET SCHEMA APD\\;CREATE TABLE IF NOT EXISTS APD.shedlock (name VARCHAR(64),lock_until TIMESTAMP(3) NULL,locked_at TIMESTAMP(3) NULL,locked_by VARCHAR(255),PRIMARY KEY (name)) spring.datasource.username=sa spring.datasource.password=sa spring.datasource.driver-class-name=org.h2.Driver @@ -39,6 +39,11 @@ cron.job.schedule.expression.expired.status=*/35 * * * * * cron.job.schedule.historicization.enabled=true cron.job.schedule.expression.historicization.debt.positions=*/55 * * * * * cron.job.schedule.extraction.history.query =SELECT pp FROM PaymentPosition pp WHERE pp.status IN ('PAID', 'REPORTED', 'INVALID', 'EXPIRED') AND pp.lastUpdatedDate < ?1 +cron.job.schedule.extraction.history.query.paginated = true +# The number of records extracted each time the query runs. The parameter is used only if pagination mode is true (default 100.000) +cron.job.schedule.extraction.history.query.page.size = 5 +# The query to get the number of total records to be extracted in paginated mode. The parameter is used only if pagination mode is true +cron.job.schedule.extraction.history.query.count = SELECT count(pp.id) FROM PaymentPosition pp WHERE pp.status IN ('PAID', 'REPORTED', 'INVALID', 'EXPIRED') AND pp.lastUpdatedDate < ?1 # The time, in days, to be subtracted from the current date to decide how old, the debt positions to be historicized, must be (default 365 days) cron.job.schedule.extraction.history.query.interval=0 From f2db73933a71077d7500a4645c1dd247baa3378a Mon Sep 17 00:00:00 2001 From: aacitelli Date: Mon, 12 Feb 2024 11:47:03 +0100 Subject: [PATCH 11/15] rebase 2 --- helm/Chart.yaml | 2 +- helm/values-dev.yaml | 17 +++++++++-- helm/values-prod.yaml | 19 +++++++++++-- helm/values-uat.yaml | 19 +++++++++++-- openapi/openapi_external.json | 2 +- openapi/openapi_external_massive.json | 2 +- openapi/openapi_internal.json | 2 +- openapi/openapi_send.json | 2 +- pom.xml | 41 ++++++++++++++++++++++++++- 9 files changed, 92 insertions(+), 14 deletions(-) diff --git a/helm/Chart.yaml b/helm/Chart.yaml index d0dd5527..3d97c171 100644 --- a/helm/Chart.yaml +++ b/helm/Chart.yaml @@ -3,7 +3,7 @@ name: pagopa-gpd-core description: micro-service to manage Creditor Institution debtor positions type: application version: 0.86.0 -appVersion: 0.11.1-2-PAGOPA-1436-infra-use-dns-pgflex-for-bcdr +appVersion: 0.11.1-1-PAGOPA-1488-renewal-debt-positions dependencies: - name: microservice-chart version: 2.4.0 diff --git a/helm/values-dev.yaml b/helm/values-dev.yaml index bc9f3b1d..65d73bf5 100644 --- a/helm/values-dev.yaml +++ b/helm/values-dev.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-debt-position - tag: "0.11.1-2-PAGOPA-1436-infra-use-dns-pgflex-for-bcdr" + tag: "0.11.1-1-PAGOPA-1488-renewal-debt-positions" pullPolicy: Always livenessProbe: httpGet: @@ -93,6 +93,18 @@ microservice-chart: CRON_JOB_SCHEDULE_ENABLED: "true" CRON_JOB_SCHEDULE_EXPRESSION_TO_VALID: "0 */10 * * * *" CRON_JOB_SCHEDULE_EXPRESSION_TO_EXPIRED: "0 */20 * * * *" + CRON_JOB_SCHEDULE_HISTORY_ENABLED: "true" + CRON_JOB_SCHEDULE_HISTORY_TRIGGER: "0 */30 * * * *" + CRON_JOB_SCHEDULE_HISTORY_QUERY: "SELECT pp FROM PaymentPosition pp WHERE pp.status IN ('PAID', 'REPORTED', 'INVALID', 'EXPIRED') AND pp.lastUpdatedDate < ?1" + CRON_JOB_SCHEDULE_HISTORY_PAGINATED: "true" + CRON_JOB_SCHEDULE_HISTORY_QUERY_COUNT: "SELECT count(pp.id) FROM PaymentPosition pp WHERE pp.status IN ('PAID', 'REPORTED', 'INVALID', 'EXPIRED') AND pp.lastUpdatedDate < ?1" + CRON_JOB_SCHEDULE_HISTORY_QUERY_PAGE_SIZE: "5" + CRON_JOB_SCHEDULE_HISTORY_QUERY_INTERVAL: "7" + CRON_JOB_SCHEDULE_HISTORY_SHEDLOCK_DEFAULTLOCKATMOSTFOR: "5m" + CRON_JOB_SCHEDULE_HISTORY_SHEDLOCK_LOCKATMOSTFOR: "10m" + CRON_JOB_SCHEDULE_HISTORY_SHEDLOCK_LOCKATLEASTFOR: "1m" + GPD_ARCHIVE_SA_PO_TABLE: "paymentoptiontable" + GPD_ARCHIVE_SA_PP_TABLE: "paymentpositiontable" AUX_DIGIT: "3" NODE_HOST: "https://api.dev.platform.pagopa.it" NODE_CHECK_POSITION_PATH: "/nodo/nodo-per-pm/v1/checkPosition" @@ -109,6 +121,7 @@ microservice-chart: SPRING_DATASOURCE_PASSWORD: "db-apd-user-password" SPRING_DATASOURCE_USERNAME: "db-apd-user-name" NODE_SUBSCRIPTION_KEY: "gpd-d-node-subscription-key" + GPD_ARCHIVE_SA_CONNECTION_STRING: "gpd-archive-d-sa-connection-string" keyvault: name: "pagopa-d-gps-kv" tenantId: "7788edaf-0346-4068-9d79-c868aed15b3d" @@ -138,7 +151,7 @@ microservice-chart: create: true image: repository: ghcr.io/pagopa/pagopa-debt-position - tag: "0.11.1-1-PAGOPA-1436-infra-use-dns-pgflex-for-bcdr" + tag: "0.9.0" pullPolicy: Always envConfig: {} envSecret: {} diff --git a/helm/values-prod.yaml b/helm/values-prod.yaml index 9aafcdab..0e77f1ee 100644 --- a/helm/values-prod.yaml +++ b/helm/values-prod.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-debt-position - tag: "0.11.1-2-PAGOPA-1436-infra-use-dns-pgflex-for-bcdr" + tag: "0.11.1-1-PAGOPA-1488-renewal-debt-positions" pullPolicy: Always livenessProbe: httpGet: @@ -85,7 +85,7 @@ microservice-chart: envConfig: WEBSITE_SITE_NAME: 'pagopa-p-gpd-core-service' ENV: 'Azure Kubernetes' - SPRING_DATASOURCE_URL: "jdbc:postgresql://gpd-db.p.internal.postgresql.pagopa.it:6432/apd?sslmode=require&prepareThreshold=0" + SPRING_DATASOURCE_URL: "jdbc:postgresql://pagopa-p-gpd-pgflex.postgres.database.azure.com:6432/apd?sslmode=require&prepareThreshold=0" SPRING_DATASOURCE_TYPE: "org.springframework.jdbc.datasource.SimpleDriverDataSource" SPRING_JPA_HIBERNATE_DDL_AUTO: "validate" SPRING_JPA_HIBERNATE_SHOW_SQL: "false" @@ -93,6 +93,18 @@ microservice-chart: CRON_JOB_SCHEDULE_ENABLED: "true" CRON_JOB_SCHEDULE_EXPRESSION_TO_VALID: "0 */30 * * * *" CRON_JOB_SCHEDULE_EXPRESSION_TO_EXPIRED: "0 */40 * * * *" + CRON_JOB_SCHEDULE_HISTORY_ENABLED: "true" + CRON_JOB_SCHEDULE_HISTORY_TRIGGER: "0 0 2 * * *" + CRON_JOB_SCHEDULE_HISTORY_QUERY: "SELECT pp FROM PaymentPosition pp WHERE pp.status IN ('PAID', 'REPORTED', 'INVALID', 'EXPIRED') AND pp.lastUpdatedDate < ?1" + CRON_JOB_SCHEDULE_HISTORY_PAGINATED: "true" + CRON_JOB_SCHEDULE_HISTORY_QUERY_COUNT: "SELECT count(pp.id) FROM PaymentPosition pp WHERE pp.status IN ('PAID', 'REPORTED', 'INVALID', 'EXPIRED') AND pp.lastUpdatedDate < ?1" + CRON_JOB_SCHEDULE_HISTORY_QUERY_PAGE_SIZE: "100000" + CRON_JOB_SCHEDULE_HISTORY_QUERY_INTERVAL: "365" + CRON_JOB_SCHEDULE_HISTORY_SHEDLOCK_DEFAULTLOCKATMOSTFOR: "5m" + CRON_JOB_SCHEDULE_HISTORY_SHEDLOCK_LOCKATMOSTFOR: "180m" + CRON_JOB_SCHEDULE_HISTORY_SHEDLOCK_LOCKATLEASTFOR: "15m" + GPD_ARCHIVE_SA_PO_TABLE: "paymentoptiontable" + GPD_ARCHIVE_SA_PP_TABLE: "paymentpositiontable" AUX_DIGIT: "3" NODE_HOST: "https://api.platform.pagopa.it/" NODE_CHECK_POSITION_PATH: "/nodo/nodo-per-pm/v1/checkPosition" @@ -109,6 +121,7 @@ microservice-chart: SPRING_DATASOURCE_PASSWORD: "db-apd-user-password" SPRING_DATASOURCE_USERNAME: "db-apd-user-name" NODE_SUBSCRIPTION_KEY: "gpd-p-node-subscription-key" + GPD_ARCHIVE_SA_CONNECTION_STRING: "gpd-archive-p-sa-connection-string" keyvault: name: "pagopa-p-gps-kv" tenantId: "7788edaf-0346-4068-9d79-c868aed15b3d" @@ -147,7 +160,7 @@ microservice-chart: create: true image: repository: ghcr.io/pagopa/pagopa-debt-position - tag: "0.11.1-1-PAGOPA-1436-infra-use-dns-pgflex-for-bcdr" + tag: "0.9.0" pullPolicy: Always envConfig: {} envSecret: {} diff --git a/helm/values-uat.yaml b/helm/values-uat.yaml index c8c7a35f..3049f17d 100644 --- a/helm/values-uat.yaml +++ b/helm/values-uat.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-debt-position - tag: "0.11.1-2-PAGOPA-1436-infra-use-dns-pgflex-for-bcdr" + tag: "0.11.1-1-PAGOPA-1488-renewal-debt-positions" pullPolicy: Always livenessProbe: httpGet: @@ -85,7 +85,7 @@ microservice-chart: envConfig: WEBSITE_SITE_NAME: 'pagopa-u-gpd-core-service' ENV: 'Azure Kubernetes' - SPRING_DATASOURCE_URL: "jdbc:postgresql://gpd-db.u.internal.postgresql.pagopa.it:6432/apd?sslmode=require&prepareThreshold=0" + SPRING_DATASOURCE_URL: "jdbc:postgresql://pagopa-u-gpd-pgflex.postgres.database.azure.com:6432/apd?sslmode=require&prepareThreshold=0" SPRING_DATASOURCE_TYPE: "org.springframework.jdbc.datasource.SimpleDriverDataSource" SPRING_JPA_HIBERNATE_DDL_AUTO: "validate" SPRING_JPA_HIBERNATE_SHOW_SQL: "false" @@ -93,6 +93,18 @@ microservice-chart: CRON_JOB_SCHEDULE_ENABLED: "true" CRON_JOB_SCHEDULE_EXPRESSION_TO_VALID: "0 */10 * * * *" CRON_JOB_SCHEDULE_EXPRESSION_TO_EXPIRED: "0 */20 * * * *" + CRON_JOB_SCHEDULE_HISTORY_ENABLED: "true" + CRON_JOB_SCHEDULE_HISTORY_TRIGGER: "0 */45 * * * *" + CRON_JOB_SCHEDULE_HISTORY_QUERY: "SELECT pp FROM PaymentPosition pp WHERE pp.status IN ('PAID', 'REPORTED', 'INVALID', 'EXPIRED') AND pp.lastUpdatedDate < ?1" + CRON_JOB_SCHEDULE_HISTORY_PAGINATED: "true" + CRON_JOB_SCHEDULE_HISTORY_QUERY_COUNT: "SELECT count(pp.id) FROM PaymentPosition pp WHERE pp.status IN ('PAID', 'REPORTED', 'INVALID', 'EXPIRED') AND pp.lastUpdatedDate < ?1" + CRON_JOB_SCHEDULE_HISTORY_QUERY_PAGE_SIZE: "100000" + CRON_JOB_SCHEDULE_HISTORY_QUERY_INTERVAL: "90" + CRON_JOB_SCHEDULE_HISTORY_SHEDLOCK_DEFAULTLOCKATMOSTFOR: "5m" + CRON_JOB_SCHEDULE_HISTORY_SHEDLOCK_LOCKATMOSTFOR: "30m" + CRON_JOB_SCHEDULE_HISTORY_SHEDLOCK_LOCKATLEASTFOR: "5m" + GPD_ARCHIVE_SA_PO_TABLE: "paymentoptiontable" + GPD_ARCHIVE_SA_PP_TABLE: "paymentpositiontable" AUX_DIGIT: "3" NODE_HOST: "https://api.uat.platform.pagopa.it" NODE_CHECK_POSITION_PATH: "/nodo/nodo-per-pm/v1/checkPosition" @@ -109,6 +121,7 @@ microservice-chart: SPRING_DATASOURCE_PASSWORD: "db-apd-user-password" SPRING_DATASOURCE_USERNAME: "db-apd-user-name" NODE_SUBSCRIPTION_KEY: "gpd-u-node-subscription-key" + GPD_ARCHIVE_SA_CONNECTION_STRING: "gpd-archive-u-sa-connection-string" keyvault: name: "pagopa-u-gps-kv" tenantId: "7788edaf-0346-4068-9d79-c868aed15b3d" @@ -138,7 +151,7 @@ microservice-chart: create: true image: repository: ghcr.io/pagopa/pagopa-debt-position - tag: "0.11.1-1-PAGOPA-1436-infra-use-dns-pgflex-for-bcdr" + tag: "0.9.0" pullPolicy: Always envConfig: {} envSecret: {} diff --git a/openapi/openapi_external.json b/openapi/openapi_external.json index feb0475c..72ded529 100644 --- a/openapi/openapi_external.json +++ b/openapi/openapi_external.json @@ -4,7 +4,7 @@ "title": "PagoPA API Debt Position", "description": "Progetto Gestione Posizioni Debitorie", "termsOfService": "https://www.pagopa.gov.it/", - "version": "0.11.1-2-PAGOPA-1436-infra-use-dns-pgflex-for-bcdr" + "version": "0.11.1-1-PAGOPA-1488-renewal-debt-positions" }, "servers": [ { diff --git a/openapi/openapi_external_massive.json b/openapi/openapi_external_massive.json index 5b04e7e1..2fafb8ba 100644 --- a/openapi/openapi_external_massive.json +++ b/openapi/openapi_external_massive.json @@ -4,7 +4,7 @@ "title": "PagoPA API Debt Position", "description": "Progetto Gestione Posizioni Debitorie", "termsOfService": "https://www.pagopa.gov.it/", - "version": "0.11.1-2-PAGOPA-1436-infra-use-dns-pgflex-for-bcdr" + "version": "0.11.1-1-PAGOPA-1488-renewal-debt-positions" }, "servers": [ { diff --git a/openapi/openapi_internal.json b/openapi/openapi_internal.json index ff553c4f..c018be20 100644 --- a/openapi/openapi_internal.json +++ b/openapi/openapi_internal.json @@ -4,7 +4,7 @@ "title": "PagoPA API Debt Position", "description": "Progetto Gestione Posizioni Debitorie", "termsOfService": "https://www.pagopa.gov.it/", - "version": "0.11.1-2-PAGOPA-1436-infra-use-dns-pgflex-for-bcdr" + "version": "0.11.1-1-PAGOPA-1488-renewal-debt-positions" }, "servers": [ { diff --git a/openapi/openapi_send.json b/openapi/openapi_send.json index f25801fe..5a9409be 100644 --- a/openapi/openapi_send.json +++ b/openapi/openapi_send.json @@ -4,7 +4,7 @@ "title": "PagoPA API Debt Position", "description": "Progetto Gestione Posizioni Debitorie", "termsOfService": "https://www.pagopa.gov.it/", - "version": "0.11.1-2-PAGOPA-1436-infra-use-dns-pgflex-for-bcdr" + "version": "0.11.1-1-PAGOPA-1488-renewal-debt-positions" }, "servers": [ { diff --git a/pom.xml b/pom.xml index c05f0782..4e85d607 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ it.gov.pagopa.debtposition gpd - 0.11.1-2-PAGOPA-1436-infra-use-dns-pgflex-for-bcdr + 0.11.1-1-PAGOPA-1488-renewal-debt-positions Gestione Posizioni Debitorie Progetto Gestione Posizioni Debitorie @@ -21,6 +21,10 @@ 2.13.1 8.5.10 3.1.8 + 12.3.18 + 1.45.1 + 5.10.2 + 5.2.0 @@ -55,6 +59,34 @@ springdoc-openapi-ui ${springdoc-version} + + org.springframework.boot + spring-boot-starter-batch + + + + com.azure + azure-core + ${azure.core.version} + + + com.azure + azure-data-tables + ${azure.data.table.version} + + + + + net.javacrumbs.shedlock + shedlock-spring + ${shedlock.version} + + + net.javacrumbs.shedlock + shedlock-provider-jdbc-template + ${shedlock.version} + + org.springframework.boot spring-boot-devtools @@ -91,6 +123,13 @@ awaitility test + + + org.mockito + mockito-inline + ${mockito-inline.version} + test + org.hibernate.validator hibernate-validator From 709ec6201ad3dcfc31394e63cd9899a32726ddd7 Mon Sep 17 00:00:00 2001 From: pagopa-github-bot Date: Mon, 12 Feb 2024 08:31:42 +0000 Subject: [PATCH 12/15] Bump to version 0.11.1-2-PAGOPA-1488-renewal-debt-positions [skip ci] --- helm/Chart.yaml | 4 ++-- helm/values-dev.yaml | 2 +- helm/values-prod.yaml | 2 +- helm/values-uat.yaml | 2 +- openapi/openapi_external.json | 2 +- openapi/openapi_external_massive.json | 2 +- openapi/openapi_internal.json | 2 +- openapi/openapi_send.json | 2 +- pom.xml | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/helm/Chart.yaml b/helm/Chart.yaml index 3d97c171..32870362 100644 --- a/helm/Chart.yaml +++ b/helm/Chart.yaml @@ -2,8 +2,8 @@ apiVersion: v2 name: pagopa-gpd-core description: micro-service to manage Creditor Institution debtor positions type: application -version: 0.86.0 -appVersion: 0.11.1-1-PAGOPA-1488-renewal-debt-positions +version: 0.87.0 +appVersion: 0.11.1-2-PAGOPA-1488-renewal-debt-positions dependencies: - name: microservice-chart version: 2.4.0 diff --git a/helm/values-dev.yaml b/helm/values-dev.yaml index 65d73bf5..3b5fc886 100644 --- a/helm/values-dev.yaml +++ b/helm/values-dev.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-debt-position - tag: "0.11.1-1-PAGOPA-1488-renewal-debt-positions" + tag: "0.11.1-2-PAGOPA-1488-renewal-debt-positions" pullPolicy: Always livenessProbe: httpGet: diff --git a/helm/values-prod.yaml b/helm/values-prod.yaml index 0e77f1ee..0a19f328 100644 --- a/helm/values-prod.yaml +++ b/helm/values-prod.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-debt-position - tag: "0.11.1-1-PAGOPA-1488-renewal-debt-positions" + tag: "0.11.1-2-PAGOPA-1488-renewal-debt-positions" pullPolicy: Always livenessProbe: httpGet: diff --git a/helm/values-uat.yaml b/helm/values-uat.yaml index 3049f17d..4b8bf118 100644 --- a/helm/values-uat.yaml +++ b/helm/values-uat.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-debt-position - tag: "0.11.1-1-PAGOPA-1488-renewal-debt-positions" + tag: "0.11.1-2-PAGOPA-1488-renewal-debt-positions" pullPolicy: Always livenessProbe: httpGet: diff --git a/openapi/openapi_external.json b/openapi/openapi_external.json index 72ded529..f7668ced 100644 --- a/openapi/openapi_external.json +++ b/openapi/openapi_external.json @@ -4,7 +4,7 @@ "title": "PagoPA API Debt Position", "description": "Progetto Gestione Posizioni Debitorie", "termsOfService": "https://www.pagopa.gov.it/", - "version": "0.11.1-1-PAGOPA-1488-renewal-debt-positions" + "version": "0.11.1-2-PAGOPA-1488-renewal-debt-positions" }, "servers": [ { diff --git a/openapi/openapi_external_massive.json b/openapi/openapi_external_massive.json index 2fafb8ba..3d5da14b 100644 --- a/openapi/openapi_external_massive.json +++ b/openapi/openapi_external_massive.json @@ -4,7 +4,7 @@ "title": "PagoPA API Debt Position", "description": "Progetto Gestione Posizioni Debitorie", "termsOfService": "https://www.pagopa.gov.it/", - "version": "0.11.1-1-PAGOPA-1488-renewal-debt-positions" + "version": "0.11.1-2-PAGOPA-1488-renewal-debt-positions" }, "servers": [ { diff --git a/openapi/openapi_internal.json b/openapi/openapi_internal.json index c018be20..99c3e9f2 100644 --- a/openapi/openapi_internal.json +++ b/openapi/openapi_internal.json @@ -4,7 +4,7 @@ "title": "PagoPA API Debt Position", "description": "Progetto Gestione Posizioni Debitorie", "termsOfService": "https://www.pagopa.gov.it/", - "version": "0.11.1-1-PAGOPA-1488-renewal-debt-positions" + "version": "0.11.1-2-PAGOPA-1488-renewal-debt-positions" }, "servers": [ { diff --git a/openapi/openapi_send.json b/openapi/openapi_send.json index 5a9409be..690d085b 100644 --- a/openapi/openapi_send.json +++ b/openapi/openapi_send.json @@ -4,7 +4,7 @@ "title": "PagoPA API Debt Position", "description": "Progetto Gestione Posizioni Debitorie", "termsOfService": "https://www.pagopa.gov.it/", - "version": "0.11.1-1-PAGOPA-1488-renewal-debt-positions" + "version": "0.11.1-2-PAGOPA-1488-renewal-debt-positions" }, "servers": [ { diff --git a/pom.xml b/pom.xml index 4e85d607..7449fe8c 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ it.gov.pagopa.debtposition gpd - 0.11.1-1-PAGOPA-1488-renewal-debt-positions + 0.11.1-2-PAGOPA-1488-renewal-debt-positions Gestione Posizioni Debitorie Progetto Gestione Posizioni Debitorie From 2c588801bc5321b140f6f49b40a594e6c894f064 Mon Sep 17 00:00:00 2001 From: aacitelli Date: Mon, 12 Feb 2024 11:48:05 +0100 Subject: [PATCH 13/15] rebase 3 --- .../debtposition/config/SchedulerConfig.java | 16 ++++++++++++++++ .../scheduler/HistoricizationScheduler.java | 6 +++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/main/java/it/gov/pagopa/debtposition/config/SchedulerConfig.java b/src/main/java/it/gov/pagopa/debtposition/config/SchedulerConfig.java index 6bd1b6fe..e92bce5d 100644 --- a/src/main/java/it/gov/pagopa/debtposition/config/SchedulerConfig.java +++ b/src/main/java/it/gov/pagopa/debtposition/config/SchedulerConfig.java @@ -1,12 +1,28 @@ package it.gov.pagopa.debtposition.config; + +import javax.sql.DataSource; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableScheduling; +import net.javacrumbs.shedlock.core.LockProvider; +import net.javacrumbs.shedlock.provider.jdbctemplate.JdbcTemplateLockProvider; +import net.javacrumbs.shedlock.spring.annotation.EnableSchedulerLock; + @Configuration @EnableScheduling @EnableAsync +@EnableSchedulerLock(defaultLockAtMostFor = "${cron.job.schedule.history.shedlock.defaultlockatmostfor}") public class SchedulerConfig { + @Value("${spring.jpa.properties.hibernate.default_schema:apd}") + private String defaultSchema; + @Bean + public LockProvider lockProvider(DataSource dataSource) { + return new JdbcTemplateLockProvider(dataSource, defaultSchema+".shedlock"); + } } diff --git a/src/main/java/it/gov/pagopa/debtposition/scheduler/HistoricizationScheduler.java b/src/main/java/it/gov/pagopa/debtposition/scheduler/HistoricizationScheduler.java index ec104d14..7dbb2eea 100644 --- a/src/main/java/it/gov/pagopa/debtposition/scheduler/HistoricizationScheduler.java +++ b/src/main/java/it/gov/pagopa/debtposition/scheduler/HistoricizationScheduler.java @@ -96,7 +96,7 @@ public void manageDebtPositionsToHistoricize() throws JsonProcessingException, T int numOfPages = (int)Math.ceil((float)countResult/pageSize); for (int pageNumber=0; pageNumber ppList) throws JsonProc // write on azure table storage to persist the PP debt position info and json this.saveToPPTable(entry.getKey(), pp, objectMapper); } - log.info(String.format(LOG_BASE_HEADER_INFO, CRON_JOB, "archivesDebtPositions", "historicized n. "+organizationPpList.size()+" debt positions for the organization fiscal code: " +entry.getKey())); + log.debug(String.format(LOG_BASE_HEADER_INFO, CRON_JOB, "archivesDebtPositions", "historicized n. "+organizationPpList.size()+" debt positions for the organization fiscal code: " +entry.getKey())); } } } From 65a390d5c388fe9d23cbddbcd2ffb64d49fefe8b Mon Sep 17 00:00:00 2001 From: pagopa-github-bot Date: Mon, 12 Feb 2024 09:05:15 +0000 Subject: [PATCH 14/15] Bump to version 0.11.1-3-PAGOPA-1488-renewal-debt-positions [skip ci] --- helm/Chart.yaml | 4 ++-- helm/values-dev.yaml | 2 +- helm/values-prod.yaml | 2 +- helm/values-uat.yaml | 2 +- openapi/openapi_external.json | 2 +- openapi/openapi_external_massive.json | 2 +- openapi/openapi_internal.json | 2 +- openapi/openapi_send.json | 2 +- pom.xml | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/helm/Chart.yaml b/helm/Chart.yaml index 32870362..6846adca 100644 --- a/helm/Chart.yaml +++ b/helm/Chart.yaml @@ -2,8 +2,8 @@ apiVersion: v2 name: pagopa-gpd-core description: micro-service to manage Creditor Institution debtor positions type: application -version: 0.87.0 -appVersion: 0.11.1-2-PAGOPA-1488-renewal-debt-positions +version: 0.88.0 +appVersion: 0.11.1-3-PAGOPA-1488-renewal-debt-positions dependencies: - name: microservice-chart version: 2.4.0 diff --git a/helm/values-dev.yaml b/helm/values-dev.yaml index 3b5fc886..70707721 100644 --- a/helm/values-dev.yaml +++ b/helm/values-dev.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-debt-position - tag: "0.11.1-2-PAGOPA-1488-renewal-debt-positions" + tag: "0.11.1-3-PAGOPA-1488-renewal-debt-positions" pullPolicy: Always livenessProbe: httpGet: diff --git a/helm/values-prod.yaml b/helm/values-prod.yaml index 0a19f328..b2bc3579 100644 --- a/helm/values-prod.yaml +++ b/helm/values-prod.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-debt-position - tag: "0.11.1-2-PAGOPA-1488-renewal-debt-positions" + tag: "0.11.1-3-PAGOPA-1488-renewal-debt-positions" pullPolicy: Always livenessProbe: httpGet: diff --git a/helm/values-uat.yaml b/helm/values-uat.yaml index 4b8bf118..138c4939 100644 --- a/helm/values-uat.yaml +++ b/helm/values-uat.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-debt-position - tag: "0.11.1-2-PAGOPA-1488-renewal-debt-positions" + tag: "0.11.1-3-PAGOPA-1488-renewal-debt-positions" pullPolicy: Always livenessProbe: httpGet: diff --git a/openapi/openapi_external.json b/openapi/openapi_external.json index f7668ced..4ec6f328 100644 --- a/openapi/openapi_external.json +++ b/openapi/openapi_external.json @@ -4,7 +4,7 @@ "title": "PagoPA API Debt Position", "description": "Progetto Gestione Posizioni Debitorie", "termsOfService": "https://www.pagopa.gov.it/", - "version": "0.11.1-2-PAGOPA-1488-renewal-debt-positions" + "version": "0.11.1-3-PAGOPA-1488-renewal-debt-positions" }, "servers": [ { diff --git a/openapi/openapi_external_massive.json b/openapi/openapi_external_massive.json index 3d5da14b..1b11a56d 100644 --- a/openapi/openapi_external_massive.json +++ b/openapi/openapi_external_massive.json @@ -4,7 +4,7 @@ "title": "PagoPA API Debt Position", "description": "Progetto Gestione Posizioni Debitorie", "termsOfService": "https://www.pagopa.gov.it/", - "version": "0.11.1-2-PAGOPA-1488-renewal-debt-positions" + "version": "0.11.1-3-PAGOPA-1488-renewal-debt-positions" }, "servers": [ { diff --git a/openapi/openapi_internal.json b/openapi/openapi_internal.json index 99c3e9f2..3744615b 100644 --- a/openapi/openapi_internal.json +++ b/openapi/openapi_internal.json @@ -4,7 +4,7 @@ "title": "PagoPA API Debt Position", "description": "Progetto Gestione Posizioni Debitorie", "termsOfService": "https://www.pagopa.gov.it/", - "version": "0.11.1-2-PAGOPA-1488-renewal-debt-positions" + "version": "0.11.1-3-PAGOPA-1488-renewal-debt-positions" }, "servers": [ { diff --git a/openapi/openapi_send.json b/openapi/openapi_send.json index 690d085b..71e2815b 100644 --- a/openapi/openapi_send.json +++ b/openapi/openapi_send.json @@ -4,7 +4,7 @@ "title": "PagoPA API Debt Position", "description": "Progetto Gestione Posizioni Debitorie", "termsOfService": "https://www.pagopa.gov.it/", - "version": "0.11.1-2-PAGOPA-1488-renewal-debt-positions" + "version": "0.11.1-3-PAGOPA-1488-renewal-debt-positions" }, "servers": [ { diff --git a/pom.xml b/pom.xml index 7449fe8c..73208f49 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ it.gov.pagopa.debtposition gpd - 0.11.1-2-PAGOPA-1488-renewal-debt-positions + 0.11.1-3-PAGOPA-1488-renewal-debt-positions Gestione Posizioni Debitorie Progetto Gestione Posizioni Debitorie From 12b68eb8576f01e8029ddc3fc7fb1cec1d67d2f2 Mon Sep 17 00:00:00 2001 From: pagopa-github-bot Date: Mon, 12 Feb 2024 11:27:17 +0000 Subject: [PATCH 15/15] Bump to version 0.11.1-4-PAGOPA-1488-renewal-debt-positions [skip ci] --- helm/Chart.yaml | 4 ++-- helm/values-dev.yaml | 2 +- helm/values-prod.yaml | 2 +- helm/values-uat.yaml | 2 +- openapi/openapi_external.json | 2 +- openapi/openapi_external_massive.json | 2 +- openapi/openapi_internal.json | 2 +- openapi/openapi_send.json | 2 +- pom.xml | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/helm/Chart.yaml b/helm/Chart.yaml index 6846adca..b5865c8d 100644 --- a/helm/Chart.yaml +++ b/helm/Chart.yaml @@ -2,8 +2,8 @@ apiVersion: v2 name: pagopa-gpd-core description: micro-service to manage Creditor Institution debtor positions type: application -version: 0.88.0 -appVersion: 0.11.1-3-PAGOPA-1488-renewal-debt-positions +version: 0.89.0 +appVersion: 0.11.1-4-PAGOPA-1488-renewal-debt-positions dependencies: - name: microservice-chart version: 2.4.0 diff --git a/helm/values-dev.yaml b/helm/values-dev.yaml index 70707721..3526e836 100644 --- a/helm/values-dev.yaml +++ b/helm/values-dev.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-debt-position - tag: "0.11.1-3-PAGOPA-1488-renewal-debt-positions" + tag: "0.11.1-4-PAGOPA-1488-renewal-debt-positions" pullPolicy: Always livenessProbe: httpGet: diff --git a/helm/values-prod.yaml b/helm/values-prod.yaml index b2bc3579..3f13c150 100644 --- a/helm/values-prod.yaml +++ b/helm/values-prod.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-debt-position - tag: "0.11.1-3-PAGOPA-1488-renewal-debt-positions" + tag: "0.11.1-4-PAGOPA-1488-renewal-debt-positions" pullPolicy: Always livenessProbe: httpGet: diff --git a/helm/values-uat.yaml b/helm/values-uat.yaml index 138c4939..37c579c6 100644 --- a/helm/values-uat.yaml +++ b/helm/values-uat.yaml @@ -4,7 +4,7 @@ microservice-chart: fullnameOverride: "" image: repository: ghcr.io/pagopa/pagopa-debt-position - tag: "0.11.1-3-PAGOPA-1488-renewal-debt-positions" + tag: "0.11.1-4-PAGOPA-1488-renewal-debt-positions" pullPolicy: Always livenessProbe: httpGet: diff --git a/openapi/openapi_external.json b/openapi/openapi_external.json index 4ec6f328..db559d46 100644 --- a/openapi/openapi_external.json +++ b/openapi/openapi_external.json @@ -4,7 +4,7 @@ "title": "PagoPA API Debt Position", "description": "Progetto Gestione Posizioni Debitorie", "termsOfService": "https://www.pagopa.gov.it/", - "version": "0.11.1-3-PAGOPA-1488-renewal-debt-positions" + "version": "0.11.1-4-PAGOPA-1488-renewal-debt-positions" }, "servers": [ { diff --git a/openapi/openapi_external_massive.json b/openapi/openapi_external_massive.json index 1b11a56d..a6cd5de5 100644 --- a/openapi/openapi_external_massive.json +++ b/openapi/openapi_external_massive.json @@ -4,7 +4,7 @@ "title": "PagoPA API Debt Position", "description": "Progetto Gestione Posizioni Debitorie", "termsOfService": "https://www.pagopa.gov.it/", - "version": "0.11.1-3-PAGOPA-1488-renewal-debt-positions" + "version": "0.11.1-4-PAGOPA-1488-renewal-debt-positions" }, "servers": [ { diff --git a/openapi/openapi_internal.json b/openapi/openapi_internal.json index 3744615b..95d26623 100644 --- a/openapi/openapi_internal.json +++ b/openapi/openapi_internal.json @@ -4,7 +4,7 @@ "title": "PagoPA API Debt Position", "description": "Progetto Gestione Posizioni Debitorie", "termsOfService": "https://www.pagopa.gov.it/", - "version": "0.11.1-3-PAGOPA-1488-renewal-debt-positions" + "version": "0.11.1-4-PAGOPA-1488-renewal-debt-positions" }, "servers": [ { diff --git a/openapi/openapi_send.json b/openapi/openapi_send.json index 71e2815b..df2c69da 100644 --- a/openapi/openapi_send.json +++ b/openapi/openapi_send.json @@ -4,7 +4,7 @@ "title": "PagoPA API Debt Position", "description": "Progetto Gestione Posizioni Debitorie", "termsOfService": "https://www.pagopa.gov.it/", - "version": "0.11.1-3-PAGOPA-1488-renewal-debt-positions" + "version": "0.11.1-4-PAGOPA-1488-renewal-debt-positions" }, "servers": [ { diff --git a/pom.xml b/pom.xml index 73208f49..eebd8ccf 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ it.gov.pagopa.debtposition gpd - 0.11.1-3-PAGOPA-1488-renewal-debt-positions + 0.11.1-4-PAGOPA-1488-renewal-debt-positions Gestione Posizioni Debitorie Progetto Gestione Posizioni Debitorie