From 1f79f1298f086fcd945a3516570d04781c3fec0e Mon Sep 17 00:00:00 2001 From: ashirwadadayarathne Date: Thu, 12 Dec 2024 10:09:12 +0530 Subject: [PATCH] Fixed review comments --- .../pom.xml | 2 +- .../endpoint/api/EventCreationEndpoint.java | 20 ++++++++++++++----- .../endpoint/api/EventPollingEndpoint.java | 15 +++++++++++--- .../api/EventSubscriptionEndpoint.java | 13 ++++++++++-- .../endpoint/util/EventNotificationUtils.java | 4 ++++ .../endpoint/util/EventSubscriptionUtils.java | 4 ++++ 6 files changed, 47 insertions(+), 11 deletions(-) diff --git a/financial-services-accelerator/internal-webapps/org.wso2.financial.services.accelerator.event.notifications.endpoint/pom.xml b/financial-services-accelerator/internal-webapps/org.wso2.financial.services.accelerator.event.notifications.endpoint/pom.xml index af3e47546..344acd076 100644 --- a/financial-services-accelerator/internal-webapps/org.wso2.financial.services.accelerator.event.notifications.endpoint/pom.xml +++ b/financial-services-accelerator/internal-webapps/org.wso2.financial.services.accelerator.event.notifications.endpoint/pom.xml @@ -28,7 +28,7 @@ ../../pom.xml - org.wso2.financial.services.accelerator.event.notification.endpoint + org.wso2.financial.services.accelerator.event.notifications.endpoint war WSO2 Financial Services - Event Notification Endpoint diff --git a/financial-services-accelerator/internal-webapps/org.wso2.financial.services.accelerator.event.notifications.endpoint/src/main/java/org/wso2/financial/services/accelerator/event/notifications/endpoint/api/EventCreationEndpoint.java b/financial-services-accelerator/internal-webapps/org.wso2.financial.services.accelerator.event.notifications.endpoint/src/main/java/org/wso2/financial/services/accelerator/event/notifications/endpoint/api/EventCreationEndpoint.java index 485803157..b11162143 100644 --- a/financial-services-accelerator/internal-webapps/org.wso2.financial.services.accelerator.event.notifications.endpoint/src/main/java/org/wso2/financial/services/accelerator/event/notifications/endpoint/api/EventCreationEndpoint.java +++ b/financial-services-accelerator/internal-webapps/org.wso2.financial.services.accelerator.event.notifications.endpoint/src/main/java/org/wso2/financial/services/accelerator/event/notifications/endpoint/api/EventCreationEndpoint.java @@ -52,9 +52,19 @@ public class EventCreationEndpoint { private static final Log log = LogFactory.getLog(EventCreationEndpoint.class); - private static final EventCreationServiceHandler eventCreationServiceHandler = EventNotificationUtils. - getEventNotificationCreationServiceHandler(); + private final EventCreationServiceHandler eventCreationServiceHandler; private static final String specialChars = "!@#$%&*()'+,./:;<=>?[]^_`{|}"; + private static final String illegalChars = "\\\\r|\\\\n|\\r|\\n|\\[|]| "; + + public EventCreationEndpoint() { + + eventCreationServiceHandler = EventNotificationUtils.getEventNotificationCreationServiceHandler(); + } + + public EventCreationEndpoint(EventCreationServiceHandler handler) { + + eventCreationServiceHandler = handler; + } /** * This API will be used to create events. @@ -82,7 +92,7 @@ public Response createEvents(@Context HttpServletRequest request, @Context HttpS if (!parameterMap.isEmpty() && parameterMap.containsKey(EventNotificationEndPointConstants.REQUEST)) { requestData = parameterMap.get(EventNotificationEndPointConstants.REQUEST). - toString().replaceAll("\\\\r|\\\\n|\\r|\\n|\\[|]| ", StringUtils.EMPTY); + toString().replaceAll(illegalChars, StringUtils.EMPTY); byte[] decodedBytes = Base64.getDecoder().decode(requestData); String decodedString = new String(decodedBytes, StandardCharsets.UTF_8); @@ -124,9 +134,8 @@ public Response createEvents(@Context HttpServletRequest request, @Context HttpS } //set events to notificationCreationDTO - JSONObject finalNotificationEvents = notificationEvents; notificationEvents.keySet().forEach(eventName -> { - JSONObject eventInformation = (JSONObject) finalNotificationEvents.get(eventName); + JSONObject eventInformation = notificationEvents.getJSONObject(eventName); notificationCreationDTO.setEventPayload(eventName, eventInformation); }); @@ -142,6 +151,7 @@ public Response createEvents(@Context HttpServletRequest request, @Context HttpS .getErrorDTO(EventNotificationEndPointConstants.INVALID_REQUEST_PAYLOAD, EventNotificationEndPointConstants.REQUEST_PAYLOAD_ERROR)).build(); } catch (FSEventNotificationException e) { + log.error(EventNotificationEndPointConstants.EVENT_CREATION_ERROR_RESPONSE, e); return Response.status(e.getStatus()).entity(EventNotificationServiceUtil .getErrorDTO(EventNotificationEndPointConstants.INVALID_REQUEST, e.getMessage())).build(); diff --git a/financial-services-accelerator/internal-webapps/org.wso2.financial.services.accelerator.event.notifications.endpoint/src/main/java/org/wso2/financial/services/accelerator/event/notifications/endpoint/api/EventPollingEndpoint.java b/financial-services-accelerator/internal-webapps/org.wso2.financial.services.accelerator.event.notifications.endpoint/src/main/java/org/wso2/financial/services/accelerator/event/notifications/endpoint/api/EventPollingEndpoint.java index 5aec5a6af..c6c3c171b 100644 --- a/financial-services-accelerator/internal-webapps/org.wso2.financial.services.accelerator.event.notifications.endpoint/src/main/java/org/wso2/financial/services/accelerator/event/notifications/endpoint/api/EventPollingEndpoint.java +++ b/financial-services-accelerator/internal-webapps/org.wso2.financial.services.accelerator.event.notifications.endpoint/src/main/java/org/wso2/financial/services/accelerator/event/notifications/endpoint/api/EventPollingEndpoint.java @@ -58,9 +58,18 @@ @Path("/events") public class EventPollingEndpoint { - private static final Log log = LogFactory.getLog(EventCreationEndpoint.class); - private static final EventPollingServiceHandler eventPollingServiceHandler = EventNotificationUtils. - getEventPollingServiceHandler(); + private static final Log log = LogFactory.getLog(EventPollingEndpoint.class); + private EventPollingServiceHandler eventPollingServiceHandler; + + public EventPollingEndpoint() { + + eventPollingServiceHandler = EventNotificationUtils.getEventPollingServiceHandler(); + } + + public EventPollingEndpoint(EventPollingServiceHandler handler) { + + eventPollingServiceHandler = handler; + } /** * Retrieve Event Notifications Using Aggregated Polling. diff --git a/financial-services-accelerator/internal-webapps/org.wso2.financial.services.accelerator.event.notifications.endpoint/src/main/java/org/wso2/financial/services/accelerator/event/notifications/endpoint/api/EventSubscriptionEndpoint.java b/financial-services-accelerator/internal-webapps/org.wso2.financial.services.accelerator.event.notifications.endpoint/src/main/java/org/wso2/financial/services/accelerator/event/notifications/endpoint/api/EventSubscriptionEndpoint.java index 404e0e342..324e2a815 100644 --- a/financial-services-accelerator/internal-webapps/org.wso2.financial.services.accelerator.event.notifications.endpoint/src/main/java/org/wso2/financial/services/accelerator/event/notifications/endpoint/api/EventSubscriptionEndpoint.java +++ b/financial-services-accelerator/internal-webapps/org.wso2.financial.services.accelerator.event.notifications.endpoint/src/main/java/org/wso2/financial/services/accelerator/event/notifications/endpoint/api/EventSubscriptionEndpoint.java @@ -58,8 +58,17 @@ public class EventSubscriptionEndpoint { private static final Log log = LogFactory.getLog(EventSubscriptionEndpoint.class); - private static final EventSubscriptionServiceHandler eventSubscriptionServiceHandler = EventSubscriptionUtils. - getEventSubscriptionServiceHandler(); + private final EventSubscriptionServiceHandler eventSubscriptionServiceHandler; + + public EventSubscriptionEndpoint() { + + eventSubscriptionServiceHandler = EventSubscriptionUtils.getEventSubscriptionServiceHandler(); + } + + public EventSubscriptionEndpoint(EventSubscriptionServiceHandler handler) { + + eventSubscriptionServiceHandler = handler; + } /** * Register an Event Notification Subscription. diff --git a/financial-services-accelerator/internal-webapps/org.wso2.financial.services.accelerator.event.notifications.endpoint/src/main/java/org/wso2/financial/services/accelerator/event/notifications/endpoint/util/EventNotificationUtils.java b/financial-services-accelerator/internal-webapps/org.wso2.financial.services.accelerator.event.notifications.endpoint/src/main/java/org/wso2/financial/services/accelerator/event/notifications/endpoint/util/EventNotificationUtils.java index 23a34898f..c706bcc4d 100644 --- a/financial-services-accelerator/internal-webapps/org.wso2.financial.services.accelerator.event.notifications.endpoint/src/main/java/org/wso2/financial/services/accelerator/event/notifications/endpoint/util/EventNotificationUtils.java +++ b/financial-services-accelerator/internal-webapps/org.wso2.financial.services.accelerator.event.notifications.endpoint/src/main/java/org/wso2/financial/services/accelerator/event/notifications/endpoint/util/EventNotificationUtils.java @@ -40,6 +40,10 @@ public class EventNotificationUtils { private static final Log log = LogFactory.getLog(EventNotificationUtils.class); + private EventNotificationUtils() { + + } + /** * This method is to get the event creation service handler as per the config. * @return EventCreationServiceHandler diff --git a/financial-services-accelerator/internal-webapps/org.wso2.financial.services.accelerator.event.notifications.endpoint/src/main/java/org/wso2/financial/services/accelerator/event/notifications/endpoint/util/EventSubscriptionUtils.java b/financial-services-accelerator/internal-webapps/org.wso2.financial.services.accelerator.event.notifications.endpoint/src/main/java/org/wso2/financial/services/accelerator/event/notifications/endpoint/util/EventSubscriptionUtils.java index a690ce6ad..67655ba32 100644 --- a/financial-services-accelerator/internal-webapps/org.wso2.financial.services.accelerator.event.notifications.endpoint/src/main/java/org/wso2/financial/services/accelerator/event/notifications/endpoint/util/EventSubscriptionUtils.java +++ b/financial-services-accelerator/internal-webapps/org.wso2.financial.services.accelerator.event.notifications.endpoint/src/main/java/org/wso2/financial/services/accelerator/event/notifications/endpoint/util/EventSubscriptionUtils.java @@ -36,6 +36,10 @@ */ public class EventSubscriptionUtils { + private EventSubscriptionUtils() { + + } + /** * Extract string payload from request object. */