+ * 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;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+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 java.time.Instant;
+import java.util.List;
+import java.util.UUID;
+
+/**
+ * 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;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+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.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;
+import java.util.UUID;
+
+/**
+ * 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;
+
+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;
+
+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;
+
+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.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 ERROR_FIELD = "error";
+ public static final String ERROR_DESCRIPTION_FIELD = "error_description";
+ 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_TYPES_PARAM = "eventTypes";
+ public static final String EVENT_TYPE_PARAM = "eventType";
+ 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 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 java.util.List;
+
+/**
+ * Event Subscription DTO.
+ */
+public class EventSubscriptionDTO {
+ private String clientId = null;
+ private String subscriptionId = null;
+ private String callbackUrl = null;
+ private String specVersion = 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.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 {
+
+ private int status;
+
+ public FSEventNotificationException(String message) {
+ super(message);
+ }
+
+ public FSEventNotificationException(int status, String message) {
+
+ super(message);
+ this.status = status;
+ }
+ public FSEventNotificationException(int status, String message, Throwable e) {
+
+ super(message, e);
+ this.status = status;
+ }
+
+ public FSEventNotificationException(String message, Throwable e) {
+ super(message, e);
+ }
+
+ public int getStatus() {
+ return status;
+ }
+
+ public void setStatus(int status) {
+ this.status = 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/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..3cfc755b
--- /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,103 @@
+/**
+ * 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.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.EventCreationService;
+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.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)
+ throws FSEventNotificationException {
+
+ //validate if the resourceID is existing
+ ConsentResource consentResource = null;
+ ConsentCoreServiceImpl consentCoreService = EventNotificationServiceUtil.getConsentCoreServiceImpl();
+
+ 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) {
+ String errorMsg = String.format("A resource was not found for the resource id : '%s' in the database. ",
+ notificationCreationDTO.getResourceId().replaceAll("[\r\n]", ""));
+ log.error(errorMsg, e);
+ throw new FSEventNotificationException(HttpStatus.SC_BAD_REQUEST, errorMsg, e);
+ }
+
+ //validate if the clientID is existing
+ try {
+ EventNotificationServiceUtil.validateClientId(notificationCreationDTO.getClientId());
+
+ } catch (FSEventNotificationException e) {
+ String errorMsg = String.format("A client was not found" + " for the client id : '%s' in the database. ",
+ notificationCreationDTO.getClientId().replaceAll("[\r\n]", ""));
+ log.error(errorMsg, e);
+ throw new FSEventNotificationException(HttpStatus.SC_BAD_REQUEST, errorMsg, e);
+ }
+
+ String registrationResponse = "";
+ try {
+ registrationResponse = eventCreationService.publishEventNotification(notificationCreationDTO);
+ JSONObject responseJSON = new JSONObject();
+ responseJSON.put(EventNotificationConstants.NOTIFICATIONS_ID, registrationResponse);
+
+ EventCreationResponse eventCreationResponse = new EventCreationResponse();
+ eventCreationResponse.setStatus(EventNotificationConstants.CREATED);
+ eventCreationResponse.setResponseBody(responseJSON);
+ return eventCreationResponse;
+
+ } catch (FSEventNotificationException e) {
+ log.error("FS Event Notification Creation error", e);
+ throw new FSEventNotificationException(HttpStatus.SC_BAD_REQUEST, "FS Event Notification Creation error",
+ 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/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..19237fb1
--- /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,113 @@
+/**
+ * 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.common.config.FinancialServicesConfigParser;
+import org.wso2.financial.services.accelerator.common.util.Generated;
+import org.wso2.financial.services.accelerator.event.notifications.service.EventPollingService;
+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.util.EventNotificationServiceUtil;
+
+/**
+ * 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) throws FSEventNotificationException {
+
+ //Validate clientID of the polling request
+ try {
+ EventNotificationServiceUtil.validateClientId(eventPollingDTO.getClientId());
+ } catch (FSEventNotificationException e) {
+ String errorMessage = String.format("A client was not found for the client id : '%s' in the database. ",
+ eventPollingDTO.getClientId().replaceAll("[\r\n]", ""));
+ log.error(errorMessage, e);
+ throw new FSEventNotificationException(HttpStatus.SC_BAD_REQUEST, errorMessage, e);
+ }
+
+ EventPolling eventPolling = mapEventPollingDtoToModel(eventPollingDTO);
+ //Poll events
+ try {
+ AggregatedPollingResponse aggregatedPollingResponse = eventPollingService.pollEvents(eventPolling);
+
+ EventPollingResponse eventPollingResponse = new EventPollingResponse();
+ eventPollingResponse.setStatus(aggregatedPollingResponse.getStatus());
+ eventPollingResponse.setResponseBody(getPollingResponseJSON(aggregatedPollingResponse));
+ return eventPollingResponse;
+ } catch (FSEventNotificationException e) {
+ log.error("OB Event Notification error" , e);
+ throw new FSEventNotificationException(HttpStatus.SC_BAD_REQUEST, e.getMessage(), e);
+ }
+
+ }
+
+ /**
+ * 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;
+ }
+
+ @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..7488ec42
--- /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,284 @@
+/**
+ * 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.EventSubscriptionService;
+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.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;
+ }
+
+ @Override
+ public EventSubscriptionResponse createEventSubscription(EventSubscriptionDTO eventSubscriptionRequestDto)
+ throws FSEventNotificationException {
+
+ try {
+ EventNotificationServiceUtil.validateClientId(eventSubscriptionRequestDto.getClientId());
+
+ } catch (FSEventNotificationException e) {
+ String errorMsg = String.format("A client was not found" + " for the client id : '%s' in the database. ",
+ eventSubscriptionRequestDto.getClientId().replaceAll("[\r\n]", ""));
+ log.error(errorMsg, e);
+ throw new FSEventNotificationException(HttpStatus.SC_BAD_REQUEST, errorMsg, e);
+ }
+
+ try {
+ EventSubscription eventSubscriptionCreateResponse = eventSubscriptionService.
+ createEventSubscription(mapEventSubscriptionDtoToModel(eventSubscriptionRequestDto));
+
+ EventSubscriptionResponse eventSubscriptionResponse = new EventSubscriptionResponse();
+ eventSubscriptionResponse.setResponseStatus(HttpStatus.SC_CREATED);
+ eventSubscriptionResponse
+ .setResponseBody(mapSubscriptionModelToResponseJson(eventSubscriptionCreateResponse));
+ return eventSubscriptionResponse;
+ } catch (FSEventNotificationException e) {
+ log.error("Error occurred while creating event subscription", e);
+ throw new FSEventNotificationException(HttpStatus.SC_INTERNAL_SERVER_ERROR, e.getMessage(), e);
+ }
+ }
+
+ @Override
+ public EventSubscriptionResponse getEventSubscription(String clientId, String subscriptionId)
+ throws FSEventNotificationException {
+
+ try {
+ EventNotificationServiceUtil.validateClientId(clientId);
+
+ } catch (FSEventNotificationException e) {
+ String errorMsg = String.format("A client was not found" + " for the client id : '%s' in the database. ",
+ clientId.replaceAll("[\r\n]", ""));
+ log.error(errorMsg, e);
+ throw new FSEventNotificationException(HttpStatus.SC_BAD_REQUEST, errorMsg, e);
+ }
+
+ try {
+ EventSubscription eventSubscription = eventSubscriptionService.
+ getEventSubscriptionBySubscriptionId(subscriptionId);
+
+ EventSubscriptionResponse eventSubscriptionResponse = new EventSubscriptionResponse();
+ eventSubscriptionResponse.setResponseStatus(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)) {
+ throw new FSEventNotificationException(HttpStatus.SC_BAD_REQUEST, e.getMessage(), e);
+ } else {
+ throw new FSEventNotificationException(HttpStatus.SC_INTERNAL_SERVER_ERROR, e.getMessage(), e);
+ }
+ }
+ }
+
+ @Override
+ public EventSubscriptionResponse getAllEventSubscriptions(String clientId)
+ throws FSEventNotificationException {
+
+ try {
+ EventNotificationServiceUtil.validateClientId(clientId);
+
+ } catch (FSEventNotificationException e) {
+ String errorMsg = String.format("A client was not found" + " for the client id : '%s' in the database. ",
+ clientId.replaceAll("[\r\n]", ""));
+ log.error(errorMsg, e);
+ throw new FSEventNotificationException(HttpStatus.SC_BAD_REQUEST, errorMsg, e);
+ }
+
+ 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.exception.FSEventNotificationException;
+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
+ * @throws FSEventNotificationException Exception when creating event
+ */
+ EventCreationResponse publishEvent(NotificationCreationDTO notificationCreationDTO)
+ throws FSEventNotificationException;
+
+}
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..a87639a1
--- /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,41 @@
+/**
+ * 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.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.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.
+ * @throws FSEventNotificationException Exception when polling events
+ */
+ EventPollingResponse pollEvents(EventPollingDTO eventPollingDTO) throws FSEventNotificationException;
+
+}
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..6a5178fa
--- /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,96 @@
+/**
+ * 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.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.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
+ * @throws FSEventNotificationException Exception when creating event subscription.
+ */
+ EventSubscriptionResponse createEventSubscription(EventSubscriptionDTO eventSubscriptionRequestDto)
+ throws FSEventNotificationException;
+
+ /**
+ * 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.
+ * @throws FSEventNotificationException Exception when retrieving event subscription.
+ */
+ EventSubscriptionResponse getEventSubscription(String clientId, String subscriptionId)
+ throws FSEventNotificationException;
+
+ /**
+ * 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.
+ * @throws FSEventNotificationException Exception when retrieving event subscriptions.
+ */
+ EventSubscriptionResponse getAllEventSubscriptions(String clientId) throws FSEventNotificationException;
+
+ /**
+ * 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.
+ * @throws FSEventNotificationException Exception when retrieving event subscriptions.
+ */
+ EventSubscriptionResponse getEventSubscriptionsByEventType(String clientId, String eventType)
+ throws FSEventNotificationException;
+
+ /**
+ * 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.
+ * @throws FSEventNotificationException Exception when updating event subscription.
+ */
+ EventSubscriptionResponse updateEventSubscription(EventSubscriptionDTO eventSubscriptionUpdateRequestDto)
+ throws FSEventNotificationException;
+
+ /**
+ * 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.
+ * @throws FSEventNotificationException Exception when deleting event subscription.
+ */
+ EventSubscriptionResponse deleteEventSubscription(String clientId, String subscriptionId)
+ throws FSEventNotificationException;
+
+}
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..d6124767
--- /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,98 @@
+/**
+ * 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) {
+ 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 JSONObject errorResponse;
+
+ public JSONObject getErrorResponse() {
+ return errorResponse;
+ }
+
+ public void setErrorResponse(JSONObject 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 JSONObject 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 JSONObject getErrorResponse() {
+ return errorResponse;
+ }
+
+ public void setErrorResponse(JSONObject 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..a870be05
--- /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,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.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 responseStatus;
+ private Object responseBody;
+
+
+ public int getResponseStatus() {
+ return responseStatus;
+ }
+
+ public void setResponseStatus(int responseStatus) {
+ this.responseStatus = responseStatus;
+ }
+
+ public Object getResponseBody() {
+ return responseBody;
+ }
+
+ public void setResponseBody(Object 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/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/util/EventNotificationServiceUtil.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/util/EventNotificationServiceUtil.java
new file mode 100644
index 00000000..b3916f14
--- /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/util/EventNotificationServiceUtil.java
@@ -0,0 +1,144 @@
+/**
+ * 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.util;
+
+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.EventNotificationGenerator;
+import org.wso2.financial.services.accelerator.event.notifications.service.constants.EventNotificationConstants;
+import org.wso2.financial.services.accelerator.event.notifications.service.exception.FSEventNotificationException;
+
+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 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