Skip to content

Commit

Permalink
CCMSPUI-379 Adding missing sort statement to NotificationSearchReposi…
Browse files Browse the repository at this point in the history
…tory

Signed-off-by: Jamie Briggs <jamie.briggs@digital.justice.gov.uk>
  • Loading branch information
Jamie Briggs committed Feb 12, 2025
1 parent d3ea4a1 commit 2b3374b
Showing 1 changed file with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,18 @@ public Page<NotificationInfo> findAll(final long providerId,

final String searchNotificationQuery =
"""
SELECT * FROM XXCCMS.XXCCMS_GET_NOTIF_INFO_V
"""
+
SELECT * FROM XXCCMS.XXCCMS_GET_NOTIF_INFO_V
"""
+
getFilterSql(providerId, caseReferenceNumber, providerCaseReference,
assignedToUserId, clientSurname, feeEarnerId, includeClosed,
notificationType, assignedDateFrom, assignedDateTo)
+
+
getSortSql(pageable) +
"""
OFFSET :offset ROWS FETCH NEXT :size ROWS ONLY
""";

Query query = entityManager.createNativeQuery(searchNotificationQuery, NotificationInfo.class);
query.setHint("org.hibernate.readOnly", true);
query.setParameter("offset", pageable.getOffset());
Expand Down Expand Up @@ -142,4 +144,15 @@ private static boolean stringNotEmpty(String value) {
return value != null && !value.isEmpty();
}

private static String getSortSql(Pageable pageable) {
if (pageable.getSort().isEmpty()) {
return " ";
}

StringJoiner sortJoiner = new StringJoiner(", ", " ORDER BY ", " ");
pageable.getSort().forEach(order ->
sortJoiner.add(order.getProperty() + " " + order.getDirection().name()));
return sortJoiner.toString();
}

}

0 comments on commit 2b3374b

Please sign in to comment.