Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FT-845: Implement FindPersonasByName() Method #69

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading