diff --git a/financial-services-accelerator/accelerators/fs-is/carbon-home/dbscripts/financial-services/event-notifications/mssql.sql b/financial-services-accelerator/accelerators/fs-is/carbon-home/dbscripts/financial-services/event-notifications/mssql.sql
index d0c43ab8..58965e86 100644
--- a/financial-services-accelerator/accelerators/fs-is/carbon-home/dbscripts/financial-services/event-notifications/mssql.sql
+++ b/financial-services-accelerator/accelerators/fs-is/carbon-home/dbscripts/financial-services/event-notifications/mssql.sql
@@ -21,7 +21,7 @@
-- Since the database systems does not support adding default unix time to the database columns, the default data
-- storing is handled within the database querieS.
-CREATE TABLE OB_NOTIFICATION (
+CREATE TABLE FS_NOTIFICATION (
NOTIFICATION_ID varchar(36) NOT NULL,
CLIENT_ID varchar(255) NOT NULL,
RESOURCE_ID varchar(255) NOT NULL,
@@ -30,24 +30,24 @@ CREATE TABLE OB_NOTIFICATION (
PRIMARY KEY (NOTIFICATION_ID)
);
-CREATE TABLE OB_NOTIFICATION_EVENT (
+CREATE TABLE FS_NOTIFICATION_EVENT (
EVENT_ID int NOT NULL IDENTITY,
NOTIFICATION_ID varchar(36) NOT NULL,
EVENT_TYPE varchar(200) NOT NULL,
EVENT_INFO varchar(1000) NOT NULL,
PRIMARY KEY (EVENT_ID),
- CONSTRAINT FK_NotificationEvent FOREIGN KEY (NOTIFICATION_ID) REFERENCES OB_NOTIFICATION(NOTIFICATION_ID)
+ CONSTRAINT FK_NotificationEvent FOREIGN KEY (NOTIFICATION_ID) REFERENCES FS_NOTIFICATION(NOTIFICATION_ID)
);
-CREATE TABLE OB_NOTIFICATION_ERROR (
+CREATE TABLE FS_NOTIFICATION_ERROR (
NOTIFICATION_ID varchar(36) NOT NULL,
ERROR_CODE varchar(255) NOT NULL,
DESCRIPTION varchar(255) NOT NULL,
PRIMARY KEY (NOTIFICATION_ID),
- CONSTRAINT FK_NotificationError FOREIGN KEY (NOTIFICATION_ID) REFERENCES OB_NOTIFICATION(NOTIFICATION_ID)
+ CONSTRAINT FK_NotificationError FOREIGN KEY (NOTIFICATION_ID) REFERENCES FS_NOTIFICATION(NOTIFICATION_ID)
);
-CREATE TABLE OB_NOTIFICATION_SUBSCRIPTION (
+CREATE TABLE FS_NOTIFICATION_SUBSCRIPTION (
SUBSCRIPTION_ID varchar(36) NOT NULL,
CLIENT_ID varchar(255) NOT NULL,
REQUEST JSON NOT NULL,
@@ -58,9 +58,9 @@ CREATE TABLE OB_NOTIFICATION_SUBSCRIPTION (
PRIMARY KEY (SUBSCRIPTION_ID)
);
-CREATE TABLE OB_NOTIFICATION_SUBSCRIBED_EVENTS (
+CREATE TABLE FS_NOTIFICATION_SUBSCRIBED_EVENTS (
SUBSCRIPTION_ID varchar(36) NOT NULL,
EVENT_TYPE varchar(255) NOT NULL,
PRIMARY KEY (SUBSCRIPTION_ID, EVENT_TYPE),
- CONSTRAINT FK_NotificationSubEvents FOREIGN KEY (SUBSCRIPTION_ID) REFERENCES OB_NOTIFICATION_SUBSCRIPTION(SUBSCRIPTION_ID)
+ CONSTRAINT FK_NotificationSubEvents FOREIGN KEY (SUBSCRIPTION_ID) REFERENCES FS_NOTIFICATION_SUBSCRIPTION(SUBSCRIPTION_ID)
);
diff --git a/financial-services-accelerator/accelerators/fs-is/carbon-home/dbscripts/financial-services/event-notifications/mysql.sql b/financial-services-accelerator/accelerators/fs-is/carbon-home/dbscripts/financial-services/event-notifications/mysql.sql
index 30201693..4cce33d9 100644
--- a/financial-services-accelerator/accelerators/fs-is/carbon-home/dbscripts/financial-services/event-notifications/mysql.sql
+++ b/financial-services-accelerator/accelerators/fs-is/carbon-home/dbscripts/financial-services/event-notifications/mysql.sql
@@ -23,7 +23,7 @@
-- For event notifications feature run the following queries against the openbank_openbankingdb--
-CREATE TABLE IF NOT EXISTS OB_NOTIFICATION (
+CREATE TABLE IF NOT EXISTS FS_NOTIFICATION (
NOTIFICATION_ID varchar(36) NOT NULL,
CLIENT_ID varchar(255) NOT NULL,
RESOURCE_ID varchar(255) NOT NULL,
@@ -33,26 +33,26 @@ CREATE TABLE IF NOT EXISTS OB_NOTIFICATION (
)
ENGINE=InnoDB;
-CREATE TABLE IF NOT EXISTS OB_NOTIFICATION_EVENT (
+CREATE TABLE IF NOT EXISTS FS_NOTIFICATION_EVENT (
EVENT_ID int(11) NOT NULL AUTO_INCREMENT,
NOTIFICATION_ID varchar(36) NOT NULL,
EVENT_TYPE varchar(200) NOT NULL,
EVENT_INFO varchar(1000) NOT NULL,
PRIMARY KEY (EVENT_ID),
- CONSTRAINT FK_NotificationEvent FOREIGN KEY (NOTIFICATION_ID) REFERENCES OB_NOTIFICATION(NOTIFICATION_ID)
+ CONSTRAINT FK_NotificationEvent FOREIGN KEY (NOTIFICATION_ID) REFERENCES FS_NOTIFICATION(NOTIFICATION_ID)
)
ENGINE=InnoDB;
-CREATE TABLE IF NOT EXISTS OB_NOTIFICATION_ERROR (
+CREATE TABLE IF NOT EXISTS FS_NOTIFICATION_ERROR (
NOTIFICATION_ID varchar(36) NOT NULL,
ERROR_CODE varchar(255) NOT NULL,
DESCRIPTION varchar(255) NOT NULL,
PRIMARY KEY (NOTIFICATION_ID),
- CONSTRAINT FK_NotificationError FOREIGN KEY (NOTIFICATION_ID) REFERENCES OB_NOTIFICATION(NOTIFICATION_ID)
+ CONSTRAINT FK_NotificationError FOREIGN KEY (NOTIFICATION_ID) REFERENCES FS_NOTIFICATION(NOTIFICATION_ID)
)
ENGINE=InnoDB;
-CREATE TABLE IF NOT EXISTS OB_NOTIFICATION_SUBSCRIPTION (
+CREATE TABLE IF NOT EXISTS FS_NOTIFICATION_SUBSCRIPTION (
SUBSCRIPTION_ID varchar(36) NOT NULL,
CLIENT_ID varchar(255) NOT NULL,
REQUEST JSON NOT NULL,
@@ -64,10 +64,10 @@ CREATE TABLE IF NOT EXISTS OB_NOTIFICATION_SUBSCRIPTION (
)
ENGINE=InnoDB;
-CREATE TABLE IF NOT EXISTS OB_NOTIFICATION_SUBSCRIBED_EVENTS (
+CREATE TABLE IF NOT EXISTS FS_NOTIFICATION_SUBSCRIBED_EVENTS (
SUBSCRIPTION_ID varchar(36) NOT NULL,
EVENT_TYPE varchar(255) NOT NULL,
PRIMARY KEY (SUBSCRIPTION_ID, EVENT_TYPE),
- CONSTRAINT FK_NotificationSubEvents FOREIGN KEY (SUBSCRIPTION_ID) REFERENCES OB_NOTIFICATION_SUBSCRIPTION(SUBSCRIPTION_ID)
+ CONSTRAINT FK_NotificationSubEvents FOREIGN KEY (SUBSCRIPTION_ID) REFERENCES FS_NOTIFICATION_SUBSCRIPTION(SUBSCRIPTION_ID)
)
ENGINE=InnoDB;
diff --git a/financial-services-accelerator/accelerators/fs-is/carbon-home/dbscripts/financial-services/event-notifications/oracle.sql b/financial-services-accelerator/accelerators/fs-is/carbon-home/dbscripts/financial-services/event-notifications/oracle.sql
index 26a374e4..0d5341ea 100644
--- a/financial-services-accelerator/accelerators/fs-is/carbon-home/dbscripts/financial-services/event-notifications/oracle.sql
+++ b/financial-services-accelerator/accelerators/fs-is/carbon-home/dbscripts/financial-services/event-notifications/oracle.sql
@@ -19,9 +19,9 @@
-- All the data related to time are stored in unix time stamp and therefore, the data types for the time related data
-- are represented in BIGINT.
-- Since the database systems does not support adding default unix time to the database columns, the default data
--- storing is handled within the database querieS.
+-- storing is handled within the database queries.
-CREATE TABLE OB_NOTIFICATION (
+CREATE TABLE FS_NOTIFICATION (
NOTIFICATION_ID varchar2(36) NOT NULL,
CLIENT_ID varchar2(255) NOT NULL,
RESOURCE_ID varchar2(255) NOT NULL,
@@ -30,34 +30,34 @@ CREATE TABLE OB_NOTIFICATION (
PRIMARY KEY (NOTIFICATION_ID)
);
-CREATE TABLE OB_NOTIFICATION_EVENT (
+CREATE TABLE FS_NOTIFICATION_EVENT (
EVENT_ID number(10) NOT NULL,
NOTIFICATION_ID varchar2(36) NOT NULL,
EVENT_TYPE varchar2(200) NOT NULL,
EVENT_INFO varchar2(1000) NOT NULL,
PRIMARY KEY (EVENT_ID),
- CONSTRAINT FK_NotificationEvent FOREIGN KEY (NOTIFICATION_ID) REFERENCES OB_NOTIFICATION(NOTIFICATION_ID)
+ CONSTRAINT FK_NotificationEvent FOREIGN KEY (NOTIFICATION_ID) REFERENCES FS_NOTIFICATION(NOTIFICATION_ID)
);
-- Generate ID using sequence and trigger
-CREATE SEQUENCE OB_NOTIFICATION_EVENT_seq START WITH 1 INCREMENT BY 1;
+CREATE SEQUENCE FS_NOTIFICATION_EVENT_seq START WITH 1 INCREMENT BY 1;
-CREATE OR REPLACE TRIGGER OB_NOTIFICATION_EVENT_seq_tr
- BEFORE INSERT ON OB_NOTIFICATION_EVENT FOR EACH ROW
+CREATE OR REPLACE TRIGGER FS_NOTIFICATION_EVENT_seq_tr
+ BEFORE INSERT ON FS_NOTIFICATION_EVENT FOR EACH ROW
WHEN (NEW.EVENT_ID IS NULL)
BEGIN
- SELECT OB_NOTIFICATION_EVENT_seq.NEXTVAL INTO :NEW.EVENT_ID FROM DUAL;
+ SELECT FS_NOTIFICATION_EVENT_seq.NEXTVAL INTO :NEW.EVENT_ID FROM DUAL;
END;
-CREATE TABLE OB_NOTIFICATION_ERROR (
+CREATE TABLE FS_NOTIFICATION_ERROR (
NOTIFICATION_ID varchar2(36) NOT NULL,
ERROR_CODE varchar2(255) NOT NULL,
DESCRIPTION varchar2(255) NOT NULL,
PRIMARY KEY (NOTIFICATION_ID),
- CONSTRAINT FK_NotificationError FOREIGN KEY (NOTIFICATION_ID) REFERENCES OB_NOTIFICATION(NOTIFICATION_ID)
+ CONSTRAINT FK_NotificationError FOREIGN KEY (NOTIFICATION_ID) REFERENCES FS_NOTIFICATION(NOTIFICATION_ID)
)
-CREATE TABLE OB_NOTIFICATION_SUBSCRIPTION (
+CREATE TABLE FS_NOTIFICATION_SUBSCRIPTION (
SUBSCRIPTION_ID varchar(36) NOT NULL,
CLIENT_ID varchar(255) NOT NULL,
REQUEST JSON NOT NULL,
@@ -68,9 +68,9 @@ CREATE TABLE OB_NOTIFICATION_SUBSCRIPTION (
PRIMARY KEY (SUBSCRIPTION_ID)
);
-CREATE TABLE OB_NOTIFICATION_SUBSCRIBED_EVENTS (
+CREATE TABLE FS_NOTIFICATION_SUBSCRIBED_EVENTS (
SUBSCRIPTION_ID varchar(36) NOT NULL,
EVENT_TYPE varchar(255) NOT NULL,
PRIMARY KEY (SUBSCRIPTION_ID, EVENT_TYPE),
- CONSTRAINT FK_NotificationSubEvents FOREIGN KEY (SUBSCRIPTION_ID) REFERENCES OB_NOTIFICATION_SUBSCRIPTION(SUBSCRIPTION_ID)
+ CONSTRAINT FK_NotificationSubEvents FOREIGN KEY (SUBSCRIPTION_ID) REFERENCES FS_NOTIFICATION_SUBSCRIPTION(SUBSCRIPTION_ID)
);
diff --git a/financial-services-accelerator/accelerators/fs-is/carbon-home/dbscripts/financial-services/event-notifications/postgresql.sql b/financial-services-accelerator/accelerators/fs-is/carbon-home/dbscripts/financial-services/event-notifications/postgresql.sql
index 86d3d7c3..629230ff 100644
--- a/financial-services-accelerator/accelerators/fs-is/carbon-home/dbscripts/financial-services/event-notifications/postgresql.sql
+++ b/financial-services-accelerator/accelerators/fs-is/carbon-home/dbscripts/financial-services/event-notifications/postgresql.sql
@@ -23,7 +23,7 @@
-- For event notifications feature run the following queries against the openbank_openbankingdb--
-CREATE TABLE IF NOT EXISTS OB_NOTIFICATION (
+CREATE TABLE IF NOT EXISTS FS_NOTIFICATION (
NOTIFICATION_ID varchar(36) NOT NULL,
CLIENT_ID varchar(255) NOT NULL,
RESOURCE_ID varchar(255) NOT NULL,
@@ -32,23 +32,23 @@ CREATE TABLE IF NOT EXISTS OB_NOTIFICATION (
PRIMARY KEY (NOTIFICATION_ID)
);
-CREATE TABLE IF NOT EXISTS OB_NOTIFICATION_EVENT (
+CREATE TABLE IF NOT EXISTS FS_NOTIFICATION_EVENT (
EVENT_ID SERIAL PRIMARY KEY,
NOTIFICATION_ID varchar(36) NOT NULL,
EVENT_TYPE varchar(200) NOT NULL,
EVENT_INFO varchar(1000) NOT NULL,
- CONSTRAINT FK_NotificationEvent FOREIGN KEY (NOTIFICATION_ID) REFERENCES OB_NOTIFICATION(NOTIFICATION_ID)
+ CONSTRAINT FK_NotificationEvent FOREIGN KEY (NOTIFICATION_ID) REFERENCES FS_NOTIFICATION(NOTIFICATION_ID)
);
-CREATE TABLE IF NOT EXISTS OB_NOTIFICATION_ERROR (
+CREATE TABLE IF NOT EXISTS FS_NOTIFICATION_ERROR (
NOTIFICATION_ID varchar(36) NOT NULL,
ERROR_CODE varchar(255) NOT NULL,
DESCRIPTION varchar(255) NOT NULL,
PRIMARY KEY (NOTIFICATION_ID),
- CONSTRAINT FK_NotificationError FOREIGN KEY (NOTIFICATION_ID) REFERENCES OB_NOTIFICATION(NOTIFICATION_ID)
+ CONSTRAINT FK_NotificationError FOREIGN KEY (NOTIFICATION_ID) REFERENCES FS_NOTIFICATION(NOTIFICATION_ID)
);
-CREATE TABLE IF NOT EXISTS OB_NOTIFICATION_SUBSCRIPTION (
+CREATE TABLE IF NOT EXISTS FS_NOTIFICATION_SUBSCRIPTION (
SUBSCRIPTION_ID varchar(36) NOT NULL,
CLIENT_ID varchar(255) NOT NULL,
REQUEST JSON NOT NULL,
@@ -59,9 +59,9 @@ CREATE TABLE IF NOT EXISTS OB_NOTIFICATION_SUBSCRIPTION (
PRIMARY KEY (SUBSCRIPTION_ID)
);
-CREATE TABLE IF NOT EXISTS OB_NOTIFICATION_SUBSCRIBED_EVENTS (
+CREATE TABLE IF NOT EXISTS FS_NOTIFICATION_SUBSCRIBED_EVENTS (
SUBSCRIPTION_ID varchar(36) NOT NULL,
EVENT_TYPE varchar(255) NOT NULL,
PRIMARY KEY (SUBSCRIPTION_ID, EVENT_TYPE),
- CONSTRAINT FK_NotificationSubEvents FOREIGN KEY (SUBSCRIPTION_ID) REFERENCES OB_NOTIFICATION_SUBSCRIPTION(SUBSCRIPTION_ID)
+ CONSTRAINT FK_NotificationSubEvents FOREIGN KEY (SUBSCRIPTION_ID) REFERENCES FS_NOTIFICATION_SUBSCRIPTION(SUBSCRIPTION_ID)
);
diff --git a/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/pom.xml b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/pom.xml
new file mode 100644
index 00000000..d1826979
--- /dev/null
+++ b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/pom.xml
@@ -0,0 +1,214 @@
+
+
+ * 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 + *
+ * http://www.apache.org/licenses/LICENSE-2.0 + *
+ * 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.constants; + +/** + * Event Notification Constants. + */ +public class EventNotificationConstants { + + //Service level constants + public static final String X_WSO2_CLIENT_ID = "x-wso2-client_id"; + + //Event Notification Status + public static final String ACK = "ACK"; + public static final String ERROR = "ERR"; + public static final String OPEN = "OPEN"; + + //Response Status + public static final String NOT_FOUND = "NOTFOUND"; + public static final String OK = "OK"; + public static final String CREATED = "CREATED"; + public static final String BAD_REQUEST = "BADREQUEST"; + public static final String NO_CONTENT = "NO_CONTENT"; + public static final String INTERNAL_SERVER_ERROR = "INTERNAL_SERVER_ERROR"; + //Database columns + public static final String NOTIFICATION_ID = "NOTIFICATION_ID"; + public static final String CLIENT_ID = "CLIENT_ID"; + public static final String RESOURCE_ID = "RESOURCE_ID"; + public static final String STATUS = "STATUS"; + public static final String UPDATED_TIMESTAMP = "UPDATED_TIMESTAMP"; + public static final String EVENT_INFO = "EVENT_INFO"; + public static final String EVENT_TYPE = "EVENT_TYPE"; + public static final String SUBSCRIPTION_ID = "SUBSCRIPTION_ID"; + public static final String CALLBACK_URL = "CALLBACK_URL"; + public static final String TIME_STAMP = "TIMESTAMP"; + public static final String SPEC_VERSION = "SPEC_VERSION"; + public static final String REQUEST = "REQUEST"; + + //Error Constants + public static final String INVALID_REQUEST = "invalid_request"; + public static final String EVENT_NOTIFICATION_CREATION_ERROR = "Error occurred while saving event " + + "notifications in the database"; + public static final String MISSING_REQ_PAYLOAD = "No request payload found"; + public static final String MISSING_HEADER_PARAM_CLIENT_ID = "Missing header x-wso2-client_id"; + public static final String MISSING_HEADER_PARAM_RESOURCE_ID = "Missing header x-wso2-resource_id"; + public static final String ERROR_IN_EVENT_POLLING_REQUEST = "Error in event polling request"; + public static final String INVALID_CHARS_IN_HEADER_ERROR = "Invalid characters found in the request headers"; + + //Polling request params + public static final String SET_ERRORS = "setErrs"; + public static final String MAX_EVENTS = "maxEvents"; + public static final String DESCRIPTION = "description"; + public static final String RETURN_IMMEDIATELY = "returnImmediately"; + + //Polling response params + public static final String SETS = "sets"; + public static final String MORE_AVAILABLE = "moreAvailable"; + public static final String NOTIFICATIONS_ID = "notificationsID"; + + // Event Subscription Request Params + public static final String SUBSCRIPTION_ID_PARAM = "subscriptionId"; + public static final String CALLBACK_URL_PARAM = "callbackUrl"; + public static final String VERSION_PARAM = "version"; + public static final String EVENT_TYPE_PARAM = "eventTypes"; + public static final String DATA_PARAM = "data"; + + public static final String DB_ERROR_UPDATING = "Database error while updating notification with ID : " + + "'%s' in the database. "; + public static final String DB_ERROR_NOTIFICATION_RETRIEVE = "Error occurred while retrieving" + + " notifications for client ID : '%s'."; + public static final String DB_FAILED_ERROR_NOTIFICATION_STORING = "Failed to store error notification with ID : "; + public static final String DB_ERROR_STORING_ERROR_NOTIFICATION = "Error occurred while closing the " + + "event-notification database connection"; + public static final String DB_ERROR_EVENTS_RETRIEVE = "Error occurred while retrieving events for" + + " notifications ID : '%s'."; + public static final String PARSE_ERROR_NOTIFICATION_ID = "Error occurred while parsing events for" + + " notifications ID : '%s'."; + public static final String DB_CONN_ESTABLISHED = "Database connection is established to get notification " + + "for client ID : '%s' in the database. "; + public static final String RETRIEVED_NOTIFICATION_CLIENT = "Retrieved notification for client ID: '%s'. "; + + public static final String RETRIEVED_EVENTS_NOTIFICATION = "Retrieved events for notification ID: '%s'. "; + public static final String NO_NOTIFICATIONS_FOUND_CLIENT = "No notifications found for client ID - '%s'"; + public static final String NO_EVENTS_NOTIFICATION_ID = "No events found for notification ID - '%s'"; + public static final String INVALID_CLIENT_ID = "Invalid mandatory parameter x-wso2-client-id."; + public static final String DATABASE_CONNECTION_CLOSE_LOG_MSG = "Closing database connection"; + + public static final String ERROR_STORING_EVENT_SUBSCRIPTION = "Error occurred while storing event " + + "subscription in the database. "; + public static final String ERROR_UPDATING_EVENT_SUBSCRIPTION = "Error occurred while updating event " + + "subscription in the database. "; + public static final String ERROR_RETRIEVING_EVENT_SUBSCRIPTION = "Error occurred while retrieving event " + + "subscription in the database. "; + public static final String ERROR_RETRIEVING_EVENT_SUBSCRIPTIONS = "Error occurred while retrieving event " + + "subscriptions in the database."; + public static final String ERROR_DELETING_EVENT_SUBSCRIPTION = "Error occurred while deleting event " + + "subscription in the database. "; + public static final String EVENT_SUBSCRIPTION_NOT_FOUND = "Event subscription not found."; + public static final String EVENT_SUBSCRIPTIONS_NOT_FOUND = "Event subscriptions not found for the given client id."; + public static final String ERROR_HANDLING_EVENT_SUBSCRIPTION = "Error occurred while handling the event " + + "subscription request"; +} diff --git a/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/dao/EventNotificationDAO.java b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/dao/EventNotificationDAO.java new file mode 100644 index 00000000..d195a96d --- /dev/null +++ b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/dao/EventNotificationDAO.java @@ -0,0 +1,127 @@ +/** + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). + *
+ * 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 + *
+ * http://www.apache.org/licenses/LICENSE-2.0 + *
+ * 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.dao;
+
+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.NotificationError;
+import org.wso2.financial.services.accelerator.event.notifications.service.model.NotificationEvent;
+
+import java.sql.Connection;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Event Publisher DAO interface.
+ */
+public interface EventNotificationDAO {
+
+ /**
+ * This method is used to persist event notifications in the database.
+ *
+ * @param connection Database connection
+ * @param notification Notification details
+ * @param eventsList List of notification events
+ * @return NotificationID of the saved notification.
+ * @throws FSEventNotificationException Exception when persisting event notification data
+ */
+ String persistEventNotification(Connection connection, Notification notification,
+ ArrayList
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.dao;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.financial.services.accelerator.event.notifications.service.constants.EventNotificationConstants;
+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.NotificationError;
+import org.wso2.financial.services.accelerator.event.notifications.service.model.NotificationEvent;
+import org.wso2.financial.services.accelerator.event.notifications.service.queries.EventNotificationSqlStatements;
+import org.wso2.financial.services.accelerator.event.notifications.service.util.EventNotificationServiceUtil;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * Persisting event notifications to database.
+ */
+public class EventNotificationDAOImpl implements EventNotificationDAO {
+
+ private static Log log = LogFactory.getLog(EventNotificationDAOImpl.class);
+ protected EventNotificationSqlStatements sqlStatements;
+
+ public EventNotificationDAOImpl(EventNotificationSqlStatements eventNotificationSqlStatements) {
+ this.sqlStatements = eventNotificationSqlStatements;
+ }
+
+ @Override
+ public String persistEventNotification(Connection connection, Notification notification,
+ ArrayList
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.dao;
+
+import org.wso2.financial.services.accelerator.event.notifications.service.exception.FSEventNotificationException;
+import org.wso2.financial.services.accelerator.event.notifications.service.model.EventSubscription;
+
+import java.sql.Connection;
+import java.util.List;
+
+/**
+ * Event Notification Subscription DAO interface.
+ */
+public interface EventSubscriptionDAO {
+
+ /**
+ * This method is used to store event notification subscription in the database.
+ *
+ * @param connection Database connection.
+ * @param eventSubscription EventSubscription object.
+ * @return EventSubscription object.
+ * @throws FSEventNotificationException Exception when storing event subscription
+ */
+ EventSubscription storeEventSubscription(Connection connection, EventSubscription eventSubscription)
+ throws FSEventNotificationException;
+
+ /**
+ * This method is used to store subscribed event types in the database.
+ *
+ * @param connection Database connection.
+ * @param subscriptionId Subscription ID.
+ * @param eventTypes Event types to be stored.
+ * @return List of strings with subscribed event types.
+ * @throws FSEventNotificationException Exception when storing subscribed event types
+ */
+ List
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.dao;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.financial.services.accelerator.event.notifications.service.constants.EventNotificationConstants;
+import org.wso2.financial.services.accelerator.event.notifications.service.exception.FSEventNotificationException;
+import org.wso2.financial.services.accelerator.event.notifications.service.model.EventSubscription;
+import org.wso2.financial.services.accelerator.event.notifications.service.queries.EventSubscriptionSqlStatements;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.time.Instant;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+import static java.sql.Statement.EXECUTE_FAILED;
+
+/**
+ * Default EventSubscriptionDAO Impl.
+ */
+public class EventSubscriptionDAOImpl implements EventSubscriptionDAO {
+ private static Log log = LogFactory.getLog(EventSubscriptionDAOImpl.class);
+
+ protected EventSubscriptionSqlStatements sqlStatements;
+
+ public EventSubscriptionDAOImpl(EventSubscriptionSqlStatements sqlStatements) {
+ this.sqlStatements = sqlStatements;
+ }
+
+ public EventSubscription storeEventSubscription(Connection connection, EventSubscription eventSubscription)
+ throws FSEventNotificationException {
+
+ int storeSubscriptionAffectedRows;
+
+ UUID subscriptionId = UUID.randomUUID();
+ long unixTime = Instant.now().getEpochSecond();
+ eventSubscription.setSubscriptionId(subscriptionId.toString());
+ eventSubscription.setTimeStamp(unixTime);
+ eventSubscription.setStatus(EventNotificationConstants.CREATED);
+
+ final String sql = sqlStatements.storeEventSubscriptionQuery();
+ try (PreparedStatement storeEventSubscriptionStatement = connection.prepareStatement(sql)) {
+ storeEventSubscriptionStatement.setString(1, eventSubscription.getSubscriptionId());
+ storeEventSubscriptionStatement.setString(2, eventSubscription.getClientId());
+ storeEventSubscriptionStatement.setString(3, eventSubscription.getCallbackUrl());
+ storeEventSubscriptionStatement.setLong(4, eventSubscription.getTimeStamp());
+ storeEventSubscriptionStatement.setString(5, eventSubscription.getSpecVersion());
+ storeEventSubscriptionStatement.setString(6, eventSubscription.getStatus());
+ storeEventSubscriptionStatement.setString(7, eventSubscription.getRequestData());
+ storeSubscriptionAffectedRows = storeEventSubscriptionStatement.executeUpdate();
+ if (storeSubscriptionAffectedRows == 0) {
+ log.error("Failed to store the event notification subscription.");
+ throw new FSEventNotificationException(EventNotificationConstants.ERROR_STORING_EVENT_SUBSCRIPTION);
+ }
+ } catch (SQLException e) {
+ log.error("SQL exception when storing the event types of the subscription", e);
+ throw new FSEventNotificationException(EventNotificationConstants.ERROR_STORING_EVENT_SUBSCRIPTION);
+ }
+ return eventSubscription;
+ }
+
+ @Override
+ public List
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.dao;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.financial.services.accelerator.common.util.Generated;
+import org.wso2.financial.services.accelerator.event.notifications.service.constants.EventNotificationConstants;
+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.queries.EventNotificationSqlStatements;
+import org.wso2.financial.services.accelerator.event.notifications.service.util.EventNotificationServiceUtil;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * PostgreSql event polling dao class.
+ */
+@Generated(message = "Postgres Implementation")
+public class PostgreSqlEventNotificationDAOImpl extends EventNotificationDAOImpl {
+
+ private static Log log = LogFactory.getLog(PostgreSqlEventNotificationDAOImpl.class);
+
+ public PostgreSqlEventNotificationDAOImpl(EventNotificationSqlStatements eventNotificationSqlStatements) {
+ super(eventNotificationSqlStatements);
+ }
+
+ @Override
+ public List
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.dto;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+/**
+ * Error model for Event Notifications.
+ */
+public class EventNotificationErrorDTO {
+
+ private String errorDescription;
+ private String error;
+
+ @JsonProperty("error_description")
+ public String getErrorDescription() {
+
+ return errorDescription;
+ }
+
+ public void setErrorDescription(String errorDescription) {
+
+ this.errorDescription = errorDescription;
+ }
+
+ @JsonProperty("error")
+ public String getError() {
+
+ return error;
+ }
+
+ public void setError(String error) {
+
+ this.error = error;
+ }
+
+}
diff --git a/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/dto/EventPollingDTO.java b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/dto/EventPollingDTO.java
new file mode 100644
index 00000000..500e5fb9
--- /dev/null
+++ b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/dto/EventPollingDTO.java
@@ -0,0 +1,75 @@
+/**
+ * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com).
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.dto;
+
+import org.wso2.financial.services.accelerator.event.notifications.service.model.NotificationError;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Event Polling DTO.
+ */
+public class EventPollingDTO {
+
+ //Set to true by default as WSO2 Financial Services don't support long polling
+ private final Boolean returnImmediately = true;
+ private String clientId = null;
+ private int maxEvents = 0;
+ private List
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.dto;
+
+import org.json.JSONObject;
+
+/**
+ * Event Subscription DTO.
+ */
+public class EventSubscriptionDTO {
+ private String clientId = null;
+ private String subscriptionId = null;
+ private JSONObject requestData = null;
+
+ public String getClientId() {
+ return clientId;
+ }
+
+ public void setClientId(String clientId) {
+ this.clientId = clientId;
+ }
+
+ public String getSubscriptionId() {
+ return subscriptionId;
+ }
+
+ public void setSubscriptionId(String subscriptionId) {
+ this.subscriptionId = subscriptionId;
+ }
+
+ public JSONObject getRequestData() {
+ return requestData;
+ }
+
+ public void setRequestData(JSONObject requestData) {
+ this.requestData = requestData;
+ }
+}
diff --git a/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/dto/NotificationCreationDTO.java b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/dto/NotificationCreationDTO.java
new file mode 100644
index 00000000..f75c58ab
--- /dev/null
+++ b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/dto/NotificationCreationDTO.java
@@ -0,0 +1,59 @@
+/**
+ * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com).
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.dto;
+
+import org.json.JSONObject;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Event Creation DTO.
+ */
+public class NotificationCreationDTO {
+
+ private Map
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.exception;
+
+import org.wso2.financial.services.accelerator.common.exception.FinancialServicesException;
+
+/**
+ * Event Notification Exceptions.
+ */
+public class FSEventNotificationException extends FinancialServicesException {
+
+ public FSEventNotificationException(String message) {
+ super(message);
+ }
+
+ public FSEventNotificationException(String message, Throwable e) {
+ super(message, e);
+ }
+}
diff --git a/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/handler/DefaultEventCreationServiceHandler.java b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/handler/DefaultEventCreationServiceHandler.java
new file mode 100644
index 00000000..67fa8039
--- /dev/null
+++ b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/handler/DefaultEventCreationServiceHandler.java
@@ -0,0 +1,105 @@
+/**
+ * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com).
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.handler;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.json.JSONObject;
+import org.wso2.financial.services.accelerator.common.exception.ConsentManagementException;
+import org.wso2.financial.services.accelerator.consent.mgt.dao.models.ConsentResource;
+import org.wso2.financial.services.accelerator.consent.mgt.service.impl.ConsentCoreServiceImpl;
+import org.wso2.financial.services.accelerator.event.notifications.service.constants.EventNotificationConstants;
+import org.wso2.financial.services.accelerator.event.notifications.service.dto.NotificationCreationDTO;
+import org.wso2.financial.services.accelerator.event.notifications.service.exception.FSEventNotificationException;
+import org.wso2.financial.services.accelerator.event.notifications.service.model.EventCreationResponse;
+import org.wso2.financial.services.accelerator.event.notifications.service.service.EventCreationService;
+import org.wso2.financial.services.accelerator.event.notifications.service.util.EventNotificationServiceUtil;
+
+/**
+ * This is to handle FS Event Creation.
+ */
+public class DefaultEventCreationServiceHandler implements EventCreationServiceHandler {
+
+ private static final Log log = LogFactory.getLog(DefaultEventCreationServiceHandler.class);
+ private EventCreationService eventCreationService = new EventCreationService();
+
+ public void setEventCreationService(EventCreationService eventCreationService) {
+ this.eventCreationService = eventCreationService;
+ }
+
+ /**
+ * This method is used to publish FS events in the accelerator database.
+ *
+ * @param notificationCreationDTO Notification details DTO
+ * @return EventCreationResponse Response after event creation
+ */
+ public EventCreationResponse publishEvent(NotificationCreationDTO notificationCreationDTO) {
+
+ //validate if the resourceID is existing
+ ConsentResource consentResource = null;
+ ConsentCoreServiceImpl consentCoreService = EventNotificationServiceUtil.getConsentCoreServiceImpl();
+ EventCreationResponse eventCreationResponse = new EventCreationResponse();
+
+ try {
+ consentResource = consentCoreService.getConsent(notificationCreationDTO.getResourceId(),
+ false);
+
+ if (log.isDebugEnabled()) {
+ log.debug("Consent resource available for resource ID " +
+ consentResource.getConsentID().replaceAll("[\r\n]", ""));
+ }
+ } catch (ConsentManagementException e) {
+ log.error("Consent Management Exception when validating the consent resource", e);
+ eventCreationResponse.setErrorResponse(String.format("A resource was not found for the resource " +
+ "id : '%s' in the database. ", notificationCreationDTO.getResourceId()));
+ eventCreationResponse.setStatus(EventNotificationConstants.BAD_REQUEST);
+ return eventCreationResponse;
+ }
+
+ //validate if the clientID is existing
+ try {
+ EventNotificationServiceUtil.validateClientId(notificationCreationDTO.getClientId());
+
+ } catch (FSEventNotificationException e) {
+ log.error("Invalid client ID", e);
+ eventCreationResponse.setErrorResponse(String.format("A client was not found" +
+ " for the client id : '%s' in the database. ",
+ notificationCreationDTO.getClientId().replaceAll("[\r\n]", "")));
+ eventCreationResponse.setStatus(EventNotificationConstants.BAD_REQUEST);
+ return eventCreationResponse;
+ }
+
+ String registrationResponse = "";
+ try {
+ registrationResponse = eventCreationService.publishEventNotification(notificationCreationDTO);
+ JSONObject responseJSON = new JSONObject();
+ responseJSON.put(EventNotificationConstants.NOTIFICATIONS_ID, registrationResponse);
+ eventCreationResponse.setStatus(EventNotificationConstants.CREATED);
+ eventCreationResponse.setResponseBody(responseJSON);
+ return eventCreationResponse;
+
+ } catch (FSEventNotificationException e) {
+ log.error("FS Event Notification Creation error", e);
+ }
+
+ eventCreationResponse.setStatus(EventNotificationConstants.BAD_REQUEST);
+ eventCreationResponse.setErrorResponse("Error in event creation request payload");
+ return eventCreationResponse;
+ }
+}
diff --git a/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/handler/DefaultEventPollingServiceHandler.java b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/handler/DefaultEventPollingServiceHandler.java
new file mode 100644
index 00000000..b5930e69
--- /dev/null
+++ b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/handler/DefaultEventPollingServiceHandler.java
@@ -0,0 +1,181 @@
+/**
+ * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com).
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.handler;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.json.JSONArray;
+import org.json.JSONObject;
+import org.wso2.financial.services.accelerator.common.config.FinancialServicesConfigParser;
+import org.wso2.financial.services.accelerator.common.util.Generated;
+import org.wso2.financial.services.accelerator.event.notifications.service.constants.EventNotificationConstants;
+import org.wso2.financial.services.accelerator.event.notifications.service.dto.EventPollingDTO;
+import org.wso2.financial.services.accelerator.event.notifications.service.exception.FSEventNotificationException;
+import org.wso2.financial.services.accelerator.event.notifications.service.model.AggregatedPollingResponse;
+import org.wso2.financial.services.accelerator.event.notifications.service.model.EventPolling;
+import org.wso2.financial.services.accelerator.event.notifications.service.model.EventPollingResponse;
+import org.wso2.financial.services.accelerator.event.notifications.service.model.NotificationError;
+import org.wso2.financial.services.accelerator.event.notifications.service.service.EventPollingService;
+import org.wso2.financial.services.accelerator.event.notifications.service.util.EventNotificationServiceUtil;
+
+import java.util.Locale;
+
+/**
+ * This is the service handler for event polling.
+ */
+public class DefaultEventPollingServiceHandler implements EventPollingServiceHandler {
+
+ private static final Log log = LogFactory.getLog(DefaultEventPollingServiceHandler.class);
+
+ public void setEventPollingService(EventPollingService eventPollingService) {
+ this.eventPollingService = eventPollingService;
+ }
+
+ private EventPollingService eventPollingService = new EventPollingService();
+
+
+ /**
+ * This method is used to Poll Events as per request params.
+ * @param eventPollingDTO Event polling DTO
+ * @return EventPollingResponse
+ */
+ public EventPollingResponse pollEvents(EventPollingDTO eventPollingDTO) {
+
+ EventPollingResponse eventPollingResponse = new EventPollingResponse();
+
+ //Validate clientID of the polling request
+ try {
+ EventNotificationServiceUtil.validateClientId(eventPollingDTO.getClientId());
+ } catch (FSEventNotificationException e) {
+ log.error("Invalid client ID", e);
+ eventPollingResponse.setStatus(EventNotificationConstants.BAD_REQUEST);
+ eventPollingResponse.setErrorResponse(EventNotificationServiceUtil.getErrorDTO(
+ EventNotificationConstants.INVALID_REQUEST, String.format("A client was not found" +
+ " for the client id : '%s' in the database.. ", eventPollingDTO.getClientId())));
+ return eventPollingResponse;
+ }
+
+ EventPolling eventPolling = mapEventPollingDtoToModel(eventPollingDTO);
+ //Poll events
+ try {
+ AggregatedPollingResponse aggregatedPollingResponse = eventPollingService.pollEvents(eventPolling);
+ eventPollingResponse.setStatus(aggregatedPollingResponse.getStatus());
+ eventPollingResponse.setResponseBody(getPollingResponseJSON(aggregatedPollingResponse));
+ return eventPollingResponse;
+ } catch (FSEventNotificationException e) {
+ log.error("OB Event Notification error" , e);
+ eventPollingResponse.setStatus(EventNotificationConstants.BAD_REQUEST);
+ eventPollingResponse.setErrorResponse(EventNotificationServiceUtil.getErrorDTO(
+ EventNotificationConstants.INVALID_REQUEST, e.getMessage()));
+ return eventPollingResponse;
+ }
+
+ }
+
+ /**
+ * This method will map the event subscription DTO to event subscription model
+ * to be passed to the dao layer.
+ *
+ * @param eventPollingDTO Event polling DTO
+ * @return EventPolling Event polling Model mapped
+ */
+ private EventPolling mapEventPollingDtoToModel(EventPollingDTO eventPollingDTO) {
+
+ EventPolling eventPolling = new EventPolling();
+ eventPolling.setClientId(eventPollingDTO.getClientId());
+ eventPolling.setMaxEvents(eventPollingDTO.getMaxEvents());
+ eventPolling.setReturnImmediately(eventPollingDTO.getReturnImmediately());
+ eventPolling.setSetsToReturn(FinancialServicesConfigParser.getInstance().getNumberOfSetsToReturn());
+ eventPollingDTO.getAck().forEach(eventPolling::setAck);
+ eventPollingDTO.getErrors().forEach(eventPolling::setErrors);
+
+ return eventPolling;
+ }
+
+ /**
+ * This method will map the eventPollingRequest JSON to EventPollingDTO.
+ * @param eventPollingRequest JSON request for event polling
+ * @return EventPollingDTO
+ */
+ public EventPollingDTO mapPollingRequest(JSONObject eventPollingRequest) {
+
+ EventPollingDTO eventPollingDTO = new EventPollingDTO();
+ eventPollingDTO.setClientId(eventPollingRequest.get(EventNotificationConstants.X_WSO2_CLIENT_ID).toString());
+
+ if (eventPollingRequest.length() == 0) {
+
+ eventPollingDTO.setMaxEvents(FinancialServicesConfigParser.getInstance().getNumberOfSetsToReturn());
+
+ return eventPollingDTO;
+ }
+
+ //Set acknowledged events to DTO
+ if (eventPollingRequest.has(EventNotificationConstants.ACK.toLowerCase(Locale.ROOT))) {
+ JSONArray acknowledgedEvents = (JSONArray) eventPollingRequest.
+ get(EventNotificationConstants.ACK.toLowerCase(Locale.ROOT));
+ acknowledgedEvents.forEach((event -> {
+ eventPollingDTO.setAck(event.toString());
+ }));
+ }
+
+ //Set error events to DTO
+ if (eventPollingRequest.has(EventNotificationConstants.SET_ERRORS)) {
+ JSONObject errorEvents = (JSONObject) eventPollingRequest.
+ get(EventNotificationConstants.SET_ERRORS);
+ errorEvents.keySet().forEach(errorEvent -> {
+ JSONObject errorEventInformation = (JSONObject) errorEvents.get(errorEvent);
+ NotificationError notificationError = getNotificationError(errorEventInformation);
+ notificationError.setNotificationId(errorEvent);
+ eventPollingDTO.setErrors(errorEvent, notificationError);
+ });
+ }
+
+ //Set maxEvents count to return
+ if (eventPollingRequest.has(EventNotificationConstants.MAX_EVENTS)) {
+ eventPollingDTO.setMaxEvents(Integer.parseInt(eventPollingRequest.
+ get(EventNotificationConstants.MAX_EVENTS).toString()));
+ } else {
+ eventPollingDTO.setMaxEvents(FinancialServicesConfigParser.getInstance().getNumberOfSetsToReturn());
+ }
+
+ return eventPollingDTO;
+ }
+
+ @Generated(message = "Private method tested when testing the invoked method")
+ private NotificationError getNotificationError(JSONObject errorEvent) {
+
+ NotificationError notificationError = new NotificationError();
+ notificationError.setErrorCode(errorEvent.get(
+ EventNotificationConstants.ERROR.toLowerCase(Locale.ROOT)).toString());
+ notificationError.setErrorDescription(
+ errorEvent.get(EventNotificationConstants.DESCRIPTION).toString());
+ return notificationError;
+ }
+
+ @Generated(message = "Private method tested when testing the invoked method")
+ private JSONObject getPollingResponseJSON(AggregatedPollingResponse aggregatedPollingResponse) {
+
+ JSONObject responseJSON = new JSONObject();
+ responseJSON.put(EventNotificationConstants.SETS, aggregatedPollingResponse.getSets());
+ responseJSON.put(EventNotificationConstants.MORE_AVAILABLE,
+ aggregatedPollingResponse.isMoreAvailable());
+ return responseJSON;
+ }
+
+}
diff --git a/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/handler/DefaultEventSubscriptionServiceHandler.java b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/handler/DefaultEventSubscriptionServiceHandler.java
new file mode 100644
index 00000000..cba1d7b6
--- /dev/null
+++ b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/handler/DefaultEventSubscriptionServiceHandler.java
@@ -0,0 +1,345 @@
+/**
+ * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com).
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.handler;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.http.HttpStatus;
+import org.json.JSONObject;
+import org.wso2.financial.services.accelerator.event.notifications.service.constants.EventNotificationConstants;
+import org.wso2.financial.services.accelerator.event.notifications.service.dto.EventSubscriptionDTO;
+import org.wso2.financial.services.accelerator.event.notifications.service.exception.FSEventNotificationException;
+import org.wso2.financial.services.accelerator.event.notifications.service.model.EventSubscription;
+import org.wso2.financial.services.accelerator.event.notifications.service.model.EventSubscriptionResponse;
+import org.wso2.financial.services.accelerator.event.notifications.service.service.EventSubscriptionService;
+import org.wso2.financial.services.accelerator.event.notifications.service.util.EventNotificationServiceUtil;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * This is the default service handler for event notification subscription.
+ */
+public class DefaultEventSubscriptionServiceHandler implements EventSubscriptionServiceHandler {
+ private static final Log log = LogFactory.getLog(DefaultEventSubscriptionServiceHandler.class);
+
+ private EventSubscriptionService eventSubscriptionService = new EventSubscriptionService();
+
+ public void setEventSubscriptionService(EventSubscriptionService eventSubscriptionService) {
+ this.eventSubscriptionService = eventSubscriptionService;
+ }
+
+ /**
+ * This method is used to create event subscriptions.
+ *
+ * @param eventSubscriptionRequestDto Event Subscription DTO
+ * @return EventSubscriptionResponse Event Subscription Response
+ */
+ public EventSubscriptionResponse createEventSubscription(EventSubscriptionDTO eventSubscriptionRequestDto) {
+ EventSubscriptionResponse eventSubscriptionResponse = new EventSubscriptionResponse();
+
+ EventSubscriptionResponse clientIdValidation = validateClientId(eventSubscriptionRequestDto.getClientId());
+ // check whether clientIdValidation is not null, then return the error response
+ if (clientIdValidation != null) {
+ return clientIdValidation;
+ }
+
+ EventSubscription eventSubscription = mapEventSubscriptionDtoToModel(eventSubscriptionRequestDto);
+
+ try {
+ EventSubscription createEventSubscriptionResponse = eventSubscriptionService.
+ createEventSubscription(eventSubscription);
+ eventSubscriptionResponse.setStatus(HttpStatus.SC_CREATED);
+ eventSubscriptionResponse.
+ setResponseBody(mapSubscriptionModelToResponseJson(createEventSubscriptionResponse));
+ return eventSubscriptionResponse;
+ } catch (FSEventNotificationException e) {
+ log.error("Error occurred while creating event subscription", e);
+ eventSubscriptionResponse.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
+ eventSubscriptionResponse.setErrorResponse(EventNotificationServiceUtil.getErrorDTO(
+ EventNotificationConstants.INVALID_REQUEST, e.getMessage()));
+ return eventSubscriptionResponse;
+ }
+
+ }
+
+ /**
+ * This method is used to retrieve a single event subscription.
+ *
+ * @param clientId Client ID of the subscription created
+ * @param subscriptionId Subscription ID of the subscription created
+ * @return EventSubscriptionResponse Event Subscription Response containing subscription
+ * details for the given subscription ID
+ */
+ public EventSubscriptionResponse getEventSubscription(String clientId, String subscriptionId) {
+ EventSubscriptionResponse eventSubscriptionResponse = new EventSubscriptionResponse();
+
+ EventSubscriptionResponse clientIdValidation = validateClientId(clientId);
+ // check whether clientIdValidation is not null, then return the error response
+ if (clientIdValidation != null) {
+ return clientIdValidation;
+ }
+
+ try {
+ EventSubscription eventSubscription = eventSubscriptionService.
+ getEventSubscriptionBySubscriptionId(subscriptionId);
+ eventSubscriptionResponse.setStatus(HttpStatus.SC_OK);
+ eventSubscriptionResponse.setResponseBody(mapSubscriptionModelToResponseJson(eventSubscription));
+ return eventSubscriptionResponse;
+ } catch (FSEventNotificationException e) {
+ log.error("Error occurred while retrieving event subscription", e);
+ if (e.getMessage().equals(EventNotificationConstants.EVENT_SUBSCRIPTION_NOT_FOUND)) {
+ eventSubscriptionResponse.setStatus(HttpStatus.SC_BAD_REQUEST);
+ eventSubscriptionResponse.setErrorResponse(EventNotificationServiceUtil.getErrorDTO(
+ EventNotificationConstants.INVALID_REQUEST, e.getMessage()));
+ } else {
+ eventSubscriptionResponse.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);
+ eventSubscriptionResponse.setErrorResponse(EventNotificationServiceUtil.getErrorDTO(
+ EventNotificationConstants.INVALID_REQUEST, e.getMessage()));
+ }
+ return eventSubscriptionResponse;
+ }
+ }
+
+ /**
+ * This method is used to retrieve all event subscriptions of a client.
+ *
+ * @param clientId Client ID
+ * @return EventSubscriptionResponse Event Subscription Response containing all the subscriptions
+ */
+ public EventSubscriptionResponse getAllEventSubscriptions(String clientId) {
+ EventSubscriptionResponse eventSubscriptionResponse = new EventSubscriptionResponse();
+
+ EventSubscriptionResponse clientIdValidation = validateClientId(clientId);
+ // check whether clientIdValidation is not null, then return the error response
+ if (clientIdValidation != null) {
+ return clientIdValidation;
+ }
+
+ try {
+ List
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.handler;
+
+import org.wso2.financial.services.accelerator.event.notifications.service.dto.NotificationCreationDTO;
+import org.wso2.financial.services.accelerator.event.notifications.service.model.EventCreationResponse;
+
+/**
+ * Event creation service handler is used to map the creation request and validate the date before
+ * calling the service. In need of a custom handling this class can be extended and the extended class
+ * can be added to the deployment.toml under event_creation_handler to execute the specific class.
+ */
+public interface EventCreationServiceHandler {
+ /**
+ * This method is used to publish FS events in the accelerator database. The method is a generic
+ * method that is used to persist data into the FS_NOTIFICATION and FS_NOTIFICATION_EVENT tables.
+ * @param notificationCreationDTO Notification details DTO
+ * @return For successful request the API will return a JSON with the notificationID
+ */
+ EventCreationResponse publishEvent(NotificationCreationDTO notificationCreationDTO);
+
+}
diff --git a/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/handler/EventPollingServiceHandler.java b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/handler/EventPollingServiceHandler.java
new file mode 100644
index 00000000..2b5fc735
--- /dev/null
+++ b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/handler/EventPollingServiceHandler.java
@@ -0,0 +1,48 @@
+/**
+ * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com).
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.handler;
+
+import org.json.JSONObject;
+import org.wso2.financial.services.accelerator.event.notifications.service.dto.EventPollingDTO;
+import org.wso2.financial.services.accelerator.event.notifications.service.model.EventPollingResponse;
+
+/**
+ * EventPolling Service handler is used to validate and map the polling request to the DTO before calling the
+ * polling service. For custom validations this class can be extended and the extended class
+ * can be added to the deployment.toml under event_polling_handler to execute the specific class.
+ */
+public interface EventPollingServiceHandler {
+ /**
+ * This method follows the IETF Specification for SET delivery over HTTP.
+ * The method supports event acknowledgment in both positive and negative.
+ * Also, can be used to POLL for available OPEN notifications.
+ * @param eventPollingDTO Event polling DTO
+ * @return EventPollingResponse to the polling endpoint.
+ */
+ EventPollingResponse pollEvents(EventPollingDTO eventPollingDTO);
+
+ /**
+ * This method is used to map the eventPollingRequest to EventPollingDTO.
+ * @param eventPollingRequest JSON request for event polling
+ * @return eventPollingDTO with the request parameters.
+ */
+ EventPollingDTO mapPollingRequest(JSONObject eventPollingRequest);
+
+}
+
diff --git a/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/handler/EventSubscriptionServiceHandler.java b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/handler/EventSubscriptionServiceHandler.java
new file mode 100644
index 00000000..d755bd14
--- /dev/null
+++ b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/handler/EventSubscriptionServiceHandler.java
@@ -0,0 +1,94 @@
+/**
+ * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com).
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.handler;
+
+import org.json.JSONObject;
+import org.wso2.financial.services.accelerator.event.notifications.service.dto.EventSubscriptionDTO;
+import org.wso2.financial.services.accelerator.event.notifications.service.model.EventSubscription;
+import org.wso2.financial.services.accelerator.event.notifications.service.model.EventSubscriptionResponse;
+
+/**
+ * EventSubscription Service handler is used to validate subscription requests before calling the
+ * subscription service. For custom validations this class can be extended and the extended class
+ * can be added to the deployment.toml under event_subscription_handler to execute the specific class.
+ */
+public interface EventSubscriptionServiceHandler {
+
+ /**
+ * This method is used to create event subscriptions in the accelerator database. The method is a generic
+ * method that is used to persist data into the NOTIFICATION_SUBSCRIPTION and NOTIFICATION_SUBSCRIPTION_EVENT
+ * tables.
+ *
+ * @param eventSubscriptionRequestDto The request DTO that contains the subscription details.
+ * @return For successful request the API will return a JSON with the subscriptionId
+ */
+ EventSubscriptionResponse createEventSubscription(EventSubscriptionDTO eventSubscriptionRequestDto);
+
+ /**
+ * This method is used to retrieve an event subscription by its subscription ID.
+ *
+ * @param clientId The client ID of the subscription.
+ * @param subscriptionId The subscription ID of the subscription.
+ * @return For successful request the API will return a JSON with the retrieved Subscription.
+ */
+ EventSubscriptionResponse getEventSubscription(String clientId, String subscriptionId);
+
+ /**
+ * This method is used to retrieve all event subscriptions of a client.
+ *
+ * @param clientId The client ID of the subscription.
+ * @return For successful request the API will return a JSON with the retrieved Subscriptions.
+ */
+ EventSubscriptionResponse getAllEventSubscriptions(String clientId);
+
+ /**
+ * This method is used to retrieve all event subscriptions by event type.
+ *
+ * @param clientId The client ID of the subscription.
+ * @param eventType The event type that needs to be subscribed by the retrieving subscriptions.
+ * @return For successful request the API will return a JSON with the retrieved Subscriptions.
+ */
+ EventSubscriptionResponse getEventSubscriptionsByEventType(String clientId, String eventType);
+
+ /**
+ * This method is used to update an event subscription.
+ *
+ * @param eventSubscriptionUpdateRequestDto The request DTO that contains the updating subscription details.
+ * @return For successful request the API will return a JSON with the updated Subscription.
+ */
+ EventSubscriptionResponse updateEventSubscription(EventSubscriptionDTO eventSubscriptionUpdateRequestDto);
+
+ /**
+ * This method is used to delete an event subscription.
+ *
+ * @param clientId The client ID of the subscription.
+ * @param subscriptionId The subscription ID of the subscription.
+ * @return For successful request the API will an OK response.
+ */
+ EventSubscriptionResponse deleteEventSubscription(String clientId, String subscriptionId);
+
+ /**
+ * This method is used to create the response JSON object from the event subscription model.
+ *
+ * @param eventSubscription The event subscription model.
+ * @return JSONObject
+ */
+ JSONObject mapSubscriptionModelToResponseJson(EventSubscription eventSubscription);
+
+}
diff --git a/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/internal/EventNotificationComponent.java b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/internal/EventNotificationComponent.java
new file mode 100644
index 00000000..547d5f15
--- /dev/null
+++ b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/internal/EventNotificationComponent.java
@@ -0,0 +1,100 @@
+/**
+ * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com).
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.internal;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.component.annotations.ReferenceCardinality;
+import org.osgi.service.component.annotations.ReferencePolicy;
+import org.wso2.carbon.identity.oauth2.OAuth2Service;
+import org.wso2.financial.services.accelerator.common.config.FinancialServicesConfigParser;
+import org.wso2.financial.services.accelerator.common.config.FinancialServicesConfigurationService;
+
+/**
+ * The Component class for activating event notification osgi service.
+ */
+@Component(
+ name = "org.wso2.financial.services.accelerator.event.notifications.service.internal.EventNotificationComponent",
+ immediate = true)
+public class EventNotificationComponent {
+ private static Log log = LogFactory.getLog(EventNotificationComponent.class);
+
+ @Activate
+ protected void activate(ComponentContext context) {
+ if (log.isDebugEnabled()) {
+ log.debug("Event Notification Service Component Activated");
+ }
+
+ // Check if realtime event notification enabled
+ if (FinancialServicesConfigParser.getInstance().isRealtimeEventNotificationEnabled()) {
+ /*
+ * Initialize the blocking queue for storing the realtime event notifications
+ * Initialize the quartz job for consuming the realtime event notifications
+ * Initialize the thread for producing the open state realtime event notifications
+ */
+ //TODO:
+// new Thread(new RealtimeEventNotificationLoaderService()).start();
+// new PeriodicalEventNotificationConsumerJobActivator().activate();
+ }
+ }
+
+ /**
+ * Setters for the descendent OSGI services of the EventNotificationComponent.
+ * This is added to run the EventNotification OSGI component after the Common module
+ * @param configService OpenBankingConfigurationService
+ */
+ @Reference(
+ service = FinancialServicesConfigurationService.class,
+ cardinality = ReferenceCardinality.MANDATORY,
+ policy = ReferencePolicy.DYNAMIC,
+ unbind = "unsetConfigService"
+ )
+ public void setConfigService(FinancialServicesConfigurationService configService) {
+ EventNotificationDataHolder.getInstance().setFinancialServicesConfigurationService(configService);
+ }
+
+ public void unsetConfigService(FinancialServicesConfigurationService configService) {
+ EventNotificationDataHolder.getInstance().setFinancialServicesConfigurationService(null);
+ }
+
+ /**
+ * Setters for the descendent OSGI services of the EventNotificationComponent.
+ * This is added to run the EventNotification OSGI component after the OAuth2Service
+ */
+ @Reference(
+ service = OAuth2Service.class,
+ cardinality = ReferenceCardinality.MANDATORY,
+ policy = ReferencePolicy.DYNAMIC,
+ unbind = "unsetOAuth2Service"
+ )
+
+ /**
+ * Setters for the descendent OSGI services of the EventNotificationComponent.
+ * @param oAuth2Service OAuth2Service
+ */
+ public void setOAuth2Service(OAuth2Service oAuth2Service) {
+ }
+
+ public void unsetOAuth2Service(OAuth2Service oAuth2Service) {
+ }
+}
diff --git a/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/internal/EventNotificationDataHolder.java b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/internal/EventNotificationDataHolder.java
new file mode 100644
index 00000000..d16bb2f7
--- /dev/null
+++ b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/internal/EventNotificationDataHolder.java
@@ -0,0 +1,73 @@
+/**
+ * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com).
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.internal;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.financial.services.accelerator.common.config.FinancialServicesConfigurationService;
+
+/**
+ * Data holder for Open Banking Event Notifications.
+ */
+public class EventNotificationDataHolder {
+ private static Log log = LogFactory.getLog(EventNotificationDataHolder.class);
+ private static volatile EventNotificationDataHolder instance;
+// private volatile LinkedBlockingQueue
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.model;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Default Polling Response Implementation.
+ */
+public class AggregatedPollingResponse {
+
+ private Map
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.model;
+
+import org.json.JSONObject;
+
+/**
+ * This class is to pass the event creation response to the api endpoint.
+ */
+public class EventCreationResponse {
+
+ private String status;
+ private JSONObject responseBody;
+ private String errorResponse;
+
+ public String getErrorResponse() {
+ return errorResponse;
+ }
+
+ public void setErrorResponse(String errorResponse) {
+ this.errorResponse = errorResponse;
+ }
+
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(String status) {
+ this.status = status;
+ }
+
+ public JSONObject getResponseBody() {
+ return responseBody;
+ }
+
+ public void setResponseBody(JSONObject responseBody) {
+ this.responseBody = responseBody;
+ }
+}
diff --git a/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/model/EventPolling.java b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/model/EventPolling.java
new file mode 100644
index 00000000..7b415809
--- /dev/null
+++ b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/model/EventPolling.java
@@ -0,0 +1,86 @@
+/**
+ * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com).
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.model;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Event Polling model.
+ */
+public class EventPolling {
+
+ private Boolean returnImmediately = true;
+ private String clientId = null;
+ private int maxEvents = 0;
+ private int setsToReturn = 0;
+ private List
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.model;
+
+import org.json.JSONObject;
+
+/**
+ * This class is used to map the Event Polling service response to the API response.
+ */
+public class EventPollingResponse {
+
+ private String status;
+ private JSONObject responseBody;
+ private Object errorResponse;
+
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(String status) {
+ this.status = status;
+ }
+
+ public JSONObject getResponseBody() {
+ return responseBody;
+ }
+
+ public void setResponseBody(JSONObject responseBody) {
+ this.responseBody = responseBody;
+ }
+
+ public Object getErrorResponse() {
+ return errorResponse;
+ }
+
+ public void setErrorResponse(Object errorResponse) {
+ this.errorResponse = errorResponse;
+ }
+}
diff --git a/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/model/EventSubscription.java b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/model/EventSubscription.java
new file mode 100644
index 00000000..9776d179
--- /dev/null
+++ b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/model/EventSubscription.java
@@ -0,0 +1,99 @@
+/**
+ * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com).
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.model;
+
+import java.util.List;
+
+/**
+ * This is the Event Subscription Model.
+ */
+public class EventSubscription {
+ private String subscriptionId = null;
+ private String clientId = null;
+ private String callbackUrl = null;
+ private Long timeStamp = null;
+ private String specVersion = null;
+ private String status = null;
+ private List
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.model;
+
+/**
+ * This class is used to map the Event Subscription service response to the API response.
+ */
+public class EventSubscriptionResponse {
+
+ private int status;
+ private Object responseBody;
+ private Object errorResponse;
+
+ public int getStatus() {
+ return status;
+ }
+
+ public void setStatus(int status) {
+ this.status = status;
+ }
+
+ public Object getResponseBody() {
+ return responseBody;
+ }
+
+ public void setResponseBody(Object responseBody) {
+ this.responseBody = responseBody;
+ }
+
+ public Object getErrorResponse() {
+ return errorResponse;
+ }
+
+ public void setErrorResponse(Object errorResponse) {
+ this.errorResponse = errorResponse;
+ }
+
+}
diff --git a/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/model/Notification.java b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/model/Notification.java
new file mode 100644
index 00000000..0c8d5157
--- /dev/null
+++ b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/model/Notification.java
@@ -0,0 +1,71 @@
+/**
+ * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com).
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.model;
+
+/**
+ * This is the notification model.
+ */
+public class Notification {
+
+ String notificationId = null;
+ String clientId = null;
+ String resourceId = null;
+ String status = null;
+ Long updatedTimeStamp = null;
+
+ public String getNotificationId() {
+ return notificationId;
+ }
+
+ public void setNotificationId(String notificationId) {
+ this.notificationId = notificationId;
+ }
+
+ public String getClientId() {
+ return clientId;
+ }
+
+ public void setClientId(String clientId) {
+ this.clientId = clientId;
+ }
+
+ public String getResourceId() {
+ return resourceId;
+ }
+
+ public void setResourceId(String resourceId) {
+ this.resourceId = resourceId;
+ }
+
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(String status) {
+ this.status = status;
+ }
+
+ public Long getUpdatedTimeStamp() {
+ return updatedTimeStamp;
+ }
+
+ public void setUpdatedTimeStamp(Long updatedTimeStamp) {
+ this.updatedTimeStamp = updatedTimeStamp;
+ }
+}
diff --git a/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/model/NotificationError.java b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/model/NotificationError.java
new file mode 100644
index 00000000..0a9a8058
--- /dev/null
+++ b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/model/NotificationError.java
@@ -0,0 +1,52 @@
+/**
+ * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com).
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.model;
+
+/**
+ * The notification error model.
+ */
+public class NotificationError {
+ private String notificationId = null;
+ private String errorCode = null;
+ private String errorDescription = null;
+
+ public String getNotificationId() {
+ return notificationId;
+ }
+
+ public void setNotificationId(String notificationId) {
+ this.notificationId = notificationId;
+ }
+
+ public String getErrorCode() {
+ return errorCode;
+ }
+
+ public void setErrorCode(String errorCode) {
+ this.errorCode = errorCode;
+ }
+
+ public String getErrorDescription() {
+ return errorDescription;
+ }
+
+ public void setErrorDescription(String errorDescription) {
+ this.errorDescription = errorDescription;
+ }
+}
diff --git a/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/model/NotificationEvent.java b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/model/NotificationEvent.java
new file mode 100644
index 00000000..09713cec
--- /dev/null
+++ b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/model/NotificationEvent.java
@@ -0,0 +1,64 @@
+/**
+ * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com).
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.model;
+
+import org.json.JSONObject;
+
+/**
+ * This is the notification event model class.
+ */
+public class NotificationEvent {
+
+ private Integer eventId = null;
+ private String notificationId = null;
+ private String eventType = null;
+ private JSONObject eventInformation;
+
+ public Integer getEventId() {
+ return eventId;
+ }
+
+ public void setEventId(Integer eventId) {
+ this.eventId = eventId;
+ }
+
+ public String getNotificationId() {
+ return notificationId;
+ }
+
+ public void setNotificationId(String notificationId) {
+ this.notificationId = notificationId;
+ }
+
+ public String getEventType() {
+ return eventType;
+ }
+
+ public void setEventType(String eventType) {
+ this.eventType = eventType;
+ }
+
+ public JSONObject getEventInformation() {
+ return eventInformation;
+ }
+
+ public void setEventInformation(JSONObject eventInformation) {
+ this.eventInformation = eventInformation;
+ }
+}
diff --git a/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/model/NotificationResponse.java b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/model/NotificationResponse.java
new file mode 100644
index 00000000..d34ded42
--- /dev/null
+++ b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/model/NotificationResponse.java
@@ -0,0 +1,126 @@
+/**
+ * Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com).
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.model;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.nimbusds.jose.JOSEException;
+import org.json.JSONObject;
+import org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * This is the notification response model.
+ */
+public class NotificationResponse {
+ private String iss = null;
+ private Long iat = null;
+ private String jti = null;
+ private String sub = null;
+ private String aud = null;
+ private String txn = null;
+ private Long toe = null;
+ private Map
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.persistence;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.financial.services.accelerator.common.persistence.JDBCPersistenceManager;
+import org.wso2.financial.services.accelerator.event.notifications.service.dao.EventNotificationDAO;
+import org.wso2.financial.services.accelerator.event.notifications.service.dao.EventNotificationDAOImpl;
+import org.wso2.financial.services.accelerator.event.notifications.service.dao.EventSubscriptionDAO;
+import org.wso2.financial.services.accelerator.event.notifications.service.dao.EventSubscriptionDAOImpl;
+import org.wso2.financial.services.accelerator.event.notifications.service.dao.PostgreSqlEventNotificationDAOImpl;
+import org.wso2.financial.services.accelerator.event.notifications.service.dao.PostgreSqlEventSubscriptionDAOImpl;
+import org.wso2.financial.services.accelerator.event.notifications.service.exception.FSEventNotificationException;
+import org.wso2.financial.services.accelerator.event.notifications.service.queries.EventNotificationSqlStatements;
+import org.wso2.financial.services.accelerator.event.notifications.service.queries.EventSubscriptionSqlStatements;
+import org.wso2.financial.services.accelerator.event.notifications.service.queries.MSSQLEventNotificationSqlStatements;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+
+/**
+ * Initializer Class for Event Notification Service DB.
+ */
+public class EventNotificationStoreInitializer {
+
+ private static Log log = LogFactory.getLog(EventNotificationStoreInitializer.class);
+ private static final String MYSQL = "MySQL";
+ private static final String POSTGRE = "PostgreSQL";
+ private static final String MSSQL = "Microsoft";
+ private static final String ORACLE = "Oracle";
+ private static final String H2 = "h2";
+
+ public static EventNotificationDAO initializeEventNotificationDAO() throws FSEventNotificationException {
+
+ EventNotificationDAO eventNotificationDAO;
+ try (Connection connection = JDBCPersistenceManager.getInstance().getDBConnection()) {
+ String driverName = connection.getMetaData().getDriverName();
+
+ if (driverName.contains(MYSQL) || driverName.contains(H2)) {
+ eventNotificationDAO = new EventNotificationDAOImpl(new EventNotificationSqlStatements());
+ } else if (driverName.contains(POSTGRE)) {
+ eventNotificationDAO = new PostgreSqlEventNotificationDAOImpl(new EventNotificationSqlStatements());
+ } else if (driverName.contains(MSSQL)) {
+ eventNotificationDAO = new EventNotificationDAOImpl(new MSSQLEventNotificationSqlStatements());
+ } else if (driverName.contains(ORACLE)) {
+ eventNotificationDAO = new EventNotificationDAOImpl(new EventNotificationSqlStatements());
+ } else {
+ throw new FSEventNotificationException("Unhandled DB driver: " + driverName + " detected");
+ }
+
+ } catch (SQLException e) {
+ throw new FSEventNotificationException("Error while getting the database connection : ", e);
+ }
+ return eventNotificationDAO;
+ }
+
+ public static EventNotificationDAO getEventNotificationDAO() throws FSEventNotificationException {
+
+ return initializeEventNotificationDAO();
+ }
+
+ public static EventSubscriptionDAO initializeSubscriptionDAO() throws FSEventNotificationException {
+
+ EventSubscriptionDAO eventSubscriptionDao;
+ try (Connection connection = JDBCPersistenceManager.getInstance().getDBConnection()) {
+ String driverName = connection.getMetaData().getDriverName();
+
+ if (driverName.contains(MYSQL) || driverName.contains(H2)) {
+ eventSubscriptionDao = new EventSubscriptionDAOImpl(new EventSubscriptionSqlStatements());
+ } else if (driverName.contains(POSTGRE)) {
+ eventSubscriptionDao = new PostgreSqlEventSubscriptionDAOImpl(new EventSubscriptionSqlStatements());
+ } else if (driverName.contains(MSSQL)) {
+ eventSubscriptionDao = new EventSubscriptionDAOImpl(new EventSubscriptionSqlStatements());
+ } else if (driverName.contains(ORACLE)) {
+ eventSubscriptionDao = new EventSubscriptionDAOImpl(new EventSubscriptionSqlStatements());
+ } else {
+ throw new FSEventNotificationException("Unhandled DB driver: " + driverName + " detected");
+ }
+ } catch (SQLException e) {
+ throw new FSEventNotificationException("Error while getting the database connection : ", e);
+ }
+
+ return eventSubscriptionDao;
+ }
+
+ public static EventSubscriptionDAO getEventSubscriptionDAO() throws FSEventNotificationException {
+
+ return initializeSubscriptionDAO();
+ }
+}
diff --git a/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/queries/EventNotificationSqlStatements.java b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/queries/EventNotificationSqlStatements.java
new file mode 100644
index 00000000..6dfe0ae5
--- /dev/null
+++ b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/queries/EventNotificationSqlStatements.java
@@ -0,0 +1,70 @@
+/**
+ * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com).
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.queries;
+
+/**
+ * SQL queries to store and retrieve event notifications.
+ */
+public class EventNotificationSqlStatements {
+
+ public String getStoreNotification() {
+
+ return "INSERT INTO FS_NOTIFICATION (NOTIFICATION_ID, CLIENT_ID, RESOURCE_ID, STATUS) VALUES (?,?,?,?)";
+ }
+
+ public String getStoreNotificationEvents() {
+
+ return "INSERT INTO FS_NOTIFICATION_EVENT (NOTIFICATION_ID, EVENT_TYPE, EVENT_INFO) VALUES (?,?,?)";
+ }
+
+ public String getEventsByNotificationIdQuery() {
+
+ return "SELECT * FROM FS_NOTIFICATION_EVENT WHERE NOTIFICATION_ID = ?";
+ }
+
+ public String getMaxNotificationsQuery() {
+
+ return "SELECT * FROM FS_NOTIFICATION WHERE CLIENT_ID = ? AND STATUS = ? LIMIT ?";
+ }
+
+ public String getNotificationsCountQuery() {
+
+ return "SELECT COUNT(*) AS NOTIFICATION_COUNT FROM FS_NOTIFICATION WHERE CLIENT_ID = ? AND STATUS = ?";
+ }
+
+ public String storeErrorNotificationQuery() {
+
+ return "INSERT INTO FS_NOTIFICATION_ERROR (NOTIFICATION_ID, ERROR_CODE, DESCRIPTION) VALUES (?,?,?)";
+ }
+
+ public String updateNotificationStatusQueryById() {
+
+ return "UPDATE FS_NOTIFICATION SET STATUS = ?, UPDATED_TIMESTAMP= ? WHERE NOTIFICATION_ID = ?";
+ }
+
+ public String getNotificationByNotificationId() {
+
+ return "SELECT NOTIFICATION_ID, STATUS FROM FS_NOTIFICATION WHERE NOTIFICATION_ID = ?";
+ }
+
+ public String getNotificationsByState() {
+
+ return "SELECT * FROM FS_NOTIFICATION WHERE STATUS = ?";
+ }
+}
diff --git a/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/queries/EventSubscriptionSqlStatements.java b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/queries/EventSubscriptionSqlStatements.java
new file mode 100644
index 00000000..818424bb
--- /dev/null
+++ b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/queries/EventSubscriptionSqlStatements.java
@@ -0,0 +1,71 @@
+/**
+ * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com).
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.queries;
+
+/**
+ * SQL queries to store, retrieve, update and delete event notification subscriptions.
+ */
+public class EventSubscriptionSqlStatements {
+
+ public String storeEventSubscriptionQuery() {
+ return "INSERT INTO FS_NOTIFICATION_SUBSCRIPTION (SUBSCRIPTION_ID, CLIENT_ID, CALLBACK_URL, TIMESTAMP, " +
+ "SPEC_VERSION, STATUS, REQUEST) VALUES (?,?,?,?,?,?,?)";
+ }
+
+ public String storeSubscribedEventTypesQuery() {
+ return "INSERT INTO FS_NOTIFICATION_SUBSCRIBED_EVENTS (SUBSCRIPTION_ID, EVENT_TYPE) VALUES (?,?)";
+ }
+
+ public String getEventSubscriptionBySubscriptionIdQuery() {
+ return "SELECT ns.SUBSCRIPTION_ID, ns.CLIENT_ID, ns.REQUEST, ns.CALLBACK_URL, ns.TIMESTAMP, ns.SPEC_VERSION, " +
+ "ns.STATUS, nse.EVENT_TYPE FROM FS_NOTIFICATION_SUBSCRIPTION ns LEFT JOIN " +
+ "FS_NOTIFICATION_SUBSCRIBED_EVENTS nse ON ns.SUBSCRIPTION_ID = nse.SUBSCRIPTION_ID WHERE " +
+ "ns.SUBSCRIPTION_ID = ? AND ns.STATUS = 'CREATED'";
+ }
+
+ public String getEventSubscriptionsByClientIdQuery() {
+ return "SELECT ns.SUBSCRIPTION_ID, ns.CLIENT_ID, ns.REQUEST, ns.CALLBACK_URL, ns.TIMESTAMP, ns.SPEC_VERSION, " +
+ "ns.STATUS, nse.EVENT_TYPE FROM FS_NOTIFICATION_SUBSCRIPTION ns LEFT JOIN " +
+ "FS_NOTIFICATION_SUBSCRIBED_EVENTS nse ON ns.SUBSCRIPTION_ID = nse.SUBSCRIPTION_ID WHERE " +
+ "ns.CLIENT_ID = ? AND ns.STATUS = 'CREATED'";
+ }
+
+ public String getEventSubscriptionsByEventTypeQuery() {
+ return "SELECT ns.SUBSCRIPTION_ID, ns.CLIENT_ID, ns.REQUEST, ns.CALLBACK_URL, ns.TIMESTAMP, ns.SPEC_VERSION, " +
+ "ns.STATUS, nse.EVENT_TYPE FROM FS_NOTIFICATION_SUBSCRIPTION ns LEFT JOIN " +
+ "FS_NOTIFICATION_SUBSCRIBED_EVENTS nse ON ns.SUBSCRIPTION_ID = nse.SUBSCRIPTION_ID WHERE " +
+ "ns.SUBSCRIPTION_ID IN (SELECT ns.SUBSCRIPTION_ID FROM FS_NOTIFICATION_SUBSCRIPTION ns LEFT " +
+ "JOIN FS_NOTIFICATION_SUBSCRIBED_EVENTS nse ON ns.SUBSCRIPTION_ID = nse.SUBSCRIPTION_ID WHERE " +
+ "nse.EVENT_TYPE = ? AND ns.STATUS = 'CREATED')";
+ }
+
+ public String updateEventSubscriptionQuery() {
+ return "UPDATE FS_NOTIFICATION_SUBSCRIPTION SET CALLBACK_URL = ?, TIMESTAMP = ?, REQUEST = ?" +
+ "WHERE SUBSCRIPTION_ID = ?";
+ }
+
+ public String updateEventSubscriptionStatusQuery() {
+ return "UPDATE FS_NOTIFICATION_SUBSCRIPTION SET STATUS = ? WHERE SUBSCRIPTION_ID = ? AND STATUS = 'CREATED'";
+ }
+
+ public String deleteSubscribedEventTypesQuery() {
+ return "DELETE FROM FS_NOTIFICATION_SUBSCRIBED_EVENTS WHERE SUBSCRIPTION_ID = ?";
+ }
+
+}
diff --git a/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/queries/MSSQLEventNotificationSqlStatements.java b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/queries/MSSQLEventNotificationSqlStatements.java
new file mode 100644
index 00000000..ba4e35ef
--- /dev/null
+++ b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/queries/MSSQLEventNotificationSqlStatements.java
@@ -0,0 +1,32 @@
+/**
+ * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com).
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.queries;
+
+/**
+ * MSSQL Queries for Event Notifications.
+ */
+public class MSSQLEventNotificationSqlStatements extends EventNotificationSqlStatements {
+
+ @Override
+ public String getMaxNotificationsQuery() {
+
+ return "SELECT * FROM FS_NOTIFICATION WHERE CLIENT_ID = ? AND STATUS = ? ORDER BY NOTIFICATION_ID " +
+ "OFFSET 0 ROWS FETCH NEXT ? ROWS ONLY";
+ }
+}
diff --git a/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/service/DefaultEventNotificationGenerator.java b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/service/DefaultEventNotificationGenerator.java
new file mode 100644
index 00000000..6eaecc0b
--- /dev/null
+++ b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/service/DefaultEventNotificationGenerator.java
@@ -0,0 +1,85 @@
+/**
+ * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com).
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.service;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.registry.core.utils.UUIDGenerator;
+import org.wso2.financial.services.accelerator.common.config.FinancialServicesConfigParser;
+import org.wso2.financial.services.accelerator.common.util.Generated;
+import org.wso2.financial.services.accelerator.common.util.JWTUtils;
+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.model.NotificationResponse;
+import org.wso2.financial.services.accelerator.event.notifications.service.util.EventNotificationServiceUtil;
+
+import java.time.Instant;
+import java.util.List;
+
+/**
+ * Default Event Notification Response Generator Class.
+ */
+public class DefaultEventNotificationGenerator implements EventNotificationGenerator {
+
+ private static Log log = LogFactory.getLog(DefaultEventNotificationGenerator.class);
+
+ @Override
+ public NotificationResponse generateEventNotificationBody(Notification notification,
+ List
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.service;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.json.JSONObject;
+import org.wso2.carbon.registry.core.utils.UUIDGenerator;
+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.dto.NotificationCreationDTO;
+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.ArrayList;
+import java.util.Map;
+
+/**
+ * This is the event creation service class.
+ */
+public class EventCreationService {
+
+ private static Log log = LogFactory.getLog(EventCreationService.class);
+
+ /**
+ * The publishEventNotification methods will call the dao layer to persist the event
+ * notifications for event polling request.
+ *
+ * @param notificationCreationDTO Notification creation DTO
+ * @return Event Response
+ * @throws FSEventNotificationException Exception when persisting event notification data
+ */
+ public String publishEventNotification(NotificationCreationDTO notificationCreationDTO)
+ throws FSEventNotificationException {
+
+ Connection connection = DatabaseUtils.getDBConnection();
+ Notification notification = getNotification(notificationCreationDTO);
+ ArrayList
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.service;
+
+import com.fasterxml.jackson.databind.JsonNode;
+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.model.NotificationResponse;
+
+import java.util.List;
+
+/**
+ * Interface for event notification generation. For custom class extensions the class name
+ * is to be referred from the event_notification_generator in deployment.toml
+ */
+public interface EventNotificationGenerator {
+
+ /**
+ * This method is to generate event notification body. To generate custom values
+ * for the body this method should be extended.
+ *
+ * @param notification Notification details
+ * @param notificationEventList List of notification events
+ * @return Event Notification Response Body
+ * @throws FSEventNotificationException Exception when generating event notification body
+ */
+ NotificationResponse generateEventNotificationBody(Notification notification, List
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.service;
+
+import com.nimbusds.jose.JOSEException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception;
+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.AggregatedPollingResponse;
+import org.wso2.financial.services.accelerator.event.notifications.service.model.EventPolling;
+import org.wso2.financial.services.accelerator.event.notifications.service.model.Notification;
+import org.wso2.financial.services.accelerator.event.notifications.service.model.NotificationError;
+import org.wso2.financial.services.accelerator.event.notifications.service.model.NotificationEvent;
+import org.wso2.financial.services.accelerator.event.notifications.service.model.NotificationResponse;
+import org.wso2.financial.services.accelerator.event.notifications.service.persistence.EventNotificationStoreInitializer;
+import org.wso2.financial.services.accelerator.event.notifications.service.util.EventNotificationServiceUtil;
+
+import java.io.IOException;
+import java.sql.Connection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * This is the event polling service.
+ */
+public class EventPollingService {
+
+ private static Log log = LogFactory.getLog(EventPollingService.class);
+
+ /**
+ * The pollEvents methods will return the Aggregated Polling Response for
+ * event polling request.
+ * @param eventPolling Event polling request
+ * @return AggregatedPollingResponse Aggregated Polling Response
+ * @throws FSEventNotificationException Exception when polling events
+ */
+ public AggregatedPollingResponse pollEvents(EventPolling eventPolling)
+ throws FSEventNotificationException {
+
+ Connection connection = DatabaseUtils.getDBConnection();
+ AggregatedPollingResponse aggregatedPollingResponse = new AggregatedPollingResponse();
+ EventNotificationDAO eventNotificationDAO = EventNotificationStoreInitializer.getEventNotificationDAO();
+
+ EventNotificationGenerator eventNotificationGenerator = EventNotificationServiceUtil.
+ getEventNotificationGenerator();
+
+ Map
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.service;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.json.JSONException;
+import org.json.JSONObject;
+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.EventSubscriptionDAO;
+import org.wso2.financial.services.accelerator.event.notifications.service.exception.FSEventNotificationException;
+import org.wso2.financial.services.accelerator.event.notifications.service.model.EventSubscription;
+import org.wso2.financial.services.accelerator.event.notifications.service.persistence.EventNotificationStoreInitializer;
+
+import java.sql.Connection;
+import java.util.List;
+
+/**
+ * This is the event subscription service class.
+ */
+public class EventSubscriptionService {
+ private static final Log log = LogFactory.getLog(EventSubscriptionService.class);
+
+ /**
+ * This method will call the dao layer to persist the event subscription.
+ *
+ * @param eventSubscription event subscription object that needs to be persisted
+ * @return event subscription object that is persisted
+ * @throws FSEventNotificationException if an error occurred while persisting the event subscription
+ */
+ public EventSubscription createEventSubscription(EventSubscription eventSubscription)
+ throws FSEventNotificationException {
+
+ EventSubscriptionDAO eventSubscriptionDAO = EventNotificationStoreInitializer.getEventSubscriptionDAO();
+
+ Connection connection = DatabaseUtils.getDBConnection();
+
+ try {
+ //store event subscription data in the database
+ EventSubscription storeEventSubscriptionResult = eventSubscriptionDAO.
+ storeEventSubscription(connection, eventSubscription);
+ //store subscribed event types in the database
+ if (eventSubscription.getEventTypes() != null && !eventSubscription.getEventTypes().isEmpty()) {
+ List
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.util;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.wso2.carbon.identity.application.common.model.ServiceProvider;
+import org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception;
+import org.wso2.carbon.identity.oauth2.util.OAuth2Util;
+import org.wso2.financial.services.accelerator.common.config.FinancialServicesConfigParser;
+import org.wso2.financial.services.accelerator.common.util.FinancialServicesUtils;
+import org.wso2.financial.services.accelerator.common.util.Generated;
+import org.wso2.financial.services.accelerator.consent.mgt.service.impl.ConsentCoreServiceImpl;
+import org.wso2.financial.services.accelerator.event.notifications.service.constants.EventNotificationConstants;
+import org.wso2.financial.services.accelerator.event.notifications.service.dto.EventNotificationErrorDTO;
+import org.wso2.financial.services.accelerator.event.notifications.service.exception.FSEventNotificationException;
+import org.wso2.financial.services.accelerator.event.notifications.service.handler.DefaultEventCreationServiceHandler;
+import org.wso2.financial.services.accelerator.event.notifications.service.service.EventNotificationGenerator;
+
+import java.util.Optional;
+
+/**
+ * Default event notification validations.
+ */
+public class EventNotificationServiceUtil {
+
+ private static final Log log = LogFactory.getLog(EventNotificationServiceUtil.class);
+ private static volatile ConsentCoreServiceImpl consentCoreService;
+
+ /**
+ * This method is used to send the polling generator as per config.
+ *
+ * @return EventNotificationGenerator
+ */
+ public static EventNotificationGenerator getEventNotificationGenerator() {
+
+ return (EventNotificationGenerator)
+ FinancialServicesUtils.getClassInstanceFromFQN(FinancialServicesConfigParser.getInstance()
+ .getEventNotificationGenerator());
+ }
+
+ /**
+ * This method is used to send the default realtime event notification request generator.
+ *
+ * @return RealtimeEventNotificationRequestGenerator
+ */
+ //TODO
+// public static RealtimeEventNotificationRequestGenerator getRealtimeEventNotificationRequestGenerator() {
+//
+// RealtimeEventNotificationRequestGenerator realtimeEventNotificationRequestGenerator =
+// (RealtimeEventNotificationRequestGenerator) FinancialServicesUtils
+// .getClassInstanceFromFQN(FinancialServicesConfigParser.getInstance().
+// getRealtimeEventNotificationRequestGenerator());
+// return realtimeEventNotificationRequestGenerator;
+// }
+
+ /**
+ * Method to modify event notification payload with custom eventValues.
+ *
+ * @param jsonNode Json Node to convert
+ * @return String eventNotificationPayload
+ */
+ public static String getCustomNotificationPayload(JsonNode jsonNode) {
+
+ return jsonNode.toString();
+ }
+
+ /**
+ * Method to get event JSON from eventInformation payload string.
+ * @param eventInformation String event Information
+ * @return JSONObject converted event json
+ * @throws JSONException Exception when parsing event information
+ */
+ public static JSONObject getEventJSONFromString(String eventInformation) throws JSONException {
+
+ return new JSONObject(eventInformation);
+ }
+
+ /**
+ * Validate if the client ID is existing.
+ * @param clientId client ID of the TPP
+ * @throws FSEventNotificationException Exception when validating client ID
+ */
+ @Generated(message = "Excluded since this needs OAuth2Util service provider")
+ public static void validateClientId(String clientId) throws FSEventNotificationException {
+
+ if (StringUtils.isNotEmpty(clientId)) {
+ Optional