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.getColumnField;
import static org.openmetadata.service.util.EntityUtil.getEntityReferences; import static org.openmetadata.service.util.EntityUtil.getEntityReferences;
import static org.openmetadata.service.util.EntityUtil.getExtensionField; 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.mergedInheritedEntityRefs;
import static org.openmetadata.service.util.EntityUtil.nextMajorVersion; import static org.openmetadata.service.util.EntityUtil.nextMajorVersion;
import static org.openmetadata.service.util.EntityUtil.nextVersion; import static org.openmetadata.service.util.EntityUtil.nextVersion;
@ -2625,7 +2626,7 @@ public abstract class EntityRepository<T extends EntityInterface> {
protected void createAndInsertChangeEvent( protected void createAndInsertChangeEvent(
T original, T updated, ChangeDescription changeDescription, EventType eventType) { T original, T updated, ChangeDescription changeDescription, EventType eventType) {
if (changeDescription == null) { if (isNullOrEmptyChangeDescription(changeDescription)) {
return; return;
} }
@ -2990,7 +2991,7 @@ public abstract class EntityRepository<T extends EntityInterface> {
} }
private void updateChangeSummary() { private void updateChangeSummary() {
if (changeDescription == null) { if (isNullOrEmptyChangeDescription(changeDescription)) {
return; return;
} }
// build new change summary // build new change summary
@ -3113,7 +3114,8 @@ public abstract class EntityRepository<T extends EntityInterface> {
// delete operation // delete operation
if (!Objects.equals(updated.getDeleted(), original.getDeleted()) if (!Objects.equals(updated.getDeleted(), original.getDeleted())
&& Boolean.TRUE.equals(updated.getDeleted()) && Boolean.TRUE.equals(updated.getDeleted())
&& changeDescription != null) { && isNullOrEmptyChangeDescription(changeDescription)
&& (Objects.equals(original.getVersion(), updated.getVersion()))) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
CatalogExceptionMessage.readOnlyAttribute(entityType, FIELD_DELETED)); 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.SearchUtils.isConnectedVia;
import static org.openmetadata.service.search.models.IndexMapping.INDEX_NAME_SEPARATOR; 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.compareEntityReferenceById;
import static org.openmetadata.service.util.EntityUtil.isNullOrEmptyChangeDescription;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
@ -422,10 +423,7 @@ public class SearchRepository {
ChangeDescription incrementalChangeDescription = entity.getIncrementalChangeDescription(); ChangeDescription incrementalChangeDescription = entity.getIncrementalChangeDescription();
ChangeDescription changeDescription; ChangeDescription changeDescription;
if (incrementalChangeDescription != null if (!isNullOrEmptyChangeDescription(incrementalChangeDescription)) {
&& (!incrementalChangeDescription.getFieldsAdded().isEmpty()
|| !incrementalChangeDescription.getFieldsUpdated().isEmpty()
|| !incrementalChangeDescription.getFieldsDeleted().isEmpty())) {
changeDescription = incrementalChangeDescription; changeDescription = incrementalChangeDescription;
} else { } else {
changeDescription = entity.getChangeDescription(); changeDescription = entity.getChangeDescription();
@ -948,12 +946,17 @@ public class SearchRepository {
scriptTxt, scriptTxt,
List.of(new ImmutablePair<>("dashboards.id", docId))); List.of(new ImmutablePair<>("dashboards.id", docId)));
} }
default -> searchClient.softDeleteOrRestoreChildren( default -> {
List<String> indexNames = indexMapping.getChildAliases(clusterAlias);
if (!indexNames.isEmpty()) {
searchClient.softDeleteOrRestoreChildren(
indexMapping.getChildAliases(clusterAlias), indexMapping.getChildAliases(clusterAlias),
scriptTxt, scriptTxt,
List.of(new ImmutablePair<>(entityType + ".id", docId))); List.of(new ImmutablePair<>(entityType + ".id", docId)));
} }
} }
}
}
public String getScriptWithParams( public String getScriptWithParams(
EntityInterface entity, EntityInterface entity,

View File

@ -712,4 +712,13 @@ public final class EntityUtil {
public static String encodeEntityFqn(String fqn) { public static String encodeEntityFqn(String fqn) {
return URLEncoder.encode(fqn.trim(), StandardCharsets.UTF_8).replace("+", "%20"); 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();
}
} }