diff --git a/data-service/src/integrationTest/java/uk/gov/laa/ccms/data/repository/NotificationRepositoryIntegrationTest.java b/data-service/src/integrationTest/java/uk/gov/laa/ccms/data/repository/NotificationRepositoryIntegrationTest.java index 31e7c6c..3e17e14 100644 --- a/data-service/src/integrationTest/java/uk/gov/laa/ccms/data/repository/NotificationRepositoryIntegrationTest.java +++ b/data-service/src/integrationTest/java/uk/gov/laa/ccms/data/repository/NotificationRepositoryIntegrationTest.java @@ -4,14 +4,18 @@ import jakarta.persistence.EntityManager; import jakarta.persistence.PersistenceContext; -import java.util.Optional; +import java.time.LocalDate; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.domain.Specification; import org.springframework.test.context.ActiveProfiles; import uk.gov.laa.ccms.data.entity.Notification; +import uk.gov.laa.ccms.data.repository.specification.NotificationSpecification; @DataJpaTest @ActiveProfiles("h2-test") @@ -23,22 +27,338 @@ public class NotificationRepositoryIntegrationTest { @PersistenceContext private EntityManager entityManager; - + + private Notification n1; + private Notification n2; @BeforeEach void setUp() { // Insert test data into the in-memory database - Notification n1 = Notification.builder().notificationId(1L).build(); - Notification n2 = Notification.builder().notificationId(2L).build(); + n1 = Notification.builder().notificationId(1L) + .lscCaseRefReference("1001") + .providerCaseReference("2001") + .assignedTo("JBriggs") + .personFirstName("Jamie") + .personLastName("Briggs") + .feeEarnerPartyId(3001L) + .isOpen(true) + .actionNotificationInd("N") + .dateAssigned(LocalDate.of(2025, 1, 1)) + .build(); + n2 = Notification.builder().notificationId(2L) + .lscCaseRefReference("1002") + .providerCaseReference("2002") + .assignedTo("SMonday") + .personFirstName("Ski") + .personLastName("Bri-Monday") + .feeEarnerPartyId(3002L) + .isOpen(false) + .actionNotificationInd("O") + .dateAssigned(LocalDate.of(2026, 1, 1)) + .build(); // Use entityManager as NotificationRepository extends ReadOnlyRepository. entityManager.persist(n1); entityManager.persist(n2); } @Test - void tempTest(){ - Optional all = notificationRepository.findByNotificationId(1L); + @DisplayName("Should get all Notifications") + void shouldGetAllNotifications(){ + // Given + Specification spec = NotificationSpecification.withFilters( + null, + null, + null, + null, + null, + true, + null, + null, + null); + // When + Page result = notificationRepository.findAll(spec, Pageable.unpaged()); + // Then + assertEquals(2, result.getTotalElements()); + assertEquals(true, result.getContent().contains(n1)); + assertEquals(true, result.getContent().contains(n2)); + } + + @Test + @DisplayName("Should filter by case reference number") + void shouldFilterByCaseReferenceNumber(){ + // Given + Specification spec = NotificationSpecification.withFilters( + "1001", + null, + null, + null, + null, + true, + null, + null, + null); + // When + Page result = notificationRepository.findAll(spec, Pageable.unpaged()); + // Then + assertEquals(1, result.getTotalElements()); + assertEquals(true, result.getContent().contains(n1)); + } + + @Test + @DisplayName("Should filter by similar case reference number") + void shouldFilterBySimilarCaseReferenceNumber(){ + // Given + Specification spec = NotificationSpecification.withFilters( + "100", + null, + null, + null, + null, + true, + null, + null, + null); + // When + Page result = notificationRepository.findAll(spec, Pageable.unpaged()); + // Then + assertEquals(2, result.getTotalElements()); + assertEquals(true, result.getContent().contains(n1)); + assertEquals(true, result.getContent().contains(n2)); + } + + @Test + @DisplayName("Should filter by provider case reference number") + void shouldFilterByProviderCaseReferenceNumber(){ + // Given + Specification spec = NotificationSpecification.withFilters( + null, + "2001", + null, + null, + null, + true, + null, + null, + null); + // When + Page result = notificationRepository.findAll(spec, Pageable.unpaged()); + // Then + assertEquals(1, result.getTotalElements()); + assertEquals(true, result.getContent().contains(n1)); + } + + @Test + @DisplayName("Should filter by similar provider case reference number") + void shouldFilterBySimilarProviderCaseReferenceNumber(){ + // Given + Specification spec = NotificationSpecification.withFilters( + null, + "200", + null, + null, + null, + true, + null, + null, + null); + // When + Page result = notificationRepository.findAll(spec, Pageable.unpaged()); + // Then + assertEquals(2, result.getTotalElements()); + assertEquals(true, result.getContent().contains(n1)); + assertEquals(true, result.getContent().contains(n2)); + } + + @Test + @DisplayName("Should filter by assigned to user ID") + void shouldFilterByAssignedToUserID(){ + // Given + Specification spec = NotificationSpecification.withFilters( + null, + null, + "JBriggs", + null, + null, + true, + null, + null, + null); + // When + Page result = notificationRepository.findAll(spec, Pageable.unpaged()); + // Then + assertEquals(1, result.getTotalElements()); + assertEquals(true, result.getContent().contains(n1)); + } + + @Test + @DisplayName("Should filter by user surname") + void shouldFilterByUserSurname(){ + // Given + Specification spec = NotificationSpecification.withFilters( + null, + null, + null, + "Briggs", + null, + true, + null, + null, + null); + // When + Page result = notificationRepository.findAll(spec, Pageable.unpaged()); + // Then + assertEquals(1, result.getTotalElements()); + assertEquals(true, result.getContent().contains(n1)); + } + + @Test + @DisplayName("Should filter by like user surname") + void shouldFilterByLikeUserSurname(){ + // Given + Specification spec = NotificationSpecification.withFilters( + null, + null, + null, + "Bri", + null, + true, + null, + null, + null); + // When + Page result = notificationRepository.findAll(spec, Pageable.unpaged()); + // Then + assertEquals(2, result.getTotalElements()); + assertEquals(true, result.getContent().contains(n1)); + assertEquals(true, result.getContent().contains(n2)); + } - assertEquals(true, all.isPresent()); + @Test + @DisplayName("Should filter by fee earner ID") + void shouldFilterByFeeEarnerID(){ + // Given + Specification spec = NotificationSpecification.withFilters( + null, + null, + null, + null, + 3001, + true, + null, + null, + null); + // When + Page result = notificationRepository.findAll(spec, Pageable.unpaged()); + // Then + assertEquals(1, result.getTotalElements()); + assertEquals(true, result.getContent().contains(n1)); } + + @Test + @DisplayName("Should filter by notification type") + void shouldFilterByNotificationType(){ + // Given + Specification spec = NotificationSpecification.withFilters( + null, + null, + null, + null, + null, + false, "N", + null, + null); + // When + Page result = notificationRepository.findAll(spec, Pageable.unpaged()); + // Then + assertEquals(1, result.getTotalElements()); + assertEquals(true, result.getContent().contains(n1)); + } + + @Test + @DisplayName("Should filter by date from") + void shouldFilterByDateFrom(){ + // Given + Specification spec = NotificationSpecification.withFilters( + null, + null, + null, + null, + null, + true, + null, + LocalDate.of(2025, 2, 1), + null); + // When + Page result = notificationRepository.findAll(spec, Pageable.unpaged()); + // Then + assertEquals(1, result.getTotalElements()); + assertEquals(true, result.getContent().contains(n2)); + } + + @Test + @DisplayName("Should filter by date from inclusive") + void shouldFilterByDateFromInclusive(){ + // Given + Specification spec = NotificationSpecification.withFilters( + null, + null, + null, + null, + null, + true, + null, + LocalDate.of(2024, 1, 1), + null); + // When + Page result = notificationRepository.findAll(spec, Pageable.unpaged()); + // Then + assertEquals(2, result.getTotalElements()); + assertEquals(true, result.getContent().contains(n1)); + assertEquals(true, result.getContent().contains(n2)); + } + + @Test + @DisplayName("Should filter by date to") + void shouldFilterByDateTo(){ + // Given + Specification spec = NotificationSpecification.withFilters( + null, + null, + null, + null, + null, + true, + null, + null, + LocalDate.of(2025, 12, 1)); + // When + Page result = notificationRepository.findAll(spec, Pageable.unpaged()); + // Then + assertEquals(1, result.getTotalElements()); + assertEquals(true, result.getContent().contains(n1)); + } + + @Test + @DisplayName("Should filter by date to inclusive") + void shouldFilterByDateToInclusive(){ + // Given + Specification spec = NotificationSpecification.withFilters( + null, + null, + null, + null, + null, + true, + null, + null, + LocalDate.of(2026, 1, 1)); + // When + Page result = notificationRepository.findAll(spec, Pageable.unpaged()); + // Then + assertEquals(2, result.getTotalElements()); + assertEquals(true, result.getContent().contains(n1)); + assertEquals(true, result.getContent().contains(n2)); + } + + } diff --git a/data-service/src/main/java/uk/gov/laa/ccms/data/entity/Notification.java b/data-service/src/main/java/uk/gov/laa/ccms/data/entity/Notification.java index 9fceb17..56fa671 100644 --- a/data-service/src/main/java/uk/gov/laa/ccms/data/entity/Notification.java +++ b/data-service/src/main/java/uk/gov/laa/ccms/data/entity/Notification.java @@ -76,39 +76,39 @@ public class Notification { private LocalDate dueDate; @Column(name = "ACTION_NOTIFICATION_IND", length = 150) - String actionNotificationInd; + private String actionNotificationInd; @Column(name = "STATUS", length = 150) - String status; + private String status; @Column(name = "EVIDENCE_ALLOWED_IND", length = 5) - String evidenceAllowedInd; + private String evidenceAllowedInd; - @Column(name = "IS_OPEN", length = 5) - String isOpen; + @Column(name = "IS_OPEN") + private Boolean isOpen; @Column(name = "ASSIGNED_TO_PARTY_ID", precision = 15, scale = 0) - Long assignedToPartyId; + private Long assignedToPartyId; @Column(name = "PERSON_FIRST_NAME", length = 150) - String personFirstName; + private String personFirstName; @Column(name = "PERSON_LAST_NAME", length = 150) - String personLastName; + private String personLastName; @Lob @Column(name = "NOTES") - String notes; + private String notes; @Lob @Column(name = "UPLOADED_DOCUMENTS") - String uploadedDocuments; + private String uploadedDocuments; @Lob @Column(name = "ATTACHED_DOCUMENTS") - String attachedDocuments; + private String attachedDocuments; @Lob @Column(name = "AVAILABLE_RESPONSES") - String availableResponses; + private String availableResponses; } diff --git a/data-service/src/main/java/uk/gov/laa/ccms/data/repository/NotificationRepository.java b/data-service/src/main/java/uk/gov/laa/ccms/data/repository/NotificationRepository.java index 4b9d3c0..28bf337 100644 --- a/data-service/src/main/java/uk/gov/laa/ccms/data/repository/NotificationRepository.java +++ b/data-service/src/main/java/uk/gov/laa/ccms/data/repository/NotificationRepository.java @@ -1,42 +1,13 @@ package uk.gov.laa.ccms.data.repository; -import java.util.Optional; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.stereotype.Repository; import uk.gov.laa.ccms.data.entity.Notification; -/** - * Repository interface for accessing {@link Notification} entities. - * - *

This repository extends the {@link ReadOnlyRepository} interface, it supports - * read-only operations for the {@link Notification} entity, with the priary key of type - * {@link Long}.

- * - * @see Notification - * @see ReadOnlyRepository - * @author Jamie Briggs - */ + @Repository public interface NotificationRepository extends ReadOnlyRepository, JpaSpecificationExecutor { - Optional findByNotificationId(Long notificationId); - /* - *//** - * Retrieves a paginated list of notifications assigned to a specific user. - * - * @param assignedTo the identifier of the user to whom notifications are assigned - * @param pageable the pagination information including page number and size - * @return a paginated list of notifications assigned to the specified user - *//* - Page findByAssignedTo(String assignedTo, Pageable pageable); - - *//** - * Retrieves a paginated list of all notifications. - * - * @param pageable the pagination information including page number, size, and sorting - * @return a paginated list of notifications - *//* - //Page findAll(Pageable pageable);*/ } diff --git a/data-service/src/main/java/uk/gov/laa/ccms/data/repository/specification/NotificationSpecification.java b/data-service/src/main/java/uk/gov/laa/ccms/data/repository/specification/NotificationSpecification.java index d253cfc..2e2e756 100644 --- a/data-service/src/main/java/uk/gov/laa/ccms/data/repository/specification/NotificationSpecification.java +++ b/data-service/src/main/java/uk/gov/laa/ccms/data/repository/specification/NotificationSpecification.java @@ -12,7 +12,7 @@ public class NotificationSpecification { public static Specification withFilters( String caseReferenceNumber, String providerCaseReference, String assignedToUserId, String clientSurname, - Integer feeEarnerId, Boolean includeClosed, String notificationType, LocalDate dateFrom, + Integer feeEarnerId, boolean includeClosed, String notificationType, LocalDate dateFrom, LocalDate dateTo ){ return (root, query, criteriaBuilder) -> { @@ -20,33 +20,31 @@ public static Specification withFilters( // Add predicates for each filter only if they are non-null if (caseReferenceNumber != null) { - predicates.add(criteriaBuilder.equal(root.get("caseReferenceNumber"), caseReferenceNumber)); + predicates.add(criteriaBuilder.like(root.get("lscCaseRefReference"), "%" + caseReferenceNumber + "%")); } if (providerCaseReference != null) { - predicates.add(criteriaBuilder.equal(root.get("providerCaseReference"), providerCaseReference)); + predicates.add(criteriaBuilder.like(root.get("providerCaseReference"), "%" + providerCaseReference + "%")); } if (assignedToUserId != null) { predicates.add(criteriaBuilder.equal(root.get("assignedTo"), assignedToUserId)); } if (clientSurname != null) { - predicates.add(criteriaBuilder.like(root.get("clientName"), "%" + clientSurname + "%")); + predicates.add(criteriaBuilder.like(root.get("personLastName"), "%" + clientSurname + "%")); } if (feeEarnerId != null) { - predicates.add(criteriaBuilder.equal(root.get("feeEarnerId"), feeEarnerId)); + predicates.add(criteriaBuilder.equal(root.get("feeEarnerPartyId"), feeEarnerId)); } - if (includeClosed != null) { - if (!includeClosed) { - predicates.add(criteriaBuilder.isFalse(root.get("isClosed"))); - } + if (!includeClosed) { + predicates.add(criteriaBuilder.isTrue(root.get("isOpen"))); } if (notificationType != null) { - predicates.add(criteriaBuilder.equal(root.get("notificationType"), notificationType)); + predicates.add(criteriaBuilder.equal(root.get("actionNotificationInd"), notificationType)); } if (dateFrom != null) { - predicates.add(criteriaBuilder.greaterThanOrEqualTo(root.get("date"), dateFrom)); + predicates.add(criteriaBuilder.greaterThanOrEqualTo(root.get("dateAssigned"), dateFrom)); } if (dateTo != null) { - predicates.add(criteriaBuilder.lessThanOrEqualTo(root.get("date"), dateTo)); + predicates.add(criteriaBuilder.lessThanOrEqualTo(root.get("dateAssigned"), dateTo)); } // Combine all predicates with AND diff --git a/data-service/src/test/java/uk/gov/laa/ccms/data/mapper/NotificationsMapperImplTest.java b/data-service/src/test/java/uk/gov/laa/ccms/data/mapper/NotificationsMapperImplTest.java index c09c03b..7f9bd1f 100644 --- a/data-service/src/test/java/uk/gov/laa/ccms/data/mapper/NotificationsMapperImplTest.java +++ b/data-service/src/test/java/uk/gov/laa/ccms/data/mapper/NotificationsMapperImplTest.java @@ -54,7 +54,7 @@ void shouldMapSingleNotificationExcludingLobObjects(){ .dueDate(LocalDate.of(2025, 2, 1)) .status("Status") .evidenceAllowedInd("true") - .isOpen("true") + .isOpen(true) .actionNotificationInd("N") .lscCaseRefReference("LSC Case Ref") .providerCaseReference("Provider Case Ref")