From 44ed3278e57bec9a3d194e7d5e63721d6020b844 Mon Sep 17 00:00:00 2001
From: Jamie Briggs
Date: Thu, 30 Jan 2025 14:47:06 +0000
Subject: [PATCH] CCMSPUI-529 Made provider case reference and surname
case-insensitive for notification search
Signed-off-by: Jamie Briggs
---
...NotificationRepositoryIntegrationTest.java | 93 ++++++++++++++-----
.../NotificationSpecification.java | 54 ++++++-----
2 files changed, 99 insertions(+), 48 deletions(-)
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 b9ddeac1..7c78a289 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
@@ -1,6 +1,8 @@
package uk.gov.laa.ccms.data.repository;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
@@ -36,7 +38,7 @@ void setUp() {
// Insert test data into the in-memory database
n1 = Notification.builder().notificationId(1L)
.lscCaseRefReference("1001")
- .providerCaseReference("2001")
+ .providerCaseReference("First Case Reference")
.assignedTo("JBriggs")
.personFirstName("Jamie")
.personLastName("Briggs")
@@ -47,7 +49,7 @@ void setUp() {
.build();
n2 = Notification.builder().notificationId(2L)
.lscCaseRefReference("1002")
- .providerCaseReference("2002")
+ .providerCaseReference("Second Case Reference")
.assignedTo("SMonday")
.personFirstName("Ski")
.personLastName("Bri-Monday")
@@ -79,8 +81,8 @@ void shouldGetAllNotifications(){
Page result = notificationRepository.findAll(spec, Pageable.ofSize(10).withPage(0));
// Then
assertEquals(2, result.getTotalElements());
- assertEquals(true, result.getContent().contains(n1));
- assertEquals(true, result.getContent().contains(n2));
+ assertTrue(result.getContent().contains(n1));
+ assertTrue(result.getContent().contains(n2));
}
@Test
@@ -101,7 +103,7 @@ void shouldFilterByCaseReferenceNumber(){
Page result = notificationRepository.findAll(spec, Pageable.ofSize(10).withPage(0));
// Then
assertEquals(1, result.getTotalElements());
- assertEquals(true, result.getContent().contains(n1));
+ assertTrue(result.getContent().contains(n1));
}
@Test
@@ -122,8 +124,8 @@ void shouldFilterBySimilarCaseReferenceNumber(){
Page result = notificationRepository.findAll(spec, Pageable.ofSize(10).withPage(0));
// Then
assertEquals(2, result.getTotalElements());
- assertEquals(true, result.getContent().contains(n1));
- assertEquals(true, result.getContent().contains(n2));
+ assertTrue(result.getContent().contains(n1));
+ assertTrue(result.getContent().contains(n2));
}
@Test
@@ -132,7 +134,7 @@ void shouldFilterByProviderCaseReferenceNumber(){
// Given
Specification spec = NotificationSpecification.withFilters(
null,
- "2001",
+ "First",
null,
null,
null,
@@ -144,7 +146,28 @@ void shouldFilterByProviderCaseReferenceNumber(){
Page result = notificationRepository.findAll(spec, Pageable.ofSize(10).withPage(0));
// Then
assertEquals(1, result.getTotalElements());
- assertEquals(true, result.getContent().contains(n1));
+ assertTrue(result.getContent().contains(n1));
+ }
+
+ @Test
+ @DisplayName("Should filter by provider case reference number case insensitive")
+ void shouldFilterByProviderCaseReferenceNumberCaseInsensitive(){
+ // Given
+ Specification spec = NotificationSpecification.withFilters(
+ null,
+ "FIRST case REF",
+ null,
+ null,
+ null,
+ true,
+ null,
+ null,
+ null);
+ // When
+ Page result = notificationRepository.findAll(spec, Pageable.ofSize(10).withPage(0));
+ // Then
+ assertEquals(1, result.getTotalElements());
+ assertTrue(result.getContent().contains(n1));
}
@Test
@@ -153,7 +176,7 @@ void shouldFilterBySimilarProviderCaseReferenceNumber(){
// Given
Specification spec = NotificationSpecification.withFilters(
null,
- "200",
+ "Case Reference",
null,
null,
null,
@@ -165,8 +188,8 @@ void shouldFilterBySimilarProviderCaseReferenceNumber(){
Page result = notificationRepository.findAll(spec, Pageable.ofSize(10).withPage(0));
// Then
assertEquals(2, result.getTotalElements());
- assertEquals(true, result.getContent().contains(n1));
- assertEquals(true, result.getContent().contains(n2));
+ assertTrue(result.getContent().contains(n1));
+ assertTrue(result.getContent().contains(n2));
}
@Test
@@ -187,7 +210,7 @@ void shouldFilterByAssignedToUserID(){
Page result = notificationRepository.findAll(spec, Pageable.ofSize(10).withPage(0));
// Then
assertEquals(1, result.getTotalElements());
- assertEquals(true, result.getContent().contains(n1));
+ assertTrue(result.getContent().contains(n1));
}
@Test
@@ -208,7 +231,7 @@ void shouldFilterByUserSurname(){
Page result = notificationRepository.findAll(spec, Pageable.ofSize(10).withPage(0));
// Then
assertEquals(1, result.getTotalElements());
- assertEquals(true, result.getContent().contains(n1));
+ assertTrue(result.getContent().contains(n1));
}
@Test
@@ -229,8 +252,30 @@ void shouldFilterByLikeUserSurname(){
Page result = notificationRepository.findAll(spec, Pageable.ofSize(10).withPage(0));
// Then
assertEquals(2, result.getTotalElements());
- assertEquals(true, result.getContent().contains(n1));
- assertEquals(true, result.getContent().contains(n2));
+ assertTrue(result.getContent().contains(n1));
+ assertTrue(result.getContent().contains(n2));
+ }
+
+ @Test
+ @DisplayName("Should filter by like user surname case insensitive")
+ void shouldFilterByLikeUserSurnameCaseInsensitive(){
+ // Given
+ Specification spec = NotificationSpecification.withFilters(
+ null,
+ null,
+ null,
+ "bri-MONDAY",
+ null,
+ true,
+ null,
+ null,
+ null);
+ // When
+ Page result = notificationRepository.findAll(spec, Pageable.ofSize(10).withPage(0));
+ // Then
+ assertEquals(1, result.getTotalElements());
+ assertFalse(result.getContent().contains(n1));
+ assertTrue(result.getContent().contains(n2));
}
@Test
@@ -251,7 +296,7 @@ void shouldFilterByFeeEarnerID(){
Page result = notificationRepository.findAll(spec, Pageable.ofSize(10).withPage(0));
// Then
assertEquals(1, result.getTotalElements());
- assertEquals(true, result.getContent().contains(n1));
+ assertTrue(result.getContent().contains(n1));
}
@Test
@@ -271,7 +316,7 @@ void shouldFilterByNotificationType(){
Page result = notificationRepository.findAll(spec, Pageable.ofSize(10).withPage(0));
// Then
assertEquals(1, result.getTotalElements());
- assertEquals(true, result.getContent().contains(n1));
+ assertTrue(result.getContent().contains(n1));
}
@Test
@@ -292,7 +337,7 @@ void shouldFilterByDateFrom(){
Page result = notificationRepository.findAll(spec, Pageable.ofSize(10).withPage(0));
// Then
assertEquals(1, result.getTotalElements());
- assertEquals(true, result.getContent().contains(n2));
+ assertTrue(result.getContent().contains(n2));
}
@Test
@@ -313,8 +358,8 @@ void shouldFilterByDateFromInclusive(){
Page result = notificationRepository.findAll(spec, Pageable.ofSize(10).withPage(0));
// Then
assertEquals(2, result.getTotalElements());
- assertEquals(true, result.getContent().contains(n1));
- assertEquals(true, result.getContent().contains(n2));
+ assertTrue(result.getContent().contains(n1));
+ assertTrue(result.getContent().contains(n2));
}
@Test
@@ -335,7 +380,7 @@ void shouldFilterByDateTo(){
Page result = notificationRepository.findAll(spec, Pageable.ofSize(10).withPage(0));
// Then
assertEquals(1, result.getTotalElements());
- assertEquals(true, result.getContent().contains(n1));
+ assertTrue(result.getContent().contains(n1));
}
@Test
@@ -356,8 +401,8 @@ void shouldFilterByDateToInclusive(){
Page result = notificationRepository.findAll(spec, Pageable.ofSize(10).withPage(0));
// Then
assertEquals(2, result.getTotalElements());
- assertEquals(true, result.getContent().contains(n1));
- assertEquals(true, result.getContent().contains(n2));
+ assertTrue(result.getContent().contains(n1));
+ assertTrue(result.getContent().contains(n2));
}
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 e9a59ecb..aef84e7a 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,9 +12,9 @@
* A utility class for creating specifications to filter and query notifications.
*
* The {@link NotificationSpecification} class provides mechanisms to construct dynamic
- * query criteria using the JPA Specification API. It allows filtering of
- * {@link Notification} entities based on various attributes such as case reference number,
- * provider case reference, assigned user, client surname, and more.
+ * query criteria using the JPA Specification API. It allows filtering of {@link Notification}
+ * entities based on various attributes such as case reference number, provider case reference,
+ * assigned user, client surname, and more.
*
* The filters include:
*
@@ -31,36 +31,40 @@
* This allows querying for notifications based on multiple combinations of these filters,
* with all specified conditions combined.
*
+ * @author Jamie Briggs
* @see Notification
* @see Specification
* @see uk.gov.laa.ccms.data.repository.NotificationRepository
- * @author Jamie Briggs
*/
public class NotificationSpecification {
/**
* Private constructor to prevent instantiation of the NotificationSpecification class.
*/
- private NotificationSpecification() {}
+ private NotificationSpecification() {
+ }
/**
- * Builds a {@link Specification} for filtering {@link Notification} entities based
- * on various criteria. The method dynamically constructs filter
- * conditions for the provided filter parameters. Multiple filters are combined using
- * an AND logic.
+ * Builds a {@link Specification} for filtering {@link Notification} entities based on various
+ * criteria. The method dynamically constructs filter conditions for the provided filter
+ * parameters. Multiple filters are combined using an AND logic.
*
- * @param caseReferenceNumber the case reference number to filter by (optional, partial match).
- * @param providerCaseReference the provider case reference to filter
- * by (optional, partial match).
- * @param assignedToUserId the user ID assigned to the notification (optional, exact match).
- * @param clientSurname the client's surname to filter by (optional, partial match).
- * @param feeEarnerId the ID of the fee earner to filter by (optional, exact match).
- * @param includeClosed a flag to include closed notifications in the result set (optional).
- * @param notificationType the type of notification to filter by (optional, exact match).
- * @param dateFrom the starting date for filtering notifications by the date assigned (inclusive).
- * @param dateTo the ending date for filtering notifications by the date assigned (inclusive).
- * @return a {@link Specification} object encapsulating the
- * filtering logic for {@link Notification} entities.
+ * @param caseReferenceNumber the case reference number to filter by (optional, partial match).
+ * @param providerCaseReference the provider case reference to filter by (optional, partial
+ * match, case-insensitive).
+ * @param assignedToUserId the user ID assigned to the notification (optional, exact match).
+ * @param clientSurname the client's surname to filter by (optional, partial match,
+ * case-insensitive).
+ * @param feeEarnerId the ID of the fee earner to filter by (optional, exact match).
+ * @param includeClosed a flag to include closed notifications in the result set
+ * (optional).
+ * @param notificationType the type of notification to filter by (optional, exact match).
+ * @param dateFrom the starting date for filtering notifications by the date assigned
+ * (inclusive).
+ * @param dateTo the ending date for filtering notifications by the date assigned
+ * (inclusive).
+ * @return a {@link Specification} object encapsulating the filtering logic for
+ * {@link Notification} entities.
*/
public static Specification withFilters(
String caseReferenceNumber,
@@ -77,14 +81,16 @@ public static Specification withFilters(
"%" + caseReferenceNumber + "%"));
}
if (stringNotEmpty(providerCaseReference)) {
- predicates.add(criteriaBuilder.like(root.get("providerCaseReference"),
- "%" + providerCaseReference + "%"));
+ predicates.add(
+ criteriaBuilder.like(criteriaBuilder.upper(root.get("providerCaseReference")),
+ "%" + providerCaseReference.toUpperCase() + "%"));
}
if (Objects.nonNull(assignedToUserId)) {
predicates.add(criteriaBuilder.equal(root.get("assignedTo"), assignedToUserId));
}
if (stringNotEmpty(clientSurname)) {
- predicates.add(criteriaBuilder.like(root.get("personLastName"), "%" + clientSurname + "%"));
+ predicates.add(criteriaBuilder.like(criteriaBuilder.upper(root.get("personLastName")),
+ "%" + clientSurname.toUpperCase() + "%"));
}
if (Objects.nonNull(feeEarnerId)) {
predicates.add(criteriaBuilder.equal(root.get("feeEarnerPartyId"), feeEarnerId));