Make restoring patch attributes consistent across entities (#13961)

* Make restoring patch attributes consistent across entities

* Fix test failures

* Fix test failures
This commit is contained in:
Suresh Srinivas 2023-11-13 16:32:18 -08:00 committed by GitHub
parent 10d8ec84fe
commit e367f557a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 39 additions and 75 deletions

View File

@ -75,11 +75,8 @@ public class ChartRepository extends EntityRepository<Chart> {
@Override @Override
public void restorePatchAttributes(Chart original, Chart updated) { public void restorePatchAttributes(Chart original, Chart updated) {
// Patch can't make changes to following fields. Ignore the changes // Patch can't make changes to following fields. Ignore the changes
updated super.restorePatchAttributes(original, updated);
.withFullyQualifiedName(original.getFullyQualifiedName()) updated.withService(original.getService());
.withName(original.getName())
.withService(original.getService())
.withId(original.getId());
} }
@Override @Override

View File

@ -48,6 +48,7 @@ public class ClassificationRepository extends EntityRepository<Classification> {
""); "");
quoteFqn = true; quoteFqn = true;
supportsSearch = true; supportsSearch = true;
renameAllowed = true;
} }
@Override @Override
@ -110,7 +111,6 @@ public class ClassificationRepository extends EntityRepository<Classification> {
@Transaction @Transaction
@Override @Override
public void entitySpecificUpdate() { public void entitySpecificUpdate() {
// TODO handle name change
// TODO mutuallyExclusive from false to true? // TODO mutuallyExclusive from false to true?
recordChange("mutuallyExclusive", original.getMutuallyExclusive(), updated.getMutuallyExclusive()); recordChange("mutuallyExclusive", original.getMutuallyExclusive(), updated.getMutuallyExclusive());
recordChange("disabled", original.getDisabled(), updated.getDisabled()); recordChange("disabled", original.getDisabled(), updated.getDisabled());
@ -125,6 +125,7 @@ public class ClassificationRepository extends EntityRepository<Classification> {
} }
// Classification name changed - update tag names starting from classification and all the children tags // Classification name changed - update tag names starting from classification and all the children tags
LOG.info("Classification name changed from {} to {}", original.getName(), updated.getName()); LOG.info("Classification name changed from {} to {}", original.getName(), updated.getName());
setFullyQualifiedName(updated);
daoCollection.tagDAO().updateFqn(original.getName(), updated.getName()); daoCollection.tagDAO().updateFqn(original.getName(), updated.getName());
daoCollection daoCollection
.tagUsageDAO() .tagUsageDAO()

View File

@ -146,12 +146,8 @@ public class ContainerRepository extends EntityRepository<Container> {
@Override @Override
public void restorePatchAttributes(Container original, Container updated) { public void restorePatchAttributes(Container original, Container updated) {
// Patch can't make changes to following fields. Ignore the changes // Patch can't make changes to following fields. Ignore the changes
updated super.restorePatchAttributes(original, updated);
.withFullyQualifiedName(original.getFullyQualifiedName()) updated.withService(original.getService()).withParent(original.getParent());
.withService(original.getService())
.withParent(original.getParent())
.withName(original.getName())
.withId(original.getId());
} }
@Override @Override

View File

@ -174,11 +174,8 @@ public class DashboardDataModelRepository extends EntityRepository<DashboardData
@Override @Override
public void restorePatchAttributes(DashboardDataModel original, DashboardDataModel updated) { public void restorePatchAttributes(DashboardDataModel original, DashboardDataModel updated) {
// Patch can't make changes to following fields. Ignore the changes // Patch can't make changes to following fields. Ignore the changes
updated super.restorePatchAttributes(original, updated);
.withFullyQualifiedName(original.getFullyQualifiedName()) updated.withService(original.getService());
.withName(original.getName())
.withService(original.getService())
.withId(original.getId());
} }
private void applyTags(List<Column> columns) { private void applyTags(List<Column> columns) {

View File

@ -118,11 +118,8 @@ public class DashboardRepository extends EntityRepository<Dashboard> {
@Override @Override
public void restorePatchAttributes(Dashboard original, Dashboard updated) { public void restorePatchAttributes(Dashboard original, Dashboard updated) {
// Patch can't make changes to following fields. Ignore the changes // Patch can't make changes to following fields. Ignore the changes
updated super.restorePatchAttributes(original, updated);
.withId(original.getId()) updated.withService(original.getService());
.withFullyQualifiedName(original.getFullyQualifiedName())
.withName(original.getName())
.withService(original.getService());
} }
private void populateService(Dashboard dashboard) { private void populateService(Dashboard dashboard) {

View File

@ -92,6 +92,7 @@ public class DataProductRepository extends EntityRepository<DataProduct> {
@Override @Override
public void restorePatchAttributes(DataProduct original, DataProduct updated) { public void restorePatchAttributes(DataProduct original, DataProduct updated) {
super.restorePatchAttributes(original, updated);
updated.withDomain(original.getDomain()); // Domain can't be changed updated.withDomain(original.getDomain()); // Domain can't be changed
} }

View File

@ -112,11 +112,8 @@ public class DatabaseRepository extends EntityRepository<Database> {
@Override @Override
public void restorePatchAttributes(Database original, Database updated) { public void restorePatchAttributes(Database original, Database updated) {
// Patch can't make changes to following fields. Ignore the changes // Patch can't make changes to following fields. Ignore the changes
updated super.restorePatchAttributes(original, updated);
.withFullyQualifiedName(original.getFullyQualifiedName()) updated.withService(original.getService());
.withName(original.getName())
.withService(original.getService())
.withId(original.getId());
} }
@Override @Override

View File

@ -124,11 +124,8 @@ public class DatabaseSchemaRepository extends EntityRepository<DatabaseSchema> {
@Override @Override
public void restorePatchAttributes(DatabaseSchema original, DatabaseSchema updated) { public void restorePatchAttributes(DatabaseSchema original, DatabaseSchema updated) {
// Patch can't make changes to following fields. Ignore the changes // Patch can't make changes to following fields. Ignore the changes
updated super.restorePatchAttributes(original, updated);
.withFullyQualifiedName(original.getFullyQualifiedName()) updated.withService(original.getService());
.withName(original.getName())
.withService(original.getService())
.withId(original.getId());
} }
@Override @Override

View File

@ -43,12 +43,6 @@ public class DocumentRepository extends EntityRepository<Document> {
doc.setFullyQualifiedName(doc.getFullyQualifiedName()); doc.setFullyQualifiedName(doc.getFullyQualifiedName());
} }
@Override
public void restorePatchAttributes(Document original, Document updated) {
// Patch can't make changes to following fields. Ignore the changes
updated.withName(original.getName()).withId(original.getId());
}
@Override @Override
public Document setFields(Document document, Fields fields) { public Document setFields(Document document, Fields fields) {
return document; return document;

View File

@ -97,6 +97,7 @@ public class DomainRepository extends EntityRepository<Domain> {
@Override @Override
public void restorePatchAttributes(Domain original, Domain updated) { public void restorePatchAttributes(Domain original, Domain updated) {
super.restorePatchAttributes(original, updated);
updated.withParent(original.getParent()); // Parent can't be changed updated.withParent(original.getParent()); // Parent can't be changed
updated.withChildren(original.getChildren()); // Children can't be changed updated.withChildren(original.getChildren()); // Children can't be changed
} }

View File

@ -211,6 +211,7 @@ public abstract class EntityRepository<T extends EntityInterface> {
@Getter protected final boolean supportsReviewers; @Getter protected final boolean supportsReviewers;
@Getter protected final boolean supportsExperts; @Getter protected final boolean supportsExperts;
protected boolean quoteFqn = false; // Entity FQNS not hierarchical such user, teams, services need to be quoted protected boolean quoteFqn = false; // Entity FQNS not hierarchical such user, teams, services need to be quoted
protected boolean renameAllowed = false; // Entity can be renamed
/** Fields that can be updated during PATCH operation */ /** Fields that can be updated during PATCH operation */
@Getter private final Fields patchFields; @Getter private final Fields patchFields;
@ -370,7 +371,10 @@ public abstract class EntityRepository<T extends EntityInterface> {
* stored in the original entity. * stored in the original entity.
*/ */
public void restorePatchAttributes(T original, T updated) { public void restorePatchAttributes(T original, T updated) {
/* Nothing to restore during PATCH */ updated.setId(original.getId());
updated.setName(renameAllowed ? updated.getName() : original.getName());
updated.setFullyQualifiedName(original.getFullyQualifiedName());
updated.setChangeDescription(original.getChangeDescription());
} }
/** Set fullyQualifiedName of an entity */ /** Set fullyQualifiedName of an entity */

View File

@ -93,11 +93,6 @@ public class EventSubscriptionRepository extends EntityRepository<EventSubscript
// No relationships to store beyond what is stored in the super class // No relationships to store beyond what is stored in the super class
} }
@Override
public void restorePatchAttributes(EventSubscription original, EventSubscription updated) {
updated.withId(original.getId()).withName(original.getName());
}
private SubscriptionPublisher getPublisher(UUID id) { private SubscriptionPublisher getPublisher(UUID id) {
return subscriptionPublisherMap.get(id); return subscriptionPublisherMap.get(id);
} }

View File

@ -269,6 +269,7 @@ public class GlossaryRepository extends EntityRepository<Glossary> {
public class GlossaryUpdater extends EntityUpdater { public class GlossaryUpdater extends EntityUpdater {
public GlossaryUpdater(Glossary original, Glossary updated, Operation operation) { public GlossaryUpdater(Glossary original, Glossary updated, Operation operation) {
super(original, updated, operation); super(original, updated, operation);
renameAllowed = true;
} }
@Transaction @Transaction
@ -285,6 +286,7 @@ public class GlossaryRepository extends EntityRepository<Glossary> {
} }
// Glossary name changed - update tag names starting from glossary and all the children tags // Glossary name changed - update tag names starting from glossary and all the children tags
LOG.info("Glossary name changed from {} to {}", original.getName(), updated.getName()); LOG.info("Glossary name changed from {} to {}", original.getName(), updated.getName());
setFullyQualifiedName(updated);
daoCollection.glossaryTermDAO().updateFqn(original.getName(), updated.getName()); daoCollection.glossaryTermDAO().updateFqn(original.getName(), updated.getName());
daoCollection daoCollection
.tagUsageDAO() .tagUsageDAO()

View File

@ -82,6 +82,7 @@ public class GlossaryTermRepository extends EntityRepository<GlossaryTerm> {
PATCH_FIELDS, PATCH_FIELDS,
UPDATE_FIELDS); UPDATE_FIELDS);
supportsSearch = true; supportsSearch = true;
renameAllowed = true;
} }
@Override @Override
@ -177,6 +178,7 @@ public class GlossaryTermRepository extends EntityRepository<GlossaryTerm> {
@Override @Override
public void restorePatchAttributes(GlossaryTerm original, GlossaryTerm updated) { public void restorePatchAttributes(GlossaryTerm original, GlossaryTerm updated) {
// Patch can't update Children // Patch can't update Children
super.restorePatchAttributes(original, updated);
updated.withChildren(original.getChildren()); updated.withChildren(original.getChildren());
} }
@ -435,6 +437,7 @@ public class GlossaryTermRepository extends EntityRepository<GlossaryTerm> {
CatalogExceptionMessage.systemEntityRenameNotAllowed(original.getName(), entityType)); CatalogExceptionMessage.systemEntityRenameNotAllowed(original.getName(), entityType));
} }
// Glossary term name changed - update the FQNs of the children terms to reflect this // Glossary term name changed - update the FQNs of the children terms to reflect this
setFullyQualifiedName(updated);
LOG.info("Glossary term name changed from {} to {}", original.getName(), updated.getName()); LOG.info("Glossary term name changed from {} to {}", original.getName(), updated.getName());
daoCollection.glossaryTermDAO().updateFqn(original.getFullyQualifiedName(), updated.getFullyQualifiedName()); daoCollection.glossaryTermDAO().updateFqn(original.getFullyQualifiedName(), updated.getFullyQualifiedName());
daoCollection daoCollection
@ -455,6 +458,7 @@ public class GlossaryTermRepository extends EntityRepository<GlossaryTerm> {
UUID newGlossaryId = getId(updated.getGlossary()); UUID newGlossaryId = getId(updated.getGlossary());
boolean glossaryChanged = !Objects.equals(oldGlossaryId, newGlossaryId); boolean glossaryChanged = !Objects.equals(oldGlossaryId, newGlossaryId);
setFullyQualifiedName(updated); // Update the FQN since the parent has changed
daoCollection.glossaryTermDAO().updateFqn(original.getFullyQualifiedName(), updated.getFullyQualifiedName()); daoCollection.glossaryTermDAO().updateFqn(original.getFullyQualifiedName(), updated.getFullyQualifiedName());
daoCollection daoCollection
.tagUsageDAO() .tagUsageDAO()

View File

@ -103,11 +103,8 @@ public class MlModelRepository extends EntityRepository<MlModel> {
@Override @Override
public void restorePatchAttributes(MlModel original, MlModel updated) { public void restorePatchAttributes(MlModel original, MlModel updated) {
// Patch can't make changes to following fields. Ignore the changes // Patch can't make changes to following fields. Ignore the changes
updated super.restorePatchAttributes(original, updated);
.withFullyQualifiedName(original.getFullyQualifiedName()) updated.withService(original.getService());
.withService(original.getService())
.withName(original.getName())
.withId(original.getId());
} }
private void setMlFeatureSourcesFQN(List<MlFeatureSource> mlSources) { private void setMlFeatureSourcesFQN(List<MlFeatureSource> mlSources) {

View File

@ -56,12 +56,6 @@ public class PersonaRepository extends EntityRepository<Persona> {
return persona; return persona;
} }
@Override
public void restorePatchAttributes(Persona original, Persona updated) {
// Patch can't make changes to following fields. Ignore the changes
updated.withName(original.getName()).withId(original.getId());
}
@Override @Override
public void prepare(Persona persona, boolean update) { public void prepare(Persona persona, boolean update) {
validateUsers(persona.getUsers()); validateUsers(persona.getUsers());

View File

@ -210,11 +210,8 @@ public class PipelineRepository extends EntityRepository<Pipeline> {
@Override @Override
public void restorePatchAttributes(Pipeline original, Pipeline updated) { public void restorePatchAttributes(Pipeline original, Pipeline updated) {
// Patch can't make changes to following fields. Ignore the changes // Patch can't make changes to following fields. Ignore the changes
updated super.restorePatchAttributes(original, updated);
.withFullyQualifiedName(original.getFullyQualifiedName()) updated.withService(original.getService());
.withName(original.getName())
.withService(original.getService())
.withId(original.getId());
} }
@Override @Override

View File

@ -65,12 +65,6 @@ public class RoleRepository extends EntityRepository<Role> {
return findFrom(role.getId(), Entity.ROLE, Relationship.HAS, Entity.TEAM); return findFrom(role.getId(), Entity.ROLE, Relationship.HAS, Entity.TEAM);
} }
@Override
public void restorePatchAttributes(Role original, Role updated) {
// Patch can't make changes to following fields. Ignore the changes
updated.withName(original.getName()).withId(original.getId());
}
/** /**
* If policy does not exist for this role, create a new entity reference. The actual policy gets created within the * If policy does not exist for this role, create a new entity reference. The actual policy gets created within the
* storeEntity method call. * storeEntity method call.

View File

@ -170,12 +170,8 @@ public class TableRepository extends EntityRepository<Table> {
@Override @Override
public void restorePatchAttributes(Table original, Table updated) { public void restorePatchAttributes(Table original, Table updated) {
// Patch can't make changes to following fields. Ignore the changes. // Patch can't make changes to following fields. Ignore the changes.
updated super.restorePatchAttributes(original, updated);
.withFullyQualifiedName(original.getFullyQualifiedName()) updated.withDatabase(original.getDatabase()).withService(original.getService());
.withName(original.getName())
.withDatabase(original.getDatabase())
.withService(original.getService())
.withId(original.getId());
} }
@Override @Override

View File

@ -41,6 +41,7 @@ public class TagRepository extends EntityRepository<Tag> {
public TagRepository() { public TagRepository() {
super(TagResource.TAG_COLLECTION_PATH, Entity.TAG, Tag.class, Entity.getCollectionDAO().tagDAO(), "", ""); super(TagResource.TAG_COLLECTION_PATH, Entity.TAG, Tag.class, Entity.getCollectionDAO().tagDAO(), "", "");
supportsSearch = true; supportsSearch = true;
renameAllowed = true;
} }
@Override @Override
@ -67,6 +68,7 @@ public class TagRepository extends EntityRepository<Tag> {
@Override @Override
public void restorePatchAttributes(Tag original, Tag updated) { public void restorePatchAttributes(Tag original, Tag updated) {
super.restorePatchAttributes(original, updated);
updated.setChildren(original.getChildren()); updated.setChildren(original.getChildren());
} }
@ -153,6 +155,7 @@ public class TagRepository extends EntityRepository<Tag> {
} }
// Category name changed - update tag names starting from classification and all the children tags // Category name changed - update tag names starting from classification and all the children tags
LOG.info("Tag name changed from {} to {}", original.getName(), updated.getName()); LOG.info("Tag name changed from {} to {}", original.getName(), updated.getName());
setFullyQualifiedName(updated);
daoCollection.tagDAO().updateFqn(original.getFullyQualifiedName(), updated.getFullyQualifiedName()); daoCollection.tagDAO().updateFqn(original.getFullyQualifiedName(), updated.getFullyQualifiedName());
daoCollection daoCollection
.tagUsageDAO() .tagUsageDAO()
@ -176,6 +179,7 @@ public class TagRepository extends EntityRepository<Tag> {
UUID newCategoryId = getId(updated.getClassification()); UUID newCategoryId = getId(updated.getClassification());
boolean classificationChanged = !Objects.equals(oldCategoryId, newCategoryId); boolean classificationChanged = !Objects.equals(oldCategoryId, newCategoryId);
setFullyQualifiedName(updated);
daoCollection.tagDAO().updateFqn(original.getFullyQualifiedName(), updated.getFullyQualifiedName()); daoCollection.tagDAO().updateFqn(original.getFullyQualifiedName(), updated.getFullyQualifiedName());
daoCollection daoCollection
.tagUsageDAO() .tagUsageDAO()

View File

@ -125,7 +125,7 @@ public class TeamRepository extends EntityRepository<Team> {
@Override @Override
public void restorePatchAttributes(Team original, Team updated) { public void restorePatchAttributes(Team original, Team updated) {
// Patch can't make changes to following fields. Ignore the changes // Patch can't make changes to following fields. Ignore the changes
updated.withName(original.getName()).withId(original.getId()); super.restorePatchAttributes(original, updated);
updated.withInheritedRoles(original.getInheritedRoles()); updated.withInheritedRoles(original.getInheritedRoles());
} }

View File

@ -136,9 +136,8 @@ public class UserRepository extends EntityRepository<User> {
@Override @Override
public void restorePatchAttributes(User original, User updated) { public void restorePatchAttributes(User original, User updated) {
// Patch can't make changes to following fields. Ignore the changes // Patch can't make changes to following fields. Ignore the changes
super.restorePatchAttributes(original, updated);
updated updated
.withId(original.getId())
.withName(original.getName())
.withInheritedRoles(original.getInheritedRoles()) .withInheritedRoles(original.getInheritedRoles())
.withAuthenticationMechanism(original.getAuthenticationMechanism()); .withAuthenticationMechanism(original.getAuthenticationMechanism());
} }