Add BindUUID JDBI support to directly pass UUID to queries (#13315)

This commit is contained in:
Suresh Srinivas 2023-09-22 12:21:22 -07:00 committed by GitHub
parent 880907f8c8
commit eb865a997d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 242 additions and 230 deletions

View File

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

View File

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

View File

@ -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<ExtensionRecord> getExtensions(@Bind("id") String id, @Bind("extensionPrefix") String extensionPrefix);
List<ExtensionRecord> 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<UUID> 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<EntityRelationshipRecord> findTo(
@Bind("fromId") String fromId,
@BindUUID("fromId") UUID fromId,
@Bind("fromEntity") String fromEntity,
@BindList("relation") List<Integer> relation);
default List<EntityRelationshipRecord> findTo(String fromId, String fromEntity, int relation) {
default List<EntityRelationshipRecord> 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<EntityRelationshipRecord> 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<EntityRelationshipRecord> findToPipeline(@Bind("fromId") String fromId, @Bind("relation") int relation);
List<EntityRelationshipRecord> 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<EntityRelationshipRecord> 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<EntityRelationshipRecord> 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<EntityRelationshipRecord> findFromPipleine(@Bind("toId") String toId, @Bind("relation") int relation);
List<EntityRelationshipRecord> 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<EntityRelationshipRecord> {
@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<String> 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<String> 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<String> listThreadsByOwner(
@Bind("userId") String userId,
@BindUUID("userId") UUID userId,
@BindList("teamIds") List<String> teamIds,
@Bind("limit") int limit,
@Define("condition") String condition);
@ -1045,7 +1042,7 @@ public interface CollectionDAO {
+ "(fromEntity='team' AND fromId IN (<teamIds>))) 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<String> 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<List<String>> listCountByOwner(
@Bind("userId") String userId,
@BindUUID("userId") UUID userId,
@BindList("teamIds") List<String> teamIds,
@Define("condition") String condition);
@ -1164,7 +1161,7 @@ public interface CollectionDAO {
+ "ORDER BY createdAt DESC "
+ "LIMIT :limit")
List<String> listThreadsByFollows(
@Bind("userId") String userId,
@BindUUID("userId") UUID userId,
@BindList("teamIds") List<String> 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 (<teamIds>))) AND relation= :relation)")
int listCountThreadsByFollows(
@Bind("userId") String userId,
@BindUUID("userId") UUID userId,
@BindList("teamIds") List<String> 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<String> listTeamsUnderOrganization(String teamId) {
default List<String> 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<String> listTeamsUnderOrganization(@Bind("teamId") String teamId, @Bind("relation") int relation);
List<String> listTeamsUnderOrganization(@BindUUID("teamId") UUID teamId, @Bind("relation") int relation);
}
interface TopicDAO extends EntityDAO<Topic> {
@ -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<UsageDetails> getUsageById(@Bind("id") String id, @Bind("date") String date, @Bind("days") int days);
List<UsageDetails> 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<TokenInterface> getAllUserTokenWithType(@Bind("userId") String userId, @Bind("tokenType") String tokenType)
List<TokenInterface> 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<String> 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<Kpi> {

View File

@ -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<T extends EntityInterface> {
org.slf4j.Logger LOG = org.slf4j.LoggerFactory.getLogger(EntityDAO.class);
@ -247,7 +248,7 @@ public interface EntityDAO<T extends EntityInterface> {
@BindFQN("fqnHash") String fqnHash);
@SqlUpdate("DELETE FROM <table> 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<T extends EntityInterface> {
}
}
default int delete(String id) {
default int delete(UUID id) {
int rowsDeleted = delete(getTableName(), id);
if (rowsDeleted <= 0) {
String entityType = Entity.getEntityTypeFromClass(getEntityClass());

View File

@ -598,7 +598,7 @@ public abstract class EntityRepository<T extends EntityInterface> {
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<T extends EntityInterface> {
public EntityHistory listVersions(UUID id) {
T latest = setFieldsInternal(dao.findEntityById(id, ALL), putFields);
String extensionPrefix = EntityUtil.getVersionExtensionPrefix(entityType);
List<ExtensionRecord> records = daoCollection.entityExtensionDAO().getExtensions(id.toString(), extensionPrefix);
List<ExtensionRecord> records = daoCollection.entityExtensionDAO().getExtensions(id, extensionPrefix);
List<EntityVersionPair> oldVersions = new ArrayList<>();
records.forEach(r -> oldVersions.add(new EntityVersionPair(r)));
oldVersions.sort(EntityUtil.compareVersion.reversed());
@ -901,8 +901,7 @@ public abstract class EntityRepository<T extends EntityInterface> {
List<EntityRelationshipRecord> 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<T extends EntityInterface> {
}
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<T extends EntityInterface> {
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<T extends EntityInterface> {
return null;
}
String fieldFQNPrefix = TypeRegistry.getCustomPropertyFQNPrefix(entityType);
List<ExtensionRecord> records =
daoCollection.entityExtensionDAO().getExtensions(entity.getId().toString(), fieldFQNPrefix);
List<ExtensionRecord> records = daoCollection.entityExtensionDAO().getExtensions(entity.getId(), fieldFQNPrefix);
if (records.isEmpty()) {
return null;
}
@ -1276,7 +1274,7 @@ public abstract class EntityRepository<T extends EntityInterface> {
public PutResponse<T> restoreEntity(String updatedBy, String entityType, UUID id) {
// If an entity being restored contains other **deleted** children entities, restore them
List<EntityRelationshipRecord> 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<T extends EntityInterface> {
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<T extends EntityInterface> {
public EntityReference getFromEntityRef(
UUID toId, Relationship relationship, String fromEntityType, boolean mustHaveRelationship) {
List<EntityRelationshipRecord> 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<T extends EntityInterface> {
public EntityReference getToEntityRef(
UUID fromId, Relationship relationship, String toEntityType, boolean mustHaveRelationship) {
List<EntityRelationshipRecord> 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<EntityRelationshipRecord> 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<T extends EntityInterface> {
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<EntityReference> entityReferences) {
@ -2212,7 +2210,7 @@ public abstract class EntityRepository<T extends EntityInterface> {
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() {

View File

@ -258,7 +258,7 @@ public class FeedRepository {
.findFrom(about.getFullyQualifiedFieldValue(), about.getFullyQualifiedFieldType(), IS_ABOUT.ordinal());
for (Triple<String, String, String> 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> post = thread.getPosts().stream().filter(p -> p.getId().equals(UUID.fromString(postId))).findAny();
public Post getPostById(Thread thread, UUID postId) {
Optional<Post> 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<Thread> 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<String> 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<String> 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<Post> listPosts(String threadId) {
public List<Post> listPosts(UUID threadId) {
return get(threadId).getPosts();
}
/** List threads based on the filters and limits in the order of the updated timestamp. */
public ResultList<Thread> list(FeedFilter filter, String link, int limitPosts, String userId, int limit) {
public ResultList<Thread> list(FeedFilter filter, String link, int limitPosts, UUID userId, int limit) {
int total;
List<Thread> 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<String> teamNameHash = getTeamNames(user);
String userName = user == null ? null : user.getFullyQualifiedName();
List<String> jsons =
@ -650,7 +650,7 @@ public class FeedRepository {
public final PatchResponse<Thread> 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<EntityReference> assignees = original.getTask().getAssignees();
populateAssignees(original);
@ -727,8 +727,7 @@ public class FeedRepository {
}
// TODO fix this - overlapping announcements should be allowed
List<String> 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<String> teamIds) {
private String getUserTeamJsonMysql(UUID userId, List<String> 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<String> result = new ArrayList<>();
@ -830,7 +829,7 @@ public class FeedRepository {
return result.toString();
}
private List<String> getUserTeamJsonPostgres(String userId, List<String> teamIds) {
private List<String> getUserTeamJsonPostgres(UUID userId, List<String> 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<String> 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<String> teamIds = getTeamIds(userId);
List<String> 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<String> teamIds = getTeamIds(userId);
List<String> 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<String> jsons = dao.feedDAO().listTasksAssigned(username, limit, filter.getCondition());
List<Thread> 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<String> 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<String> 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<String> getTeamIds(String userId) {
private List<String> getTeamIds(UUID userId) {
List<String> 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<String> teamIds = getTeamIds(userId);
List<String> jsons =
dao.feedDAO()

View File

@ -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<EntityRelationshipRecord> 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<EntityReference> upstreamEntityReferences = new ArrayList<>();
for (EntityRelationshipRecord entityRelationshipRecord : records) {
@ -189,9 +184,9 @@ public class LineageRepository {
}
List<EntityRelationshipRecord> 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<EntityReference> downstreamEntityReferences = new ArrayList<>();
for (EntityRelationshipRecord entityRelationshipRecord : records) {

View File

@ -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<SearchIndex> {
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<SearchIndex> {
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<SearchIndex> {
return childrenSchemaField;
}
public static Set<TagLabel> getAllFieldTags(SearchIndexField field) {
Set<TagLabel> 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";

View File

@ -231,7 +231,7 @@ public class TableRepository extends EntityRepository<Table> {
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<Table> {
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<Table> {
// 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<CollectionDAO.EntityRelationshipRecord> entityRelationshipRecords =
daoCollection.relationshipDAO().findTo(table.getId().toString(), TABLE, Relationship.CONTAINS.ordinal());
daoCollection.relationshipDAO().findTo(table.getId(), TABLE, Relationship.CONTAINS.ordinal());
Optional<CollectionDAO.EntityRelationshipRecord> testSuiteRelationshipRecord =
entityRelationshipRecords.stream()
.filter(entityRelationshipRecord -> entityRelationshipRecord.getType().equals(Entity.TEST_SUITE))
@ -310,10 +310,7 @@ public class TableRepository extends EntityRepository<Table> {
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<Table> {
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<Table> {
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<Table> {
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<Table> {
private List<CustomMetric> 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) {

View File

@ -415,7 +415,7 @@ public class TeamRepository extends EntityRepository<Team> {
protected List<EntityReference> getChildren(UUID teamId) {
if (teamId.equals(organization.getId())) { // For organization all the parentless teams are children
List<String> children = daoCollection.teamDAO().listTeamsUnderOrganization(teamId.toString());
List<String> children = daoCollection.teamDAO().listTeamsUnderOrganization(teamId);
return EntityUtil.populateEntityReferencesById(EntityUtil.strToIds(children), Entity.TEAM);
}
return findTo(teamId, TEAM, Relationship.PARENT_OF, TEAM);

View File

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

View File

@ -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<TokenInterface> findByUserIdAndType(String userId, String type) {
public List<TokenInterface> 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) {

View File

@ -146,8 +146,7 @@ public class TopicRepository extends EntityRepository<Topic> {
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<Topic> {
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);
}

View File

@ -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> 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> usageDetails = dao.usageDAO().getUsageById(ref.getId().toString(), date, days - 1);
List<UsageDetails> 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)) {

View File

@ -262,13 +262,13 @@ public class UserRepository extends EntityRepository<User> {
private List<EntityReference> getOwns(User user) {
// Compile entities owned by the user
List<EntityRelationshipRecord> 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<EntityReference> 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<User> {
private List<EntityReference> getTeamChildren(UUID teamId) {
if (teamId.equals(organization.getId())) { // For organization all the parentless teams are children
List<String> children = daoCollection.teamDAO().listTeamsUnderOrganization(teamId.toString());
List<String> children = daoCollection.teamDAO().listTeamsUnderOrganization(teamId);
return EntityUtil.populateEntityReferencesById(EntityUtil.strToIds(children), Entity.TEAM);
}
return findTo(teamId, TEAM, Relationship.PARENT_OF, TEAM);

View File

@ -537,12 +537,12 @@ public class MigrationUtil {
List<CollectionDAO.EntityRelationshipRecord> 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());
}
}
}

View File

@ -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<CollectionDAO.EntityRelationshipRecord> records =
collectionDAO.relationshipDAO().findTo(k, TEST_SUITE, Relationship.CONTAINS.ordinal(), TEST_CASE);
collectionDAO.relationshipDAO().findTo(id, TEST_SUITE, Relationship.CONTAINS.ordinal(), TEST_CASE);
List<CollectionDAO.EntityRelationshipRecord> 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<Map<String, Object>> resultList = handle.createQuery(resultListSql).mapToMap().list();
for (Map<String, Object> 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
}

View File

@ -201,8 +201,7 @@ public class FeedResource {
.after(after)
.build();
String userIdStr = userId != null ? userId.toString() : null;
ResultList<Thread> threads = dao.list(filter, entityLink, limitPosts, userIdStr, limitParam);
ResultList<Thread> 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<Post> 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));
}

View File

@ -1056,7 +1056,7 @@ public class UserResource extends EntityResource<User, UserRepository> {
}
User user = repository.getByName(null, userName, getFields("id"), Include.NON_DELETED, true);
List<TokenInterface> 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, UserRepository> {
}
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<String> ids = request.getTokenIds().stream().map(UUID::toString).collect(Collectors.toList());
tokenRepository.deleteAllToken(ids);
}
UserTokenCache.invalidateToken(user.getName());
List<TokenInterface> 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();
}

View File

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

View File

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

View File

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

View File

@ -72,7 +72,7 @@ public class UserTokenCache {
userRepository.getByName(
null, userName, new Fields(Set.of(UserResource.USER_PROTECTED_FIELDS)), NON_DELETED, true);
List<TokenInterface> 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;
}

View File

@ -134,13 +134,14 @@ public final class EntityUtil {
private EntityUtil() {}
/** Validate that JSON payload can be turned into POJO object */
public static <T> T validate(String identity, String json, Class<T> clz) throws WebApplicationException {
public static <T> T validate(Object id, String json, Class<T> 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;
}

View File

@ -99,9 +99,7 @@ public class NotificationHandler {
} else if (Entity.TEAM.equals(e.getType())) {
// fetch all that are there in the team
List<CollectionDAO.EntityRelationshipRecord> 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<CollectionDAO.EntityRelationshipRecord> 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);
}

View File

@ -106,7 +106,7 @@ public class SubscriptionUtil {
Set<String> data = new HashSet<>();
try {
List<CollectionDAO.EntityRelationshipRecord> ownerOrFollowers =
daoCollection.relationshipDAO().findFrom(entityId.toString(), entityType, relationship.ordinal());
daoCollection.relationshipDAO().findFrom(entityId, entityType, relationship.ordinal());
ownerOrFollowers.forEach(
owner -> {
if (type == CreateEventSubscription.SubscriptionType.EMAIL

View File

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