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
29 changes: 29 additions & 0 deletions packages/gooddata-sdk/src/gooddata_sdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,15 @@
from gooddata_sdk.catalog.validate_by_item import CatalogValidateByItem
from gooddata_sdk.catalog.workspace.aac import (
aac_attribute_hierarchy_to_declarative,
aac_computed_attribute_to_declarative,
aac_dashboard_to_declarative,
aac_dataset_to_declarative,
aac_date_dataset_to_declarative,
aac_metric_to_declarative,
aac_plugin_to_declarative,
aac_visualization_to_declarative,
declarative_attribute_hierarchy_to_aac,
declarative_computed_attribute_to_aac,
declarative_dashboard_to_aac,
declarative_dataset_to_aac,
declarative_date_instance_to_aac,
Expand All @@ -239,6 +241,8 @@
from gooddata_sdk.catalog.workspace.declarative_model.workspace.analytics_model.analytics_model import (
CatalogAbsolutePublisherDocumentPeriod,
CatalogDeclarativeAnalytics,
CatalogDeclarativeComputedAttribute,
CatalogDeclarativeComputedAttributeContent,
CatalogDeclarativeMemoryItem,
CatalogDeclarativeMetric,
CatalogDeclarativeParameter,
Expand Down Expand Up @@ -292,6 +296,13 @@
CatalogDeclarativeWorkspaceModel,
CatalogDeclarativeWorkspaces,
)
from gooddata_sdk.catalog.workspace.entity_model.content_objects.computed_attribute import (
CatalogComputedAttribute,
CatalogComputedAttributeAttributes,
CatalogComputedAttributeContent,
CatalogComputedAttributeDocument,
CatalogComputedAttributePostDocument,
)
from gooddata_sdk.catalog.workspace.entity_model.content_objects.custom_application_setting import (
CatalogCustomApplicationSetting,
)
Expand Down Expand Up @@ -416,6 +427,11 @@
"CatalogBedrockAccessKeyAuth": "gooddata_sdk.catalog.organization.entity_model.llm_provider",
"CatalogColorPalette": "gooddata_sdk.catalog.appearance.entity_model.color_palette",
"CatalogColorPaletteAttributes": "gooddata_sdk.catalog.appearance.entity_model.color_palette",
"CatalogComputedAttribute": "gooddata_sdk.catalog.workspace.entity_model.content_objects.computed_attribute",
"CatalogComputedAttributeAttributes": "gooddata_sdk.catalog.workspace.entity_model.content_objects.computed_attribute",
"CatalogComputedAttributeContent": "gooddata_sdk.catalog.workspace.entity_model.content_objects.computed_attribute",
"CatalogComputedAttributeDocument": "gooddata_sdk.catalog.workspace.entity_model.content_objects.computed_attribute",
"CatalogComputedAttributePostDocument": "gooddata_sdk.catalog.workspace.entity_model.content_objects.computed_attribute",
"CatalogContentSlideTemplate": "gooddata_sdk.catalog.organization.common.slide_template",
"CatalogCoverSlideTemplate": "gooddata_sdk.catalog.organization.common.slide_template",
"CatalogCspDirective": "gooddata_sdk.catalog.organization.entity_model.directive",
Expand Down Expand Up @@ -446,6 +462,8 @@
"CatalogDeclarativeAttribute": "gooddata_sdk.catalog.workspace.declarative_model.workspace.logical_model.dataset.dataset",
"CatalogDeclarativeAutomation": "gooddata_sdk.catalog.workspace.declarative_model.workspace.automation",
"CatalogDeclarativeColumn": "gooddata_sdk.catalog.data_source.declarative_model.physical_model.table",
"CatalogDeclarativeComputedAttribute": "gooddata_sdk.catalog.workspace.declarative_model.workspace.analytics_model.analytics_model",
"CatalogDeclarativeComputedAttributeContent": "gooddata_sdk.catalog.workspace.declarative_model.workspace.analytics_model.analytics_model",
"CatalogDeclarativeDashboardPermissionsForAssignee": "gooddata_sdk.catalog.permission.declarative_model.permission",
"CatalogDeclarativeDashboardPermissionsForAssigneeRule": "gooddata_sdk.catalog.permission.declarative_model.permission",
"CatalogDeclarativeDataSource": "gooddata_sdk.catalog.data_source.declarative_model.data_source",
Expand Down Expand Up @@ -649,13 +667,15 @@
"VisualizationMetric": "gooddata_sdk.visualization",
"VisualizationService": "gooddata_sdk.visualization",
"aac_attribute_hierarchy_to_declarative": "gooddata_sdk.catalog.workspace.aac",
"aac_computed_attribute_to_declarative": "gooddata_sdk.catalog.workspace.aac",
"aac_dashboard_to_declarative": "gooddata_sdk.catalog.workspace.aac",
"aac_dataset_to_declarative": "gooddata_sdk.catalog.workspace.aac",
"aac_date_dataset_to_declarative": "gooddata_sdk.catalog.workspace.aac",
"aac_metric_to_declarative": "gooddata_sdk.catalog.workspace.aac",
"aac_plugin_to_declarative": "gooddata_sdk.catalog.workspace.aac",
"aac_visualization_to_declarative": "gooddata_sdk.catalog.workspace.aac",
"declarative_attribute_hierarchy_to_aac": "gooddata_sdk.catalog.workspace.aac",
"declarative_computed_attribute_to_aac": "gooddata_sdk.catalog.workspace.aac",
"declarative_dashboard_to_aac": "gooddata_sdk.catalog.workspace.aac",
"declarative_dataset_to_aac": "gooddata_sdk.catalog.workspace.aac",
"declarative_date_instance_to_aac": "gooddata_sdk.catalog.workspace.aac",
Expand Down Expand Up @@ -695,6 +715,11 @@
"CatalogBedrockAccessKeyAuth",
"CatalogColorPalette",
"CatalogColorPaletteAttributes",
"CatalogComputedAttribute",
"CatalogComputedAttributeAttributes",
"CatalogComputedAttributeContent",
"CatalogComputedAttributeDocument",
"CatalogComputedAttributePostDocument",
"CatalogContentSlideTemplate",
"CatalogCoverSlideTemplate",
"CatalogCspDirective",
Expand Down Expand Up @@ -725,6 +750,8 @@
"CatalogDeclarativeAttribute",
"CatalogDeclarativeAutomation",
"CatalogDeclarativeColumn",
"CatalogDeclarativeComputedAttribute",
"CatalogDeclarativeComputedAttributeContent",
"CatalogDeclarativeDashboardPermissionsForAssignee",
"CatalogDeclarativeDashboardPermissionsForAssigneeRule",
"CatalogDeclarativeDataSource",
Expand Down Expand Up @@ -928,13 +955,15 @@
"VisualizationMetric",
"VisualizationService",
"aac_attribute_hierarchy_to_declarative",
"aac_computed_attribute_to_declarative",
"aac_dashboard_to_declarative",
"aac_dataset_to_declarative",
"aac_date_dataset_to_declarative",
"aac_metric_to_declarative",
"aac_plugin_to_declarative",
"aac_visualization_to_declarative",
"declarative_attribute_hierarchy_to_aac",
"declarative_computed_attribute_to_aac",
"declarative_dashboard_to_aac",
"declarative_dataset_to_aac",
"declarative_date_instance_to_aac",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from gooddata_code_convertors import (
ConversionError,
declarative_attribute_hierarchy_to_yaml,
declarative_computed_attribute_to_yaml,
declarative_dashboard_to_yaml,
declarative_dataset_to_yaml,
declarative_date_instance_to_yaml,
Expand All @@ -19,6 +20,7 @@
declarative_publisher_page_template_to_yaml_v2,
declarative_visualisation_to_yaml,
yaml_attribute_hierarchy_to_declarative,
yaml_computed_attribute_to_declarative,
yaml_dashboard_to_declarative,
yaml_dataset_to_declarative,
yaml_date_dataset_to_declarative,
Expand Down Expand Up @@ -73,6 +75,7 @@
"plugin",
"attribute_hierarchy",
"parameter",
"computed_attribute",
"document",
"document_template",
"page_template",
Expand Down Expand Up @@ -214,6 +217,11 @@ def aac_attribute_hierarchy_to_declarative(aac: dict[str, Any]) -> dict[str, Any
return yaml_attribute_hierarchy_to_declarative(aac)


def aac_computed_attribute_to_declarative(aac: dict[str, Any]) -> dict[str, Any]:
"""Convert an AAC computed attribute dict to declarative format."""
return yaml_computed_attribute_to_declarative(aac)


def aac_document_to_declarative(aac: dict[str, Any]) -> dict[str, Any]:
"""Convert an AAC document dict to declarative format.

Expand Down Expand Up @@ -317,6 +325,11 @@ def declarative_attribute_hierarchy_to_aac(declarative: dict[str, Any]) -> dict[
return declarative_attribute_hierarchy_to_yaml(declarative)


def declarative_computed_attribute_to_aac(declarative: dict[str, Any]) -> dict[str, Any]:
"""Convert a declarative computed attribute dict to AAC format."""
return declarative_computed_attribute_to_yaml(declarative)


def declarative_document_to_aac(declarative: dict[str, Any]) -> dict[str, Any]:
"""Convert a declarative document dict to AAC format.

Expand Down Expand Up @@ -373,6 +386,7 @@ def detect_yaml_format(path: Path) -> Literal["aac", "declarative"]:
"plugins",
"attributeHierarchies",
"parameters",
"computedAttributes",
"documents",
"documentTemplates",
"pageTemplates",
Expand Down Expand Up @@ -451,6 +465,7 @@ def load_aac_workspace_from_disk(
dashboard_plugins: list[dict[str, Any]] = []
attribute_hierarchies: list[dict[str, Any]] = []
parameters: list[dict[str, Any]] = []
computed_attributes: list[dict[str, Any]] = []
documents: list[dict[str, Any]] = []
document_templates: list[dict[str, Any]] = []
page_templates: list[dict[str, Any]] = []
Expand Down Expand Up @@ -478,6 +493,8 @@ def load_aac_workspace_from_disk(
attribute_hierarchies.append(aac_attribute_hierarchy_to_declarative(aac))
case "parameter":
parameters.append(aac_parameter_to_declarative(aac))
case "computed_attribute":
computed_attributes.append(aac_computed_attribute_to_declarative(aac))
case "document":
documents.append(aac_document_to_declarative(aac))
case "document_template":
Expand Down Expand Up @@ -510,6 +527,8 @@ def load_aac_workspace_from_disk(
analytics["attributeHierarchyObjects"] = attribute_hierarchies
if parameters:
analytics["parameters"] = parameters
if computed_attributes:
analytics["computedAttributes"] = computed_attributes
if documents:
analytics["documents"] = documents
if document_templates:
Expand Down Expand Up @@ -539,7 +558,7 @@ def store_aac_workspace_to_disk(model: CatalogDeclarativeWorkspaceModel, source_
"""Convert a declarative workspace model to AAC YAML files and write to disk.

Creates typed subdirectories (datasets/, metrics/, visualisations/, dashboards/,
plugins/, attributeHierarchies/, parameters/, documents/, documentTemplates/, pageTemplates/)
plugins/, attributeHierarchies/, parameters/, computedAttributes/, documents/, documentTemplates/, pageTemplates/)
under source_dir.

Raises:
Expand Down Expand Up @@ -591,6 +610,11 @@ def store_aac_workspace_to_disk(model: CatalogDeclarativeWorkspaceModel, source_
result = declarative_parameter_to_aac(parameter)
_write_aac_file(source_dir, "parameters", parameter["id"], result["content"])

# The layout omits computedAttributes when a workspace has none, so the key may be missing.
for computed_attribute in analytics.get("computedAttributes") or []:
result = declarative_computed_attribute_to_aac(computed_attribute)
_write_aac_file(source_dir, "computedAttributes", computed_attribute["id"], result["content"])

for document_id, result in documents:
_write_aac_file(source_dir, "documents", document_id, result["content"])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,12 @@ def _prepare_afm_for_availability(items: list[ValidObjectTypes]) -> afm_models.A

return compute_model_to_api_model(attributes=attributes, metrics=metrics, filters=filters)

def compute_valid_objects(self, workspace_id: str, ctx: ValidObjectsInputType) -> ValidObjects:
def compute_valid_objects(
self,
workspace_id: str,
ctx: ValidObjectsInputType,
types: list[str] | None = None,
) -> ValidObjects:
"""
Returns attributes, facts, and metrics which are valid to add to a context that already
contains some entities from the semantic model. The entities are typically used to compute analytics and
Expand All @@ -565,6 +570,9 @@ def compute_valid_objects(self, workspace_id: str, ctx: ValidObjectsInputType) -
Workspace identification string e.g. "demo"
ctx (ValidObjectsInputType):
items already in context. you can specify context in one of the following ways:
types (Optional[list[str]]):
object types to ask for. Defaults to facts, attributes and measures.
Pass "computedAttributes" as well to include computed attributes.

Returns:
ValidObjects:
Expand All @@ -578,7 +586,9 @@ def compute_valid_objects(self, workspace_id: str, ctx: ValidObjectsInputType) -
else:
afm = self._prepare_afm_for_availability([ctx])

query = afm_models.AfmValidObjectsQuery(afm=afm, types=["facts", "attributes", "measures"])
query = afm_models.AfmValidObjectsQuery(
afm=afm, types=types if types is not None else ["facts", "attributes", "measures"]
)
response = self._actions_api.compute_valid_objects(workspace_id=workspace_id, afm_valid_objects_query=query)

by_type: dict[str, set[str]] = dict()
Expand Down
Loading
Loading