Skip to content

Commit

Permalink
fixed review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashi1993 committed Dec 11, 2024
1 parent ba4ed70 commit 00babc1
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ public List<NotificationEvent> getEventsByNotificationID(String notificationId)
* @param notificationStatus Notification status to update
* @throws FSEventNotificationException Exception when updating notification status by ID
*/
public void updateNotificationStatusById(String notificationId, String notificationStatus)
public void updateNotificationStatusById(String notificationId,
EventNotificationConstants.EventNotificationStatusEnum notificationStatus)
throws FSEventNotificationException {

Connection connection = DatabaseUtils.getDBConnection();
Expand All @@ -123,7 +124,8 @@ public void updateNotificationStatusById(String notificationId, String notificat

try {
//update the stored event notification
eventNotificationDAO.updateNotificationStatusById(connection, notificationId, notificationStatus);
eventNotificationDAO.updateNotificationStatusById(connection, notificationId,
notificationStatus.toString());

log.debug("Event Notification updated successfully.");
DatabaseUtils.commitTransaction(connection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@

package org.wso2.financial.services.accelerator.event.notifications.service.constants;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;

/**
* Event Notification Constants.
*/
Expand All @@ -31,6 +35,40 @@ public class EventNotificationConstants {
public static final String ERROR = "ERR";
public static final String OPEN = "OPEN";

/**
* Specifies the Schema Names of Debtor Account.
*/
public enum EventNotificationStatusEnum {

ACK("ACK"),

ERROR("ERR"),

OPEN("OPEN");

private final String value;

EventNotificationStatusEnum(String value) {
this.value = value;
}

@Override
public String toString() {
return String.valueOf(value);
}

public static EventNotificationStatusEnum fromValue(String text) {

List<EventNotificationStatusEnum> valueList = Arrays.asList(EventNotificationStatusEnum.values());
Optional<EventNotificationStatusEnum> accountOpt = valueList
.stream()
.filter(i -> String.valueOf(i.value).equals(text))
.findAny();

return accountOpt.orElse(null);
}
}

//Response Status
public static final String NOT_FOUND = "NOTFOUND";
public static final String OK = "OK";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ private void postWithRetry() throws FSEventNotificationException {
notificationId.replaceAll("[\r\n]", "") + " sent successfully");
}
realtimeNotificationService.updateNotificationStatusById(notificationId,
EventNotificationConstants.ACK);
EventNotificationConstants.EventNotificationStatusEnum.ACK);
return;
} else {
if (log.isDebugEnabled()) {
Expand All @@ -191,11 +191,8 @@ private void postWithRetry() throws FSEventNotificationException {
// If the circuit breaker is opened or the maximum retry count is exceeded,
// the notification status will be updated as ERROR.
realtimeNotificationService.updateNotificationStatusById(notificationId,
EventNotificationConstants.ERROR);
} catch (IOException | InterruptedException e) {
log.error("Real-time event notification with notificationId: " +
notificationId.replaceAll("[\r\n]", "") + " sent failed", e);
} catch (FSEventNotificationException e) {
EventNotificationConstants.EventNotificationStatusEnum.ERROR);
} catch (IOException | InterruptedException | FSEventNotificationException e) {
log.error("Real-time event notification with notificationId: " +
notificationId.replaceAll("[\r\n]", "") + " sent failed", e);
}
Expand Down

0 comments on commit 00babc1

Please sign in to comment.