Fix #5036: added category filter for types API (#5160)

* added category filter for types API

* added category filter for types API
This commit is contained in:
Parth Panchal 2022-05-30 11:45:04 +05:30 committed by GitHub
parent 1e57d03a76
commit ffebbb2d28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 3 deletions

View File

@ -38,6 +38,7 @@ public class ListFilter {
condition = addCondition(condition, getDatabaseCondition(tableName));
condition = addCondition(condition, getServiceCondition(tableName));
condition = addCondition(condition, getParentCondition(tableName));
condition = addCondition(condition, getCategoryCondition(tableName));
return condition.isEmpty() ? "WHERE TRUE" : "WHERE " + condition;
}
@ -67,12 +68,23 @@ public class ListFilter {
return parentFqn == null ? "" : getFqnPrefixCondition(tableName, escape(parentFqn));
}
public String getCategoryCondition(String tableName) {
String category = queryParams.get("category");
return category == null ? "" : getCategoryPrefixCondition(tableName, escape(category));
}
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 getCategoryPrefixCondition(String tableName, String category) {
return tableName == null
? String.format("category LIKE '%s%s%%'", category, "")
: String.format("%s.category LIKE '%s%s%%'", tableName, category, "");
}
private String addCondition(String condition1, String condition2) {
if (condition1.isEmpty()) {
return condition2;

View File

@ -56,7 +56,6 @@ import org.openmetadata.catalog.CatalogApplicationConfig;
import org.openmetadata.catalog.Entity;
import org.openmetadata.catalog.api.CreateType;
import org.openmetadata.catalog.entity.Type;
import org.openmetadata.catalog.entity.type.Category;
import org.openmetadata.catalog.entity.type.CustomField;
import org.openmetadata.catalog.jdbi3.CollectionDAO;
import org.openmetadata.catalog.jdbi3.ListFilter;
@ -144,7 +143,7 @@ public class TypeResource extends EntityResource<Type, TypeRepository> {
description = "Filter types by metadata type category.",
schema = @Schema(type = "string", example = "Field, Entity"))
@QueryParam("category")
Category category,
String categoryParam,
@Parameter(description = "Limit the number types returned. (1 to 1000000, " + "default = 10)")
@DefaultValue("10")
@Min(0)
@ -158,7 +157,7 @@ public class TypeResource extends EntityResource<Type, TypeRepository> {
@QueryParam("after")
String after)
throws IOException {
ListFilter filter = new ListFilter(Include.ALL);
ListFilter filter = new ListFilter(Include.ALL).addQueryParam("category", categoryParam);
return super.listInternal(uriInfo, securityContext, "", filter, limitParam, before, after);
}