Skip to content

Commit ffae04e

Browse files
committed
fixed bug on notifications ui, added audit trail for notification updates
1 parent e51b2f6 commit ffae04e

File tree

9 files changed

+51
-18
lines changed

9 files changed

+51
-18
lines changed

JeMPI_Apps/JeMPI_LibAPI/src/main/java/org/jembi/jempi/libapi/Ask.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ static CompletionStage<BackEnd.PostUpdateNotificationResponse> postUpdateNotific
331331
.ask(backEnd,
332332
replyTo -> new BackEnd.PostUpdateNotificationRequest(replyTo,
333333
notificationRequest.notificationId(),
334+
notificationRequest.oldGoldenId(),
334335
notificationRequest.currentGoldenId()),
335336
java.time.Duration.ofSeconds(11),
336337
actorSystem.scheduler());

JeMPI_Apps/JeMPI_LibAPI/src/main/java/org/jembi/jempi/libapi/BackEnd.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,11 @@ private Behavior<Event> getGidsPagedHandler(final GetGidsPagedRequest request) {
435435

436436
private Behavior<Event> postUpdateNotificationHandler(final PostUpdateNotificationRequest request) {
437437
try {
438+
libMPI.startTransaction();
438439
psqlNotifications.updateNotificationState(request.notificationId, request.currentGoldenId);
439-
} catch (SQLException exception) {
440+
libMPI.sendUpdatedNotificationEvent(request.notificationId, request.oldGoldenId, request.currentGoldenId);
441+
libMPI.closeTransaction();
442+
} catch (SQLException exception) {
440443
LOGGER.error(exception.getMessage());
441444
}
442445
request.replyTo.tell(new PostUpdateNotificationResponse());
@@ -609,6 +612,7 @@ public record PatchIidNewGidLinkResponse(Either<MpiGeneralError, LinkInfo> linkI
609612
public record PostUpdateNotificationRequest(
610613
ActorRef<PostUpdateNotificationResponse> replyTo,
611614
String notificationId,
615+
String oldGoldenId,
612616
String currentGoldenId) implements Event {
613617
}
614618

JeMPI_Apps/JeMPI_LibAPI/src/main/java/org/jembi/jempi/libapi/PsqlNotifications.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ final class PsqlNotifications {
3838
* @param states The state of notification.
3939
* @return A {@link MatchesForReviewResult} object containing the matches and related information.
4040
*/
41+
4142
MatchesForReviewResult getMatchesForReview(
4243
final int limit,
4344
final int offset,
@@ -166,21 +167,20 @@ void insertCandidates(
166167
}
167168
}
168169

169-
void updateNotificationState(
170-
final String notificationId,
171-
final String currentGoldenId) throws SQLException {
170+
void updateNotificationState(final String notificationId, final String currentGoldenId) throws SQLException {
172171
psqlClient.connect();
173-
try (Statement stmt = psqlClient.createStatement()) {
174-
stmt.executeQuery(String.format(Locale.ROOT,
175-
"update notification set state = '%s' where id = '%s'",
176-
"CLOSED",
177-
notificationId));
178-
stmt.executeQuery(String.format(Locale.ROOT,
179-
"update notification set golden_id = '%s' where id = '%s'",
180-
currentGoldenId,
181-
notificationId));
182-
LOGGER.info("Updated notification {} with new currentGoldenId {} ", notificationId, currentGoldenId);
183-
psqlClient.commit();
172+
String sql = String.format(Locale.ROOT, "update notification set state = '%s', golden_id = '%s' where id = '%s'",
173+
"CLOSED",
174+
currentGoldenId,
175+
notificationId);
176+
try (PreparedStatement stmt = psqlClient.prepareStatement(sql)) {
177+
int rowsAffected = stmt.executeUpdate();
178+
if (rowsAffected > 0) {
179+
LOGGER.info("Updated notification {} with new currentGoldenId {}", notificationId, currentGoldenId);
180+
psqlClient.commit();
181+
} else {
182+
LOGGER.warn("Notification with ID {} not found", notificationId);
183+
}
184184
}
185185
}
186186

JeMPI_Apps/JeMPI_LibMPI/src/main/java/org/jembi/jempi/libmpi/LibMPI.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,23 @@ public LinkInfo createInteractionAndLinkToClonedGoldenRecord(
375375
return result;
376376
}
377377

378+
/*
379+
* *****************************************************************************
380+
* *
381+
* Notifications
382+
* *****************************************************************************
383+
* *
384+
*/
385+
386+
public void sendUpdatedNotificationEvent(final String notificationId, final String oldGoldenId, final String currentGoldenId) {
387+
var message = String.format(
388+
"Notification -> new GoldenID: old(%s) new(%s), new State: old(OPEN) new(CLOSED)",
389+
oldGoldenId,
390+
currentGoldenId);
391+
var eventData = new NotificationAuditEventData(message, notificationId);
392+
auditTrailUtil.sendAuditEvent(GlobalConstants.AuditEventType.NOTIFICATION_EVENT, eventData);
393+
}
394+
378395
/*
379396
* *****************************************************************************
380397
* *

JeMPI_Apps/JeMPI_LibShared/src/main/java/org/jembi/jempi/shared/models/GlobalConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public final class GlobalConstants {
8181

8282
public enum AuditEventType {
8383
LINKING_EVENT,
84+
NOTIFICATION_EVENT,
8485
UNKNOWN_EVENT
8586
}
8687

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.jembi.jempi.shared.models;
2+
3+
public record NotificationAuditEventData(
4+
String message,
5+
String notificationId
6+
) {
7+
}

JeMPI_Apps/JeMPI_LibShared/src/main/java/org/jembi/jempi/shared/models/NotificationRequest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
public record NotificationRequest(
88
@JsonProperty("notificationId") String notificationId,
99
@JsonProperty("state") String state,
10+
@JsonProperty("oldGoldenId") String oldGoldenId,
1011
@JsonProperty("currentGoldenId") String currentGoldenId) {
1112

1213
}

JeMPI_Apps/JeMPI_UI/src/components/reviewLink/ReviewLink.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,11 @@ const ReviewLink = () => {
8989
}
9090
})
9191

92-
const updateNotification = (currentGoldenId: string) => {
92+
const updateNotification = (oldGoldenId: string, currentGoldenId: string) => {
9393
mutateNotification.mutate(
9494
{
9595
notificationId: payload?.notificationId,
96+
oldGoldenId: oldGoldenId,
9697
currentGoldenId: currentGoldenId,
9798
},
9899
{
@@ -118,7 +119,7 @@ const ReviewLink = () => {
118119
{
119120
onSuccess: data => {
120121
if (payload?.notificationId) {
121-
updateNotification(goldenRecord ? goldenRecord.uid : '')
122+
updateNotification(id, goldenRecord ? goldenRecord.uid : '')
122123
}
123124
enqueueSnackbar('New record linked', {
124125
variant: 'success'
@@ -154,7 +155,7 @@ const ReviewLink = () => {
154155
{
155156
onSuccess: () => {
156157
if (payload?.notificationId) {
157-
updateNotification(goldenRecord.uid)
158+
updateNotification(id, goldenRecord.uid)
158159
navigate('/notifications')
159160
} else {
160161
navigate(`/record-details/${id}`)

JeMPI_Apps/JeMPI_UI/src/types/BackendResponse.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88

99
export interface NotificationRequest {
1010
notificationId: string
11+
oldGoldenId: string
1112
currentGoldenId: string
1213
}
1314

0 commit comments

Comments
 (0)