Menu
Introduction
Getting Started
Developer guide
Release
Architecture
CLI
Technical documentations
Version
Publication date

Mar 9, 2022

Confidentiality
Public
Reactions
1
Share

EntityNavigator

Navigate the lineage graph of scenarios, resources, views and notes.

A navigator wraps a set of entities of one type and exposes traversals to their direct and transitive neighbors (next/previous), plus tag propagation over the same graph.

Two traversal flavors coexist and are intentionally separate:

  • get_next_entities_recursive / get_previous_entities_recursive collect every reachable entity into a flat NavigableEntitySet (with depth info) and discard edge information. Use these for "what's impacted" queries.
  • propagate_tags / delete_propagated_tags walk the same graph but must preserve per-edge provenance: each propagated tag carries an origin (TagOrigin) describing the immediate upstream entity that caused it. Because the origin depends on the edge kind (e.g. resource->view vs. resource->resource), these methods cannot be expressed on top of the flat-set recursion without losing attribution.

Both flavors apply the same two performance rules: hoist get_next_*()/get_previous_*() queries out of per-entity loops, and skip already-visited entities so reconverging paths don't re-walk subgraphs.

Functions
__init__

Initialize self. See help(type(self)) for accurate signature.

entities : Union
delete_propagated_tags

Remove previously propagated copies of tags from every reachable downstream entity.

Inverse of propagate_tags -- traverses the same graph with the same per-edge origin attribution and deletes the matching tag entries. See propagate_tags for why this cannot be expressed on top of get_next_entities_recursive.

tags : list
tags whose propagated copies should be removed.
entity_tags_cache : dict[gws_core.entity_navigator.entity_navigator_type.NavigableEntity, gws_core.tag.entity_tag_list.EntityTagList] | None
shared cache mapping entity to its tag list, populated as the walk progresses.
visited : set[gws_core.entity_navigator.entity_navigator_type.NavigableEntity] | None
get_as_nav_set

Wrap the current entities as a depth-0 NavigableEntitySet.

Return type : NavigableEntitySet
get_entities_as_set

Return the wrapped entities as a set.

Return type : set
get_entities_list

Return the wrapped entities as a list. Order is not guaranteed (the underlying storage is a set).

Return type : list
get_first_entity

Return an arbitrary entity from the set, or None if empty.

Useful when the caller knows the navigator wraps a single entity.

Return type : Optional
get_next_entities

Return the direct downstream neighbors of the wrapped entities.

Only one hop is followed (no recursion). Entities of any type listed in requested_entities are merged into a single NavigableEntitySet.

requested_entities : list
Return type : NavigableEntitySet
get_next_entities_recursive

Return every entity transitively reachable downstream.

Traverses the lineage graph breadth-first. Each entity is visited once, annotated with its depth in the returned NavigableEntitySet. Use this for impact analysis ("what entities would be affected"). Edge-level provenance is not preserved -- if you need to know which immediate upstream caused a given downstream to be reached, use propagate_tags instead.

requested_entities : list[gws_core.entity_navigator.entity_navigator_type.NavigableEntityType] | None
entity types to consider during traversal. Defaults to all four navigable types.
include_current_entities : bool - False
Return type : NavigableEntitySet
get_next_notes

Return the direct downstream notes. Empty by default; overridden by subclasses whose entity type has a notes-edge in the lineage graph.

Return type : EntityNavigatorNote
get_next_resources

Return the direct downstream resources. Empty by default; overridden by subclasses.

Return type : EntityNavigatorResource
get_next_scenarios

Return the direct downstream scenarios. Empty by default; overridden by subclasses.

Return type : EntityNavigatorScenario
get_next_views

Return the direct downstream views. Empty by default; overridden by subclasses.

Return type : EntityNavigatorView
get_previous_entities_recursive

Return every entity transitively reachable upstream.

Mirror of get_next_entities_recursive but walks the lineage graph in the opposite direction (towards ancestors).

requested_entities : list[gws_core.entity_navigator.entity_navigator_type.NavigableEntityType] | None
entity types to consider during traversal. Defaults to all four navigable types.
include_current_entities : bool - False
Return type : NavigableEntitySet
get_previous_notes

Return the direct upstream notes. Empty by default; overridden by subclasses.

Return type : EntityNavigatorNote
get_previous_resources

Return the direct upstream resources. Empty by default; overridden by subclasses.

Return type : EntityNavigatorResource
get_previous_scenarios

Return the direct upstream scenarios. Empty by default; overridden by subclasses.

Return type : EntityNavigatorScenario
get_previous_views

Return the direct upstream views. Empty by default; overridden by subclasses.

Return type : EntityNavigatorView
has_entities

Return True if at least one entity is wrapped.

Return type : bool
has_next_entities

Return True if any direct downstream neighbor exists.

requested_entities : list[gws_core.entity_navigator.entity_navigator_type.NavigableEntityType] | None
Return type : bool
is_empty

Return True if no entities are wrapped.

Return type : bool
propagate_tags

Propagate the given tags to every transitively reachable downstream entity.

Each propagated tag carries an origin (TagOrigin) describing the immediate upstream entity that caused it -- this is why we cannot reuse get_next_entities_recursive here: that method flattens the graph and discards edge information, while propagation needs per-edge attribution. The origin's type and id depend on the edge kind: scenario->resource yields SCENARIO_PROPAGATED, resource->next-resource yields TASK_PROPAGATED, resource->view yields RESOURCE_PROPAGATED, view->note yields VIEW_PROPAGATED.

Performance: get_next_*() queries are hoisted out of the per-entity loop, and visited tracks entities whose downstream has already been walked so reconverging paths in the DAG don't re-walk subgraphs.

tags : list
tags to propagate. Their origin is set per edge during the walk.
entity_tags_cache : dict[gws_core.entity_navigator.entity_navigator_type.NavigableEntity, gws_core.tag.entity_tag_list.EntityTagList] | None
shared cache mapping entity to its tag list, populated as the walk progresses. Pass ``None`` for top-level calls; recursive calls thread the same cache through.
visited : set[gws_core.entity_navigator.entity_navigator_type.NavigableEntity] | None
from_entity_id @classmethod

Build the appropriate concrete navigator for a single entity, by type and id.

Raises if the entity does not exist or if entity_type is unknown.

entity_type : NavigableEntityType
entity_id : str
Return type : EntityNavigator
Shine Logo
Technical bricks to reuse or customize

Have you developed a brick?

Share it to accelerate projects for the entire community.