diff --git a/open-banking-accelerator/accelerators/ob-is/carbon-home/dbscripts/open-banking/event-notifications/mssql.sql b/open-banking-accelerator/accelerators/ob-is/carbon-home/dbscripts/open-banking/event-notifications/mssql.sql new file mode 100644 index 00000000..428f201f --- /dev/null +++ b/open-banking-accelerator/accelerators/ob-is/carbon-home/dbscripts/open-banking/event-notifications/mssql.sql @@ -0,0 +1,66 @@ +/** + * 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. + */ + +-- All the data related to time are stored in unix time stamp and therefore, the data types for the time related data +-- are represented in BIGINT. +-- Since the database systems does not support adding default unix time to the database columns, the default data +-- storing is handled within the database querieS. + +CREATE TABLE OB_NOTIFICATION ( + NOTIFICATION_ID varchar(36) NOT NULL, + CLIENT_ID varchar(255) NOT NULL, + RESOURCE_ID varchar(255) NOT NULL, + STATUS varchar(10) NOT NULL, + UPDATED_TIMESTAMP DATETIME2(0) DEFAULT GETDATE(), + PRIMARY KEY (NOTIFICATION_ID) +); + +CREATE TABLE OB_NOTIFICATION_EVENT ( + EVENT_ID int NOT NULL IDENTITY, + NOTIFICATION_ID varchar(36) NOT NULL, + EVENT_TYPE varchar(200) NOT NULL, + EVENT_INFO varchar(1000) NOT NULL, + PRIMARY KEY (EVENT_ID), + CONSTRAINT FK_NotificationEvent FOREIGN KEY (NOTIFICATION_ID) REFERENCES OB_NOTIFICATION(NOTIFICATION_ID) +); + +CREATE TABLE OB_NOTIFICATION_ERROR ( + NOTIFICATION_ID varchar(36) NOT NULL, + ERROR_CODE varchar(255) NOT NULL, + DESCRIPTION varchar(255) NOT NULL, + PRIMARY KEY (NOTIFICATION_ID), + CONSTRAINT FK_NotificationError FOREIGN KEY (NOTIFICATION_ID) REFERENCES OB_NOTIFICATION(NOTIFICATION_ID) +); + +CREATE TABLE OB_NOTIFICATION_SUBSCRIPTION ( + SUBSCRIPTION_ID varchar(36) NOT NULL, + CLIENT_ID varchar(255) NOT NULL, + REQUEST JSON NOT NULL, + CALLBACK_URL varchar(255), + TIMESTAMP BIGINT NOT NULL, + SPEC_VERSION varchar(255), + STATUS varchar(255) NOT NULL, + PRIMARY KEY (SUBSCRIPTION_ID) +); + +CREATE TABLE OB_NOTIFICATION_SUBSCRIBED_EVENTS ( + SUBSCRIPTION_ID varchar(36) NOT NULL, + EVENT_TYPE varchar(255) NOT NULL, + PRIMARY KEY (SUBSCRIPTION_ID, EVENT_TYPE), + CONSTRAINT FK_NotificationSubEvents FOREIGN KEY (SUBSCRIPTION_ID) REFERENCES OB_NOTIFICATION_SUBSCRIPTION(SUBSCRIPTION_ID) +); diff --git a/open-banking-accelerator/accelerators/ob-is/carbon-home/dbscripts/open-banking/event-notifications/mysql.sql b/open-banking-accelerator/accelerators/ob-is/carbon-home/dbscripts/open-banking/event-notifications/mysql.sql new file mode 100644 index 00000000..1da13b5c --- /dev/null +++ b/open-banking-accelerator/accelerators/ob-is/carbon-home/dbscripts/open-banking/event-notifications/mysql.sql @@ -0,0 +1,73 @@ +/** + * 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. + */ + +-- All the data related to time are stored in unix time stamp and therefore, the data types for the time related data +-- are represented in BIGINT. +-- Since the database systems does not support adding default unix time to the database columns, the default data +-- storing is handled within the database querieS. + +-- For event notifications feature run the following queries against the openbank_openbankingdb-- + +CREATE TABLE IF NOT EXISTS OB_NOTIFICATION ( + NOTIFICATION_ID varchar(36) NOT NULL, + CLIENT_ID varchar(255) NOT NULL, + RESOURCE_ID varchar(255) NOT NULL, + STATUS varchar(10) NOT NULL, + UPDATED_TIMESTAMP TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + PRIMARY KEY (NOTIFICATION_ID) +) +ENGINE=InnoDB; + +CREATE TABLE IF NOT EXISTS OB_NOTIFICATION_EVENT ( + EVENT_ID int(11) NOT NULL AUTO_INCREMENT, + NOTIFICATION_ID varchar(36) NOT NULL, + EVENT_TYPE varchar(200) NOT NULL, + EVENT_INFO varchar(1000) NOT NULL, + PRIMARY KEY (EVENT_ID), + CONSTRAINT FK_NotificationEvent FOREIGN KEY (NOTIFICATION_ID) REFERENCES OB_NOTIFICATION(NOTIFICATION_ID) +) +ENGINE=InnoDB; + +CREATE TABLE IF NOT EXISTS OB_NOTIFICATION_ERROR ( + NOTIFICATION_ID varchar(36) NOT NULL, + ERROR_CODE varchar(255) NOT NULL, + DESCRIPTION varchar(255) NOT NULL, + PRIMARY KEY (NOTIFICATION_ID), + CONSTRAINT FK_NotificationError FOREIGN KEY (NOTIFICATION_ID) REFERENCES OB_NOTIFICATION(NOTIFICATION_ID) +) +ENGINE=InnoDB; + +CREATE TABLE IF NOT EXISTS OB_NOTIFICATION_SUBSCRIPTION ( + SUBSCRIPTION_ID varchar(36) NOT NULL, + CLIENT_ID varchar(255) NOT NULL, + REQUEST JSON NOT NULL, + CALLBACK_URL varchar(255), + TIMESTAMP BIGINT NOT NULL, + SPEC_VERSION varchar(255), + STATUS varchar(255) NOT NULL, + PRIMARY KEY (SUBSCRIPTION_ID) +) +ENGINE=InnoDB; + +CREATE TABLE IF NOT EXISTS OB_NOTIFICATION_SUBSCRIBED_EVENTS ( + SUBSCRIPTION_ID varchar(36) NOT NULL, + EVENT_TYPE varchar(255) NOT NULL, + PRIMARY KEY (SUBSCRIPTION_ID, EVENT_TYPE), + CONSTRAINT FK_NotificationSubEvents FOREIGN KEY (SUBSCRIPTION_ID) REFERENCES OB_NOTIFICATION_SUBSCRIPTION(SUBSCRIPTION_ID) +) +ENGINE=InnoDB; diff --git a/open-banking-accelerator/accelerators/ob-is/carbon-home/dbscripts/open-banking/event-notifications/oracle.sql b/open-banking-accelerator/accelerators/ob-is/carbon-home/dbscripts/open-banking/event-notifications/oracle.sql new file mode 100644 index 00000000..478fb598 --- /dev/null +++ b/open-banking-accelerator/accelerators/ob-is/carbon-home/dbscripts/open-banking/event-notifications/oracle.sql @@ -0,0 +1,76 @@ +/** + * 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. + */ + +-- All the data related to time are stored in unix time stamp and therefore, the data types for the time related data +-- are represented in BIGINT. +-- Since the database systems does not support adding default unix time to the database columns, the default data +-- storing is handled within the database querieS. + +CREATE TABLE OB_NOTIFICATION ( + NOTIFICATION_ID varchar2(36) NOT NULL, + CLIENT_ID varchar2(255) NOT NULL, + RESOURCE_ID varchar2(255) NOT NULL, + STATUS varchar2(10) NOT NULL, + UPDATED_TIMESTAMP TIMESTAMP(0) DEFAULT SYSTIMESTAMP, + PRIMARY KEY (NOTIFICATION_ID) +); + +CREATE TABLE OB_NOTIFICATION_EVENT ( + EVENT_ID number(10) NOT NULL, + NOTIFICATION_ID varchar2(36) NOT NULL, + EVENT_TYPE varchar2(200) NOT NULL, + EVENT_INFO varchar2(1000) NOT NULL, + PRIMARY KEY (EVENT_ID), + CONSTRAINT FK_NotificationEvent FOREIGN KEY (NOTIFICATION_ID) REFERENCES OB_NOTIFICATION(NOTIFICATION_ID) +); + +-- Generate ID using sequence and trigger +CREATE SEQUENCE OB_NOTIFICATION_EVENT_seq START WITH 1 INCREMENT BY 1; + +CREATE OR REPLACE TRIGGER OB_NOTIFICATION_EVENT_seq_tr + BEFORE INSERT ON OB_NOTIFICATION_EVENT FOR EACH ROW + WHEN (NEW.EVENT_ID IS NULL) +BEGIN + SELECT OB_NOTIFICATION_EVENT_seq.NEXTVAL INTO :NEW.EVENT_ID FROM DUAL; +END; + +CREATE TABLE OB_NOTIFICATION_ERROR ( + NOTIFICATION_ID varchar2(36) NOT NULL, + ERROR_CODE varchar2(255) NOT NULL, + DESCRIPTION varchar2(255) NOT NULL, + PRIMARY KEY (NOTIFICATION_ID), + CONSTRAINT FK_NotificationError FOREIGN KEY (NOTIFICATION_ID) REFERENCES OB_NOTIFICATION(NOTIFICATION_ID) +) + +CREATE TABLE OB_NOTIFICATION_SUBSCRIPTION ( + SUBSCRIPTION_ID varchar(36) NOT NULL, + CLIENT_ID varchar(255) NOT NULL, + REQUEST JSON NOT NULL, + CALLBACK_URL varchar(255), + TIMESTAMP BIGINT NOT NULL, + SPEC_VERSION varchar(255), + STATUS varchar(255) NOT NULL, + PRIMARY KEY (SUBSCRIPTION_ID) +); + +CREATE TABLE OB_NOTIFICATION_SUBSCRIBED_EVENTS ( + SUBSCRIPTION_ID varchar(36) NOT NULL, + EVENT_TYPE varchar(255) NOT NULL, + PRIMARY KEY (SUBSCRIPTION_ID, EVENT_TYPE), + CONSTRAINT FK_NotificationSubEvents FOREIGN KEY (SUBSCRIPTION_ID) REFERENCES OB_NOTIFICATION_SUBSCRIPTION(SUBSCRIPTION_ID) +); diff --git a/open-banking-accelerator/accelerators/ob-is/carbon-home/dbscripts/open-banking/event-notifications/postgresql.sql b/open-banking-accelerator/accelerators/ob-is/carbon-home/dbscripts/open-banking/event-notifications/postgresql.sql new file mode 100644 index 00000000..fb616f99 --- /dev/null +++ b/open-banking-accelerator/accelerators/ob-is/carbon-home/dbscripts/open-banking/event-notifications/postgresql.sql @@ -0,0 +1,67 @@ +/** + * 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. + */ + +-- All the data related to time are stored in unix time stamp and therefore, the data types for the time related data +-- are represented in BIGINT. +-- Since the database systems does not support adding default unix time to the database columns, the default data +-- storing is handled within the database querieS. + +-- For event notifications feature run the following queries against the openbank_openbankingdb-- + +CREATE TABLE IF NOT EXISTS OB_NOTIFICATION ( + NOTIFICATION_ID varchar(36) NOT NULL, + CLIENT_ID varchar(255) NOT NULL, + RESOURCE_ID varchar(255) NOT NULL, + STATUS varchar(10) NOT NULL, + UPDATED_TIMESTAMP TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (NOTIFICATION_ID) +); + +CREATE TABLE IF NOT EXISTS OB_NOTIFICATION_EVENT ( + EVENT_ID SERIAL PRIMARY KEY, + NOTIFICATION_ID varchar(36) NOT NULL, + EVENT_TYPE varchar(200) NOT NULL, + EVENT_INFO varchar(1000) NOT NULL, + CONSTRAINT FK_NotificationEvent FOREIGN KEY (NOTIFICATION_ID) REFERENCES OB_NOTIFICATION(NOTIFICATION_ID) +); + +CREATE TABLE IF NOT EXISTS OB_NOTIFICATION_ERROR ( + NOTIFICATION_ID varchar(36) NOT NULL, + ERROR_CODE varchar(255) NOT NULL, + DESCRIPTION varchar(255) NOT NULL, + PRIMARY KEY (NOTIFICATION_ID), + CONSTRAINT FK_NotificationError FOREIGN KEY (NOTIFICATION_ID) REFERENCES OB_NOTIFICATION(NOTIFICATION_ID) +); + +CREATE TABLE IF NOT EXISTS OB_NOTIFICATION_SUBSCRIPTION ( + SUBSCRIPTION_ID varchar(36) NOT NULL, + CLIENT_ID varchar(255) NOT NULL, + REQUEST JSON NOT NULL, + CALLBACK_URL varchar(255), + TIMESTAMP BIGINT NOT NULL, + SPEC_VERSION varchar(255), + STATUS varchar(255) NOT NULL, + PRIMARY KEY (SUBSCRIPTION_ID) +); + +CREATE TABLE IF NOT EXISTS OB_NOTIFICATION_SUBSCRIBED_EVENTS ( + SUBSCRIPTION_ID varchar(36) NOT NULL, + EVENT_TYPE varchar(255) NOT NULL, + PRIMARY KEY (SUBSCRIPTION_ID, EVENT_TYPE), + CONSTRAINT FK_NotificationSubEvents FOREIGN KEY (SUBSCRIPTION_ID) REFERENCES OB_NOTIFICATION_SUBSCRIPTION(SUBSCRIPTION_ID) +); diff --git a/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/constants/EventNotificationConstants.java b/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/constants/EventNotificationConstants.java index 12124024..835e2248 100644 --- a/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/constants/EventNotificationConstants.java +++ b/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/constants/EventNotificationConstants.java @@ -114,5 +114,5 @@ public class EventNotificationConstants { 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"; + "subscription request"; } diff --git a/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/dao/AggregatedPollingDAO.java b/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/dao/AggregatedPollingDAO.java index 41c80dd2..8f98a2ad 100644 --- a/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/dao/AggregatedPollingDAO.java +++ b/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/dao/AggregatedPollingDAO.java @@ -35,18 +35,19 @@ public interface AggregatedPollingDAO { * This method is to update the notification status by ID, allowed values are. * OPEN,ACK and ERR * - * @param notificationId - * @param notificationStatus - * @return + * @param notificationId Notification ID to update + * @param notificationStatus Notification status to update + * @return Update is success or not * @throws OBEventNotificationException */ Boolean updateNotificationStatusById(String notificationId, String notificationStatus) throws OBEventNotificationException; /** - * This method is to store event notifications in the OB_NOTIFICATION table. - * @param notificationError - * @return + * This method is to store event notifications error details in the OB_NOTIFICATION table. + * + * @param notificationError Notification error details + * @return Stored event notifications error details * @throws OBEventNotificationException */ Map storeErrorNotification(NotificationError notificationError) @@ -54,10 +55,11 @@ Map storeErrorNotification(NotificationError notifica /** * This method is to retrieve given number of notifications in the OB_NOTIFICATION table by client and status. - * @param clientId - * @param status - * @param max - * @return + * + * @param clientId Client ID to retrieve notifications + * @param status Notification status to retrieve + * @param max Maximum number of notifications to retrieve + * @return List of notifications by client and status * @throws OBEventNotificationException */ List getNotificationsByClientIdAndStatus(String clientId, String @@ -65,28 +67,28 @@ List getNotificationsByClientIdAndStatus(String clientId, Strin /** * This method is to retrieve notifications by NotificationID. - * @param notificationId * - * @return + * @param notificationId Notification ID to retrieve + * @return List of notifications by notification ID * @throws OBEventNotificationException */ List getEventsByNotificationID(String notificationId) throws OBEventNotificationException; /** * This method is to retrieve notifications in the OB_NOTIFICATION table by status. - * @param status * - * @return List + * @param status Notification status to retrieve + * @return List of notifications by status * @throws OBEventNotificationException */ List getNotificationsByStatus(String status) throws OBEventNotificationException; /** * This method is to retrieve notificationsCount by ClientId and Status. - * @param clientId - * @param eventStatus * - * @return + * @param clientId Client ID to retrieve notifications + * @param eventStatus Notification status to retrieve + * @return List of notifications by status and client id * @throws OBEventNotificationException */ int getNotificationCountByClientIdAndStatus(String clientId, String eventStatus) @@ -94,9 +96,9 @@ int getNotificationCountByClientIdAndStatus(String clientId, String eventStatus) /** * This method is to retrieve the notification status. - * @param notificationId * - * @return + * @param notificationId Notification ID to retrieve + * @return Notification status by notification ID * @throws OBEventNotificationException */ boolean getNotificationStatus(String notificationId) throws OBEventNotificationException; diff --git a/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/dao/AggregatedPollingDAOImpl.java b/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/dao/AggregatedPollingDAOImpl.java index 57708a1e..a14b74b7 100644 --- a/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/dao/AggregatedPollingDAOImpl.java +++ b/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/dao/AggregatedPollingDAOImpl.java @@ -61,7 +61,7 @@ public Boolean updateNotificationStatusById(String notificationId, String notifi Connection connection = DatabaseUtil.getDBConnection(); if (log.isDebugEnabled()) { log.debug(String.format("Database connection is established for updating notification with " + - "ID : '%s' in the database. ", notificationId)); + "ID : '%s' in the database. ", notificationId.replaceAll("[\r\n]", ""))); } try { connection.setAutoCommit(false); @@ -78,32 +78,31 @@ public Boolean updateNotificationStatusById(String notificationId, String notifi if (affectedRows != 0) { connection.commit(); if (log.isDebugEnabled()) { - log.debug("Updated notification with Notification ID : " + notificationId); + log.debug(String.format("Updated notification with Notification ID '%s'", + notificationId.replaceAll("[\r\n]", ""))); } return true; } else { if (log.isDebugEnabled()) { - log.debug("Failed updating notification with ID : " + notificationId); + log.debug(String.format("Failed updating notification with ID : '%s'", + notificationId.replaceAll("[\r\n]", ""))); } return false; } } catch (SQLException e) { connection.rollback(savepoint); - log.error(String.format(EventNotificationConstants.DB_ERROR_UPDATING, notificationId), e); + log.error(String.format(EventNotificationConstants.DB_ERROR_UPDATING, + notificationId.replaceAll("[\r\n]", "")), e); throw new OBEventNotificationException(String.format(EventNotificationConstants.DB_ERROR_UPDATING, notificationId)); } } catch (SQLException e) { - if (log.isDebugEnabled()) { - log.debug("SQL exception when updating notification status", e); - } + log.debug("SQL exception when updating notification status", e); throw new OBEventNotificationException("Database error while closing the connection to the" + " the database."); } finally { - if (log.isDebugEnabled()) { - log.debug(EventNotificationConstants.DATABASE_CONNECTION_CLOSE_LOG_MSG); - } + log.debug(EventNotificationConstants.DATABASE_CONNECTION_CLOSE_LOG_MSG); DatabaseUtil.closeConnection(connection); } } @@ -119,8 +118,9 @@ public Map storeErrorNotification(NotificationError n connection.setAutoCommit(false); if (log.isDebugEnabled()) { - log.debug("Database connection is established for storing error notification with ID : " - + notificationError.getNotificationId()); + log.debug(String.format("Database connection is established for storing error notification with ID" + + " : '%s' in the database. ", + notificationError.getNotificationId().replaceAll("[\r\n]", ""))); } final String storeErrorNotificationQuery = sqlStatements.storeErrorNotificationQuery(); @@ -138,14 +138,14 @@ public Map storeErrorNotification(NotificationError n if (affectedRows == 1) { connection.commit(); if (log.isDebugEnabled()) { - log.debug("Successfully stored error notification with ID : " + - notificationError.getNotificationId()); + log.debug(String.format("Successfully stored error notification with ID:'%s'.", + notificationError.getNotificationId().replaceAll("[\r\n]", ""))); } response.put(notificationError.getNotificationId(), notificationError); } else { if (log.isDebugEnabled()) { - log.debug(EventNotificationConstants.DB_FAILED_ERROR_NOTIFICATION_STORING - + notificationError.getNotificationId()); + log.debug(String.format("Failed store error notification with ID:'%s'.", + notificationError.getNotificationId().replaceAll("[\r\n]", ""))); } throw new OBEventNotificationException(EventNotificationConstants. DB_FAILED_ERROR_NOTIFICATION_STORING + notificationError.getNotificationId()); @@ -176,7 +176,8 @@ public List getNotificationsByClientIdAndStatus(String clientId notificationList = new ArrayList<>(); if (log.isDebugEnabled()) { - log.debug(String.format(EventNotificationConstants.DB_CONN_ESTABLISHED, clientId)); + log.debug(String.format(EventNotificationConstants.DB_CONN_ESTABLISHED, + clientId.replaceAll("[\r\n]", ""))); } final String sql = sqlStatements.getMaxNotificationsQuery(); @@ -215,12 +216,12 @@ public List getNotificationsByClientIdAndStatus(String clientId if (log.isDebugEnabled()) { log.debug(String.format(EventNotificationConstants.RETRIEVED_NOTIFICATION_CLIENT, - clientId)); + clientId.replaceAll("[\r\n]", ""))); } } else { if (log.isDebugEnabled()) { log.debug(String.format(EventNotificationConstants.NO_NOTIFICATIONS_FOUND_CLIENT, - clientId)); + clientId.replaceAll("[\r\n]", ""))); } } } @@ -268,7 +269,7 @@ public List getEventsByNotificationID(String notificationId) (EventNotificationConstants.EVENT_TYPE)); event.setEventInformation(EventNotificationServiceUtil. getEventJSONFromString(eventsResultSet.getString - (EventNotificationConstants.EVENT_INFO))); + (EventNotificationConstants.EVENT_INFO))); eventList.add(event); } eventsResultSet.close(); @@ -276,21 +277,23 @@ public List getEventsByNotificationID(String notificationId) if (log.isDebugEnabled()) { log.debug(String.format(EventNotificationConstants.RETRIEVED_EVENTS_NOTIFICATION, - notificationId)); + notificationId.replaceAll("[\r\n]", ""))); } } else { if (log.isDebugEnabled()) { log.debug(String.format(EventNotificationConstants.NO_EVENTS_NOTIFICATION_ID, - notificationId)); + notificationId.replaceAll("[\r\n]", ""))); } } } catch (ParseException e) { - log.error(String.format(EventNotificationConstants.PARSE_ERROR_NOTIFICATION_ID, notificationId), e); + log.error(String.format(EventNotificationConstants.PARSE_ERROR_NOTIFICATION_ID, + notificationId.replaceAll("[\r\n]", "")), e); throw new OBEventNotificationException(String.format ( EventNotificationConstants.PARSE_ERROR_NOTIFICATION_ID, notificationId), e); } } catch (SQLException e) { - log.error(String.format(EventNotificationConstants.DB_ERROR_EVENTS_RETRIEVE, notificationId), e); + log.error(String.format(EventNotificationConstants.DB_ERROR_EVENTS_RETRIEVE, + notificationId.replaceAll("[\r\n]", "")), e); throw new OBEventNotificationException(String.format (EventNotificationConstants.DB_ERROR_EVENTS_RETRIEVE, notificationId), e); } @@ -337,7 +340,8 @@ public List getNotificationsByStatus(String status) throws OBEv notificationResultSet.close(); getNotificationsPreparedStatement.close(); if (log.isDebugEnabled()) { - log.debug(EventNotificationConstants.RETRIEVED_NOTIFICATION_CLIENT); + log.debug( + EventNotificationConstants.RETRIEVED_NOTIFICATION_CLIENT); } } else { if (log.isDebugEnabled()) { @@ -378,7 +382,7 @@ public int getNotificationCountByClientIdAndStatus(String clientId, String event if (log.isDebugEnabled()) { log.debug(String.format("Retrieved notification count for client ID: '%s'. ", - clientId)); + clientId.replaceAll("[\r\n]", ""))); } return count; @@ -386,7 +390,7 @@ public int getNotificationCountByClientIdAndStatus(String clientId, String event if (log.isDebugEnabled()) { log.debug(String.format( EventNotificationConstants.NO_NOTIFICATIONS_FOUND_CLIENT, - clientId)); + clientId.replaceAll("[\r\n]", ""))); } return 0; @@ -394,8 +398,7 @@ public int getNotificationCountByClientIdAndStatus(String clientId, String event } } catch (SQLException e) { throw new OBEventNotificationException(String.format - (EventNotificationConstants.DB_ERROR_NOTIFICATION_RETRIEVE, - clientId), e); + (EventNotificationConstants.DB_ERROR_NOTIFICATION_RETRIEVE, clientId), e); } } finally { log.debug(EventNotificationConstants.DATABASE_CONNECTION_CLOSE_LOG_MSG); @@ -422,13 +425,14 @@ public boolean getNotificationStatus(String notificationId) throws OBEventNotifi isOpenStatus = true; } - return isOpenStatus; - } else { - if (log.isDebugEnabled()) { - log.debug("No notifications found for notification ID : " + notificationId); - } - } - } + return isOpenStatus; + } else { + if (log.isDebugEnabled()) { + log.debug(String.format("No notifications found for notification ID - '%s'", + notificationId.replaceAll("[\r\n]", ""))); + } + } + } } catch (SQLException e) { throw new OBEventNotificationException(String.format ("Error occurred while retrieving status for the notifications ID : '%s'.", diff --git a/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/dao/EventPublisherDAO.java b/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/dao/EventPublisherDAO.java index 7e59e93c..a410b770 100644 --- a/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/dao/EventPublisherDAO.java +++ b/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/dao/EventPublisherDAO.java @@ -32,9 +32,9 @@ public interface EventPublisherDAO { /** * This method is used to persist event notifications in the database. - * @param connection - * @param notificationDTO - * @param eventsList + * @param connection Database connection + * @param notificationDTO Notification details DTO + * @param eventsList List of notification events * @return NotificationID of the saved notification. * @throws OBEventNotificationException */ diff --git a/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/dao/EventSubscriptionSqlStatements.java b/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/dao/EventSubscriptionSqlStatements.java index 0e052546..855cbde9 100644 --- a/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/dao/EventSubscriptionSqlStatements.java +++ b/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/dao/EventSubscriptionSqlStatements.java @@ -24,48 +24,48 @@ public class EventSubscriptionSqlStatements { public String storeEventSubscriptionQuery() { - return "INSERT INTO NOTIFICATION_SUBSCRIPTION (SUBSCRIPTION_ID, CLIENT_ID, CALLBACK_URL, TIMESTAMP, " + + return "INSERT INTO OB_NOTIFICATION_SUBSCRIPTION (SUBSCRIPTION_ID, CLIENT_ID, CALLBACK_URL, TIMESTAMP, " + "SPEC_VERSION, STATUS, REQUEST) VALUES (?,?,?,?,?,?,?)"; } public String storeSubscribedEventTypesQuery() { - return "INSERT INTO NOTIFICATION_SUBSCRIPTION_EVENTS (SUBSCRIPTION_ID, EVENT_TYPE) VALUES (?,?)"; + return "INSERT INTO OB_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 NOTIFICATION_SUBSCRIPTION ns LEFT JOIN " + - "NOTIFICATION_SUBSCRIPTION_EVENTS nse ON ns.SUBSCRIPTION_ID = nse.SUBSCRIPTION_ID WHERE " + + "ns.STATUS, nse.EVENT_TYPE FROM OB_NOTIFICATION_SUBSCRIPTION ns LEFT JOIN " + + "OB_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 NOTIFICATION_SUBSCRIPTION ns LEFT JOIN " + - "NOTIFICATION_SUBSCRIPTION_EVENTS nse ON ns.SUBSCRIPTION_ID = nse.SUBSCRIPTION_ID WHERE " + + "ns.STATUS, nse.EVENT_TYPE FROM OB_NOTIFICATION_SUBSCRIPTION ns LEFT JOIN " + + "OB_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 NOTIFICATION_SUBSCRIPTION ns LEFT JOIN " + - "NOTIFICATION_SUBSCRIPTION_EVENTS nse ON ns.SUBSCRIPTION_ID = nse.SUBSCRIPTION_ID WHERE " + - "ns.SUBSCRIPTION_ID IN (SELECT ns.SUBSCRIPTION_ID FROM NOTIFICATION_SUBSCRIPTION ns LEFT " + - "JOIN NOTIFICATION_SUBSCRIPTION_EVENTS nse ON ns.SUBSCRIPTION_ID = nse.SUBSCRIPTION_ID WHERE " + + "ns.STATUS, nse.EVENT_TYPE FROM OB_NOTIFICATION_SUBSCRIPTION ns LEFT JOIN " + + "OB_NOTIFICATION_SUBSCRIBED_EVENTS nse ON ns.SUBSCRIPTION_ID = nse.SUBSCRIPTION_ID WHERE " + + "ns.SUBSCRIPTION_ID IN (SELECT ns.SUBSCRIPTION_ID FROM OB_NOTIFICATION_SUBSCRIPTION ns LEFT " + + "JOIN OB_NOTIFICATION_SUBSCRIBED_EVENTS nse ON ns.SUBSCRIPTION_ID = nse.SUBSCRIPTION_ID WHERE " + "nse.EVENT_TYPE = ? AND ns.STATUS = 'CREATED')"; } public String updateEventSubscriptionQuery() { - return "UPDATE NOTIFICATION_SUBSCRIPTION SET CALLBACK_URL = ?, TIMESTAMP = ?, REQUEST = ?" + + return "UPDATE OB_NOTIFICATION_SUBSCRIPTION SET CALLBACK_URL = ?, TIMESTAMP = ?, REQUEST = ?" + "WHERE SUBSCRIPTION_ID = ?"; } public String updateEventSubscriptionStatusQuery() { - return "UPDATE NOTIFICATION_SUBSCRIPTION SET STATUS = ? WHERE SUBSCRIPTION_ID = ? && STATUS = 'CREATED'"; + return "UPDATE OB_NOTIFICATION_SUBSCRIPTION SET STATUS = ? WHERE SUBSCRIPTION_ID = ? && STATUS = 'CREATED'"; } public String deleteSubscribedEventTypesQuery() { - return "DELETE FROM NOTIFICATION_SUBSCRIPTION_EVENTS WHERE SUBSCRIPTION_ID = ?"; + return "DELETE FROM OB_NOTIFICATION_SUBSCRIBED_EVENTS WHERE SUBSCRIPTION_ID = ?"; } } diff --git a/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/dao/PostgreSqlPollingDAOImpl.java b/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/dao/PostgreSqlPollingDAOImpl.java index 7144e4e7..0421e4ec 100644 --- a/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/dao/PostgreSqlPollingDAOImpl.java +++ b/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/dao/PostgreSqlPollingDAOImpl.java @@ -59,7 +59,8 @@ public List getNotificationsByClientIdAndStatus(String clientId notificationList = new ArrayList<>(); if (log.isDebugEnabled()) { - log.debug(String.format(EventNotificationConstants.DB_CONN_ESTABLISHED, clientId)); + log.debug(String.format(EventNotificationConstants.DB_CONN_ESTABLISHED, + clientId.replaceAll("[\r\n]", ""))); } final String sql = sqlStatements.getMaxNotificationsQuery(); @@ -99,13 +100,13 @@ public List getNotificationsByClientIdAndStatus(String clientId if (log.isDebugEnabled()) { log.debug(String.format(EventNotificationConstants.RETRIEVED_NOTIFICATION_CLIENT, - clientId)); + clientId.replaceAll("[\r\n]", ""))); } } else { if (log.isDebugEnabled()) { log.debug(String.format(EventNotificationConstants.NO_NOTIFICATIONS_FOUND_CLIENT, - clientId)); + clientId.replaceAll("[\r\n]", ""))); } } } @@ -162,21 +163,23 @@ public List getEventsByNotificationID(String notificationId) if (log.isDebugEnabled()) { log.debug(String.format(EventNotificationConstants.RETRIEVED_EVENTS_NOTIFICATION, - notificationId)); + notificationId.replaceAll("[\r\n]", ""))); } } else { if (log.isDebugEnabled()) { log.debug(String.format(EventNotificationConstants.NO_EVENTS_NOTIFICATION_ID, - notificationId)); + notificationId.replaceAll("[\r\n]", ""))); } } } catch (ParseException e) { - log.error(String.format(EventNotificationConstants.PARSE_ERROR_NOTIFICATION_ID, notificationId), e); + log.error(String.format(EventNotificationConstants.PARSE_ERROR_NOTIFICATION_ID, + notificationId.replaceAll("[\r\n]", "")), e); throw new OBEventNotificationException(String.format ( EventNotificationConstants.PARSE_ERROR_NOTIFICATION_ID, notificationId), e); } } catch (SQLException e) { - log.error(String.format(EventNotificationConstants.DB_ERROR_EVENTS_RETRIEVE, notificationId), e); + log.error(String.format(EventNotificationConstants.DB_ERROR_EVENTS_RETRIEVE, + notificationId.replaceAll("[\r\n]", "")), e); throw new OBEventNotificationException(String.format (EventNotificationConstants.DB_ERROR_EVENTS_RETRIEVE, notificationId), e); } diff --git a/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/handler/DefaultEventCreationServiceHandler.java b/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/handler/DefaultEventCreationServiceHandler.java index 8a9f9c60..df5bd14a 100644 --- a/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/handler/DefaultEventCreationServiceHandler.java +++ b/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/handler/DefaultEventCreationServiceHandler.java @@ -43,6 +43,12 @@ public void setEventCreationService(EventCreationService eventCreationService) { this.eventCreationService = eventCreationService; } + /** + * This method is used to publish OB events in the accelerator database. + * + * @param notificationCreationDTO Notification details DTO + * @return EventCreationResponse Response after event creation + */ public EventCreationResponse publishOBEvent(NotificationCreationDTO notificationCreationDTO) { //validate if the resourceID is existing @@ -53,6 +59,7 @@ public EventCreationResponse publishOBEvent(NotificationCreationDTO notification try { consentResource = consentCoreService.getConsent(notificationCreationDTO.getResourceId(), false); + if (log.isDebugEnabled()) { log.debug("Consent resource available for resource ID " + consentResource.getConsentID().replaceAll("[\r\n]", "")); @@ -71,9 +78,9 @@ public EventCreationResponse publishOBEvent(NotificationCreationDTO notification } catch (OBEventNotificationException e) { log.error("Invalid client ID", e); - eventCreationResponse.setErrorResponse(String.format(String.format("A client was not found" + + eventCreationResponse.setErrorResponse(String.format("A client was not found" + " for the client id : '%s' in the database. ", - notificationCreationDTO.getClientId()))); + notificationCreationDTO.getClientId().replaceAll("[\r\n]", ""))); eventCreationResponse.setStatus(EventNotificationConstants.BAD_REQUEST); return eventCreationResponse; } diff --git a/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/handler/DefaultEventPollingServiceHandler.java b/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/handler/DefaultEventPollingServiceHandler.java index 063a2dca..905a9802 100644 --- a/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/handler/DefaultEventPollingServiceHandler.java +++ b/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/handler/DefaultEventPollingServiceHandler.java @@ -51,7 +51,7 @@ public void setEventPollingService(EventPollingService eventPollingService) { /** * This method is used to Poll Events as per request params. - * @param eventPollingRequest + * @param eventPollingRequest JSON request for event polling * @return */ public EventPollingResponse pollEvents(JSONObject eventPollingRequest) { @@ -66,7 +66,7 @@ public EventPollingResponse pollEvents(JSONObject eventPollingRequest) { log.error("Invalid client ID", e); eventPollingResponse.setStatus(EventNotificationConstants.BAD_REQUEST); eventPollingResponse.setErrorResponse(EventNotificationServiceUtil.getErrorDTO( - EventNotificationConstants.INVALID_REQUEST, String.format("A client was not found" + + EventNotificationConstants.INVALID_REQUEST, String.format("A client was not found" + " for the client id : '%s' in the database.. ", eventPollingDTO.getClientId()))); return eventPollingResponse; } @@ -89,7 +89,7 @@ public EventPollingResponse pollEvents(JSONObject eventPollingRequest) { /** * This method will map the eventPollingRequest JSON to EventPollingDTO. - * @param eventPollingRequest + * @param eventPollingRequest JSON request for event polling * @return EventPollingDTO */ public EventPollingDTO mapPollingRequest(JSONObject eventPollingRequest) { diff --git a/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/handler/DefaultEventSubscriptionServiceHandler.java b/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/handler/DefaultEventSubscriptionServiceHandler.java index 163f5dbb..406d2a64 100644 --- a/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/handler/DefaultEventSubscriptionServiceHandler.java +++ b/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/handler/DefaultEventSubscriptionServiceHandler.java @@ -28,7 +28,7 @@ import net.minidev.json.JSONObject; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.eclipse.jetty.http.HttpStatus; +import org.springframework.http.HttpStatus; import java.util.ArrayList; import java.util.List; @@ -65,13 +65,13 @@ public EventSubscriptionResponse createEventSubscription(EventSubscriptionDTO ev try { EventSubscription createEventSubscriptionResponse = eventSubscriptionService. createEventSubscription(eventSubscription); - eventSubscriptionResponse.setStatus(HttpStatus.CREATED_201); + eventSubscriptionResponse.setStatus(HttpStatus.CREATED.value()); eventSubscriptionResponse. setResponseBody(mapSubscriptionModelToResponseJson(createEventSubscriptionResponse)); return eventSubscriptionResponse; } catch (OBEventNotificationException e) { log.error("Error occurred while creating event subscription", e); - eventSubscriptionResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR_500); + eventSubscriptionResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); eventSubscriptionResponse.setErrorResponse(EventNotificationServiceUtil.getErrorDTO( EventNotificationConstants.INVALID_REQUEST, e.getMessage())); return eventSubscriptionResponse; @@ -99,17 +99,17 @@ public EventSubscriptionResponse getEventSubscription(String clientId, String su try { EventSubscription eventSubscription = eventSubscriptionService. getEventSubscriptionBySubscriptionId(subscriptionId); - eventSubscriptionResponse.setStatus(HttpStatus.OK_200); + eventSubscriptionResponse.setStatus(HttpStatus.OK.value()); eventSubscriptionResponse.setResponseBody(mapSubscriptionModelToResponseJson(eventSubscription)); return eventSubscriptionResponse; } catch (OBEventNotificationException e) { log.error("Error occurred while retrieving event subscription", e); if (e.getMessage().equals(EventNotificationConstants.EVENT_SUBSCRIPTION_NOT_FOUND)) { - eventSubscriptionResponse.setStatus(HttpStatus.BAD_REQUEST_400); + eventSubscriptionResponse.setStatus(HttpStatus.BAD_REQUEST.value()); eventSubscriptionResponse.setErrorResponse(EventNotificationServiceUtil.getErrorDTO( EventNotificationConstants.INVALID_REQUEST, e.getMessage())); } else { - eventSubscriptionResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR_500); + eventSubscriptionResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); eventSubscriptionResponse.setErrorResponse(EventNotificationServiceUtil.getErrorDTO( EventNotificationConstants.INVALID_REQUEST, e.getMessage())); } @@ -139,12 +139,12 @@ public EventSubscriptionResponse getAllEventSubscriptions(String clientId) { for (EventSubscription eventSubscription : eventSubscriptionList) { eventSubscriptionResponseList.add(mapSubscriptionModelToResponseJson(eventSubscription)); } - eventSubscriptionResponse.setStatus(HttpStatus.OK_200); + eventSubscriptionResponse.setStatus(HttpStatus.OK.value()); eventSubscriptionResponse.setResponseBody(eventSubscriptionResponseList); return eventSubscriptionResponse; } catch (OBEventNotificationException e) { log.error("Error occurred while retrieving event subscriptions", e); - eventSubscriptionResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR_500); + eventSubscriptionResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); eventSubscriptionResponse.setErrorResponse(EventNotificationServiceUtil.getErrorDTO( EventNotificationConstants.INVALID_REQUEST, e.getMessage())); return eventSubscriptionResponse; @@ -175,12 +175,12 @@ public EventSubscriptionResponse getEventSubscriptionsByEventType(String clientI for (EventSubscription eventSubscription : eventSubscriptionList) { eventSubscriptionResponseList.add(mapSubscriptionModelToResponseJson(eventSubscription)); } - eventSubscriptionResponse.setStatus(HttpStatus.OK_200); + eventSubscriptionResponse.setStatus(HttpStatus.OK.value()); eventSubscriptionResponse.setResponseBody(eventSubscriptionResponseList); return eventSubscriptionResponse; } catch (OBEventNotificationException e) { log.error("Error occurred while retrieving event subscriptions", e); - eventSubscriptionResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR_500); + eventSubscriptionResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); eventSubscriptionResponse.setErrorResponse(EventNotificationServiceUtil.getErrorDTO( EventNotificationConstants.INVALID_REQUEST, e.getMessage())); return eventSubscriptionResponse; @@ -208,13 +208,13 @@ public EventSubscriptionResponse updateEventSubscription(EventSubscriptionDTO ev try { Boolean isUpdated = eventSubscriptionService.updateEventSubscription(eventSubscription); if (!isUpdated) { - eventSubscriptionResponse.setStatus(HttpStatus.BAD_REQUEST_400); + eventSubscriptionResponse.setStatus(HttpStatus.BAD_REQUEST.value()); eventSubscriptionResponse.setErrorResponse(EventNotificationServiceUtil.getErrorDTO( EventNotificationConstants.INVALID_REQUEST, "Event subscription not found.")); return eventSubscriptionResponse; } - eventSubscriptionResponse.setStatus(HttpStatus.OK_200); + eventSubscriptionResponse.setStatus(HttpStatus.OK.value()); EventSubscription eventSubscriptionUpdateResponse = eventSubscriptionService. getEventSubscriptionBySubscriptionId(eventSubscriptionUpdateRequestDto.getSubscriptionId()); eventSubscriptionResponse. @@ -222,7 +222,7 @@ public EventSubscriptionResponse updateEventSubscription(EventSubscriptionDTO ev return eventSubscriptionResponse; } catch (OBEventNotificationException e) { log.error("Error occurred while updating event subscription", e); - eventSubscriptionResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR_500); + eventSubscriptionResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); eventSubscriptionResponse.setErrorResponse(EventNotificationServiceUtil.getErrorDTO( EventNotificationConstants.INVALID_REQUEST, e.getMessage())); return eventSubscriptionResponse; @@ -247,17 +247,17 @@ public EventSubscriptionResponse deleteEventSubscription(String clientId, String try { Boolean isDeleted = eventSubscriptionService.deleteEventSubscription(subscriptionId); if (!isDeleted) { - eventSubscriptionResponse.setStatus(HttpStatus.BAD_REQUEST_400); + eventSubscriptionResponse.setStatus(HttpStatus.BAD_REQUEST.value()); eventSubscriptionResponse.setErrorResponse(EventNotificationServiceUtil.getErrorDTO( EventNotificationConstants.INVALID_REQUEST, "Event subscription not found")); return eventSubscriptionResponse; } - eventSubscriptionResponse.setStatus(HttpStatus.NO_CONTENT_204); + eventSubscriptionResponse.setStatus(HttpStatus.NO_CONTENT.value()); return eventSubscriptionResponse; } catch (OBEventNotificationException e) { log.error("Error occurred while deleting event subscription", e); - eventSubscriptionResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR_500); + eventSubscriptionResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); eventSubscriptionResponse.setErrorResponse(EventNotificationServiceUtil.getErrorDTO( EventNotificationConstants.INVALID_REQUEST, e.getMessage())); return eventSubscriptionResponse; @@ -277,7 +277,7 @@ private EventSubscriptionResponse validateClientId(String clientId) { } catch (OBEventNotificationException e) { log.error("Invalid client ID", e); EventSubscriptionResponse eventSubscriptionResponse = new EventSubscriptionResponse(); - eventSubscriptionResponse.setStatus(HttpStatus.BAD_REQUEST_400); + eventSubscriptionResponse.setStatus(HttpStatus.BAD_REQUEST.value()); eventSubscriptionResponse.setErrorResponse(EventNotificationServiceUtil.getErrorDTO( EventNotificationConstants.INVALID_REQUEST, e.getMessage())); return eventSubscriptionResponse; diff --git a/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/handler/EventCreationServiceHandler.java b/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/handler/EventCreationServiceHandler.java index 3f1c6877..671a64c6 100644 --- a/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/handler/EventCreationServiceHandler.java +++ b/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/handler/EventCreationServiceHandler.java @@ -30,7 +30,7 @@ public interface EventCreationServiceHandler { /** * This method is used to publish OB events in the accelerator database. The method is a generic * method that is used to persist data into the OB_NOTIFICATION and OB_NOTIFICATION_EVENT tables. - * @param notificationCreationDTO + * @param notificationCreationDTO Notification details DTO * @return For successful request the API will return a JSON with the notificationID */ EventCreationResponse publishOBEvent(NotificationCreationDTO notificationCreationDTO); diff --git a/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/handler/EventNotificationPersistenceServiceHandler.java b/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/handler/EventNotificationPersistenceServiceHandler.java index dfea1457..720d89a8 100644 --- a/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/handler/EventNotificationPersistenceServiceHandler.java +++ b/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/handler/EventNotificationPersistenceServiceHandler.java @@ -39,6 +39,15 @@ public static EventNotificationPersistenceServiceHandler getInstance() { return instance; } + /** + * This method is to persist authorization revoke event. + * + * @param clientId - client ID + * @param resourceId - resource ID + * @param notificationType - notification type + * @param notificationInfo - notification info + * @return EventCreationResponse + */ public EventCreationResponse persistRevokeEvent(String clientId, String resourceId, String notificationType, JSONObject notificationInfo) { diff --git a/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/handler/EventPollingServiceHandler.java b/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/handler/EventPollingServiceHandler.java index 7a714db2..2c42d2dc 100644 --- a/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/handler/EventPollingServiceHandler.java +++ b/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/handler/EventPollingServiceHandler.java @@ -32,14 +32,14 @@ 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 eventPollingRequest + * @param eventPollingRequest JSON request for event polling * @return EventPollingResponse to the polling endpoint. */ EventPollingResponse pollEvents(JSONObject eventPollingRequest); /** - * This method is used to map the eventPollingRequest to EventPollingDTO. - * @param eventPollingRequest + * This method is used to map the eventPollingRequest to EventPollingDTO + * @param eventPollingRequest JSON request for event polling * @return eventPollingDTO with the request parameters. */ EventPollingDTO mapPollingRequest(JSONObject eventPollingRequest); diff --git a/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/service/EventCreationService.java b/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/service/EventCreationService.java index 466e0f33..025984b6 100644 --- a/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/service/EventCreationService.java +++ b/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/service/EventCreationService.java @@ -48,10 +48,9 @@ public class EventCreationService { /** * The publishOBEventNotification methods will call the dao layer to persist the event - * notifications - * event polling request. - * @param notificationCreationDTO - * + * notifications for event polling request. + * @param notificationCreationDTO Notification Creation DTO + * @return Event Response * @throws OBEventNotificationException */ public String publishOBEventNotification(NotificationCreationDTO notificationCreationDTO) @@ -84,7 +83,8 @@ public String publishOBEventNotification(NotificationCreationDTO notificationCre /** * The getEvents method is used to get the NotificationEvents Array list from payload. * - * @param notificationEvents + * @param notificationEvents Notification Events to convert + * @return Event notification List */ @Generated(message = "Private methods invoked when calling referred method") private ArrayList getEvents(Map notificationEvents) { @@ -104,7 +104,8 @@ private ArrayList getEvents(Map notificat /** * The getNotification method is used to get the NotificationDAO from payload. * - * @param notificationCreationDTO + * @param notificationCreationDTO Notification Creation DTO + * @return Notification Details */ @Generated(message = "Private methods invoked when calling referred method") private NotificationDTO getNotification(NotificationCreationDTO notificationCreationDTO) { diff --git a/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/service/EventNotificationGenerator.java b/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/service/EventNotificationGenerator.java index fc24e51e..4eb6dc9c 100644 --- a/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/service/EventNotificationGenerator.java +++ b/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/service/EventNotificationGenerator.java @@ -35,9 +35,10 @@ public interface EventNotificationGenerator { /** * This method is to generate event notification body. To generate custom values * for the body this method should be extended. - * @param notificationDTO - * @param notificationEventList - * @return + * @param notificationDTO Notification details DTO + * @param notificationEventList List of notification events + * + * @return Event Notification Body * @throws OBEventNotificationException */ Notification generateEventNotificationBody(NotificationDTO notificationDTO, List diff --git a/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/service/EventPollingService.java b/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/service/EventPollingService.java index a823288a..aa7495d0 100644 --- a/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/service/EventPollingService.java +++ b/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/service/EventPollingService.java @@ -50,8 +50,8 @@ public class EventPollingService { /** * The pollEvents methods will return the Aggregated Polling Response for * event polling request. - * @param eventPollingDTO - * + * @param eventPollingDTO Event polling request DTO + * @return AggregatedPollingResponse Aggregated Polling Response * @throws OBEventNotificationException */ public AggregatedPollingResponse pollEvents(EventPollingDTO eventPollingDTO) @@ -107,13 +107,13 @@ public AggregatedPollingResponse pollEvents(EventPollingDTO eventPollingDTO) if (notificationList.isEmpty()) { if (log.isDebugEnabled()) { log.debug(String.format("No OB Event Notifications available for for the client " + - "with ID : '%s'.", eventPollingDTO.getClientId())); + "with ID : '%s'.", eventPollingDTO.getClientId().replaceAll("[\r\n]", ""))); } aggregatedPollingResponse.setStatus(EventNotificationConstants.NOT_FOUND); } else { if (log.isDebugEnabled()) { log.debug(String.format("OB Event Notifications available for the client " + - "with ID : '%s'.", eventPollingDTO.getClientId())); + "with ID : '%s'.", eventPollingDTO.getClientId().replaceAll("[\r\n]", ""))); } aggregatedPollingResponse.setStatus(EventNotificationConstants.OK); diff --git a/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/service/EventSubscriptionService.java b/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/service/EventSubscriptionService.java index 20e9d55d..a0b84125 100644 --- a/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/service/EventSubscriptionService.java +++ b/open-banking-accelerator/components/event-notifications/com.wso2.openbanking.accelerator.event.notifications.service/src/main/java/com/wso2/openbanking/accelerator/event/notifications/service/service/EventSubscriptionService.java @@ -43,6 +43,7 @@ public class EventSubscriptionService { * 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 OBEventNotificationException */ public EventSubscription createEventSubscription(EventSubscription eventSubscription) @@ -78,6 +79,7 @@ public EventSubscription createEventSubscription(EventSubscription eventSubscrip * This method will call the dao layer to retrieve a single event subscription. * * @param subscriptionId subscription id of the event subscription + * @return event subscription object that is retrieved * @throws OBEventNotificationException */ public EventSubscription getEventSubscriptionBySubscriptionId(String subscriptionId) @@ -101,6 +103,7 @@ public EventSubscription getEventSubscriptionBySubscriptionId(String subscriptio * This method will call the dao layer to retrieve all event subscriptions of a client. * * @param clientId client id of the event subscription + * @return list of event subscriptions that are retrieved * @throws OBEventNotificationException */ public List getEventSubscriptionsByClientId(String clientId) @@ -122,6 +125,7 @@ public List getEventSubscriptionsByClientId(String clientId) * This method will call the dao layer to retrieve all event subscriptions by event type. * * @param eventType event type that needs to be subscribed by the retrieving event subscriptions. + * @return list of event subscriptions that are retrieved * @throws OBEventNotificationException */ public List getEventSubscriptionsByClientIdAndEventType(String eventType) @@ -144,6 +148,7 @@ public List getEventSubscriptionsByClientIdAndEventType(Strin * This method will call the dao layer to update an event subscription. * * @param eventSubscription event subscription object that needs to be updated + * @return true if the event subscription is updated successfully * @throws OBEventNotificationException */ public Boolean updateEventSubscription(EventSubscription eventSubscription) @@ -206,6 +211,7 @@ public Boolean updateEventSubscription(EventSubscription eventSubscription) * This method will call the dao layer to delete an event subscription. * * @param subscriptionId subscription id of the event subscription + * @return true if the event subscription is deleted successfully * @throws OBEventNotificationException */ public Boolean deleteEventSubscription(String subscriptionId) throws OBEventNotificationException { diff --git a/open-banking-accelerator/internal-apis/internal-webapps/com.wso2.openbanking.accelerator.event.notifications.endpoint/src/main/java/com/wso2/openbanking/accelerator/event/notifications/endpoint/api/EventPollingEndpoint.java b/open-banking-accelerator/internal-apis/internal-webapps/com.wso2.openbanking.accelerator.event.notifications.endpoint/src/main/java/com/wso2/openbanking/accelerator/event/notifications/endpoint/api/EventPollingEndpoint.java index 213a7316..9ab95c6e 100644 --- a/open-banking-accelerator/internal-apis/internal-webapps/com.wso2.openbanking.accelerator.event.notifications.endpoint/src/main/java/com/wso2/openbanking/accelerator/event/notifications/endpoint/api/EventPollingEndpoint.java +++ b/open-banking-accelerator/internal-apis/internal-webapps/com.wso2.openbanking.accelerator.event.notifications.endpoint/src/main/java/com/wso2/openbanking/accelerator/event/notifications/endpoint/api/EventPollingEndpoint.java @@ -83,37 +83,43 @@ public Response pollEvents(@Context HttpServletRequest request, @Context HttpSer eventPollingData = parameterMap.get(EventNotificationEndPointConstants.REQUEST). toString().replaceAll("\\\\r|\\\\n|\\r|\\n|\\[|]| ", StringUtils.EMPTY); - byte[] decodedBytes = Base64.getDecoder().decode(eventPollingData); - String decodedString = new String(decodedBytes, StandardCharsets.UTF_8); - try { - eventPollingRequest = (JSONObject) new JSONParser(JSONParser.MODE_PERMISSIVE).parse(decodedString); - - //check if the client id is present in the header - String clientId = request.getHeader(EventNotificationConstants.X_WSO2_CLIENT_ID); - if (!StringUtils.isBlank(clientId)) { - eventPollingRequest.put(EventNotificationConstants.X_WSO2_CLIENT_ID, request. - getHeader(EventNotificationConstants.X_WSO2_CLIENT_ID)); - } else { + if (StringUtils.isNotBlank(eventPollingData)) { + byte[] decodedBytes = Base64.getDecoder().decode(eventPollingData); + String decodedString = new String(decodedBytes, StandardCharsets.UTF_8); + try { + eventPollingRequest = (JSONObject) new JSONParser(JSONParser.MODE_PERMISSIVE).parse(decodedString); + + //check if the client id is present in the header + String clientId = request.getHeader(EventNotificationConstants.X_WSO2_CLIENT_ID); + if (!StringUtils.isBlank(clientId)) { + eventPollingRequest.put(EventNotificationConstants.X_WSO2_CLIENT_ID, request. + getHeader(EventNotificationConstants.X_WSO2_CLIENT_ID)); + } else { + return Response.status(Response.Status.BAD_REQUEST).entity(EventNotificationUtils.getErrorDTO( + EventNotificationEndPointConstants.MISSING_REQUEST_HEADER, + EventNotificationConstants.MISSING_HEADER_PARAM_CLIENT_ID)).build(); + } + + EventPollingResponse eventPollingResponse = eventPollingServiceHandler. + pollEvents(eventPollingRequest); + + return EventNotificationUtils.mapEventPollingServiceResponse(eventPollingResponse); + + } catch (ParseException e) { + log.error("Exception when parsing the request payload", e); return Response.status(Response.Status.BAD_REQUEST).entity(EventNotificationUtils.getErrorDTO( - EventNotificationEndPointConstants.MISSING_REQUEST_HEADER, - EventNotificationConstants.MISSING_HEADER_PARAM_CLIENT_ID)).build(); + EventNotificationEndPointConstants.INVALID_REQUEST_PAYLOAD, + EventNotificationEndPointConstants.REQUEST_PAYLOAD_ERROR)).build(); + } catch (ClassCastException e) { + log.error(EventNotificationEndPointConstants.REQUEST_PAYLOAD_ERROR, e); + return Response.status(Response.Status.BAD_REQUEST).entity(EventNotificationUtils.getErrorDTO( + EventNotificationEndPointConstants.INVALID_REQUEST_PAYLOAD, + EventNotificationEndPointConstants.REQUEST_PAYLOAD_ERROR)).build(); } - - EventPollingResponse eventPollingResponse = eventPollingServiceHandler. - pollEvents(eventPollingRequest); - - return EventNotificationUtils.mapEventPollingServiceResponse(eventPollingResponse); - - } catch (ParseException e) { - log.error("Exception when parsing the request payload", e); - return Response.status(Response.Status.BAD_REQUEST).entity(EventNotificationUtils.getErrorDTO( - EventNotificationEndPointConstants.INVALID_REQUEST_PAYLOAD, - EventNotificationEndPointConstants.REQUEST_PAYLOAD_ERROR)).build(); - } catch (ClassCastException e) { - log.error(EventNotificationEndPointConstants.REQUEST_PAYLOAD_ERROR, e); + } else { return Response.status(Response.Status.BAD_REQUEST).entity(EventNotificationUtils.getErrorDTO( EventNotificationEndPointConstants.INVALID_REQUEST_PAYLOAD, - EventNotificationEndPointConstants.REQUEST_PAYLOAD_ERROR)).build(); + EventNotificationEndPointConstants.EMPTY_REQ_PAYLOAD)).build(); } } else { return Response.status(Response.Status.BAD_REQUEST).entity(EventNotificationUtils.getErrorDTO( diff --git a/open-banking-accelerator/internal-apis/internal-webapps/com.wso2.openbanking.accelerator.event.notifications.endpoint/src/main/java/com/wso2/openbanking/accelerator/event/notifications/endpoint/constants/EventNotificationEndPointConstants.java b/open-banking-accelerator/internal-apis/internal-webapps/com.wso2.openbanking.accelerator.event.notifications.endpoint/src/main/java/com/wso2/openbanking/accelerator/event/notifications/endpoint/constants/EventNotificationEndPointConstants.java index ea9b3523..90530c99 100644 --- a/open-banking-accelerator/internal-apis/internal-webapps/com.wso2.openbanking.accelerator.event.notifications.endpoint/src/main/java/com/wso2/openbanking/accelerator/event/notifications/endpoint/constants/EventNotificationEndPointConstants.java +++ b/open-banking-accelerator/internal-apis/internal-webapps/com.wso2.openbanking.accelerator.event.notifications.endpoint/src/main/java/com/wso2/openbanking/accelerator/event/notifications/endpoint/constants/EventNotificationEndPointConstants.java @@ -29,6 +29,7 @@ public class EventNotificationEndPointConstants { public static final String POLLING_ERROR_RESPONSE = "OB Event Notification Polling error"; public static final String EVENT_CREATION_ERROR_RESPONSE = "OB Event Notification Creation error"; public static final String REQUEST_PAYLOAD_ERROR = "Error in the request payload"; + public static final String EMPTY_REQ_PAYLOAD = "Request payload cannot be empty"; public static final String INVALID_REQUEST = "invalid_request"; public static final String INVALID_REQUEST_PAYLOAD = "invalid_request_payload"; public static final String MISSING_REQUEST_PAYLOAD = "missing_request_payload"; diff --git a/open-banking-accelerator/internal-apis/internal-webapps/com.wso2.openbanking.accelerator.event.notifications.endpoint/src/main/java/com/wso2/openbanking/accelerator/event/notifications/endpoint/util/EventNotificationUtils.java b/open-banking-accelerator/internal-apis/internal-webapps/com.wso2.openbanking.accelerator.event.notifications.endpoint/src/main/java/com/wso2/openbanking/accelerator/event/notifications/endpoint/util/EventNotificationUtils.java index ab744948..9f7c038d 100644 --- a/open-banking-accelerator/internal-apis/internal-webapps/com.wso2.openbanking.accelerator.event.notifications.endpoint/src/main/java/com/wso2/openbanking/accelerator/event/notifications/endpoint/util/EventNotificationUtils.java +++ b/open-banking-accelerator/internal-apis/internal-webapps/com.wso2.openbanking.accelerator.event.notifications.endpoint/src/main/java/com/wso2/openbanking/accelerator/event/notifications/endpoint/util/EventNotificationUtils.java @@ -98,13 +98,16 @@ public static Response mapEventPollingServiceResponse(EventPollingResponse event if (EventNotificationConstants.OK.equals(eventPollingResponse.getStatus())) { return Response.status(Response.Status.OK).entity(eventPollingResponse.getResponseBody()).build(); + } else if (EventNotificationConstants.NOT_FOUND.equals(eventPollingResponse.getStatus())) { + return Response.status(Response.Status.NOT_FOUND).entity(eventPollingResponse.getResponseBody()).build(); } else { if (eventPollingResponse.getErrorResponse() instanceof String) { - return Response.status(Response.Status.BAD_REQUEST).entity(EventNotificationUtils.getErrorDTO( - EventNotificationEndPointConstants.INVALID_REQUEST, - eventPollingResponse.getErrorResponse().toString())).build(); + return Response.status(getErrorResponseStatus(eventPollingResponse.getStatus())) + .entity(EventNotificationUtils.getErrorDTO(EventNotificationEndPointConstants.INVALID_REQUEST, + eventPollingResponse.getErrorResponse().toString())).build(); } else { - return Response.status(Response.Status.BAD_REQUEST).entity(eventPollingResponse.getErrorResponse()) + return Response.status(getErrorResponseStatus(eventPollingResponse.getStatus())) + .entity(eventPollingResponse.getErrorResponse()) .build(); } } @@ -120,4 +123,20 @@ public static EventNotificationErrorDTO getErrorDTO(String error, String errorDe eventNotificationErrorDTO.setErrorDescription(errorDescription); return eventNotificationErrorDTO; } + + /** + * Get mapped Response.Status for the given status value. + * @param status status value + * @return Mapped Response.Status + */ + private static Response.Status getErrorResponseStatus(String status) { + + if (EventNotificationConstants.NOT_FOUND.equals(status)) { + return Response.Status.NOT_FOUND; + } else if (EventNotificationConstants.BAD_REQUEST.equals(status)) { + return Response.Status.BAD_REQUEST; + } else { + return Response.Status.INTERNAL_SERVER_ERROR; + } + } } diff --git a/open-banking-accelerator/internal-apis/internal-webapps/com.wso2.openbanking.accelerator.event.notifications.endpoint/src/main/java/com/wso2/openbanking/accelerator/event/notifications/endpoint/util/EventSubscriptionUtils.java b/open-banking-accelerator/internal-apis/internal-webapps/com.wso2.openbanking.accelerator.event.notifications.endpoint/src/main/java/com/wso2/openbanking/accelerator/event/notifications/endpoint/util/EventSubscriptionUtils.java index f5cd07f5..6c8ac0f1 100644 --- a/open-banking-accelerator/internal-apis/internal-webapps/com.wso2.openbanking.accelerator.event.notifications.endpoint/src/main/java/com/wso2/openbanking/accelerator/event/notifications/endpoint/util/EventSubscriptionUtils.java +++ b/open-banking-accelerator/internal-apis/internal-webapps/com.wso2.openbanking.accelerator.event.notifications.endpoint/src/main/java/com/wso2/openbanking/accelerator/event/notifications/endpoint/util/EventSubscriptionUtils.java @@ -29,7 +29,7 @@ import net.minidev.json.parser.JSONParser; import net.minidev.json.parser.ParseException; import org.apache.commons.io.IOUtils; -import org.eclipse.jetty.http.HttpStatus; +import org.springframework.http.HttpStatus; import java.io.IOException; @@ -76,22 +76,24 @@ public static JSONObject getJSONObjectPayload(HttpServletRequest request) throws */ public static Response mapEventSubscriptionServiceResponse(EventSubscriptionResponse eventSubscriptionResponse) { int status = eventSubscriptionResponse.getStatus(); - if (eventSubscriptionResponse.getErrorResponse() == null) { + if (HttpStatus.NO_CONTENT.value() == status) { + return Response.status(status) + .build(); + } else if (eventSubscriptionResponse.getErrorResponse() == null) { if (eventSubscriptionResponse.getResponseBody() != null) { return Response.status(status) .entity(eventSubscriptionResponse.getResponseBody()) .build(); } else { - return Response.status(HttpStatus.INTERNAL_SERVER_ERROR_500) + return Response.status(HttpStatus.INTERNAL_SERVER_ERROR.value()) .entity(EventNotificationServiceUtil.getErrorDTO(EventNotificationConstants.INVALID_REQUEST, EventNotificationConstants.ERROR_HANDLING_EVENT_SUBSCRIPTION)) .build(); } - } else { + } else { return Response.status(status) .entity(eventSubscriptionResponse.getErrorResponse()) .build(); } - } }