From 19d7949da9d299d8285b3b513afa59da67ef3958 Mon Sep 17 00:00:00 2001 From: Ashirwada Date: Thu, 12 Oct 2023 17:33:01 +0530 Subject: [PATCH 1/3] Fixing issue in event subscription --- .../event-notifications/mssql.sql | 43 ++++++++++++++ .../event-notifications/mysql.sql | 50 +++++++++++++++++ .../event-notifications/oracle.sql | 56 +++++++++++++++++++ .../event-notifications/postgresql.sql | 44 +++++++++++++++ ...efaultEventSubscriptionServiceHandler.java | 34 +++++------ .../endpoint/util/EventNotificationUtils.java | 27 +++++++-- .../endpoint/util/EventSubscriptionUtils.java | 6 +- 7 files changed, 237 insertions(+), 23 deletions(-) create mode 100644 open-banking-accelerator/accelerators/ob-is/carbon-home/dbscripts/open-banking/event-notifications/mssql.sql create mode 100644 open-banking-accelerator/accelerators/ob-is/carbon-home/dbscripts/open-banking/event-notifications/mysql.sql create mode 100644 open-banking-accelerator/accelerators/ob-is/carbon-home/dbscripts/open-banking/event-notifications/oracle.sql create mode 100644 open-banking-accelerator/accelerators/ob-is/carbon-home/dbscripts/open-banking/event-notifications/postgresql.sql 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..d16e4688 --- /dev/null +++ b/open-banking-accelerator/accelerators/ob-is/carbon-home/dbscripts/open-banking/event-notifications/mssql.sql @@ -0,0 +1,43 @@ +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_SUBSCRIPTION_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..4a47d580 --- /dev/null +++ b/open-banking-accelerator/accelerators/ob-is/carbon-home/dbscripts/open-banking/event-notifications/mysql.sql @@ -0,0 +1,50 @@ +-- 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_SUBSCRIPTION_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..a3e0c467 --- /dev/null +++ b/open-banking-accelerator/accelerators/ob-is/carbon-home/dbscripts/open-banking/event-notifications/oracle.sql @@ -0,0 +1,56 @@ +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_SUBSCRIPTION_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..bdea8f05 --- /dev/null +++ b/open-banking-accelerator/accelerators/ob-is/carbon-home/dbscripts/open-banking/event-notifications/postgresql.sql @@ -0,0 +1,44 @@ +-- 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_SUBSCRIPTION_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/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/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..ec3792bd 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 @@ -76,7 +76,10 @@ 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_204 == status) { + return Response.status(status) + .build(); + } else if (eventSubscriptionResponse.getErrorResponse() == null) { if (eventSubscriptionResponse.getResponseBody() != null) { return Response.status(status) .entity(eventSubscriptionResponse.getResponseBody()) @@ -92,6 +95,5 @@ public static Response mapEventSubscriptionServiceResponse(EventSubscriptionResp .entity(eventSubscriptionResponse.getErrorResponse()) .build(); } - } } From 2b4fa901889a9b8a82b0c2bcfa3ae8f6f624ece0 Mon Sep 17 00:00:00 2001 From: Ashirwada Date: Fri, 13 Oct 2023 09:24:20 +0530 Subject: [PATCH 2/3] Fixing issue in event subscription --- .../notifications/endpoint/util/EventSubscriptionUtils.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 ec3792bd..e0dee0b5 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,7 +76,7 @@ public static JSONObject getJSONObjectPayload(HttpServletRequest request) throws */ public static Response mapEventSubscriptionServiceResponse(EventSubscriptionResponse eventSubscriptionResponse) { int status = eventSubscriptionResponse.getStatus(); - if (HttpStatus.NO_CONTENT_204 == status) { + if (HttpStatus.NO_CONTENT.value() == status) { return Response.status(status) .build(); } else if (eventSubscriptionResponse.getErrorResponse() == null) { @@ -85,7 +85,7 @@ public static Response mapEventSubscriptionServiceResponse(EventSubscriptionResp .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(); From c6d2b11eb6423b9753ee2d156e9e10c9efd7a85c Mon Sep 17 00:00:00 2001 From: Ashirwada Date: Fri, 13 Oct 2023 10:50:32 +0530 Subject: [PATCH 3/3] Fixing issue in event subscription --- .../event-notifications/mssql.sql | 2 +- .../event-notifications/mysql.sql | 2 +- .../event-notifications/oracle.sql | 2 +- .../event-notifications/postgresql.sql | 2 +- .../dao/EventSubscriptionSqlStatements.java | 26 +++++++++---------- 5 files changed, 17 insertions(+), 17 deletions(-) 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 index d16e4688..6419446c 100644 --- 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 @@ -35,7 +35,7 @@ CREATE TABLE OB_NOTIFICATION_SUBSCRIPTION ( PRIMARY KEY (SUBSCRIPTION_ID) ); -CREATE TABLE OB_NOTIFICATION_SUBSCRIPTION_EVENTS ( +CREATE TABLE OB_NOTIFICATION_SUBSCRIBED_EVENTS ( SUBSCRIPTION_ID varchar(36) NOT NULL, EVENT_TYPE varchar(255) NOT NULL, PRIMARY KEY (SUBSCRIPTION_ID, EVENT_TYPE), 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 index 4a47d580..fbbfa516 100644 --- 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 @@ -41,7 +41,7 @@ CREATE TABLE IF NOT EXISTS OB_NOTIFICATION_SUBSCRIPTION ( ) ENGINE=InnoDB; -CREATE TABLE IF NOT EXISTS OB_NOTIFICATION_SUBSCRIPTION_EVENTS ( +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), 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 index a3e0c467..176c0d97 100644 --- 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 @@ -46,7 +46,7 @@ CREATE TABLE OB_NOTIFICATION_SUBSCRIPTION ( PRIMARY KEY (SUBSCRIPTION_ID) ); -CREATE TABLE OB_NOTIFICATION_SUBSCRIPTION_EVENTS ( +CREATE TABLE OB_NOTIFICATION_SUBSCRIBED_EVENTS ( SUBSCRIPTION_ID varchar(36) NOT NULL, EVENT_TYPE varchar(255) NOT NULL, PRIMARY KEY (SUBSCRIPTION_ID, EVENT_TYPE), 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 index bdea8f05..971e6487 100644 --- 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 @@ -36,7 +36,7 @@ CREATE TABLE IF NOT EXISTS OB_NOTIFICATION_SUBSCRIPTION ( PRIMARY KEY (SUBSCRIPTION_ID) ); -CREATE TABLE IF NOT EXISTS OB_NOTIFICATION_SUBSCRIPTION_EVENTS ( +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), 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 = ?"; } }