From fe8fb625e2926b2419e47c294f9a480accd9c79f Mon Sep 17 00:00:00 2001 From: Parth Panchal <83201188+parthp2107@users.noreply.github.com> Date: Tue, 6 Sep 2022 00:16:12 +0530 Subject: [PATCH] Added Webhook type filter in list api (#7221) * added webhook type filter in list api * added webhook type filter in list api --- .../org/openmetadata/catalog/jdbi3/ListFilter.java | 12 ++++++++++++ .../catalog/resources/events/WebhookResource.java | 8 +++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/ListFilter.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/ListFilter.java index 6a88daf8926..6cf0305a114 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/ListFilter.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/ListFilter.java @@ -43,6 +43,7 @@ public class ListFilter { condition = addCondition(condition, getParentCondition(tableName)); condition = addCondition(condition, getCategoryCondition(tableName)); condition = addCondition(condition, getWebhookCondition(tableName)); + condition = addCondition(condition, getWebhookTypeCondition(tableName)); return condition.isEmpty() ? "WHERE TRUE" : "WHERE " + condition; } @@ -82,12 +83,23 @@ public class ListFilter { return webhookStatus == null ? "" : getStatusPrefixCondition(tableName, escape(webhookStatus)); } + public String getWebhookTypeCondition(String tableName) { + String webhookType = queryParams.get("webhookType"); + return webhookType == null ? "" : getWebhookTypePrefixCondition(tableName, escape(webhookType)); + } + private String getFqnPrefixCondition(String tableName, String fqnPrefix) { return tableName == null ? String.format("fullyQualifiedName LIKE '%s%s%%'", fqnPrefix, Entity.SEPARATOR) : String.format("%s.fullyQualifiedName LIKE '%s%s%%'", tableName, fqnPrefix, Entity.SEPARATOR); } + private String getWebhookTypePrefixCondition(String tableName, String typePrefix) { + return tableName == null + ? String.format("webhookType LIKE '%s%%'", typePrefix) + : String.format("%s.webhookType LIKE '%s%%'", tableName, typePrefix); + } + private String getCategoryPrefixCondition(String tableName, String category) { return tableName == null ? String.format("category LIKE '%s%s%%'", category, "") diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/events/WebhookResource.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/events/WebhookResource.java index e059955f15e..9b0dcd0b6c1 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/events/WebhookResource.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/events/WebhookResource.java @@ -120,6 +120,11 @@ public class WebhookResource extends EntityResource @Parameter(description = "Filter webhooks by status", schema = @Schema(type = "string", example = "active")) @QueryParam("status") String statusParam, + @Parameter( + description = "Filter webhooks by type", + schema = @Schema(type = "string", example = "generic, slack, msteams")) + @QueryParam("webhookType") + String typeParam, @Parameter(description = "Limit the number webhooks returned. (1 to 1000000, default = " + "10) ") @DefaultValue("10") @Min(0) @@ -139,7 +144,8 @@ public class WebhookResource extends EntityResource @DefaultValue("non-deleted") Include include) throws IOException { - ListFilter filter = new ListFilter(Include.ALL).addQueryParam("status", statusParam); + ListFilter filter = + new ListFilter(Include.ALL).addQueryParam("status", statusParam).addQueryParam("webhookType", typeParam); return listInternal(uriInfo, securityContext, "", filter, limitParam, before, after); }