Clean up code warnings - remove unused method, exceptions declared not thrown, and others (#5088)

This commit is contained in:
Suresh Srinivas 2022-05-22 15:28:55 -07:00 committed by GitHub
parent bec87bb1b1
commit eab5bf9a0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
76 changed files with 139 additions and 443 deletions

View File

@ -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<CatalogApplicationConfig> {
@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<CatalogApplicationConfig> {
AuthorizerConfiguration authorizerConf = catalogConfig.getAuthorizerConfiguration();
AuthenticationConfiguration authenticationConfiguration = catalogConfig.getAuthenticationConfiguration();
if (authorizerConf != null) {
authorizer = ((Class<Authorizer>) 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<ContainerRequestFilter>) 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<CatalogApplicationConfig> {
}
} 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<CatalogApplicationConfig> {
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");
}

View File

@ -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);

View File

@ -28,7 +28,7 @@ public interface CreateEntity {
default Object getExtension() {
return null;
};
}
<K extends CreateEntity> K withName(String name);
@ -42,5 +42,5 @@ public interface CreateEntity {
default <K extends CreateEntity> K withExtension(Object extension) {
return (K) this;
};
}
}

View File

@ -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) {

View File

@ -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);

View File

@ -12,8 +12,4 @@ public class ElasticSearchRetriableException extends RetriableException {
public ElasticSearchRetriableException(String message) {
super(message);
}
public ElasticSearchRetriableException(Throwable cause) {
super(cause);
}
}

View File

@ -23,7 +23,7 @@ public abstract class AbstractEventPublisher implements EventPublisher {
private int currentBackoffTime = BACKOFF_NORMAL;
private final List<ChangeEvent> batch = new ArrayList<>();
private final ConcurrentHashMap<EventType, List<String>> filter = new ConcurrentHashMap<>();
private int batchSize = 10;
private final int batchSize;
protected AbstractEventPublisher(int batchSize, List<EventFilter> filters) {
filters.forEach(f -> filter.put(f.getEventType(), f.getEntities()));

View File

@ -9,8 +9,8 @@ import org.slf4j.Marker;
@JsonTypeName("audit-exclude-filter-factory")
public class AuditExcludeFilterFactory implements FilterFactory<ILoggingEvent> {
private static Filter<ILoggingEvent> auditFilter =
new Filter<ILoggingEvent>() {
private static final Filter<ILoggingEvent> auditFilter =
new Filter<>() {
@Override
public FilterReply decide(final ILoggingEvent event) {
Marker marker = event.getMarker();

View File

@ -9,8 +9,8 @@ import org.slf4j.Marker;
@JsonTypeName("audit-only-filter-factory")
public class AuditOnlyFilterFactory implements FilterFactory<ILoggingEvent> {
private static Filter<ILoggingEvent> auditFilter =
new Filter<ILoggingEvent>() {
private static final Filter<ILoggingEvent> auditFilter =
new Filter<>() {
@Override
public FilterReply decide(final ILoggingEvent event) {
Marker marker = event.getMarker();

View File

@ -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<ChangeEventHolder> disruptor;
private static ExecutorService executor;

View File

@ -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);
}
}

View File

@ -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) {

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -306,7 +306,7 @@ public interface CollectionDAO {
List<ExtensionRecord> 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<EntityReference> {
@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<EntityReference> {
@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");

View File

@ -178,22 +178,6 @@ public class DashboardRepository extends EntityRepository<Dashboard> {
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<UUID> origChartIds = EntityUtil.getIDList(original.getCharts());
List<UUID> 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) {

View File

@ -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<DatabaseSchema> {
public DatabaseSchemaRepository(CollectionDAO dao) {
super(
DatabaseResource.COLLECTION_PATH,
DatabaseSchemaResource.COLLECTION_PATH,
Entity.DATABASE_SCHEMA,
DatabaseSchema.class,
dao.databaseSchemaDAO(),

View File

@ -130,17 +130,7 @@ public interface EntityDAO<T extends EntityInterface> {
}
default T findEntityById(UUID id, Include include) throws IOException {
Class<T> 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<T extends EntityInterface> {
@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<T> 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<T extends EntityInterface> {
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<T extends EntityInterface> {
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();
}

View File

@ -480,7 +480,7 @@ public abstract class EntityRepository<T extends EntityInterface> {
// 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<T extends EntityInterface> {
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<T extends EntityInterface> {
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) {

View File

@ -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<List<String>> result;
List<EntityLinkThreadCount> entityLinkThreadCounts = new ArrayList<>();
@ -512,20 +513,12 @@ public class FeedRepository {
}
public static class FilteredThreads {
List<Thread> threads;
int totalCount;
@Getter private final List<Thread> threads;
@Getter private final int totalCount;
public FilteredThreads(List<Thread> threads, int totalCount) {
this.threads = threads;
this.totalCount = totalCount;
}
public List<Thread> getThreads() {
return threads;
}
public int getTotalCount() {
return totalCount;
}
}
}

View File

@ -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<EntityReference> {
@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"));
}
}

View File

@ -7,7 +7,7 @@ import org.openmetadata.catalog.type.Include;
public class ListFilter {
private final Include include;
Map<String, String> queryParams = new HashMap<>();
private final Map<String, String> queryParams = new HashMap<>();
public ListFilter() {
this(Include.NON_DELETED);

View File

@ -101,9 +101,7 @@ public class MessagingServiceRepository extends EntityRepository<MessagingServic
@Override
public void entitySpecificUpdate() throws IOException {
MessagingService origService = original;
MessagingService updatedService = updated;
recordChange("connection", origService.getConnection(), updatedService.getConnection(), true);
recordChange("connection", original.getConnection(), updated.getConnection(), true);
}
}
}

View File

@ -192,10 +192,6 @@ public class MlModelRepository extends EntityRepository<MlModel> {
}
}
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) {

View File

@ -87,7 +87,7 @@ public class TagCategoryRepository extends EntityRepository<TagCategory> {
}
@Override
public void prepare(TagCategory entity) throws IOException {
public void prepare(TagCategory entity) {
setFullyQualifiedName(entity);
}

View File

@ -75,7 +75,7 @@ public class TagRepository extends EntityRepository<Tag> {
}
@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);

View File

@ -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<EntityReference> {
@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"));
}
}

View File

@ -56,7 +56,7 @@ public class TypeRepository extends EntityRepository<Type> {
}
@Override
public void prepare(Type type) throws IOException {
public void prepare(Type type) {
setFullyQualifiedName(type);
TypeRegistry.instance().validateCustomFields(type);
}

View File

@ -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> usageDetails = dao.usageDAO().getUsageById(ref.getId().toString(), date, days - 1);
return new EntityUsage().withUsage(usageDetails).withEntity(ref);

View File

@ -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<User> {
}
@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<User> {
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);

View File

@ -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<Webhook> {
}
@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<Webhook> {
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

View File

@ -76,9 +76,8 @@ public class FeedResource {
private final FeedRepository dao;
private final Authorizer authorizer;
public static List<Thread> addHref(UriInfo uriInfo, List<Thread> threads) {
public static void addHref(UriInfo uriInfo, List<Thread> 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);
}

View File

@ -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;

View File

@ -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

View File

@ -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());

View File

@ -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!");

View File

@ -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;

View File

@ -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;

View File

@ -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()

View File

@ -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;
}

View File

@ -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());
}
}

View File

@ -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());

View File

@ -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<Object, Object> objectMatch = Object::equals;
public static final BiPredicate<EntityInterface, EntityInterface> entityMatch =
(ref1, ref2) -> ref1.getId().equals(ref2.getId());
public static final BiPredicate<EntityReference, EntityReference> 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();

View File

@ -56,7 +56,7 @@ public class FullyQualifiedName {
}
private static class SplitListener extends FqnBaseListener {
List<String> list = new ArrayList<>();
final List<String> list = new ArrayList<>();
public String[] split() {
return list.toArray(new String[0]);

View File

@ -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);

View File

@ -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";

View File

@ -18,7 +18,7 @@ import org.openmetadata.catalog.exception.PipelineServiceClientException;
*
* <ul>
* <li>A PipelineService is a service such as AirFlow to which a pipeline can be deployed
* <li>A Pipeline is a workflow for performing certain taks. Example - ingestion pipeline is a workflow that connects
* <li>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.
* <li>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<String> getServiceStatus();

View File

@ -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<T extends EntityInterface, K extends Cr
// Entity specific validate for entity create using PUT
public void validateUpdatedEntity(T updatedEntity, K request, Map<String, String> authHeaders)
throws HttpResponseException {
validateCommonEntityFields(updatedEntity, request, authHeaders);
validateCreatedEntity(updatedEntity, request, authHeaders);
}
protected void validateDeletedEntity(
K create, T entityBeforeDeletion, T entityAfterDeletion, Map<String, String> authHeaders)
throws HttpResponseException {
validateCommonEntityFields(entityAfterDeletion, create, authHeaders);
validateCreatedEntity(entityAfterDeletion, create, authHeaders);
}
@ -1382,23 +1386,23 @@ public abstract class EntityResourceTest<T extends EntityInterface, K extends Cr
/** Helper function to create an entity, submit POST API request and validate response. */
public final T createAndCheckEntity(K create, Map<String, String> 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<T extends EntityInterface, K extends Cr
// Validate information returned in patch response has the updates
T returned = patchEntity(updated.getId(), originalJson, updated, authHeaders);
validateCommonEntityFields(updated, returned, authHeaders);
compareEntities(updated, returned, authHeaders);
validateChangeDescription(returned, updateType, expectedChange);
validateEntityHistory(returned.getId(), updateType, expectedChange, authHeaders);
@ -1488,6 +1493,7 @@ public abstract class EntityResourceTest<T extends EntityInterface, K extends Cr
// GET the entity and Validate information returned
T getEntity = getEntity(returned.getId(), authHeaders);
validateCommonEntityFields(updated, returned, authHeaders);
compareEntities(updated, getEntity, authHeaders);
validateChangeDescription(getEntity, updateType, expectedChange);
@ -1525,12 +1531,24 @@ public abstract class EntityResourceTest<T extends EntityInterface, K extends Cr
entity, originalJson, authHeaders(userName + "@open-metadata.org"), MINOR_UPDATE, change);
}
protected final void validateCommonEntityFields(
T entity, String expectedDescription, String expectedUpdatedByUser, EntityReference expectedOwner) {
protected final void validateCommonEntityFields(T entity, CreateEntity create, Map<String, String> 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<String, String> 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<T extends EntityInterface, K extends Cr
assertEquals(entityType, changeEvent.getEntityType());
assertEquals(entity.getId(), changeEvent.getEntityId());
assertEquals(entity.getVersion(), changeEvent.getCurrentVersion());
assertEquals(TestUtils.getPrincipal(authHeaders), changeEvent.getUserName());
assertEquals(SecurityUtil.getPrincipalName(authHeaders), changeEvent.getUserName());
//
// previous, entity, changeDescription
@ -1630,7 +1648,9 @@ public abstract class EntityResourceTest<T extends EntityInterface, K extends Cr
assertEquals(EventType.ENTITY_CREATED, changeEvent.getEventType());
assertEquals(0.1, changeEvent.getPreviousVersion());
assertNull(changeEvent.getChangeDescription());
compareEntities(entity, JsonUtils.readValue((String) changeEvent.getEntity(), entityClass), authHeaders);
T changeEventEntity = JsonUtils.readValue((String) changeEvent.getEntity(), entityClass);
validateCommonEntityFields(entity, changeEventEntity, authHeaders);
compareEntities(entity, changeEventEntity, authHeaders);
} else if (expectedEventType == EventType.ENTITY_UPDATED) {
assertChangeDescription(expectedChangeDescription, changeEvent.getChangeDescription());
} else if (expectedEventType == EventType.ENTITY_DELETED) {
@ -1641,7 +1661,7 @@ public abstract class EntityResourceTest<T extends EntityInterface, K extends Cr
private void validateDeletedEvent(
UUID id, long timestamp, EventType expectedEventType, Double expectedVersion, Map<String, String> authHeaders)
throws IOException {
String updatedBy = TestUtils.getPrincipal(authHeaders);
String updatedBy = SecurityUtil.getPrincipalName(authHeaders);
ResultList<ChangeEvent> changeEvents;
ChangeEvent changeEvent = null;

View File

@ -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<Bot, CreateBot> {
public static User botUser;
@ -65,13 +63,11 @@ public class BotResourceTest extends EntityResourceTest<Bot, CreateBot> {
@Override
public void validateCreatedEntity(Bot entity, CreateBot request, Map<String, String> authHeaders)
throws HttpResponseException {
validateCommonEntityFields(entity, request.getDescription(), getPrincipal(authHeaders), null);
assertReference(request.getBotUser(), entity.getBotUser());
}
@Override
public void compareEntities(Bot expected, Bot updated, Map<String, String> authHeaders) throws HttpResponseException {
validateCommonEntityFields(updated, expected.getDescription(), TestUtils.getPrincipal(authHeaders), null);
assertReference(expected.getBotUser(), updated.getBotUser());
}

View File

@ -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<Chart, CreateChart> {
@ -117,16 +116,12 @@ public class ChartResourceTest extends EntityResourceTest<Chart, CreateChart> {
@Override
public void validateCreatedEntity(Chart chart, CreateChart createRequest, Map<String, String> 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<String, String> authHeaders) {
validateCommonEntityFields(
patched, expected.getDescription(), TestUtils.getPrincipal(authHeaders), expected.getOwner());
assertReference(expected.getService(), patched.getService());
}

View File

@ -215,8 +215,6 @@ public class DashboardResourceTest extends EntityResourceTest<Dashboard, CreateD
@Override
public void validateCreatedEntity(Dashboard dashboard, CreateDashboard createRequest, Map<String, String> authHeaders)
throws HttpResponseException {
validateCommonEntityFields(
dashboard, createRequest.getDescription(), TestUtils.getPrincipal(authHeaders), createRequest.getOwner());
assertNotNull(dashboard.getServiceType());
assertReference(createRequest.getService(), dashboard.getService());
validateDashboardCharts(dashboard, createRequest.getCharts());

View File

@ -155,9 +155,6 @@ public class DatabaseResourceTest extends EntityResourceTest<Database, CreateDat
@Override
public void validateCreatedEntity(Database database, CreateDatabase createRequest, Map<String, String> 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<Database, CreateDat
@Override
public void compareEntities(Database expected, Database updated, Map<String, String> 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());

View File

@ -117,9 +117,6 @@ public class DatabaseSchemaResourceTest extends EntityResourceTest<DatabaseSchem
@Override
public void validateCreatedEntity(
DatabaseSchema schema, CreateDatabaseSchema createRequest, Map<String, String> 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<DatabaseSchem
@Override
public void compareEntities(DatabaseSchema expected, DatabaseSchema updated, Map<String, String> authHeaders) {
validateCommonEntityFields(
updated, expected.getDescription(), TestUtils.getPrincipal(authHeaders), expected.getOwner());
// Validate service
assertReference(expected.getDatabase(), updated.getDatabase());
assertEquals(

View File

@ -2047,9 +2047,6 @@ public class TableResourceTest extends EntityResourceTest<Table, CreateTable> {
@Override
public void validateCreatedEntity(Table createdEntity, CreateTable createRequest, Map<String, String> 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<Table, CreateTable> {
@Override
public void compareEntities(Table expected, Table patched, Map<String, String> 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());

View File

@ -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<Webhook, CreateWebho
@Override
public void validateCreatedEntity(Webhook webhook, CreateWebhook createRequest, Map<String, String> authHeaders)
throws HttpResponseException {
validateCommonEntityFields(webhook, createRequest.getDescription(), TestUtils.getPrincipal(authHeaders), null);
assertEquals(createRequest.getName(), webhook.getName());
ArrayList<EventFilter> filters = new ArrayList<>(createRequest.getEventFilters());
EntityUtil.addSoftDeleteFilter(filters);

View File

@ -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());
}
}

View File

@ -133,19 +133,12 @@ public class GlossaryResourceTest extends EntityResourceTest<Glossary, CreateGlo
public void validateCreatedEntity(
Glossary createdEntity, CreateGlossary createRequest, Map<String, String> 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<String, String> 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());

View File

@ -312,7 +312,6 @@ public class GlossaryTermResourceTest extends EntityResourceTest<GlossaryTerm, C
@Override
public void validateCreatedEntity(GlossaryTerm entity, CreateGlossaryTerm request, Map<String, String> 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<GlossaryTerm, C
@Override
public void compareEntities(GlossaryTerm expected, GlossaryTerm patched, Map<String, String> 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());

View File

@ -75,8 +75,6 @@ public class LocationResourceTest extends EntityResourceTest<Location, CreateLoc
@Override
public void validateCreatedEntity(Location location, CreateLocation createRequest, Map<String, String> 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<Location, CreateLoc
@Override
public void compareEntities(Location expected, Location patched, Map<String, String> 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());

View File

@ -137,10 +137,6 @@ public class TypeResourceTest extends EntityResourceTest<Type, CreateType> {
@Override
public void validateCreatedEntity(Type createdEntity, CreateType createRequest, Map<String, String> 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<Type, CreateType> {
@Override
public void compareEntities(Type expected, Type patched, Map<String, String> authHeaders)
throws HttpResponseException {
validateCommonEntityFields(patched, expected.getDescription(), TestUtils.getPrincipal(authHeaders), null);
// Entity specific validation
assertEquals(expected.getSchema(), patched.getSchema());
// TODO more checks
}

View File

@ -379,9 +379,6 @@ public class MlModelResourceTest extends EntityResourceTest<MlModel, CreateMlMod
@Override
public void compareEntities(MlModel expected, MlModel updated, Map<String, String> 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<MlModel, CreateMlMod
@Override
public void validateCreatedEntity(MlModel createdEntity, CreateMlModel createRequest, Map<String, String> 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);

View File

@ -105,8 +105,6 @@ public class PipelineResourceTest extends EntityResourceTest<Pipeline, CreatePip
@Override
public void validateCreatedEntity(Pipeline pipeline, CreatePipeline createRequest, Map<String, String> 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<Pipeline, CreatePip
@Override
public void compareEntities(Pipeline expected, Pipeline updated, Map<String, String> 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());

View File

@ -78,8 +78,6 @@ public class PolicyResourceTest extends EntityResourceTest<Policy, CreatePolicy>
@Override
public void validateCreatedEntity(Policy policy, CreatePolicy createRequest, Map<String, String> authHeaders) {
validateCommonEntityFields(
policy, createRequest.getDescription(), TestUtils.getPrincipal(authHeaders), createRequest.getOwner());
assertEquals(createRequest.getPolicyUrl(), policy.getPolicyUrl());
}

View File

@ -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<DashboardSe
@Override
public void validateCreatedEntity(
DashboardService service, CreateDashboardService createRequest, Map<String, String> authHeaders) {
validateCommonEntityFields(
service, createRequest.getDescription(), getPrincipal(authHeaders), createRequest.getOwner());
assertEquals(createRequest.getName(), service.getName());
DashboardConnection expectedConnection = createRequest.getConnection();
DashboardConnection actualConnection = service.getConnection();

View File

@ -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<DatabaseServ
@Override
public void validateCreatedEntity(
DatabaseService service, CreateDatabaseService createRequest, Map<String, String> authHeaders) {
validateCommonEntityFields(
service, createRequest.getDescription(), getPrincipal(authHeaders), createRequest.getOwner());
assertEquals(createRequest.getName(), service.getName());
validateDatabaseConnection(createRequest.getConnection(), service.getConnection(), service.getServiceType());
}

View File

@ -198,8 +198,6 @@ public class MessagingServiceResourceTest extends EntityResourceTest<MessagingSe
@Override
public void validateCreatedEntity(
MessagingService service, CreateMessagingService createRequest, Map<String, String> authHeaders) {
validateCommonEntityFields(
service, createRequest.getDescription(), TestUtils.getPrincipal(authHeaders), createRequest.getOwner());
MessagingConnection expectedMessagingConnection = createRequest.getConnection();
MessagingConnection actualMessagingConnection = service.getConnection();
validateConnection(expectedMessagingConnection, actualMessagingConnection, service.getServiceType());

View File

@ -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<PipelineServ
@Override
public void validateCreatedEntity(
PipelineService service, CreatePipelineService createRequest, Map<String, String> authHeaders) {
validateCommonEntityFields(
service, createRequest.getDescription(), getPrincipal(authHeaders), createRequest.getOwner());
assertEquals(createRequest.getName(), service.getName());
Schedule expectedIngestion = createRequest.getIngestionSchedule();

View File

@ -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<StorageServic
@Override
public void validateCreatedEntity(
StorageService service, CreateStorageService createRequest, Map<String, String> authHeaders) {
validateCommonEntityFields(
service, createRequest.getDescription(), getPrincipal(authHeaders), createRequest.getOwner());
assertEquals(createRequest.getName(), service.getName());
}

View File

@ -138,8 +138,6 @@ public class IngestionPipelineResourceTest extends EntityResourceTest<IngestionP
public void validateCreatedEntity(
IngestionPipeline ingestion, CreateIngestionPipeline createRequest, Map<String, String> 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<IngestionP
@Override
public void compareEntities(IngestionPipeline expected, IngestionPipeline updated, Map<String, String> 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());

View File

@ -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<String, String> 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<String, String> 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<String, String> 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<String, String> 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<String, String> 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<String, String> 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);

View File

@ -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<Role, CreateRole> {
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<Role, CreateRole> {
@Override
public void validateCreatedEntity(Role role, CreateRole createRequest, Map<String, String> authHeaders) {
validateCommonEntityFields(role, createRequest.getDescription(), TestUtils.getPrincipal(authHeaders), null);
assertEntityReferenceList(role.getPolicies(), createRequest.getPolicies());
}
@Override
public void compareEntities(Role expected, Role updated, Map<String, String> authHeaders) {
validateCommonEntityFields(updated, expected.getDescription(), TestUtils.getPrincipal(authHeaders), null);
assertEquals(expected.getDisplayName(), updated.getDisplayName());
}

View File

@ -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<Team, CreateTeam> {
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<Team, CreateTeam> {
@Override
public void validateCreatedEntity(Team team, CreateTeam createRequest, Map<String, String> 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<Team, CreateTeam> {
TestUtils.assertEntityReferenceList(expectedDefaultRoles, team.getDefaultRoles());
}
@Override
public void validateUpdatedEntity(Team updatedEntity, CreateTeam request, Map<String, String> authHeaders) {
validateCreatedEntity(updatedEntity, request, authHeaders);
}
@Override
protected void validateDeletedEntity(
CreateTeam create, Team teamBeforeDeletion, Team teamAfterDeletion, Map<String, String> authHeaders)
@ -424,9 +417,6 @@ public class TeamResourceTest extends EntityResourceTest<Team, CreateTeam> {
@Override
public void compareEntities(Team expected, Team updated, Map<String, String> authHeaders) {
validateCommonEntityFields(
updated, expected.getDescription(), TestUtils.getPrincipal(authHeaders), expected.getOwner());
assertEquals(expected.getDisplayName(), updated.getDisplayName());
assertEquals(expected.getProfile(), updated.getProfile());
TestUtils.validateEntityReferences(updated.getOwns());

View File

@ -793,8 +793,6 @@ public class UserResourceTest extends EntityResourceTest<User, CreateUser> {
@Override
public void validateCreatedEntity(User user, CreateUser createRequest, Map<String, String> 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<User, CreateUser> {
@Override
public void compareEntities(User expected, User updated, Map<String, String> authHeaders) {
validateCommonEntityFields(expected, expected.getDescription(), TestUtils.getPrincipal(authHeaders), null);
assertEquals(expected.getName(), expected.getName());
assertEquals(expected.getDisplayName(), expected.getDisplayName());
assertEquals(expected.getTimezone(), expected.getTimezone());

View File

@ -280,8 +280,6 @@ public class TopicResourceTest extends EntityResourceTest<Topic, CreateTopic> {
@Override
public void validateCreatedEntity(Topic topic, CreateTopic createRequest, Map<String, String> 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<Topic, CreateTopic> {
@Override
public void compareEntities(Topic expected, Topic updated, Map<String, String> 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());

View File

@ -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

View File

@ -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<String, String> 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) {