Delete Tasks related to entity when the entity is deleted (#11660)

* Delete Tasks related to entity when the entity is deleted

* Delete all conversation related to entity only when its permanantly deleted

* renamed function name deleteTasksForRelatedEntity to deleteAllConversationsRelatedToEntity

---------

Co-authored-by: Himank Mehta <himankmehta@Himanks-MacBook-Air.local>
This commit is contained in:
07Himank 2023-05-25 10:48:46 +05:30 committed by GitHub
parent 5bd1b09402
commit ef2869cd9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View File

@ -174,6 +174,7 @@ public class ChangeEventHandler implements EventHandler {
EntityReference entityReference = entityInterface.getEntityReference();
String entityType = entityReference.getType();
String entityFQN = entityReference.getFullyQualifiedName();
deleteAllConversationsRelatedToEntity(entityInterface);
return getChangeEvent(updateBy, ENTITY_DELETED, entityType, entityInterface)
.withPreviousVersion(entityInterface.getVersion())
.withEntity(entityInterface)
@ -275,6 +276,15 @@ public class ChangeEventHandler implements EventHandler {
.withMessage(message);
}
private void deleteAllConversationsRelatedToEntity(EntityInterface entityInterface) {
String entityId = entityInterface.getId().toString();
List<String> threadIds = dao.feedDAO().findByEntityId(entityId);
for (String threadId : threadIds) {
dao.relationshipDAO().deleteAll(threadId, Entity.THREAD);
dao.feedDAO().delete(threadId);
}
}
public void close() {
/* Nothing to do */
}

View File

@ -1095,6 +1095,9 @@ public interface CollectionDAO {
@Bind("relation") int relation,
@Define("condition") String condition);
@SqlQuery("select id from thread_entity where entityId = :entityId")
List<String> findByEntityId(@Bind("entityId") String entityId);
class CountFieldMapper implements RowMapper<List<String>> {
@Override
public List<String> map(ResultSet rs, StatementContext ctx) throws SQLException {