66from typing import Any , Optional
77
88import attr
9+ from gooddata_api_client .model .declarative_filter_view import DeclarativeFilterView
910from gooddata_api_client .model .declarative_user_data_filter import DeclarativeUserDataFilter
1011from gooddata_api_client .model .declarative_user_data_filters import DeclarativeUserDataFilters
1112from gooddata_api_client .model .declarative_workspace import DeclarativeWorkspace
1718
1819from gooddata_sdk .catalog .base import Base
1920from gooddata_sdk .catalog .identifier import (
21+ CatalogDeclarativeAnalyticalDashboardIdentifier ,
2022 CatalogDeclarativeUserGroupIdentifier ,
2123 CatalogUserIdentifier ,
2224 CatalogWorkspaceIdentifier ,
3638LAYOUT_WORKSPACES_DIR = "workspaces"
3739LAYOUT_WORKSPACES_DATA_FILTERS_DIR = "workspaces_data_filters"
3840LAYOUT_USER_DATA_FILTERS_DIR = "user_data_filters"
41+ LAYOUT_FILTER_VIEWS_DIR = "filter_views"
3942
4043
4144def get_workspace_folder (workspace_id : str , layout_organization_folder : Path ) -> Path :
@@ -85,6 +88,7 @@ class CatalogDeclarativeWorkspace(Base):
8588 user_data_filters : list [CatalogDeclarativeUserDataFilter ] = attr .field (factory = list )
8689 custom_application_settings : list [CatalogDeclarativeCustomApplicationSetting ] = attr .field (factory = list )
8790 automations : list [CatalogDeclarativeAutomation ] = attr .field (factory = list )
91+ filter_views : list [CatalogDeclarativeFilterView ] = attr .field (factory = list )
8892
8993 @staticmethod
9094 def client_class () -> type [DeclarativeWorkspace ]:
@@ -211,12 +215,13 @@ def load_from_disk(cls, workspaces_data_filter_file: Path) -> CatalogDeclarative
211215 @classmethod
212216 def from_dict (cls , data : dict [str , Any ], camel_case : bool = True ) -> CatalogDeclarativeWorkspaceDataFilter :
213217 """
214- :param data: Data loaded for example from the file.
215- :param camel_case: True if the variable names in the input
216- data are serialized names as specified in the OpenAPI document.
217- False if the variables names in the input data are python
218- variable names in PEP-8 snake case.
219- :return: CatalogDeclarativeWorkspaceDataFilter object.
218+ Args:
219+ data (dict[str, Any]): Data loaded, for example, from a file.
220+ camel_case (bool): True if the variable names in the input data are serialized names as specified in the OpenAPI document.
221+ False if the variable names in the input data are Python variable names in PEP-8 snake case.
222+
223+ Returns:
224+ CatalogDeclarativeWorkspaceDataFilter: CatalogDeclarativeWorkspaceDataFilter object.
220225 """
221226 declarative_workspace_data_filter = DeclarativeWorkspaceDataFilter .from_dict (data , camel_case )
222227 return cls .from_api (declarative_workspace_data_filter )
@@ -273,17 +278,61 @@ def load_from_disk(cls, user_data_filter_file: Path) -> CatalogDeclarativeUserDa
273278 @classmethod
274279 def from_dict (cls , data : dict [str , Any ], camel_case : bool = True ) -> CatalogDeclarativeUserDataFilter :
275280 """
276- :param data: Data loaded for example from the file.
277- :param camel_case: True if the variable names in the input
278- data are serialized names as specified in the OpenAPI document.
279- False if the variables names in the input data are python
280- variable names in PEP-8 snake case.
281- :return: CatalogDeclarativeUserDataFilter object.
281+ Args:
282+ data (dict[str, Any]): Data loaded, for example, from a file.
283+ camel_case (bool): True if the variable names in the input data are serialized names as specified in the OpenAPI document.
284+ False if the variable names in the input data are Python variable names in PEP-8 snake case.
285+
286+ Returns:
287+ CatalogDeclarativeUserDataFilter: CatalogDeclarativeUserDataFilter object.
282288 """
283289 declarative_user_data_filter = DeclarativeUserDataFilter .from_dict (data , camel_case )
284290 return cls .from_api (declarative_user_data_filter )
285291
286292
293+ @attr .s (auto_attribs = True , kw_only = True )
294+ class CatalogDeclarativeFilterView (Base ):
295+ id : str
296+ title : str
297+ analytical_dashboard : Optional [CatalogDeclarativeAnalyticalDashboardIdentifier ] = None
298+ content : Optional [dict [str , Any ]] = None
299+ description : Optional [str ] = None
300+ is_default : Optional [bool ] = None
301+ tags : Optional [list [str ]] = None
302+ user : Optional [CatalogUserIdentifier ] = None
303+
304+ @staticmethod
305+ def client_class () -> type [DeclarativeFilterView ]:
306+ return DeclarativeFilterView
307+
308+ def store_to_disk (self , filter_views_folder : Path ) -> None :
309+ filter_view_file = filter_views_folder / f"{ self .id } .yaml"
310+ write_layout_to_file (filter_view_file , self .to_api ().to_dict (camel_case = True ))
311+
312+ @classmethod
313+ def load_from_disk (cls , filter_view_file : Path ) -> CatalogDeclarativeFilterView :
314+ filter_view = read_layout_from_file (filter_view_file )
315+ return CatalogDeclarativeFilterView .from_dict (filter_view , camel_case = True )
316+
317+ @classmethod
318+ def store_filter_views_to_disk (
319+ cls , filter_views : list [CatalogDeclarativeFilterView ], layout_organization_folder : Path
320+ ) -> None :
321+ filter_views_folder = CatalogDeclarativeWorkspaces .filter_views_folder (layout_organization_folder )
322+ create_directory (filter_views_folder )
323+ for filter_view in filter_views :
324+ filter_view .store_to_disk (filter_views_folder )
325+
326+ @classmethod
327+ def load_filter_views_from_disk (cls , layout_organization_folder : Path ) -> list [CatalogDeclarativeFilterView ]:
328+ filter_views_files = get_sorted_yaml_files (
329+ CatalogDeclarativeWorkspaces .filter_views_folder (layout_organization_folder )
330+ )
331+ return [
332+ CatalogDeclarativeFilterView .load_from_disk (filter_views_file ) for filter_views_file in filter_views_files
333+ ]
334+
335+
287336@attr .s (auto_attribs = True , kw_only = True )
288337class CatalogDeclarativeWorkspaces (Base ):
289338 workspaces : list [CatalogDeclarativeWorkspace ]
@@ -305,6 +354,10 @@ def workspace_data_filters_folder(layout_organization_folder: Path) -> Path:
305354 def user_data_filters_folder (layout_organization_folder : Path ) -> Path :
306355 return layout_organization_folder / LAYOUT_USER_DATA_FILTERS_DIR
307356
357+ @staticmethod
358+ def filter_views_folder (layout_organization_folder : Path ) -> Path :
359+ return layout_organization_folder / LAYOUT_FILTER_VIEWS_DIR
360+
308361 def store_to_disk (self , layout_organization_folder : Path ) -> None :
309362 workspaces_folder = self .workspaces_folder (layout_organization_folder )
310363 workspaces_data_filters_folder = self .workspace_data_filters_folder (layout_organization_folder )
0 commit comments