Skip to content

Commit 425406b

Browse files
committed
Add logic for Announcments
1 parent dbdaed9 commit 425406b

File tree

8 files changed

+424
-107
lines changed

8 files changed

+424
-107
lines changed

Diff for: mypy.ini

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[mypy]

Diff for: pyatlan/generator/templates/entity.jinja2

+34-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ from __future__ import annotations
22
from typing import Optional, Dict, Any, List, Literal
33
from pydantic import Field
44
from datetime import date
5-
from pyatlan.model.core import AtlanObject, Classification
5+
from pyatlan.model.core import AtlanObject, Classification, Announcement
66
from pyatlan.model.enums import CertificateStatus, EntityStatus, google_datastudio_asset_type, powerbi_endorsement, \
7-
icon_type
7+
icon_type, AnnouncementType
88

99
class Internal(AtlanObject):
1010
"""For internal usage"""
@@ -35,7 +35,7 @@ class {{ entity_def.name }}({{super_classes[0]}}):
3535
{%- set type = attribute_def.typeName | get_type %}
3636
{{attribute_def.name | to_snake_case }}: {% if attribute_def.isOptional %}Optional[{% endif %}{{type}}{% if attribute_def.isOptional %}]{% endif %} = Field(None, description='', alias='{{attribute_def.name}}') # relationship
3737
{%- endfor %}
38-
attributes: Optional['{{entity_def.name}}.Attributes'] = Field(
38+
attributes: '{{entity_def.name}}.Attributes' = Field(
3939
None,
4040
description='Map of attributes in the instance and their values. The specific keys of this map will vary '
4141
'by type, so are described in the sub-types of this schema.\n',
@@ -135,11 +135,41 @@ class {{ entity_def.name }}({{super_classes[0]}}):
135135
{%- set type = attribute_def.typeName | get_type %}
136136
{{attribute_def.name | to_snake_case }}: {% if attribute_def.isOptional %}Optional[{% endif %}{{type}}{% if attribute_def.isOptional %}]{% endif %} = Field(None, description='', alias='{{attribute_def.name}}') # relationship
137137
{%- endfor %}
138-
attributes: Optional['{{entity_def.name}}.Attributes'] = Field(
138+
attributes: '{{entity_def.name}}.Attributes' = Field(
139139
None,
140140
description='Map of attributes in the instance and their values. The specific keys of this map will vary by '
141141
'type, so are described in the sub-types of this schema.\n',
142142
)
143+
{% if entity_def.name == "Asset" %}
144+
def has_announcement(self) -> bool:
145+
if self.attributes and (
146+
self.attributes.announcement_title or self.attributes.announcement_type
147+
):
148+
return True
149+
else:
150+
return False
151+
152+
def set_announcement(self, announcement: Announcement) -> None:
153+
self.attributes.announcement_type = announcement.announcement_type.value
154+
self.attributes.announcement_title = announcement.announcement_title
155+
self.attributes.announcement_message = announcement.announcement_message
156+
157+
def get_announcment(self) -> Optional[Announcement]:
158+
if self.attributes.announcement_type and self.attributes.announcement_title:
159+
return Announcement(
160+
announcement_type=AnnouncementType[
161+
self.attributes.announcement_type.upper()
162+
],
163+
announcement_title=self.attributes.announcement_title,
164+
announcement_message=self.attributes.announcement_message,
165+
)
166+
return None
167+
168+
def clear_announcment(self):
169+
self.attributes.announcement_message = None
170+
self.attributes.announcement_title = None
171+
self.attributes.announcement_type = None
172+
{% endif %}
143173
{% endif %}
144174
{%- endif %}
145175
{% endfor %}

0 commit comments

Comments
 (0)