From b8a3da0322aa460b2c8742d3c335b82e89996826 Mon Sep 17 00:00:00 2001 From: Karanjot Singh Date: Tue, 3 Sep 2024 19:37:10 +0530 Subject: [PATCH 1/2] feat: Added GetByQualifiedName Method Signed-off-by: Karanjot Singh --- atlan/assets/asset.go | 32 ++++++++++++++++++++++++++++++++ atlan/assets/constants.go | 7 +++++++ 2 files changed, 39 insertions(+) diff --git a/atlan/assets/asset.go b/atlan/assets/asset.go index bdec0c6..c312d6f 100644 --- a/atlan/assets/asset.go +++ b/atlan/assets/asset.go @@ -773,6 +773,38 @@ func GetByGuid[T AtlanObject](guid string) (T, error) { return newAsset, nil } +func GetByQualifiedName[T AtlanObject](qualifiedName string) (T, error) { + + var asset T + + if DefaultAtlanClient == nil { + return asset, fmt.Errorf("default AtlanClient not initialized") + } + + api := &GET_ENTITY_BY_UNIQUE_ATTRIBUTE + api.Path += reflect.TypeOf(asset).Elem().Name() + + queryParams := map[string]string{ + "attr:qualifiedName": qualifiedName, + } + + response, err := DefaultAtlanClient.CallAPI(api, queryParams, nil) + if err != nil { + return asset, err + } + + // Create a new instance of T using reflection + assetType := reflect.TypeOf(asset).Elem() + newAsset := reflect.New(assetType).Interface().(T) + + err = newAsset.FromJSON(response) + if err != nil { + return asset, err + } + + return newAsset, nil +} + // RetrieveMinimal retrieves an asset by its GUID, without any of its relationships. func RetrieveMinimal(guid string) (*structs.Asset, error) { if DefaultAtlanClient == nil { diff --git a/atlan/assets/constants.go b/atlan/assets/constants.go index 405da6a..fc9a662 100644 --- a/atlan/assets/constants.go +++ b/atlan/assets/constants.go @@ -106,6 +106,13 @@ var ( Endpoint: AtlasEndpoint, } + GET_ENTITY_BY_UNIQUE_ATTRIBUTE = API{ + Path: ENTITY_API + "uniqueAttribute/type/", + Method: http.MethodGet, + Status: http.StatusOK, + Endpoint: AtlasEndpoint, + } + INDEX_SEARCH = API{ Path: "search/indexsearch/", Method: http.MethodPost, From 368adf81305145dc4112790828bc455584a4ca9f Mon Sep 17 00:00:00 2001 From: Karanjot Singh Date: Tue, 3 Sep 2024 20:09:14 +0530 Subject: [PATCH 2/2] test: Added test for retrieval of glossary by QualifiedName Signed-off-by: Karanjot Singh --- atlan/assets/glossary_client_test.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/atlan/assets/glossary_client_test.go b/atlan/assets/glossary_client_test.go index 96fdd81..0d467bd 100644 --- a/atlan/assets/glossary_client_test.go +++ b/atlan/assets/glossary_client_test.go @@ -16,13 +16,15 @@ func TestIntegrationGlossary(t *testing.T) { NewContext() - glossaryGUID := testCreateGlossary(t) + glossaryGUID, glossaryQualifiedName := testCreateGlossary(t) + fmt.Printf("glossaryQn: %v\n", glossaryQualifiedName) testUpdateGlossary(t, glossaryGUID) testRetrieveGlossary(t, glossaryGUID) + testRetrieveGlossarybyQualifiedName(t, glossaryQualifiedName) testDeleteGlossary(t, glossaryGUID) } -func testCreateGlossary(t *testing.T) string { +func testCreateGlossary(t *testing.T) (string, string) { g := &AtlasGlossary{} // Create Glossary g.Creator(GlossaryName, atlan.AtlanIconAirplaneInFlight) @@ -39,7 +41,7 @@ func testCreateGlossary(t *testing.T) string { assert.Equal(t, GlossaryName, *assetone.Attributes.Name, "glossary name should match") assert.Equal(t, *g.TypeName, assetone.TypeName, "glossary type should match") - return assetone.Guid + return assetone.Guid, *assetone.Attributes.QualifiedName } func testUpdateGlossary(t *testing.T, glossaryGUID string) { @@ -66,6 +68,15 @@ func testRetrieveGlossary(t *testing.T, glossaryGUID string) { assert.Equal(t, glossaryGUID, *glossary.Guid, "glossary guid should match") } +func testRetrieveGlossarybyQualifiedName(t *testing.T, glossaryQualifiedName string) { + glossary, err := GetByQualifiedName[*AtlasGlossary](glossaryQualifiedName) + if err != nil { + fmt.Println("Error:", err) + } + assert.NotNil(t, glossary, "fetched glossary should not be nil") + assert.Equal(t, glossaryQualifiedName, *glossary.QualifiedName, "glossary qualified name should match") +} + func testDeleteGlossary(t *testing.T, glossaryGUID string) { deleteresponse, err := PurgeByGuid([]string{glossaryGUID}) if err != nil {