diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/exception/CatalogExceptionMessage.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/exception/CatalogExceptionMessage.java index 5f16854d4b8..fcb0ef77b56 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/exception/CatalogExceptionMessage.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/exception/CatalogExceptionMessage.java @@ -57,7 +57,7 @@ public final class CatalogExceptionMessage { return String.format("%s instance for %s and version %s not found", entityType, id, version); } - public static String invalidServiceEntity(String serviceEntity, String entityType) { - return String.format("Invalid service entity type %s for %s", serviceEntity, entityType); + public static String invalidServiceEntity(String serviceType, String entityType, String expected) { + return String.format("Invalid service type `%s` for %s. Expected %s.", serviceType, entityType, expected); } } diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/DashboardRepository.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/DashboardRepository.java index 468ba096736..dcc465d27ac 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/DashboardRepository.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/DashboardRepository.java @@ -113,7 +113,8 @@ public class DashboardRepository extends EntityRepository { if (entityType.equalsIgnoreCase(Entity.DASHBOARD_SERVICE)) { return daoCollection.dashboardServiceDAO().findEntityById(serviceId); } - throw new IllegalArgumentException(CatalogExceptionMessage.invalidServiceEntity(entityType, Entity.DASHBOARD)); + throw new IllegalArgumentException( + CatalogExceptionMessage.invalidServiceEntity(entityType, Entity.DASHBOARD, Entity.DASHBOARD_SERVICE)); } public void setService(Dashboard dashboard, EntityReference service) { diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/DatabaseRepository.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/DatabaseRepository.java index 4a3cf6bdf43..8ece0317671 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/DatabaseRepository.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/DatabaseRepository.java @@ -193,7 +193,8 @@ public class DatabaseRepository extends EntityRepository { if (entityType.equalsIgnoreCase(Entity.DATABASE_SERVICE)) { return daoCollection.dbServiceDAO().findEntityById(serviceId); } - throw new IllegalArgumentException(CatalogExceptionMessage.invalidServiceEntity(entityType, Entity.DATABASE)); + throw new IllegalArgumentException( + CatalogExceptionMessage.invalidServiceEntity(entityType, Entity.DATABASE, Entity.DATABASE_SERVICE)); } @Transaction diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/LocationRepository.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/LocationRepository.java index d4e9ad29777..a0b77bd6c15 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/LocationRepository.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/LocationRepository.java @@ -170,7 +170,8 @@ public class LocationRepository extends EntityRepository { if (entityType.equalsIgnoreCase(Entity.STORAGE_SERVICE)) { return daoCollection.storageServiceDAO().findEntityById(serviceId); } - throw new IllegalArgumentException(CatalogExceptionMessage.invalidServiceEntity(entityType, Entity.LOCATION)); + throw new IllegalArgumentException( + CatalogExceptionMessage.invalidServiceEntity(entityType, Entity.LOCATION, STORAGE_SERVICE)); } @Override @@ -231,7 +232,7 @@ public class LocationRepository extends EntityRepository { return daoCollection.storageServiceDAO().findEntityReferenceById(service.getId()); } throw new IllegalArgumentException( - CatalogExceptionMessage.invalidServiceEntity(service.getType(), Entity.LOCATION)); + CatalogExceptionMessage.invalidServiceEntity(service.getType(), Entity.LOCATION, STORAGE_SERVICE)); } public void setService(Location location, EntityReference service) throws IOException { diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/MetricsRepository.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/MetricsRepository.java index d8e28b1ae86..fb4d18ae2dd 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/MetricsRepository.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/MetricsRepository.java @@ -118,7 +118,8 @@ public class MetricsRepository extends EntityRepository { if (service.getType().equalsIgnoreCase(Entity.DASHBOARD_SERVICE)) { return daoCollection.dbServiceDAO().findEntityReferenceById(service.getId()); } - throw new IllegalArgumentException(CatalogExceptionMessage.invalidServiceEntity(service.getType(), Entity.METRICS)); + throw new IllegalArgumentException( + CatalogExceptionMessage.invalidServiceEntity(service.getType(), Entity.METRICS, DASHBOARD_SERVICE)); } static class MetricsEntityInterface implements EntityInterface { diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/PipelineRepository.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/PipelineRepository.java index e58a56dbaf1..34cde8cdd45 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/PipelineRepository.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/PipelineRepository.java @@ -163,7 +163,8 @@ public class PipelineRepository extends EntityRepository { if (entityType.equalsIgnoreCase(Entity.PIPELINE_SERVICE)) { return daoCollection.pipelineServiceDAO().findEntityById(serviceId); } - throw new IllegalArgumentException(CatalogExceptionMessage.invalidServiceEntity(entityType, Entity.PIPELINE)); + throw new IllegalArgumentException( + CatalogExceptionMessage.invalidServiceEntity(entityType, Entity.PIPELINE, PIPELINE_SERVICE)); } public static class PipelineEntityInterface implements EntityInterface { diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/dashboards/DashboardResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/dashboards/DashboardResourceTest.java index 6daa66d3eff..8a3275108c1 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/dashboards/DashboardResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/dashboards/DashboardResourceTest.java @@ -25,6 +25,7 @@ import static org.openmetadata.catalog.util.TestUtils.ADMIN_AUTH_HEADERS; import static org.openmetadata.catalog.util.TestUtils.UpdateType.MINOR_UPDATE; import static org.openmetadata.catalog.util.TestUtils.assertListNotNull; import static org.openmetadata.catalog.util.TestUtils.assertListNull; +import static org.openmetadata.catalog.util.TestUtils.assertResponse; import static org.openmetadata.catalog.util.TestUtils.assertResponseContains; import java.io.IOException; @@ -108,8 +109,10 @@ public class DashboardResourceTest extends EntityResourceTest createEntity(create, ADMIN_AUTH_HEADERS)); - assertResponseContains( - exception, BAD_REQUEST, invalidServiceEntity(SUPERSET_INVALID_SERVICE_REFERENCE.getType(), Entity.DASHBOARD)); + assertResponse( + exception, + BAD_REQUEST, + invalidServiceEntity(SUPERSET_INVALID_SERVICE_REFERENCE.getType(), Entity.DASHBOARD, Entity.DASHBOARD_SERVICE)); } @Test diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/databases/DatabaseResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/databases/DatabaseResourceTest.java index 146f4cc6b26..53796f5dd52 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/databases/DatabaseResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/databases/DatabaseResourceTest.java @@ -34,6 +34,7 @@ import org.junit.jupiter.api.TestInstance; import org.openmetadata.catalog.Entity; import org.openmetadata.catalog.api.data.CreateDatabase; import org.openmetadata.catalog.entity.data.Database; +import org.openmetadata.catalog.exception.CatalogExceptionMessage; import org.openmetadata.catalog.jdbi3.DatabaseRepository.DatabaseEntityInterface; import org.openmetadata.catalog.resources.EntityResourceTest; import org.openmetadata.catalog.resources.databases.DatabaseResource.DatabaseList; @@ -63,6 +64,18 @@ public class DatabaseResourceTest extends EntityResourceTest createEntity(create, ADMIN_AUTH_HEADERS), + BAD_REQUEST, + CatalogExceptionMessage.invalidServiceEntity("invalid", Entity.DATABASE, Entity.DATABASE_SERVICE)); + } + @Test void post_validDatabases_as_admin_200_OK(TestInfo test) throws IOException { // Create team with different optional fields