Skip to content

Commit

Permalink
Merge pull request #56 from atlanhq/DVX-612-Add-GetbyQualifiedName
Browse files Browse the repository at this point in the history
DVX-612: feat: Added GetByQualifiedName Method
  • Loading branch information
0xquark authored Sep 5, 2024
2 parents 76897fd + 368adf8 commit 5a43679
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
32 changes: 32 additions & 0 deletions atlan/assets/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions atlan/assets/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
17 changes: 14 additions & 3 deletions atlan/assets/glossary_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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) {
Expand All @@ -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 {
Expand Down

0 comments on commit 5a43679

Please sign in to comment.