From 1cfe80b8f7dadc3ca7dd16af5a795f6580ae78e1 Mon Sep 17 00:00:00 2001 From: "DIR\\noemi.luongo" Date: Mon, 27 Nov 2023 10:21:27 +0100 Subject: [PATCH] fix counter --- .../pull/service/repository/SignalRepository.java | 11 +++++------ .../signalhub/pull/service/rest/SignalController.java | 6 +++--- .../pull/service/service/impl/SignalServiceImpl.java | 10 ++++------ 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/main/java/it/pagopa/interop/signalhub/pull/service/repository/SignalRepository.java b/src/main/java/it/pagopa/interop/signalhub/pull/service/repository/SignalRepository.java index 0102d29..65af071 100644 --- a/src/main/java/it/pagopa/interop/signalhub/pull/service/repository/SignalRepository.java +++ b/src/main/java/it/pagopa/interop/signalhub/pull/service/repository/SignalRepository.java @@ -10,13 +10,12 @@ @Repository public interface SignalRepository extends ReactiveCrudRepository { - @Query("select * from signal s where s.eservice_id= :eserviceId and s.signal_id BETWEEN :signalIdStart AND :signalIdEnd " + - "order by s.signal_id") - Flux findSignal(String eserviceId, Long signalIdStart, Long signalIdEnd); + @Query("select * from signal s where s.eservice_id= :eserviceId and s.signal_id >= :signalIdStart " + + "order by s.signal_id limit :size") + Flux findSignal(String eserviceId, Long signalIdStart, Long size); - @Query("select max(s.signal_id) from signal s where s.eservice_id= :eserviceId " + - "group by s.eservice_id") - Mono maxSignal(String eserviceId); + @Query("select count (*) from signal s where s.eservice_id= :eserviceId") + Mono countAllSignal(String eserviceId); } diff --git a/src/main/java/it/pagopa/interop/signalhub/pull/service/rest/SignalController.java b/src/main/java/it/pagopa/interop/signalhub/pull/service/rest/SignalController.java index 33d3852..869aab0 100644 --- a/src/main/java/it/pagopa/interop/signalhub/pull/service/rest/SignalController.java +++ b/src/main/java/it/pagopa/interop/signalhub/pull/service/rest/SignalController.java @@ -40,15 +40,15 @@ public Mono> getRequest(String eserviceId, Long return this.signalService.pullSignal(principal.getPrincipalId(), eserviceId, signalId, finalSize) .collectList() .map(list -> ResponseEntity.status(finalStatus) - .body(toPagination(list, principalAndCounter.getT2()))); + .body(toPagination(list))); }); } - private PaginationSignal toPagination(List list, Integer maxSignalId ) { + private PaginationSignal toPagination(List list) { PaginationSignal paginationSignal = new PaginationSignal(); paginationSignal.setSignals(list); - if (list == null || list.isEmpty()) paginationSignal.setLastSignalId(maxSignalId.longValue()-1); + if (list == null || list.isEmpty()) paginationSignal.setLastSignalId(null); else { paginationSignal.setLastSignalId(list.get(list.size()-1).getSignalId()); } diff --git a/src/main/java/it/pagopa/interop/signalhub/pull/service/service/impl/SignalServiceImpl.java b/src/main/java/it/pagopa/interop/signalhub/pull/service/service/impl/SignalServiceImpl.java index 4bc061d..b8f4ce1 100644 --- a/src/main/java/it/pagopa/interop/signalhub/pull/service/service/impl/SignalServiceImpl.java +++ b/src/main/java/it/pagopa/interop/signalhub/pull/service/service/impl/SignalServiceImpl.java @@ -28,19 +28,17 @@ public class SignalServiceImpl implements SignalService { @Override public Flux pullSignal(String consumerId, String eServiceId, Long signalId, Long size) { - long finalSignalId = signalId; - long start = finalSignalId+1; - long end = finalSignalId+size; + long start = signalId+1; return consumerService.getConsumerEservice(eServiceId, consumerId) .switchIfEmpty(Mono.error(new PDNDGenericException(ExceptionTypeEnum.UNAUTHORIZED, ExceptionTypeEnum.UNAUTHORIZED.getMessage().concat(eServiceId), HttpStatus.FORBIDDEN))) .flatMap(consumerEService -> organizationService.getEService(eServiceId, consumerEService.getDescriptorId())) - .doOnNext(eService -> log.info("Searching signals from {} to {}", start, end)) - .flatMapMany(eservice -> signalRepository.findSignal(eServiceId, start, end)) + .doOnNext(eService -> log.info("Searching signals from {} to {}", start, size)) + .flatMapMany(eservice -> signalRepository.findSignal(eServiceId, start, size)) .map(signalMapper::toDto); } public Mono counter(String eServiceId){ - return signalRepository.maxSignal(eServiceId); + return signalRepository.countAllSignal(eServiceId); }