Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
Removing store param check.
Browse files Browse the repository at this point in the history
  • Loading branch information
jzonthemtn committed Mar 11, 2024
1 parent 3b4e43a commit a9165f4
Showing 1 changed file with 17 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,45 +209,33 @@ private RestChannelConsumer create(final NodeClient nodeClient, final String sto

private RestChannelConsumer post(final NodeClient nodeClient, final String storeName, final RestRequest restRequest) throws IOException {

if(storeName == null || storeName.isEmpty()) {
try {

final XContentBuilder builder = XContentType.JSON.contentBuilder();
builder.startObject().field("error", "a store name is required");
builder.endObject();

return (channel) -> channel.sendResponse(new BytesRestResponse(RestStatus.BAD_REQUEST, builder));

} else {
final String eventJson = restRequest.content().utf8ToString();
final String eventJsonWithTimestamp = setEventTimestamp(eventJson);

try {
LOGGER.info("Indexing UBI event into store {}", storeName);
final String eventsIndexName = UbiUtils.getEventsIndexName(storeName);

final String eventJson = restRequest.content().utf8ToString();
final String eventJsonWithTimestamp = setEventTimestamp(eventJson);
final Event event = new Event(eventsIndexName, eventJsonWithTimestamp);
OpenSearchEventManager.getInstance(nodeClient).add(event);

LOGGER.info("Indexing UBI event into store {}", storeName);
final String eventsIndexName = UbiUtils.getEventsIndexName(storeName);

final Event event = new Event(eventsIndexName, eventJsonWithTimestamp);
OpenSearchEventManager.getInstance(nodeClient).add(event);

} catch (JsonProcessingException ex) {
LOGGER.error("Unable to get/set timestamp on UBI event.", ex);

final XContentBuilder builder = XContentType.JSON.contentBuilder();
builder.startObject().field("error", "unable to set event timestamp");
builder.endObject();

return (channel) -> channel.sendResponse(new BytesRestResponse(RestStatus.BAD_REQUEST, builder));
}
} catch (JsonProcessingException ex) {
LOGGER.error("Unable to get/set timestamp on UBI event.", ex);

final XContentBuilder builder = XContentType.JSON.contentBuilder();
builder.startObject().field("status", "received");
builder.startObject().field("error", "unable to set event timestamp");
builder.endObject();

return (channel) -> channel.sendResponse(new BytesRestResponse(RestStatus.OK, builder));

return (channel) -> channel.sendResponse(new BytesRestResponse(RestStatus.BAD_REQUEST, builder));
}

final XContentBuilder builder = XContentType.JSON.contentBuilder();
builder.startObject().field("status", "received");
builder.endObject();

return (channel) -> channel.sendResponse(new BytesRestResponse(RestStatus.OK, builder));

}

private RestChannelConsumer delete(final NodeClient nodeClient, final String storeName) throws IOException {
Expand Down

0 comments on commit a9165f4

Please sign in to comment.