diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/CatalogApplication.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/CatalogApplication.java index 9a4eb1e3b39..4c230bf64e5 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/CatalogApplication.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/CatalogApplication.java @@ -31,7 +31,6 @@ import io.federecio.dropwizard.swagger.SwaggerBundle; import io.federecio.dropwizard.swagger.SwaggerBundleConfiguration; import java.io.IOException; import java.lang.reflect.InvocationTargetException; -import java.sql.SQLException; import java.time.temporal.ChronoUnit; import java.util.Optional; import javax.ws.rs.container.ContainerRequestFilter; @@ -78,7 +77,7 @@ public class CatalogApplication extends Application { @Override public void run(CatalogApplicationConfig catalogConfig, Environment environment) throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, - InvocationTargetException, IOException, SQLException { + InvocationTargetException, IOException { final Jdbi jdbi = new JdbiFactory().build(environment, catalogConfig.getDataSourceFactory(), "database"); SqlLogger sqlLogger = @@ -191,12 +190,14 @@ public class CatalogApplication extends Application { AuthorizerConfiguration authorizerConf = catalogConfig.getAuthorizerConfiguration(); AuthenticationConfiguration authenticationConfiguration = catalogConfig.getAuthenticationConfiguration(); if (authorizerConf != null) { - authorizer = ((Class) Class.forName(authorizerConf.getClassName())).getConstructor().newInstance(); + authorizer = + Class.forName(authorizerConf.getClassName()).asSubclass(Authorizer.class).getConstructor().newInstance(); String filterClazzName = authorizerConf.getContainerRequestFilter(); ContainerRequestFilter filter; if (!StringUtils.isEmpty(filterClazzName)) { filter = - ((Class) Class.forName(filterClazzName)) + Class.forName(filterClazzName) + .asSubclass(ContainerRequestFilter.class) .getConstructor(AuthenticationConfiguration.class) .newInstance(authenticationConfiguration); LOG.info("Registering ContainerRequestFilter: {}", filter.getClass().getCanonicalName()); @@ -204,8 +205,8 @@ public class CatalogApplication extends Application { } } else { LOG.info("Authorizer config not set, setting noop authorizer"); - authorizer = NoopAuthorizer.class.getConstructor().newInstance(); - ContainerRequestFilter filter = NoopFilter.class.getConstructor().newInstance(); + authorizer = new NoopAuthorizer(); + ContainerRequestFilter filter = new NoopFilter(authenticationConfiguration); environment.jersey().register(filter); } } @@ -256,12 +257,12 @@ public class CatalogApplication extends Application { public static class ManagedShutdown implements Managed { @Override - public void start() throws Exception { + public void start() { LOG.info("Starting the application"); } @Override - public void stop() throws Exception { + public void stop() throws InterruptedException { EventPubSub.shutdown(); LOG.info("Stopping the application"); } diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/CatalogHealthCheck.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/CatalogHealthCheck.java index 0b29ee5f779..55a6c70e3d9 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/CatalogHealthCheck.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/CatalogHealthCheck.java @@ -33,7 +33,7 @@ public class CatalogHealthCheck extends HealthCheck { } @Override - protected Result check() throws Exception { + protected Result check() { try { ListFilter filter = new ListFilter(); userRepository.listAfter(null, Fields.EMPTY_FIELDS, filter, 1, null); diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/CreateEntity.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/CreateEntity.java index 0a0c00773a0..47492d211c6 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/CreateEntity.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/CreateEntity.java @@ -28,7 +28,7 @@ public interface CreateEntity { default Object getExtension() { return null; - }; + } K withName(String name); @@ -42,5 +42,5 @@ public interface CreateEntity { default K withExtension(Object extension) { return (K) this; - }; + } } diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/Entity.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/Entity.java index c1e81b3bb96..5c079592ec9 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/Entity.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/Entity.java @@ -85,8 +85,6 @@ public final class Entity { public static final String REPORT = "report"; public static final String TOPIC = "topic"; public static final String MLMODEL = "mlmodel"; - // Not deleted to ensure the ordinal value of the entities after this remains the same - public static final String UNUSED = "unused"; public static final String BOT = "bot"; public static final String THREAD = "THREAD"; public static final String LOCATION = "location"; @@ -146,22 +144,10 @@ public final class Entity { entityRepository.getClass().getSimpleName()); } - public static void validateEntity(String entityType) { - String canonicalEntity = CANONICAL_ENTITY_NAME_MAP.get(entityType.toLowerCase()); - if (canonicalEntity == null) { - throw new IllegalArgumentException(CatalogExceptionMessage.invalidEntity(entityType)); - } - } - public static EntityReference getEntityReference(EntityReference ref) throws IOException { return ref == null ? null : getEntityReferenceById(ref.getType(), ref.getId(), Include.NON_DELETED); } - public static EntityReference getEntityReferenceById(@NonNull String entityType, @NonNull UUID id) - throws IOException { - return getEntityReferenceById(entityType, id, Include.NON_DELETED); - } - public static EntityReference getEntityReferenceById(@NonNull String entityType, @NonNull UUID id, Include include) throws IOException { EntityRepository repository = ENTITY_REPOSITORY_MAP.get(entityType); @@ -173,7 +159,7 @@ public final class Entity { } public static EntityReference getEntityReferenceByName( - @NonNull String entityType, @NonNull String fqn, Include include) throws IOException { + @NonNull String entityType, @NonNull String fqn, Include include) { EntityDAO dao = DAO_MAP.get(entityType); if (dao == null) { throw EntityNotFoundException.byMessage(CatalogExceptionMessage.entityTypeNotFound(entityType)); @@ -190,14 +176,14 @@ public final class Entity { listOrEmpty(list).forEach(ref -> withHref(uriInfo, ref)); } - public static EntityReference withHref(UriInfo uriInfo, EntityReference ref) { + public static void withHref(UriInfo uriInfo, EntityReference ref) { if (ref == null) { - return null; + return; } String entityType = ref.getType(); EntityRepository entityRepository = getEntityRepository(entityType); URI href = entityRepository.getHref(uriInfo, ref.getId()); - return ref.withHref(href); + ref.withHref(href); } public static boolean shouldHaveOwner(@NonNull String entityType) { diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/airflow/AirflowRESTClient.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/airflow/AirflowRESTClient.java index 0af96f38285..63f80dd3d77 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/airflow/AirflowRESTClient.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/airflow/AirflowRESTClient.java @@ -13,7 +13,6 @@ package org.openmetadata.catalog.airflow; -import java.io.IOException; import java.net.URI; import java.net.http.HttpRequest; import java.net.http.HttpResponse; @@ -49,7 +48,7 @@ public class AirflowRESTClient extends PipelineServiceClient { @SneakyThrows @Override - public String authenticate() throws IOException { + public String authenticate() { AirflowAuthRequest authRequest = AirflowAuthRequest.builder().username(this.username).password(this.password).build(); String authPayload = JsonUtils.pojoToJson(authRequest); diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/elasticsearch/ElasticSearchRetriableException.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/elasticsearch/ElasticSearchRetriableException.java index 200d1d96535..f525505851e 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/elasticsearch/ElasticSearchRetriableException.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/elasticsearch/ElasticSearchRetriableException.java @@ -12,8 +12,4 @@ public class ElasticSearchRetriableException extends RetriableException { public ElasticSearchRetriableException(String message) { super(message); } - - public ElasticSearchRetriableException(Throwable cause) { - super(cause); - } } diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/events/AbstractEventPublisher.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/events/AbstractEventPublisher.java index 7507e0c12d9..57abdca2292 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/events/AbstractEventPublisher.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/events/AbstractEventPublisher.java @@ -23,7 +23,7 @@ public abstract class AbstractEventPublisher implements EventPublisher { private int currentBackoffTime = BACKOFF_NORMAL; private final List batch = new ArrayList<>(); private final ConcurrentHashMap> filter = new ConcurrentHashMap<>(); - private int batchSize = 10; + private final int batchSize; protected AbstractEventPublisher(int batchSize, List filters) { filters.forEach(f -> filter.put(f.getEventType(), f.getEntities())); diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/events/AuditExcludeFilterFactory.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/events/AuditExcludeFilterFactory.java index db9fb468ee1..6f6ea469b5d 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/events/AuditExcludeFilterFactory.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/events/AuditExcludeFilterFactory.java @@ -9,8 +9,8 @@ import org.slf4j.Marker; @JsonTypeName("audit-exclude-filter-factory") public class AuditExcludeFilterFactory implements FilterFactory { - private static Filter auditFilter = - new Filter() { + private static final Filter auditFilter = + new Filter<>() { @Override public FilterReply decide(final ILoggingEvent event) { Marker marker = event.getMarker(); diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/events/AuditOnlyFilterFactory.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/events/AuditOnlyFilterFactory.java index bc7a6d9cc71..7958e7f8e2d 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/events/AuditOnlyFilterFactory.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/events/AuditOnlyFilterFactory.java @@ -9,8 +9,8 @@ import org.slf4j.Marker; @JsonTypeName("audit-only-filter-factory") public class AuditOnlyFilterFactory implements FilterFactory { - private static Filter auditFilter = - new Filter() { + private static final Filter auditFilter = + new Filter<>() { @Override public FilterReply decide(final ILoggingEvent event) { Marker marker = event.getMarker(); diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/events/EventPubSub.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/events/EventPubSub.java index 1ff9b4f1e84..638f76b5dd4 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/events/EventPubSub.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/events/EventPubSub.java @@ -26,8 +26,8 @@ import java.util.concurrent.TimeUnit; import lombok.extern.slf4j.Slf4j; import org.openmetadata.catalog.type.ChangeEvent; -@Slf4j /** Change event PubSub built based on LMAX Disruptor. */ +@Slf4j public class EventPubSub { private static Disruptor disruptor; private static ExecutorService executor; diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/exception/BadRequestException.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/exception/BadRequestException.java index 1781dabcbb7..6e9b506c4aa 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/exception/BadRequestException.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/exception/BadRequestException.java @@ -17,41 +17,12 @@ import javax.ws.rs.core.Response; public final class BadRequestException extends WebServiceException { private static final String DEFAULT_MESSAGE = "Bad request."; - private static final String PARAMETER_MISSING_MESSAGE = "Bad request. Param [%s] is missing or empty."; private BadRequestException(String message) { super(Response.Status.BAD_REQUEST, message); } - private BadRequestException(String message, Throwable cause) { - super(Response.Status.BAD_REQUEST, message, cause); - } - - public static BadRequestException message(String message) { - return new BadRequestException(message); - } - - public static BadRequestException message(String message, Throwable cause) { - return new BadRequestException(message, cause); - } - public static BadRequestException of() { return new BadRequestException(DEFAULT_MESSAGE); } - - public static BadRequestException of(Throwable cause) { - return new BadRequestException(DEFAULT_MESSAGE, cause); - } - - public static BadRequestException missingParameter(String parameterName) { - return new BadRequestException(buildParameterMissingMessage(parameterName)); - } - - public static BadRequestException missingParameter(String parameterName, Throwable cause) { - return new BadRequestException(buildParameterMissingMessage(parameterName), cause); - } - - private static String buildParameterMissingMessage(String parameterName) { - return String.format(PARAMETER_MISSING_MESSAGE, parameterName); - } } 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 7b3fb3270a3..bb70735d554 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 @@ -53,12 +53,8 @@ public final class CatalogExceptionMessage { return String.format("Entity type %s not found", entityType); } - public static String fieldIsNull(String field) { - return String.format("Field %s is null", field); - } - - public static String deactivatedUser(UUID id) { - return String.format("User %s is deactivated", id); + public static String deletedUser(UUID id) { + return String.format("User %s is deleted", id); } public static String userAlreadyPartOfTeam(String userName, String teamName) { diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/exception/DuplicateEntityException.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/exception/DuplicateEntityException.java deleted file mode 100644 index 81e5de7e86e..00000000000 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/exception/DuplicateEntityException.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2021 Collate - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.openmetadata.catalog.exception; - -public class DuplicateEntityException extends RuntimeException { - public DuplicateEntityException(String message, Throwable cause) { - super(message, cause); - } -} diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/exception/WebserviceAuthorizationException.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/exception/WebserviceAuthorizationException.java deleted file mode 100644 index 54169a981c8..00000000000 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/exception/WebserviceAuthorizationException.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2021 Collate - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.openmetadata.catalog.exception; - -import javax.ws.rs.core.Response; - -public class WebserviceAuthorizationException extends WebServiceException { - public WebserviceAuthorizationException(String msg) { - super(Response.Status.FORBIDDEN, msg); - } -} diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/CollectionDAO.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/CollectionDAO.java index bfddfbade01..a9cd1823659 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/CollectionDAO.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/CollectionDAO.java @@ -306,7 +306,7 @@ public interface CollectionDAO { List getExtensions(@Bind("id") String id, @Bind("extensionPrefix") String extensionPrefix); @SqlUpdate("DELETE FROM entity_extension WHERE id = :id") - int deleteAll(@Bind("id") String id); + void deleteAll(@Bind("id") String id); } class EntityVersionPair { @@ -336,9 +336,23 @@ public interface CollectionDAO { } } + class FromEntityReferenceMapper implements RowMapper { + @Override + public EntityReference map(ResultSet rs, org.jdbi.v3.core.statement.StatementContext ctx) throws SQLException { + return new EntityReference().withId(UUID.fromString(rs.getString("fromId"))).withType(rs.getString("fromEntity")); + } + } + + class ToEntityReferenceMapper implements RowMapper { + @Override + public EntityReference map(ResultSet rs, org.jdbi.v3.core.statement.StatementContext ctx) throws SQLException { + return new EntityReference().withId(UUID.fromString(rs.getString("toId"))).withType(rs.getString("toEntity")); + } + } + interface EntityRelationshipDAO { - default int insert(UUID fromId, UUID toId, String fromEntity, String toEntity, int relation) { - return insert(fromId, toId, fromEntity, toEntity, relation, null); + default void insert(UUID fromId, UUID toId, String fromEntity, String toEntity, int relation) { + insert(fromId, toId, fromEntity, toEntity, relation, null); } default int insert(UUID fromId, UUID toId, String fromEntity, String toEntity, int relation, String json) { @@ -453,7 +467,7 @@ public interface CollectionDAO { @SqlUpdate( "DELETE from entity_relationship WHERE fromId = :fromId AND fromEntity = :fromEntity " + "AND relation = :relation AND toEntity = :toEntity") - int deleteFrom( + void deleteFrom( @Bind("fromId") String fromId, @Bind("fromEntity") String fromEntity, @Bind("relation") int relation, @@ -463,7 +477,7 @@ public interface CollectionDAO { @SqlUpdate( "DELETE from entity_relationship WHERE toId = :toId AND toEntity = :toEntity AND relation = :relation " + "AND fromEntity = :fromEntity") - int deleteTo( + void deleteTo( @Bind("toId") String toId, @Bind("toEntity") String toEntity, @Bind("relation") int relation, @@ -472,7 +486,7 @@ public interface CollectionDAO { @SqlUpdate( "DELETE from entity_relationship WHERE (toId = :id AND toEntity = :entity) OR " + "(fromId = :id AND fromEntity = :entity)") - int deleteAll(@Bind("id") String id, @Bind("entity") String entity); + void deleteAll(@Bind("id") String id, @Bind("entity") String entity); } interface FeedDAO { @@ -721,7 +735,7 @@ public interface CollectionDAO { + "VALUES (:fromFQN, :toFQN, :fromType, :toType, :relation, (:json :: jsonb)) " + "ON CONFLICT (fromFQN, toFQN, relation) DO NOTHING", connectionType = POSTGRES) - int insert( + void insert( @Bind("fromFQN") String fromFQN, @Bind("toFQN") String toFQN, @Bind("fromType") String fromType, @@ -1379,7 +1393,7 @@ public interface CollectionDAO { UsageDetails getLatestUsage(@Bind("id") String id); @SqlUpdate("DELETE FROM entity_usage WHERE id = :id") - int delete(@Bind("id") String id); + void delete(@Bind("id") String id); /** * TODO: Not sure I get what the next comment means, but tests now use mysql 8 so maybe tests can be improved here @@ -1453,9 +1467,6 @@ public interface CollectionDAO { return "name"; } - @SqlQuery("SELECT json FROM user_entity WHERE email = :email") - String findByEmail(@Bind("email") String email); - @Override default int listCount(ListFilter filter) { String team = filter.getQueryParam("team"); 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 8049ff99ca4..b82be29ae5b 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 @@ -178,22 +178,6 @@ public class DashboardRepository extends EntityRepository { return chartRefs.isEmpty() ? null : chartRefs; } - public void updateCharts(Dashboard original, Dashboard updated, EntityUpdater updater) - throws JsonProcessingException { - // Remove all charts associated with this dashboard - deleteFrom(updated.getId(), Entity.DASHBOARD, Relationship.HAS, Entity.CHART); - - // Add relationship from dashboard to chart - if (updated.getCharts() != null) { - for (EntityReference chart : updated.getCharts()) { - addRelationship(updated.getId(), chart.getId(), Entity.DASHBOARD, Entity.CHART, Relationship.HAS); - } - } - List origChartIds = EntityUtil.getIDList(original.getCharts()); - List updatedChartIds = EntityUtil.getIDList(updated.getCharts()); - updater.recordChange("charts", origChartIds, updatedChartIds); - } - /** Handles entity updated from PUT and POST operation. */ public class DashboardUpdater extends EntityUpdater { public DashboardUpdater(Dashboard original, Dashboard updated, Operation operation) { diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/DatabaseSchemaRepository.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/DatabaseSchemaRepository.java index e6ef673b86d..e78d4897d1c 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/DatabaseSchemaRepository.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/DatabaseSchemaRepository.java @@ -21,7 +21,7 @@ import java.util.List; import org.openmetadata.catalog.Entity; import org.openmetadata.catalog.entity.data.Database; import org.openmetadata.catalog.entity.data.DatabaseSchema; -import org.openmetadata.catalog.resources.databases.DatabaseResource; +import org.openmetadata.catalog.resources.databases.DatabaseSchemaResource; import org.openmetadata.catalog.type.EntityReference; import org.openmetadata.catalog.type.Include; import org.openmetadata.catalog.type.Relationship; @@ -36,7 +36,7 @@ public class DatabaseSchemaRepository extends EntityRepository { public DatabaseSchemaRepository(CollectionDAO dao) { super( - DatabaseResource.COLLECTION_PATH, + DatabaseSchemaResource.COLLECTION_PATH, Entity.DATABASE_SCHEMA, DatabaseSchema.class, dao.databaseSchemaDAO(), diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/EntityDAO.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/EntityDAO.java index 9eecb36398a..93e2962f80e 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/EntityDAO.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/EntityDAO.java @@ -130,17 +130,7 @@ public interface EntityDAO { } default T findEntityById(UUID id, Include include) throws IOException { - Class clz = getEntityClass(); - String json = findById(getTableName(), id.toString(), getCondition(include)); - T entity = null; - if (json != null) { - entity = JsonUtils.readValue(json, clz); - } - if (entity == null) { - String entityType = Entity.getEntityTypeFromClass(clz); - throw EntityNotFoundException.byMessage(CatalogExceptionMessage.entityNotFound(entityType, id)); - } - return entity; + return jsonToEntity(findById(getTableName(), id.toString(), getCondition(include)), id.toString()); } default T findEntityById(UUID id) throws IOException { @@ -153,15 +143,18 @@ public interface EntityDAO { @SneakyThrows default T findEntityByName(String fqn, Include include) { + return jsonToEntity(findByName(getTableName(), getNameColumn(), fqn, getCondition(include)), fqn); + } + + default T jsonToEntity(String json, String identity) throws IOException { Class clz = getEntityClass(); - String json = findByName(getTableName(), getNameColumn(), fqn, getCondition(include)); T entity = null; if (json != null) { entity = JsonUtils.readValue(json, clz); } if (entity == null) { String entityType = Entity.getEntityTypeFromClass(clz); - throw EntityNotFoundException.byMessage(CatalogExceptionMessage.entityNotFound(entityType, fqn)); + throw EntityNotFoundException.byMessage(CatalogExceptionMessage.entityNotFound(entityType, identity)); } return entity; } @@ -170,7 +163,7 @@ public interface EntityDAO { return findEntityById(id).getEntityReference(); } - default EntityReference findEntityReferenceByName(String fqn) throws IOException { + default EntityReference findEntityReferenceByName(String fqn) { return findEntityByName(fqn).getEntityReference(); } @@ -178,7 +171,7 @@ public interface EntityDAO { return findEntityById(id, include).getEntityReference(); } - default EntityReference findEntityReferenceByName(String fqn, Include include) throws IOException { + default EntityReference findEntityReferenceByName(String fqn, Include include) { return findEntityByName(fqn, include).getEntityReference(); } diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/EntityRepository.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/EntityRepository.java index c627cd1021b..c1153597a69 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/EntityRepository.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/EntityRepository.java @@ -480,7 +480,7 @@ public abstract class EntityRepository { // Validate follower User user = daoCollection.userDAO().findEntityById(userId); if (Boolean.TRUE.equals(user.getDeleted())) { - throw new IllegalArgumentException(CatalogExceptionMessage.deactivatedUser(userId)); + throw new IllegalArgumentException(CatalogExceptionMessage.deletedUser(userId)); } // Add relationship @@ -814,11 +814,6 @@ public abstract class EntityRepository { return addRelationship(fromId, toId, fromEntity, toEntity, relationship, false); } - public int addRelationship( - UUID fromId, UUID toId, String fromEntity, String toEntity, Relationship relationship, String json) { - return addRelationship(fromId, toId, fromEntity, toEntity, relationship, json, false); - } - public int addRelationship( UUID fromId, UUID toId, String fromEntity, String toEntity, Relationship relationship, boolean bidirectional) { return addRelationship(fromId, toId, fromEntity, toEntity, relationship, null, bidirectional); @@ -943,12 +938,12 @@ public abstract class EntityRepository { return getOwner(entity); } - public EntityReference populateOwner(EntityReference owner) throws IOException { + public void populateOwner(EntityReference owner) throws IOException { if (owner == null) { - return null; + return; } EntityReference ref = Entity.getEntityReferenceById(owner.getType(), owner.getId(), ALL); - return EntityUtil.copy(ref, owner); + EntityUtil.copy(ref, owner); } protected void storeOwner(T entity, EntityReference owner) { diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/FeedRepository.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/FeedRepository.java index d1faef5a269..a995f6b40f0 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/FeedRepository.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/FeedRepository.java @@ -30,6 +30,7 @@ import java.util.stream.Collectors; import javax.json.JsonPatch; import javax.ws.rs.core.Response.Status; import javax.ws.rs.core.UriInfo; +import lombok.Getter; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.jdbi.v3.sqlobject.transaction.Transaction; @@ -213,7 +214,7 @@ public class FeedRepository { } @Transaction - public ThreadCount getThreadsCount(String link, boolean isResolved) throws IOException { + public ThreadCount getThreadsCount(String link, boolean isResolved) { ThreadCount threadCount = new ThreadCount(); List> result; List entityLinkThreadCounts = new ArrayList<>(); @@ -512,20 +513,12 @@ public class FeedRepository { } public static class FilteredThreads { - List threads; - int totalCount; + @Getter private final List threads; + @Getter private final int totalCount; public FilteredThreads(List threads, int totalCount) { this.threads = threads; this.totalCount = totalCount; } - - public List getThreads() { - return threads; - } - - public int getTotalCount() { - return totalCount; - } } } diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/FromEntityReferenceMapper.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/FromEntityReferenceMapper.java deleted file mode 100644 index 16abb61620b..00000000000 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/FromEntityReferenceMapper.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2021 Collate - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.openmetadata.catalog.jdbi3; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.UUID; -import org.jdbi.v3.core.mapper.RowMapper; -import org.openmetadata.catalog.type.EntityReference; - -public class FromEntityReferenceMapper implements RowMapper { - @Override - public EntityReference map(ResultSet rs, org.jdbi.v3.core.statement.StatementContext ctx) throws SQLException { - return new EntityReference().withId(UUID.fromString(rs.getString("fromId"))).withType(rs.getString("fromEntity")); - } -} diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/ListFilter.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/ListFilter.java index b8c906530a9..745543f70df 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/ListFilter.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/ListFilter.java @@ -7,7 +7,7 @@ import org.openmetadata.catalog.type.Include; public class ListFilter { private final Include include; - Map queryParams = new HashMap<>(); + private final Map queryParams = new HashMap<>(); public ListFilter() { this(Include.NON_DELETED); diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/MessagingServiceRepository.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/MessagingServiceRepository.java index 928c71f9b8f..b7bb7410f78 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/MessagingServiceRepository.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/MessagingServiceRepository.java @@ -101,9 +101,7 @@ public class MessagingServiceRepository extends EntityRepository { } } - public void removeDashboard(MlModel mlModel) { - deleteTo(mlModel.getId(), Entity.MLMODEL, Relationship.USES, Entity.DASHBOARD); - } - /** Handles entity updated from PUT and POST operation. */ public class MlModelUpdater extends EntityUpdater { public MlModelUpdater(MlModel original, MlModel updated, Operation operation) { diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/TagCategoryRepository.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/TagCategoryRepository.java index 9f44b488553..45061af02b8 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/TagCategoryRepository.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/TagCategoryRepository.java @@ -87,7 +87,7 @@ public class TagCategoryRepository extends EntityRepository { } @Override - public void prepare(TagCategory entity) throws IOException { + public void prepare(TagCategory entity) { setFullyQualifiedName(entity); } diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/TagRepository.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/TagRepository.java index 8270118a005..773531898d6 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/TagRepository.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/TagRepository.java @@ -75,7 +75,7 @@ public class TagRepository extends EntityRepository { } @Override - public void prepare(Tag entity) throws IOException { + public void prepare(Tag entity) { String[] split = FullyQualifiedName.split(entity.getFullyQualifiedName()); String category = split[0]; daoCollection.tagCategoryDAO().existsByName(category); diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/ToEntityReferenceMapper.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/ToEntityReferenceMapper.java deleted file mode 100644 index 4a186cfca24..00000000000 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/ToEntityReferenceMapper.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2021 Collate - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.openmetadata.catalog.jdbi3; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.UUID; -import org.jdbi.v3.core.mapper.RowMapper; -import org.openmetadata.catalog.type.EntityReference; - -public class ToEntityReferenceMapper implements RowMapper { - @Override - public EntityReference map(ResultSet rs, org.jdbi.v3.core.statement.StatementContext ctx) throws SQLException { - return new EntityReference().withId(UUID.fromString(rs.getString("toId"))).withType(rs.getString("toEntity")); - } -} diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/TypeRepository.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/TypeRepository.java index 7796c884e7f..686ac433fd4 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/TypeRepository.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/TypeRepository.java @@ -56,7 +56,7 @@ public class TypeRepository extends EntityRepository { } @Override - public void prepare(Type type) throws IOException { + public void prepare(Type type) { setFullyQualifiedName(type); TypeRegistry.instance().validateCustomFields(type); } diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/UsageRepository.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/UsageRepository.java index 431c5caaf9f..f2a01551dc5 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/UsageRepository.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/UsageRepository.java @@ -48,7 +48,7 @@ public class UsageRepository { } @Transaction - public EntityUsage getByName(String entityType, String fqn, String date, int days) throws IOException { + public EntityUsage getByName(String entityType, String fqn, String date, int days) { EntityReference ref = Entity.getEntityReferenceByName(entityType, fqn, Include.NON_DELETED); List usageDetails = dao.usageDAO().getUsageById(ref.getId().toString(), date, days - 1); return new EntityUsage().withUsage(usageDetails).withEntity(ref); diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/UserRepository.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/UserRepository.java index 904449c3181..5703f24025d 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/UserRepository.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/UserRepository.java @@ -23,7 +23,6 @@ import java.util.Optional; import java.util.UUID; import java.util.stream.Collectors; import lombok.extern.slf4j.Slf4j; -import org.jdbi.v3.sqlobject.transaction.Transaction; import org.openmetadata.catalog.Entity; import org.openmetadata.catalog.entity.teams.AuthenticationMechanism; import org.openmetadata.catalog.entity.teams.Team; @@ -55,14 +54,14 @@ public class UserRepository extends EntityRepository { } @Override - public EntityReference getOriginalOwner(User entity) throws IOException { + public EntityReference getOriginalOwner(User entity) { // For User entity, the entity and the owner are the same return entity.getEntityReference(); } /** Ensures that the default roles are added for POST, PUT and PATCH operations. */ @Override - public void prepare(User user) throws IOException { + public void prepare(User user) { setFullyQualifiedName(user); } @@ -116,12 +115,6 @@ public class UserRepository extends EntityRepository { return new UserUpdater(original, updated, operation); } - @Transaction - public User getByEmail(String email, Fields fields) throws IOException { - User user = EntityUtil.validate(email, daoCollection.userDAO().findByEmail(email), User.class); - return setFields(user, fields); - } - @Override public User setFields(User user, Fields fields) throws IOException { user.setProfile(fields.contains("profile") ? user.getProfile() : null); diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/WebhookRepository.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/WebhookRepository.java index cce45c80f1d..889f5c72464 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/WebhookRepository.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/WebhookRepository.java @@ -36,7 +36,6 @@ import javax.ws.rs.client.Invocation.Builder; import javax.ws.rs.core.Response; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; -import org.jdbi.v3.sqlobject.transaction.Transaction; import org.openmetadata.catalog.Entity; import org.openmetadata.catalog.events.EventPubSub; import org.openmetadata.catalog.events.EventPubSub.ChangeEventHolder; @@ -63,12 +62,12 @@ public class WebhookRepository extends EntityRepository { } @Override - public Webhook setFields(Webhook entity, Fields fields) throws IOException { + public Webhook setFields(Webhook entity, Fields fields) { return entity; // No fields to set } @Override - public void prepare(Webhook entity) throws IOException { + public void prepare(Webhook entity) { setFullyQualifiedName(entity); } @@ -146,11 +145,6 @@ public class WebhookRepository extends EntityRepository { webhookPublisherMap.remove(id); } - @Transaction - public boolean delete(String id) { - return daoCollection.webhookDAO().delete(id) > 0; - } - /** * WebhookPublisher publishes events to the webhook endpoint using POST http requests. There is one instance of * WebhookPublisher per webhook subscription. Each WebhookPublish is an EventHandler that runs in a separate thread diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/feeds/FeedResource.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/feeds/FeedResource.java index d5b4019db5c..0484af71647 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/feeds/FeedResource.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/feeds/FeedResource.java @@ -76,9 +76,8 @@ public class FeedResource { private final FeedRepository dao; private final Authorizer authorizer; - public static List addHref(UriInfo uriInfo, List threads) { + public static void addHref(UriInfo uriInfo, List threads) { threads.forEach(t -> addHref(uriInfo, t)); - return threads; } public static Thread addHref(UriInfo uriInfo, Thread thread) { @@ -178,8 +177,7 @@ public class FeedResource { } else { // Forward paging or first page threads = dao.list(entityLink, limitPosts, userId, filterType, limitParam, after, resolved, PaginationType.AFTER); } - threads.getData().forEach(thread -> addHref(uriInfo, thread)); - + addHref(uriInfo, threads.getData()); return threads; } @@ -249,8 +247,7 @@ public class FeedResource { @Parameter(description = "Filter threads by whether it is active or resolved", schema = @Schema(type = "boolean")) @DefaultValue("false") @QueryParam("isResolved") - Boolean isResolved) - throws IOException { + Boolean isResolved) { return dao.getThreadsCount(entityLink, isResolved); } diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/usage/UsageResource.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/usage/UsageResource.java index 209805f0459..be42b10981d 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/usage/UsageResource.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/resources/usage/UsageResource.java @@ -136,8 +136,7 @@ public class UsageResource { description = "Usage for number of days going back from this date in ISO 8601 format " + "(default = currentDate)") @QueryParam("date") - String date) - throws IOException { + String date) { // TODO add href int actualDays = Math.min(Math.max(days, 1), 30); String actualDate = date == null ? RestUtil.DATE_FORMAT.format(new Date()) : date; diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/security/Authorizer.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/security/Authorizer.java index 62bf280b587..e9e960f75c7 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/security/Authorizer.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/security/Authorizer.java @@ -13,7 +13,6 @@ package org.openmetadata.catalog.security; -import java.io.IOException; import java.util.List; import org.jdbi.v3.core.Jdbi; import org.openmetadata.catalog.type.EntityReference; @@ -22,7 +21,7 @@ import org.openmetadata.catalog.type.MetadataOperation; public interface Authorizer { /** Initialize the authorizer */ - void init(AuthorizerConfiguration config, Jdbi jdbi) throws IOException; + void init(AuthorizerConfiguration config, Jdbi jdbi); /** * Check if the authenticated user has given permission on the target entity identified by the given resourceType and diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/security/DefaultAuthorizer.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/security/DefaultAuthorizer.java index 6a752df011c..6b4df5d8cac 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/security/DefaultAuthorizer.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/security/DefaultAuthorizer.java @@ -47,7 +47,7 @@ public class DefaultAuthorizer implements Authorizer { private String principalDomain; @Override - public void init(AuthorizerConfiguration config, Jdbi dbi) throws IOException { + public void init(AuthorizerConfiguration config, Jdbi dbi) { LOG.debug("Initializing DefaultAuthorizer with config {}", config); this.adminUsers = new HashSet<>(config.getAdminPrincipals()); this.botUsers = new HashSet<>(config.getBotPrincipals()); diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/security/JwtFilter.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/security/JwtFilter.java index 19cba670418..92816745f2d 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/security/JwtFilter.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/security/JwtFilter.java @@ -98,7 +98,7 @@ public class JwtFilter implements ContainerRequestFilter { } // Check if expired - // if the expiresAt set to null, treat it as never expiring token + // If expiresAt is set to null, treat it as never expiring token if (jwt.getExpiresAt() != null && jwt.getExpiresAt().before(Calendar.getInstance(TimeZone.getTimeZone("UTC")).getTime())) { throw new AuthenticationException("Expired token!"); diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/security/auth/CatalogSecurityContext.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/security/auth/CatalogSecurityContext.java index bb749b50ff3..f7001a56454 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/security/auth/CatalogSecurityContext.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/security/auth/CatalogSecurityContext.java @@ -17,8 +17,8 @@ import java.security.Principal; import javax.ws.rs.core.SecurityContext; import lombok.extern.slf4j.Slf4j; -@Slf4j /** Holds authenticated principal and security context which is passed to the JAX-RS request methods */ +@Slf4j public class CatalogSecurityContext implements SecurityContext { private final Principal principal; private final String scheme; diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/security/policyevaluator/CommonFields.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/security/policyevaluator/CommonFields.java index 2972cae4787..538dcaf45bb 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/security/policyevaluator/CommonFields.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/security/policyevaluator/CommonFields.java @@ -28,7 +28,6 @@ final class CommonFields { static final String ENTITY_TAGS = "entityTags"; static final String ENTITY_TYPE = "entityType"; static final String OPERATION = "operation"; - static final String USER_ROLES = "userRoles"; // By default, if no rule matches, do not grant access. static final boolean DEFAULT_ACCESS = false; diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/security/policyevaluator/PolicyEvaluator.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/security/policyevaluator/PolicyEvaluator.java index bf712655500..04b2e5a9c9c 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/security/policyevaluator/PolicyEvaluator.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/security/policyevaluator/PolicyEvaluator.java @@ -92,7 +92,7 @@ public class PolicyEvaluator { LOG.info("Finished loading Access Control policies"); } - /** Checks if the policy has rules that gives permission to perform an operation on the given entity. */ + /** Checks if the policy has rules that give permission to perform an operation on the given entity. */ public boolean hasPermission(@NonNull UUID policyId, EntityInterface entity, @NonNull MetadataOperation operation) { AttributeBasedFacts facts = new AttributeBasedFacts.AttributeBasedFactsBuilder() diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/security/policyevaluator/SetAllowedOperationAction.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/security/policyevaluator/SetAllowedOperationAction.java index d4399da2fe4..99fdcd813e2 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/security/policyevaluator/SetAllowedOperationAction.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/security/policyevaluator/SetAllowedOperationAction.java @@ -28,7 +28,7 @@ class SetAllowedOperationAction implements Action { } @Override - public void execute(Facts facts) throws Exception { + public void execute(Facts facts) { if (Boolean.FALSE.equals(rule.getAllow())) { return; } diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/security/policyevaluator/SetPermissionAction.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/security/policyevaluator/SetPermissionAction.java index 91fd1889d79..3153a85b29b 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/security/policyevaluator/SetPermissionAction.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/security/policyevaluator/SetPermissionAction.java @@ -26,7 +26,7 @@ class SetPermissionAction implements Action { } @Override - public void execute(Facts facts) throws Exception { + public void execute(Facts facts) { facts.put(CommonFields.ALLOW, this.rule.getAllow()); } } diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/slack/SlackWebhookEventPublisher.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/slack/SlackWebhookEventPublisher.java index cfe7e6d65b0..775443734e2 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/slack/SlackWebhookEventPublisher.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/slack/SlackWebhookEventPublisher.java @@ -152,7 +152,7 @@ public class SlackWebhookEventPublisher extends AbstractEventPublisher { && changeDescription.getFieldsUpdated() != null && !changeDescription.getFieldsUpdated().isEmpty()) { for (FieldChange fieldChange : changeDescription.getFieldsUpdated()) { - // when the entity is deleted we will get deleted set as true. We do not need to parse this for slack messages. + // when the entity is deleted we will get deleted set as true. We do not need to parse this for Slack messages. if (!fieldChange.getName().equals(FIELD_DELETED)) { SlackAttachment attachment = new SlackAttachment(); attachment.setTitle("Updated " + fieldChange.getName()); diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/util/EntityUtil.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/util/EntityUtil.java index e4705c922aa..11194c9cb12 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/util/EntityUtil.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/util/EntityUtil.java @@ -36,7 +36,6 @@ import lombok.extern.slf4j.Slf4j; import org.joda.time.Period; import org.joda.time.format.ISOPeriodFormat; import org.openmetadata.catalog.Entity; -import org.openmetadata.catalog.EntityInterface; import org.openmetadata.catalog.api.data.TermReference; import org.openmetadata.catalog.entity.data.GlossaryTerm; import org.openmetadata.catalog.entity.data.Table; @@ -88,9 +87,6 @@ public final class EntityUtil { // public static final BiPredicate objectMatch = Object::equals; - public static final BiPredicate entityMatch = - (ref1, ref2) -> ref1.getId().equals(ref2.getId()); - public static final BiPredicate entityReferenceMatch = (ref1, ref2) -> ref1.getId().equals(ref2.getId()) && ref1.getType().equals(ref2.getType()); @@ -195,7 +191,7 @@ public final class EntityUtil { return refs; } - public static EntityReference validateEntityLink(EntityLink entityLink) throws IOException { + public static EntityReference validateEntityLink(EntityLink entityLink) { String entityType = entityLink.getEntityType(); String fqn = entityLink.getEntityFQN(); diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/util/FullyQualifiedName.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/util/FullyQualifiedName.java index 9f42547e077..88fa56caf4a 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/util/FullyQualifiedName.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/util/FullyQualifiedName.java @@ -56,7 +56,7 @@ public class FullyQualifiedName { } private static class SplitListener extends FqnBaseListener { - List list = new ArrayList<>(); + final List list = new ArrayList<>(); public String[] split() { return list.toArray(new String[0]); diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/util/JsonUtils.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/util/JsonUtils.java index d4b473cab96..929b8b3a1df 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/util/JsonUtils.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/util/JsonUtils.java @@ -16,11 +16,9 @@ package org.openmetadata.catalog.util; import static org.openmetadata.catalog.util.RestUtil.DATE_TIME_FORMAT; import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.io.JsonStringEncoder; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; -import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.type.TypeFactory; import com.fasterxml.jackson.datatype.jsr353.JSR353Module; import com.networknt.schema.JsonSchema; @@ -45,7 +43,6 @@ import javax.json.JsonPatch; import javax.json.JsonReader; import javax.json.JsonStructure; import javax.json.JsonValue; -import javax.ws.rs.core.MediaType; import lombok.extern.slf4j.Slf4j; import org.openmetadata.catalog.entity.Type; import org.openmetadata.catalog.entity.type.Category; @@ -54,7 +51,6 @@ import org.openmetadata.catalog.entity.type.Category; public final class JsonUtils { public static final String FIELD_TYPE_ANNOTATION = "@om-field-type"; public static final String ENTITY_TYPE_ANNOTATION = "@om-entity-type"; - public static final MediaType DEFAULT_MEDIA_TYPE = MediaType.APPLICATION_JSON_TYPE; public static final String JSON_FILE_EXTENSION = ".json"; private static final ObjectMapper OBJECT_MAPPER; private static final JsonSchemaFactory schemaFactory = JsonSchemaFactory.getInstance(VersionFlag.V7); @@ -210,10 +206,6 @@ public final class JsonUtils { } } - public static String jsonToString(String json) { - return String.valueOf(JsonStringEncoder.getInstance().quoteAsString(json)); - } - public static JsonSchema getJsonSchema(String schema) { return schemaFactory.getSchema(schema); } @@ -222,10 +214,6 @@ public final class JsonUtils { return OBJECT_MAPPER.valueToTree(object); } - public static ObjectNode createObject() { - return OBJECT_MAPPER.createObjectNode(); - } - public static boolean hasAnnotation(JsonNode jsonNode, String annotation) { String comment = String.valueOf(jsonNode.get("$comment")); return comment != null && comment.contains(annotation); diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/util/OpenMetadataClientSecurityUtil.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/util/OpenMetadataClientSecurityUtil.java index a5a9dd8961b..ca69431166d 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/util/OpenMetadataClientSecurityUtil.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/util/OpenMetadataClientSecurityUtil.java @@ -21,7 +21,6 @@ import org.openmetadata.catalog.services.connections.metadata.OpenMetadataServer @Slf4j public final class OpenMetadataClientSecurityUtil { public static final String CLIENT_ID = "clientId"; - public static final String AUDIENCE = "audience"; public static final String DOMAIN = "domain"; public static final String EMAIL = "email"; public static final String SCOPES = "scopes"; diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/util/PipelineServiceClient.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/util/PipelineServiceClient.java index d84b7387e8b..002d1d2d5bd 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/util/PipelineServiceClient.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/util/PipelineServiceClient.java @@ -18,7 +18,7 @@ import org.openmetadata.catalog.exception.PipelineServiceClientException; * *
    *
  • A PipelineService is a service such as AirFlow to which a pipeline can be deployed - *
  • A Pipeline is a workflow for performing certain taks. Example - ingestion pipeline is a workflow that connects + *
  • A Pipeline is a workflow for performing certain tasks. Example - ingestion pipeline is a workflow that connects * to a database service or other services and collect metadata. *
  • Pipeline uses `Connection` to a service as dependency. A Pipeline might need to connection to database service * to collect metadata, OpenMetadata to user metadata over APIs, etc. @@ -67,7 +67,7 @@ public abstract class PipelineServiceClient { } /* Authenticate with the service */ - public abstract String authenticate() throws IOException; + public abstract String authenticate(); /* Check the status of pipeline service to ensure it is healthy */ public abstract HttpResponse getServiceStatus(); diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/EntityResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/EntityResourceTest.java index 69562e30963..7ea7a6e654d 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/EntityResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/EntityResourceTest.java @@ -38,6 +38,7 @@ import static org.openmetadata.catalog.exception.CatalogExceptionMessage.noPermi import static org.openmetadata.catalog.exception.CatalogExceptionMessage.notAdmin; import static org.openmetadata.catalog.exception.CatalogExceptionMessage.readOnlyAttribute; import static org.openmetadata.catalog.security.SecurityUtil.authHeaders; +import static org.openmetadata.catalog.security.SecurityUtil.getPrincipalName; import static org.openmetadata.catalog.util.TestUtils.ADMIN_AUTH_HEADERS; import static org.openmetadata.catalog.util.TestUtils.ENTITY_NAME_LENGTH_ERROR; import static org.openmetadata.catalog.util.TestUtils.LONG_ENTITY_NAME; @@ -123,6 +124,7 @@ import org.openmetadata.catalog.resources.tags.TagResourceTest; import org.openmetadata.catalog.resources.teams.RoleResourceTest; import org.openmetadata.catalog.resources.teams.TeamResourceTest; import org.openmetadata.catalog.resources.teams.UserResourceTest; +import org.openmetadata.catalog.security.SecurityUtil; import org.openmetadata.catalog.type.ChangeDescription; import org.openmetadata.catalog.type.ChangeEvent; import org.openmetadata.catalog.type.Column; @@ -329,12 +331,14 @@ public abstract class EntityResourceTest authHeaders) throws HttpResponseException { + validateCommonEntityFields(updatedEntity, request, authHeaders); validateCreatedEntity(updatedEntity, request, authHeaders); } protected void validateDeletedEntity( K create, T entityBeforeDeletion, T entityAfterDeletion, Map authHeaders) throws HttpResponseException { + validateCommonEntityFields(entityAfterDeletion, create, authHeaders); validateCreatedEntity(entityAfterDeletion, create, authHeaders); } @@ -1382,23 +1386,23 @@ public abstract class EntityResourceTest authHeaders, K created) throws IOException { // Validate an entity that is created has all the information set in create request - String updatedBy = TestUtils.getPrincipal(authHeaders); + String updatedBy = SecurityUtil.getPrincipalName(authHeaders); T entity = createEntity(create, authHeaders); assertEquals(updatedBy, entity.getUpdatedBy()); assertEquals(0.1, entity.getVersion()); // First version of the entity - assertEquals(JsonUtils.valueToTree(create.getExtension()), JsonUtils.valueToTree(entity.getExtension())); + validateCommonEntityFields(entity, created, authHeaders); validateCreatedEntity(entity, created, authHeaders); // GET the entity created and ensure it has all the information set in create request T getEntity = getEntity(entity.getId(), authHeaders); assertEquals(0.1, entity.getVersion()); // First version of the entity - assertEquals(JsonUtils.valueToTree(create.getExtension()), JsonUtils.valueToTree(getEntity.getExtension())); + validateCommonEntityFields(entity, created, authHeaders); validateCreatedEntity(getEntity, created, authHeaders); getEntity = getEntityByName(entity.getFullyQualifiedName(), allFields, authHeaders); assertEquals(0.1, entity.getVersion()); // First version of the entity - assertEquals(JsonUtils.valueToTree(create.getExtension()), JsonUtils.valueToTree(getEntity.getExtension())); + validateCommonEntityFields(entity, created, authHeaders); validateCreatedEntity(getEntity, created, authHeaders); // Validate that change event was created @@ -1481,6 +1485,7 @@ public abstract class EntityResourceTest authHeaders) { assertListNotNull(entity.getId(), entity.getHref(), entity.getFullyQualifiedName()); - assertEquals(expectedDescription, entity.getDescription()); - assertEquals(expectedUpdatedByUser, entity.getUpdatedBy()); - assertReference(expectedOwner, entity.getOwner()); + assertEquals(create.getName(), entity.getName()); + assertEquals(create.getDisplayName(), entity.getDisplayName()); + assertEquals(create.getDescription(), entity.getDescription()); + assertEquals(JsonUtils.valueToTree(create.getExtension()), JsonUtils.valueToTree(entity.getExtension())); + assertEquals(create.getOwner(), entity.getOwner()); + assertEquals(getPrincipalName(authHeaders), entity.getUpdatedBy()); + } + + protected final void validateCommonEntityFields(T expected, T actual, Map authHeaders) { + assertListNotNull(actual.getId(), actual.getHref(), actual.getFullyQualifiedName()); + assertEquals(expected.getName(), actual.getName()); + assertEquals(expected.getDisplayName(), actual.getDisplayName()); + assertEquals(expected.getDescription(), actual.getDescription()); + assertEquals(JsonUtils.valueToTree(expected.getExtension()), JsonUtils.valueToTree(actual.getExtension())); + assertEquals(expected.getOwner(), actual.getOwner()); + assertEquals(getPrincipalName(authHeaders), actual.getUpdatedBy()); } protected final void validateChangeDescription(T updated, UpdateType updateType, ChangeDescription expectedChange) @@ -1621,7 +1639,7 @@ public abstract class EntityResourceTest authHeaders) throws IOException { - String updatedBy = TestUtils.getPrincipal(authHeaders); + String updatedBy = SecurityUtil.getPrincipalName(authHeaders); ResultList changeEvents; ChangeEvent changeEvent = null; diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/bots/BotResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/bots/BotResourceTest.java index 5b7c4b131d8..e0ef92eef72 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/bots/BotResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/bots/BotResourceTest.java @@ -1,7 +1,6 @@ package org.openmetadata.catalog.resources.bots; import static org.openmetadata.catalog.util.TestUtils.ADMIN_AUTH_HEADERS; -import static org.openmetadata.catalog.util.TestUtils.getPrincipal; import java.io.IOException; import java.net.URISyntaxException; @@ -20,7 +19,6 @@ import org.openmetadata.catalog.resources.EntityResourceTest; import org.openmetadata.catalog.resources.bots.BotResource.BotList; import org.openmetadata.catalog.resources.teams.UserResourceTest; import org.openmetadata.catalog.type.EntityReference; -import org.openmetadata.catalog.util.TestUtils; public class BotResourceTest extends EntityResourceTest { public static User botUser; @@ -65,13 +63,11 @@ public class BotResourceTest extends EntityResourceTest { @Override public void validateCreatedEntity(Bot entity, CreateBot request, Map authHeaders) throws HttpResponseException { - validateCommonEntityFields(entity, request.getDescription(), getPrincipal(authHeaders), null); assertReference(request.getBotUser(), entity.getBotUser()); } @Override public void compareEntities(Bot expected, Bot updated, Map authHeaders) throws HttpResponseException { - validateCommonEntityFields(updated, expected.getDescription(), TestUtils.getPrincipal(authHeaders), null); assertReference(expected.getBotUser(), updated.getBotUser()); } diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/charts/ChartResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/charts/ChartResourceTest.java index 8898b459562..03bc1d25e81 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/charts/ChartResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/charts/ChartResourceTest.java @@ -38,7 +38,6 @@ import org.openmetadata.catalog.resources.charts.ChartResource.ChartList; import org.openmetadata.catalog.type.ChartType; import org.openmetadata.catalog.type.EntityReference; import org.openmetadata.catalog.util.ResultList; -import org.openmetadata.catalog.util.TestUtils; @Slf4j public class ChartResourceTest extends EntityResourceTest { @@ -117,16 +116,12 @@ public class ChartResourceTest extends EntityResourceTest { @Override public void validateCreatedEntity(Chart chart, CreateChart createRequest, Map authHeaders) { - validateCommonEntityFields( - chart, createRequest.getDescription(), TestUtils.getPrincipal(authHeaders), createRequest.getOwner()); assertNotNull(chart.getServiceType()); assertReference(createRequest.getService(), chart.getService()); } @Override public void compareEntities(Chart expected, Chart patched, Map authHeaders) { - validateCommonEntityFields( - patched, expected.getDescription(), TestUtils.getPrincipal(authHeaders), expected.getOwner()); assertReference(expected.getService(), patched.getService()); } 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 179adab8a74..5b23a7aa9b5 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 @@ -215,8 +215,6 @@ public class DashboardResourceTest extends EntityResourceTest authHeaders) throws HttpResponseException { - validateCommonEntityFields( - dashboard, createRequest.getDescription(), TestUtils.getPrincipal(authHeaders), createRequest.getOwner()); assertNotNull(dashboard.getServiceType()); assertReference(createRequest.getService(), dashboard.getService()); validateDashboardCharts(dashboard, createRequest.getCharts()); 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 e0d1672385e..2477d84c82b 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 @@ -155,9 +155,6 @@ public class DatabaseResourceTest extends EntityResourceTest authHeaders) { - validateCommonEntityFields( - database, createRequest.getDescription(), TestUtils.getPrincipal(authHeaders), createRequest.getOwner()); - // Validate service assertNotNull(database.getServiceType()); assertReference(createRequest.getService(), database.getService()); @@ -167,9 +164,6 @@ public class DatabaseResourceTest extends EntityResourceTest authHeaders) { - validateCommonEntityFields( - updated, expected.getDescription(), TestUtils.getPrincipal(authHeaders), expected.getOwner()); - // Validate service assertReference(expected.getService(), updated.getService()); assertEquals( FullyQualifiedName.add(updated.getService().getName(), updated.getName()), updated.getFullyQualifiedName()); diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/databases/DatabaseSchemaResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/databases/DatabaseSchemaResourceTest.java index ae6b2c63f72..7f5a80a8724 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/databases/DatabaseSchemaResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/databases/DatabaseSchemaResourceTest.java @@ -117,9 +117,6 @@ public class DatabaseSchemaResourceTest extends EntityResourceTest authHeaders) { - validateCommonEntityFields( - schema, createRequest.getDescription(), TestUtils.getPrincipal(authHeaders), createRequest.getOwner()); - // Validate service assertNotNull(schema.getServiceType()); assertReference(createRequest.getDatabase(), schema.getDatabase()); @@ -130,8 +127,6 @@ public class DatabaseSchemaResourceTest extends EntityResourceTest authHeaders) { - validateCommonEntityFields( - updated, expected.getDescription(), TestUtils.getPrincipal(authHeaders), expected.getOwner()); // Validate service assertReference(expected.getDatabase(), updated.getDatabase()); assertEquals( diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/databases/TableResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/databases/TableResourceTest.java index 6d5f48f9d6f..6d8ee65e259 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/databases/TableResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/databases/TableResourceTest.java @@ -2047,9 +2047,6 @@ public class TableResourceTest extends EntityResourceTest { @Override public void validateCreatedEntity(Table createdEntity, CreateTable createRequest, Map authHeaders) throws HttpResponseException { - validateCommonEntityFields( - createdEntity, createRequest.getDescription(), TestUtils.getPrincipal(authHeaders), createRequest.getOwner()); - // Entity specific validation assertEquals(createRequest.getTableType(), createdEntity.getTableType()); assertColumns(createRequest.getColumns(), createdEntity.getColumns()); @@ -2085,9 +2082,6 @@ public class TableResourceTest extends EntityResourceTest { @Override public void compareEntities(Table expected, Table patched, Map authHeaders) throws HttpResponseException { - validateCommonEntityFields( - patched, expected.getDescription(), TestUtils.getPrincipal(authHeaders), expected.getOwner()); - // Entity specific validation assertEquals(expected.getTableType(), patched.getTableType()); assertColumns(expected.getColumns(), patched.getColumns()); diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/events/WebhookResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/events/WebhookResourceTest.java index 5e7aac16c02..325295a739f 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/events/WebhookResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/events/WebhookResourceTest.java @@ -46,7 +46,6 @@ import org.openmetadata.catalog.type.Webhook; import org.openmetadata.catalog.type.Webhook.Status; import org.openmetadata.catalog.util.EntityUtil; import org.openmetadata.catalog.util.JsonUtils; -import org.openmetadata.catalog.util.TestUtils; import org.openmetadata.catalog.util.TestUtils.UpdateType; @Slf4j @@ -232,7 +231,6 @@ public class WebhookResourceTest extends EntityResourceTest authHeaders) throws HttpResponseException { - validateCommonEntityFields(webhook, createRequest.getDescription(), TestUtils.getPrincipal(authHeaders), null); assertEquals(createRequest.getName(), webhook.getName()); ArrayList filters = new ArrayList<>(createRequest.getEventFilters()); EntityUtil.addSoftDeleteFilter(filters); diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/feeds/FeedResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/feeds/FeedResourceTest.java index 0cea80ddd92..4056da7a7eb 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/feeds/FeedResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/feeds/FeedResourceTest.java @@ -27,6 +27,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.openmetadata.catalog.exception.CatalogExceptionMessage.entityNotFound; import static org.openmetadata.catalog.exception.CatalogExceptionMessage.noPermission; import static org.openmetadata.catalog.security.SecurityUtil.authHeaders; +import static org.openmetadata.catalog.security.SecurityUtil.getPrincipalName; import static org.openmetadata.catalog.util.TestUtils.ADMIN_AUTH_HEADERS; import static org.openmetadata.catalog.util.TestUtils.ADMIN_USER_NAME; import static org.openmetadata.catalog.util.TestUtils.NON_EXISTENT_ENTITY; @@ -121,7 +122,8 @@ public class FeedResourceTest extends CatalogApplicationTest { .withDescription("Team2 description") .withUsers(List.of(USER2.getId())); TEAM2 = teamResourceTest.createAndCheckEntity(createTeam, ADMIN_AUTH_HEADERS); - EntityReference TEAM2_REF = new EntityReference().withId(TEAM2.getId()).withType(Entity.TEAM); + EntityReference TEAM2_REF = TEAM2.getEntityReference(); + CreateTable createTable2 = tableResourceTest.createRequest(test); createTable2.withName("table2").withOwner(TEAM2_REF); TABLE2 = tableResourceTest.createAndCheckEntity(createTable2, ADMIN_AUTH_HEADERS); @@ -780,6 +782,6 @@ public class FeedResourceTest extends CatalogApplicationTest { assertListNotNull(patched.getId(), patched.getHref(), patched.getAbout()); assertEquals(expected.getMessage(), patched.getMessage()); assertEquals(expected.getResolved(), patched.getResolved()); - assertEquals(TestUtils.getPrincipal(authHeaders), patched.getUpdatedBy()); + assertEquals(getPrincipalName(authHeaders), patched.getUpdatedBy()); } } diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/glossary/GlossaryResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/glossary/GlossaryResourceTest.java index e996c73607d..0fc921c9efb 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/glossary/GlossaryResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/glossary/GlossaryResourceTest.java @@ -133,19 +133,12 @@ public class GlossaryResourceTest extends EntityResourceTest authHeaders) throws HttpResponseException { - validateCommonEntityFields( - createdEntity, createRequest.getDescription(), TestUtils.getPrincipal(authHeaders), createRequest.getOwner()); - - // Entity specific validation TestUtils.validateTags(createRequest.getTags(), createdEntity.getTags()); } @Override public void compareEntities(Glossary expected, Glossary patched, Map authHeaders) throws HttpResponseException { - validateCommonEntityFields( - patched, expected.getDescription(), TestUtils.getPrincipal(authHeaders), expected.getOwner()); - // Entity specific validation TestUtils.validateTags(expected.getTags(), patched.getTags()); TestUtils.assertEntityReferenceList(expected.getReviewers(), patched.getReviewers()); diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/glossary/GlossaryTermResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/glossary/GlossaryTermResourceTest.java index f907b87c7e8..f37b307053d 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/glossary/GlossaryTermResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/glossary/GlossaryTermResourceTest.java @@ -312,7 +312,6 @@ public class GlossaryTermResourceTest extends EntityResourceTest authHeaders) throws HttpResponseException { - validateCommonEntityFields(entity, request.getDescription(), TestUtils.getPrincipal(authHeaders), null); assertReference(request.getParent(), entity.getParent()); assertReference(request.getGlossary(), entity.getGlossary()); @@ -343,8 +342,6 @@ public class GlossaryTermResourceTest extends EntityResourceTest authHeaders) throws HttpResponseException { - validateCommonEntityFields(patched, expected.getDescription(), TestUtils.getPrincipal(authHeaders), null); - assertReference(expected.getGlossary(), patched.getGlossary()); assertReference(expected.getParent(), patched.getParent()); assertEquals(expected.getFullyQualifiedName(), patched.getFullyQualifiedName()); diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/locations/LocationResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/locations/LocationResourceTest.java index 50c846f3518..52d8d3ebfe8 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/locations/LocationResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/locations/LocationResourceTest.java @@ -75,8 +75,6 @@ public class LocationResourceTest extends EntityResourceTest authHeaders) throws HttpResponseException { - validateCommonEntityFields( - location, createRequest.getDescription(), TestUtils.getPrincipal(authHeaders), createRequest.getOwner()); assertEquals(createRequest.getPath(), location.getPath()); // Validate service EntityReference expectedService = createRequest.getService(); @@ -91,9 +89,6 @@ public class LocationResourceTest extends EntityResourceTest authHeaders) throws HttpResponseException { - validateCommonEntityFields( - patched, expected.getDescription(), TestUtils.getPrincipal(authHeaders), expected.getOwner()); - // Entity specific validation assertEquals(expected.getDisplayName(), patched.getDisplayName()); assertEquals(expected.getFullyQualifiedName(), patched.getFullyQualifiedName()); assertEquals(expected.getLocationType(), patched.getLocationType()); diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/metadata/TypeResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/metadata/TypeResourceTest.java index 52dee73eb6e..63fdee1b479 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/metadata/TypeResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/metadata/TypeResourceTest.java @@ -137,10 +137,6 @@ public class TypeResourceTest extends EntityResourceTest { @Override public void validateCreatedEntity(Type createdEntity, CreateType createRequest, Map authHeaders) throws HttpResponseException { - validateCommonEntityFields( - createdEntity, createRequest.getDescription(), TestUtils.getPrincipal(authHeaders), null); - - // Entity specific validation assertEquals(createRequest.getSchema(), createdEntity.getSchema()); // TODO } @@ -148,9 +144,6 @@ public class TypeResourceTest extends EntityResourceTest { @Override public void compareEntities(Type expected, Type patched, Map authHeaders) throws HttpResponseException { - validateCommonEntityFields(patched, expected.getDescription(), TestUtils.getPrincipal(authHeaders), null); - - // Entity specific validation assertEquals(expected.getSchema(), patched.getSchema()); // TODO more checks } diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/mlmodels/MlModelResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/mlmodels/MlModelResourceTest.java index 271256f4db6..bf4b26bbb09 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/mlmodels/MlModelResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/mlmodels/MlModelResourceTest.java @@ -379,9 +379,6 @@ public class MlModelResourceTest extends EntityResourceTest authHeaders) throws HttpResponseException { - validateCommonEntityFields( - updated, expected.getDescription(), TestUtils.getPrincipal(authHeaders), expected.getOwner()); - // Entity specific validations assertEquals(expected.getAlgorithm(), updated.getAlgorithm()); assertEquals(expected.getDashboard(), updated.getDashboard()); @@ -435,10 +432,6 @@ public class MlModelResourceTest extends EntityResourceTest authHeaders) throws HttpResponseException { - validateCommonEntityFields( - createdEntity, createRequest.getDescription(), TestUtils.getPrincipal(authHeaders), createRequest.getOwner()); - - // Entity specific validations assertEquals(createRequest.getAlgorithm(), createdEntity.getAlgorithm()); assertEquals(createRequest.getDashboard(), createdEntity.getDashboard()); assertListProperty(createRequest.getMlFeatures(), createdEntity.getMlFeatures(), assertMlFeature); diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/pipelines/PipelineResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/pipelines/PipelineResourceTest.java index 348229950e8..7b4af21ae7b 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/pipelines/PipelineResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/pipelines/PipelineResourceTest.java @@ -105,8 +105,6 @@ public class PipelineResourceTest extends EntityResourceTest authHeaders) throws HttpResponseException { - validateCommonEntityFields( - pipeline, createRequest.getDescription(), TestUtils.getPrincipal(authHeaders), createRequest.getOwner()); assertNotNull(pipeline.getServiceType()); assertReference(createRequest.getService(), pipeline.getService()); validateTasks(createRequest.getTasks(), pipeline.getTasks()); @@ -132,8 +130,6 @@ public class PipelineResourceTest extends EntityResourceTest authHeaders) throws HttpResponseException { - validateCommonEntityFields( - updated, expected.getDescription(), TestUtils.getPrincipal(authHeaders), expected.getOwner()); assertEquals(expected.getDisplayName(), updated.getDisplayName()); assertReference(expected.getService(), updated.getService()); validateTasks(expected.getTasks(), updated.getTasks()); diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/policies/PolicyResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/policies/PolicyResourceTest.java index 1141e0a1f9e..f25169d535b 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/policies/PolicyResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/policies/PolicyResourceTest.java @@ -78,8 +78,6 @@ public class PolicyResourceTest extends EntityResourceTest @Override public void validateCreatedEntity(Policy policy, CreatePolicy createRequest, Map authHeaders) { - validateCommonEntityFields( - policy, createRequest.getDescription(), TestUtils.getPrincipal(authHeaders), createRequest.getOwner()); assertEquals(createRequest.getPolicyUrl(), policy.getPolicyUrl()); } diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/DashboardServiceResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/DashboardServiceResourceTest.java index b0a1f2f58ce..e54931471fa 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/DashboardServiceResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/DashboardServiceResourceTest.java @@ -18,7 +18,6 @@ import static javax.ws.rs.core.Response.Status.OK; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.openmetadata.catalog.util.TestUtils.ADMIN_AUTH_HEADERS; import static org.openmetadata.catalog.util.TestUtils.assertResponse; -import static org.openmetadata.catalog.util.TestUtils.getPrincipal; import java.io.IOException; import java.net.URI; @@ -148,8 +147,6 @@ public class DashboardServiceResourceTest extends EntityResourceTest authHeaders) { - validateCommonEntityFields( - service, createRequest.getDescription(), getPrincipal(authHeaders), createRequest.getOwner()); assertEquals(createRequest.getName(), service.getName()); DashboardConnection expectedConnection = createRequest.getConnection(); DashboardConnection actualConnection = service.getConnection(); diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/DatabaseServiceResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/DatabaseServiceResourceTest.java index b4180375300..f9a8c2dea62 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/DatabaseServiceResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/DatabaseServiceResourceTest.java @@ -18,7 +18,6 @@ import static javax.ws.rs.core.Response.Status.OK; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.openmetadata.catalog.util.TestUtils.ADMIN_AUTH_HEADERS; import static org.openmetadata.catalog.util.TestUtils.assertResponseContains; -import static org.openmetadata.catalog.util.TestUtils.getPrincipal; import java.io.IOException; import java.util.List; @@ -262,10 +261,7 @@ public class DatabaseServiceResourceTest extends EntityResourceTest authHeaders) { - validateCommonEntityFields( - service, createRequest.getDescription(), getPrincipal(authHeaders), createRequest.getOwner()); assertEquals(createRequest.getName(), service.getName()); - validateDatabaseConnection(createRequest.getConnection(), service.getConnection(), service.getServiceType()); } diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/MessagingServiceResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/MessagingServiceResourceTest.java index 23afa416788..9f1d7760851 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/MessagingServiceResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/MessagingServiceResourceTest.java @@ -198,8 +198,6 @@ public class MessagingServiceResourceTest extends EntityResourceTest authHeaders) { - validateCommonEntityFields( - service, createRequest.getDescription(), TestUtils.getPrincipal(authHeaders), createRequest.getOwner()); MessagingConnection expectedMessagingConnection = createRequest.getConnection(); MessagingConnection actualMessagingConnection = service.getConnection(); validateConnection(expectedMessagingConnection, actualMessagingConnection, service.getServiceType()); diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/PipelineServiceResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/PipelineServiceResourceTest.java index d29c8644c60..83571a0019c 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/PipelineServiceResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/PipelineServiceResourceTest.java @@ -19,7 +19,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.openmetadata.catalog.util.TestUtils.ADMIN_AUTH_HEADERS; import static org.openmetadata.catalog.util.TestUtils.assertResponse; import static org.openmetadata.catalog.util.TestUtils.assertResponseContains; -import static org.openmetadata.catalog.util.TestUtils.getPrincipal; import java.io.IOException; import java.net.URI; @@ -224,8 +223,6 @@ public class PipelineServiceResourceTest extends EntityResourceTest authHeaders) { - validateCommonEntityFields( - service, createRequest.getDescription(), getPrincipal(authHeaders), createRequest.getOwner()); assertEquals(createRequest.getName(), service.getName()); Schedule expectedIngestion = createRequest.getIngestionSchedule(); diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/StorageServiceResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/StorageServiceResourceTest.java index 05a00908520..c94cc38fc1a 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/StorageServiceResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/StorageServiceResourceTest.java @@ -15,7 +15,6 @@ package org.openmetadata.catalog.resources.services; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.openmetadata.catalog.util.TestUtils.ADMIN_AUTH_HEADERS; -import static org.openmetadata.catalog.util.TestUtils.getPrincipal; import java.io.IOException; import java.util.Map; @@ -76,8 +75,6 @@ public class StorageServiceResourceTest extends EntityResourceTest authHeaders) { - validateCommonEntityFields( - service, createRequest.getDescription(), getPrincipal(authHeaders), createRequest.getOwner()); assertEquals(createRequest.getName(), service.getName()); } diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/ingestionpipelines/IngestionPipelineResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/ingestionpipelines/IngestionPipelineResourceTest.java index 93f5637ec5c..f20bfed58b1 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/ingestionpipelines/IngestionPipelineResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/services/ingestionpipelines/IngestionPipelineResourceTest.java @@ -138,8 +138,6 @@ public class IngestionPipelineResourceTest extends EntityResourceTest authHeaders) throws HttpResponseException { - validateCommonEntityFields( - ingestion, createRequest.getDescription(), TestUtils.getPrincipal(authHeaders), createRequest.getOwner()); assertEquals(createRequest.getAirflowConfig().getConcurrency(), ingestion.getAirflowConfig().getConcurrency()); validateSourceConfig(createRequest.getSourceConfig(), ingestion.getSource().getSourceConfig(), ingestion); } @@ -147,8 +145,6 @@ public class IngestionPipelineResourceTest extends EntityResourceTest authHeaders) throws HttpResponseException { - validateCommonEntityFields( - updated, expected.getDescription(), TestUtils.getPrincipal(authHeaders), expected.getOwner()); assertEquals(expected.getDisplayName(), updated.getDisplayName()); assertReference(expected.getService(), updated.getService()); assertEquals(expected.getSource().getSourceConfig(), updated.getSource().getSourceConfig()); diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/tags/TagResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/tags/TagResourceTest.java index 3b14fb76d06..d5c11edd4ea 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/tags/TagResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/tags/TagResourceTest.java @@ -20,6 +20,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.openmetadata.catalog.exception.CatalogExceptionMessage.entityNotFound; import static org.openmetadata.catalog.security.SecurityUtil.authHeaders; +import static org.openmetadata.catalog.security.SecurityUtil.getPrincipalName; import static org.openmetadata.catalog.util.TestUtils.ADMIN_AUTH_HEADERS; import static org.openmetadata.catalog.util.TestUtils.TEST_AUTH_HEADERS; import static org.openmetadata.catalog.util.TestUtils.assertResponse; @@ -438,7 +439,7 @@ public class TagResourceTest extends CatalogApplicationTest { private TagCategory createAndCheckCategory(CreateTagCategory create, Map authHeaders) throws HttpResponseException { - String updatedBy = TestUtils.getPrincipal(authHeaders); + String updatedBy = getPrincipalName(authHeaders); WebTarget target = getResource("tags"); TagCategory tagCategory = TestUtils.post(target, create, TagCategory.class, authHeaders); TagCategory category = @@ -452,7 +453,7 @@ public class TagResourceTest extends CatalogApplicationTest { private Tag createPrimaryTag(String category, CreateTag create, Map authHeaders) throws HttpResponseException { - String updatedBy = TestUtils.getPrincipal(authHeaders); + String updatedBy = getPrincipalName(authHeaders); WebTarget target = getResource("tags/" + category); // Ensure POST returns the primary tag as expected @@ -472,7 +473,7 @@ public class TagResourceTest extends CatalogApplicationTest { private Tag createSecondaryTag(String category, String primaryTag, CreateTag create, Map authHeaders) throws HttpResponseException { - String updatedBy = TestUtils.getPrincipal(authHeaders); + String updatedBy = getPrincipalName(authHeaders); WebTarget target = getResource("tags/" + category + "/" + primaryTag); // Ensure POST returns the secondary tag as expected @@ -492,7 +493,7 @@ public class TagResourceTest extends CatalogApplicationTest { @SneakyThrows private void updateCategory(String category, CreateTagCategory update, Map authHeaders) { - String updatedBy = TestUtils.getPrincipal(authHeaders); + String updatedBy = getPrincipalName(authHeaders); WebTarget target = getResource("tags/" + category); // Ensure PUT returns the updated tag category @@ -506,7 +507,7 @@ public class TagResourceTest extends CatalogApplicationTest { private void updatePrimaryTag(String category, String primaryTag, CreateTag update, Map authHeaders) throws HttpResponseException { - String updatedBy = TestUtils.getPrincipal(authHeaders); + String updatedBy = getPrincipalName(authHeaders); String parentHref = getResource("tags/" + category).getUri().toString(); WebTarget target = getResource("tags/" + category + "/" + primaryTag); @@ -526,7 +527,7 @@ public class TagResourceTest extends CatalogApplicationTest { private void updateSecondaryTag( String category, String primaryTag, String secondaryTag, CreateTag update, Map authHeaders) throws HttpResponseException { - String updatedBy = TestUtils.getPrincipal(authHeaders); + String updatedBy = getPrincipalName(authHeaders); String parentHref = getResource("tags/" + category + "/" + primaryTag).getUri().toString(); WebTarget target = getResource("tags/" + category + "/" + primaryTag + "/" + secondaryTag); diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/teams/RoleResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/teams/RoleResourceTest.java index cca97bd2d86..1232ade161a 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/teams/RoleResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/teams/RoleResourceTest.java @@ -18,6 +18,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.fail; import static org.openmetadata.catalog.exception.CatalogExceptionMessage.noPermission; +import static org.openmetadata.catalog.security.SecurityUtil.getPrincipalName; import static org.openmetadata.catalog.util.TestUtils.ADMIN_AUTH_HEADERS; import static org.openmetadata.catalog.util.TestUtils.TEST_AUTH_HEADERS; import static org.openmetadata.catalog.util.TestUtils.TEST_USER_NAME; @@ -201,7 +202,7 @@ public class RoleResourceTest extends EntityResourceTest { ADMIN_AUTH_HEADERS); } - String updatedBy = TestUtils.getPrincipal(ADMIN_AUTH_HEADERS); + String updatedBy = getPrincipalName(ADMIN_AUTH_HEADERS); role = byName ? getEntityByName(role.getName(), null, null, ADMIN_AUTH_HEADERS) @@ -229,14 +230,11 @@ public class RoleResourceTest extends EntityResourceTest { @Override public void validateCreatedEntity(Role role, CreateRole createRequest, Map authHeaders) { - validateCommonEntityFields(role, createRequest.getDescription(), TestUtils.getPrincipal(authHeaders), null); assertEntityReferenceList(role.getPolicies(), createRequest.getPolicies()); } @Override public void compareEntities(Role expected, Role updated, Map authHeaders) { - validateCommonEntityFields(updated, expected.getDescription(), TestUtils.getPrincipal(authHeaders), null); - assertEquals(expected.getDisplayName(), updated.getDisplayName()); } diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/teams/TeamResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/teams/TeamResourceTest.java index 63e58909831..3eee5762d8d 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/teams/TeamResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/teams/TeamResourceTest.java @@ -18,6 +18,7 @@ import static javax.ws.rs.core.Response.Status.FORBIDDEN; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.openmetadata.catalog.security.SecurityUtil.getPrincipalName; import static org.openmetadata.catalog.util.TestUtils.ADMIN_AUTH_HEADERS; import static org.openmetadata.catalog.util.TestUtils.TEST_AUTH_HEADERS; import static org.openmetadata.catalog.util.TestUtils.TEST_USER_NAME; @@ -346,7 +347,7 @@ public class TeamResourceTest extends EntityResourceTest { userResourceTest.createEntity(create, ADMIN_AUTH_HEADERS); } - String updatedBy = TestUtils.getPrincipal(ADMIN_AUTH_HEADERS); + String updatedBy = getPrincipalName(ADMIN_AUTH_HEADERS); String fields = ""; Team getTeam = byName @@ -383,9 +384,6 @@ public class TeamResourceTest extends EntityResourceTest { @Override public void validateCreatedEntity(Team team, CreateTeam createRequest, Map authHeaders) { - validateCommonEntityFields( - team, createRequest.getDescription(), TestUtils.getPrincipal(authHeaders), createRequest.getOwner()); - assertEquals(createRequest.getProfile(), team.getProfile()); TestUtils.validateEntityReferences(team.getOwns()); @@ -404,11 +402,6 @@ public class TeamResourceTest extends EntityResourceTest { TestUtils.assertEntityReferenceList(expectedDefaultRoles, team.getDefaultRoles()); } - @Override - public void validateUpdatedEntity(Team updatedEntity, CreateTeam request, Map authHeaders) { - validateCreatedEntity(updatedEntity, request, authHeaders); - } - @Override protected void validateDeletedEntity( CreateTeam create, Team teamBeforeDeletion, Team teamAfterDeletion, Map authHeaders) @@ -424,9 +417,6 @@ public class TeamResourceTest extends EntityResourceTest { @Override public void compareEntities(Team expected, Team updated, Map authHeaders) { - validateCommonEntityFields( - updated, expected.getDescription(), TestUtils.getPrincipal(authHeaders), expected.getOwner()); - assertEquals(expected.getDisplayName(), updated.getDisplayName()); assertEquals(expected.getProfile(), updated.getProfile()); TestUtils.validateEntityReferences(updated.getOwns()); diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/teams/UserResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/teams/UserResourceTest.java index 7a1d9f2b4fa..97a7cb34dd2 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/teams/UserResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/teams/UserResourceTest.java @@ -793,8 +793,6 @@ public class UserResourceTest extends EntityResourceTest { @Override public void validateCreatedEntity(User user, CreateUser createRequest, Map authHeaders) throws HttpResponseException { - validateCommonEntityFields(user, createRequest.getDescription(), TestUtils.getPrincipal(authHeaders), null); - assertEquals(createRequest.getName(), user.getName()); assertEquals(createRequest.getDisplayName(), user.getDisplayName()); assertEquals(createRequest.getTimezone(), user.getTimezone()); @@ -820,8 +818,6 @@ public class UserResourceTest extends EntityResourceTest { @Override public void compareEntities(User expected, User updated, Map authHeaders) { - validateCommonEntityFields(expected, expected.getDescription(), TestUtils.getPrincipal(authHeaders), null); - assertEquals(expected.getName(), expected.getName()); assertEquals(expected.getDisplayName(), expected.getDisplayName()); assertEquals(expected.getTimezone(), expected.getTimezone()); diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/topics/TopicResourceTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/topics/TopicResourceTest.java index 4617146c5c1..f55739dfccf 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/topics/TopicResourceTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/resources/topics/TopicResourceTest.java @@ -280,8 +280,6 @@ public class TopicResourceTest extends EntityResourceTest { @Override public void validateCreatedEntity(Topic topic, CreateTopic createRequest, Map authHeaders) throws HttpResponseException { - validateCommonEntityFields( - topic, createRequest.getDescription(), TestUtils.getPrincipal(authHeaders), createRequest.getOwner()); assertReference(createRequest.getService(), topic.getService()); // TODO add other fields TestUtils.validateTags(createRequest.getTags(), topic.getTags()); @@ -290,8 +288,6 @@ public class TopicResourceTest extends EntityResourceTest { @Override public void compareEntities(Topic expected, Topic updated, Map authHeaders) throws HttpResponseException { - validateCommonEntityFields( - updated, expected.getDescription(), TestUtils.getPrincipal(authHeaders), expected.getOwner()); assertReference(expected.getService(), expected.getService()); // TODO add other fields TestUtils.validateTags(expected.getTags(), updated.getTags()); diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/util/JsonUtilsTest.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/util/JsonUtilsTest.java index 1af5c877b24..8d6437e274e 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/util/JsonUtilsTest.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/util/JsonUtilsTest.java @@ -46,7 +46,7 @@ class JsonUtilsTest { users.add(user2); teamJson.add("id", teamId).add("name", "finance").add("users", users); - Team original = EntityUtil.validate(teamId, teamJson.build().toString(), Team.class); + Team original = JsonUtils.readValue(teamJson.build().toString(), Team.class); JsonPatchBuilder patchBuilder = Json.createPatchBuilder(); // Add two users to the team diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/util/TestUtils.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/util/TestUtils.java index 4e6537cfe0a..cbe6e6ea384 100644 --- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/util/TestUtils.java +++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/util/TestUtils.java @@ -49,7 +49,6 @@ import org.openmetadata.catalog.entity.teams.User; import org.openmetadata.catalog.resources.glossary.GlossaryTermResourceTest; import org.openmetadata.catalog.resources.tags.TagResourceTest; import org.openmetadata.catalog.resources.teams.UserResourceTest; -import org.openmetadata.catalog.security.CatalogOpenIdAuthorizationRequestFilter; import org.openmetadata.catalog.security.SecurityUtil; import org.openmetadata.catalog.services.connections.dashboard.SupersetConnection; import org.openmetadata.catalog.services.connections.database.BigQueryConnection; @@ -345,15 +344,6 @@ public final class TestUtils { existsInEntityReferenceList(user.getFollows(), entityId, expectedFollowing); } - public static String getPrincipal(Map authHeaders) { - // Get username from the email address - if (authHeaders == null) { - return null; - } - String principal = authHeaders.get(CatalogOpenIdAuthorizationRequestFilter.X_AUTH_PARAMS_EMAIL_HEADER); - return principal == null ? null : principal.split("@")[0]; - } - // TODO remove this public static void validateUpdate(Double previousVersion, Double newVersion, UpdateType updateType) { if (updateType == UpdateType.CREATED) {