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..6419446c --- /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_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..fbbfa516 --- /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_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..176c0d97 --- /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_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..971e6487 --- /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_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/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/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..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,13 +76,16 @@ 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(); @@ -92,6 +95,5 @@ public static Response mapEventSubscriptionServiceResponse(EventSubscriptionResp .entity(eventSubscriptionResponse.getErrorResponse()) .build(); } - } }