Skip to content

Commit

Permalink
Fixed review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashi1993 committed Dec 12, 2024
1 parent bd498c6 commit 1f79f12
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<relativePath>../../pom.xml</relativePath>
</parent>

<artifactId>org.wso2.financial.services.accelerator.event.notification.endpoint</artifactId>
<artifactId>org.wso2.financial.services.accelerator.event.notifications.endpoint</artifactId>
<packaging>war</packaging>
<name>WSO2 Financial Services - Event Notification Endpoint</name>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
});

Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
*/
public class EventSubscriptionUtils {

private EventSubscriptionUtils() {

}

/**
* Extract string payload from request object.
*/
Expand Down

0 comments on commit 1f79f12

Please sign in to comment.