|
24 | 24 |
|
25 | 25 | from pyatlan.model.constants import DELETED_, DELETED_SENTINEL |
26 | 26 | from pyatlan.model.enums import AnnouncementType, EntityStatus, SaveSemantic |
| 27 | +from pyatlan.model.retranslators import AtlanTagRetranslator |
27 | 28 | from pyatlan.model.structs import SourceTagAttachment |
28 | 29 | from pyatlan.model.translators import AtlanTagTranslator |
29 | 30 |
|
@@ -103,13 +104,13 @@ def _convert_to_tag_name(cls, data): |
103 | 104 | return data |
104 | 105 | return AtlanTagName(data) if data else cls.get_deleted_sentinel() |
105 | 106 |
|
106 | | - @staticmethod |
107 | | - def json_encode_atlan_tag(atlan_tag_name: "AtlanTagName"): |
108 | | - from pyatlan.client.atlan import AtlanClient |
| 107 | + # @staticmethod |
| 108 | + # def json_encode_atlan_tag(atlan_tag_name: "AtlanTagName"): |
| 109 | + # from pyatlan.client.atlan import AtlanClient |
109 | 110 |
|
110 | | - return AtlanClient.get_current_client().atlan_tag_cache.get_id_for_name( |
111 | | - atlan_tag_name._display_text |
112 | | - ) |
| 111 | + # return AtlanClient.get_current_client().atlan_tag_cache.get_id_for_name( |
| 112 | + # atlan_tag_name._display_text |
| 113 | + # ) |
113 | 114 |
|
114 | 115 |
|
115 | 116 | class AtlanObject(BaseModel): |
@@ -219,6 +220,33 @@ def to_dict(self) -> Dict[str, Any]: |
219 | 220 | return self.translated |
220 | 221 |
|
221 | 222 |
|
| 223 | +class AtlanRequest: |
| 224 | + def __init__(self, model: BaseModel, client: "AtlanClient"): |
| 225 | + self.client = client |
| 226 | + self.model = model |
| 227 | + self.retranslators = [ |
| 228 | + AtlanTagRetranslator(client), |
| 229 | + # add others... |
| 230 | + ] |
| 231 | + # Do: model.json() → parse → translate → store |
| 232 | + raw_json = self.model.json(by_alias=True, exclude_unset=True) |
| 233 | + parsed = json.loads(raw_json) |
| 234 | + self.translated = self._deep_retranslate(parsed) |
| 235 | + |
| 236 | + def _deep_retranslate(self, data: Any) -> Any: |
| 237 | + if isinstance(data, dict): |
| 238 | + for retranslator in self.retranslators: |
| 239 | + if retranslator.applies_to(data): |
| 240 | + data = retranslator.retranslate(data) |
| 241 | + return {key: self._deep_retranslate(value) for key, value in data.items()} |
| 242 | + elif isinstance(data, list): |
| 243 | + return [self._deep_retranslate(item) for item in data] |
| 244 | + return data |
| 245 | + |
| 246 | + def json(self, **kwargs) -> str: |
| 247 | + return json.dumps(self.translated, **kwargs) |
| 248 | + |
| 249 | + |
222 | 250 | class SearchRequest(AtlanObject, ABC): |
223 | 251 | attributes: Optional[List[str]] = Field( |
224 | 252 | default_factory=list, |
|
0 commit comments