Skip to content
Open
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
7 changes: 7 additions & 0 deletions packages/gooddata-sdk/src/gooddata_sdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@
CatalogDeclarativeAnalytics,
CatalogDeclarativeMemoryItem,
CatalogDeclarativeMetric,
MemoryItemStrategy,
)
from gooddata_sdk.catalog.workspace.declarative_model.workspace.analytics_model.export_definition import (
CatalogDeclarativeExportDefinition,
Expand Down Expand Up @@ -225,6 +226,12 @@
CatalogDependentEntitiesResponse,
CatalogEntityIdentifier,
)
from gooddata_sdk.catalog.workspace.entity_model.memory_item import (
CatalogMemoryItem,
CatalogMemoryItemAttributes,
CatalogMemoryItemPatch,
CatalogMemoryItemPatchAttributes,
)
from gooddata_sdk.catalog.workspace.entity_model.user_data_filter import (
CatalogUserDataFilter,
CatalogUserDataFilterAttributes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from __future__ import annotations

from pathlib import Path
from typing import Any, Optional, Union
from typing import Any, Literal, Optional, Union

import attr
from attrs import define
Expand Down Expand Up @@ -41,6 +41,8 @@
DeclarativeVisualizationObject,
]

MemoryItemStrategy = Literal["AUTO", "ALWAYS"]

LAYOUT_ANALYTICS_MODEL_DIR = "analytics_model"
LAYOUT_ANALYTICAL_DASHBOARDS_DIR = "analytical_dashboards"
LAYOUT_ANALYTICAL_DASHBOARD_EXTENSIONS_DIR = "analytical_dashboard_extensions"
Expand Down Expand Up @@ -336,7 +338,7 @@ def client_class() -> type[DeclarativeAttributeHierarchy]:
@define(auto_attribs=True, kw_only=True)
class CatalogDeclarativeMemoryItem(CatalogAnalyticsBaseMeta):
instruction: str
strategy: str
strategy: MemoryItemStrategy
title: str
tags: list[str] | None = None
description: str | None = None
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# (C) 2024 GoodData Corporation
from __future__ import annotations

from typing import Optional

import attr
from gooddata_api_client.model.json_api_memory_item_in import JsonApiMemoryItemIn
from gooddata_api_client.model.json_api_memory_item_in_attributes import JsonApiMemoryItemInAttributes
from gooddata_api_client.model.json_api_memory_item_in_document import JsonApiMemoryItemInDocument
from gooddata_api_client.model.json_api_memory_item_patch import JsonApiMemoryItemPatch
from gooddata_api_client.model.json_api_memory_item_patch_attributes import JsonApiMemoryItemPatchAttributes
from gooddata_api_client.model.json_api_memory_item_patch_document import JsonApiMemoryItemPatchDocument

from gooddata_sdk.catalog.base import Base


@attr.s(auto_attribs=True, kw_only=True)
class CatalogMemoryItemDocument(Base):
data: CatalogMemoryItem

@staticmethod
def client_class() -> type[JsonApiMemoryItemInDocument]:
return JsonApiMemoryItemInDocument

def to_api(self) -> JsonApiMemoryItemInDocument:
return JsonApiMemoryItemInDocument(data=self.data.to_api())


@attr.s(auto_attribs=True, kw_only=True)
class CatalogMemoryItemPatchDocument(Base):
data: CatalogMemoryItemPatch

@staticmethod
def client_class() -> type[JsonApiMemoryItemPatchDocument]:
return JsonApiMemoryItemPatchDocument

def to_api(self) -> JsonApiMemoryItemPatchDocument:
return JsonApiMemoryItemPatchDocument(data=self.data.to_api())


@attr.s(auto_attribs=True, kw_only=True)
class CatalogMemoryItem(Base):
id: str
attributes: CatalogMemoryItemAttributes

@staticmethod
def client_class() -> type[JsonApiMemoryItemIn]:
return JsonApiMemoryItemIn

@classmethod
def init(
cls,
memory_item_id: str,
instruction: str,
strategy: str,
title: Optional[str] = None,
description: Optional[str] = None,
tags: Optional[list[str]] = None,
keywords: Optional[list[str]] = None,
is_disabled: Optional[bool] = None,
) -> CatalogMemoryItem:
attributes = CatalogMemoryItemAttributes(
instruction=instruction,
strategy=strategy,
title=title,
description=description,
tags=tags,
keywords=keywords,
is_disabled=is_disabled,
)
return cls(id=memory_item_id, attributes=attributes)

def to_api(self) -> JsonApiMemoryItemIn:
return JsonApiMemoryItemIn(id=self.id, attributes=self.attributes.to_api())


@attr.s(auto_attribs=True, kw_only=True)
class CatalogMemoryItemAttributes(Base):
instruction: str
strategy: str
title: Optional[str] = None
description: Optional[str] = None
tags: Optional[list[str]] = None
keywords: Optional[list[str]] = None
is_disabled: Optional[bool] = None

@staticmethod
def client_class() -> type[JsonApiMemoryItemInAttributes]:
return JsonApiMemoryItemInAttributes


@attr.s(auto_attribs=True, kw_only=True)
class CatalogMemoryItemPatch(Base):
id: str
attributes: CatalogMemoryItemPatchAttributes

@staticmethod
def client_class() -> type[JsonApiMemoryItemPatch]:
return JsonApiMemoryItemPatch

def to_api(self) -> JsonApiMemoryItemPatch:
return JsonApiMemoryItemPatch(id=self.id, attributes=self.attributes.to_api())


@attr.s(auto_attribs=True, kw_only=True)
class CatalogMemoryItemPatchAttributes(Base):
instruction: Optional[str] = None
strategy: Optional[str] = None
title: Optional[str] = None
description: Optional[str] = None
tags: Optional[list[str]] = None
keywords: Optional[list[str]] = None
is_disabled: Optional[bool] = None

@staticmethod
def client_class() -> type[JsonApiMemoryItemPatchAttributes]:
return JsonApiMemoryItemPatchAttributes
106 changes: 106 additions & 0 deletions packages/gooddata-sdk/src/gooddata_sdk/catalog/workspace/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
CatalogFilterView,
CatalogFilterViewDocument,
)
from gooddata_sdk.catalog.workspace.entity_model.memory_item import (
CatalogMemoryItem,
CatalogMemoryItemDocument,
CatalogMemoryItemPatch,
CatalogMemoryItemPatchDocument,
)
from gooddata_sdk.catalog.workspace.entity_model.user_data_filter import (
CatalogUserDataFilter,
CatalogUserDataFilterDocument,
Expand Down Expand Up @@ -1476,3 +1482,103 @@ def load_and_put_declarative_filter_views(self, workspace_id: str, layout_root_p
self.layout_organization_folder(layout_root_path)
)
self.put_declarative_filter_views(workspace_id, declarative_filter_views)

def list_memory_items(self, workspace_id: str) -> list[CatalogMemoryItem]:
"""List all memory items for a workspace.

Args:
workspace_id (str):
String containing id of the workspace.

Returns:
list[CatalogMemoryItem]:
List of memory item entities.
"""
get_memory_items = functools.partial(
self._entities_api.get_all_entities_memory_items,
workspace_id,
_check_return_type=False,
)
memory_items = load_all_entities_dict(get_memory_items, camel_case=False)
return [CatalogMemoryItem.from_dict(v, camel_case=False) for v in memory_items["data"]]

def get_memory_item(self, workspace_id: str, memory_item_id: str) -> CatalogMemoryItem:
"""Get memory item by its id.

Args:
workspace_id (str):
String containing id of the workspace.
memory_item_id (str):
String containing id of the memory item.

Returns:
CatalogMemoryItem:
Memory item entity object.
"""
memory_item_dict = self._entities_api.get_entity_memory_items(
workspace_id=workspace_id,
object_id=memory_item_id,
_check_return_type=False,
).data
return CatalogMemoryItem.from_dict(memory_item_dict, camel_case=True)

def create_memory_item(self, workspace_id: str, memory_item: CatalogMemoryItem) -> CatalogMemoryItem:
"""Create a new memory item.

Args:
workspace_id (str):
String containing id of the workspace.
memory_item (CatalogMemoryItem):
Memory item entity object to create.

Returns:
CatalogMemoryItem:
Created memory item entity object.
"""
memory_item_document = CatalogMemoryItemDocument(data=memory_item)
result = self._entities_api.create_entity_memory_items(
workspace_id=workspace_id,
json_api_memory_item_in_document=memory_item_document.to_api(),
_check_return_type=False,
)
return CatalogMemoryItem.from_dict(result.data, camel_case=True)

def patch_memory_item(
self, workspace_id: str, memory_item_id: str, memory_item_patch: CatalogMemoryItemPatch
) -> CatalogMemoryItem:
"""Patch an existing memory item.

Args:
workspace_id (str):
String containing id of the workspace.
memory_item_id (str):
String containing id of the memory item.
memory_item_patch (CatalogMemoryItemPatch):
Memory item patch object with fields to update.

Returns:
CatalogMemoryItem:
Updated memory item entity object.
"""
memory_item_patch_document = CatalogMemoryItemPatchDocument(data=memory_item_patch)
result = self._entities_api.patch_entity_memory_items(
workspace_id=workspace_id,
object_id=memory_item_id,
json_api_memory_item_patch_document=memory_item_patch_document.to_api(),
_check_return_type=False,
)
return CatalogMemoryItem.from_dict(result.data, camel_case=True)

def delete_memory_item(self, workspace_id: str, memory_item_id: str) -> None:
"""Delete a memory item.

Args:
workspace_id (str):
String containing id of the workspace.
memory_item_id (str):
String containing id of the memory item to delete.

Returns:
None
"""
self._entities_api.delete_entity_memory_items(workspace_id=workspace_id, object_id=memory_item_id)
Loading