Skip to main content

Traverse categories

You can populate glossaries in Atlan with arbitrarily deep category hierarchies.

To traverse these categories efficiently (without retrieving each level through a separate API call) you need to search for all categories in a glossary and reconstruct the hierarchy in-memory. This reconstruction can be cumbersome, so we've provided a helper method for that in the SDKs.

Retrieve hierarchy

To retrieve a traversable hierarchy for a glossary:

Retrieve traversable hierarchy
Glossary glossary = Glossary.findByName(client, "Concepts"); // (1)
Glossary.CategoryHierarchy tree = glossary.getHierarchy(client); // (2)
  1. Start by retrieving the glossary itself, for example using Glossary.findByName(). The glossary object used must have its qualifiedName present, so if you already know the qualifiedName you could also use Glossary._internal().qualifiedName("...").build(); as a shortcut, which doesn't require making any API call. Because this operation will lookup the asset in Atlan, you must provide it an AtlanClient through which to connect to the tenant.
  2. Call the .getHierarchy() method on the glossary to retrieve a traversable Glossary.CategoryHierarchy object. Because this operation will lookup the asset in Atlan, you must provide it an AtlanClient through which to connect to the tenant.
More details

The .getHierarchy() method will only retrieve the bare minimum information about each category (its GUID, qualifiedName and name). If you want to retrieve additional details, such as the terms in that category or certificate for the category, you need to pass these as an additional argument. To do this, use the .getHierarchy(AtlanClient, List<String>) method, and pass a list of strings giving the names of any additional attributes you want to retrieve for each category. (For example, to retrieve terms you would use terms, for certificates you would use certificateStatus.)

Traverse hierarchy

To traverse the hierarchy of categories you then have a few options.

Depth-first traversal

To list every category in the hierarchy in depth-first order:

Traverse the hierarchy depth-first
List<IGlossaryCategory> dfs = tree.depthFirst(); // (1)
for (GlossaryCategory category : dfs)
  1. The .depthFirst() method will return an ordered list of all the categories in the glossary, ordered by a depth-first traversal.
  2. You can then iterate through them in this particular order.

Breadth-first traversal

To list every category in the hierarchy in breadth-first order:

Traverse the hierarchy breadth-first
List<IGlossaryCategory> bfs = tree.breadthFirst(); // (1)
for (GlossaryCategory category : bfs)
  1. The .breadthFirst() method will return an ordered list of all the categories in the glossary, ordered by a breadth-first traversal.
  2. You can then iterate through them in this particular order.

Build-your-own traversal

Alternatively, you may want to iterate through the hierarchy in your own order. From the traversable hierarchy you can retrieve the top-level categories, and then decide what to do from there:

Traverse the hierarchy as you like, starting from the top
for (IGlossaryCategory top : tree.getRootCategories())
}
}
  1. The .getRootCategories() method will return a list of only those categories at the root of the glossary. (The categories that have no parent categories themselves.)
  2. You can then retrieve the child categories using .getChildrenCategories(). And you can do this iteratively as you traverse down the hierarchy.
Was this page helpful?