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