Skip to content

Commit

Permalink
Merge pull request #69 from atlanhq/FT-845
Browse files Browse the repository at this point in the history
FT-845: Implement `FindPersonasByName()` Method
  • Loading branch information
0xquark authored Dec 5, 2024
2 parents f1eed6d + 89a157c commit 3c3339a
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
14 changes: 14 additions & 0 deletions atlan/assets/index_search_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,20 @@ func WithActiveCategory(name string, glossaryqualifiedname string) (*model.BoolQ
}, nil
}

// WithActivePersona returns a query for an active persona by name.
func WithActivePersona(name string) (*model.BoolQuery, error) {
q1, err := WithState("ACTIVE")
if err != nil {
return nil, err
}
q2 := WithTypeName("Persona")
q3 := WithName(name)

return &model.BoolQuery{
Filter: []model.Query{q1, q2, q3},
}, nil
}

// Helper Functions

// WithState returns a query for an entity with a specific state.
Expand Down
45 changes: 45 additions & 0 deletions atlan/assets/persona_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"github.com/atlanhq/atlan-go/atlan"
"github.com/atlanhq/atlan-go/atlan/model"
"github.com/atlanhq/atlan-go/atlan/model/structs"
)

Expand Down Expand Up @@ -210,6 +211,46 @@ func (p *Persona) Updater(qualifiedName, name string, isEnabled bool) error {
return nil
}

func FindPersonasByName(name string) (*model.IndexSearchResponse, error) {
if name == "" {
return nil, fmt.Errorf("name cannot be empty")
}
boolQuery, err := WithActivePersona(name)
if err != nil {
return nil, err
}
pageSize := 20

request := model.IndexSearchRequest{
Dsl: model.Dsl{
From: 0,
Size: pageSize,
Query: boolQuery.ToJSON(),
TrackTotalHits: true,
},
SuppressLogs: true,
ShowSearchScore: false,
ExcludeMeanings: false,
ExcludeAtlanTags: false,
}

iterator := NewIndexSearchIterator(pageSize, request)

for iterator.HasMoreResults() {
response, err := iterator.NextPage()
if err != nil {
return nil, fmt.Errorf("error executing search: %v", err)
}
fmt.Println("Current Page: ", iterator.CurrentPage())
for _, entity := range response.Entities {
if *entity.TypeName == "Persona" {
return response, err
}
}
}
return nil, nil
}

func (p *Persona) UnmarshalJSON(data []byte) error {

// Unmarshal shared fields and specific attributes.
Expand Down Expand Up @@ -318,6 +359,10 @@ func (p *Persona) MarshalJSON() ([]byte, error) {
attributes["displayName"] = *p.DisplayName
}

if p.Description != nil && *p.Description != "" {
attributes["description"] = *p.Description
}

if p.PersonaUsers != nil {
attributes["personaUsers"] = p.PersonaUsers
}
Expand Down
14 changes: 13 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,21 @@ func main() {
ctx := assets.NewContext()
ctx.EnableLogging("debug")

response, atlanErr := assets.FindPersonasByName("Test Persona")
if atlanErr != nil {
println("Error:", atlanErr)
} else {
for _, entity := range response.Entities {
if entity.TypeName != nil && *entity.TypeName == "Persona" {
println("Persona Found: Name:", *entity.Name, "QualifiedName:", *entity.QualifiedName)
}
}

}

/*
// Get Persona by Guid
response, atlanErr := assets.GetByGuid[*assets.Persona]("6f04ac74-d6b8-4b5e-8c1b-2347f9e55414")
if atlanErr != nil {
fmt.Println("Error:", atlanErr)
Expand Down

0 comments on commit 3c3339a

Please sign in to comment.