diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/resources/tags/TagResource.java b/openmetadata-service/src/main/java/org/openmetadata/service/resources/tags/TagResource.java index b90515a708a..96fa08d9032 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/resources/tags/TagResource.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/resources/tags/TagResource.java @@ -58,7 +58,6 @@ import org.openmetadata.schema.entity.classification.Tag; import org.openmetadata.schema.type.EntityHistory; import org.openmetadata.schema.type.Include; import org.openmetadata.schema.type.MetadataOperation; -import org.openmetadata.schema.type.Relationship; import org.openmetadata.service.Entity; import org.openmetadata.service.OpenMetadataApplicationConfig; import org.openmetadata.service.jdbi3.ClassificationRepository; @@ -69,7 +68,6 @@ import org.openmetadata.service.resources.Collection; import org.openmetadata.service.resources.EntityResource; import org.openmetadata.service.security.Authorizer; import org.openmetadata.service.util.EntityUtil; -import org.openmetadata.service.util.JsonUtils; import org.openmetadata.service.util.ResultList; @Slf4j @@ -106,75 +104,9 @@ public class TagResource extends EntityResource { return null; } - private void migrateTags() { - // Just want to run it when upgrading to version above 0.13.1 where tag relationship are not - // there , once we have any entries we don't need to run it - if (repository.getDaoCollection().relationshipDAO().findIfAnyRelationExist(CLASSIFICATION, TAG) - <= 0) { - // We are missing relationship for classification -> tag, & also tag -> tag (parent - // relationship). Find tag definitions and load classifications from the file, if necessary - ClassificationRepository classificationRepository = - (ClassificationRepository) Entity.getEntityRepository(CLASSIFICATION); - try { - List classificationList = - classificationRepository.listAll( - classificationRepository.getFields("*"), new ListFilter(Include.ALL)); - List jsons = - repository.getDao().listAfter(new ListFilter(Include.ALL), Integer.MAX_VALUE, ""); - List storedTags = JsonUtils.readObjects(jsons, Tag.class); - for (Tag tag : storedTags) { - if (tag.getFullyQualifiedName().contains(".")) { - // Either it has classification or a tag which is its parent - // Check Classification - String[] tokens = tag.getFullyQualifiedName().split("\\.", 2); - String classificationName = tokens[0]; - String remainingPart = tokens[1]; - for (Classification classification : classificationList) { - if (classification.getName().equals(classificationName)) { - // This means need to add a relationship - try { - repository.addRelationship( - classification.getId(), - tag.getId(), - CLASSIFICATION, - TAG, - Relationship.CONTAINS); - break; - } catch (Exception ex) { - LOG.info("Classification Relation already exists"); - } - } - } - if (remainingPart.contains(".")) { - // Handle tag -> tag relationship - String parentTagName = - tag.getFullyQualifiedName() - .substring(0, tag.getFullyQualifiedName().lastIndexOf(".")); - for (Tag parentTag : storedTags) { - if (parentTag.getFullyQualifiedName().equals(parentTagName)) { - try { - repository.addRelationship( - parentTag.getId(), tag.getId(), TAG, TAG, Relationship.CONTAINS); - break; - } catch (Exception ex) { - LOG.info("Parent Tag Ownership already exists"); - } - } - } - } - } - } - } catch (Exception ex) { - LOG.error("Failed in Listing all the Stored Tags."); - } - } - } - @Override public void initialize(OpenMetadataApplicationConfig config) throws IOException { super.initialize(config); - // TODO: Once we have migrated to the version above 0.13.1, then this can be removed - migrateTags(); // Find tag definitions and load classifications from the json file, if necessary ClassificationRepository classificationRepository = (ClassificationRepository) Entity.getEntityRepository(CLASSIFICATION);