@@ -19,45 +19,56 @@ def retranslate(self, data: Dict[str, Any]) -> Dict[str, Any]:
1919
2020class AtlanTagRetranslator (BaseRetranslator ):
2121 _TYPE_NAME = "typeName"
22- _CLASSIFICATIONS = "classifications"
2322 _CLASSIFICATION_NAMES = "classificationNames"
2423 _SOURCE_ATTACHMENTS = "source_tag_attachements"
24+ _CLASSIFICATION_KEYS = {
25+ "classifications" ,
26+ "addOrUpdateClassifications" ,
27+ "removeClassifications" ,
28+ }
2529
2630 def __init__ (self , client : "AtlanClient" ):
2731 self .client = client
2832
2933 def applies_to (self , data : Dict [str , Any ]) -> bool :
30- return self ._CLASSIFICATION_NAMES in data or self ._CLASSIFICATIONS in data
34+ return self ._CLASSIFICATION_NAMES in data or any (
35+ key in data for key in self ._CLASSIFICATION_KEYS
36+ )
3137
3238 def retranslate (self , data : Dict [str , Any ]) -> Dict [str , Any ]:
3339 data = data .copy ()
3440
41+ # Convert classification names → IDs
3542 if self ._CLASSIFICATION_NAMES in data :
3643 data [self ._CLASSIFICATION_NAMES ] = [
3744 self .client .atlan_tag_cache .get_id_for_name (str (name ))
3845 for name in data [self ._CLASSIFICATION_NAMES ]
3946 ]
4047
41- if self ._CLASSIFICATIONS in data :
42- for classification in data [self ._CLASSIFICATIONS ]:
43- tag_name = str (classification .get (self ._TYPE_NAME ))
44- if tag_name :
45- tag_id = self .client .atlan_tag_cache .get_id_for_name (tag_name )
46- classification [self ._TYPE_NAME ] = tag_id
47-
48- # Rebuild source tag structure if `source_tag_attachements` are present
49- attachments = classification .pop (self ._SOURCE_ATTACHMENTS , None )
50- if attachments :
51- attr_id = self .client .atlan_tag_cache .get_source_tags_attr_id (
52- str (tag_id )
53- )
54- if attr_id :
55- classification .setdefault ("attributes" , {})[attr_id ] = [
56- {
57- "typeName" : "SourceTagAttachment" ,
58- "attributes" : attachment .dict (),
59- }
60- for attachment in attachments
61- ]
48+ # Convert classification objects
49+ for key in self ._CLASSIFICATION_KEYS :
50+ if key in data :
51+ for classification in data [key ]:
52+ tag_name = str (classification .get (self ._TYPE_NAME ))
53+ if tag_name :
54+ tag_id = self .client .atlan_tag_cache .get_id_for_name (tag_name )
55+ classification [self ._TYPE_NAME ] = tag_id
56+
57+ # Rebuild source tag attributes
58+ attachments = classification .pop (self ._SOURCE_ATTACHMENTS , None )
59+ if attachments :
60+ attr_id = (
61+ self .client .atlan_tag_cache .get_source_tags_attr_id (
62+ tag_id
63+ )
64+ )
65+ if attr_id :
66+ classification .setdefault ("attributes" , {})[attr_id ] = [
67+ {
68+ "typeName" : "SourceTagAttachment" ,
69+ "attributes" : attachment .dict (),
70+ }
71+ for attachment in attachments
72+ ]
6273
6374 return data
0 commit comments