-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Accelerator 4] Adding real time event notification #193
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1b84312
Adding real time event notification
3ce2364
Adding realtime event notification
8f40d67
Adding realtime event notification
86e2eaa
Merge remote-tracking branch 'upstream/main' into realtime-4.0.0
c2997c3
Adding realtime notification code
2ac08a7
Merge remote-tracking branch 'upstream/main' into realtime-4.0.0
e406966
fix review comments
Ashi1993 ba4ed70
Adding realtime notification fixes
Ashi1993 00babc1
fixed review comments
Ashi1993 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
144 changes: 144 additions & 0 deletions
144
...nancial/services/accelerator/event/notifications/service/RealtimeNotificationService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
/** | ||
* Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). | ||
* <p> | ||
* WSO2 LLC. licenses this file to you under the Apache License, | ||
* Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.wso2.financial.services.accelerator.event.notifications.service; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.json.JSONException; | ||
import org.wso2.financial.services.accelerator.common.util.DatabaseUtils; | ||
import org.wso2.financial.services.accelerator.event.notifications.service.constants.EventNotificationConstants; | ||
import org.wso2.financial.services.accelerator.event.notifications.service.dao.EventNotificationDAO; | ||
import org.wso2.financial.services.accelerator.event.notifications.service.exception.FSEventNotificationException; | ||
import org.wso2.financial.services.accelerator.event.notifications.service.model.Notification; | ||
import org.wso2.financial.services.accelerator.event.notifications.service.model.NotificationEvent; | ||
import org.wso2.financial.services.accelerator.event.notifications.service.persistence.EventNotificationStoreInitializer; | ||
|
||
import java.sql.Connection; | ||
import java.util.List; | ||
|
||
/** | ||
* Realtime Notification service class. | ||
*/ | ||
public class RealtimeNotificationService { | ||
|
||
private static final Log log = LogFactory.getLog(RealtimeNotificationService.class); | ||
|
||
/** | ||
* Method to retrieve notification by status. | ||
* | ||
* @param status Notification status to retrieve | ||
* @return List of notifications by status | ||
* @throws FSEventNotificationException Exception when retrieving notifications by status | ||
*/ | ||
public List<Notification> getNotificationsByStatus(String status) | ||
throws FSEventNotificationException { | ||
|
||
EventNotificationDAO eventNotificationDAO = EventNotificationStoreInitializer.getEventNotificationDAO(); | ||
|
||
Connection connection = DatabaseUtils.getDBConnection(); | ||
|
||
try { | ||
List<Notification> events = eventNotificationDAO. | ||
getNotificationsByStatus(connection, status); | ||
if (log.isDebugEnabled()) { | ||
log.debug(String.format("Event Notifications with %s status retrieved successfully.", | ||
status.replaceAll("[\r\n]", ""))); | ||
} | ||
DatabaseUtils.commitTransaction(connection); | ||
return events; | ||
} catch (FSEventNotificationException e) { | ||
log.error("Error while retrieving event notification.", e); | ||
DatabaseUtils.rollbackTransaction(connection); | ||
throw new FSEventNotificationException(EventNotificationConstants.ERROR_STORING_EVENT_SUBSCRIPTION, e); | ||
} finally { | ||
log.debug(EventNotificationConstants.DATABASE_CONNECTION_CLOSE_LOG_MSG); | ||
DatabaseUtils.closeConnection(connection); | ||
} | ||
} | ||
|
||
/** | ||
* Method to retrieve notifications by NotificationID. | ||
* | ||
* @param notificationId Notification ID to retrieve | ||
* @return List of notifications by notification ID | ||
* @throws FSEventNotificationException Exception when retrieving notifications by notification ID | ||
*/ | ||
public List<NotificationEvent> getEventsByNotificationID(String notificationId) | ||
throws FSEventNotificationException { | ||
|
||
EventNotificationDAO eventNotificationDAO = EventNotificationStoreInitializer.getEventNotificationDAO(); | ||
|
||
Connection connection = DatabaseUtils.getDBConnection(); | ||
|
||
try { | ||
//store event subscription data in the database | ||
List<NotificationEvent> notificationEvents = eventNotificationDAO. | ||
getEventsByNotificationID(connection, notificationId); | ||
if (log.isDebugEnabled()) { | ||
log.debug(String.format("Event Notifications with notification id %s retrieved successfully.", | ||
notificationId.replaceAll("[\r\n]", ""))); | ||
} | ||
DatabaseUtils.commitTransaction(connection); | ||
return notificationEvents; | ||
} catch (FSEventNotificationException e) { | ||
log.error("Error while retrieving event notification.", e); | ||
DatabaseUtils.rollbackTransaction(connection); | ||
throw new FSEventNotificationException(EventNotificationConstants.ERROR_STORING_EVENT_SUBSCRIPTION, e); | ||
} finally { | ||
log.debug(EventNotificationConstants.DATABASE_CONNECTION_CLOSE_LOG_MSG); | ||
DatabaseUtils.closeConnection(connection); | ||
} | ||
} | ||
|
||
/** | ||
* Method to update the notification status by ID, allowed values are. | ||
* OPEN,ACK and ERR | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if only these values are allowed shouldn't we accept an enum? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FIxed in 00babc1 |
||
* | ||
* @param notificationId Notification ID to update | ||
* @param notificationStatus Notification status to update | ||
* @throws FSEventNotificationException Exception when updating notification status by ID | ||
*/ | ||
public void updateNotificationStatusById(String notificationId, | ||
EventNotificationConstants.EventNotificationStatusEnum notificationStatus) | ||
throws FSEventNotificationException { | ||
|
||
Connection connection = DatabaseUtils.getDBConnection(); | ||
|
||
EventNotificationDAO eventNotificationDAO = EventNotificationStoreInitializer.getEventNotificationDAO(); | ||
|
||
try { | ||
//update the stored event notification | ||
eventNotificationDAO.updateNotificationStatusById(connection, notificationId, | ||
notificationStatus.toString()); | ||
|
||
log.debug("Event Notification updated successfully."); | ||
DatabaseUtils.commitTransaction(connection); | ||
} catch (JSONException e) { | ||
log.error("Error while Parsing the stored request Object", e); | ||
throw new FSEventNotificationException("Error while Parsing the stored request Object", e); | ||
} catch (FSEventNotificationException e) { | ||
log.error("Error while updating event notification.", e); | ||
DatabaseUtils.rollbackTransaction(connection); | ||
throw new FSEventNotificationException(e.getMessage(), e); | ||
} finally { | ||
log.debug(EventNotificationConstants.DATABASE_CONNECTION_CLOSE_LOG_MSG); | ||
DatabaseUtils.closeConnection(connection); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed offline, let's create an issue to remove this dynamic imports line in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created issue #218