mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-10-27 16:55:06 +00:00
- Remove Migrate Tags (#16266)
This commit is contained in:
parent
77a8e42511
commit
1fcd545641
@ -58,7 +58,6 @@ import org.openmetadata.schema.entity.classification.Tag;
|
|||||||
import org.openmetadata.schema.type.EntityHistory;
|
import org.openmetadata.schema.type.EntityHistory;
|
||||||
import org.openmetadata.schema.type.Include;
|
import org.openmetadata.schema.type.Include;
|
||||||
import org.openmetadata.schema.type.MetadataOperation;
|
import org.openmetadata.schema.type.MetadataOperation;
|
||||||
import org.openmetadata.schema.type.Relationship;
|
|
||||||
import org.openmetadata.service.Entity;
|
import org.openmetadata.service.Entity;
|
||||||
import org.openmetadata.service.OpenMetadataApplicationConfig;
|
import org.openmetadata.service.OpenMetadataApplicationConfig;
|
||||||
import org.openmetadata.service.jdbi3.ClassificationRepository;
|
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.resources.EntityResource;
|
||||||
import org.openmetadata.service.security.Authorizer;
|
import org.openmetadata.service.security.Authorizer;
|
||||||
import org.openmetadata.service.util.EntityUtil;
|
import org.openmetadata.service.util.EntityUtil;
|
||||||
import org.openmetadata.service.util.JsonUtils;
|
|
||||||
import org.openmetadata.service.util.ResultList;
|
import org.openmetadata.service.util.ResultList;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@ -106,75 +104,9 @@ public class TagResource extends EntityResource<Tag, TagRepository> {
|
|||||||
return null;
|
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<Classification> classificationList =
|
|
||||||
classificationRepository.listAll(
|
|
||||||
classificationRepository.getFields("*"), new ListFilter(Include.ALL));
|
|
||||||
List<String> jsons =
|
|
||||||
repository.getDao().listAfter(new ListFilter(Include.ALL), Integer.MAX_VALUE, "");
|
|
||||||
List<Tag> 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
|
@Override
|
||||||
public void initialize(OpenMetadataApplicationConfig config) throws IOException {
|
public void initialize(OpenMetadataApplicationConfig config) throws IOException {
|
||||||
super.initialize(config);
|
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
|
// Find tag definitions and load classifications from the json file, if necessary
|
||||||
ClassificationRepository classificationRepository =
|
ClassificationRepository classificationRepository =
|
||||||
(ClassificationRepository) Entity.getEntityRepository(CLASSIFICATION);
|
(ClassificationRepository) Entity.getEntityRepository(CLASSIFICATION);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user