Minor : Fix issue with soft delete and restore (#20336)

* Minor : Fix issue with soft delete and restore

* fix search

* fix condition

* fx search condition

---------

Co-authored-by: Shailesh Parmar <shailesh.parmar.webdev@gmail.com>
This commit is contained in:
sonika-shah 2025-03-23 14:50:21 +05:30 committed by GitHub
parent 2fe5d7e865
commit 6f2d0db079
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 25 additions and 11 deletions

View File

@ -62,6 +62,7 @@ import static org.openmetadata.service.util.EntityUtil.fieldUpdated;
import static org.openmetadata.service.util.EntityUtil.getColumnField;
import static org.openmetadata.service.util.EntityUtil.getEntityReferences;
import static org.openmetadata.service.util.EntityUtil.getExtensionField;
import static org.openmetadata.service.util.EntityUtil.isNullOrEmptyChangeDescription;
import static org.openmetadata.service.util.EntityUtil.mergedInheritedEntityRefs;
import static org.openmetadata.service.util.EntityUtil.nextMajorVersion;
import static org.openmetadata.service.util.EntityUtil.nextVersion;
@ -2625,7 +2626,7 @@ public abstract class EntityRepository<T extends EntityInterface> {
protected void createAndInsertChangeEvent(
T original, T updated, ChangeDescription changeDescription, EventType eventType) {
if (changeDescription == null) {
if (isNullOrEmptyChangeDescription(changeDescription)) {
return;
}
@ -2990,7 +2991,7 @@ public abstract class EntityRepository<T extends EntityInterface> {
}
private void updateChangeSummary() {
if (changeDescription == null) {
if (isNullOrEmptyChangeDescription(changeDescription)) {
return;
}
// build new change summary
@ -3113,7 +3114,8 @@ public abstract class EntityRepository<T extends EntityInterface> {
// delete operation
if (!Objects.equals(updated.getDeleted(), original.getDeleted())
&& Boolean.TRUE.equals(updated.getDeleted())
&& changeDescription != null) {
&& isNullOrEmptyChangeDescription(changeDescription)
&& (Objects.equals(original.getVersion(), updated.getVersion()))) {
throw new IllegalArgumentException(
CatalogExceptionMessage.readOnlyAttribute(entityType, FIELD_DELETED));
}

View File

@ -47,6 +47,7 @@ import static org.openmetadata.service.search.SearchConstants.TEST_SUITES;
import static org.openmetadata.service.search.SearchUtils.isConnectedVia;
import static org.openmetadata.service.search.models.IndexMapping.INDEX_NAME_SEPARATOR;
import static org.openmetadata.service.util.EntityUtil.compareEntityReferenceById;
import static org.openmetadata.service.util.EntityUtil.isNullOrEmptyChangeDescription;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
@ -422,10 +423,7 @@ public class SearchRepository {
ChangeDescription incrementalChangeDescription = entity.getIncrementalChangeDescription();
ChangeDescription changeDescription;
if (incrementalChangeDescription != null
&& (!incrementalChangeDescription.getFieldsAdded().isEmpty()
|| !incrementalChangeDescription.getFieldsUpdated().isEmpty()
|| !incrementalChangeDescription.getFieldsDeleted().isEmpty())) {
if (!isNullOrEmptyChangeDescription(incrementalChangeDescription)) {
changeDescription = incrementalChangeDescription;
} else {
changeDescription = entity.getChangeDescription();
@ -948,10 +946,15 @@ public class SearchRepository {
scriptTxt,
List.of(new ImmutablePair<>("dashboards.id", docId)));
}
default -> searchClient.softDeleteOrRestoreChildren(
indexMapping.getChildAliases(clusterAlias),
scriptTxt,
List.of(new ImmutablePair<>(entityType + ".id", docId)));
default -> {
List<String> indexNames = indexMapping.getChildAliases(clusterAlias);
if (!indexNames.isEmpty()) {
searchClient.softDeleteOrRestoreChildren(
indexMapping.getChildAliases(clusterAlias),
scriptTxt,
List.of(new ImmutablePair<>(entityType + ".id", docId)));
}
}
}
}

View File

@ -712,4 +712,13 @@ public final class EntityUtil {
public static String encodeEntityFqn(String fqn) {
return URLEncoder.encode(fqn.trim(), StandardCharsets.UTF_8).replace("+", "%20");
}
public static boolean isNullOrEmptyChangeDescription(ChangeDescription changeDescription) {
if (changeDescription == null) {
return true;
}
return changeDescription.getFieldsAdded().isEmpty()
&& changeDescription.getFieldsUpdated().isEmpty()
&& changeDescription.getFieldsDeleted().isEmpty();
}
}