diff --git a/resident/resident-service/src/main/java/io/mosip/resident/repository/ResidentTransactionRepository.java b/resident/resident-service/src/main/java/io/mosip/resident/repository/ResidentTransactionRepository.java index e7b1f639d5d..da8767efedb 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/repository/ResidentTransactionRepository.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/repository/ResidentTransactionRepository.java @@ -80,15 +80,15 @@ List findByTokenWithoutServiceTypeAndDate(@Param("tok Long countByTokenId(String tokenId); - @Query(value = "SELECT COUNT(*) from ResidentTransactionEntity where tokenId=:tokenId AND read_status='false'") - Long findByIdandcount(@Param("tokenId") String tokenId); + @Query(value = "SELECT COUNT(*) from ResidentTransactionEntity where tokenId=:tokenId AND read_status='false' and requestTypeCode in (:requestTypes)") + Long countByIdAndUnreadStatusForRequestTypes(@Param("tokenId") String tokenId, @Param("requestTypes") List requestTypes); - @Query(value = "SELECT COUNT(*) from ResidentTransactionEntity where tokenId=:tokenId AND crDtimes>= :lastLoginTime AND read_status='false'") - Long findByIdandlastlogincount(@Param("tokenId") String tokenId,@Param("lastLoginTime") LocalDateTime lastLoginTime); + @Query(value = "SELECT COUNT(*) from ResidentTransactionEntity where tokenId=:tokenId AND crDtimes>= :lastLoginTime AND read_status='false' AND requestTypeCode in (:requestTypes)") + Long countByIdAndUnreadStatusForRequestTypesAfterNotificationClick(@Param("tokenId") String tokenId,@Param("lastLoginTime") LocalDateTime lastLoginTime, @Param("requestTypes") List requestTypes); @Query(value = "Select new ResidentTransactionEntity(eventId, requestSummary, statusCode,requestDtimes,requestTypeCode) " - + "from ResidentTransactionEntity where tokenId=:tokenId AND read_status='false'") - List findByIdandStatus(@Param("tokenId") String tokenId); + + "from ResidentTransactionEntity where tokenId=:tokenId AND read_status='false' and requestTypeCode in (:requestTypes)") + List findByIdAndUnreadStatusForRequestTypes(@Param("tokenId") String tokenId, @Param("requestTypes") List requestTypes); @Query(value = "SELECT COUNT(*) from ResidentTransactionEntity where ref_id=:hashrefid AND auth_type_code !='OTP_REQUESTED'") /** diff --git a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ResidentServiceImpl.java b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ResidentServiceImpl.java index 520751cd901..e2f28cfa9cf 100644 --- a/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ResidentServiceImpl.java +++ b/resident/resident-service/src/main/java/io/mosip/resident/service/impl/ResidentServiceImpl.java @@ -255,6 +255,9 @@ public class ResidentServiceImpl implements ResidentService { @Value("${digital.card.pdf.encryption.enabled:false}") private boolean isDigitalCardPdfEncryptionEnabled; + + @Value("#{'${resident.async.request.types}'.split(',')}") + private List asyncRequestTypes; @Autowired private AuditUtil audit; @@ -2061,16 +2064,18 @@ public ResponseWrapper getEventStatus(String eventId, St } @Override - public ResponseWrapper getnotificationCount(String Id) { + public ResponseWrapper getnotificationCount(String id) { ResponseWrapper responseWrapper = new ResponseWrapper<>(); LocalDateTime time = null; Long residentTransactionEntity; - Optional residentUserEntity = residentUserRepository.findById(Id); + Optional residentUserEntity = residentUserRepository.findById(id); if (residentUserEntity.isPresent()) { - time = residentUserEntity.get().getLastloginDtime(); - residentTransactionEntity = residentTransactionRepository.findByIdandlastlogincount(Id, time); + time = residentUserEntity.get().getLastbellnotifDtimes(); + residentTransactionEntity = residentTransactionRepository + .countByIdAndUnreadStatusForRequestTypesAfterNotificationClick(id, time, asyncRequestTypes); } else { - residentTransactionEntity = residentTransactionRepository.findByIdandcount(Id); + residentTransactionEntity = residentTransactionRepository.countByIdAndUnreadStatusForRequestTypes(id, + asyncRequestTypes); } UnreadNotificationDto notification = new UnreadNotificationDto(); notification.setUnreadCount(residentTransactionEntity); @@ -2108,8 +2113,8 @@ public int updatebellClickdttimes(String Id) { } @Override - public ResponseWrapper> getUnreadnotifylist(String Id) { - List result = residentTransactionRepository.findByIdandStatus(Id); + public ResponseWrapper> getUnreadnotifylist(String id) { + List result = residentTransactionRepository.findByIdAndUnreadStatusForRequestTypes(id, asyncRequestTypes); List unreadServiceNotificationDto = new ArrayList<>(); diff --git a/resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentServiceDownloadCardTest.java b/resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentServiceDownloadCardTest.java index b1f86e5a476..cdc31510cd2 100644 --- a/resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentServiceDownloadCardTest.java +++ b/resident/resident-service/src/test/java/io/mosip/resident/test/service/ResidentServiceDownloadCardTest.java @@ -244,7 +244,7 @@ public void testGetUnreadNotifyList(){ residentTransactionEntity1.setStatusCode("200"); residentTransactionEntity1.setRequestDtimes(LocalDateTime.now()); residentTransactionEntity1.setRequestTypeCode("SERVICE_HISTORY"); - Mockito.when(residentTransactionRepository.findByIdandStatus(Mockito.anyString())).thenReturn(List.of(residentTransactionEntity1)); + Mockito.when(residentTransactionRepository.findByIdAndUnreadStatusForRequestTypes(Mockito.anyString(), Mockito.any())).thenReturn(List.of(residentTransactionEntity1)); assertEquals("123", residentServiceImpl.getUnreadnotifylist("123").getResponse().get(0).getEventId()); } @@ -298,7 +298,7 @@ public void testGetnotificationCount(){ UnreadNotificationDto unreadServiceNotificationDto = new UnreadNotificationDto(); unreadServiceNotificationDto.setUnreadCount(4L); responseWrapper.setResponse(unreadServiceNotificationDto); - Mockito.when(residentTransactionRepository.findByIdandcount(Mockito.anyString())).thenReturn(4L); + Mockito.when(residentTransactionRepository.countByIdAndUnreadStatusForRequestTypes(Mockito.anyString(), Mockito.anyList())).thenReturn(4L); assertEquals(Optional. of(4L), Optional.ofNullable(residentServiceImpl. getnotificationCount("123").getResponse().getUnreadCount())); } @@ -316,7 +316,7 @@ public void testGetnotificationCountLastLoginTime(){ residentUserEntity.setLastbellnotifDtimes(LocalDateTime.of(2015, 12, 3, 4, 4, 4)); Optional response = Optional.of(residentUserEntity); Mockito.when(residentUserRepository.findById(Mockito.anyString())).thenReturn(response); - Mockito.when(residentTransactionRepository.findByIdandcount(Mockito.anyString())).thenReturn(4L); + Mockito.when(residentTransactionRepository.countByIdAndUnreadStatusForRequestTypes(Mockito.anyString(), Mockito.anyList())).thenReturn(4L); assertEquals(Optional. of(0L), Optional.ofNullable(residentServiceImpl. getnotificationCount("123").getResponse().getUnreadCount())); }