From 4e268f0f0be632b83935db3bdab597ea8ef2eb2f Mon Sep 17 00:00:00 2001 From: Vivek Ratnavel Subramanian Date: Tue, 19 Jul 2022 22:21:31 -0700 Subject: [PATCH] Backend: Soft deleting a user is causing the page to not load (#6207) --- .../catalog/jdbi3/FeedRepository.java | 29 +++++++++++++++---- .../openmetadata/catalog/util/RestUtil.java | 4 +++ 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/FeedRepository.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/FeedRepository.java index 32598a126b8..ffbdd672131 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/FeedRepository.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/FeedRepository.java @@ -18,6 +18,7 @@ import static org.openmetadata.catalog.Entity.PIPELINE; import static org.openmetadata.catalog.Entity.TABLE; import static org.openmetadata.catalog.Entity.TOPIC; import static org.openmetadata.catalog.Entity.getEntityRepository; +import static org.openmetadata.catalog.type.Include.ALL; import static org.openmetadata.catalog.type.Relationship.ADDRESSED_TO; import static org.openmetadata.catalog.type.Relationship.CREATED; import static org.openmetadata.catalog.type.Relationship.IS_ABOUT; @@ -25,6 +26,10 @@ import static org.openmetadata.catalog.type.Relationship.REPLIED_TO; import static org.openmetadata.catalog.util.ChangeEventParser.getPlaintextDiff; import static org.openmetadata.catalog.util.EntityUtil.compareEntityReference; import static org.openmetadata.catalog.util.EntityUtil.populateEntityReferences; +import static org.openmetadata.catalog.util.RestUtil.DELETED_TEAM_DISPLAY; +import static org.openmetadata.catalog.util.RestUtil.DELETED_TEAM_NAME; +import static org.openmetadata.catalog.util.RestUtil.DELETED_USER_DISPLAY; +import static org.openmetadata.catalog.util.RestUtil.DELETED_USER_NAME; import com.fasterxml.jackson.core.JsonProcessingException; import io.jsonwebtoken.lang.Collections; @@ -885,12 +890,26 @@ public class FeedRepository { private Thread populateAssignees(Thread thread) { if (thread.getType().equals(ThreadType.Task)) { List assignees = thread.getTask().getAssignees(); - try { - assignees = EntityUtil.populateEntityReferences(assignees); - thread.getTask().setAssignees(assignees); - } catch (IOException e) { - throw new RuntimeException(e); + for (EntityReference ref : assignees) { + try { + EntityReference ref2 = Entity.getEntityReferenceById(ref.getType(), ref.getId(), ALL); + EntityUtil.copy(ref2, ref); + } catch (EntityNotFoundException exception) { + // mark the not found user as deleted user since + // user will not be found in case of permanent deletion of user or team + if (ref.getType().equals(Entity.TEAM)) { + ref.setName(DELETED_TEAM_NAME); + ref.setDisplayName(DELETED_TEAM_DISPLAY); + } else { + ref.setName(DELETED_USER_NAME); + ref.setDisplayName(DELETED_USER_DISPLAY); + } + } catch (IOException ioException) { + throw new RuntimeException(ioException); + } } + assignees.sort(compareEntityReference); + thread.getTask().setAssignees(assignees); } return thread; } diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/util/RestUtil.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/util/RestUtil.java index 38be36ade5d..6e4909c6699 100644 --- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/util/RestUtil.java +++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/util/RestUtil.java @@ -38,6 +38,10 @@ public final class RestUtil { public static final String ENTITY_NO_CHANGE = "entityNoChange"; public static final String ENTITY_SOFT_DELETED = "entitySoftDeleted"; public static final String ENTITY_DELETED = "entityDeleted"; + public static final String DELETED_USER_NAME = "DeletedUser"; + public static final String DELETED_USER_DISPLAY = "User was deleted"; + public static final String DELETED_TEAM_NAME = "DeletedTeam"; + public static final String DELETED_TEAM_DISPLAY = "Team was deleted"; public static final String SIGNATURE_HEADER = "X-OM-Signature"; public static final DateFormat DATE_TIME_FORMAT;