Skip to content
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
16 changes: 16 additions & 0 deletions docs/release-notes/6.2.38.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# pyegeria 6.2.38

pyegeria 6.2.38 fixes two bugs found in the 6.2.37 live check.

## Fixed

- **The "DCAT Catalog" spec could not run a search-scoped catalog** (F-DCAT1, new in 6.2.37). Its file name was
`{scope}-dcat.jsonld`, so a run with `search_string` instead of `scope` was refused with "needs parameter 'scope'"
before the exporter ran. A DOCUMENT file-name field can now name alternatives, `{scope|search_string}`: the first
parameter the run supplies is used, made file-name safe as before. Both built-in specs ("DCAT Catalog" and
"DCAT Catalog (Turtle)") use it; a run with neither parameter is refused with "needs one of the parameters
'scope', 'search_string'".
- **My Egeria: selecting a business domain showed "No business domain data returned for GUID: ['BusinessCapability',
'…']"** (F-ME1). The domain tree stores `[type name, GUID]` on each node and the whole list was passed as the GUID.
The selection screen now passes the GUID; a leaf that stores nothing (domain members, glossary folder terms,
root-collection folders) passes its qualified-name label instead of `None`.
24 changes: 21 additions & 3 deletions my_egeria/my_egeria/SelectionOverviewScreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,25 @@
from profile_utils import set_screen_heading



def node_identifier(data, label=None):
"""The GUID or qualified name a selected tree node stands for (6.2.38, F-ME1).

Shop for Data's trees store it three ways: the domain tree stores `[type name, GUID]` (passing the
whole list as the GUID read "No business domain data returned for GUID: ['BusinessCapability', ...]"),
other leaves store the GUID or qualified name itself, and some leaves (domain members, glossary folder
terms, root-collection folders) store nothing and are named by their qualified name. A list gives its
last non-empty string; nothing gives the label's text."""
if isinstance(data, (list, tuple)):
strings = [d for d in data if isinstance(d, str) and d.strip()]
return strings[-1] if strings else None
if isinstance(data, str) and data.strip():
return data
if label is None:
return None
text = getattr(label, "plain", label)
return str(text) if str(text).strip() else None

class SelectionOverviewScreen(ModalScreen):
"""Screen to display the selection of the user's data sources."""
BINDINGS = [("escape", "back", "Back"),
Expand Down Expand Up @@ -110,9 +129,8 @@ def handle_tree_node_selected(self, event: Tree.NodeSelected):
# self.log(f"Node selected: {self.node_selected}")
self.node_label = self.node_selected.label
self.node_data = self.node_selected.data
# the provided id can be either a GUID or a qualified name!
# the variable is labeled guid but it could contain a qualified name, both guid and qualified name are strings.
self.node_GUID = self.node_selected.data
# the provided id can be either a GUID or a qualified name (both strings); see node_identifier.
self.node_GUID = node_identifier(self.node_selected.data, self.node_label)
# self.log(f"Node label: {self.node_label}, GUID: {self.node_GUID}")
if self.category == "glossary":
self.display_selected_term_details(self.node_GUID)
Expand Down
11 changes: 6 additions & 5 deletions pyegeria/view/base_report_formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -4718,26 +4718,27 @@ def list_report_specs(*, with_status: bool = False) -> list:
# analytic function export_dcat. Run with output_format "DOCUMENT" and a `scope` parameter.
"DCAT Catalog": FormatSet(
heading="DCAT Catalog",
description="A DCAT-AP 3 catalog (JSON-LD) of the Assets in a collection or folder, read as you. Give "
"`scope`: the collection's qualifiedName or GUID. DigitalProducts and Agreements are Bitol's "
description="A DCAT-AP 3 catalog (JSON-LD) of the Assets in a collection or folder (or of the assets matching a search), read as you. Give "
"`scope`: the collection's qualifiedName or GUID, or `search_string`. DigitalProducts and Agreements are Bitol's "
"and are named in the notes, not exported; validated against the vendored DCAT-AP 3.0.1 "
"SHACL shapes. Run with output_format DOCUMENT.",
family="Standard Documents",
target_type="Collection",
formats=[Format(types=["DOCUMENT"], document={
"standard": "dcat-ap-3", "media_type": "application/ld+json",
"file_name": "{scope}-dcat.jsonld", "validator": "dcat-ap-3-shacl"})],
"file_name": "{scope|search_string}-dcat.jsonld", "validator": "dcat-ap-3-shacl"})],
action=ActionParameter(analytic_function="export_dcat", analytic_spec_params={"format": "jsonld"}),
),
"DCAT Catalog (Turtle)": FormatSet(
heading="DCAT Catalog (Turtle)",
description="The DCAT Catalog document as Turtle: a DCAT-AP 3 catalog of the Assets in a collection or "
"folder, read as you. Give `scope`. Run with output_format DOCUMENT.",
"folder (or of the assets matching a search), read as you. Give `scope` or "
"`search_string`. Run with output_format DOCUMENT.",
family="Standard Documents",
target_type="Collection",
formats=[Format(types=["DOCUMENT"], document={
"standard": "dcat-ap-3", "media_type": "text/turtle",
"file_name": "{scope}-dcat.ttl", "validator": "dcat-ap-3-shacl"})],
"file_name": "{scope|search_string}-dcat.ttl", "validator": "dcat-ap-3-shacl"})],
action=ActionParameter(analytic_function="export_dcat", analytic_spec_params={"format": "turtle"}),
),
})
Expand Down
36 changes: 20 additions & 16 deletions pyegeria/view/format_set_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1306,28 +1306,32 @@ def _document_spec_struct(format_set_name: Any) -> Optional[Dict[str, Any]]:
def fill_document_file_name(template: str, params: Dict[str, Any]) -> str:
"""Fill a DOCUMENT file-name template from the run's parameters.

Only plain `{name}` fields are allowed (no attribute or index access). Each value is made
file-name safe (anything but letters, digits and `._+-` becomes `_`, and `..` is broken up),
so a qualifiedName such as `Folder::Sales/EU` cannot become a path. The result is checked
again; a template that still names a path, or a parameter the run did not supply, is refused
with a sentence."""
values: Dict[str, str] = {}
for _literal, field, spec, conversion in string.Formatter().parse(template):
A field is a plain parameter name, or alternatives separated by `|` (6.2.38): `{scope|search_string}`
takes the first one the run supplies, so one template serves an exporter that takes either. Nothing
else is allowed (no attribute or index access, no format spec). Each value is made file-name safe
(anything but letters, digits and `._+-` becomes `_`, and `..` is broken up), so a qualifiedName such
as `Folder::Sales/EU` cannot become a path. The result is checked again; a template that still names
a path, or a field none of whose parameters the run supplied, is refused with a sentence."""
out: List[str] = []
for literal, field, spec, conversion in string.Formatter().parse(template):
out.append(literal)
if field is None:
continue
if not field.isidentifier():
names = field.split("|")
if not all(n.isidentifier() for n in names):
raise ValueError(f"DOCUMENT file_name template '{template}' has field '{{{field}}}'; only plain "
f"parameter names are allowed")
f"parameter names (or alternatives a|b) are allowed")
if spec or conversion:
raise ValueError(f"DOCUMENT file_name template '{template}' formats field '{field}'; only plain "
f"parameter names are allowed")
raw = params.get(field)
if raw in (None, ""):
raise ValueError(f"DOCUMENT file_name template '{template}' needs parameter '{field}', which this "
f"run did not supply")
safe = _FILE_NAME_UNSAFE.sub("_", str(raw)).replace("..", "_").strip("._") or "_"
values[field] = safe
file_name = template.format(**values)
raw = next((params.get(n) for n in names if params.get(n) not in (None, "")), None)
if raw is None:
wanted = f"parameter '{names[0]}'" if len(names) == 1 else "one of the parameters " + ", ".join(
f"'{n}'" for n in names)
raise ValueError(f"DOCUMENT file_name template '{template}' needs {wanted}, which this run did not "
f"supply")
out.append(_FILE_NAME_UNSAFE.sub("_", str(raw)).replace("..", "_").strip("._") or "_")
file_name = "".join(out)
reason = check_document_file_name(file_name)
if reason:
raise ValueError(f"DOCUMENT file_name refused: {reason}")
Expand Down
8 changes: 4 additions & 4 deletions pyegeria/view/seed/Standard Documents.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"label": "DCAT Catalog",
"envelope": {
"heading": "DCAT Catalog",
"description": "A DCAT-AP 3 catalog (JSON-LD) of the Assets in a collection or folder, read as you. Give `scope`: the collection's qualifiedName or GUID. DigitalProducts and Agreements are Bitol's and are named in the notes, not exported; validated against the vendored DCAT-AP 3.0.1 SHACL shapes. Run with output_format DOCUMENT.",
"description": "A DCAT-AP 3 catalog (JSON-LD) of the Assets in a collection or folder (or of the assets matching a search), read as you. Give `scope`: the collection's qualifiedName or GUID, or `search_string`. DigitalProducts and Agreements are Bitol's and are named in the notes, not exported; validated against the vendored DCAT-AP 3.0.1 SHACL shapes. Run with output_format DOCUMENT.",
"family": "Standard Documents",
"target_type_name": "Collection",
"aliases": []
Expand All @@ -24,7 +24,7 @@
"formatters": {
"DOCUMENT": {
"columns": [],
"document": {"standard": "dcat-ap-3", "media_type": "application/ld+json", "file_name": "{scope}-dcat.jsonld", "validator": "dcat-ap-3-shacl"}
"document": {"standard": "dcat-ap-3", "media_type": "application/ld+json", "file_name": "{scope|search_string}-dcat.jsonld", "validator": "dcat-ap-3-shacl"}
}
}
}
Expand All @@ -33,7 +33,7 @@
"label": "DCAT Catalog (Turtle)",
"envelope": {
"heading": "DCAT Catalog (Turtle)",
"description": "The DCAT Catalog document as Turtle: a DCAT-AP 3 catalog of the Assets in a collection or folder, read as you. Give `scope`. Run with output_format DOCUMENT.",
"description": "The DCAT Catalog document as Turtle: a DCAT-AP 3 catalog of the Assets in a collection or folder (or of the assets matching a search), read as you. Give `scope` or `search_string`. Run with output_format DOCUMENT.",
"family": "Standard Documents",
"target_type_name": "Collection",
"aliases": []
Expand All @@ -51,7 +51,7 @@
"formatters": {
"DOCUMENT": {
"columns": [],
"document": {"standard": "dcat-ap-3", "media_type": "text/turtle", "file_name": "{scope}-dcat.ttl", "validator": "dcat-ap-3-shacl"}
"document": {"standard": "dcat-ap-3", "media_type": "text/turtle", "file_name": "{scope|search_string}-dcat.ttl", "validator": "dcat-ap-3-shacl"}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[project]
name = "pyegeria"
version = "6.2.37"
version = "6.2.38"
license = 'Apache-2.0'
license-files = ["LICENSE"]
authors = [{name = "Dan Wolfson", email = "dan.wolfson@pdr-associates.com"},]
Expand Down
50 changes: 50 additions & 0 deletions tests/micro-tests/test_my_egeria_node_identifier.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright Contributors to the ODPi Egeria project.
"""6.2.38 F-ME1: selecting a node in My Egeria's SelectionOverviewScreen passes the node's GUID (or
qualified name), never the domain tree's whole [type, GUID] list."""
from types import SimpleNamespace

import pytest
from textual.widgets import Tree

from my_egeria.SelectionOverviewScreen import SelectionOverviewScreen, node_identifier

DOMAIN_GUID = "8dc3ff8d-0000-4000-8000-000000000001"


def _select(category, node):
calls = []
record = lambda kind: (lambda ident: calls.append((kind, ident)))
fake = SimpleNamespace(category=category,
display_selected_term_details=record("glossary"),
display_selected_digital_product=record("catalog"),
display_selected_data_dictionary=record("dictionary"),
display_selected_business_domain=record("domain"),
display_selected_root_collection=record("collection"))
SelectionOverviewScreen.handle_tree_node_selected(fake, SimpleNamespace(node=node))
return calls


def test_a_domain_node_passes_its_guid_not_the_list():
tree = Tree("Domains") # built as shop_for_data_handler.build_domain_details builds it
branch = tree.root.add("BusinessCapability::Finance", data=["BusinessCapability", DOMAIN_GUID])
assert _select("domain", branch) == [("domain", DOMAIN_GUID)]


@pytest.mark.parametrize("category, data, label, expected", [
("catalog", "a1b2-guid", "Product summary", "a1b2-guid"), # leaf data is the GUID
("dictionary", "DataDictionary::Sales::Term", "Summary", "DataDictionary::Sales::Term"),
("collection", None, "CollectionFolder::Portal", "CollectionFolder::Portal"), # no data: its QN label
("domain", None, "BusinessCapability::Finance::Payroll", "BusinessCapability::Finance::Payroll"),
("glossary", None, "GlossaryTerm::Customer", "GlossaryTerm::Customer"),
])
def test_other_node_kinds(category, data, label, expected):
tree = Tree("T")
leaf = tree.root.add_leaf(label, data=data)
assert _select(category, leaf) == [(category, expected)]


def test_node_identifier():
assert node_identifier(["BusinessCapability", DOMAIN_GUID]) == DOMAIN_GUID
assert node_identifier(("x", "")) == "x"
assert node_identifier(None) is None and node_identifier("") is None
35 changes: 35 additions & 0 deletions tests/micro-tests/test_sd2_export_dcat.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,3 +453,38 @@ def test_a_held_document_spec_that_refuses_to_load_is_skipped_with_words(bad, wo
esc._build(_held_spec(bad), folders=[], identity="erinoverview", registry_names=set())
assert caught.value.who == "Held DCAT"
assert caught.value.reason.startswith("the spec does not load:") and words in caught.value.reason


# ── 6.2.38 F-DCAT1: the seed spec runs with scope or with search_string ──

@pytest.mark.parametrize("spec_name, ext", [("DCAT Catalog", "jsonld"), ("DCAT Catalog (Turtle)", "ttl")])
def test_seed_spec_runs_with_a_search_string(spec_name, ext):
fx = _fixture("clinical_trial_files")
out = fse.exec_report_spec(spec_name, output_format="DOCUMENT", params=dict(fx["params"]),
supply=PlainSupply(Replay(fx)), view_server="vs", view_url="https://x",
user="u", user_pass="p")
assert out["kind"] == "document"
assert out["file_name"] == f"DataLake_PROJ-CT-TBDF_WeeklyMeasurements_Oak_Dene_Hospital_PROJ-CT-TBDF_00002-dcat.{ext}"
assert len(_graph(out["text"], "json-ld" if ext == "jsonld" else "turtle")) > 0
assert out["validation"]["findings"] == EXPECTED_FINDINGS["clinical_trial_files"]


def test_seed_spec_still_runs_with_a_scope():
fx = _fixture("portal_dashboards")
out = fse.exec_report_spec("DCAT Catalog", output_format="DOCUMENT", params={"scope": fx["params"]["scope"]},
supply=PlainSupply(Replay(fx)), view_server="vs", view_url="https://x",
user="u", user_pass="p")
assert out["file_name"] == "DashboardFolder_Consumer_Portal-dcat.jsonld"


def test_seed_spec_with_neither_is_refused_in_words():
with pytest.raises(ValueError, match="needs one of the parameters 'scope', 'search_string'"):
fse.exec_report_spec("DCAT Catalog", output_format="DOCUMENT", params={}, view_server="vs",
view_url="https://x", user="u", user_pass="p")


def test_file_name_alternatives():
assert fse.fill_document_file_name("{scope|search_string}.json", {"search_string": "a b"}) == "a_b.json"
assert fse.fill_document_file_name("{scope|search_string}.json", {"scope": "S", "search_string": "x"}) == "S.json"
with pytest.raises(ValueError, match="only plain parameter names"):
fse.fill_document_file_name("{scope|x.y}.json", {"scope": "S"})
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading