Fixes #13049 - Glossary recursive delete fails (#13182)

This commit is contained in:
Suresh Srinivas 2023-09-15 10:21:38 -07:00 committed by GitHub
parent d10d28da0c
commit 3abb83052d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 20 deletions

View File

@ -874,9 +874,6 @@ public abstract class EntityRepository<T extends EntityInterface> {
String changeType;
T updated = get(null, original.getId(), putFields, ALL, false);
// clearFields(updated, Fields.EMPTY_FIELDS); // Clear the entity and set the fields again
// setFieldsInternal(updated, putFields); // we need service, database, databaseSchema to delete properly from
// ES.
if (supportsSoftDelete && !hardDelete) {
updated.setUpdatedBy(deletedBy);
updated.setUpdatedAt(System.currentTimeMillis());
@ -901,7 +898,6 @@ public abstract class EntityRepository<T extends EntityInterface> {
public final DeleteResponse<T> deleteInternal(String updatedBy, UUID id, boolean recursive, boolean hardDelete) {
// Validate entity
T entity = dao.findEntityById(id, ALL);
return delete(updatedBy, entity, recursive, hardDelete);
}
@ -1069,15 +1065,11 @@ public abstract class EntityRepository<T extends EntityInterface> {
public List<String> getResultsFromAndToTimestamps(
String fullyQualifiedName, String extension, Long startTs, Long endTs) {
return getResultsFromAndToTimestamps(
fullyQualifiedName, extension, startTs, endTs, CollectionDAO.EntityExtensionTimeSeriesDAO.OrderBy.DESC);
fullyQualifiedName, extension, startTs, endTs, EntityTimeSeriesDAO.OrderBy.DESC);
}
public List<String> getResultsFromAndToTimestamps(
String fqn,
String extension,
Long startTs,
Long endTs,
CollectionDAO.EntityExtensionTimeSeriesDAO.OrderBy orderBy) {
String fqn, String extension, Long startTs, Long endTs, EntityTimeSeriesDAO.OrderBy orderBy) {
return daoCollection
.entityExtensionTimeSeriesDao()
.listBetweenTimestampsByOrder(fqn, extension, startTs, endTs, orderBy);

View File

@ -73,7 +73,7 @@ public class GlossaryTermRepository extends EntityRepository<GlossaryTerm> {
@Override
public GlossaryTerm setFields(GlossaryTerm entity, Fields fields) {
entity.withGlossary(getGlossary(entity)).withParent(getParent(entity));
entity.withParent(getParent(entity)).withGlossary(getGlossary(entity));
entity.setRelatedTerms(fields.contains("relatedTerms") ? getRelatedTerms(entity) : entity.getRelatedTerms());
return entity.withUsageCount(fields.contains("usageCount") ? getUsageCount(entity) : entity.getUsageCount());
}
@ -176,9 +176,10 @@ public class GlossaryTermRepository extends EntityRepository<GlossaryTerm> {
}
protected EntityReference getGlossary(GlossaryTerm term) {
Relationship relationship = term.getParent() != null ? Relationship.HAS : Relationship.CONTAINS;
return term.getGlossary() != null
? term.getGlossary()
: getFromEntityRef(term.getId(), Relationship.CONTAINS, GLOSSARY, true);
: getFromEntityRef(term.getId(), relationship, GLOSSARY, true);
}
public EntityReference getGlossary(String id) {
@ -220,7 +221,8 @@ public class GlossaryTermRepository extends EntityRepository<GlossaryTerm> {
}
private void addGlossaryRelationship(GlossaryTerm term) {
addRelationship(term.getGlossary().getId(), term.getId(), GLOSSARY, GLOSSARY_TERM, Relationship.CONTAINS);
Relationship relationship = term.getParent() != null ? Relationship.HAS : Relationship.CONTAINS;
addRelationship(term.getGlossary().getId(), term.getId(), GLOSSARY, GLOSSARY_TERM, relationship);
}
private void addParentRelationship(GlossaryTerm term) {
@ -357,6 +359,7 @@ public class GlossaryTermRepository extends EntityRepository<GlossaryTerm> {
invalidateTerm(original.getId());
}
if (parentChanged) {
updateGlossaryRelationship(original, updated);
updateParentRelationship(original, updated);
recordChange("parent", original.getParent(), updated.getParent(), true, entityReferenceMatch);
invalidateTerm(original.getId());
@ -378,7 +381,8 @@ public class GlossaryTermRepository extends EntityRepository<GlossaryTerm> {
}
private void deleteGlossaryRelationship(GlossaryTerm term) {
deleteRelationship(term.getGlossary().getId(), GLOSSARY, term.getId(), GLOSSARY_TERM, Relationship.CONTAINS);
Relationship relationship = term.getParent() == null ? Relationship.CONTAINS : Relationship.HAS;
deleteRelationship(term.getGlossary().getId(), GLOSSARY, term.getId(), GLOSSARY_TERM, relationship);
}
private void updateParentRelationship(GlossaryTerm orig, GlossaryTerm updated) {

View File

@ -312,20 +312,22 @@ public class GlossaryTermResourceTest extends EntityResourceTest<GlossaryTerm, C
Glossary g1 = createGlossary(test, null, null);
// Create glossary term t1 in glossary g1
CreateGlossaryTerm create = createRequest("t1", "", "", null).withGlossary(g1.getFullyQualifiedName());
GlossaryTerm t1 = createEntity(create, ADMIN_AUTH_HEADERS);
GlossaryTerm t1 = createTerm(g1, null, "t1");
TagLabel t1Label = EntityUtil.toTagLabel(t1);
// Create glossary term t11 under t1
create.withName("t11with'quote").withParent(t1.getFullyQualifiedName());
GlossaryTerm t11 = createEntity(create, ADMIN_AUTH_HEADERS);
GlossaryTerm t11 = createTerm(g1, t1, "t11");
TagLabel t11Label = EntityUtil.toTagLabel(t11);
// Create glossary term t111 under t11
create.withName("t111'quote").withParent(t11.getFullyQualifiedName());
GlossaryTerm t111 = createEntity(create, ADMIN_AUTH_HEADERS);
GlossaryTerm t111 = createTerm(g1, t11, "t111");
TagLabel t111Label = EntityUtil.toTagLabel(t111);
// Create glossary term t12, t121, t1211 under t1
GlossaryTerm t12 = createTerm(g1, t1, "t12");
GlossaryTerm t121 = createTerm(g1, t12, "t121");
GlossaryTerm t1211 = createTerm(g1, t121, "t121");
// Assign glossary terms to a table
// t1 assigned to table. t11 assigned column1 and t111 assigned to column2
TableResourceTest tableResourceTest = new TableResourceTest();