diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/events/ChangeEventHandler.java b/openmetadata-service/src/main/java/org/openmetadata/service/events/ChangeEventHandler.java index 4e709eeee1d..f09daca5b6f 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/events/ChangeEventHandler.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/events/ChangeEventHandler.java @@ -20,6 +20,7 @@ import static org.openmetadata.service.jdbi3.unitofwork.JdbiUnitOfWorkProvider.g import com.fasterxml.jackson.databind.ObjectMapper; import java.util.List; +import java.util.UUID; import javax.ws.rs.container.ContainerRequestContext; import javax.ws.rs.container.ContainerResponseContext; import javax.ws.rs.core.SecurityContext; @@ -121,8 +122,9 @@ public class ChangeEventHandler implements EventHandler { String entityId = entityInterface.getId().toString(); List threadIds = collectionDAO.feedDAO().findByEntityId(entityId); for (String threadId : threadIds) { - collectionDAO.relationshipDAO().deleteAll(threadId, Entity.THREAD); - collectionDAO.feedDAO().delete(threadId); + UUID id = UUID.fromString(threadId); + collectionDAO.relationshipDAO().deleteAll(id, Entity.THREAD); + collectionDAO.feedDAO().delete(id); } } diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/exception/CatalogExceptionMessage.java b/openmetadata-service/src/main/java/org/openmetadata/service/exception/CatalogExceptionMessage.java index 2bc18598bf4..50652d71610 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/exception/CatalogExceptionMessage.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/exception/CatalogExceptionMessage.java @@ -95,6 +95,13 @@ public final class CatalogExceptionMessage { return String.format("Entity type %s not found", entityType); } + public static String entityRelationshipNotFound( + String entityType, UUID id, String relationshipName, String toEntityType) { + return String.format( + "Entity type %s %s does not have expected relationship %s to/from entity type %s", + entityType, id, relationshipName, toEntityType); + } + public static String resourceTypeNotFound(String resourceType) { return String.format("Resource type %s not found", resourceType); } diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/CollectionDAO.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/CollectionDAO.java index 3283ca0cec3..af29c911d9c 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/CollectionDAO.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/CollectionDAO.java @@ -127,6 +127,7 @@ import org.openmetadata.service.util.EntityUtil; import org.openmetadata.service.util.FullyQualifiedName; import org.openmetadata.service.util.JsonUtils; import org.openmetadata.service.util.jdbi.BindFQN; +import org.openmetadata.service.util.jdbi.BindUUID; public interface CollectionDAO { @CreateSqlObject @@ -599,29 +600,29 @@ public interface CollectionDAO { + "ON CONFLICT (id, extension) DO UPDATE SET jsonSchema = EXCLUDED.jsonSchema, json = EXCLUDED.json", connectionType = POSTGRES) void insert( - @Bind("id") String id, + @BindUUID("id") UUID id, @Bind("extension") String extension, @Bind("jsonSchema") String jsonSchema, @Bind("json") String json); @SqlQuery("SELECT json FROM entity_extension WHERE id = :id AND extension = :extension") - String getExtension(@Bind("id") String id, @Bind("extension") String extension); + String getExtension(@BindUUID("id") UUID id, @Bind("extension") String extension); @RegisterRowMapper(ExtensionMapper.class) @SqlQuery( "SELECT extension, json FROM entity_extension WHERE id = :id AND extension " + "LIKE CONCAT (:extensionPrefix, '.%') " + "ORDER BY extension") - List getExtensions(@Bind("id") String id, @Bind("extensionPrefix") String extensionPrefix); + List getExtensions(@BindUUID("id") UUID id, @Bind("extensionPrefix") String extensionPrefix); @SqlUpdate("DELETE FROM entity_extension WHERE id = :id AND extension = :extension") - void delete(@Bind("id") String id, @Bind("extension") String extension); + void delete(@BindUUID("id") UUID id, @Bind("extension") String extension); @SqlUpdate("DELETE FROM entity_extension WHERE extension = :extension") void deleteExtension(@Bind("extension") String extension); @SqlUpdate("DELETE FROM entity_extension WHERE id = :id") - void deleteAll(@Bind("id") String id); + void deleteAll(@BindUUID("id") UUID id); } class EntityVersionPair { @@ -688,10 +689,6 @@ public interface CollectionDAO { insert(fromId, toId, fromEntity, toEntity, relation, null); } - default void insert(UUID fromId, UUID toId, String fromEntity, String toEntity, int relation, String json) { - insert(fromId.toString(), toId.toString(), fromEntity, toEntity, relation, json); - } - default void bulkInsertToRelationship( UUID fromId, List toIds, String fromEntity, String toEntity, int relation) { @@ -724,8 +721,8 @@ public interface CollectionDAO { + "ON CONFLICT (fromId, toId, relation) DO UPDATE SET json = EXCLUDED.json", connectionType = POSTGRES) void insert( - @Bind("fromId") String fromId, - @Bind("toId") String toId, + @BindUUID("fromId") UUID fromId, + @BindUUID("toId") UUID toId, @Bind("fromEntity") String fromEntity, @Bind("toEntity") String toEntity, @Bind("relation") int relation, @@ -754,11 +751,11 @@ public interface CollectionDAO { + "ORDER BY toId") @RegisterRowMapper(ToRelationshipMapper.class) List findTo( - @Bind("fromId") String fromId, + @BindUUID("fromId") UUID fromId, @Bind("fromEntity") String fromEntity, @BindList("relation") List relation); - default List findTo(String fromId, String fromEntity, int relation) { + default List findTo(UUID fromId, String fromEntity, int relation) { return findTo(fromId, fromEntity, List.of(relation)); } @@ -769,7 +766,7 @@ public interface CollectionDAO { + "ORDER BY toId") @RegisterRowMapper(ToRelationshipMapper.class) List findTo( - @Bind("fromId") String fromId, + @BindUUID("fromId") UUID fromId, @Bind("fromEntity") String fromEntity, @Bind("relation") int relation, @Bind("toEntity") String toEntity); @@ -787,7 +784,7 @@ public interface CollectionDAO { + "ORDER BY toId", connectionType = POSTGRES) @RegisterRowMapper(ToRelationshipMapper.class) - List findToPipeline(@Bind("fromId") String fromId, @Bind("relation") int relation); + List findToPipeline(@BindUUID("fromId") UUID fromId, @Bind("relation") int relation); // // Find from operations @@ -798,7 +795,7 @@ public interface CollectionDAO { + "ORDER BY fromId") @RegisterRowMapper(FromRelationshipMapper.class) List findFrom( - @Bind("toId") String toId, + @BindUUID("toId") UUID toId, @Bind("toEntity") String toEntity, @Bind("relation") int relation, @Bind("fromEntity") String fromEntity); @@ -809,7 +806,7 @@ public interface CollectionDAO { + "ORDER BY fromId") @RegisterRowMapper(FromRelationshipMapper.class) List findFrom( - @Bind("toId") String toId, @Bind("toEntity") String toEntity, @Bind("relation") int relation); + @BindUUID("toId") UUID toId, @Bind("toEntity") String toEntity, @Bind("relation") int relation); @ConnectionAwareSqlQuery( value = @@ -824,7 +821,7 @@ public interface CollectionDAO { + "ORDER BY fromId", connectionType = POSTGRES) @RegisterRowMapper(FromRelationshipMapper.class) - List findFromPipleine(@Bind("toId") String toId, @Bind("relation") int relation); + List findFromPipleine(@BindUUID("toId") UUID toId, @Bind("relation") int relation); @SqlQuery("SELECT fromId, fromEntity, json FROM entity_relationship " + "WHERE toId = :toId ORDER BY fromId") @RegisterRowMapper(FromRelationshipMapper.class) @@ -841,9 +838,9 @@ public interface CollectionDAO { + "AND fromEntity = :fromEntity AND toId = :toId AND toEntity = :toEntity " + "AND relation = :relation") int delete( - @Bind("fromId") String fromId, + @BindUUID("fromId") UUID fromId, @Bind("fromEntity") String fromEntity, - @Bind("toId") String toId, + @BindUUID("toId") UUID toId, @Bind("toEntity") String toEntity, @Bind("relation") int relation); @@ -852,7 +849,7 @@ public interface CollectionDAO { "DELETE from entity_relationship WHERE fromId = :fromId AND fromEntity = :fromEntity " + "AND relation = :relation AND toEntity = :toEntity") void deleteFrom( - @Bind("fromId") String fromId, + @BindUUID("fromId") UUID fromId, @Bind("fromEntity") String fromEntity, @Bind("relation") int relation, @Bind("toEntity") String toEntity); @@ -862,7 +859,7 @@ public interface CollectionDAO { "DELETE from entity_relationship WHERE toId = :toId AND toEntity = :toEntity AND relation = :relation " + "AND fromEntity = :fromEntity") void deleteTo( - @Bind("toId") String toId, + @BindUUID("toId") UUID toId, @Bind("toEntity") String toEntity, @Bind("relation") int relation, @Bind("fromEntity") String fromEntity); @@ -870,10 +867,10 @@ public interface CollectionDAO { @SqlUpdate( "DELETE from entity_relationship WHERE (toId = :id AND toEntity = :entity) OR " + "(fromId = :id AND fromEntity = :entity)") - void deleteAll(@Bind("id") String id, @Bind("entity") String entity); + void deleteAll(@BindUUID("id") UUID id, @Bind("entity") String entity); @SqlUpdate("DELETE from entity_relationship WHERE fromId = :id or toId = :id") - void deleteAllWithId(@Bind("id") String id); + void deleteAllWithId(@BindUUID("id") UUID id); class FromRelationshipMapper implements RowMapper { @Override @@ -906,7 +903,7 @@ public interface CollectionDAO { void insert(@Bind("json") String json); @SqlQuery("SELECT json FROM thread_entity WHERE id = :id") - String findById(@Bind("id") String id); + String findById(@BindUUID("id") UUID id); @SqlQuery("SELECT json FROM thread_entity ORDER BY createdAt DESC") List list(); @@ -915,7 +912,7 @@ public interface CollectionDAO { int listCount(@Define("condition") String condition); @SqlUpdate("DELETE FROM thread_entity WHERE id = :id") - void delete(@Bind("id") String id); + void delete(@BindUUID("id") UUID id); @ConnectionAwareSqlUpdate(value = "UPDATE task_sequence SET id=LAST_INSERT_ID(id+1)", connectionType = MYSQL) @ConnectionAwareSqlUpdate(value = "UPDATE task_sequence SET id=(id+1) RETURNING id", connectionType = POSTGRES) @@ -938,8 +935,8 @@ public interface CollectionDAO { + "OR (:endTs > announcementStart AND :endTs < announcementEnd) " + "OR (:startTs <= announcementStart AND :endTs >= announcementEnd))") List listAnnouncementBetween( - @Bind("threadId") String threadId, - @Bind("entityId") String entityId, + @BindUUID("threadId") UUID threadId, + @BindUUID("entityId") UUID entityId, @Bind("startTs") long startTs, @Bind("endTs") long endTs); @@ -1033,7 +1030,7 @@ public interface CollectionDAO { + "ORDER BY createdAt DESC " + "LIMIT :limit") List listThreadsByOwner( - @Bind("userId") String userId, + @BindUUID("userId") UUID userId, @BindList("teamIds") List teamIds, @Bind("limit") int limit, @Define("condition") String condition); @@ -1045,7 +1042,7 @@ public interface CollectionDAO { + "(fromEntity='team' AND fromId IN ())) AND relation=8) OR " + "id in (SELECT toId FROM entity_relationship WHERE (fromEntity='user' AND fromId= :userId AND toEntity='THREAD' AND relation IN (1,2)))) ") int listCountThreadsByOwner( - @Bind("userId") String userId, + @BindUUID("userId") UUID userId, @BindList("teamIds") List teamIds, @Define("condition") String condition); @@ -1123,7 +1120,7 @@ public interface CollectionDAO { @ConnectionAwareSqlUpdate( value = "UPDATE thread_entity SET json = (:json :: jsonb) where id = :id", connectionType = POSTGRES) - void update(@Bind("id") String id, @Bind("json") String json); + void update(@BindUUID("id") UUID id, @Bind("json") String json); @SqlQuery( "SELECT entityLink, COUNT(id) count FROM field_relationship fr INNER JOIN thread_entity te ON fr.fromFQNHash=MD5(te.id) " @@ -1151,7 +1148,7 @@ public interface CollectionDAO { + "GROUP BY entityLink") @RegisterRowMapper(CountFieldMapper.class) List> listCountByOwner( - @Bind("userId") String userId, + @BindUUID("userId") UUID userId, @BindList("teamIds") List teamIds, @Define("condition") String condition); @@ -1164,7 +1161,7 @@ public interface CollectionDAO { + "ORDER BY createdAt DESC " + "LIMIT :limit") List listThreadsByFollows( - @Bind("userId") String userId, + @BindUUID("userId") UUID userId, @BindList("teamIds") List teamIds, @Bind("limit") int limit, @Bind("relation") int relation, @@ -1177,7 +1174,7 @@ public interface CollectionDAO { + "((fromEntity='user' AND fromId= :userId) OR " + "(fromEntity='team' AND fromId IN ())) AND relation= :relation)") int listCountThreadsByFollows( - @Bind("userId") String userId, + @BindUUID("userId") UUID userId, @BindList("teamIds") List teamIds, @Bind("relation") int relation, @Define("condition") String condition); @@ -2410,7 +2407,7 @@ public interface CollectionDAO { return listAfter(getTableName(), getNameColumn(), mySqlCondition, postgresCondition, limit, after); } - default List listTeamsUnderOrganization(String teamId) { + default List listTeamsUnderOrganization(UUID teamId) { return listTeamsUnderOrganization(teamId, Relationship.PARENT_OF.ordinal()); } @@ -2420,7 +2417,7 @@ public interface CollectionDAO { + "WHERE te.id NOT IN (SELECT :teamId) UNION " + "(SELECT toId FROM entity_relationship " + "WHERE fromId != :teamId AND fromEntity = 'team' AND relation = :relation AND toEntity = 'team')") - List listTeamsUnderOrganization(@Bind("teamId") String teamId, @Bind("relation") int relation); + List listTeamsUnderOrganization(@BindUUID("teamId") UUID teamId, @Bind("relation") int relation); } interface TopicDAO extends EntityDAO { @@ -2463,7 +2460,7 @@ public interface CollectionDAO { connectionType = POSTGRES) void insertOrReplaceCount( @Bind("date") String date, - @Bind("id") String id, + @BindUUID("id") UUID id, @Bind("entityType") String entityType, @Bind("count1") int count1); @@ -2487,7 +2484,7 @@ public interface CollectionDAO { connectionType = POSTGRES) void insertOrUpdateCount( @Bind("date") String date, - @Bind("id") String id, + @BindUUID("id") UUID id, @Bind("entityType") String entityType, @Bind("count1") int count1); @@ -2503,7 +2500,7 @@ public interface CollectionDAO { + "percentile1, percentile7, percentile30 FROM entity_usage " + "WHERE id = :id AND usageDate >= (:date :: date) - make_interval(days => :days) AND usageDate <= (:date :: date) ORDER BY usageDate DESC", connectionType = POSTGRES) - List getUsageById(@Bind("id") String id, @Bind("date") String date, @Bind("days") int days); + List getUsageById(@BindUUID("id") UUID id, @Bind("date") String date, @Bind("days") int days); /** Get latest usage record */ @SqlQuery( @@ -2513,7 +2510,7 @@ public interface CollectionDAO { UsageDetails getLatestUsage(@Bind("id") String id); @SqlUpdate("DELETE FROM entity_usage WHERE id = :id") - void delete(@Bind("id") String id); + void delete(@BindUUID("id") UUID id); /** * TODO: Not sure I get what the next comment means, but tests now use mysql 8 so maybe tests can be improved here @@ -3466,7 +3463,7 @@ public interface CollectionDAO { @SqlQuery("SELECT tokenType, json FROM user_tokens WHERE userId = :userId AND tokenType = :tokenType ") @RegisterRowMapper(TokenRowMapper.class) - List getAllUserTokenWithType(@Bind("userId") String userId, @Bind("tokenType") String tokenType) + List getAllUserTokenWithType(@BindUUID("userId") UUID userId, @Bind("tokenType") String tokenType) throws StatementException; @ConnectionAwareSqlUpdate(value = "INSERT INTO user_tokens (json) VALUES (:json)", connectionType = MYSQL) @@ -3490,7 +3487,7 @@ public interface CollectionDAO { void deleteAll(@BindList("tokenIds") List tokens); @SqlUpdate(value = "DELETE from user_tokens WHERE userid = :userid AND tokenType = :tokenType") - void deleteTokenByUserAndType(@Bind("userid") String userid, @Bind("tokenType") String tokenType); + void deleteTokenByUserAndType(@BindUUID("userid") UUID userid, @Bind("tokenType") String tokenType); } interface KpiDAO extends EntityDAO { diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/EntityDAO.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/EntityDAO.java index 3448db27602..7881951c31f 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/EntityDAO.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/EntityDAO.java @@ -36,6 +36,7 @@ import org.openmetadata.service.jdbi3.locator.ConnectionAwareSqlUpdate; import org.openmetadata.service.util.FullyQualifiedName; import org.openmetadata.service.util.JsonUtils; import org.openmetadata.service.util.jdbi.BindFQN; +import org.openmetadata.service.util.jdbi.BindUUID; public interface EntityDAO { org.slf4j.Logger LOG = org.slf4j.LoggerFactory.getLogger(EntityDAO.class); @@ -247,7 +248,7 @@ public interface EntityDAO { @BindFQN("fqnHash") String fqnHash); @SqlUpdate("DELETE FROM WHERE id = :id") - int delete(@Define("table") String table, @Bind("id") String id); + int delete(@Define("table") String table, @BindUUID("id") UUID id); /** Default methods that interfaces with implementation. Don't override */ default void insert(EntityInterface entity, String fqn) { @@ -375,7 +376,7 @@ public interface EntityDAO { } } - default int delete(String id) { + default int delete(UUID id) { int rowsDeleted = delete(getTableName(), id); if (rowsDeleted <= 0) { String entityType = Entity.getEntityTypeFromClass(getEntityClass()); diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/EntityRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/EntityRepository.java index d4818b63559..84ac1618024 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/EntityRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/EntityRepository.java @@ -598,7 +598,7 @@ public abstract class EntityRepository { String extension = EntityUtil.getVersionExtension(entityType, requestedVersion); // Get previous version from version history - String json = daoCollection.entityExtensionDAO().getExtension(id.toString(), extension); + String json = daoCollection.entityExtensionDAO().getExtension(id, extension); if (json != null) { return JsonUtils.readValue(json, entityClass); } @@ -614,7 +614,7 @@ public abstract class EntityRepository { public EntityHistory listVersions(UUID id) { T latest = setFieldsInternal(dao.findEntityById(id, ALL), putFields); String extensionPrefix = EntityUtil.getVersionExtensionPrefix(entityType); - List records = daoCollection.entityExtensionDAO().getExtensions(id.toString(), extensionPrefix); + List records = daoCollection.entityExtensionDAO().getExtensions(id, extensionPrefix); List oldVersions = new ArrayList<>(); records.forEach(r -> oldVersions.add(new EntityVersionPair(r))); oldVersions.sort(EntityUtil.compareVersion.reversed()); @@ -901,8 +901,7 @@ public abstract class EntityRepository { List childrenRecords = daoCollection .relationshipDAO() - .findTo( - id.toString(), entityType, List.of(Relationship.CONTAINS.ordinal(), Relationship.PARENT_OF.ordinal())); + .findTo(id, entityType, List.of(Relationship.CONTAINS.ordinal(), Relationship.PARENT_OF.ordinal())); if (childrenRecords.isEmpty()) { LOG.info("No children to delete"); @@ -925,7 +924,7 @@ public abstract class EntityRepository { } protected void cleanup(T entityInterface) { - String id = entityInterface.getId().toString(); + UUID id = entityInterface.getId(); // Delete all the relationships to other entities daoCollection.relationshipDAO().deleteAll(id, entityType); @@ -1127,12 +1126,12 @@ public abstract class EntityRepository { String fieldFQN = TypeRegistry.getCustomPropertyFQN(entityType, fieldName); daoCollection .entityExtensionDAO() - .insert(entity.getId().toString(), fieldFQN, "customFieldSchema", JsonUtils.pojoToJson(value)); + .insert(entity.getId(), fieldFQN, "customFieldSchema", JsonUtils.pojoToJson(value)); } private void removeCustomProperty(EntityInterface entity, String fieldName) { String fieldFQN = TypeRegistry.getCustomPropertyFQN(entityType, fieldName); - daoCollection.entityExtensionDAO().delete(entity.getId().toString(), fieldFQN); + daoCollection.entityExtensionDAO().delete(entity.getId(), fieldFQN); } public Object getExtension(T entity) { @@ -1140,8 +1139,7 @@ public abstract class EntityRepository { return null; } String fieldFQNPrefix = TypeRegistry.getCustomPropertyFQNPrefix(entityType); - List records = - daoCollection.entityExtensionDAO().getExtensions(entity.getId().toString(), fieldFQNPrefix); + List records = daoCollection.entityExtensionDAO().getExtensions(entity.getId(), fieldFQNPrefix); if (records.isEmpty()) { return null; } @@ -1276,7 +1274,7 @@ public abstract class EntityRepository { public PutResponse restoreEntity(String updatedBy, String entityType, UUID id) { // If an entity being restored contains other **deleted** children entities, restore them List records = - daoCollection.relationshipDAO().findTo(id.toString(), entityType, Relationship.CONTAINS.ordinal()); + daoCollection.relationshipDAO().findTo(id, entityType, Relationship.CONTAINS.ordinal()); if (!records.isEmpty()) { // Restore all the contained entities @@ -1351,10 +1349,8 @@ public abstract class EntityRepository { UUID toId, String toEntityType, Relationship relationship, String fromEntityType) { // When fromEntityType is null, all the relationships from any entity is returned return fromEntityType == null - ? daoCollection.relationshipDAO().findFrom(toId.toString(), toEntityType, relationship.ordinal()) - : daoCollection - .relationshipDAO() - .findFrom(toId.toString(), toEntityType, relationship.ordinal(), fromEntityType); + ? daoCollection.relationshipDAO().findFrom(toId, toEntityType, relationship.ordinal()) + : daoCollection.relationshipDAO().findFrom(toId, toEntityType, relationship.ordinal(), fromEntityType); } public EntityReference getContainer(UUID toId) { @@ -1364,7 +1360,7 @@ public abstract class EntityRepository { public EntityReference getFromEntityRef( UUID toId, Relationship relationship, String fromEntityType, boolean mustHaveRelationship) { List records = findFromRecords(toId, entityType, relationship, fromEntityType); - ensureSingleRelationship(entityType, toId, records, relationship.value(), mustHaveRelationship); + ensureSingleRelationship(entityType, toId, records, relationship.value(), fromEntityType, mustHaveRelationship); return !records.isEmpty() ? Entity.getEntityReferenceById(records.get(0).getType(), records.get(0).getId(), ALL) : null; @@ -1373,17 +1369,23 @@ public abstract class EntityRepository { public EntityReference getToEntityRef( UUID fromId, Relationship relationship, String toEntityType, boolean mustHaveRelationship) { List records = findToRecords(fromId, entityType, relationship, toEntityType); - ensureSingleRelationship(entityType, fromId, records, relationship.value(), mustHaveRelationship); + ensureSingleRelationship(entityType, fromId, records, relationship.value(), toEntityType, mustHaveRelationship); return !records.isEmpty() ? Entity.getEntityReferenceById(records.get(0).getType(), records.get(0).getId(), ALL) : null; } public void ensureSingleRelationship( - String entityType, UUID id, List relations, String relationshipName, boolean mustHaveRelationship) { - // An entity can have only one container + String entityType, + UUID id, + List relations, + String relationshipName, + String toEntityType, + boolean mustHaveRelationship) { + // An entity can have only one relationship if (mustHaveRelationship && relations.isEmpty()) { - throw new UnhandledServerException(CatalogExceptionMessage.entityTypeNotFound(entityType)); + throw new UnhandledServerException( + CatalogExceptionMessage.entityRelationshipNotFound(entityType, id, relationshipName, toEntityType)); } if (!mustHaveRelationship && relations.isEmpty()) { return; @@ -1404,26 +1406,22 @@ public abstract class EntityRepository { UUID fromId, String fromEntityType, Relationship relationship, String toEntityType) { // When toEntityType is null, all the relationships to any entity is returned return toEntityType == null - ? daoCollection.relationshipDAO().findTo(fromId.toString(), fromEntityType, relationship.ordinal()) - : daoCollection - .relationshipDAO() - .findTo(fromId.toString(), fromEntityType, relationship.ordinal(), toEntityType); + ? daoCollection.relationshipDAO().findTo(fromId, fromEntityType, relationship.ordinal()) + : daoCollection.relationshipDAO().findTo(fromId, fromEntityType, relationship.ordinal(), toEntityType); } public void deleteRelationship( UUID fromId, String fromEntityType, UUID toId, String toEntityType, Relationship relationship) { - daoCollection - .relationshipDAO() - .delete(fromId.toString(), fromEntityType, toId.toString(), toEntityType, relationship.ordinal()); + daoCollection.relationshipDAO().delete(fromId, fromEntityType, toId, toEntityType, relationship.ordinal()); } public void deleteTo(UUID toId, String toEntityType, Relationship relationship, String fromEntityType) { - daoCollection.relationshipDAO().deleteTo(toId.toString(), toEntityType, relationship.ordinal(), fromEntityType); + daoCollection.relationshipDAO().deleteTo(toId, toEntityType, relationship.ordinal(), fromEntityType); } public void deleteFrom(UUID fromId, String fromEntityType, Relationship relationship, String toEntityType) { // Remove relationships from original - daoCollection.relationshipDAO().deleteFrom(fromId.toString(), fromEntityType, relationship.ordinal(), toEntityType); + daoCollection.relationshipDAO().deleteFrom(fromId, fromEntityType, relationship.ordinal(), toEntityType); } public void validateUsers(List entityReferences) { @@ -2212,7 +2210,7 @@ public abstract class EntityRepository { String extensionName = EntityUtil.getVersionExtension(entityType, original.getVersion()); daoCollection .entityExtensionDAO() - .insert(original.getId().toString(), extensionName, entityType, JsonUtils.pojoToJson(original)); + .insert(original.getId(), extensionName, entityType, JsonUtils.pojoToJson(original)); } private void storeNewVersion() { diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/FeedRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/FeedRepository.java index 897ee7809e3..19731244550 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/FeedRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/FeedRepository.java @@ -258,7 +258,7 @@ public class FeedRepository { .findFrom(about.getFullyQualifiedFieldValue(), about.getFullyQualifiedFieldType(), IS_ABOUT.ordinal()); for (Triple task : tasks) { if (task.getMiddle().equals(Entity.THREAD)) { - String threadId = task.getLeft(); + UUID threadId = UUID.fromString(task.getLeft()); Thread thread = EntityUtil.validate(threadId, dao.feedDAO().findById(threadId), Thread.class); if (thread.getTask() != null && thread.getTask().getType() == taskType) { return thread; @@ -283,14 +283,14 @@ public class FeedRepository { return threadContext.getThread(); } - public Thread get(String id) { + public Thread get(UUID id) { Thread thread = EntityUtil.validate(id, dao.feedDAO().findById(id), Thread.class); sortPosts(thread); return thread; } public Thread getTask(Integer id) { - Thread task = EntityUtil.validate(id.toString(), dao.feedDAO().findByTaskId(id), Thread.class); + Thread task = EntityUtil.validate(id, dao.feedDAO().findByTaskId(id), Thread.class); sortPosts(task); return populateAssignees(task); } @@ -354,7 +354,7 @@ public class FeedRepository { .withFrom(user) .withReactions(java.util.Collections.emptyList()) .withPostTs(System.currentTimeMillis()); - addPostToThread(thread.getId().toString(), post, user); + addPostToThread(thread.getId(), post, user); } public void closeTask(Thread thread, String user, CloseTask closeTask) { @@ -368,7 +368,7 @@ public class FeedRepository { task.withStatus(TaskStatus.Closed).withClosedBy(user).withClosedAt(System.currentTimeMillis()); thread.withTask(task).withUpdatedBy(user).withUpdatedAt(System.currentTimeMillis()); - dao.feedDAO().update(thread.getId().toString(), JsonUtils.pojoToJson(thread)); + dao.feedDAO().update(thread.getId(), JsonUtils.pojoToJson(thread)); addClosingPost(thread, user, closeTask.getComment()); sortPosts(thread); } @@ -394,7 +394,7 @@ public class FeedRepository { null)); } - public Thread addPostToThread(String id, Post post, String userName) { + public Thread addPostToThread(UUID id, Post post, String userName) { // Validate the user posting the message UUID fromUserId = Entity.getEntityReferenceByName(USER, post.getFrom(), NON_DELETED).getId(); @@ -417,8 +417,8 @@ public class FeedRepository { return thread; } - public Post getPostById(Thread thread, String postId) { - Optional post = thread.getPosts().stream().filter(p -> p.getId().equals(UUID.fromString(postId))).findAny(); + public Post getPostById(Thread thread, UUID postId) { + Optional post = thread.getPosts().stream().filter(p -> p.getId().equals(postId)).findAny(); if (post.isEmpty()) { throw EntityNotFoundException.byMessage(entityNotFound("Post", postId)); } @@ -435,22 +435,22 @@ public class FeedRepository { .withPosts(posts) .withPostsCount(posts.size()); // update the json document - dao.feedDAO().update(thread.getId().toString(), JsonUtils.pojoToJson(thread)); + dao.feedDAO().update(thread.getId(), JsonUtils.pojoToJson(thread)); return new DeleteResponse<>(post, RestUtil.ENTITY_DELETED); } public DeleteResponse deleteThread(Thread thread, String deletedByUser) { - deleteThreadInternal(thread.getId().toString()); + deleteThreadInternal(thread.getId()); LOG.info("{} deleted thread with id {}", deletedByUser, thread.getId()); return new DeleteResponse<>(thread, RestUtil.ENTITY_DELETED); } - public void deleteThreadInternal(String id) { + public void deleteThreadInternal(UUID id) { // Delete all the relationships to other entities dao.relationshipDAO().deleteAll(id, Entity.THREAD); // Delete all the field relationships to other entities - dao.fieldRelationshipDAO().deleteAllByPrefix(id); + dao.fieldRelationshipDAO().deleteAllByPrefix(id.toString()); // Finally, delete the thread dao.feedDAO().delete(id); @@ -460,7 +460,7 @@ public class FeedRepository { List threadIds = listOrEmpty(dao.feedDAO().findByEntityId(entityId.toString())); for (String threadId : threadIds) { try { - deleteThreadInternal(threadId); + deleteThreadInternal(UUID.fromString(threadId)); } catch (Exception ex) { // Continue deletion } @@ -487,7 +487,7 @@ public class FeedRepository { EntityReference reference = EntityUtil.validateEntityLink(entityLink); if (reference.getType().equals(USER) || reference.getType().equals(Entity.TEAM)) { if (reference.getType().equals(USER)) { - String userId = reference.getId().toString(); + UUID userId = reference.getId(); List teamIds = getTeamIds(userId); result = dao.feedDAO().listCountByOwner(userId, teamIds, filter.getCondition()); } else { @@ -519,12 +519,12 @@ public class FeedRepository { return new ThreadCount().withTotalCount(totalCount.get()).withCounts(entityLinkThreadCounts); } - public List listPosts(String threadId) { + public List listPosts(UUID threadId) { return get(threadId).getPosts(); } /** List threads based on the filters and limits in the order of the updated timestamp. */ - public ResultList list(FeedFilter filter, String link, int limitPosts, String userId, int limit) { + public ResultList list(FeedFilter filter, String link, int limitPosts, UUID userId, int limit) { int total; List threads; // No filters are enabled. Listing all the threads @@ -543,12 +543,12 @@ public class FeedRepository { // For a user entityLink get created or replied relationships to the thread if (reference.getType().equals(USER)) { - FilteredThreads filteredThreads = getThreadsByOwner(filter, reference.getId().toString(), limit + 1); + FilteredThreads filteredThreads = getThreadsByOwner(filter, reference.getId(), limit + 1); threads = filteredThreads.getThreads(); total = filteredThreads.getTotalCount(); } else { // Only data assets are added as about - User user = userId != null ? Entity.getEntity(USER, UUID.fromString(userId), "teams", NON_DELETED) : null; + User user = userId != null ? Entity.getEntity(USER, userId, "teams", NON_DELETED) : null; List teamNameHash = getTeamNames(user); String userName = user == null ? null : user.getFullyQualifiedName(); List jsons = @@ -650,7 +650,7 @@ public class FeedRepository { public final PatchResponse patchThread(UriInfo uriInfo, UUID id, String user, JsonPatch patch) { // Get all the fields in the original thread that can be updated during PATCH operation - Thread original = get(id.toString()); + Thread original = get(id); if (original.getTask() != null) { List assignees = original.getTask().getAssignees(); populateAssignees(original); @@ -727,8 +727,7 @@ public class FeedRepository { } // TODO fix this - overlapping announcements should be allowed List announcements = - dao.feedDAO() - .listAnnouncementBetween(thread.getId().toString(), thread.getEntityId().toString(), startTime, endTime); + dao.feedDAO().listAnnouncementBetween(thread.getId(), thread.getEntityId(), startTime, endTime); if (!announcements.isEmpty()) { // There is already an announcement that overlaps the new one throw new IllegalArgumentException(ANNOUNCEMENT_OVERLAP); @@ -757,7 +756,7 @@ public class FeedRepository { // if there is no change, there is no need to apply patch if (fieldsChanged(original, updated)) { populateUserReactions(updated.getReactions()); - dao.feedDAO().update(updated.getId().toString(), JsonUtils.pojoToJson(updated)); + dao.feedDAO().update(updated.getId(), JsonUtils.pojoToJson(updated)); return true; } return false; @@ -767,7 +766,7 @@ public class FeedRepository { // store the updated post // if there is no change, there is no need to apply patch if (fieldsChanged(originalPost, updatedPost)) { - dao.feedDAO().update(thread.getId().toString(), JsonUtils.pojoToJson(thread)); + dao.feedDAO().update(thread.getId(), JsonUtils.pojoToJson(thread)); return true; } return false; @@ -820,7 +819,7 @@ public class FeedRepository { } } - private String getUserTeamJsonMysql(String userId, List teamIds) { + private String getUserTeamJsonMysql(UUID userId, List teamIds) { // Build a string like this for the tasks filter // [{"id":"9e78b924-b75c-4141-9845-1b3eb81fdc1b","type":"team"},{"id":"fe21e1ba-ce00-49fa-8b62-3c9a6669a11b","type":"user"}] List result = new ArrayList<>(); @@ -830,7 +829,7 @@ public class FeedRepository { return result.toString(); } - private List getUserTeamJsonPostgres(String userId, List teamIds) { + private List getUserTeamJsonPostgres(UUID userId, List teamIds) { // Build a list of objects like this for the tasks filter // [{"id":"9e78b924-b75c-4141-9845-1b3eb81fdc1b","type":"team"}]','[{"id":"fe21e1ba-ce00-49fa-8b62-3c9a6669a11b","type":"user"}] List result = new ArrayList<>(); @@ -840,12 +839,16 @@ public class FeedRepository { return result; } + private JSONObject getUserTeamJson(UUID userId, String type) { + return new JSONObject().put("id", userId).put("type", type); + } + private JSONObject getUserTeamJson(String userId, String type) { return new JSONObject().put("id", userId).put("type", type); } /** Return the tasks assigned to the user. */ - private FilteredThreads getTasksAssignedTo(FeedFilter filter, String userId, int limit) { + private FilteredThreads getTasksAssignedTo(FeedFilter filter, UUID userId, int limit) { List teamIds = getTeamIds(userId); List userTeamJsonPostgres = getUserTeamJsonPostgres(userId, teamIds); String userTeamJsonMysql = getUserTeamJsonMysql(userId, teamIds); @@ -887,8 +890,8 @@ public class FeedRepository { } /** Return the tasks created by or assigned to the user. */ - private FilteredThreads getTasksOfUser(FeedFilter filter, String userId, int limit) { - String username = Entity.getEntityReferenceById(Entity.USER, UUID.fromString(userId), NON_DELETED).getName(); + private FilteredThreads getTasksOfUser(FeedFilter filter, UUID userId, int limit) { + String username = Entity.getEntityReferenceById(Entity.USER, userId, NON_DELETED).getName(); List teamIds = getTeamIds(userId); List userTeamJsonPostgres = getUserTeamJsonPostgres(userId, teamIds); String userTeamJsonMysql = getUserTeamJsonMysql(userId, teamIds); @@ -902,8 +905,8 @@ public class FeedRepository { } /** Return the tasks created by the user. */ - private FilteredThreads getTasksAssignedBy(FeedFilter filter, String userId, int limit) { - String username = Entity.getEntityReferenceById(Entity.USER, UUID.fromString(userId), NON_DELETED).getName(); + private FilteredThreads getTasksAssignedBy(FeedFilter filter, UUID userId, int limit) { + String username = Entity.getEntityReferenceById(Entity.USER, userId, NON_DELETED).getName(); List jsons = dao.feedDAO().listTasksAssigned(username, limit, filter.getCondition()); List threads = JsonUtils.readObjects(jsons, Thread.class); int totalCount = dao.feedDAO().listCountTasksAssignedBy(username, filter.getCondition(false)); @@ -914,7 +917,7 @@ public class FeedRepository { * Return the threads associated with user/team owned entities and the threads that were created by or replied to by * the user. */ - private FilteredThreads getThreadsByOwner(FeedFilter filter, String userId, int limit) { + private FilteredThreads getThreadsByOwner(FeedFilter filter, UUID userId, int limit) { // add threads on user or team owned entities // and threads created by or replied to by the user List teamIds = getTeamIds(userId); @@ -925,8 +928,8 @@ public class FeedRepository { } /** Returns the threads where the user or the team they belong to were mentioned by other users with @mention. */ - private FilteredThreads getThreadsByMentions(FeedFilter filter, String userId, int limit) { - User user = Entity.getEntity(Entity.USER, UUID.fromString(userId), "teams", NON_DELETED); + private FilteredThreads getThreadsByMentions(FeedFilter filter, UUID userId, int limit) { + User user = Entity.getEntity(Entity.USER, userId, "teams", NON_DELETED); String userNameHash = getUserNameHash(user); // Return the threads where the user or team was mentioned List teamNamesHash = getTeamNames(user); @@ -945,17 +948,17 @@ public class FeedRepository { } /** Get a list of team ids that the given user is a part of. */ - private List getTeamIds(String userId) { + private List getTeamIds(UUID userId) { List teamIds = null; if (userId != null) { - User user = Entity.getEntity(Entity.USER, UUID.fromString(userId), "teams", NON_DELETED); + User user = Entity.getEntity(Entity.USER, userId, "teams", NON_DELETED); teamIds = listOrEmpty(user.getTeams()).stream().map(ref -> ref.getId().toString()).collect(Collectors.toList()); } return nullOrEmpty(teamIds) ? List.of(StringUtils.EMPTY) : teamIds; } /** Returns the threads that are associated with the entities followed by the user. */ - private FilteredThreads getThreadsByFollows(FeedFilter filter, String userId, int limit) { + private FilteredThreads getThreadsByFollows(FeedFilter filter, UUID userId, int limit) { List teamIds = getTeamIds(userId); List jsons = dao.feedDAO() diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/LineageRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/LineageRepository.java index e659ac7eadc..9867ce4d040 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/LineageRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/LineageRepository.java @@ -126,12 +126,7 @@ public class LineageRepository { // Finally, delete lineage relationship return dao.relationshipDAO() - .delete( - from.getId().toString(), - from.getType(), - to.getId().toString(), - to.getType(), - Relationship.UPSTREAM.ordinal()) + .delete(from.getId(), from.getType(), to.getId(), to.getType(), Relationship.UPSTREAM.ordinal()) > 0; } @@ -158,9 +153,9 @@ public class LineageRepository { List records; // pipeline information is not maintained if (entityType.equals(Entity.PIPELINE) || entityType.equals(Entity.STORED_PROCEDURE)) { - records = dao.relationshipDAO().findFromPipleine(id.toString(), Relationship.UPSTREAM.ordinal()); + records = dao.relationshipDAO().findFromPipleine(id, Relationship.UPSTREAM.ordinal()); } else { - records = dao.relationshipDAO().findFrom(id.toString(), entityType, Relationship.UPSTREAM.ordinal()); + records = dao.relationshipDAO().findFrom(id, entityType, Relationship.UPSTREAM.ordinal()); } final List upstreamEntityReferences = new ArrayList<>(); for (EntityRelationshipRecord entityRelationshipRecord : records) { @@ -189,9 +184,9 @@ public class LineageRepository { } List records; if (entityType.equals(Entity.PIPELINE) || entityType.equals(Entity.STORED_PROCEDURE)) { - records = dao.relationshipDAO().findToPipeline(id.toString(), Relationship.UPSTREAM.ordinal()); + records = dao.relationshipDAO().findToPipeline(id, Relationship.UPSTREAM.ordinal()); } else { - records = dao.relationshipDAO().findTo(id.toString(), entityType, Relationship.UPSTREAM.ordinal()); + records = dao.relationshipDAO().findTo(id, entityType, Relationship.UPSTREAM.ordinal()); } final List downstreamEntityReferences = new ArrayList<>(); for (EntityRelationshipRecord entityRelationshipRecord : records) { diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/SearchIndexRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/SearchIndexRepository.java index 59090e4222d..07974c1dba0 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/SearchIndexRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/SearchIndexRepository.java @@ -24,10 +24,8 @@ import static org.openmetadata.service.Entity.SEARCH_SERVICE; import static org.openmetadata.service.util.EntityUtil.getSearchIndexField; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.UUID; import java.util.function.BiPredicate; import java.util.function.Function; @@ -152,7 +150,7 @@ public class SearchIndexRepository extends EntityRepository { SearchIndexSampleData sampleData = JsonUtils.readValue( - daoCollection.entityExtensionDAO().getExtension(searchIndex.getId().toString(), "searchIndex.sampleData"), + daoCollection.entityExtensionDAO().getExtension(searchIndex.getId(), "searchIndex.sampleData"), SearchIndexSampleData.class); searchIndex.setSampleData(sampleData); setFieldsInternal(searchIndex, Fields.EMPTY_FIELDS); @@ -173,11 +171,7 @@ public class SearchIndexRepository extends EntityRepository { daoCollection .entityExtensionDAO() - .insert( - searchIndexId.toString(), - "searchIndex.sampleData", - "searchIndexSampleData", - JsonUtils.pojoToJson(sampleData)); + .insert(searchIndexId, "searchIndex.sampleData", "searchIndexSampleData", JsonUtils.pojoToJson(sampleData)); setFieldsInternal(searchIndex, Fields.EMPTY_FIELDS); return searchIndex.withSampleData(sampleData); } @@ -371,17 +365,6 @@ public class SearchIndexRepository extends EntityRepository { return childrenSchemaField; } - public static Set getAllFieldTags(SearchIndexField field) { - Set tags = new HashSet<>(); - if (!listOrEmpty(field.getTags()).isEmpty()) { - tags.addAll(field.getTags()); - } - for (SearchIndexField c : listOrEmpty(field.getChildren())) { - tags.addAll(getAllFieldTags(c)); - } - return tags; - } - public class SearchIndexUpdater extends EntityUpdater { public static final String FIELD_DATA_TYPE_DISPLAY = "dataTypeDisplay"; diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TableRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TableRepository.java index 98bfa6d1820..bb60b3f6949 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TableRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TableRepository.java @@ -231,7 +231,7 @@ public class TableRepository extends EntityRepository
{ daoCollection .entityExtensionDAO() - .insert(tableId.toString(), TABLE_SAMPLE_DATA_EXTENSION, "tableData", JsonUtils.pojoToJson(tableData)); + .insert(tableId, TABLE_SAMPLE_DATA_EXTENSION, "tableData", JsonUtils.pojoToJson(tableData)); setFieldsInternal(table, Fields.EMPTY_FIELDS); return table.withSampleData(tableData); } @@ -242,7 +242,7 @@ public class TableRepository extends EntityRepository
{ TableData sampleData = JsonUtils.readValue( - daoCollection.entityExtensionDAO().getExtension(table.getId().toString(), TABLE_SAMPLE_DATA_EXTENSION), + daoCollection.entityExtensionDAO().getExtension(table.getId(), TABLE_SAMPLE_DATA_EXTENSION), TableData.class); table.setSampleData(sampleData); setFieldsInternal(table, Fields.EMPTY_FIELDS); @@ -261,20 +261,20 @@ public class TableRepository extends EntityRepository
{ // Validate the request content Table table = dao.findEntityById(tableId); - daoCollection.entityExtensionDAO().delete(tableId.toString(), TABLE_SAMPLE_DATA_EXTENSION); + daoCollection.entityExtensionDAO().delete(tableId, TABLE_SAMPLE_DATA_EXTENSION); setFieldsInternal(table, Fields.EMPTY_FIELDS); return table; } public TableProfilerConfig getTableProfilerConfig(Table table) { return JsonUtils.readValue( - daoCollection.entityExtensionDAO().getExtension(table.getId().toString(), TABLE_PROFILER_CONFIG_EXTENSION), + daoCollection.entityExtensionDAO().getExtension(table.getId(), TABLE_PROFILER_CONFIG_EXTENSION), TableProfilerConfig.class); } public TestSuite getTestSuite(Table table) { List entityRelationshipRecords = - daoCollection.relationshipDAO().findTo(table.getId().toString(), TABLE, Relationship.CONTAINS.ordinal()); + daoCollection.relationshipDAO().findTo(table.getId(), TABLE, Relationship.CONTAINS.ordinal()); Optional testSuiteRelationshipRecord = entityRelationshipRecords.stream() .filter(entityRelationshipRecord -> entityRelationshipRecord.getType().equals(Entity.TEST_SUITE)) @@ -310,10 +310,7 @@ public class TableRepository extends EntityRepository
{ daoCollection .entityExtensionDAO() .insert( - tableId.toString(), - TABLE_PROFILER_CONFIG_EXTENSION, - TABLE_PROFILER_CONFIG, - JsonUtils.pojoToJson(tableProfilerConfig)); + tableId, TABLE_PROFILER_CONFIG_EXTENSION, TABLE_PROFILER_CONFIG, JsonUtils.pojoToJson(tableProfilerConfig)); clearFields(table, Fields.EMPTY_FIELDS); return table.withTableProfilerConfig(tableProfilerConfig); } @@ -321,7 +318,7 @@ public class TableRepository extends EntityRepository
{ public Table deleteTableProfilerConfig(UUID tableId) { // Validate the request content Table table = dao.findEntityById(tableId); - daoCollection.entityExtensionDAO().delete(tableId.toString(), TABLE_PROFILER_CONFIG_EXTENSION); + daoCollection.entityExtensionDAO().delete(tableId, TABLE_PROFILER_CONFIG_EXTENSION); setFieldsInternal(table, Fields.EMPTY_FIELDS); return table; } @@ -515,7 +512,7 @@ public class TableRepository extends EntityRepository
{ String extension = TABLE_COLUMN_EXTENSION + columnName + CUSTOM_METRICS_EXTENSION; daoCollection .entityExtensionDAO() - .insert(table.getId().toString(), extension, "customMetric", JsonUtils.pojoToJson(updatedMetrics)); + .insert(table.getId(), extension, "customMetric", JsonUtils.pojoToJson(updatedMetrics)); setFieldsInternal(table, Fields.EMPTY_FIELDS); // return the newly created/updated custom metric only for (Column column : table.getColumns()) { @@ -550,7 +547,7 @@ public class TableRepository extends EntityRepository
{ String extension = TABLE_COLUMN_EXTENSION + columnName + CUSTOM_METRICS_EXTENSION; daoCollection .entityExtensionDAO() - .insert(table.getId().toString(), extension, "customMetric", JsonUtils.pojoToJson(updatedMetrics)); + .insert(table.getId(), extension, "customMetric", JsonUtils.pojoToJson(updatedMetrics)); // return the newly created/updated custom metric test only for (Column column : table.getColumns()) { if (column.getName().equals(columnName)) { @@ -986,7 +983,7 @@ public class TableRepository extends EntityRepository
{ private List getCustomMetrics(Table table, String columnName) { String extension = TABLE_COLUMN_EXTENSION + columnName + CUSTOM_METRICS_EXTENSION; return JsonUtils.readObjects( - daoCollection.entityExtensionDAO().getExtension(table.getId().toString(), extension), CustomMetric.class); + daoCollection.entityExtensionDAO().getExtension(table.getId(), extension), CustomMetric.class); } private void getCustomMetrics(boolean setMetrics, Table table) { diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TeamRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TeamRepository.java index 0bee2d5b99a..755207c8c9f 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TeamRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TeamRepository.java @@ -415,7 +415,7 @@ public class TeamRepository extends EntityRepository { protected List getChildren(UUID teamId) { if (teamId.equals(organization.getId())) { // For organization all the parentless teams are children - List children = daoCollection.teamDAO().listTeamsUnderOrganization(teamId.toString()); + List children = daoCollection.teamDAO().listTeamsUnderOrganization(teamId); return EntityUtil.populateEntityReferencesById(EntityUtil.strToIds(children), Entity.TEAM); } return findTo(teamId, TEAM, Relationship.PARENT_OF, TEAM); diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TestTransactionRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TestTransactionRepository.java index 9b56f727459..29a54c7d3af 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TestTransactionRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TestTransactionRepository.java @@ -39,7 +39,7 @@ public class TestTransactionRepository { public void updateUsageStatsWithTransaction(Table table, int count) { String today = RestUtil.DATE_FORMAT.format(new Date()); DailyCount dailyCount = new DailyCount().withCount(count).withDate(today); - dao.usageDAO().insertOrReplaceCount(dailyCount.getDate(), table.getId().toString(), "Table", dailyCount.getCount()); + dao.usageDAO().insertOrReplaceCount(dailyCount.getDate(), table.getId(), "Table", dailyCount.getCount()); } public void updateUsageStatsWithTransactionWithError(Table table, int count) { diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TokenRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TokenRepository.java index a4a0fe74ff1..4bf439ce0a3 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TokenRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TokenRepository.java @@ -1,6 +1,7 @@ package org.openmetadata.service.jdbi3; import java.util.List; +import java.util.UUID; import lombok.extern.slf4j.Slf4j; import org.openmetadata.schema.TokenInterface; import org.openmetadata.service.exception.EntityNotFoundException; @@ -23,7 +24,7 @@ public class TokenRepository { return result; } - public List findByUserIdAndType(String userId, String type) { + public List findByUserIdAndType(UUID userId, String type) { return dao.getTokenDAO().getAllUserTokenWithType(userId, type); } @@ -47,7 +48,7 @@ public class TokenRepository { } } - public void deleteTokenByUserAndType(String userId, String type) { + public void deleteTokenByUserAndType(UUID userId, String type) { try { dao.getTokenDAO().deleteTokenByUserAndType(userId, type); } catch (Exception ex) { diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TopicRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TopicRepository.java index 9911bd8460f..bdf6d828159 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TopicRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TopicRepository.java @@ -146,8 +146,7 @@ public class TopicRepository extends EntityRepository { TopicSampleData sampleData = JsonUtils.readValue( - daoCollection.entityExtensionDAO().getExtension(topic.getId().toString(), "topic.sampleData"), - TopicSampleData.class); + daoCollection.entityExtensionDAO().getExtension(topic.getId(), "topic.sampleData"), TopicSampleData.class); topic.setSampleData(sampleData); setFieldsInternal(topic, Fields.EMPTY_FIELDS); @@ -167,7 +166,7 @@ public class TopicRepository extends EntityRepository { daoCollection .entityExtensionDAO() - .insert(topicId.toString(), "topic.sampleData", "topicSampleData", JsonUtils.pojoToJson(sampleData)); + .insert(topicId, "topic.sampleData", "topicSampleData", JsonUtils.pojoToJson(sampleData)); setFieldsInternal(topic, Fields.EMPTY_FIELDS); return topic.withSampleData(sampleData); } diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/UsageRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/UsageRepository.java index 77baaf334da..92e26f31842 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/UsageRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/UsageRepository.java @@ -57,45 +57,45 @@ public class UsageRepository { this.dao = dao; } - public EntityUsage get(String entityType, String id, String date, int days) { - EntityReference ref = Entity.getEntityReferenceById(entityType, UUID.fromString(id), Include.NON_DELETED); + public EntityUsage get(String entityType, UUID id, String date, int days) { + EntityReference ref = Entity.getEntityReferenceById(entityType, id, Include.NON_DELETED); List usageDetails = dao.usageDAO().getUsageById(id, date, days - 1); return new EntityUsage().withUsage(usageDetails).withEntity(ref); } 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); + List usageDetails = dao.usageDAO().getUsageById(ref.getId(), date, days - 1); return new EntityUsage().withUsage(usageDetails).withEntity(ref); } - public RestUtil.PutResponse create(String entityType, String id, DailyCount usage) { + public RestUtil.PutResponse create(String entityType, UUID id, DailyCount usage) { // Validate data entity for which usage is being collected - Entity.getEntityReferenceById(entityType, UUID.fromString(id), Include.NON_DELETED); + Entity.getEntityReferenceById(entityType, id, Include.NON_DELETED); return addUsage(POST, entityType, id, usage); } public RestUtil.PutResponse createByName(String entityType, String fullyQualifiedName, DailyCount usage) { EntityReference ref = Entity.getEntityReferenceByName(entityType, fullyQualifiedName, Include.NON_DELETED); - return addUsage(POST, entityType, ref.getId().toString(), usage); + return addUsage(POST, entityType, ref.getId(), usage); } public RestUtil.PutResponse createOrUpdate(String entityType, UUID id, DailyCount usage) { // Validate data entity for which usage is being collected Entity.getEntityReferenceById(entityType, id, Include.NON_DELETED); - return addUsage(PUT, entityType, id.toString(), usage); + return addUsage(PUT, entityType, id, usage); } public RestUtil.PutResponse createOrUpdateByName(String entityType, String fullyQualifiedName, DailyCount usage) { EntityReference ref = Entity.getEntityReferenceByName(entityType, fullyQualifiedName, Include.NON_DELETED); - return addUsage(PUT, entityType, ref.getId().toString(), usage); + return addUsage(PUT, entityType, ref.getId(), usage); } public void computePercentile(String entityType, String date) { dao.usageDAO().computePercentile(entityType, date); } - private RestUtil.PutResponse addUsage(String method, String entityType, String entityId, DailyCount usage) { + private RestUtil.PutResponse addUsage(String method, String entityType, UUID entityId, DailyCount usage) { String fields = "usageSummary"; // If table usage was reported, add the usage count to schema and database String type = entityType.toLowerCase(); @@ -115,18 +115,16 @@ public class UsageRepository { } private RestUtil.PutResponse tableEntityUsage( - String method, String fields, String entityId, String entityType, DailyCount usage) { + String method, String fields, UUID entityId, String entityType, DailyCount usage) { // we accept usage for deleted entities - Table table = Entity.getEntity(Entity.TABLE, UUID.fromString(entityId), fields, Include.ALL); + Table table = Entity.getEntity(Entity.TABLE, entityId, fields, Include.ALL); // Insert usage record insertToUsageRepository(method, entityId, entityType, usage); - Table updated = Entity.getEntity(Entity.TABLE, UUID.fromString(entityId), fields, Include.ALL); + Table updated = Entity.getEntity(Entity.TABLE, entityId, fields, Include.ALL); dao.usageDAO() .insertOrUpdateCount( - usage.getDate(), table.getDatabaseSchema().getId().toString(), Entity.DATABASE_SCHEMA, usage.getCount()); - dao.usageDAO() - .insertOrUpdateCount( - usage.getDate(), table.getDatabase().getId().toString(), Entity.DATABASE, usage.getCount()); + usage.getDate(), table.getDatabaseSchema().getId(), Entity.DATABASE_SCHEMA, usage.getCount()); + dao.usageDAO().insertOrUpdateCount(usage.getDate(), table.getDatabase().getId(), Entity.DATABASE, usage.getCount()); ChangeDescription change = getChangeDescription(table.getVersion(), updated.getUsageSummary(), table.getUsageSummary()); @@ -136,10 +134,10 @@ public class UsageRepository { } private RestUtil.PutResponse dashboardEntityUsage( - String method, String fields, String entityId, String entityType, DailyCount usage) { - Dashboard dashboard = Entity.getEntity(Entity.DASHBOARD, UUID.fromString(entityId), fields, Include.ALL); + String method, String fields, UUID entityId, String entityType, DailyCount usage) { + Dashboard dashboard = Entity.getEntity(Entity.DASHBOARD, entityId, fields, Include.ALL); insertToUsageRepository(method, entityId, entityType, usage); - Dashboard updated = Entity.getEntity(Entity.DASHBOARD, UUID.fromString(entityId), fields, Include.ALL); + Dashboard updated = Entity.getEntity(Entity.DASHBOARD, entityId, fields, Include.ALL); ChangeDescription change = getChangeDescription(dashboard.getVersion(), updated.getUsageSummary(), dashboard.getUsageSummary()); @@ -149,10 +147,10 @@ public class UsageRepository { } private RestUtil.PutResponse chartEntityUsage( - String method, String fields, String entityId, String entityType, DailyCount usage) { - Chart chart = Entity.getEntity(Entity.CHART, UUID.fromString(entityId), fields, Include.ALL); + String method, String fields, UUID entityId, String entityType, DailyCount usage) { + Chart chart = Entity.getEntity(Entity.CHART, entityId, fields, Include.ALL); insertToUsageRepository(method, entityId, entityType, usage); - Chart updated = Entity.getEntity(Entity.CHART, UUID.fromString(entityId), fields, Include.ALL); + Chart updated = Entity.getEntity(Entity.CHART, entityId, fields, Include.ALL); ChangeDescription change = getChangeDescription(chart.getVersion(), updated.getUsageSummary(), chart.getUsageSummary()); @@ -162,10 +160,10 @@ public class UsageRepository { } private RestUtil.PutResponse mlModelEntityUsage( - String method, String fields, String entityId, String entityType, DailyCount usage) { - MlModel mlModel = Entity.getEntity(Entity.MLMODEL, UUID.fromString(entityId), fields, Include.ALL); + String method, String fields, UUID entityId, String entityType, DailyCount usage) { + MlModel mlModel = Entity.getEntity(Entity.MLMODEL, entityId, fields, Include.ALL); insertToUsageRepository(method, entityId, entityType, usage); - MlModel updated = Entity.getEntity(Entity.CHART, UUID.fromString(entityId), fields, Include.ALL); + MlModel updated = Entity.getEntity(Entity.CHART, entityId, fields, Include.ALL); ChangeDescription change = getChangeDescription(mlModel.getVersion(), updated.getUsageSummary(), mlModel.getUsageSummary()); @@ -174,7 +172,7 @@ public class UsageRepository { return new RestUtil.PutResponse<>(Response.Status.CREATED, changeEvent, RestUtil.ENTITY_FIELDS_CHANGED); } - private void insertToUsageRepository(String method, String entityId, String entityType, DailyCount usage) { + private void insertToUsageRepository(String method, UUID entityId, String entityType, DailyCount usage) { if (method.equals(POST)) { dao.usageDAO().insertOrReplaceCount(usage.getDate(), entityId, entityType, usage.getCount()); } else if (method.equals(PUT)) { diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/UserRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/UserRepository.java index 0e566fe74b9..5622146b202 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/UserRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/UserRepository.java @@ -262,13 +262,13 @@ public class UserRepository extends EntityRepository { private List getOwns(User user) { // Compile entities owned by the user List ownedEntities = - daoCollection.relationshipDAO().findTo(user.getId().toString(), USER, Relationship.OWNS.ordinal()); + daoCollection.relationshipDAO().findTo(user.getId(), USER, Relationship.OWNS.ordinal()); // Compile entities owned by the team the user belongs to List teams = user.getTeams() == null ? getTeams(user) : user.getTeams(); for (EntityReference team : teams) { ownedEntities.addAll( - daoCollection.relationshipDAO().findTo(team.getId().toString(), Entity.TEAM, Relationship.OWNS.ordinal())); + daoCollection.relationshipDAO().findTo(team.getId(), Entity.TEAM, Relationship.OWNS.ordinal())); } // Populate details in entity reference return EntityUtil.getEntityReferences(ownedEntities); @@ -280,7 +280,7 @@ public class UserRepository extends EntityRepository { private List getTeamChildren(UUID teamId) { if (teamId.equals(organization.getId())) { // For organization all the parentless teams are children - List children = daoCollection.teamDAO().listTeamsUnderOrganization(teamId.toString()); + List children = daoCollection.teamDAO().listTeamsUnderOrganization(teamId); return EntityUtil.populateEntityReferencesById(EntityUtil.strToIds(children), Entity.TEAM); } return findTo(teamId, TEAM, Relationship.PARENT_OF, TEAM); diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/migration/utils/v110/MigrationUtil.java b/openmetadata-service/src/main/java/org/openmetadata/service/migration/utils/v110/MigrationUtil.java index 746d3214d3a..41e7ec95cd2 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/migration/utils/v110/MigrationUtil.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/migration/utils/v110/MigrationUtil.java @@ -537,12 +537,12 @@ public class MigrationUtil { List ingestionPipelineRecords = collectionDAO .relationshipDAO() - .findTo(testSuite.getId().toString(), TEST_SUITE, Relationship.CONTAINS.ordinal(), INGESTION_PIPELINE); + .findTo(testSuite.getId(), TEST_SUITE, Relationship.CONTAINS.ordinal(), INGESTION_PIPELINE); for (CollectionDAO.EntityRelationshipRecord ingestionRecord : ingestionPipelineRecords) { // remove relationship - collectionDAO.relationshipDAO().deleteAll(ingestionRecord.getId().toString(), INGESTION_PIPELINE); + collectionDAO.relationshipDAO().deleteAll(ingestionRecord.getId(), INGESTION_PIPELINE); // Cannot use Delete directly it uses other repos internally - ingestionPipelineRepository.getDao().delete(ingestionRecord.getId().toString()); + ingestionPipelineRepository.getDao().delete(ingestionRecord.getId()); } } } diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/migration/utils/v111/MigrationUtilV111.java b/openmetadata-service/src/main/java/org/openmetadata/service/migration/utils/v111/MigrationUtilV111.java index 0291e986e3c..5eb3f5a102d 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/migration/utils/v111/MigrationUtilV111.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/migration/utils/v111/MigrationUtilV111.java @@ -4,7 +4,6 @@ import static org.openmetadata.service.Entity.INGESTION_PIPELINE; import static org.openmetadata.service.Entity.TEST_CASE; import static org.openmetadata.service.Entity.TEST_SUITE; -import java.io.IOException; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -40,15 +39,16 @@ public class MigrationUtilV111 { } resultMap.forEach( (k, v) -> { + UUID id = UUID.fromString(k); // Get all the relationship of id1 List records = - collectionDAO.relationshipDAO().findTo(k, TEST_SUITE, Relationship.CONTAINS.ordinal(), TEST_CASE); + collectionDAO.relationshipDAO().findTo(id, TEST_SUITE, Relationship.CONTAINS.ordinal(), TEST_CASE); List ingestionRecords = collectionDAO .relationshipDAO() - .findTo(k, TEST_SUITE, Relationship.CONTAINS.ordinal(), INGESTION_PIPELINE); + .findTo(id, TEST_SUITE, Relationship.CONTAINS.ordinal(), INGESTION_PIPELINE); for (CollectionDAO.EntityRelationshipRecord record : records) { UUID toId = record.getId(); @@ -60,16 +60,16 @@ public class MigrationUtilV111 { // Delete Test Suite try { - collectionDAO.testSuiteDAO().delete(k); + collectionDAO.testSuiteDAO().delete(id); // Delete Relationship - collectionDAO.relationshipDAO().deleteAllWithId(k); + collectionDAO.relationshipDAO().deleteAllWithId(id); } catch (Exception ex) { // maybe already deleted } for (CollectionDAO.EntityRelationshipRecord record : ingestionRecords) { try { - String toId = record.getId().toString(); + UUID toId = record.getId(); collectionDAO.ingestionPipelineDAO().delete(toId); collectionDAO.relationshipDAO().deleteAllWithId(toId); } catch (Exception ex) { @@ -80,8 +80,7 @@ public class MigrationUtilV111 { } public static void runTestSuiteMigration( - CollectionDAO collectionDAO, Handle handle, String getSql, String updateSql, String resultListSql) - throws IOException { + CollectionDAO collectionDAO, Handle handle, String getSql, String updateSql, String resultListSql) { List> resultList = handle.createQuery(resultListSql).mapToMap().list(); for (Map row : resultList) { if (row.containsKey("json")) { @@ -106,9 +105,9 @@ public class MigrationUtilV111 { removeDuplicateTestCases(collectionDAO, handle, getSql); } catch (Exception ex) { try { - collectionDAO.testSuiteDAO().delete(suite.getId().toString()); + collectionDAO.testSuiteDAO().delete(suite.getId()); // Delete Relationship - collectionDAO.relationshipDAO().deleteAllWithId(suite.getId().toString()); + collectionDAO.relationshipDAO().deleteAllWithId(suite.getId()); } catch (Exception ex1) { // Ignore } diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/resources/feeds/FeedResource.java b/openmetadata-service/src/main/java/org/openmetadata/service/resources/feeds/FeedResource.java index 3e1c21b6f65..235732de467 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/resources/feeds/FeedResource.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/resources/feeds/FeedResource.java @@ -201,8 +201,7 @@ public class FeedResource { .after(after) .build(); - String userIdStr = userId != null ? userId.toString() : null; - ResultList threads = dao.list(filter, entityLink, limitPosts, userIdStr, limitParam); + ResultList threads = dao.list(filter, entityLink, limitPosts, userId, limitParam); addHref(uriInfo, threads.getData()); return threads; } @@ -222,7 +221,7 @@ public class FeedResource { }) public Thread get( @Context UriInfo uriInfo, - @Parameter(description = "Id of the Thread", schema = @Schema(type = "string")) @PathParam("id") String id, + @Parameter(description = "Id of the Thread", schema = @Schema(type = "string")) @PathParam("id") UUID id, @Parameter(description = "Type of the Entity", schema = @Schema(type = "string")) @PathParam("entityType") String entityType) { return addHref(uriInfo, dao.get(id)); @@ -393,7 +392,7 @@ public class FeedResource { public Response addPost( @Context SecurityContext securityContext, @Context UriInfo uriInfo, - @Parameter(description = "Id of the thread", schema = @Schema(type = "string")) @PathParam("id") String id, + @Parameter(description = "Id of the thread", schema = @Schema(type = "string")) @PathParam("id") UUID id, @Valid CreatePost createPost) throws IOException { Post post = getPost(createPost); @@ -417,8 +416,8 @@ public class FeedResource { @Context SecurityContext securityContext, @Context UriInfo uriInfo, @Parameter(description = "Id of the thread", schema = @Schema(type = "string")) @PathParam("threadId") - String threadId, - @Parameter(description = "Id of the post", schema = @Schema(type = "string")) @PathParam("postId") String postId, + UUID threadId, + @Parameter(description = "Id of the post", schema = @Schema(type = "string")) @PathParam("postId") UUID postId, @RequestBody( description = "JsonPatch with array of operations", content = @@ -451,7 +450,7 @@ public class FeedResource { @Context SecurityContext securityContext, @Parameter(description = "ThreadId of the thread to be deleted", schema = @Schema(type = "string")) @PathParam("threadId") - String threadId) { + UUID threadId) { // validate and get the thread Thread thread = dao.get(threadId); // delete thread only if the admin/bot/author tries to delete it @@ -476,10 +475,10 @@ public class FeedResource { @Context SecurityContext securityContext, @Parameter(description = "ThreadId of the post to be deleted", schema = @Schema(type = "string")) @PathParam("threadId") - String threadId, + UUID threadId, @Parameter(description = "PostId of the post to be deleted", schema = @Schema(type = "string")) @PathParam("postId") - String postId) + UUID postId) throws IOException { // validate and get thread & post Thread thread = dao.get(threadId); @@ -506,7 +505,7 @@ public class FeedResource { }) public ResultList getPosts( @Context UriInfo uriInfo, - @Parameter(description = "Id of the thread", schema = @Schema(type = "string")) @PathParam("id") String id) { + @Parameter(description = "Id of the thread", schema = @Schema(type = "string")) @PathParam("id") UUID id) { return new ResultList<>(dao.listPosts(id)); } diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/resources/teams/UserResource.java b/openmetadata-service/src/main/java/org/openmetadata/service/resources/teams/UserResource.java index b0406fa3351..f4dadf0a5f4 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/resources/teams/UserResource.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/resources/teams/UserResource.java @@ -1056,7 +1056,7 @@ public class UserResource extends EntityResource { } User user = repository.getByName(null, userName, getFields("id"), Include.NON_DELETED, true); List tokens = - tokenRepository.findByUserIdAndType(user.getId().toString(), TokenType.PERSONAL_ACCESS_TOKEN.value()); + tokenRepository.findByUserIdAndType(user.getId(), TokenType.PERSONAL_ACCESS_TOKEN.value()); return Response.status(Response.Status.OK).entity(new ResultList<>(tokens)).build(); } @@ -1093,14 +1093,14 @@ public class UserResource extends EntityResource { } User user = repository.getByName(null, userName, getFields("id"), Include.NON_DELETED, false); if (removeAll) { - tokenRepository.deleteTokenByUserAndType(user.getId().toString(), TokenType.PERSONAL_ACCESS_TOKEN.value()); + tokenRepository.deleteTokenByUserAndType(user.getId(), TokenType.PERSONAL_ACCESS_TOKEN.value()); } else { List ids = request.getTokenIds().stream().map(UUID::toString).collect(Collectors.toList()); tokenRepository.deleteAllToken(ids); } UserTokenCache.invalidateToken(user.getName()); List tokens = - tokenRepository.findByUserIdAndType(user.getId().toString(), TokenType.PERSONAL_ACCESS_TOKEN.value()); + tokenRepository.findByUserIdAndType(user.getId(), TokenType.PERSONAL_ACCESS_TOKEN.value()); return Response.status(Response.Status.OK).entity(new ResultList<>(tokens)).build(); } diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/resources/usage/UsageResource.java b/openmetadata-service/src/main/java/org/openmetadata/service/resources/usage/UsageResource.java index 2d75d6324dd..6247c114c6a 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/resources/usage/UsageResource.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/resources/usage/UsageResource.java @@ -89,7 +89,7 @@ public class UsageResource { @PathParam("entity") String entity, @Parameter(description = "Entity id", required = true, schema = @Schema(type = "string")) @PathParam("id") - String id, + UUID id, @Parameter( description = "Usage for number of days going back from the given date " + "(default=1, min=1, max=30)") @QueryParam("days") @@ -178,7 +178,7 @@ public class UsageResource { @PathParam("entity") String entity, @Parameter(description = "Entity id", required = true, schema = @Schema(type = "string")) @PathParam("id") - String id, + UUID id, @Parameter(description = "Usage information a given date") @Valid DailyCount usage) { OperationContext operationContext = new OperationContext(entity, MetadataOperation.EDIT_USAGE); ResourceContext resourceContext = new ResourceContext(entity); diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/security/auth/BasicAuthenticator.java b/openmetadata-service/src/main/java/org/openmetadata/service/security/auth/BasicAuthenticator.java index 2419a185e59..39742298d08 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/security/auth/BasicAuthenticator.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/security/auth/BasicAuthenticator.java @@ -145,12 +145,12 @@ public class BasicAuthenticator implements AuthenticatorHandler { userRepository.createOrUpdate(uriInfo, registeredUser); // deleting the entry for the token from the Database - tokenRepository.deleteTokenByUserAndType(registeredUser.getId().toString(), EMAIL_VERIFICATION.toString()); + tokenRepository.deleteTokenByUserAndType(registeredUser.getId(), EMAIL_VERIFICATION.toString()); } @Override public void resendRegistrationToken(UriInfo uriInfo, User registeredUser) throws IOException { - tokenRepository.deleteTokenByUserAndType(registeredUser.getId().toString(), EMAIL_VERIFICATION.toString()); + tokenRepository.deleteTokenByUserAndType(registeredUser.getId(), EMAIL_VERIFICATION.toString()); sendEmailVerification(uriInfo, registeredUser); } @@ -193,7 +193,7 @@ public class BasicAuthenticator implements AuthenticatorHandler { throw new CustomExceptionMessage(424, EMAIL_SENDING_ISSUE); } // don't persist tokens delete existing - tokenRepository.deleteTokenByUserAndType(user.getId().toString(), PASSWORD_RESET.toString()); + tokenRepository.deleteTokenByUserAndType(user.getId(), PASSWORD_RESET.toString()); tokenRepository.insertToken(resetToken); } @@ -225,7 +225,7 @@ public class BasicAuthenticator implements AuthenticatorHandler { userRepository.createOrUpdate(uriInfo, storedUser); // delete the user's all password reset token as well , since already updated - tokenRepository.deleteTokenByUserAndType(storedUser.getId().toString(), PASSWORD_RESET.toString()); + tokenRepository.deleteTokenByUserAndType(storedUser.getId(), PASSWORD_RESET.toString()); // Update user about Password Change try { diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/security/auth/LdapAuthenticator.java b/openmetadata-service/src/main/java/org/openmetadata/service/security/auth/LdapAuthenticator.java index 1ff204a3e91..957bbdc0be6 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/security/auth/LdapAuthenticator.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/security/auth/LdapAuthenticator.java @@ -225,7 +225,7 @@ public class LdapAuthenticator implements AuthenticatorHandler { @Override public RefreshToken createRefreshTokenForLogin(UUID currentUserId) { // just delete the existing token - tokenRepository.deleteTokenByUserAndType(currentUserId.toString(), REFRESH_TOKEN.toString()); + tokenRepository.deleteTokenByUserAndType(currentUserId, REFRESH_TOKEN.toString()); RefreshToken newRefreshToken = TokenUtil.getRefreshToken(currentUserId, UUID.randomUUID()); // save Refresh Token in Database tokenRepository.insertToken(newRefreshToken); diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/security/auth/UserTokenCache.java b/openmetadata-service/src/main/java/org/openmetadata/service/security/auth/UserTokenCache.java index 045c9a98b85..411cc757bb7 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/security/auth/UserTokenCache.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/security/auth/UserTokenCache.java @@ -72,7 +72,7 @@ public class UserTokenCache { userRepository.getByName( null, userName, new Fields(Set.of(UserResource.USER_PROTECTED_FIELDS)), NON_DELETED, true); List tokens = - tokenRepository.findByUserIdAndType(user.getId().toString(), TokenType.PERSONAL_ACCESS_TOKEN.value()); + tokenRepository.findByUserIdAndType(user.getId(), TokenType.PERSONAL_ACCESS_TOKEN.value()); tokens.forEach(t -> result.add(((PersonalAccessToken) t).getJwtToken())); return result; } diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/util/EntityUtil.java b/openmetadata-service/src/main/java/org/openmetadata/service/util/EntityUtil.java index b9b1b17fd18..076c748d861 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/util/EntityUtil.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/util/EntityUtil.java @@ -134,13 +134,14 @@ public final class EntityUtil { private EntityUtil() {} /** Validate that JSON payload can be turned into POJO object */ - public static T validate(String identity, String json, Class clz) throws WebApplicationException { + public static T validate(Object id, String json, Class clz) throws WebApplicationException { T entity = null; if (json != null) { entity = JsonUtils.readValue(json, clz); } if (entity == null) { - throw EntityNotFoundException.byMessage(CatalogExceptionMessage.entityNotFound(clz.getSimpleName(), identity)); + throw EntityNotFoundException.byMessage( + CatalogExceptionMessage.entityNotFound(clz.getSimpleName(), id.toString())); } return entity; } diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/util/NotificationHandler.java b/openmetadata-service/src/main/java/org/openmetadata/service/util/NotificationHandler.java index 7c2e3a42528..b91dc879c70 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/util/NotificationHandler.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/util/NotificationHandler.java @@ -99,9 +99,7 @@ public class NotificationHandler { } else if (Entity.TEAM.equals(e.getType())) { // fetch all that are there in the team List records = - collectionDAO - .relationshipDAO() - .findTo(e.getId().toString(), TEAM, Relationship.HAS.ordinal(), Entity.USER); + collectionDAO.relationshipDAO().findTo(e.getId(), TEAM, Relationship.HAS.ordinal(), Entity.USER); records.forEach(eRecord -> receiversList.add(eRecord.getId())); } }); @@ -148,7 +146,7 @@ public class NotificationHandler { Team team = collectionDAO.teamDAO().findEntityByName(fqn); // fetch all that are there in the team List records = - collectionDAO.relationshipDAO().findTo(team.getId().toString(), TEAM, Relationship.HAS.ordinal(), USER); + collectionDAO.relationshipDAO().findTo(team.getId(), TEAM, Relationship.HAS.ordinal(), USER); // Notify on WebSocket for Realtime WebSocketManager.getInstance().sendToManyWithString(records, WebSocketManager.MENTION_CHANNEL, jsonThread); } diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/util/SubscriptionUtil.java b/openmetadata-service/src/main/java/org/openmetadata/service/util/SubscriptionUtil.java index 2da2166ef19..56565be4a02 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/util/SubscriptionUtil.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/util/SubscriptionUtil.java @@ -106,7 +106,7 @@ public class SubscriptionUtil { Set data = new HashSet<>(); try { List ownerOrFollowers = - daoCollection.relationshipDAO().findFrom(entityId.toString(), entityType, relationship.ordinal()); + daoCollection.relationshipDAO().findFrom(entityId, entityType, relationship.ordinal()); ownerOrFollowers.forEach( owner -> { if (type == CreateEventSubscription.SubscriptionType.EMAIL diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/util/jdbi/BindUUID.java b/openmetadata-service/src/main/java/org/openmetadata/service/util/jdbi/BindUUID.java new file mode 100644 index 00000000000..eaef394f59b --- /dev/null +++ b/openmetadata-service/src/main/java/org/openmetadata/service/util/jdbi/BindUUID.java @@ -0,0 +1,34 @@ +package org.openmetadata.service.util.jdbi; + +import java.lang.annotation.Annotation; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; +import java.lang.reflect.Type; +import java.util.UUID; +import org.jdbi.v3.sqlobject.customizer.SqlStatementCustomizerFactory; +import org.jdbi.v3.sqlobject.customizer.SqlStatementCustomizingAnnotation; +import org.jdbi.v3.sqlobject.customizer.SqlStatementParameterCustomizer; + +/** Convert fqn string to fqnHash */ +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.PARAMETER}) +@SqlStatementCustomizingAnnotation(BindUUID.Factory.class) +public @interface BindUUID { + String value(); + + class Factory implements SqlStatementCustomizerFactory { + @Override + public SqlStatementParameterCustomizer createForParameter( + Annotation annotation, Class sqlObjectType, Method method, Parameter param, int index, Type type) { + BindUUID bind = (BindUUID) annotation; + return (stmt, arg) -> { + UUID id = (UUID) arg; + stmt.bind(bind.value(), id.toString()); + }; + } + } +}