Skip to content

Commit ed42c4c

Browse files
committed
clean link/match streams & add new cr-link-update http request
2 parents 46567f3 + 8cd3b92 commit ed42c4c

File tree

16 files changed

+98
-33
lines changed

16 files changed

+98
-33
lines changed

JeMPI_Apps/JeMPI_Bootstrapper/src/main/resources/data/postgres/notifications-schema.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ CREATE TABLE IF NOT EXISTS Notification
2626
State VARCHAR(50),
2727
Patient_Id VARCHAR(50),
2828
Names VARCHAR(100),
29-
Golden_Id VARCHAR(50),
29+
Old_Golden_Id VARCHAR(50),
30+
Current_Golden_Id VARCHAR(50),
3031
Score Numeric
3132
);
3233

JeMPI_Apps/JeMPI_Controller/src/main/java/org/jembi/jempi/controller/PsqlNotifications.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ void insert(
2828
final String dID) throws SQLException {
2929

3030
psqlClient.connect(AppConfig.POSTGRESQL_NOTIFICATIONS_DB);
31-
String sql = "INSERT INTO notification (id, type, state, names, created, patient_id, golden_id, score) "
32-
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
31+
String sql = "INSERT INTO notification (id, type, state, names, created, patient_id, old_golden_id, current_golden_id, score) "
32+
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
3333
try (PreparedStatement pstmt = psqlClient.prepareStatement(sql)) {
3434
psqlClient.setAutoCommit(false);
3535
pstmt.setObject(1, id);
@@ -39,7 +39,8 @@ void insert(
3939
pstmt.setTimestamp(5, created);
4040
pstmt.setString(6, dID);
4141
pstmt.setString(7, gID);
42-
pstmt.setFloat(8, score);
42+
pstmt.setString(8, gID);
43+
pstmt.setFloat(9, score);
4344
pstmt.executeUpdate();
4445
} catch (SQLException e) {
4546
LOGGER.error("Error executing INSERT statement: {}", e.getMessage(), e);

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,9 @@ static CompletionStage<BackEnd.PostUpdateNotificationResponse> postUpdateNotific
330330
CompletionStage<BackEnd.PostUpdateNotificationResponse> stage = AskPattern
331331
.ask(backEnd,
332332
replyTo -> new BackEnd.PostUpdateNotificationRequest(replyTo,
333-
notificationRequest.notificationId()),
333+
notificationRequest.notificationId(),
334+
notificationRequest.oldGoldenId(),
335+
notificationRequest.currentGoldenId()),
334336
java.time.Duration.ofSeconds(11),
335337
actorSystem.scheduler());
336338
return stage.thenApply(response -> response);

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,11 @@ private Behavior<Event> getGidsPagedHandler(final GetGidsPagedRequest request) {
433433

434434
private Behavior<Event> postUpdateNotificationHandler(final PostUpdateNotificationRequest request) {
435435
try {
436-
psqlNotifications.updateNotificationState(request.notificationId);
437-
} catch (SQLException exception) {
436+
libMPI.startTransaction();
437+
psqlNotifications.updateNotificationState(request.notificationId, request.oldGoldenId, request.currentGoldenId);
438+
libMPI.sendUpdatedNotificationEvent(request.notificationId, request.oldGoldenId, request.currentGoldenId);
439+
libMPI.closeTransaction();
440+
} catch (SQLException exception) {
438441
LOGGER.error(exception.getMessage());
439442
}
440443
request.replyTo.tell(new PostUpdateNotificationResponse());
@@ -611,7 +614,9 @@ public record PatchIidNewGidLinkResponse(Either<MpiGeneralError, LinkInfo> linkI
611614

612615
public record PostUpdateNotificationRequest(
613616
ActorRef<PostUpdateNotificationResponse> replyTo,
614-
String notificationId) implements Event {
617+
String notificationId,
618+
String oldGoldenId,
619+
String currentGoldenId) implements Event {
615620
}
616621

617622
public record PostUpdateNotificationResponse() implements EventResponse {

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

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ final class PsqlNotifications {
1111

1212
private static final String NOTIFICATION_TABLE_NAME = "notification";
1313
private static final String QUERY = """
14-
SELECT patient_id, id, names, created, state,type, score, golden_id
14+
SELECT patient_id, id, names, created, state,type, score, old_golden_id, current_golden_id
1515
FROM notification
1616
WHERE created BETWEEN ? AND ? AND state IN (?, ?)
1717
ORDER BY created
@@ -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,15 +167,21 @@ void insertCandidates(
166167
}
167168
}
168169

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ private static Route postCrCandidates(
892892
try {
893893
return onComplete(postCrCandidatesProxy(linkerIP, linkerPort, http, obj),
894894
response -> {
895-
if (response.isSuccess()) {
895+
if (!response.isSuccess()) {
896896
LOGGER.warn(IM_A_TEA_POT_LOG);
897897
return complete(ApiModels.getHttpErrorResponse(GlobalConstants.IM_A_TEA_POT));
898898
}

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,4 +371,24 @@ public LinkInfo createInteractionAndLinkToClonedGoldenRecord(
371371
return result;
372372
}
373373

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

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
@@ -83,6 +83,7 @@ public final class GlobalConstants {
8383

8484
public enum AuditEventType {
8585
LINKING_EVENT,
86+
NOTIFICATION_EVENT,
8687
UNKNOWN_EVENT
8788
}
8889

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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
@JsonInclude(JsonInclude.Include.NON_NULL)
77
public record NotificationRequest(
88
@JsonProperty("notificationId") String notificationId,
9-
@JsonProperty("state") String state) {
9+
@JsonProperty("state") String state,
10+
@JsonProperty("oldGoldenId") String oldGoldenId,
11+
@JsonProperty("currentGoldenId") String currentGoldenId) {
1012

1113
}

0 commit comments

Comments
 (0)