diff --git a/mod-audit-server/src/main/java/org/folio/dao/acquisition/impl/PieceEventsDaoImpl.java b/mod-audit-server/src/main/java/org/folio/dao/acquisition/impl/PieceEventsDaoImpl.java index b81e6d6..11c1aed 100644 --- a/mod-audit-server/src/main/java/org/folio/dao/acquisition/impl/PieceEventsDaoImpl.java +++ b/mod-audit-server/src/main/java/org/folio/dao/acquisition/impl/PieceEventsDaoImpl.java @@ -37,15 +37,15 @@ public class PieceEventsDaoImpl implements PieceEventsDao { private static final String TABLE_NAME = "acquisition_piece_log"; private static final String GET_BY_PIECE_ID_SQL = "SELECT id, action, piece_id, user_id, event_date, action_date, modified_content_snapshot, " + " (SELECT count(*) AS total_records FROM %s WHERE piece_id = $1) FROM %s WHERE piece_id = $1 %s LIMIT $2 OFFSET $3"; - private static final String GET_STATUS_CHANGE_HISTORY_BY_PIECE_ID_SQL = - """ - WITH StatusChanges AS (SELECT id, action, piece_id, user_id, event_date, action_date, modified_content_snapshot, - LAG(modified_content_snapshot ->> 'receivingStatus') OVER (PARTITION BY piece_id ORDER BY action_date) AS previous_status - FROM %s WHERE piece_id=$1 + private static final String GET_STATUS_CHANGE_HISTORY_BY_PIECE_ID_SQL = """ + WITH StatusChanges AS ( + SELECT id, action, piece_id, user_id, event_date, action_date, modified_content_snapshot, + LAG(modified_content_snapshot ->> 'receivingStatus') OVER (PARTITION BY piece_id ORDER BY action_date) AS previous_status + FROM %s WHERE piece_id=$1 ) - SELECT id, action, piece_id, user_id, event_date, action_date, modified_content_snapshot, - (SELECT COUNT(*) AS total_records FROM StatusChanges - WHERE modified_content_snapshot ->> 'receivingStatus' <> COALESCE(previous_status, '')) + SELECT id, action, piece_id, user_id, event_date, action_date, modified_content_snapshot, + (SELECT COUNT(*) AS total_records FROM StatusChanges + WHERE modified_content_snapshot ->> 'receivingStatus' <> COALESCE(previous_status, '')) FROM StatusChanges WHERE modified_content_snapshot ->> 'receivingStatus' <> COALESCE(previous_status, '') %s LIMIT $2 OFFSET $3 """;