diff --git a/atlan/assets/index_search_client.go b/atlan/assets/index_search_client.go index d547bbc..62ab12a 100644 --- a/atlan/assets/index_search_client.go +++ b/atlan/assets/index_search_client.go @@ -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. diff --git a/atlan/assets/persona_client.go b/atlan/assets/persona_client.go index f9066e7..4a15ee2 100644 --- a/atlan/assets/persona_client.go +++ b/atlan/assets/persona_client.go @@ -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" ) @@ -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. @@ -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 } diff --git a/main.go b/main.go index 0e66fab..06c614d 100644 --- a/main.go +++ b/main.go @@ -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)