Skip to content

Commit

Permalink
CCMSPUI-529 Made provider case reference and surname case-insensitive…
Browse files Browse the repository at this point in the history
… for notification search

Signed-off-by: Jamie Briggs <jamie.briggs@digital.justice.gov.uk>
  • Loading branch information
Jamie Briggs committed Jan 30, 2025
1 parent 36fe9a7 commit 44ed327
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 48 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -79,8 +81,8 @@ void shouldGetAllNotifications(){
Page<Notification> 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
Expand All @@ -101,7 +103,7 @@ void shouldFilterByCaseReferenceNumber(){
Page<Notification> 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
Expand All @@ -122,8 +124,8 @@ void shouldFilterBySimilarCaseReferenceNumber(){
Page<Notification> 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
Expand All @@ -132,7 +134,7 @@ void shouldFilterByProviderCaseReferenceNumber(){
// Given
Specification<Notification> spec = NotificationSpecification.withFilters(
null,
"2001",
"First",
null,
null,
null,
Expand All @@ -144,7 +146,28 @@ void shouldFilterByProviderCaseReferenceNumber(){
Page<Notification> 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<Notification> spec = NotificationSpecification.withFilters(
null,
"FIRST case REF",
null,
null,
null,
true,
null,
null,
null);
// When
Page<Notification> result = notificationRepository.findAll(spec, Pageable.ofSize(10).withPage(0));
// Then
assertEquals(1, result.getTotalElements());
assertTrue(result.getContent().contains(n1));
}

@Test
Expand All @@ -153,7 +176,7 @@ void shouldFilterBySimilarProviderCaseReferenceNumber(){
// Given
Specification<Notification> spec = NotificationSpecification.withFilters(
null,
"200",
"Case Reference",
null,
null,
null,
Expand All @@ -165,8 +188,8 @@ void shouldFilterBySimilarProviderCaseReferenceNumber(){
Page<Notification> 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
Expand All @@ -187,7 +210,7 @@ void shouldFilterByAssignedToUserID(){
Page<Notification> 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
Expand All @@ -208,7 +231,7 @@ void shouldFilterByUserSurname(){
Page<Notification> 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
Expand All @@ -229,8 +252,30 @@ void shouldFilterByLikeUserSurname(){
Page<Notification> 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<Notification> spec = NotificationSpecification.withFilters(
null,
null,
null,
"bri-MONDAY",
null,
true,
null,
null,
null);
// When
Page<Notification> 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
Expand All @@ -251,7 +296,7 @@ void shouldFilterByFeeEarnerID(){
Page<Notification> 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
Expand All @@ -271,7 +316,7 @@ void shouldFilterByNotificationType(){
Page<Notification> 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
Expand All @@ -292,7 +337,7 @@ void shouldFilterByDateFrom(){
Page<Notification> 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
Expand All @@ -313,8 +358,8 @@ void shouldFilterByDateFromInclusive(){
Page<Notification> 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
Expand All @@ -335,7 +380,7 @@ void shouldFilterByDateTo(){
Page<Notification> 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
Expand All @@ -356,8 +401,8 @@ void shouldFilterByDateToInclusive(){
Page<Notification> 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));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
* A utility class for creating specifications to filter and query notifications.
*
* <p>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.</p>
* 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.</p>
*
* <p>The filters include:</p>
* <ul>
Expand All @@ -31,36 +31,40 @@
* <p>This allows querying for notifications based on multiple combinations of these filters,
* with all specified conditions combined.</p>
*
* @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<Notification> withFilters(
String caseReferenceNumber,
Expand All @@ -77,14 +81,16 @@ public static Specification<Notification> 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));
Expand Down

0 comments on commit 44ed327

Please sign in to comment.