diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/CollectionDAO.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/CollectionDAO.java index 07660897ebc..762370f27e1 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/CollectionDAO.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/CollectionDAO.java @@ -3047,47 +3047,47 @@ public interface CollectionDAO { interface UtilDAO { @ConnectionAwareSqlQuery( value = - "SELECT (SELECT COUNT(*) FROM table_entity) as tableCount, " - + "(SELECT COUNT(*) FROM topic_entity) as topicCount, " - + "(SELECT COUNT(*) FROM dashboard_entity) as dashboardCount, " - + "(SELECT COUNT(*) FROM pipeline_entity) as pipelineCount, " - + "(SELECT COUNT(*) FROM ml_model_entity) as mlmodelCount, " - + "(SELECT (SELECT COUNT(*) FROM database_entity) + " - + "(SELECT COUNT(*) FROM messaging_service_entity)+ " - + "(SELECT COUNT(*) FROM dashboard_service_entity)+ " - + "(SELECT COUNT(*) FROM pipeline_service_entity)+ " - + "(SELECT COUNT(*) FROM mlmodel_service_entity)) as servicesCount, " - + "(SELECT COUNT(*) FROM user_entity WHERE JSON_EXTRACT(json, '$.isBot') IS NULL OR JSON_EXTRACT(json, '$.isBot') = FALSE) as userCount, " - + "(SELECT COUNT(*) FROM team_entity) as teamCount, " - + "(SELECT COUNT(*) FROM test_suite) as testSuiteCount", + "SELECT (SELECT COUNT(*) FROM table_entity ) as tableCount, " + + "(SELECT COUNT(*) FROM topic_entity ) as topicCount, " + + "(SELECT COUNT(*) FROM dashboard_entity ) as dashboardCount, " + + "(SELECT COUNT(*) FROM pipeline_entity ) as pipelineCount, " + + "(SELECT COUNT(*) FROM ml_model_entity ) as mlmodelCount, " + + "(SELECT (SELECT COUNT(*) FROM database_entity ) + " + + "(SELECT COUNT(*) FROM messaging_service_entity )+ " + + "(SELECT COUNT(*) FROM dashboard_service_entity )+ " + + "(SELECT COUNT(*) FROM pipeline_service_entity )+ " + + "(SELECT COUNT(*) FROM mlmodel_service_entity )) as servicesCount, " + + "(SELECT COUNT(*) FROM user_entity AND (JSON_EXTRACT(json, '$.isBot') IS NULL OR JSON_EXTRACT(json, '$.isBot') = FALSE)) as userCount, " + + "(SELECT COUNT(*) FROM team_entity ) as teamCount, " + + "(SELECT COUNT(*) FROM test_suite ) as testSuiteCount", connectionType = MYSQL) @ConnectionAwareSqlQuery( value = - "SELECT (SELECT COUNT(*) FROM table_entity) as tableCount, " - + "(SELECT COUNT(*) FROM topic_entity) as topicCount, " - + "(SELECT COUNT(*) FROM dashboard_entity) as dashboardCount, " - + "(SELECT COUNT(*) FROM pipeline_entity) as pipelineCount, " - + "(SELECT COUNT(*) FROM ml_model_entity) as mlmodelCount, " - + "(SELECT (SELECT COUNT(*) FROM database_entity) + " - + "(SELECT COUNT(*) FROM messaging_service_entity)+ " - + "(SELECT COUNT(*) FROM dashboard_service_entity)+ " - + "(SELECT COUNT(*) FROM pipeline_service_entity)+ " - + "(SELECT COUNT(*) FROM mlmodel_service_entity)) as servicesCount, " - + "(SELECT COUNT(*) FROM user_entity WHERE json#>'{isBot}' IS NULL OR ((json#>'{isBot}')::boolean) = FALSE) as userCount, " - + "(SELECT COUNT(*) FROM team_entity) as teamCount, " - + "(SELECT COUNT(*) FROM test_suite) as testSuiteCount", + "SELECT (SELECT COUNT(*) FROM table_entity ) as tableCount, " + + "(SELECT COUNT(*) FROM topic_entity ) as topicCount, " + + "(SELECT COUNT(*) FROM dashboard_entity ) as dashboardCount, " + + "(SELECT COUNT(*) FROM pipeline_entity ) as pipelineCount, " + + "(SELECT COUNT(*) FROM ml_model_entity ) as mlmodelCount, " + + "(SELECT (SELECT COUNT(*) FROM database_entity ) + " + + "(SELECT COUNT(*) FROM messaging_service_entity )+ " + + "(SELECT COUNT(*) FROM dashboard_service_entity )+ " + + "(SELECT COUNT(*) FROM pipeline_service_entity )+ " + + "(SELECT COUNT(*) FROM mlmodel_service_entity )) as servicesCount, " + + "(SELECT COUNT(*) FROM user_entity AND (json#>'{isBot}' IS NULL OR ((json#>'{isBot}')::boolean) = FALSE)) as userCount, " + + "(SELECT COUNT(*) FROM team_entity ) as teamCount, " + + "(SELECT COUNT(*) FROM test_suite ) as testSuiteCount", connectionType = POSTGRES) @RegisterRowMapper(EntitiesCountRowMapper.class) - EntitiesCount getAggregatedEntitiesCount() throws StatementException; + EntitiesCount getAggregatedEntitiesCount(@Define("cond") String cond) throws StatementException; @SqlQuery( - "SELECT (SELECT COUNT(*) FROM database_entity) as databaseServiceCount, " - + "(SELECT COUNT(*) FROM messaging_service_entity) as messagingServiceCount, " - + "(SELECT COUNT(*) FROM dashboard_service_entity) as dashboardServiceCount, " - + "(SELECT COUNT(*) FROM pipeline_service_entity) as pipelineServiceCount, " - + "(SELECT COUNT(*) FROM mlmodel_service_entity) as mlModelServiceCount") + "SELECT (SELECT COUNT(*) FROM database_entity ) as databaseServiceCount, " + + "(SELECT COUNT(*) FROM messaging_service_entity ) as messagingServiceCount, " + + "(SELECT COUNT(*) FROM dashboard_service_entity ) as dashboardServiceCount, " + + "(SELECT COUNT(*) FROM pipeline_service_entity ) as pipelineServiceCount, " + + "(SELECT COUNT(*) FROM mlmodel_service_entity ) as mlModelServiceCount") @RegisterRowMapper(ServicesCountRowMapper.class) - ServicesCount getAggregatedServicesCount() throws StatementException; + ServicesCount getAggregatedServicesCount(@Define("cond") String cond) throws StatementException; } class SettingsRowMapper implements RowMapper { diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/UtilRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/UtilRepository.java index 7ccb52c82f5..7c82a674fd0 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/UtilRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/UtilRepository.java @@ -10,11 +10,11 @@ public class UtilRepository { this.dao = dao; } - public EntitiesCount getAllEntitiesCount() { - return dao.getAggregatedEntitiesCount(); + public EntitiesCount getAllEntitiesCount(ListFilter filter) { + return dao.getAggregatedEntitiesCount(filter.getCondition()); } - public ServicesCount getAllServicesCount() { - return dao.getAggregatedServicesCount(); + public ServicesCount getAllServicesCount(ListFilter filter) { + return dao.getAggregatedServicesCount(filter.getCondition()); } } diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/resources/util/UtilResource.java b/openmetadata-service/src/main/java/org/openmetadata/service/resources/util/UtilResource.java index 2b3744b7dad..9196b5f9ed9 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/resources/util/UtilResource.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/resources/util/UtilResource.java @@ -2,21 +2,26 @@ package org.openmetadata.service.resources.util; import io.swagger.annotations.Api; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.responses.ApiResponse; import java.util.Objects; import javax.ws.rs.Consumes; +import javax.ws.rs.DefaultValue; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.UriInfo; import lombok.extern.slf4j.Slf4j; +import org.openmetadata.schema.type.Include; import org.openmetadata.schema.util.EntitiesCount; import org.openmetadata.schema.util.ServicesCount; import org.openmetadata.service.jdbi3.CollectionDAO; +import org.openmetadata.service.jdbi3.ListFilter; import org.openmetadata.service.jdbi3.UtilRepository; import org.openmetadata.service.resources.Collection; import org.openmetadata.service.security.Authorizer; @@ -51,8 +56,16 @@ public class UtilResource { description = "List of Entities Count", content = @Content(mediaType = "application/json", schema = @Schema(implementation = EntitiesCount.class))) }) - public EntitiesCount listEntitiesCount(@Context UriInfo uriInfo) { - return utilRepository.getAllEntitiesCount(); + public EntitiesCount listEntitiesCount( + @Context UriInfo uriInfo, + @Parameter( + description = "Include all, deleted, or non-deleted entities.", + schema = @Schema(implementation = Include.class)) + @QueryParam("include") + @DefaultValue("non-deleted") + Include include) { + ListFilter filter = new ListFilter(include); + return utilRepository.getAllEntitiesCount(filter); } @GET @@ -68,7 +81,15 @@ public class UtilResource { description = "List of Services Count", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ServicesCount.class))) }) - public ServicesCount listServicesCount(@Context UriInfo uriInfo) { - return utilRepository.getAllServicesCount(); + public ServicesCount listServicesCount( + @Context UriInfo uriInfo, + @Parameter( + description = "Include all, deleted, or non-deleted entities.", + schema = @Schema(implementation = Include.class)) + @QueryParam("include") + @DefaultValue("non-deleted") + Include include) { + ListFilter filter = new ListFilter(include); + return utilRepository.getAllServicesCount(filter); } }