From ee879e589fe21fa552159acf8e787bc839697b19 Mon Sep 17 00:00:00 2001 From: Christopher Grote Date: Tue, 15 Oct 2024 09:53:05 +0100 Subject: [PATCH 1/2] Fix model asset references to use version-agnostic QN Signed-off-by: Christopher Grote --- .../atlan/pkg/serde/cell/AssetRefXformer.kt | 5 +- .../atlan/pkg/serde/cell/ModelAssetXformer.kt | 84 +++++++++++++++++++ 2 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 package-toolkit/runtime/src/main/kotlin/com/atlan/pkg/serde/cell/ModelAssetXformer.kt diff --git a/package-toolkit/runtime/src/main/kotlin/com/atlan/pkg/serde/cell/AssetRefXformer.kt b/package-toolkit/runtime/src/main/kotlin/com/atlan/pkg/serde/cell/AssetRefXformer.kt index 3cf7935a9e..e485dee124 100644 --- a/package-toolkit/runtime/src/main/kotlin/com/atlan/pkg/serde/cell/AssetRefXformer.kt +++ b/package-toolkit/runtime/src/main/kotlin/com/atlan/pkg/serde/cell/AssetRefXformer.kt @@ -9,6 +9,7 @@ import com.atlan.model.assets.DataProduct import com.atlan.model.assets.Glossary import com.atlan.model.assets.GlossaryCategory import com.atlan.model.assets.GlossaryTerm +import com.atlan.model.assets.IModel import com.atlan.model.assets.Link import com.atlan.model.assets.Readme import com.atlan.pkg.Utils @@ -22,7 +23,7 @@ import java.util.concurrent.atomic.AtomicLong * Static object to transform asset references. */ object AssetRefXformer { - private const val TYPE_QN_DELIMITER = "@" + const val TYPE_QN_DELIMITER = "@" /** * Encodes (serializes) an asset reference into a string form. @@ -46,6 +47,7 @@ object AssetRefXformer { is GlossaryCategory -> GlossaryCategoryXformer.encode(asset) is GlossaryTerm -> GlossaryTermXformer.encode(asset) is DataDomain -> DataDomainXformer.encode(asset) + is IModel -> ModelAssetXformer.encode(asset) else -> { var qualifiedName = asset.qualifiedName if (asset.qualifiedName.isNullOrEmpty() && asset.uniqueAttributes != null) { @@ -76,6 +78,7 @@ object AssetRefXformer { GlossaryCategory.ANCHOR.atlanFieldName -> GlossaryXformer.decode(assetRef, fieldName) "assignedTerms", in GlossaryTermXformer.TERM_TO_TERM_FIELDS -> GlossaryTermXformer.decode(assetRef, fieldName) DataDomain.PARENT_DOMAIN.atlanFieldName, DataProduct.DATA_DOMAIN.atlanFieldName -> DataDomainXformer.decode(assetRef, fieldName) + in ModelAssetXformer.MODEL_ASSET_REF_FIELDS -> ModelAssetXformer.decode(assetRef, fieldName) else -> { val tokens = assetRef.split(TYPE_QN_DELIMITER) val typeName = tokens[0] diff --git a/package-toolkit/runtime/src/main/kotlin/com/atlan/pkg/serde/cell/ModelAssetXformer.kt b/package-toolkit/runtime/src/main/kotlin/com/atlan/pkg/serde/cell/ModelAssetXformer.kt new file mode 100644 index 0000000000..772958afb7 --- /dev/null +++ b/package-toolkit/runtime/src/main/kotlin/com/atlan/pkg/serde/cell/ModelAssetXformer.kt @@ -0,0 +1,84 @@ +/* SPDX-License-Identifier: Apache-2.0 + Copyright 2023 Atlan Pte. Ltd. */ +package com.atlan.pkg.serde.cell + +import com.atlan.model.assets.Asset +import com.atlan.model.assets.IModel +import com.atlan.model.assets.ModelAttribute +import com.atlan.model.assets.ModelAttributeAssociation +import com.atlan.model.assets.ModelDataModel +import com.atlan.model.assets.ModelEntity +import com.atlan.model.assets.ModelEntityAssociation +import com.atlan.model.assets.ModelVersion +import com.atlan.pkg.serde.cell.AssetRefXformer.TYPE_QN_DELIMITER + +/** + * Static object to transform term references. + */ +object ModelAssetXformer { + val MODEL_ASSET_REF_FIELDS = + setOf( + ModelDataModel.MODEL_VERSIONS.atlanFieldName, + ModelVersion.MODEL_DATA_MODEL.atlanFieldName, + ModelVersion.MODEL_VERSION_ENTITIES.atlanFieldName, + ModelEntity.MODEL_ENTITY_ATTRIBUTES.atlanFieldName, + ModelEntity.MODEL_ENTITY_MAPPED_FROM_ENTITIES.atlanFieldName, + ModelEntity.MODEL_ENTITY_MAPPED_TO_ENTITIES.atlanFieldName, + ModelEntity.MODEL_ENTITY_RELATED_FROM_ENTITIES.atlanFieldName, + ModelEntity.MODEL_ENTITY_RELATED_TO_ENTITIES.atlanFieldName, + ModelEntity.MODEL_VERSIONS, + ModelAttribute.MODEL_ATTRIBUTE_ENTITIES.atlanFieldName, + ModelAttribute.MODEL_ATTRIBUTE_MAPPED_FROM_ATTRIBUTES.atlanFieldName, + ModelAttribute.MODEL_ATTRIBUTE_MAPPED_TO_ATTRIBUTES.atlanFieldName, + ModelAttribute.MODEL_ATTRIBUTE_RELATED_FROM_ATTRIBUTES.atlanFieldName, + ModelAttribute.MODEL_ATTRIBUTE_RELATED_TO_ATTRIBUTES.atlanFieldName, + ModelEntityAssociation.MODEL_ENTITY_ASSOCIATION_FROM.atlanFieldName, + ModelEntityAssociation.MODEL_ENTITY_ASSOCIATION_TO.atlanFieldName, + ModelAttributeAssociation.MODEL_ATTRIBUTE_ASSOCIATION_FROM.atlanFieldName, + ModelAttributeAssociation.MODEL_ATTRIBUTE_ASSOCIATION_TO.atlanFieldName, + ) + + /** + * Encodes (serializes) a term reference into a string form. + * + * @param asset to be encoded + * @return the string-encoded form for that asset + */ + fun encode(asset: Asset): String { + // Handle some assets as direct embeds + return when (asset) { + is IModel -> { + val ma = asset as IModel + "${ma.typeName}$TYPE_QN_DELIMITER${ma.modelVersionAgnosticQualifiedName}" + } + else -> AssetRefXformer.encode(asset) + } + } + + /** + * Decodes (deserializes) a string form into a term reference object. + * + * @param assetRef the string form to be decoded + * @param fieldName the name of the field containing the string-encoded value + * @return the term reference represented by the string + */ + fun decode( + assetRef: String, + fieldName: String, + ): Asset { + return when (fieldName) { + in MODEL_ASSET_REF_FIELDS -> { + val tokens = assetRef.split(TYPE_QN_DELIMITER) + if (tokens.size > 1) { + ModelDataModel._internal() // start with a model so we have versionAgnosticQN + .typeName(tokens[0]) // override the type + .modelVersionAgnosticQualifiedName(assetRef.substringAfter(TYPE_QN_DELIMITER)) + .build() + } else { + throw NoSuchElementException("Model asset $assetRef not found (via $fieldName).") + } + } + else -> AssetRefXformer.decode(assetRef, fieldName) + } + } +} From 227f0f6c352e8f68001781bb4a1a66bb10ab5ed0 Mon Sep 17 00:00:00 2001 From: Christopher Grote Date: Tue, 15 Oct 2024 09:54:40 +0100 Subject: [PATCH 2/2] Dependency bump Signed-off-by: Christopher Grote --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 32fa0b905c..b8f72cd12b 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -9,7 +9,7 @@ log4j = "2.24.1" wiremock = "3.9.1" jnanoid = "2.0.0" numaflow = "0.8.0" -awssdk = "2.28.21" +awssdk = "2.28.22" gcs = "26.48.0" system-stubs = "2.1.7" fastcsv = "3.3.1"