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 )
@@ -272,16 +277,73 @@ def load_from_disk(cls, user_data_filter_file: Path) -> CatalogDeclarativeUserDa
272277
273278 @classmethod
274279 def from_dict (cls , data : dict [str , Any ], camel_case : bool = True ) -> CatalogDeclarativeUserDataFilter :
280+ """
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.
288+ """
289+ declarative_user_data_filter = DeclarativeUserDataFilter .from_dict (data , camel_case )
290+ return cls .from_api (declarative_user_data_filter )
291+
292+
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+ @classmethod
336+ def from_dict (cls , data : dict [str , Any ], camel_case : bool = True ) -> CatalogDeclarativeFilterView :
275337 """
276338 :param data: Data loaded for example from the file.
277339 :param camel_case: True if the variable names in the input
278340 data are serialized names as specified in the OpenAPI document.
279341 False if the variables names in the input data are python
280342 variable names in PEP-8 snake case.
281- :return: CatalogDeclarativeUserDataFilter object.
343+ :return: CatalogDeclarativeFilterView object.
282344 """
283- declarative_user_data_filter = DeclarativeUserDataFilter .from_dict (data , camel_case )
284- return cls .from_api (declarative_user_data_filter )
345+ declarative_filter_view = DeclarativeFilterView .from_dict (data , camel_case )
346+ return cls .from_api (declarative_filter_view )
285347
286348
287349@attr .s (auto_attribs = True , kw_only = True )
@@ -305,6 +367,10 @@ def workspace_data_filters_folder(layout_organization_folder: Path) -> Path:
305367 def user_data_filters_folder (layout_organization_folder : Path ) -> Path :
306368 return layout_organization_folder / LAYOUT_USER_DATA_FILTERS_DIR
307369
370+ @staticmethod
371+ def filter_views_folder (layout_organization_folder : Path ) -> Path :
372+ return layout_organization_folder / LAYOUT_FILTER_VIEWS_DIR
373+
308374 def store_to_disk (self , layout_organization_folder : Path ) -> None :
309375 workspaces_folder = self .workspaces_folder (layout_organization_folder )
310376 workspaces_data_filters_folder = self .workspace_data_filters_folder (layout_organization_folder )
0 commit comments