mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-09-26 01:15:08 +00:00
Backend: Util counts api fix (#6473)
This commit is contained in:
parent
818736e2ca
commit
2f65eb711a
@ -2473,7 +2473,7 @@ public interface CollectionDAO {
|
||||
+ "(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) as userCount, "
|
||||
+ "(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",
|
||||
connectionType = MYSQL)
|
||||
@ConnectionAwareSqlQuery(
|
||||
@ -2488,7 +2488,7 @@ public interface CollectionDAO {
|
||||
+ "(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) as userCount, "
|
||||
+ "(SELECT COUNT(*) FROM user_entity WHERE json#>'{isBot}' IS NULL OR ((json#>'{isBot}')::boolean) = FALSE) as userCount, "
|
||||
+ "(SELECT COUNT(*) FROM team_entity) as teamCount",
|
||||
connectionType = POSTGRES)
|
||||
@RegisterRowMapper(EntitiesCountRowMapper.class)
|
||||
|
@ -1,14 +1,5 @@
|
||||
package org.openmetadata.catalog.jdbi3;
|
||||
|
||||
import static org.openmetadata.catalog.Entity.DASHBOARD;
|
||||
import static org.openmetadata.catalog.Entity.MLMODEL;
|
||||
import static org.openmetadata.catalog.Entity.PIPELINE;
|
||||
import static org.openmetadata.catalog.Entity.SERVICE;
|
||||
import static org.openmetadata.catalog.Entity.TABLE;
|
||||
import static org.openmetadata.catalog.Entity.TEAM;
|
||||
import static org.openmetadata.catalog.Entity.TOPIC;
|
||||
import static org.openmetadata.catalog.Entity.USER;
|
||||
|
||||
import org.openmetadata.catalog.util.EntitiesCount;
|
||||
import org.openmetadata.catalog.util.ServicesCount;
|
||||
|
||||
@ -26,27 +17,4 @@ public class UtilRepository {
|
||||
public ServicesCount getAllServicesCount() {
|
||||
return dao.getAggregatedServicesCount();
|
||||
}
|
||||
|
||||
public Object getIndividualEntityCount(String entity) {
|
||||
switch (entity) {
|
||||
case TABLE:
|
||||
return dao.getAggregatedEntitiesCount().getTableCount();
|
||||
case TOPIC:
|
||||
return dao.getAggregatedEntitiesCount().getTopicCount();
|
||||
case DASHBOARD:
|
||||
return dao.getAggregatedEntitiesCount().getDashboardCount();
|
||||
case PIPELINE:
|
||||
return dao.getAggregatedEntitiesCount().getPipelineCount();
|
||||
case MLMODEL:
|
||||
return dao.getAggregatedEntitiesCount().getMlmodelCount();
|
||||
case SERVICE:
|
||||
return dao.getAggregatedEntitiesCount().getServicesCount();
|
||||
case USER:
|
||||
return dao.getAggregatedEntitiesCount().getUserCount();
|
||||
case TEAM:
|
||||
return dao.getAggregatedEntitiesCount().getTeamCount();
|
||||
default:
|
||||
return "Invalid Entity";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package org.openmetadata.catalog.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;
|
||||
@ -10,7 +9,6 @@ import java.util.Objects;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
@ -73,28 +71,4 @@ public class UtilResource {
|
||||
public ServicesCount listServicesCount(@Context UriInfo uriInfo) {
|
||||
return utilRepository.getAllServicesCount();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/{entity}/count")
|
||||
@Operation(
|
||||
operationId = "listEntityCount",
|
||||
summary = "List Individual Entity Count",
|
||||
tags = "util",
|
||||
description = "Get total count of an Entity",
|
||||
responses = {
|
||||
@ApiResponse(
|
||||
responseCode = "200",
|
||||
description = "List of Services Count",
|
||||
content = @Content(mediaType = "application/json"))
|
||||
})
|
||||
public Object listEntityCount(
|
||||
@Context UriInfo uriInfo,
|
||||
@Parameter(
|
||||
description = "Entity type for which usage is requested",
|
||||
required = true,
|
||||
schema = @Schema(type = "string", example = "table, pipeline, topic, or dashboard"))
|
||||
@PathParam("entity")
|
||||
String entity) {
|
||||
return utilRepository.getIndividualEntityCount(entity);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"$id": "https://open-metadata.org/schema/entity/tags/entitiesCount.json",
|
||||
"$id": "https://open-metadata.org/schema/entity/utils/entitiesCount.json",
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"title": "Entities Count",
|
||||
"description": "This schema defines Entities Count. This contains aggregated entities count.",
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"$id": "https://open-metadata.org/schema/entity/tags/servicesCount.json",
|
||||
"$id": "https://open-metadata.org/schema/entity/utils/servicesCount.json",
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"title": "Services Count",
|
||||
"description": "This schema defines Services Count. This contains aggregated services count.",
|
||||
|
@ -1,8 +1,5 @@
|
||||
package org.openmetadata.catalog.resources.util;
|
||||
|
||||
import static org.openmetadata.catalog.Entity.DASHBOARD;
|
||||
import static org.openmetadata.catalog.Entity.TABLE;
|
||||
import static org.openmetadata.catalog.Entity.TOPIC;
|
||||
import static org.openmetadata.catalog.util.TestUtils.ADMIN_AUTH_HEADERS;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -65,11 +62,6 @@ public class UtilResourceTest extends CatalogApplicationTest {
|
||||
return TestUtils.get(target, ServicesCount.class, ADMIN_AUTH_HEADERS);
|
||||
}
|
||||
|
||||
public static Object getIndividualEntityCount(String entity) throws HttpResponseException {
|
||||
WebTarget target = CatalogApplicationTest.getResource("util/" + entity + "/count");
|
||||
return TestUtils.get(target, Object.class, ADMIN_AUTH_HEADERS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void entitiesCount(TestInfo test) throws HttpResponseException {
|
||||
|
||||
@ -185,34 +177,17 @@ public class UtilResourceTest extends CatalogApplicationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void individualEntityCount(TestInfo test) throws HttpResponseException {
|
||||
public void botUserCountCheck(TestInfo test) throws HttpResponseException {
|
||||
int beforeUserCount = getEntitiesCount().getUserCount();
|
||||
|
||||
int beforeTableCount = (int) getIndividualEntityCount(TABLE);
|
||||
int beforeDashboardCount = (int) getIndividualEntityCount(DASHBOARD);
|
||||
int beforeTopicCount = (int) getIndividualEntityCount(TOPIC);
|
||||
// Create a bot user.
|
||||
UserResourceTest userResourceTest = new UserResourceTest();
|
||||
CreateUser createUser = userResourceTest.createRequest(test).withIsBot(true);
|
||||
userResourceTest.createEntity(createUser, ADMIN_AUTH_HEADERS);
|
||||
|
||||
TableResourceTest tableResourceTest = new TableResourceTest();
|
||||
CreateTable createTable = tableResourceTest.createRequest(test);
|
||||
tableResourceTest.createEntity(createTable, ADMIN_AUTH_HEADERS);
|
||||
int afterUserCount = getEntitiesCount().getUserCount();
|
||||
|
||||
// Create Dashboard
|
||||
DashboardResourceTest dashboardResourceTest = new DashboardResourceTest();
|
||||
CreateDashboard createDashboard = dashboardResourceTest.createRequest(test);
|
||||
dashboardResourceTest.createEntity(createDashboard, ADMIN_AUTH_HEADERS);
|
||||
|
||||
// Create Topic
|
||||
TopicResourceTest topicResourceTest = new TopicResourceTest();
|
||||
CreateTopic createTopic = topicResourceTest.createRequest(test);
|
||||
topicResourceTest.createEntity(createTopic, ADMIN_AUTH_HEADERS);
|
||||
|
||||
int afterTableCount = (int) getIndividualEntityCount(TABLE);
|
||||
int afterDashboardCount = (int) getIndividualEntityCount(DASHBOARD);
|
||||
int afterTopicCount = (int) getIndividualEntityCount(TOPIC);
|
||||
|
||||
int actualCount = 1;
|
||||
|
||||
Assertions.assertEquals(afterDashboardCount - beforeDashboardCount, actualCount);
|
||||
Assertions.assertEquals(afterTableCount - beforeTableCount, actualCount);
|
||||
Assertions.assertEquals(afterTopicCount - beforeTopicCount, actualCount);
|
||||
// The bot user count should not be considered.
|
||||
Assertions.assertEquals(beforeUserCount, afterUserCount);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user