from datetime import datetime
from typing import Optional
from tdw_catalog import Catalog
import tdw_catalog.organization as organization
from tdw_catalog.entity import Entity, Property, EntityBase
from tdw_catalog.errors import CatalogException, _convert_error, _raise_error
from tdw_catalog.relations import _OrganizationRelation
[docs]@Entity([
Property("id", str, serialize=True),
Property("organization_id",
str,
relation="tdw_catalog.organization.Organization",
serialize=True),
Property("user_id", str),
Property("title", str, writable=True),
Property("description", Optional[str], writable=True),
Property("created_at", datetime),
Property("updated_at", datetime),
])
class GlossaryTerm(EntityBase, _OrganizationRelation):
"""
:class:`.GlossaryTerm`\\ s are used to categorize and classify columns within :class:`.Dataset`\\ s
Attributes
----------
id : str
:class:`.GlossaryTerm`\\ 's unique id
organization_id : str
The unique ID of the :class:`.Organization` to which this :class:`.GlossaryTerm` belongs
user_id : str
The unique ID of the :class:`.User` who created this :class:`.GlossaryTerm`
title : str
The title for this :class:`.GlossaryTerm`
description: Optional[str]
An Optional description for this :class:`.GlossaryTerm`
created_at : datetime
The datetime at which this :class:`.GlossaryTerm` was created
updated_at : datetime
The datetime at which this :class:`.GlossaryTerm` was last updated
"""
_client: 'Catalog'
id: str
title: str
organization: 'organization.Organization'
organization_id: str
user_id: str
description: Optional[str]
created_at: datetime
updated_at: datetime
def __str__(self) -> str:
return f"<GlossaryTerm id={self.id} title={self.title}>"
@classmethod
def get(cls, client: 'Catalog', id: str):
try:
res = client._get_glossary_term(id=id)
return cls(client, **res)
except Exception as e:
err = _raise_error(e, "Unable to fetch GlossaryTerm {}".format(id))
[docs] def save(self) -> None:
"""
Update this :class:`.GlossaryTerm`, saving any changes to its title
Parameters
----------
None
Returns
-------
None
Raises
------
CatalogPermissionDeniedException
If the caller is not allowed to update this :class:`.GlossaryTerm`, or if the given :class:`.GlossaryTerm` ID does not exist
CatalogException
If call to the :class:`.Catalog` server fails
"""
try:
res = self._client._update_glossary_term(
id=self.id, title=self.title, description=self.description)
self.deserialize(res)
except Exception as e:
raise _convert_error(e)
[docs] def delete(self) -> None:
"""
Delete this :class:`.GlossaryTerm`. This :class:`.GlossaryTerm` object should not be
used after `delete()` has successfully returned
Parameters
----------
None
Returns
-------
None
Raises
------
CatalogPermissionDeniedException
If the caller is not allowed to delete this :class:`.GlossaryTerm`
CatalogNotFoundException
If the :class:`.GlossaryTerm` being deleted does not exist
CatalogException
If call to the :class:`.Catalog` server fails
"""
try:
self._client._delete_glossary_term(id=self.id)
except Exception as e:
raise _convert_error(e)