mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-11-09 23:40:05 +00:00
Fixed#2730: added status filter support for webhooks (#5214)
* Fixed#2730: added status filter support for webhooks * added status param * addressing comments * postgres query change
This commit is contained in:
parent
ffebbb2d28
commit
f8f79ebb2d
@ -10,6 +10,7 @@ CREATE TABLE IF NOT EXISTS type_entity (
|
||||
);
|
||||
|
||||
ALTER TABLE webhook_entity
|
||||
ADD status VARCHAR(256) GENERATED ALWAYS AS (json ->> '$.status') NOT NULL,
|
||||
DROP COLUMN deleted;
|
||||
|
||||
ALTER TABLE entity_relationship
|
||||
|
||||
@ -10,6 +10,7 @@ CREATE TABLE IF NOT EXISTS type_entity (
|
||||
);
|
||||
|
||||
ALTER TABLE webhook_entity
|
||||
ADD status VARCHAR(256) GENERATED ALWAYS AS (json ->> 'status') STORED NOT NULL,
|
||||
DROP COLUMN deleted;
|
||||
|
||||
DROP INDEX entity_relationship_edge_index;
|
||||
|
||||
@ -1,6 +1,9 @@
|
||||
package org.openmetadata.catalog.jdbi3;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.openmetadata.catalog.Entity;
|
||||
import org.openmetadata.catalog.type.Include;
|
||||
@ -39,6 +42,7 @@ public class ListFilter {
|
||||
condition = addCondition(condition, getServiceCondition(tableName));
|
||||
condition = addCondition(condition, getParentCondition(tableName));
|
||||
condition = addCondition(condition, getCategoryCondition(tableName));
|
||||
condition = addCondition(condition, getWebhookCondition(tableName));
|
||||
return condition.isEmpty() ? "WHERE TRUE" : "WHERE " + condition;
|
||||
}
|
||||
|
||||
@ -73,6 +77,11 @@ public class ListFilter {
|
||||
return category == null ? "" : getCategoryPrefixCondition(tableName, escape(category));
|
||||
}
|
||||
|
||||
public String getWebhookCondition(String tableName) {
|
||||
String webhookStatus = queryParams.get("status");
|
||||
return webhookStatus == null ? "" : getStatusPrefixCondition(tableName, escape(webhookStatus));
|
||||
}
|
||||
|
||||
private String getFqnPrefixCondition(String tableName, String fqnPrefix) {
|
||||
return tableName == null
|
||||
? String.format("fullyQualifiedName LIKE '%s%s%%'", fqnPrefix, Entity.SEPARATOR)
|
||||
@ -85,6 +94,21 @@ public class ListFilter {
|
||||
: String.format("%s.category LIKE '%s%s%%'", tableName, category, "");
|
||||
}
|
||||
|
||||
private String getStatusPrefixCondition(String tableName, String statusPrefix) {
|
||||
if (!statusPrefix.isEmpty()) {
|
||||
List<String> statusList = new ArrayList<>(Arrays.asList(statusPrefix.split(",")));
|
||||
List<String> condition = new ArrayList<>();
|
||||
for (String s : statusList) {
|
||||
String format = "\"" + s + "\"";
|
||||
condition.add(format);
|
||||
}
|
||||
return "status in (" + String.join(",", condition) + ")";
|
||||
}
|
||||
return tableName == null
|
||||
? String.format("status LIKE '%s%s%%'", statusPrefix, "")
|
||||
: String.format("%s.status LIKE '%s%s%%'", tableName, statusPrefix, "");
|
||||
}
|
||||
|
||||
private String addCondition(String condition1, String condition2) {
|
||||
if (condition1.isEmpty()) {
|
||||
return condition2;
|
||||
|
||||
@ -104,6 +104,9 @@ public class WebhookResource extends EntityResource<Webhook, WebhookRepository>
|
||||
public ResultList<Webhook> list(
|
||||
@Context UriInfo uriInfo,
|
||||
@Context SecurityContext securityContext,
|
||||
@Parameter(description = "Filter webhooks by status", schema = @Schema(type = "string", example = "active"))
|
||||
@QueryParam("status")
|
||||
String statusParam,
|
||||
@Parameter(description = "Limit the number webhooks returned. (1 to 1000000, default = " + "10) ")
|
||||
@DefaultValue("10")
|
||||
@Min(0)
|
||||
@ -123,7 +126,7 @@ public class WebhookResource extends EntityResource<Webhook, WebhookRepository>
|
||||
@DefaultValue("non-deleted")
|
||||
Include include)
|
||||
throws IOException {
|
||||
ListFilter filter = new ListFilter(Include.ALL);
|
||||
ListFilter filter = new ListFilter(Include.ALL).addQueryParam("status", statusParam);
|
||||
return listInternal(uriInfo, securityContext, "", filter, limitParam, before, after);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user