mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-08-10 10:08:11 +00:00
Issue-3596: Provide option to get counts for entities using list APIs by setting limit=0 (#3604)
This commit is contained in:
parent
9ff6b928e5
commit
377d3d6248
@ -276,15 +276,16 @@ public abstract class EntityRepository<T> {
|
|||||||
@Transaction
|
@Transaction
|
||||||
public final ResultList<T> listAfter(UriInfo uriInfo, Fields fields, ListFilter filter, int limitParam, String after)
|
public final ResultList<T> listAfter(UriInfo uriInfo, Fields fields, ListFilter filter, int limitParam, String after)
|
||||||
throws GeneralSecurityException, IOException, ParseException {
|
throws GeneralSecurityException, IOException, ParseException {
|
||||||
|
int total = dao.listCount(filter);
|
||||||
|
List<T> entities = new ArrayList<>();
|
||||||
|
if (limitParam > 0) {
|
||||||
// forward scrolling, if after == null then first page is being asked
|
// forward scrolling, if after == null then first page is being asked
|
||||||
List<String> jsons = dao.listAfter(filter, limitParam + 1, after == null ? "" : RestUtil.decodeCursor(after));
|
List<String> jsons = dao.listAfter(filter, limitParam + 1, after == null ? "" : RestUtil.decodeCursor(after));
|
||||||
|
|
||||||
List<T> entities = new ArrayList<>();
|
|
||||||
for (String json : jsons) {
|
for (String json : jsons) {
|
||||||
T entity = withHref(uriInfo, setFields(JsonUtils.readValue(json, entityClass), fields));
|
T entity = withHref(uriInfo, setFields(JsonUtils.readValue(json, entityClass), fields));
|
||||||
entities.add(entity);
|
entities.add(entity);
|
||||||
}
|
}
|
||||||
int total = dao.listCount(filter);
|
|
||||||
|
|
||||||
String beforeCursor;
|
String beforeCursor;
|
||||||
String afterCursor = null;
|
String afterCursor = null;
|
||||||
@ -294,6 +295,10 @@ public abstract class EntityRepository<T> {
|
|||||||
afterCursor = getFullyQualifiedName(entities.get(limitParam - 1));
|
afterCursor = getFullyQualifiedName(entities.get(limitParam - 1));
|
||||||
}
|
}
|
||||||
return getResultList(entities, beforeCursor, afterCursor, total);
|
return getResultList(entities, beforeCursor, afterCursor, total);
|
||||||
|
} else {
|
||||||
|
// limit == 0 , return total count of entity.
|
||||||
|
return getResultList(entities, null, null, total);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transaction
|
@Transaction
|
||||||
|
@ -87,7 +87,7 @@ public class BotsResource extends EntityResource<Bots, BotsRepository> {
|
|||||||
public ResultList<Bots> list(
|
public ResultList<Bots> list(
|
||||||
@Context UriInfo uriInfo,
|
@Context UriInfo uriInfo,
|
||||||
@Context SecurityContext securityContext,
|
@Context SecurityContext securityContext,
|
||||||
@DefaultValue("10") @Min(1) @Max(1000000) @QueryParam("limit") int limitParam,
|
@DefaultValue("10") @Min(0) @Max(1000000) @QueryParam("limit") int limitParam,
|
||||||
@Parameter(description = "Returns list of bots before this cursor", schema = @Schema(type = "string"))
|
@Parameter(description = "Returns list of bots before this cursor", schema = @Schema(type = "string"))
|
||||||
@QueryParam("before")
|
@QueryParam("before")
|
||||||
String before,
|
String before,
|
||||||
|
@ -129,7 +129,7 @@ public class ChartResource extends EntityResource<Chart, ChartRepository> {
|
|||||||
@Parameter(description = "Limit the number charts returned. (1 to 1000000, default = 10)")
|
@Parameter(description = "Limit the number charts returned. (1 to 1000000, default = 10)")
|
||||||
@DefaultValue("10")
|
@DefaultValue("10")
|
||||||
@QueryParam("limit")
|
@QueryParam("limit")
|
||||||
@Min(1)
|
@Min(0)
|
||||||
@Max(1000000)
|
@Max(1000000)
|
||||||
int limitParam,
|
int limitParam,
|
||||||
@Parameter(description = "Returns list of charts before this cursor", schema = @Schema(type = "string"))
|
@Parameter(description = "Returns list of charts before this cursor", schema = @Schema(type = "string"))
|
||||||
|
@ -130,7 +130,7 @@ public class DashboardResource extends EntityResource<Dashboard, DashboardReposi
|
|||||||
String serviceParam,
|
String serviceParam,
|
||||||
@Parameter(description = "Limit the number dashboards returned. (1 to 1000000, " + "default = 10)")
|
@Parameter(description = "Limit the number dashboards returned. (1 to 1000000, " + "default = 10)")
|
||||||
@DefaultValue("10")
|
@DefaultValue("10")
|
||||||
@Min(1)
|
@Min(0)
|
||||||
@Max(1000000)
|
@Max(1000000)
|
||||||
@QueryParam("limit")
|
@QueryParam("limit")
|
||||||
int limitParam,
|
int limitParam,
|
||||||
|
@ -128,7 +128,7 @@ public class DatabaseResource extends EntityResource<Database, DatabaseRepositor
|
|||||||
@Parameter(description = "Limit the number tables returned. (1 to 1000000, default" + " = 10)")
|
@Parameter(description = "Limit the number tables returned. (1 to 1000000, default" + " = 10)")
|
||||||
@DefaultValue("10")
|
@DefaultValue("10")
|
||||||
@QueryParam("limit")
|
@QueryParam("limit")
|
||||||
@Min(1)
|
@Min(0)
|
||||||
@Max(1000000)
|
@Max(1000000)
|
||||||
int limitParam,
|
int limitParam,
|
||||||
@Parameter(description = "Returns list of tables before this cursor", schema = @Schema(type = "string"))
|
@Parameter(description = "Returns list of tables before this cursor", schema = @Schema(type = "string"))
|
||||||
|
@ -153,7 +153,7 @@ public class TableResource extends EntityResource<Table, TableRepository> {
|
|||||||
String databaseParam,
|
String databaseParam,
|
||||||
@Parameter(description = "Limit the number tables returned. (1 to 1000000, default = " + "10) ")
|
@Parameter(description = "Limit the number tables returned. (1 to 1000000, default = " + "10) ")
|
||||||
@DefaultValue("10")
|
@DefaultValue("10")
|
||||||
@Min(1)
|
@Min(0)
|
||||||
@Max(1000000)
|
@Max(1000000)
|
||||||
@QueryParam("limit")
|
@QueryParam("limit")
|
||||||
int limitParam,
|
int limitParam,
|
||||||
|
@ -105,7 +105,7 @@ public class WebhookResource extends EntityResource<Webhook, WebhookRepository>
|
|||||||
@Context SecurityContext securityContext,
|
@Context SecurityContext securityContext,
|
||||||
@Parameter(description = "Limit the number webhooks returned. (1 to 1000000, default = " + "10) ")
|
@Parameter(description = "Limit the number webhooks returned. (1 to 1000000, default = " + "10) ")
|
||||||
@DefaultValue("10")
|
@DefaultValue("10")
|
||||||
@Min(1)
|
@Min(0)
|
||||||
@Max(1000000)
|
@Max(1000000)
|
||||||
@QueryParam("limit")
|
@QueryParam("limit")
|
||||||
int limitParam,
|
int limitParam,
|
||||||
|
@ -135,7 +135,7 @@ public class FeedResource {
|
|||||||
@Parameter(
|
@Parameter(
|
||||||
description = "Limit the number of posts sorted by chronological order (1 to 1000000, default = 3)",
|
description = "Limit the number of posts sorted by chronological order (1 to 1000000, default = 3)",
|
||||||
schema = @Schema(type = "integer"))
|
schema = @Schema(type = "integer"))
|
||||||
@Min(1)
|
@Min(0)
|
||||||
@Max(1000000)
|
@Max(1000000)
|
||||||
@DefaultValue("3")
|
@DefaultValue("3")
|
||||||
@QueryParam("limitPosts")
|
@QueryParam("limitPosts")
|
||||||
|
@ -128,7 +128,7 @@ public class GlossaryResource extends EntityResource<Glossary, GlossaryRepositor
|
|||||||
String fieldsParam,
|
String fieldsParam,
|
||||||
@Parameter(description = "Limit the number glossaries returned. (1 to 1000000, " + "default = 10)")
|
@Parameter(description = "Limit the number glossaries returned. (1 to 1000000, " + "default = 10)")
|
||||||
@DefaultValue("10")
|
@DefaultValue("10")
|
||||||
@Min(1)
|
@Min(0)
|
||||||
@Max(1000000)
|
@Max(1000000)
|
||||||
@QueryParam("limit")
|
@QueryParam("limit")
|
||||||
int limitParam,
|
int limitParam,
|
||||||
|
@ -146,7 +146,7 @@ public class GlossaryTermResource extends EntityResource<GlossaryTerm, GlossaryT
|
|||||||
String fieldsParam,
|
String fieldsParam,
|
||||||
@Parameter(description = "Limit the number glossary terms returned. (1 to 1000000, " + "default = 10)")
|
@Parameter(description = "Limit the number glossary terms returned. (1 to 1000000, " + "default = 10)")
|
||||||
@DefaultValue("10")
|
@DefaultValue("10")
|
||||||
@Min(1)
|
@Min(0)
|
||||||
@Max(1000000)
|
@Max(1000000)
|
||||||
@QueryParam("limit")
|
@QueryParam("limit")
|
||||||
int limitParam,
|
int limitParam,
|
||||||
|
@ -127,7 +127,7 @@ public class LocationResource extends EntityResource<Location, LocationRepositor
|
|||||||
String serviceParam,
|
String serviceParam,
|
||||||
@Parameter(description = "Limit the number locations returned. " + "(1 to 1000000, default = 10)")
|
@Parameter(description = "Limit the number locations returned. " + "(1 to 1000000, default = 10)")
|
||||||
@DefaultValue("10")
|
@DefaultValue("10")
|
||||||
@Min(1)
|
@Min(0)
|
||||||
@Max(1000000)
|
@Max(1000000)
|
||||||
@QueryParam("limit")
|
@QueryParam("limit")
|
||||||
int limitParam,
|
int limitParam,
|
||||||
|
@ -98,7 +98,7 @@ public class MetricsResource extends EntityResource<Metrics, MetricsRepository>
|
|||||||
schema = @Schema(type = "string", example = FIELDS))
|
schema = @Schema(type = "string", example = FIELDS))
|
||||||
@QueryParam("fields")
|
@QueryParam("fields")
|
||||||
String fieldsParam,
|
String fieldsParam,
|
||||||
@DefaultValue("10") @Min(1) @Max(1000000) @QueryParam("limit") int limitParam,
|
@DefaultValue("10") @Min(0) @Max(1000000) @QueryParam("limit") int limitParam,
|
||||||
@Parameter(description = "Returns list of metrics before this cursor", schema = @Schema(type = "string"))
|
@Parameter(description = "Returns list of metrics before this cursor", schema = @Schema(type = "string"))
|
||||||
@QueryParam("before")
|
@QueryParam("before")
|
||||||
String before,
|
String before,
|
||||||
|
@ -126,7 +126,7 @@ public class MlModelResource extends EntityResource<MlModel, MlModelRepository>
|
|||||||
String fieldsParam,
|
String fieldsParam,
|
||||||
@Parameter(description = "Limit the number models returned. (1 to 1000000, " + "default = 10)")
|
@Parameter(description = "Limit the number models returned. (1 to 1000000, " + "default = 10)")
|
||||||
@DefaultValue("10")
|
@DefaultValue("10")
|
||||||
@Min(1)
|
@Min(0)
|
||||||
@Max(1000000)
|
@Max(1000000)
|
||||||
@QueryParam("limit")
|
@QueryParam("limit")
|
||||||
int limitParam,
|
int limitParam,
|
||||||
|
@ -152,7 +152,7 @@ public class AirflowPipelineResource extends EntityResource<AirflowPipeline, Air
|
|||||||
String serviceParam,
|
String serviceParam,
|
||||||
@Parameter(description = "Limit the number ingestion returned. (1 to 1000000, " + "default = 10)")
|
@Parameter(description = "Limit the number ingestion returned. (1 to 1000000, " + "default = 10)")
|
||||||
@DefaultValue("10")
|
@DefaultValue("10")
|
||||||
@Min(1)
|
@Min(0)
|
||||||
@Max(1000000)
|
@Max(1000000)
|
||||||
@QueryParam("limit")
|
@QueryParam("limit")
|
||||||
int limitParam,
|
int limitParam,
|
||||||
|
@ -132,7 +132,7 @@ public class PipelineResource extends EntityResource<Pipeline, PipelineRepositor
|
|||||||
String serviceParam,
|
String serviceParam,
|
||||||
@Parameter(description = "Limit the number pipelines returned. (1 to 1000000, " + "default = 10)")
|
@Parameter(description = "Limit the number pipelines returned. (1 to 1000000, " + "default = 10)")
|
||||||
@DefaultValue("10")
|
@DefaultValue("10")
|
||||||
@Min(1)
|
@Min(0)
|
||||||
@Max(1000000)
|
@Max(1000000)
|
||||||
@QueryParam("limit")
|
@QueryParam("limit")
|
||||||
int limitParam,
|
int limitParam,
|
||||||
|
@ -137,7 +137,7 @@ public class PolicyResource extends EntityResource<Policy, PolicyRepository> {
|
|||||||
String fieldsParam,
|
String fieldsParam,
|
||||||
@Parameter(description = "Limit the number policies returned. (1 to 1000000, " + "default = 10)")
|
@Parameter(description = "Limit the number policies returned. (1 to 1000000, " + "default = 10)")
|
||||||
@DefaultValue("10")
|
@DefaultValue("10")
|
||||||
@Min(1)
|
@Min(0)
|
||||||
@Max(1000000)
|
@Max(1000000)
|
||||||
@QueryParam("limit")
|
@QueryParam("limit")
|
||||||
int limitParam,
|
int limitParam,
|
||||||
|
@ -112,7 +112,7 @@ public class DashboardServiceResource extends EntityResource<DashboardService, D
|
|||||||
schema = @Schema(type = "string", example = FIELDS))
|
schema = @Schema(type = "string", example = FIELDS))
|
||||||
@QueryParam("fields")
|
@QueryParam("fields")
|
||||||
String fieldsParam,
|
String fieldsParam,
|
||||||
@DefaultValue("10") @Min(1) @Max(1000000) @QueryParam("limit") int limitParam,
|
@DefaultValue("10") @Min(0) @Max(1000000) @QueryParam("limit") int limitParam,
|
||||||
@Parameter(
|
@Parameter(
|
||||||
description = "Returns list of dashboard services before this cursor",
|
description = "Returns list of dashboard services before this cursor",
|
||||||
schema = @Schema(type = "string"))
|
schema = @Schema(type = "string"))
|
||||||
|
@ -123,7 +123,7 @@ public class DatabaseServiceResource extends EntityResource<DatabaseService, Dat
|
|||||||
schema = @Schema(type = "string", example = FIELDS))
|
schema = @Schema(type = "string", example = FIELDS))
|
||||||
@QueryParam("fields")
|
@QueryParam("fields")
|
||||||
String fieldsParam,
|
String fieldsParam,
|
||||||
@DefaultValue("10") @Min(1) @Max(1000000) @QueryParam("limit") int limitParam,
|
@DefaultValue("10") @Min(0) @Max(1000000) @QueryParam("limit") int limitParam,
|
||||||
@Parameter(
|
@Parameter(
|
||||||
description = "Returns list of database services before this cursor",
|
description = "Returns list of database services before this cursor",
|
||||||
schema = @Schema(type = "string"))
|
schema = @Schema(type = "string"))
|
||||||
|
@ -116,7 +116,7 @@ public class MessagingServiceResource extends EntityResource<MessagingService, M
|
|||||||
String fieldsParam,
|
String fieldsParam,
|
||||||
@Parameter(description = "Limit number services returned. (1 to 1000000, " + "default 10)")
|
@Parameter(description = "Limit number services returned. (1 to 1000000, " + "default 10)")
|
||||||
@DefaultValue("10")
|
@DefaultValue("10")
|
||||||
@Min(1)
|
@Min(0)
|
||||||
@Max(1000000)
|
@Max(1000000)
|
||||||
@QueryParam("limit")
|
@QueryParam("limit")
|
||||||
int limitParam,
|
int limitParam,
|
||||||
|
@ -116,7 +116,7 @@ public class PipelineServiceResource extends EntityResource<PipelineService, Pip
|
|||||||
String fieldsParam,
|
String fieldsParam,
|
||||||
@Parameter(description = "Limit number services returned. (1 to 1000000, " + "default 10)")
|
@Parameter(description = "Limit number services returned. (1 to 1000000, " + "default 10)")
|
||||||
@DefaultValue("10")
|
@DefaultValue("10")
|
||||||
@Min(1)
|
@Min(0)
|
||||||
@Max(1000000)
|
@Max(1000000)
|
||||||
@QueryParam("limit")
|
@QueryParam("limit")
|
||||||
int limitParam,
|
int limitParam,
|
||||||
|
@ -116,7 +116,7 @@ public class StorageServiceResource extends EntityResource<StorageService, Stora
|
|||||||
String fieldsParam,
|
String fieldsParam,
|
||||||
@Parameter(description = "Limit number of services returned. (1 to 1000000, " + "default 10)")
|
@Parameter(description = "Limit number of services returned. (1 to 1000000, " + "default 10)")
|
||||||
@DefaultValue("10")
|
@DefaultValue("10")
|
||||||
@Min(1)
|
@Min(0)
|
||||||
@Max(1000000)
|
@Max(1000000)
|
||||||
@QueryParam("limit")
|
@QueryParam("limit")
|
||||||
int limitParam,
|
int limitParam,
|
||||||
|
@ -130,7 +130,7 @@ public class RoleResource extends EntityResource<Role, RoleRepository> {
|
|||||||
String fieldsParam,
|
String fieldsParam,
|
||||||
@Parameter(description = "Limit the number tables returned. (1 to 1000000, default = 10)")
|
@Parameter(description = "Limit the number tables returned. (1 to 1000000, default = 10)")
|
||||||
@DefaultValue("10")
|
@DefaultValue("10")
|
||||||
@Min(1)
|
@Min(0)
|
||||||
@Max(1000000)
|
@Max(1000000)
|
||||||
@QueryParam("limit")
|
@QueryParam("limit")
|
||||||
int limitParam,
|
int limitParam,
|
||||||
|
@ -123,7 +123,7 @@ public class TeamResource extends EntityResource<Team, TeamRepository> {
|
|||||||
String fieldsParam,
|
String fieldsParam,
|
||||||
@Parameter(description = "Limit the number tables returned. (1 to 1000000, default = 10)")
|
@Parameter(description = "Limit the number tables returned. (1 to 1000000, default = 10)")
|
||||||
@DefaultValue("10")
|
@DefaultValue("10")
|
||||||
@Min(1)
|
@Min(0)
|
||||||
@Max(1000000)
|
@Max(1000000)
|
||||||
@QueryParam("limit")
|
@QueryParam("limit")
|
||||||
int limitParam,
|
int limitParam,
|
||||||
|
@ -131,7 +131,7 @@ public class UserResource extends EntityResource<User, UserRepository> {
|
|||||||
String teamParam,
|
String teamParam,
|
||||||
@Parameter(description = "Limit the number users returned. (1 to 1000000, default = 10)")
|
@Parameter(description = "Limit the number users returned. (1 to 1000000, default = 10)")
|
||||||
@DefaultValue("10")
|
@DefaultValue("10")
|
||||||
@Min(1)
|
@Min(0)
|
||||||
@Max(1000000)
|
@Max(1000000)
|
||||||
@QueryParam("limit")
|
@QueryParam("limit")
|
||||||
int limitParam,
|
int limitParam,
|
||||||
|
@ -133,7 +133,7 @@ public class TopicResource extends EntityResource<Topic, TopicRepository> {
|
|||||||
@Parameter(description = "Limit the number topics returned. (1 to 1000000, default = " + "10)")
|
@Parameter(description = "Limit the number topics returned. (1 to 1000000, default = " + "10)")
|
||||||
@DefaultValue("10")
|
@DefaultValue("10")
|
||||||
@QueryParam("limit")
|
@QueryParam("limit")
|
||||||
@Min(1)
|
@Min(0)
|
||||||
@Max(1000000)
|
@Max(1000000)
|
||||||
int limitParam,
|
int limitParam,
|
||||||
@Parameter(description = "Returns list of topics before this cursor", schema = @Schema(type = "string"))
|
@Parameter(description = "Returns list of topics before this cursor", schema = @Schema(type = "string"))
|
||||||
|
@ -719,12 +719,12 @@ public abstract class EntityResourceTest<T, K> extends CatalogApplicationTest {
|
|||||||
assertResponse(
|
assertResponse(
|
||||||
() -> listEntities(null, -1, null, null, ADMIN_AUTH_HEADERS),
|
() -> listEntities(null, -1, null, null, ADMIN_AUTH_HEADERS),
|
||||||
BAD_REQUEST,
|
BAD_REQUEST,
|
||||||
"[query param limit must be greater than or equal to 1]");
|
"[query param limit must be greater than or equal to 0]");
|
||||||
|
|
||||||
assertResponse(
|
assertResponse(
|
||||||
() -> listEntities(null, 0, null, null, ADMIN_AUTH_HEADERS),
|
() -> listEntities(null, -1, null, null, ADMIN_AUTH_HEADERS),
|
||||||
BAD_REQUEST,
|
BAD_REQUEST,
|
||||||
"[query param limit must be greater than or equal to 1]");
|
"[query param limit must be greater than or equal to 0]");
|
||||||
|
|
||||||
assertResponse(
|
assertResponse(
|
||||||
() -> listEntities(null, 1000001, null, null, ADMIN_AUTH_HEADERS),
|
() -> listEntities(null, 1000001, null, null, ADMIN_AUTH_HEADERS),
|
||||||
|
@ -366,11 +366,11 @@ public class FeedResourceTest extends CatalogApplicationTest {
|
|||||||
thread = threads.getData().get(0);
|
thread = threads.getData().get(0);
|
||||||
assertEquals(3, thread.getPosts().size());
|
assertEquals(3, thread.getPosts().size());
|
||||||
|
|
||||||
// limit 0 is not supported and should throw an exception
|
// limit <0 is not supported and should throw an exception
|
||||||
assertResponse(
|
assertResponse(
|
||||||
() -> listThreads(null, 0, AUTH_HEADERS),
|
() -> listThreads(null, -1, AUTH_HEADERS),
|
||||||
BAD_REQUEST,
|
BAD_REQUEST,
|
||||||
"[query param limitPosts must be greater than or equal to 1]");
|
"[query param limitPosts must be greater than or equal to 0]");
|
||||||
|
|
||||||
// limit greater than total number of posts should return correct response
|
// limit greater than total number of posts should return correct response
|
||||||
threads = listThreads(null, 100, AUTH_HEADERS);
|
threads = listThreads(null, 100, AUTH_HEADERS);
|
||||||
|
@ -192,12 +192,7 @@ public class PolicyResourceTest extends EntityResourceTest<Policy, CreatePolicy>
|
|||||||
assertResponse(
|
assertResponse(
|
||||||
() -> listPolicies(null, -1, null, null, ADMIN_AUTH_HEADERS),
|
() -> listPolicies(null, -1, null, null, ADMIN_AUTH_HEADERS),
|
||||||
BAD_REQUEST,
|
BAD_REQUEST,
|
||||||
"[query param limit must be greater than or equal to 1]");
|
"[query param limit must be greater than or equal to 0]");
|
||||||
|
|
||||||
assertResponse(
|
|
||||||
() -> listPolicies(null, 0, null, null, ADMIN_AUTH_HEADERS),
|
|
||||||
BAD_REQUEST,
|
|
||||||
"[query param limit must be greater than or equal to 1]");
|
|
||||||
|
|
||||||
assertResponse(
|
assertResponse(
|
||||||
() -> listPolicies(null, 1000001, null, null, ADMIN_AUTH_HEADERS),
|
() -> listPolicies(null, 1000001, null, null, ADMIN_AUTH_HEADERS),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user