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
20 changes: 20 additions & 0 deletions pyegeria/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@
GovernanceControlProperties,
MonitoredResourceProperties,
NotificationSubscriberProperties,
DataValueSpecificationProperties,
MeasurementSpecificationProperties,
DataSetProperties,
ReportProperties,
DashboardProperties,
LabeledRelationshipProperties,
BasisDataFieldProperties,
AsOfDataFieldProperties,
ReportTypeInstanceProperties,
ReportRunOfProperties,
RequestBody,
NewRelationshipRequestBody,
NewAttachmentRequestBody,
Expand Down Expand Up @@ -120,6 +130,16 @@
"GovernanceControlProperties",
"MonitoredResourceProperties",
"NotificationSubscriberProperties",
"DataValueSpecificationProperties",
"MeasurementSpecificationProperties",
"DataSetProperties",
"ReportProperties",
"DashboardProperties",
"LabeledRelationshipProperties",
"BasisDataFieldProperties",
"AsOfDataFieldProperties",
"ReportTypeInstanceProperties",
"ReportRunOfProperties",
"RequestBody",
"NewRelationshipRequestBody",
"NewAttachmentRequestBody",
Expand Down
112 changes: 112 additions & 0 deletions pyegeria/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,118 @@ class NotificationSubscriberProperties(PyegeriaModel):
effective_to: datetime | None = None


#
# Report specifications, measurements and dashboards (Egeria 6.3, odpi/egeria#9432, area 0582).
# Each `class_` is the Java bean name exactly: Egeria resolves the polymorphic "class" against its
# known `*Properties` subtypes, so sending a type name ("Dashboard") is an HTTP 400
# "Could not resolve type id" (the ScopedBy lesson, pyegeria #537).
#

class DataValueSpecificationProperties(AuthoredReferenceableProperties):
"""Properties of a DataValueSpecification (and the base of DataClass, DataGrain, MeasurementSpecification)."""
class_: Annotated[Literal["DataValueSpecificationProperties"], Field(alias="class")]
match_property_names: list[str] | None = None
namespace_path: str | None = None
match_threshold: int | None = None
specification: str | None = None
specification_details: dict[str, str] | None = None
data_type: str | None = None
units: str | None = None
absolute_uncertainty: int | None = None
relative_uncertainty: int | None = None


class MeasurementSpecificationProperties(DataValueSpecificationProperties):
"""How a measured value is to be read: completeness, confidence form, uncertainty form and the sentences
to show in place of a value when there isn't one. Created through DataDesigner.create_data_value_specification.

completenessDeclared: complete | lower_bound | unknown
confidenceForm: measured | estimated | inferred | judged | generated
uncertaintyForm: plus_minus | low_high | band
absenceSentences: map keyed by absence state (nothing_found, not_measured, not_permitted, not_applicable)

The state set is not a property: it is a ValidValuesAssignment from the specification. The basis and
as-of fields are the BasisDataField / AsOfDataField relationships, not strings.
"""
class_: Annotated[Literal["MeasurementSpecificationProperties"], Field(alias="class")]
completeness_declared: str | None = None
confidence_form: str | None = None
uncertainty_form: str | None = None
absence_sentences: dict[str, str] | None = None


class DataSetProperties(ReferenceableProperties):
"""Partial model of Egeria's DataSetProperties (a DataAsset). Only the DataSet-level fields are declared;
other Asset fields a caller supplies are kept (extra='allow') rather than silently dropped."""
model_config = ConfigDict(extra='allow')
class_: Annotated[Literal["DataSetProperties"], Field(alias="class")]
formula: str | None = None
formula_type: str | None = None

@model_validator(mode='after')
def _drop_injected_metadata(self):
# OpenMetadataRootProperties.preprocess_data adds an empty 'metadata' key; with extra='allow' it
# would otherwise be serialized and sent to Egeria.
if self.__pydantic_extra__ and self.__pydantic_extra__.get('metadata') == {}:
self.__pydantic_extra__.pop('metadata')
return self


class ReportProperties(DataSetProperties):
"""A Report asset. outputFormat and reportParameters (a JSON string) are new in Egeria 6.3."""
class_: Annotated[Literal["ReportProperties"], Field(alias="class")]
purpose: str | None = None
start_time: datetime | None = None
completion_time: datetime | None = None
completion_message: str | None = None
created_time: datetime | None = None
last_modified_time: datetime | None = None
last_modifier: str | None = None
output_format: str | None = None
report_parameters: str | None = None


class DashboardProperties(DataSetProperties):
"""A Dashboard asset (a DataSet, sibling of Report). refreshTimeInterval is a long, in minutes
(Egeria's existing REFRESH_TIME_INTERVAL property: "how frequently the processing should run - in minutes")."""
class_: Annotated[Literal["DashboardProperties"], Field(alias="class")]
aliases: list[str] | None = None
refresh_time_interval: int | None = None
layout_style: str | None = None


class LabeledRelationshipProperties(PyegeriaModel):
"""Egeria's LabeledRelationshipProperties: the base of the relationship properties below."""
class_: Annotated[Literal["LabeledRelationshipProperties"], Field(alias="class")]
label: str | None = None
description: str | None = None
effective_from: datetime | None = None
effective_to: datetime | None = None


class BasisDataFieldProperties(LabeledRelationshipProperties):
"""BasisDataField: MeasurementSpecification (end 1) -> the DataField giving the measurement's basis."""
class_: Annotated[Literal["BasisDataFieldProperties"], Field(alias="class")]


class AsOfDataFieldProperties(LabeledRelationshipProperties):
"""AsOfDataField: MeasurementSpecification (end 1) -> the DataField giving the time of the measurement."""
class_: Annotated[Literal["AsOfDataFieldProperties"], Field(alias="class")]


class ReportTypeInstanceProperties(LabeledRelationshipProperties):
"""ReportTypeInstance: ReportType (end 1, e.g. a ReportSpec) -> a Report generated from it."""
class_: Annotated[Literal["ReportTypeInstanceProperties"], Field(alias="class")]


class ReportRunOfProperties(LabeledRelationshipProperties):
"""ReportRunOf: ResultsSet (end 1) -> the Report it is a run of, with the run's result state."""
class_: Annotated[Literal["ReportRunOfProperties"], Field(alias="class")]
result_state: str | None = None
result_state_reason: str | None = None
result_location: str | None = None


class RequestBody(PyegeriaModel):
external_source_guid: str | None = None
external_source_name: str | None = None
Expand Down
109 changes: 108 additions & 1 deletion pyegeria/omvs/collection_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
COLLECTION_PROPERTIES_LIST = ["CollectionProperties", "DataDictionaryProperties",
"DataSpecProperties", "DigitalProductProperties",
"AgreementProperties","RootCollectionProperties", "HomeCollectionProperties",
"SkillSetProperties", "ReferenceListProperties",]
"SkillSetProperties", "ReferenceListProperties",
"ReportTypeProperties", "ReportSpecProperties",]

AGREEMENT_PROPERTIES_LIST = ["AgreementProperties", "DigitalSubscriptionProperties",]

Expand Down Expand Up @@ -111,6 +112,20 @@ class ReportTypeProperties(CollectionProperties):
lastModifier: str | None = None


class ReportSpecProperties(ReportTypeProperties):
"""A ReportSpec (Egeria 6.3, ReportType subtype): a report specification held in Egeria.

microflow is the ordered list of stages with their parameters, as a JSON string; outputTypes the output
formats it can produce; targetTypeName the type of element it reports on.
"""
class_: Annotated[Literal["ReportSpecProperties"], Field(alias="class")]
microflow: str | None = None
target_type_name: str | None = None
aliases: list[str] | None = None
output_types: list[str] | None = None
include_preamble: bool | None = None


class DataDictionaryProperties(CollectionProperties):
class_: Annotated[Literal["DataDictionaryProperties"], Field(alias="class")]

Expand Down Expand Up @@ -2368,6 +2383,98 @@ def create_report_type_collection(self, display_name: Optional[str] = None, desc
self._async_create_report_type_collection(display_name, description,category,
classification_name, body))

@dynamic_catch
async def _async_create_report_spec(self, display_name: Optional[str] = None,
description: Optional[str] = None, category: Optional[str] = None,
microflow: Optional[str] = None, target_type_name: Optional[str] = None,
aliases: Optional[list[str]] = None,
output_types: Optional[list[str]] = None,
include_preamble: Optional[bool] = None,
body: Optional[dict | NewElementRequestBody] = None) -> str:
""" Create a ReportSpec (a ReportType collection subtype, Egeria 6.3). Async version.

If `body` is supplied it is sent as given (its properties class should be "ReportSpecProperties")
and the other arguments are ignored. Otherwise a self-anchored ReportSpec is built from the
arguments, with the qualified name manufactured from `display_name` ("ReportSpec::...").

Parameters
----------
display_name: str, optional
The display name of the report spec; required when no body is given.
description: str, optional
category: str, optional
The family the spec belongs to.
microflow: str, optional
The ordered list of stages to run with their parameters, as a JSON string.
target_type_name: str, optional
The type of element the spec reports on.
aliases: list[str], optional
output_types: list[str], optional
The output formats the spec can produce (e.g. ["MD", "JSON"]).
include_preamble: bool, optional
body: dict | NewElementRequestBody, optional

Returns
-------
str - the guid of the created report spec

Raises
------
PyegeriaException
ValidationError
"""
if body:
validated_body = self.validate_new_element_request(body, ["ReportSpecProperties"])
elif display_name is not None:
qualified_name = self.__create_qualified_name__("ReportSpec", display_name)
spec_properties = ReportSpecProperties(class_="ReportSpecProperties",
qualified_name=qualified_name,
display_name=display_name,
description=description,
category=category,
microflow=microflow,
target_type_name=target_type_name,
aliases=aliases,
output_types=output_types,
include_preamble=include_preamble)
body = {
"class": "NewElementRequestBody",
"isOwnAnchor": True,
"properties": spec_properties.model_dump(exclude_none=True),
}
validated_body = NewElementRequestBody.model_validate(body)
else:
raise PyegeriaInvalidParameterException(additional_info={"reason": "Invalid input parameters"})

url = f"{self.collection_command_root}"
json_body = validated_body.model_dump_json(indent=2, exclude_none=True, by_alias=True)
logger.info(json_body)
resp = await self._async_make_request("POST", url, json_body, is_json=True)
logger.info(f"Create report spec with GUID: {resp.json().get('guid')}")
return resp.json().get("guid", NO_GUID_RETURNED)

@dynamic_catch
def create_report_spec(self, display_name: Optional[str] = None,
description: Optional[str] = None, category: Optional[str] = None,
microflow: Optional[str] = None, target_type_name: Optional[str] = None,
aliases: Optional[list[str]] = None,
output_types: Optional[list[str]] = None,
include_preamble: Optional[bool] = None,
body: Optional[dict | NewElementRequestBody] = None) -> str:
""" Create a ReportSpec (a ReportType collection subtype, Egeria 6.3).

See `_async_create_report_spec` for the parameters. Update an existing spec with
`update_collection(guid, body)` using a "ReportSpecProperties" properties class.

Returns
-------
str - the guid of the created report spec
"""
return run_sync(
self._async_create_report_spec(display_name, description, category, microflow,
target_type_name, aliases, output_types,
include_preamble, body))

@dynamic_catch
async def _async_create_question_spec_folder(self, display_name: Optional[str] = None,
description: Optional[str] = None,
Expand Down
Loading
Loading