Fix #2718: Update entity_thread schema to store activity feeds (#2726)

This commit is contained in:
Vivek Ratnavel Subramanian 2022-02-10 20:47:31 -08:00 committed by GitHub
parent 6891cd1e62
commit 6447e34bff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 55 additions and 7 deletions

View File

@ -0,0 +1,17 @@
DROP TABLE IF EXISTS thread_entity;
CREATE TABLE IF NOT EXISTS thread_entity (
id VARCHAR(36) GENERATED ALWAYS AS (json ->> '$.id') STORED NOT NULL,
entityLink VARCHAR(256) GENERATED ALWAYS AS (json ->> '$.about') NOT NULL,
assignedTo VARCHAR(256) GENERATED ALWAYS AS (json ->> '$.addressedTo'),
json JSON NOT NULL,
createdAt BIGINT UNSIGNED GENERATED ALWAYS AS (json ->> '$.threadTs') STORED NOT NULL,
createdBy VARCHAR(256) GENERATED ALWAYS AS (json ->> '$.createdBy') STORED NOT NULL,
updatedAt BIGINT UNSIGNED GENERATED ALWAYS AS (json ->> '$.updatedAt') NOT NULL,
updatedBy VARCHAR(256) GENERATED ALWAYS AS (json ->> '$.updatedBy') NOT NULL,
resolved BOOLEAN GENERATED ALWAYS AS (JSON_EXTRACT(json, '$.resolved')),
PRIMARY KEY (id),
INDEX (updatedBy),
INDEX (updatedAt)
);

View File

@ -198,7 +198,7 @@ public class FeedRepository {
Set<String> uniqueValues = new HashSet<>();
for (String t : threadIds) {
// If an entity has multiple relationships (created, mentioned, repliedTo etc.) to the same thread
// Don't sent duplicated copies of the thread in response
// Don't send duplicated copies of the thread in response
if (uniqueValues.add(t)) {
threads.add(EntityUtil.validate(t, dao.feedDAO().findById(t), Thread.class));
}

View File

@ -35,6 +35,7 @@ import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.SecurityContext;
import javax.ws.rs.core.UriInfo;
import org.openmetadata.catalog.api.feed.CreateThread;
import org.openmetadata.catalog.entity.feed.Thread;
@ -131,12 +132,10 @@ public class FeedResource {
content = @Content(mediaType = "application/json", schema = @Schema(implementation = CreateThread.class))),
@ApiResponse(responseCode = "400", description = "Bad request")
})
public Response create(@Context UriInfo uriInfo, @Valid CreateThread cr) throws IOException, ParseException {
Thread thread =
new Thread().withId(UUID.randomUUID()).withThreadTs(System.currentTimeMillis()).withAbout(cr.getAbout());
// For now redundantly storing everything in json (that includes fromEntity, addressedTo entity)
// TODO - This needs cleanup later if this information is too much or inconsistent in relationship table
FeedUtil.addPost(thread, new Post().withMessage(cr.getMessage()).withFrom(cr.getFrom()));
public Response create(@Context UriInfo uriInfo, @Context SecurityContext securityContext, @Valid CreateThread create)
throws IOException, ParseException {
Thread thread = getThread(securityContext, create);
FeedUtil.addPost(thread, new Post().withMessage(create.getMessage()).withFrom(create.getFrom()));
addHref(uriInfo, dao.create(thread));
return Response.created(thread.getHref()).entity(thread).build();
}
@ -158,4 +157,15 @@ public class FeedResource {
Thread thread = addHref(uriInfo, dao.addPostToThread(id, post));
return Response.created(thread.getHref()).entity(thread).build();
}
private Thread getThread(SecurityContext securityContext, CreateThread create) {
return new Thread()
.withId(UUID.randomUUID())
.withThreadTs(System.currentTimeMillis())
.withCreatedBy(securityContext.getUserPrincipal().getName())
.withAbout(create.getAbout())
.withAddressedTo(create.getAddressedTo())
.withUpdatedBy(securityContext.getUserPrincipal().getName())
.withUpdatedAt(System.currentTimeMillis());
}
}

View File

@ -13,6 +13,10 @@
"description": "ID of User (regular user or bot) posting the message",
"$ref": "../../type/basic.json#/definitions/uuid"
},
"addressedTo": {
"description": "User or team this thread is addressed to in format <#E/{entities}/{entityName}/{field}/{fieldValue}.",
"$ref": "../../type/basic.json#/definitions/entityLink"
},
"about": {
"description": "Data asset about which this thread is created for with format <#E/{entities}/{entityType}/{field}/{fieldValue}",
"$ref": "../../type/basic.json#/definitions/entityLink"

View File

@ -48,6 +48,23 @@
"description": "User or team this thread is addressed to in format <#E/{entities}/{entityName}/{field}/{fieldValue}.",
"$ref": "../../type/basic.json#/definitions/entityLink"
},
"createdBy": {
"description": "User who created the thread.",
"type": "string"
},
"updatedAt": {
"description": "Last update time corresponding to the new version of the entity in Unix epoch time milliseconds.",
"$ref": "../../type/basic.json#/definitions/timestamp"
},
"updatedBy": {
"description": "User who made the update.",
"type": "string"
},
"resolved": {
"description": "When `true` indicates the thread has been resolved",
"type": "boolean",
"default": false
},
"posts": {
"type": "array",
"items": {