@@ -29,6 +29,20 @@ def __init__(
2929 last_updated_by : str = None ,
3030 last_updated : str = None ,
3131 ):
32+ """
33+ Initialize an Annotation object.
34+
35+ :param comment_value: The value of the annotation comment.
36+ :param object_name: Name of the TM1 object the annotation is attached to.
37+ :param dimensional_context: Iterable of dimension elements providing context.
38+ :param comment_type: Type of the comment (default "ANNOTATION").
39+ :param annotation_id: Unique ID of the annotation.
40+ :param text: Text of the annotation.
41+ :param creator: Creator of the annotation.
42+ :param created: Creation timestamp.
43+ :param last_updated_by: Last user who updated the annotation.
44+ :param last_updated: Last update timestamp.
45+ """
3246 self ._id = annotation_id
3347 self ._text = text
3448 self ._creator = creator
@@ -45,7 +59,7 @@ def from_json(cls, annotation_as_json: str) -> "Annotation":
4559 """Alternative constructor
4660
4761 :param annotation_as_json: String, JSON
48- :return: instance of TM1py.Process
62+ :return: instance of Annotation
4963 """
5064 annotation_as_dict = json .loads (annotation_as_json )
5165 annotation_id = annotation_as_dict ["ID" ]
@@ -73,66 +87,123 @@ def from_json(cls, annotation_as_json: str) -> "Annotation":
7387
7488 @property
7589 def body (self ) -> str :
90+ """
91+ Get the annotation body as a JSON string.
92+
93+ :return: JSON string representation of the annotation.
94+ """
7695 return json .dumps (self ._construct_body ())
7796
7897 @property
7998 def body_as_dict (self ) -> Dict :
99+ """
100+ Get the annotation body as a dictionary.
101+
102+ :return: Dictionary representation of the annotation.
103+ """
80104 return self ._construct_body ()
81105
82106 @property
83107 def comment_value (self ) -> str :
108+ """
109+ Get the comment value.
110+
111+ :return: The comment value string.
112+ """
84113 return self ._comment_value
85114
86115 @property
87116 def text (self ) -> str :
117+ """
118+ Get the annotation text.
119+
120+ :return: The annotation text.
121+ """
88122 return self ._text
89123
90124 @property
91125 def dimensional_context (self ) -> List [str ]:
126+ """
127+ Get the dimensional context.
128+
129+ :return: List of dimension elements providing context.
130+ """
92131 return self ._dimensional_context
93132
94133 @property
95134 def created (self ) -> str :
135+ """
136+ Get the creation timestamp.
137+
138+ :return: Creation timestamp as string.
139+ """
96140 return self ._created
97141
98142 @property
99143 def object_name (self ) -> str :
144+ """
145+ Get the object name.
146+
147+ :return: Name of the TM1 object.
148+ """
100149 return self ._object_name
101150
102151 @property
103152 def last_updated (self ) -> str :
153+ """
154+ Get the last updated timestamp.
155+
156+ :return: Last update timestamp as string.
157+ """
104158 return self ._last_updated
105159
106160 @property
107161 def last_updated_by (self ) -> str :
162+ """
163+ Get the last user who updated the annotation.
164+
165+ :return: Username of last updater.
166+ """
108167 return self ._last_updated_by
109168
110169 @comment_value .setter
111170 def comment_value (self , value : str ):
171+ """
172+ Set the comment value.
173+
174+ :param value: New comment value.
175+ """
112176 self ._comment_value = value
113177
114178 @property
115179 def id (self ) -> str :
180+ """
181+ Get the annotation ID.
182+
183+ :return: Annotation ID string.
184+ """
116185 return self ._id
117186
118187 def move (self , dimension_order : Iterable [str ], dimension : str , target_element : str , source_element : str = None ):
119- """Move annotation on given dimension from source_element to target_element
188+ """
189+ Move annotation on given dimension from source_element to target_element.
120190
121- :param dimension_order: List, order of the dimensions in the cube
122- :param dimension: dimension name
123- :param target_element: target element name
124- :param source_element: source element name
125- :return:
191+ :param dimension_order: List, order of the dimensions in the cube.
192+ :param dimension: Dimension name.
193+ :param target_element: Target element name.
194+ :param source_element: Source element name (optional).
195+ :return: None
126196 """
127197 for i , dimension_name in enumerate (dimension_order ):
128198 if dimension_name .lower () == dimension .lower ():
129199 if not source_element or self ._dimensional_context [i ] == source_element :
130200 self ._dimensional_context [i ] = target_element
131201
132202 def _construct_body (self ) -> Dict :
133- """construct the ODATA conform JSON represenation for the Annotation entity.
203+ """
204+ Construct the ODATA conform JSON representation for the Annotation entity.
134205
135- :return: string , the valid JSON
206+ :return: Dictionary , the valid JSON.
136207 """
137208 dimensional_context = [{"Name" : element } for element in self ._dimensional_context ]
138209 body = collections .OrderedDict ()
@@ -151,6 +222,12 @@ def _construct_body(self) -> Dict:
151222 return body
152223
153224 def construct_body_for_post (self , cube_dimensions ) -> Dict :
225+ """
226+ Construct the body for POST requests to create an annotation.
227+
228+ :param cube_dimensions: List of cube dimension names.
229+ :return: Dictionary for POST request body.
230+ """
154231 body = collections .OrderedDict ()
155232 body ["Text" ] = self .text
156233 body ["ApplicationContext" ] = [
@@ -167,4 +244,4 @@ def construct_body_for_post(self, cube_dimensions) -> Dict:
167244 body ["commentType" ] = "ANNOTATION"
168245 body ["commentLocation" ] = "," .join (self .dimensional_context )
169246
170- return body
247+ return body
0 commit comments