mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-08-27 18:36:08 +00:00
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:
parent
2fe5d7e865
commit
6f2d0db079
@ -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));
|
||||
}
|
||||
|
@ -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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user