pyegeria 5.4.0.23__py3-none-any.whl → 5.4.0.25__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. commands/cat/debug_log +7967 -465
  2. commands/cat/debug_log.2025-08-15_09-14-07_444802.zip +0 -0
  3. commands/cat/debug_log.2025-08-16_10-21-59_388912.zip +0 -0
  4. commands/cat/debug_log.2025-08-17_11-34-27_981852.zip +0 -0
  5. commands/cat/dr_egeria_md.py +36 -6
  6. commands/cat/logs/pyegeria.log +3 -135
  7. md_processing/.DS_Store +0 -0
  8. md_processing/__init__.py +12 -6
  9. md_processing/data/commands.json +8523 -2234
  10. md_processing/dr_egeria_inbox/gov_def.md +76 -18
  11. md_processing/dr_egeria_inbox/img.png +0 -0
  12. md_processing/dr_egeria_inbox/product.md +185 -24
  13. md_processing/dr_egeria_outbox/.obsidian/workspace.json +5 -5
  14. md_processing/dr_egeria_outbox/monday/processed-2025-08-19 07:05-product.md +426 -0
  15. md_processing/dr_egeria_outbox/monday/processed-2025-08-19 07:56-product.md +212 -0
  16. md_processing/dr_egeria_outbox/monday/processed-2025-08-19 09:43-product.md +201 -0
  17. md_processing/dr_egeria_outbox/tuesday/processed-2025-08-19 10:55-product.md +209 -0
  18. md_processing/md_commands/governance_officer_commands.py +247 -178
  19. md_processing/md_commands/product_manager_commands.py +730 -580
  20. md_processing/md_processing_utils/common_md_proc_utils.py +170 -12
  21. md_processing/md_processing_utils/common_md_utils.py +126 -28
  22. md_processing/md_processing_utils/extraction_utils.py +2 -2
  23. md_processing/md_processing_utils/md_processing_constants.py +14 -10
  24. pyegeria/.DS_Store +0 -0
  25. pyegeria/__init__.py +1 -1
  26. pyegeria/_client_new.py +61 -12
  27. pyegeria/_exceptions_new.py +6 -0
  28. pyegeria/_output_formats.py +42 -2
  29. pyegeria/collection_manager.py +79 -14
  30. pyegeria/{data_designer_omvs.py → data_designer.py} +1171 -1675
  31. pyegeria/glossary_browser.py +1259 -0
  32. pyegeria/{glossary_manager_omvs.py → glossary_manager.py} +1181 -1099
  33. pyegeria/governance_officer.py +1 -3
  34. pyegeria/load_config.py +1 -1
  35. pyegeria/models.py +37 -4
  36. pyegeria/output_formatter.py +2 -1
  37. pyegeria/project_manager.py +1952 -0
  38. pyegeria/utils.py +5 -2
  39. {pyegeria-5.4.0.23.dist-info → pyegeria-5.4.0.25.dist-info}/METADATA +1 -1
  40. {pyegeria-5.4.0.23.dist-info → pyegeria-5.4.0.25.dist-info}/RECORD +43 -44
  41. md_processing/dr_egeria_outbox/friday/processed-2025-07-18 15:00-product.md +0 -62
  42. md_processing/dr_egeria_outbox/friday/processed-2025-07-18 15:13-product.md +0 -62
  43. md_processing/dr_egeria_outbox/friday/processed-2025-07-20 13:23-product.md +0 -47
  44. md_processing/dr_egeria_outbox/friday/processed-2025-08-01 11:55-data_test3.md +0 -503
  45. md_processing/dr_egeria_outbox/monday/processed-2025-07-14 12:38-data_designer_out.md +0 -663
  46. md_processing/dr_egeria_outbox/monday/processed-2025-07-21 10:52-generated_help_report.md +0 -2744
  47. md_processing/dr_egeria_outbox/monday/processed-2025-07-21 18:38-collections.md +0 -62
  48. md_processing/dr_egeria_outbox/monday/processed-2025-08-01 11:34-gov_def.md +0 -444
  49. md_processing/dr_egeria_outbox/processed-2025-08-03 16:05-glossary_list.md +0 -37
  50. pyegeria/glossary_browser_omvs.py +0 -3840
  51. pyegeria/governance_officer_omvs.py +0 -2367
  52. {pyegeria-5.4.0.23.dist-info → pyegeria-5.4.0.25.dist-info}/LICENSE +0 -0
  53. {pyegeria-5.4.0.23.dist-info → pyegeria-5.4.0.25.dist-info}/WHEEL +0 -0
  54. {pyegeria-5.4.0.23.dist-info → pyegeria-5.4.0.25.dist-info}/entry_points.txt +0 -0
@@ -1,3840 +0,0 @@
1
- """
2
- PDX-License-Identifier: Apache-2.0
3
- Copyright Contributors to the ODPi Egeria project.
4
-
5
- This module contains an initial version of the glossary_browser omvs module. There are additional methods that will be
6
- added in subsequent versions of the glossary_omvs module.
7
-
8
- """
9
-
10
- import asyncio
11
- from datetime import datetime
12
-
13
- from pyegeria import NO_GLOSSARIES_FOUND, max_paging_size
14
- from pyegeria._client import Client
15
- from pyegeria._exceptions import InvalidParameterException, PropertyServerException, UserNotAuthorizedException
16
- from pyegeria._globals import NO_CATEGORIES_FOUND, NO_TERMS_FOUND
17
- from pyegeria._validators import validate_guid, validate_name, validate_search_string
18
- from pyegeria.utils import body_slimmer
19
- from pyegeria._output_formats import select_output_format_set, get_output_format_type_match
20
- from pyegeria.output_formatter import (
21
- make_preamble,
22
- make_md_attribute,
23
- format_for_markdown_table,
24
- generate_entity_md,
25
- generate_entity_md_table,
26
- generate_entity_dict,
27
- generate_output,
28
- MD_SEPARATOR
29
- )
30
-
31
-
32
- class GlossaryBrowser(Client):
33
- """
34
- GlossaryBrowser is a class that extends the Client class. It provides methods to search and retrieve glossaries,
35
- terms, and categories.
36
-
37
- Attributes:
38
-
39
- view_server: str
40
- The name of the View Server to connect to.
41
- platform_url : str
42
- URL of the server platform to connect to
43
- user_id : str
44
- The identity of the user calling the method - this sets a default optionally used by the methods
45
- when the user doesn't pass the user_id on a method call.
46
- user_pwd: str
47
- The password associated with the user_id. Defaults to None
48
-
49
- """
50
-
51
- def __init__(self, view_server: str, platform_url: str, user_id: str, user_pwd: str = None, token: str = None, ):
52
- self.view_server = view_server
53
- self.platform_url = platform_url
54
- self.user_pwd = user_pwd
55
- self.user_id = user_id
56
- self.g_browser_command_root: str
57
-
58
- Client.__init__(self, view_server, platform_url, user_id, user_pwd, token)
59
-
60
-
61
- def _extract_glossary_properties(self, element: dict, output_format: str = None) -> dict:
62
- """
63
- Extract common properties from a glossary element.
64
-
65
- Args:
66
- element (dict): The glossary element
67
- output_format (str, optional): The output format (FORM, REPORT, etc.)
68
-
69
- Returns:
70
- dict: Dictionary of extracted properties
71
- """
72
- guid = element['elementHeader'].get("guid", None)
73
- properties = element['glossaryProperties']
74
- display_name = properties.get("displayName", "") or ""
75
- description = properties.get("description", "") or ""
76
- language = properties.get("language", "") or ""
77
- usage = properties.get("usage", "") or ""
78
- qualified_name = properties.get("qualifiedName", "") or ""
79
-
80
- categories = self.get_categories_for_glossary(guid)
81
- cat_md_display = ''
82
- cat_md_qn = ''
83
- category_names = ''
84
- category_qualified_names = ''
85
-
86
- if type(categories) is list:
87
- for category in categories:
88
- cat_md_display += f" {category['glossaryCategoryProperties'][('displayName')]},\n"
89
- cat_md_qn += f" {category['glossaryCategoryProperties'][('qualifiedName')]},\n"
90
- category_names = cat_md_display.rstrip(',')
91
- category_qualified_names = cat_md_qn.rstrip(',')
92
-
93
- result = {
94
- 'GUID': guid, 'properties': properties, 'display_name': display_name, 'description': description,
95
- 'language': language, 'usage': usage, 'qualified_name': qualified_name
96
- }
97
-
98
- # Include appropriate category information based on output format
99
- if output_format == 'FORM':
100
- result['categories_qualified_names'] = category_qualified_names
101
- else:
102
- result['categories_names'] = category_names
103
-
104
- return result
105
-
106
- def _generate_entity_md(self, elements: list, elements_action: str, output_format: str, entity_type: str,
107
- extract_properties_func, get_additional_props_func=None) -> str:
108
- """
109
- Generic method to generate markdown for entities (glossaries, terms, categories).
110
-
111
- Args:
112
- elements (list): List of entity elements
113
- elements_action (str): Action description for elements
114
- output_format (str): Output format
115
- entity_type (str): Type of entity (Glossary, Term, Category)
116
- extract_properties_func: Function to extract properties from an element
117
- get_additional_props_func: Optional function to get additional properties
118
-
119
- Returns:
120
- str: Markdown representation
121
- """
122
- return generate_entity_md(
123
- elements=elements,
124
- elements_action=elements_action,
125
- output_format=output_format,
126
- entity_type=entity_type,
127
- extract_properties_func=extract_properties_func,
128
- get_additional_props_func=get_additional_props_func
129
- )
130
-
131
- def _generate_glossary_md(self, elements: list, elements_action: str, output_format: str) -> str:
132
- """
133
- Generate markdown for glossaries.
134
-
135
- Args:
136
- elements (list): List of glossary elements
137
- elements_action (str): Action description for elements
138
- output_format (str): Output format
139
-
140
- Returns:
141
- str: Markdown representation
142
- """
143
- # Store the current output format for use by _extract_glossary_properties_with_format
144
- self._current_output_format = output_format
145
-
146
- return self._generate_entity_md(elements=elements, elements_action=elements_action, output_format=output_format,
147
- entity_type="Glossary",
148
- extract_properties_func=self._extract_glossary_properties_with_format)
149
-
150
- def _generate_entity_md_table(self, elements: list, search_string: str, entity_type: str, extract_properties_func,
151
- columns: list, get_additional_props_func=None, output_format: str = 'LIST') -> str:
152
- """
153
- Generic method to generate a markdown table for entities (glossaries, terms, categories).
154
-
155
- Args:
156
- elements (list): List of entity elements
157
- search_string (str): The search string used
158
- entity_type (str): Type of entity (Glossary, Term, Category)
159
- extract_properties_func: Function to extract properties from an element
160
- columns: List of column definitions, each containing 'name', 'key', and 'format' (optional)
161
- get_additional_props_func: Optional function to get additional properties
162
- output_format (str): Output format (FORM, REPORT, LIST, etc.)
163
-
164
- Returns:
165
- str: Markdown table
166
- """
167
- return generate_entity_md_table(
168
- elements=elements,
169
- search_string=search_string,
170
- entity_type=entity_type,
171
- extract_properties_func=extract_properties_func,
172
- columns=columns,
173
- get_additional_props_func=get_additional_props_func,
174
- output_format=output_format
175
- )
176
-
177
- def _generate_glossary_md_table(self, elements: list, search_string: str) -> str:
178
- """
179
- Generate a markdown table for glossaries.
180
-
181
- Args:
182
- elements (list): List of glossary elements
183
- search_string (str): The search string used
184
-
185
- Returns:
186
- str: Markdown table
187
- """
188
- # Store the current output format for use by _extract_glossary_properties_with_format
189
- self._current_output_format = 'LIST' # Tables use LIST format
190
-
191
- columns = [{'name': 'Glossary Name', 'key': 'display_name'},
192
- {'name': 'Qualified Name', 'key': 'qualified_name'},
193
- {'name': 'Language', 'key': 'language', 'format': True},
194
- {'name': 'Description', 'key': 'description', 'format': True},
195
- {'name': 'Usage', 'key': 'usage', 'format': True},
196
- {'name': 'Categories', 'key': 'categories_names', 'format': True}, ]
197
-
198
- return self._generate_entity_md_table(elements=elements, search_string=search_string, entity_type="Glossary",
199
- extract_properties_func=self._extract_glossary_properties_with_format,
200
- columns=columns)
201
-
202
- def _generate_entity_dict(self, elements: list, extract_properties_func, get_additional_props_func=None,
203
- include_keys=None, exclude_keys=None, output_format: str = 'DICT') -> list:
204
- """
205
- Generic method to generate a dictionary representation of entities (glossaries, terms, categories).
206
-
207
- Args:
208
- elements (list): List of entity elements
209
- extract_properties_func: Function to extract properties from an element
210
- get_additional_props_func: Optional function to get additional properties
211
- include_keys: Optional list of keys to include in the result (if None, include all)
212
- exclude_keys: Optional list of keys to exclude from the result (if None, exclude none)
213
- output_format (str): Output format (FORM, REPORT, DICT, etc.)
214
-
215
- Returns:
216
- list: List of entity dictionaries
217
- """
218
- return generate_entity_dict(
219
- elements=elements,
220
- extract_properties_func=extract_properties_func,
221
- get_additional_props_func=get_additional_props_func,
222
- include_keys=include_keys,
223
- exclude_keys=exclude_keys,
224
- output_format=output_format
225
- )
226
-
227
- def _generate_glossary_dict(self, elements: list, output_format: str = 'DICT') -> list:
228
- """
229
- Generate a dictionary representation of glossaries.
230
-
231
- Args:
232
- elements (list): List of glossary elements
233
- output_format (str): Output format (FORM, REPORT, DICT, etc.)
234
-
235
- Returns:
236
- list: List of glossary dictionaries
237
- """
238
- # Store the current output format for use by _extract_glossary_properties_with_format
239
- self._current_output_format = output_format
240
-
241
- return self._generate_entity_dict(elements=elements, extract_properties_func=self._extract_glossary_properties_with_format,
242
- exclude_keys=['properties'], output_format=output_format)
243
-
244
- def _extract_glossary_properties_with_format(self, element: dict) -> dict:
245
- """
246
- Wrapper function for _extract_glossary_properties that passes the current output format.
247
- This is used internally by generate_glossaries_md.
248
-
249
- Args:
250
- element (dict): The glossary element
251
-
252
- Returns:
253
- dict: Dictionary of extracted properties
254
- """
255
- # The output_format is stored as an instance variable during generate_glossaries_md
256
- return self._extract_glossary_properties(element, self._current_output_format)
257
-
258
- def generate_glossaries_md(self, elements: list | dict, search_string: str,
259
- output_format: str = 'MD', output_format_set: str | dict = None) -> str | list:
260
- """
261
- Generate markdown or dictionary representation of glossaries.
262
-
263
- Args:
264
- elements (list | dict): List or dictionary of glossary elements
265
- search_string (str): The search string used
266
- output_format (str): Output format (MD, FORM, REPORT, LIST, DICT)
267
- output_format_set (str | dict, optional): Output format set name or dictionary. Defaults to None.
268
-
269
- Returns:
270
- str | list: Markdown string or list of dictionaries depending on output_format
271
- """
272
- # Store the current output format for use by _extract_glossary_properties_with_format
273
- self._current_output_format = output_format
274
-
275
- # Define default columns for LIST format
276
- default_columns = [
277
- {'name': 'Glossary Name', 'key': 'display_name'},
278
- {'name': 'Qualified Name', 'key': 'qualified_name'},
279
- {'name': 'Language', 'key': 'language', 'format': True},
280
- {'name': 'Description', 'key': 'description', 'format': True},
281
- {'name': 'Usage', 'key': 'usage', 'format': True},
282
- {'name': 'Categories', 'key': 'categories_names', 'format': True},
283
- ]
284
-
285
- # Determine the output format set
286
- output_formats = None
287
- if output_format_set:
288
- if isinstance(output_format_set, str):
289
- output_formats = select_output_format_set(output_format_set, output_format)
290
- elif isinstance(output_format_set, dict):
291
- output_formats = get_output_format_type_match(output_format_set, output_format)
292
- else:
293
- # Use default entity type to lookup the output format
294
- output_formats = select_output_format_set("Glossary", output_format)
295
- # If no format set is found, create one with default columns
296
- if not output_formats and output_format == 'LIST':
297
- output_formats = {"formats": {"columns": default_columns}}
298
-
299
- return generate_output(
300
- elements=elements,
301
- search_string=search_string,
302
- entity_type="Glossary",
303
- output_format=output_format,
304
- extract_properties_func=self._extract_glossary_properties_with_format,
305
- columns_struct=output_formats
306
- )
307
-
308
- def _extract_term_properties(self, element: dict) -> dict:
309
- """
310
- Extract common properties from a term element.
311
-
312
- Args:
313
- element (dict): The term element
314
-
315
- Returns:
316
- dict: Dictionary of extracted properties
317
- """
318
- guid = element['elementHeader'].get("guid", None)
319
- properties = element['glossaryTermProperties']
320
- display_name = properties.get("displayName", "") or ""
321
- summary = properties.get("summary", "") or ""
322
- description = properties.get("description", "") or ""
323
- examples = properties.get("examples", "") or ""
324
- usage = properties.get("usage", "") or ""
325
- pub_version = properties.get("publishVersionIdentifier", "") or ""
326
- qualified_name = properties.get("qualifiedName", "") or ""
327
- status = element['elementHeader'].get('status', "") or ""
328
- aliases = ", ".join(properties.get("aliases", "")) or ""
329
-
330
- return {
331
- 'GUID': guid, 'properties': properties, 'display_name': display_name, 'aliases': aliases,
332
- 'summary': summary, 'description': description, 'examples': examples, 'usage': usage,
333
- 'version identifier': pub_version, 'qualified_name': qualified_name, 'status': status
334
- }
335
-
336
- def _get_categories_for_term(self, term_guid: str, output_format: str = None) -> tuple[list, str]:
337
- """
338
- Get a list of categories for a given term.
339
-
340
- Args:
341
- term_guid (str): The GUID of the term
342
- output_format (str): Output format (FORM, REPORT, LIST, etc.)
343
-
344
- Returns:
345
- tuple: A tuple containing:
346
- - list: List of category names
347
- - str: Formatted string of category names for markdown
348
- """
349
- category_names = []
350
- category_list_md = "\n"
351
-
352
- category_list = self.get_categories_for_term(term_guid)
353
- if type(category_list) is str and category_list == NO_CATEGORIES_FOUND:
354
- category_list_md = ''
355
- elif isinstance(category_list, list) and len(category_list) > 0:
356
- first_cat = True
357
- for category in category_list:
358
- # Use qualified name for FORM output, display name for REPORT and LIST output
359
- if output_format in ['REPORT', 'LIST']:
360
- category_name = category["glossaryCategoryProperties"].get("displayName", '---')
361
- else:
362
- category_name = category["glossaryCategoryProperties"].get("qualifiedName", '---')
363
-
364
- if category_name:
365
- category_names.append(category_name)
366
- if first_cat:
367
- category_list_md += f" {category_name}\n"
368
- first_cat = False
369
- else:
370
- category_list_md += f", {category_name}\n"
371
- else:
372
- category_list_md = '---'
373
-
374
- return category_names, category_list_md
375
-
376
- def _get_term_table_properties(self, element: dict, term_guid: str, output_format: str = None) -> dict:
377
- """
378
- Get properties for a term table row.
379
-
380
- Args:
381
- element (dict): The term element
382
- term_guid (str): The GUID of the term
383
- output_format (str): Output format (FORM, REPORT, etc.)
384
-
385
- Returns:
386
- dict: Dictionary of properties for the table row
387
- """
388
- # Get glossary information
389
- glossary_qualified_name = self._get_glossary_name_for_element(element, output_format)
390
-
391
- # Get categories
392
- category_names, _ = self._get_categories_for_term(term_guid, output_format)
393
- categories_str = ", ".join(category_names) if category_names else "---"
394
-
395
- return {
396
- 'glossary': glossary_qualified_name, 'categories_str': categories_str
397
- }
398
-
399
- def _generate_term_md_table(self, elements: list, search_string: str, output_format: str = 'LIST') -> str:
400
- """
401
- Generate a markdown table for terms.
402
-
403
- Args:
404
- elements (list): List of term elements
405
- search_string (str): The search string used
406
- output_format (str): Output format (FORM, REPORT, LIST, etc.)
407
-
408
- Returns:
409
- str: Markdown table
410
- """
411
- columns = [{'name': 'Term Name', 'key': 'display_name'}, {'name': 'Qualified Name', 'key': 'qualified_name'},
412
- {'name': 'Aliases', 'key': 'aliases', 'format': True},
413
- {'name': 'Summary', 'key': 'summary', 'format': True}, {'name': 'Glossary', 'key': 'glossary'},
414
- {'name': 'Categories', 'key': 'categories_str', 'format': True}]
415
-
416
- # Create a wrapper function to pass output_format to _get_term_table_properties
417
- def get_table_props_with_format(element, term_guid, output_format_param=None):
418
- return self._get_term_table_properties(element, term_guid, output_format)
419
-
420
- return self._generate_entity_md_table(elements=elements, search_string=search_string, entity_type="Term",
421
- extract_properties_func=self._extract_term_properties, columns=columns,
422
- get_additional_props_func=get_table_props_with_format)
423
-
424
- def _get_term_dict_properties(self, element: dict, term_guid: str, output_format: str = None) -> dict:
425
- """
426
- Get additional properties for a term dictionary.
427
-
428
- Args:
429
- element (dict): The term element
430
- term_guid (str): The GUID of the term
431
- output_format (str): Output format (FORM, REPORT, etc.)
432
-
433
- Returns:
434
- dict: Dictionary of additional properties
435
- """
436
- # Get glossary information
437
- glossary_qualified_name = self._get_glossary_name_for_element(element, output_format)
438
-
439
- # Get categories
440
- category_names, _ = self._get_categories_for_term(term_guid, output_format)
441
-
442
- return {
443
- 'in_glossary': glossary_qualified_name, 'categories': category_names,
444
- 'version': element['glossaryTermProperties'].get('publishfinVersionIdentifier', '')
445
- }
446
-
447
- def _generate_term_dict(self, elements: list, output_format: str = 'DICT') -> list:
448
- """
449
- Generate a dictionary representation of terms.
450
-
451
- Args:
452
- elements (list): List of term elements
453
- output_format (str): Output format (FORM, REPORT, DICT, etc.)
454
-
455
- Returns:
456
- list: List of term dictionaries
457
- """
458
-
459
- # Create a wrapper function to pass output_format to _get_term_dict_properties
460
- def get_dict_props_with_format(element, term_guid, output_format_param=None):
461
- return self._get_term_dict_properties(element, term_guid, output_format)
462
-
463
- return self._generate_entity_dict(elements=elements, extract_properties_func=self._extract_term_properties,
464
- get_additional_props_func=get_dict_props_with_format,
465
- exclude_keys=['properties', 'pub_version']
466
- # Exclude raw properties and pub_version (renamed to version)
467
- )
468
-
469
- def _get_term_additional_properties(self, element: dict, term_guid: str, output_format: str = None) -> dict:
470
- """
471
- Get additional properties for a term.
472
-
473
- Args:
474
- element (dict): The term element
475
- term_guid (str): The GUID of the term
476
- output_format (str): Output format (FORM, REPORT, etc.)
477
-
478
- Returns:
479
- dict: Dictionary of additional properties
480
- """
481
- # Get glossary information
482
- glossary_qualified_name = self._get_glossary_name_for_element(element, output_format)
483
-
484
- # Get categories
485
- _, category_list_md = self._get_categories_for_term(term_guid, output_format)
486
-
487
- return {
488
- 'in_glossary': glossary_qualified_name, 'categories': category_list_md
489
- }
490
-
491
- def _generate_term_md(self, elements: list, elements_action: str, output_format: str) -> str:
492
- """
493
- Generate markdown for terms.
494
-
495
- Args:
496
- elements (list): List of term elements
497
- elements_action (str): Action description for elements
498
- output_format (str): Output format
499
-
500
- Returns:
501
- str: Markdown representation
502
- """
503
- return self._generate_entity_md(elements=elements, elements_action=elements_action, output_format=output_format,
504
- entity_type="Term", extract_properties_func=self._extract_term_properties,
505
- get_additional_props_func=self._get_term_additional_properties)
506
-
507
- def generate_terms_md(self, elements: list | dict, search_string: str, output_format: str = 'MD', output_format_set: str | dict = None) -> str | list:
508
- """
509
- Generate markdown or dictionary representation of terms.
510
-
511
- Args:
512
- elements (list | dict): List or dictionary of term elements
513
- search_string (str): The search string used
514
- output_format (str): Output format (MD, MD-TABLE, DICT, FORM, REPORT)
515
- output_format_set (str | dict, optional): Output format set name or dictionary. Defaults to None.
516
-
517
- Returns:
518
- str | list: Markdown string or list of dictionaries depending on output_format
519
- """
520
- # Define default columns for LIST format
521
- default_columns = [
522
- {'name': 'Term Name', 'key': 'display_name'},
523
- {'name': 'Qualified Name', 'key': 'qualified_name'},
524
- {'name': 'Summary', 'key': 'summary', 'format': True},
525
- {'name': 'Description', 'key': 'description', 'format': True},
526
- {'name': 'Status', 'key': 'status'},
527
- {'name': 'Categories', 'key': 'categories', 'format': True},
528
- {'name': 'Glossary', 'key': 'glossary_name'},
529
- ]
530
-
531
- # Determine the output format set
532
- output_formats = None
533
- if output_format_set:
534
- if isinstance(output_format_set, str):
535
- output_formats = select_output_format_set(output_format_set, output_format)
536
- elif isinstance(output_format_set, dict):
537
- output_formats = get_output_format_type_match(output_format_set, output_format)
538
- else:
539
- # Use default entity type to lookup the output format
540
- output_formats = select_output_format_set("Term", output_format)
541
- # If no format set is found, create one with default columns
542
- if not output_formats and output_format == 'LIST':
543
- output_formats = {"formats": {"columns": default_columns}}
544
-
545
- return generate_output(
546
- elements=elements,
547
- search_string=search_string,
548
- entity_type="Term",
549
- output_format=output_format,
550
- extract_properties_func=self._extract_term_properties,
551
- get_additional_props_func=self._get_term_additional_properties,
552
- columns_struct=output_formats
553
- )
554
-
555
- def _get_parent_category_name(self, category_guid: str, output_format: str = None) -> str:
556
- """
557
- Get the parent category name for a given category.
558
-
559
- Args:
560
- category_guid (str): The GUID of the category
561
- output_format (str): Output format (FORM, REPORT, LIST, etc.)
562
-
563
- Returns:
564
- str: The parent category name or ' ' if no parent
565
- """
566
- parent_cat = self.get_category_parent(category_guid)
567
- if isinstance(parent_cat, str):
568
- return ' '
569
-
570
- # Return qualified name for FORM output, display name for REPORT and LIST output
571
- if output_format == 'FORM':
572
- return parent_cat['glossaryCategoryProperties']['qualifiedName']
573
- elif output_format in ['REPORT', 'LIST']:
574
- return parent_cat['glossaryCategoryProperties']['displayName']
575
- else:
576
- # Default to qualified name for backward compatibility
577
- return parent_cat['glossaryCategoryProperties']['qualifiedName']
578
-
579
- def _get_subcategories_list(self, category_guid: str, output_format: str = None) -> tuple[list, str]:
580
- """
581
- Get a list of subcategories for a given category.
582
-
583
- Args:
584
- category_guid (str): The GUID of the category
585
- output_format (str): Output format (FORM, REPORT, LIST, etc.)
586
-
587
- Returns:
588
- tuple: A tuple containing:
589
- - list: List of subcategory names
590
- - str: Formatted string of subcategory names for markdown
591
- """
592
- subcategories = self.get_glossary_subcategories(category_guid)
593
- subcategory_list = []
594
-
595
- if isinstance(subcategories, str) and subcategories == NO_CATEGORIES_FOUND:
596
- subcategory_list_md = '---'
597
- elif isinstance(subcategories, list) and len(subcategories) > 0:
598
- for subcat in subcategories:
599
- # Use qualified name for FORM output, display name for REPORT and LIST output
600
- if output_format == 'FORM':
601
- subcat_name = subcat["glossaryCategoryProperties"].get("qualifiedName", '')
602
- elif output_format in ['REPORT', 'LIST']:
603
- subcat_name = subcat["glossaryCategoryProperties"].get("displayName", '')
604
- else:
605
- # Default to qualified name for backward compatibility
606
- subcat_name = subcat["glossaryCategoryProperties"].get("qualifiedName", '')
607
-
608
- if subcat_name:
609
- subcategory_list.append(subcat_name)
610
- subcategory_list_md = ", ".join(subcategory_list)
611
- else:
612
- subcategory_list_md = '---'
613
-
614
- return subcategory_list, subcategory_list_md
615
-
616
- def _get_glossary_name_for_element(self, element: dict, output_format: str = None) -> str:
617
- """
618
- Get the glossary name for a given element.
619
-
620
- Args:
621
- element (dict): The element dictionary
622
- output_format (str): Output format (FORM, REPORT, etc.)
623
-
624
- Returns:
625
- str: The glossary name or '---' if not found
626
- """
627
- classification_props = element["elementHeader"]['classifications'][0].get('classificationProperties', None)
628
- if classification_props is None:
629
- return '---'
630
-
631
- glossary_guid = classification_props.get('anchorScopeGUID', '---')
632
- if glossary_guid == '---':
633
- return '---'
634
-
635
- glossary = self.get_glossary_by_guid(glossary_guid)
636
-
637
- # Return display name for REPORT output, qualified name otherwise
638
- if output_format == 'REPORT':
639
- return glossary['glossaryProperties']['displayName']
640
- else:
641
- return glossary['glossaryProperties']['qualifiedName']
642
-
643
- def _extract_category_properties(self, element: dict) -> dict:
644
- """
645
- Extract common properties from a category element.
646
-
647
- Args:
648
- element (dict): The category element
649
-
650
- Returns:
651
- dict: Dictionary of extracted properties
652
- """
653
- guid = element['elementHeader'].get("guid", None)
654
- properties = element['glossaryCategoryProperties']
655
- display_name = properties.get("displayName", "") or ""
656
- description = properties.get("description", "") or ""
657
- qualified_name = properties.get("qualifiedName", "") or ""
658
-
659
- return {
660
- 'GUID': guid, 'properties': properties, 'display_name': display_name, 'description': description,
661
- 'qualified_name': qualified_name
662
- }
663
-
664
- def _get_category_table_properties(self, element: dict, category_guid: str, output_format: str = None) -> dict:
665
- """
666
- Get properties for a category table row.
667
-
668
- Args:
669
- element (dict): The category element
670
- category_guid (str): The GUID of the category
671
- output_format (str): Output format (FORM, REPORT, etc.)
672
-
673
- Returns:
674
- dict: Dictionary of properties for the table row
675
- """
676
- # Get parent category
677
- parent_cat_md = self._get_parent_category_name(category_guid, output_format)
678
-
679
- # Get subcategories
680
- _, subcategory_list_md = self._get_subcategories_list(category_guid, output_format)
681
-
682
- return {
683
- 'parent_category': parent_cat_md, 'subcategories': subcategory_list_md
684
- }
685
-
686
- def _generate_category_md_table(self, elements: list, search_string: str, output_format: str = 'LIST') -> str:
687
- """
688
- Generate a markdown table for categories.
689
-
690
- Args:
691
- elements (list): List of category elements
692
- search_string (str): The search string used
693
- output_format (str): Output format (FORM, REPORT, etc.)
694
-
695
- Returns:
696
- str: Markdown table
697
- """
698
- columns = [{'name': 'Display Name', 'key': 'display_name'},
699
- {'name': 'Description', 'key': 'description', 'format': True},
700
- {'name': 'Qualified Name', 'key': 'qualified_name'},
701
- {'name': 'Parent Category', 'key': 'parent_category'},
702
- {'name': 'Subcategories', 'key': 'subcategories', 'format': True}]
703
-
704
- # Create a wrapper function to pass output_format to _get_category_table_properties
705
- def get_table_props_with_format(element, category_guid, output_format_param=None):
706
- return self._get_category_table_properties(element, category_guid, output_format)
707
-
708
- return self._generate_entity_md_table(elements=elements, search_string=search_string, entity_type="Category",
709
- extract_properties_func=self._extract_category_properties,
710
- columns=columns, get_additional_props_func=get_table_props_with_format)
711
-
712
- def _get_category_dict_properties(self, element: dict, category_guid: str, output_format: str = None) -> dict:
713
- """
714
- Get additional properties for a category dictionary.
715
-
716
- Args:
717
- element (dict): The category element
718
- category_guid (str): The GUID of the category
719
- output_format (str): Output format (FORM, REPORT, etc.)
720
-
721
- Returns:
722
- dict: Dictionary of additional properties
723
- """
724
- # Get parent category
725
- parent_cat_md = self._get_parent_category_name(category_guid, output_format)
726
-
727
- # Get subcategories
728
- subcategory_list, _ = self._get_subcategories_list(category_guid, output_format)
729
-
730
- # Get glossary information
731
- glossary_qualified_name = self._get_glossary_name_for_element(element, output_format)
732
-
733
- return {
734
- 'parent_category': parent_cat_md, 'subcategories': subcategory_list, 'in_glossary': glossary_qualified_name
735
- }
736
-
737
- def _generate_category_dict(self, elements: list, output_format: str = 'DICT') -> list:
738
- """
739
- Generate a dictionary representation of categories.
740
-
741
- Args:
742
- elements (list): List of category elements
743
- output_format (str): Output format (FORM, REPORT, etc.)
744
-
745
- Returns:
746
- list: List of category dictionaries
747
- """
748
-
749
- # Create a wrapper function to pass output_format to _get_category_dict_properties
750
- def get_dict_props_with_format(element, category_guid, output_format_param=None):
751
- return self._get_category_dict_properties(element, category_guid, output_format)
752
-
753
- return self._generate_entity_dict(elements=elements, extract_properties_func=self._extract_category_properties,
754
- get_additional_props_func=get_dict_props_with_format,
755
- exclude_keys=['properties'], # Exclude raw properties
756
- output_format=output_format)
757
-
758
- def _get_category_additional_properties(self, element: dict, category_guid: str, output_format: str = None) -> dict:
759
- """
760
- Get additional properties for a category.
761
-
762
- Args:
763
- element (dict): The category element
764
- category_guid (str): The GUID of the category
765
- output_format (str): Output format (FORM, REPORT, etc.)
766
-
767
- Returns:
768
- dict: Dictionary of additional properties
769
- """
770
- # Get parent category
771
- parent_cat_md = self._get_parent_category_name(category_guid, output_format)
772
-
773
- # Get glossary information
774
- glossary_qualified_name = self._get_glossary_name_for_element(element, output_format)
775
-
776
- # Only include subcategories if output_format is not FORM, REPORT, or MD
777
- if output_format not in ['FORM', 'REPORT', 'MD']:
778
- # Get subcategories
779
- _, subcategory_list_md = self._get_subcategories_list(category_guid, output_format)
780
- return {
781
- 'in_glossary': glossary_qualified_name, 'parent_category': parent_cat_md,
782
- 'subcategories': subcategory_list_md
783
- }
784
- else:
785
- return {
786
- 'in_glossary': glossary_qualified_name, 'parent_category': parent_cat_md
787
- }
788
-
789
- def _generate_category_md(self, elements: list, elements_action: str, output_format: str) -> str:
790
- """
791
- Generate markdown for categories.
792
-
793
- Args:
794
- elements (list): List of category elements
795
- elements_action (str): Action description for elements
796
- output_format (str): Output format
797
-
798
- Returns:
799
- str: Markdown representation
800
- """
801
-
802
- # Create a wrapper function to pass output_format to _get_category_additional_properties
803
- def get_additional_props_with_format(element, category_guid, output_format_param=None):
804
- return self._get_category_additional_properties(element, category_guid, output_format)
805
-
806
- return self._generate_entity_md(elements=elements, elements_action=elements_action, output_format=output_format,
807
- entity_type="Category",
808
- extract_properties_func=self._extract_category_properties,
809
- get_additional_props_func=get_additional_props_with_format)
810
-
811
- def generate_categories_md(self, elements: list | dict, search_string: str,
812
- output_format: str = 'MD', output_format_set: str | dict = None) -> str | list:
813
- """
814
- Generate markdown or dictionary representation of categories.
815
-
816
- Args:
817
- elements (list | dict): List or dictionary of category elements
818
- search_string (str): The search string used
819
- output_format (str): Output format (MD, LIST, DICT, FORM, REPORT)
820
- output_format_set (str | dict, optional): Output format set name or dictionary. Defaults to None.
821
-
822
- Returns:
823
- str | list: Markdown string or list of dictionaries depending on output_format
824
- """
825
- # Define default columns for LIST format
826
- default_columns = [
827
- {'name': 'Category Name', 'key': 'display_name'},
828
- {'name': 'Qualified Name', 'key': 'qualified_name'},
829
- {'name': 'Description', 'key': 'description', 'format': True},
830
- {'name': 'Parent Category', 'key': 'parent_category', 'format': True},
831
- {'name': 'Subcategories', 'key': 'subcategories', 'format': True},
832
- {'name': 'Glossary', 'key': 'glossary_name'},
833
- ]
834
-
835
- # Determine the output format set
836
- output_formats = None
837
- if output_format_set:
838
- if isinstance(output_format_set, str):
839
- output_formats = select_output_format_set(output_format_set, output_format)
840
- elif isinstance(output_format_set, dict):
841
- output_formats = get_output_format_type_match(output_format_set, output_format)
842
- else:
843
- # Use default entity type to lookup the output format
844
- output_formats = select_output_format_set("Category", output_format)
845
- # If no format set is found, create one with default columns
846
- if not output_formats and output_format == 'LIST':
847
- output_formats = {"formats": {"columns": default_columns}}
848
-
849
- # Create a wrapper function to pass output_format to _get_category_additional_properties
850
- def get_additional_props_with_format(element, category_guid, output_format_param=None):
851
- return self._get_category_additional_properties(element, category_guid, output_format)
852
-
853
- return generate_output(
854
- elements=elements,
855
- search_string=search_string,
856
- entity_type="Category",
857
- output_format=output_format,
858
- extract_properties_func=self._extract_category_properties,
859
- get_additional_props_func=get_additional_props_with_format,
860
- columns_struct=output_formats
861
- )
862
-
863
- #
864
- # Get Valid Values for Enumerations
865
- #
866
-
867
- async def _async_get_glossary_term_statuses(self) -> [str]:
868
- """Return the list of glossary term status enum values. Async version.
869
-
870
- Parameters
871
- ----------
872
-
873
-
874
- Returns
875
- -------
876
- List[str]
877
- A list of glossary term statuses retrieved from the server.
878
-
879
- """
880
-
881
- url = (f"{self.platform_url}/servers/{self.view_server}"
882
- f"/api/open-metadata/glossary-browser/glossaries/terms/status-list")
883
-
884
- response = await self._async_make_request("GET", url)
885
- return response.json().get("statuses", [])
886
-
887
- def get_glossary_term_statuses(self) -> [str]:
888
- """Return the list of glossary term status enum values.
889
-
890
- Parameters
891
- ----------
892
-
893
-
894
- Returns
895
- -------
896
- list of str
897
- A list of glossary term statuses. Each status is represented as a string.
898
-
899
- """
900
- loop = asyncio.get_event_loop()
901
- response = loop.run_until_complete(self._async_get_glossary_term_statuses())
902
- return response
903
-
904
- async def _async_get_glossary_term_rel_statuses(self) -> [str]:
905
- """Return the list of glossary term relationship status enum values. These values are stored in a
906
- term-to-term, or term-to-category, relationship and are used to indicate how much the relationship should be
907
- trusted. Async version.
908
-
909
- Parameters
910
- ----------
911
-
912
-
913
- Returns
914
- -------
915
- List[str]
916
- A list of glossary term statuses retrieved from the server.
917
-
918
- """
919
-
920
- url = (f"{self.platform_url}/servers/{self.view_server}"
921
- f"/api/open-metadata/glossary-browser/glossaries/terms/relationships/status-list")
922
-
923
- response = await self._async_make_request("GET", url)
924
- return response.json().get("statuses", [])
925
-
926
- def get_glossary_term_rel_statuses(self) -> [str]:
927
- """Return the list of glossary term relationship status enum values. These values are stored in a
928
- term-to-term, or term-to-category, relationship and are used to indicate how much the relationship should be
929
- trusted.
930
-
931
- Parameters
932
- ----------
933
-
934
-
935
- Returns
936
- -------
937
- list of str
938
- A list of glossary term statuses. Each status is represented as a string.
939
-
940
- """
941
- loop = asyncio.get_event_loop()
942
- response = loop.run_until_complete(self._async_get_glossary_term_rel_statuses())
943
- return response
944
-
945
- async def _async_get_glossary_term_activity_types(self) -> [str]:
946
- """Return the list of glossary term activity type enum values. Async version.
947
-
948
- Parameters
949
- ----------
950
-
951
-
952
- Returns
953
- -------
954
- List[str]
955
- A list of glossary term statuses retrieved from the server.
956
-
957
- """
958
-
959
- url = (f"{self.platform_url}/servers/{self.view_server}"
960
- f"/api/open-metadata/glossary-browser/glossaries/terms/activity-types")
961
-
962
- response = await self._async_make_request("GET", url)
963
- return response.json().get("types", [])
964
-
965
- def get_glossary_term_activity_types(self) -> [str]:
966
- """Return the list of glossary term activity type enum values.
967
-
968
- Parameters
969
- ----------
970
-
971
-
972
- Returns
973
- -------
974
- list of str
975
- A list of glossary term statuses. Each status is represented as a string.
976
-
977
- """
978
- loop = asyncio.get_event_loop()
979
- response = loop.run_until_complete(self._async_get_glossary_term_statuses())
980
- return response
981
-
982
- async def _async_get_term_relationship_types(self) -> [str]:
983
- """Return the list of term relationship types enum values. Async version.
984
-
985
- Parameters
986
- ----------
987
-
988
-
989
- Returns
990
- -------
991
- List[str]
992
- A list of glossary term relationships retrieved from the server.
993
-
994
- """
995
-
996
- url = (f"{self.platform_url}/servers/{self.view_server}"
997
- f"/api/open-metadata/glossary-manager/glossaries/terms/relationships/type-names")
998
-
999
- response = await self._async_make_request("GET", url)
1000
- return response.json().get("names", [])
1001
-
1002
- def get_term_relationship_types(self) -> [str]:
1003
- """Return the list of term relationship type enum values.
1004
-
1005
- Parameters
1006
- ----------
1007
-
1008
-
1009
- Returns
1010
- -------
1011
- list of str
1012
- A list of term relationship types. Each status is represented as a string.
1013
-
1014
- """
1015
- loop = asyncio.get_event_loop()
1016
- response = loop.run_until_complete(self._async_get_term_relationship_types())
1017
- return response
1018
-
1019
- #
1020
- # Glossaries
1021
- #
1022
-
1023
- async def _async_find_glossaries(self, search_string: str, effective_time: str = None, starts_with: bool = False,
1024
- ends_with: bool = False, ignore_case: bool = False, for_lineage: bool = False,
1025
- for_duplicate_processing: bool = False, type_name: str = None, start_from: int = 0,
1026
- page_size: int = None, output_format: str = 'JSON', output_format_set: str | dict = None) -> list | str:
1027
- """Retrieve the list of glossary metadata elements that contain the search string. Async version.
1028
- The search string is located in the request body and is interpreted as a plain string.
1029
- The request parameters, startsWith, endsWith, and ignoreCase can be used to allow a fuzzy search.
1030
-
1031
- Parameters
1032
- ----------
1033
- search_string: str,
1034
- Search string to use to find matching glossaries. If the search string is '*' then all glossaries returned.
1035
-
1036
- effective_time: str, [default=None], optional
1037
- Effective time of the query. If not specified will default to any time. Time format is
1038
- "YYYY-MM-DDTHH:MM:SS" (ISO 8601)
1039
-
1040
- If not provided, the server name associated with the instance is used.
1041
- starts_with : bool, [default=False], optional
1042
- Starts with the supplied string.
1043
- ends_with : bool, [default=False], optional
1044
- Ends with the supplied string
1045
- ignore_case : bool, [default=False], optional
1046
- Ignore case when searching
1047
- for_lineage : bool, [default=False], optional
1048
-
1049
- for_duplicate_processing : bool, [default=False], optional
1050
- type_name: str, [default=None], optional
1051
- An optional parameter indicating the subtype of the glossary to filter by.
1052
- Values include 'ControlledGlossary', 'EditingGlossary', and 'StagingGlossary'
1053
- start_from: int, [default=0], optional
1054
- When multiple pages of results are available, the page number to start from.
1055
- page_size: int, [default=None]
1056
- The number of items to return in a single page. If not specified, the default will be taken from
1057
- the class instance.
1058
- output_format: str, default = 'JSON'
1059
- Type of output to produce:
1060
- JSON - output standard json
1061
- MD - output standard markdown with no preamble
1062
- FORM - output markdown with a preamble for a form
1063
- REPORT - output markdown with a preamble for a report
1064
- output_format_set: str | dict, optional
1065
- Output format set name or dictionary. Defaults to None.
1066
-
1067
- Returns
1068
- -------
1069
- List | str
1070
-
1071
- A list of glossary definitions active in the server.
1072
-
1073
- Raises
1074
- ------
1075
-
1076
- InvalidParameterException
1077
- If the client passes incorrect parameters on the request - such as bad URLs or invalid values
1078
- PropertyServerException
1079
- Raised by the server when an issue arises in processing a valid request
1080
- NotAuthorizedException
1081
- The principle specified by the user_id does not have authorization for the requested action
1082
-
1083
- """
1084
-
1085
- if page_size is None:
1086
- page_size = self.page_size
1087
- starts_with_s = str(starts_with).lower()
1088
- ends_with_s = str(ends_with).lower()
1089
- ignore_case_s = str(ignore_case).lower()
1090
- for_lineage_s = str(for_lineage).lower()
1091
- for_duplicate_processing_s = str(for_duplicate_processing).lower()
1092
-
1093
- validate_search_string(search_string)
1094
-
1095
- if search_string == "*":
1096
- search_string = None
1097
-
1098
- body = {
1099
- "class": "SearchStringRequestBody", "searchString": search_string, "effectiveTime": effective_time,
1100
- "typeName": type_name,
1101
- }
1102
-
1103
- url = (f"{self.platform_url}/servers/{self.view_server}/api/open-metadata/glossary-browser/glossaries/"
1104
- f"by-search-string?startFrom={start_from}&pageSize={page_size}&startsWith={starts_with_s}&"
1105
- f"endsWith={ends_with_s}&ignoreCase={ignore_case_s}&forLineage={for_lineage_s}&"
1106
- f"forDuplicateProcessing={for_duplicate_processing_s}")
1107
-
1108
- response = await self._async_make_request("POST", url, body_slimmer(body))
1109
- element = response.json().get("elementList", NO_GLOSSARIES_FOUND)
1110
- if element == NO_GLOSSARIES_FOUND:
1111
- if output_format == 'JSON':
1112
- return NO_GLOSSARIES_FOUND
1113
- elif output_format in ['MD', 'FORM', 'REPORT', 'LIST']:
1114
- return "\n# No glossaries found.\n"
1115
- elif output_format == 'DICT':
1116
- return None
1117
-
1118
- if output_format != 'JSON': # return a simplified markdown representation
1119
- return self.generate_glossaries_md(element, search_string, output_format, output_format_set)
1120
- return response.json().get("elementList", NO_GLOSSARIES_FOUND)
1121
-
1122
- def find_glossaries(self, search_string: str, effective_time: str = None, starts_with: bool = False,
1123
- ends_with: bool = False, ignore_case: bool = False, for_lineage: bool = False,
1124
- for_duplicate_processing: bool = False, type_name: str = None, start_from: int = 0,
1125
- page_size: int = None, output_format: str = "JSON", output_format_set: str | dict = None) -> list | str:
1126
- """Retrieve the list of glossary metadata elements that contain the search string.
1127
- The search string is located in the request body and is interpreted as a plain string.
1128
- The request parameters, startsWith, endsWith, and ignoreCase can be used to allow a fuzzy search.
1129
-
1130
- Parameters
1131
- ----------
1132
- search_string: str,
1133
- Search string to use to find matching glossaries. If the search string is '*',
1134
- then all glossaries returned.
1135
-
1136
- effective_time: str, [default=None], optional
1137
- Effective time of the query. If not specified will default to any time. Time format is
1138
- "YYYY-MM-DDTHH:MM:SS" (ISO 8601)
1139
-
1140
- If not provided, the server name associated with the instance is used.
1141
- starts_with : bool, [default=False], optional
1142
- Starts with the supplied string.
1143
- ends_with : bool, [default=False], optional
1144
- Ends with the supplied string
1145
- ignore_case : bool, [default=False], optional
1146
- Ignore case when searching
1147
- for_lineage : bool, [default=False], optional
1148
- Indicates the search is for lineage.
1149
- for_duplicate_processing : bool, [default=False], optional
1150
- type_name: str, [default=None], optional
1151
- An optional parameter indicating the subtype of the glossary to filter by.
1152
- Values include 'ControlledGlossary', 'EditingGlossary', and 'StagingGlossary'
1153
- start_from : int, [default=0], optional
1154
- When multiple pages of results are available, the page number to start from.
1155
- page_size: int, [default=None]
1156
- The number of items to return in a single page. If not specified, the default will be taken from
1157
- the class instance.
1158
- output_format: str, default = 'JSON'
1159
- Type of output to produce:
1160
- JSON - output standard json
1161
- MD - output standard markdown with no preamble
1162
- FORM - output markdown with a preamble for a form
1163
- REPORT - output markdown with a preamble for a report
1164
- LIST - output a markdown table with columns for Glossary Name, Qualified Name, Language, Description,
1165
- Usage
1166
- DICT - output a dictionary structure containing all attributes
1167
- output_format_set: str | dict, optional
1168
- Output format set name or dictionary. Defaults to None.
1169
- Returns
1170
- -------
1171
- List | str
1172
-
1173
- A list of glossary definitions active in the server.
1174
-
1175
- Raises
1176
- ------
1177
-
1178
- InvalidParameterException
1179
- If the client passes incorrect parameters on the request - such as bad URLs or invalid values
1180
- PropertyServerException
1181
- Raised by the server when an issue arises in processing a valid request
1182
- NotAuthorizedException
1183
- The principle specified by the user_id does not have authorization for the requested action
1184
-
1185
- """
1186
- loop = asyncio.get_event_loop()
1187
- response = loop.run_until_complete(
1188
- self._async_find_glossaries(search_string, effective_time, starts_with, ends_with, ignore_case, for_lineage,
1189
- for_duplicate_processing, type_name, start_from, page_size, output_format, output_format_set))
1190
-
1191
- return response
1192
-
1193
- async def _async_get_glossary_by_guid(self, glossary_guid: str, effective_time: str = None,
1194
- output_format: str = "JSON", output_format_set: str | dict = None) -> dict | str:
1195
- """Retrieves information about a glossary
1196
- Parameters
1197
- ----------
1198
- glossary_guid : str
1199
- Unique idetifier for the glossary
1200
- effective_time: str, optional
1201
- Effective time of the query. If not specified will default to any time. Time format is
1202
- "YYYY-MM-DDTHH:MM:SS" (ISO 8601)
1203
- output_format: str, default = 'JSON'
1204
- Type of output to produce:
1205
- JSON - output standard json
1206
- MD - output standard markdown with no preamble
1207
- FORM - output markdown with a preamble for a form
1208
- REPORT - output markdown with a preamble for a report
1209
- LIST - output a markdown table with columns for Glossary Name, Qualified Name, Language, Description,
1210
- Usage
1211
- DICT - output a dictionary structure containing all attributes
1212
- output_format_set: str | dict, optional
1213
- Output format set name or dictionary. Defaults to None.
1214
-
1215
- Returns
1216
- -------
1217
- dict | str
1218
- if output format is JSON: The glossary definition associated with the glossary_guid
1219
- if output format is MD: A markdown string with the same information.
1220
- Raises
1221
- ------
1222
- InvalidParameterException
1223
- If the client passes incorrect parameters on the request - such as bad URLs or invalid values.
1224
- PropertyServerException
1225
- Raised by the server when an issue arises in processing a valid request.
1226
- NotAuthorizedException
1227
- The principle specified by the user_id does not have authorization for the requested action.
1228
- Notes
1229
- -----
1230
- """
1231
- output_format = output_format.upper()
1232
- validate_guid(glossary_guid)
1233
-
1234
- body = {
1235
- "class": "EffectiveTimeQueryRequestBody", "effectiveTime": effective_time
1236
- }
1237
- url = (f"{self.platform_url}/servers/{self.view_server}/api/open-metadata/glossary-browser/glossaries/"
1238
- f"{glossary_guid}/retrieve")
1239
- response = await self._async_make_request("POST", url, body_slimmer(body))
1240
- element = response.json().get("element", NO_GLOSSARIES_FOUND)
1241
- if element == NO_GLOSSARIES_FOUND:
1242
- return NO_GLOSSARIES_FOUND
1243
- if output_format != 'JSON': # return a simplified markdown representation
1244
- return self.generate_glossaries_md(element, "GUID", output_format, output_format_set)
1245
- return response.json().get("element", NO_GLOSSARIES_FOUND)
1246
-
1247
- def get_glossary_by_guid(self, glossary_guid: str, effective_time: str = None, output_format: str = "JSON", output_format_set: str | dict = None) -> dict:
1248
- """Retrieves information about a glossary
1249
- Parameters
1250
- ----------
1251
- glossary_guid : str
1252
- Unique idetifier for the glossary
1253
- effective_time: str, optional
1254
- Effective time of the query. If not specified will default to any time. Time format is
1255
- "YYYY-MM-DDTHH:MM:SS" (ISO 8601)
1256
- output_format: str, default = 'JSON'
1257
- Type of output to produce:
1258
- JSON - output standard json
1259
- MD - output standard markdown with no preamble
1260
- FORM - output markdown with a preamble for a form
1261
- REPORT - output markdown with a preamble for a report
1262
- LIST - output a markdown table with columns for Glossary Name, Qualified Name, Language, Description,
1263
- Usage
1264
- DICT - output a dictionary structure containing all attributes
1265
- output_format_set: str | dict, optional
1266
- Output format set name or dictionary. Defaults to None.
1267
-
1268
- Returns
1269
- -------
1270
- dict
1271
- The glossary definition associated with the glossary_guid
1272
-
1273
- Raises
1274
- ------
1275
- InvalidParameterException
1276
- If the client passes incorrect parameters on the request - such as bad URLs or invalid values.
1277
- PropertyServerException
1278
- Raised by the server when an issue arises in processing a valid request.
1279
- NotAuthorizedException
1280
- The principle specified by the user_id does not have authorization for the requested action.
1281
- Notes
1282
- -----
1283
- """
1284
- loop = asyncio.get_event_loop()
1285
- response = loop.run_until_complete(
1286
- self._async_get_glossary_by_guid(glossary_guid, effective_time, output_format, output_format_set))
1287
- return response
1288
-
1289
- async def _async_get_glossaries_by_name(self, glossary_name: str, effective_time: str = None, start_from: int = 0,
1290
- page_size: int = None, ) -> dict | str:
1291
- """Retrieve the list of glossary metadata elements with an exactly matching qualified or display name.
1292
- There are no wildcards supported on this request.
1293
-
1294
- Parameters
1295
- ----------
1296
- glossary_name: str,
1297
- Name of the glossary to be retrieved
1298
- effective_time: datetime, [default=None], optional
1299
- Effective time of the query. If not specified will default to any effective time. Time format is
1300
- "YYYY-MM-DDTHH:MM:SS" (ISO 8601)
1301
-
1302
- If not provided, the server name associated with the instance is used.
1303
- start_from: int, [default=0], optional
1304
- When multiple pages of results are available, the page number to start from.
1305
- page_size: int, [default=None]
1306
- The number of items to return in a single page. If not specified, the default will be taken from
1307
- the class instance.
1308
-
1309
- Returns
1310
- -------
1311
- None
1312
-
1313
- Raises
1314
- ------
1315
-
1316
- InvalidParameterException
1317
- If the client passes incorrect parameters on the request - such as bad URLs or invalid values
1318
- PropertyServerException
1319
- Raised by the server when an issue arises in processing a valid request
1320
- NotAuthorizedException
1321
- The principle specified by the user_id does not have authorization for the requested action
1322
- ConfigurationErrorException
1323
- Raised when configuration parameters passed on earlier calls turn out to be
1324
- invalid or make the new call invalid.
1325
- """
1326
-
1327
- if page_size is None:
1328
- page_size = self.page_size
1329
- validate_name(glossary_name)
1330
-
1331
- if effective_time is None:
1332
- body = {"name": glossary_name}
1333
- else:
1334
- body = {"name": glossary_name, "effectiveTime": effective_time}
1335
-
1336
- url = (f"{self.platform_url}/servers/{self.view_server}/api/open-metadata/glossary-browser/glossaries/"
1337
- f"by-name?startFrom={start_from}&pageSize={page_size}")
1338
-
1339
- response = await self._async_make_request("POST", url, body)
1340
- return response.json().get("elementList", "No glossaries found")
1341
-
1342
- def get_glossaries_by_name(self, glossary_name: str, effective_time: str = None, start_from: int = 0,
1343
- page_size: int = None, ) -> dict | str:
1344
- """Retrieve the list of glossary metadata elements with an exactly matching qualified or display name.
1345
- There are no wildcards supported on this request.
1346
-
1347
- Parameters
1348
- ----------
1349
- glossary_name: str,
1350
- Name of the glossary to be retrieved
1351
- effective_time: datetime, [default=None], optional
1352
- Effective time of the query. If not specified will default to any effective time.
1353
-
1354
- If not provided, the server name associated with the instance is used.
1355
- start_from: int, [default=0], optional
1356
- When multiple pages of results are available, the page number to start from.
1357
- page_size: int, [default=None]
1358
- The number of items to return in a single page. If not specified, the default will be taken from
1359
- the class instance.
1360
-
1361
- Returns
1362
- -------
1363
- None
1364
-
1365
- Raises
1366
- ------
1367
- InvalidParameterException
1368
- If the client passes incorrect parameters on the request - such as bad URLs or invalid values
1369
- PropertyServerException
1370
- Raised by the server when an issue arises in processing a valid request
1371
- NotAuthorizedException
1372
- The principle specified by the user_id does not have authorization for the requested action
1373
- ConfigurationErrorException
1374
- Raised when configuration parameters passed on earlier calls turn out to be
1375
- invalid or make the new call invalid.
1376
- """
1377
- loop = asyncio.get_event_loop()
1378
- response = loop.run_until_complete(
1379
- self._async_get_glossaries_by_name(glossary_name, effective_time, start_from, page_size))
1380
- return response
1381
-
1382
- #
1383
- # Glossary Categories
1384
- #
1385
-
1386
- async def _async_get_glossary_for_category(self, glossary_category_guid: str,
1387
- effective_time: str = None, ) -> dict | str:
1388
- """Retrieve the glossary metadata element for the requested category. The optional request body allows you to
1389
- specify that the glossary element should only be returned if it was effective at a particular time.
1390
-
1391
- Parameters
1392
- ----------
1393
- glossary_category_guid: str,
1394
- Unique identifier for the glossary category.
1395
- effective_time: datetime, [default=None], optional
1396
- Effective time of the query. If not specified will default to any effective time. Time format is
1397
- "YYYY-MM-DDTHH:MM:SS" (ISO 8601)
1398
-
1399
- If not provided, the server name associated with the instance is used.
1400
-
1401
- Returns
1402
- -------
1403
- A dict structure with the glossary metadata element for the requested category.
1404
-
1405
- Raises
1406
- ------
1407
-
1408
- InvalidParameterException
1409
- If the client passes incorrect parameters on the request - such as bad URLs or invalid values
1410
- PropertyServerException
1411
- Raised by the server when an issue arises in processing a valid request
1412
- NotAuthorizedException
1413
- The principle specified by the user_id does not have authorization for the requested action
1414
- ConfigurationErrorException
1415
- Raised when configuration parameters passed on earlier calls turn out to be
1416
- invalid or make the new call invalid.
1417
- """
1418
-
1419
- body = {
1420
- "class": "EffectiveTimeQueryRequestBody", "effectiveTime": effective_time,
1421
- }
1422
-
1423
- url = (f"{self.platform_url}/servers/{self.view_server}/api/open-metadata/glossary-browser/glossaries/"
1424
- f"for-category/{glossary_category_guid}/retrieve")
1425
-
1426
- response = await self._async_make_request("POST", url, body)
1427
- return response.json().get("elementList", "No categories found")
1428
-
1429
- def get_glossary_for_category(self, glossary_category_guid: str, effective_time: str = None, ) -> dict | str:
1430
- """Retrieve the glossary metadata element for the requested category. The optional request body allows you to
1431
- specify that the glossary element should only be returned if it was effective at a particular time.
1432
-
1433
- Parameters
1434
- ----------
1435
- glossary_category_guid: str,
1436
- Unique identifier for the glossary category.
1437
- effective_time: datetime, [default=None], optional
1438
- Effective time of the query. If not specified will default to any effective time. Time format is
1439
- "YYYY-MM-DDTHH:MM:SS" (ISO 8601)
1440
-
1441
- If not provided, the server name associated with the instance is used.
1442
-
1443
- Returns
1444
- -------
1445
- A dict structure with the glossary metadata element for the requested category.
1446
-
1447
- Raises
1448
- ------
1449
-
1450
- InvalidParameterException
1451
- If the client passes incorrect parameters on the request - such as bad URLs or invalid values
1452
- PropertyServerException
1453
- Raised by the server when an issue arises in processing a valid request
1454
- NotAuthorizedException
1455
- The principle specified by the user_id does not have authorization for the requested action
1456
- ConfigurationErrorException
1457
- Raised when configuration parameters passed on earlier calls turn out to be
1458
- invalid or make the new call invalid.
1459
- """
1460
- loop = asyncio.get_event_loop()
1461
- response = loop.run_until_complete(
1462
- self._async_get_glossary_for_category(glossary_category_guid, effective_time))
1463
- return response
1464
-
1465
- async def _async_get_glossary_subcategories(self, glossary_category_guid: str, effective_time: str = None,
1466
- start_from: int = 0, page_size: int = max_paging_size,
1467
- for_lineage: bool = False,
1468
- for_duplicate_processing: bool = False, ) -> dict | str:
1469
- """Glossary categories can be organized in a hierarchy. Retrieve the subcategories for the glossary category
1470
- metadata element with the supplied unique identifier. If the requested category does not have any subcategories,
1471
- null is returned. The optional request body contain an effective time for the query.
1472
-
1473
- Parameters
1474
- ----------
1475
- glossary_category_guid: str,
1476
- Unique identifier for the glossary category.
1477
- effective_time: datetime, [default=None], optional
1478
- Effective time of the query. If not specified will default to any effective time. Time format is
1479
- "YYYY-MM-DDTHH:MM:SS" (ISO 8601)
1480
- start_from: int, [default=0], optional
1481
- The page to start from.
1482
- page_size: int, [default=max_paging_size], optional
1483
- The number of results per page to return.
1484
- for_lineage: bool, [default=False], optional
1485
- Indicates the search is for lineage.
1486
- for_duplicate_processing: bool, [default=False], optional
1487
- If set to True the user will handle duplicate processing.
1488
-
1489
- Returns
1490
- -------
1491
- A dict list with the glossary metadata element for the requested category.
1492
-
1493
- Raises
1494
- ------
1495
-
1496
- InvalidParameterException
1497
- If the client passes incorrect parameters on the request - such as bad URLs or invalid values
1498
- PropertyServerException
1499
- Raised by the server when an issue arises in processing a valid request
1500
- NotAuthorizedException
1501
- The principle specified by the user_id does not have authorization for the requested action
1502
- ConfigurationErrorException
1503
- Raised when configuration parameters passed on earlier calls turn out to be
1504
- invalid or make the new call invalid.
1505
- """
1506
- for_lineage_s = str(for_lineage).lower()
1507
- for_duplicate_processing_s = str(for_duplicate_processing).lower()
1508
-
1509
- body = {
1510
- "class": "EffectiveTimeQueryRequestBody", "effectiveTime": effective_time,
1511
- }
1512
-
1513
- url = (f"{self.platform_url}/servers/{self.view_server}/api/open-metadata/glossary-browser/glossaries/"
1514
- f"categories/{glossary_category_guid}/subcategories/retrieve?startFrom={start_from}&pageSize="
1515
- f"{page_size}&"
1516
- f"forLineage={for_lineage_s}&forDuplicateProcessing={for_duplicate_processing_s}")
1517
- if effective_time:
1518
- response = await self._async_make_request("POST", url, body_slimmer(body))
1519
- else:
1520
- response = await self._async_make_request("POST", url)
1521
-
1522
- return response.json().get("elementList", "No categories found")
1523
-
1524
- def get_glossary_subcategories(self, glossary_category_guid: str, effective_time: str = None, start_from: int = 0,
1525
- page_size: int = max_paging_size, for_lineage: bool = False,
1526
- for_duplicate_processing: bool = False, ) -> dict | str:
1527
- """Glossary categories can be organized in a hierarchy. Retrieve the subcategories for the glossary category
1528
- metadata element with the supplied unique identifier. If the requested category does not have any subcategories,
1529
- null is returned. The optional request body contain an effective time for the query.
1530
-
1531
- Parameters
1532
- ----------
1533
- glossary_category_guid: str,
1534
- Unique identifier for the glossary category.
1535
- effective_time: datetime, [default=None], optional
1536
- Effective time of the query. If not specified will default to any effective time. Time format is
1537
- "YYYY-MM-DDTHH:MM:SS" (ISO 8601)
1538
- start_from: int, [default=0], optional
1539
- The page to start from.
1540
- page_size: int, [default=max_paging_size], optional
1541
- The number of results per page to return.
1542
- for_lineage: bool, [default=False], optional
1543
- Indicates the search is for lineage.
1544
- for_duplicate_processing: bool, [default=False], optional
1545
- If set to True the user will handle duplicate processing.
1546
-
1547
- Returns
1548
- -------
1549
- A dict list with the glossary metadata element for the requested category.
1550
-
1551
- Raises
1552
- ------
1553
-
1554
- InvalidParameterException
1555
- If the client passes incorrect parameters on the request - such as bad URLs or invalid values
1556
- PropertyServerException
1557
- Raised by the server when an issue arises in processing a valid request
1558
- NotAuthorizedException
1559
- The principle specified by the user_id does not have authorization for the requested action
1560
- ConfigurationErrorException
1561
- Raised when configuration parameters passed on earlier calls turn out to be
1562
- invalid or make the new call invalid.
1563
- """
1564
- loop = asyncio.get_event_loop()
1565
- response = loop.run_until_complete(
1566
- self._async_get_glossary_subcategories(glossary_category_guid, effective_time, start_from, page_size,
1567
- for_lineage, for_duplicate_processing))
1568
- return response
1569
-
1570
- async def _async_find_glossary_categories(self, search_string: str, effective_time: str = None,
1571
- starts_with: bool = False, ends_with: bool = False,
1572
- ignore_case: bool = False, start_from: int = 0, page_size: int = None,
1573
- output_format: str = "JSON", output_format_set: str | dict = None) -> list | str:
1574
- """Retrieve the list of glossary category metadata elements that contain the search string.
1575
- The search string is located in the request body and is interpreted as a plain string.
1576
- The request parameters, startsWith, endsWith, and ignoreCase can be used to allow a fuzzy search.
1577
- Async version.
1578
-
1579
- Parameters
1580
- ----------
1581
- search_string: str,
1582
- Search string to use to find matching glossaries. If the search string is '*' then all glossaries returned.
1583
-
1584
- effective_time: str, [default=None], optional
1585
- Effective time of the query. If not specified will default to any time. Time format is
1586
- "YYYY-MM-DDTHH:MM:SS" (ISO 8601)
1587
-
1588
- If not provided, the server name associated with the instance is used.
1589
- starts_with : bool, [default=False], optional
1590
- Starts with the supplied string.
1591
- ends_with : bool, [default=False], optional
1592
- Ends with the supplied string
1593
- ignore_case : bool, [default=False], optional
1594
- Ignore case when searching
1595
- start_from: int, [default=0], optional
1596
- When multiple pages of results are available, the page number to start from.
1597
- page_size: int, [default=None]
1598
- The number of items to return in a single page. If not specified, the default will be taken from
1599
- the class instance.
1600
- output_format: str, default = 'JSON'
1601
- Type of output to produce:
1602
- JSON - output standard json
1603
- MD - output standard markdown with no preamble
1604
- FORM - output markdown with a preamble for a form
1605
- REPORT - output markdown with a preamble for a report
1606
- output_format_set: str | dict, optional
1607
- Output format set name or dictionary. Defaults to None.
1608
-
1609
- Returns
1610
- -------
1611
- List | str
1612
-
1613
- A list of glossary definitions active in the server.
1614
-
1615
- Raises
1616
- ------
1617
-
1618
- InvalidParameterException
1619
- If the client passes incorrect parameters on the request - such as bad URLs or invalid values
1620
- PropertyServerException
1621
- Raised by the server when an issue arises in processing a valid request
1622
- NotAuthorizedException
1623
- The principle specified by the user_id does not have authorization for the requested action
1624
-
1625
- """
1626
-
1627
- if page_size is None:
1628
- page_size = self.page_size
1629
- starts_with_s = str(starts_with).lower()
1630
- ends_with_s = str(ends_with).lower()
1631
- ignore_case_s = str(ignore_case).lower()
1632
-
1633
- validate_search_string(search_string)
1634
-
1635
- if search_string == "*":
1636
- search_string = None
1637
-
1638
- body = {
1639
- "class": "SearchStringRequestBody", "searchString": search_string, "effectiveTime": effective_time,
1640
- }
1641
-
1642
- url = (f"{self.platform_url}/servers/{self.view_server}/api/open-metadata/glossary-browser/glossaries/"
1643
- f"categories/by-search-string?startFrom={start_from}&pageSize={page_size}&startsWith={starts_with_s}&"
1644
- f"endsWith={ends_with_s}&ignoreCase={ignore_case_s}")
1645
- response = await self._async_make_request("POST", url, body_slimmer(body))
1646
- element = response.json().get("elementList", NO_CATEGORIES_FOUND)
1647
- if element == NO_CATEGORIES_FOUND:
1648
- if output_format == 'JSON':
1649
- return NO_CATEGORIES_FOUND
1650
- elif output_format in ['MD', 'FORM', 'REPORT', 'LIST']:
1651
- return "\n# No categories found.\n"
1652
- elif output_format == 'DICT':
1653
- return None
1654
- if output_format != 'JSON': # return a simplified markdown representation
1655
- return self.generate_categories_md(element, search_string, output_format, output_format_set)
1656
- return response.json().get("elementList", NO_CATEGORIES_FOUND)
1657
-
1658
- def find_glossary_categories(self, search_string: str, effective_time: str = None, starts_with: bool = False,
1659
- ends_with: bool = False, ignore_case: bool = False, start_from: int = 0,
1660
- page_size: int = None, output_format: str = "JSON", output_format_set: str | dict = None) -> list | str:
1661
- """Retrieve the list of glossary category metadata elements that contain the search string.
1662
- The search string is located in the request body and is interpreted as a plain string.
1663
- The request parameters, startsWith, endsWith, and ignoreCase can be used to allow a fuzzy search.
1664
-
1665
- Parameters
1666
- ----------
1667
- search_string: str,
1668
- Search string to use to find matching glossaries. If the search string is '*' then all
1669
- glossaries returned.
1670
-
1671
- effective_time: str, [default=None], optional
1672
- Effective time of the query. If not specified will default to any time. Time format is
1673
- "YYYY-MM-DDTHH:MM:SS" (ISO 8601)
1674
-
1675
- If not provided, the server name associated with the instance is used.
1676
- starts_with : bool, [default=False], optional
1677
- Starts with the supplied string.
1678
- ends_with : bool, [default=False], optional
1679
- Ends with the supplied string
1680
- ignore_case : bool, [default=False], optional
1681
- Ignore case when searching
1682
- start_from: int, [default=0], optional
1683
- When multiple pages of results are available, the page number to start from.
1684
- page_size: int, [default=None]
1685
- The number of items to return in a single page. If not specified, the default will be taken from
1686
- the class instance.
1687
- output_format: str, default = 'JSON'
1688
- Type of output to produce:
1689
- JSON - output standard json
1690
- MD - output standard markdown with no preamble
1691
- FORM - output markdown with a preamble for a form
1692
- REPORT - output markdown with a preamble for a report
1693
- output_format_set: str | dict, optional
1694
- Output format set name or dictionary. Defaults to None.
1695
-
1696
- Returns
1697
- -------
1698
- List | str
1699
-
1700
- A list of glossary definitions active in the server.
1701
-
1702
- Raises
1703
- ------
1704
-
1705
- InvalidParameterException
1706
- If the client passes incorrect parameters on the request - such as bad URLs or invalid values
1707
- PropertyServerException
1708
- Raised by the server when an issue arises in processing a valid request
1709
- NotAuthorizedException
1710
- The principle specified by the user_id does not have authorization for the requested action
1711
-
1712
- """
1713
- loop = asyncio.get_event_loop()
1714
- response = loop.run_until_complete(
1715
- self._async_find_glossary_categories(search_string, effective_time, starts_with, ends_with, ignore_case,
1716
- start_from, page_size, output_format, output_format_set))
1717
-
1718
- return response
1719
-
1720
- async def _async_get_categories_for_glossary(self, glossary_guid: str, start_from: int = 0,
1721
- page_size: int = None, ) -> list | str:
1722
- """Return the list of categories associated with a glossary.
1723
- Async version.
1724
-
1725
- Parameters
1726
- ----------
1727
- glossary_guid: str,
1728
- Unique identity of the glossary
1729
-
1730
- If not provided, the server name associated with the instance is used.
1731
- start_from: int, [default=0], optional
1732
- When multiple pages of results are available, the page number to start from.
1733
- page_size: int, [default=None]
1734
- The number of items to return in a single page. If not specified, the default will be taken from
1735
- the class instance.
1736
- Returns
1737
- -------
1738
- List | str
1739
-
1740
- A list of categories associated with a glossary.
1741
-
1742
- Raises
1743
- ------
1744
-
1745
- InvalidParameterException
1746
- If the client passes incorrect parameters on the request - such as bad URLs or invalid values
1747
- PropertyServerException
1748
- Raised by the server when an issue arises in processing a valid request
1749
- NotAuthorizedException
1750
- The principle specified by the user_id does not have authorization for the requested action
1751
-
1752
- """
1753
-
1754
- if page_size is None:
1755
- page_size = self.page_size
1756
-
1757
- url = (f"{self.platform_url}/servers/{self.view_server}/api/open-metadata/glossary-browser/glossaries/"
1758
- f"{glossary_guid}/categories/retrieve?startFrom={start_from}&pageSize={page_size}")
1759
-
1760
- response = await self._async_make_request("POST", url)
1761
- return response.json().get("elementList", "No Categories found")
1762
-
1763
- def get_categories_for_glossary(self, glossary_guid: str, start_from: int = 0,
1764
- page_size: int = None, ) -> list | str:
1765
- """Return the list of categories associated with a glossary.
1766
-
1767
- Parameters
1768
- ----------
1769
- glossary_guid: str,
1770
- Unique identity of the glossary
1771
-
1772
- If not provided, the server name associated with the instance is used.
1773
- start_from: int, [default=0], optional
1774
- When multiple pages of results are available, the page number to start from.
1775
- page_size: int, [default=None]
1776
- The number of items to return in a single page. If not specified, the default will be taken from
1777
- the class instance.
1778
- Returns
1779
- -------
1780
- List | str
1781
-
1782
- A list of categories associated with a glossary.
1783
-
1784
- Raises
1785
- ------
1786
-
1787
- InvalidParameterException
1788
- If the client passes incorrect parameters on the request - such as bad URLs or invalid values
1789
- PropertyServerException
1790
- Raised by the server when an issue arises in processing a valid request
1791
- NotAuthorizedException
1792
- The principle specified by the user_id does not have authorization for the requested action
1793
-
1794
- """
1795
- loop = asyncio.get_event_loop()
1796
- response = loop.run_until_complete(
1797
- self._async_get_categories_for_glossary(glossary_guid, start_from, page_size))
1798
- return response
1799
-
1800
- async def _async_get_categories_for_term(self, glossary_term_guid: str, start_from: int = 0,
1801
- page_size: int = None, ) -> list | str:
1802
- """Return the list of categories associated with a glossary term.
1803
- Async version.
1804
-
1805
- Parameters
1806
- ----------
1807
- glossary_term_guid: str,
1808
- Unique identity of a glossary term
1809
-
1810
- start_from: int, [default=0], optional
1811
- When multiple pages of results are available, the page number to start from.
1812
- page_size: int, [default=None]
1813
- The number of items to return in a single page. If not specified, the default will be taken from
1814
- the class instance.
1815
- Returns
1816
- -------
1817
- List | str
1818
-
1819
- A list of categories associated with a glossary term.
1820
-
1821
- Raises
1822
- ------
1823
-
1824
- InvalidParameterException
1825
- If the client passes incorrect parameters on the request - such as bad URLs or invalid values
1826
- PropertyServerException
1827
- Raised by the server when an issue arises in processing a valid request
1828
- NotAuthorizedException
1829
- The principle specified by the user_id does not have authorization for the requested action
1830
-
1831
- """
1832
-
1833
- if page_size is None:
1834
- page_size = self.page_size
1835
-
1836
- url = (f"{self.platform_url}/servers/{self.view_server}/api/open-metadata/glossary-browser/glossaries/terms/"
1837
- f"{glossary_term_guid}/categories/retrieve?startFrom={start_from}&pageSize={page_size}")
1838
-
1839
- response = await self._async_make_request("POST", url)
1840
- return response.json().get("elementList", NO_CATEGORIES_FOUND)
1841
-
1842
- def get_categories_for_term(self, glossary_term_guid: str, start_from: int = 0,
1843
- page_size: int = None, ) -> list | str:
1844
- """Return the list of categories associated with a glossary term.
1845
-
1846
- Parameters
1847
- ----------
1848
- glossary_term_guid: str,
1849
- Unique identity of a glossary term
1850
-
1851
- start_from: int, [default=0], optional
1852
- When multiple pages of results are available, the page number to start from.
1853
- page_size: int, [default=None]
1854
- The number of items to return in a single page. If not specified, the default will be taken from
1855
- the class instance.
1856
- Returns
1857
- -------
1858
- List | str
1859
-
1860
- A list of categories associated with a glossary term.
1861
-
1862
- Raises
1863
- ------
1864
-
1865
- InvalidParameterException
1866
- If the client passes incorrect parameters on the request - such as bad URLs or invalid values
1867
- PropertyServerException
1868
- Raised by the server when an issue arises in processing a valid request
1869
- NotAuthorizedException
1870
- The principle specified by the user_id does not have authorization for the requested action
1871
-
1872
- """
1873
- loop = asyncio.get_event_loop()
1874
- response = loop.run_until_complete(
1875
- self._async_get_categories_for_term(glossary_term_guid, start_from, page_size))
1876
- return response
1877
-
1878
- async def _async_get_categories_by_name(self, name: str, glossary_guid: str = None, status: [str] = ["ACTIVE"],
1879
- start_from: int = 0, page_size: int = None, ) -> list | str:
1880
- """Retrieve the list of glossary category metadata elements that either have the requested qualified name or
1881
- display name. The name to search for is located in the request body and is interpreted as a plain string.
1882
- The request body also supports the specification of a glossaryGUID to restrict the search to within a single
1883
- glossary.
1884
-
1885
- Async version.
1886
-
1887
- Parameters
1888
- ----------
1889
- name: str,
1890
- category name to search for.
1891
- glossary_guid: str, optional
1892
- The identity of the glossary to search. If not specified, all glossaries will be searched.
1893
- start_from: int, [default=0], optional
1894
- When multiple pages of results are available, the page number to start from.
1895
- page_size: int, [default=None]
1896
- The number of items to return in a single page. If not specified, the default will be taken from
1897
- the class instance.
1898
- Returns
1899
- -------
1900
- List | str
1901
-
1902
- A list of categories with the corresponding display name or qualified name.
1903
-
1904
- Raises
1905
- ------
1906
-
1907
- InvalidParameterException
1908
- If the client passes incorrect parameters on the request - such as bad URLs or invalid values
1909
- PropertyServerException
1910
- Raised by the server when an issue arises in processing a valid request
1911
- NotAuthorizedException
1912
- The principle specified by the user_id does not have authorization for the requested action
1913
-
1914
- """
1915
-
1916
- if page_size is None:
1917
- page_size = self.page_size
1918
- validate_name(name)
1919
-
1920
- url = (
1921
- f"{self.platform_url}/servers/{self.view_server}/api/open-metadata/glossary-browser/glossaries/categories/"
1922
- f"by-name?startFrom={start_from}&pageSize={page_size}")
1923
-
1924
- body = {
1925
- "class": "GlossaryNameRequestBody", "name": name, "glossaryGUID": glossary_guid,
1926
- "limitResultsByStatus": status,
1927
- }
1928
-
1929
- response = await self._async_make_request("POST", url, body)
1930
- return response.json().get("elementList", NO_CATEGORIES_FOUND)
1931
-
1932
- def get_categories_by_name(self, name: str, glossary_guid: str = None, status: [str] = ["ACTIVE"],
1933
- start_from: int = 0, page_size: int = None) -> list | str:
1934
- """Retrieve the list of glossary category metadata elements that either have the requested qualified name or
1935
- display name. The name to search for is located in the request body and is interpreted as a plain string.
1936
- The request body also supports the specification of a glossaryGUID to restrict the search to within a
1937
- single glossary.
1938
-
1939
- Parameters
1940
- ----------
1941
- name: str,
1942
- category name to search for.
1943
- glossary_guid: str, optional
1944
- The identity of the glossary to search. If not specified, all glossaries will be searched.
1945
- start_from: int, [default=0], optional
1946
- When multiple pages of results are available, the page number to start from.
1947
- page_size: int, [default=None]
1948
- The number of items to return in a single page. If not specified, the default will be taken from
1949
- the class instance.
1950
- Returns
1951
- -------
1952
- List | str
1953
-
1954
- A list of categories with the corresponding display name or qualified name.
1955
-
1956
- Raises
1957
- ------
1958
-
1959
- InvalidParameterException
1960
- If the client passes incorrect parameters on the request - such as bad URLs or invalid values
1961
- PropertyServerException
1962
- Raised by the server when an issue arises in processing a valid request
1963
- NotAuthorizedException
1964
- The principle specified by the user_id does not have authorization for the requested action
1965
-
1966
- """
1967
- loop = asyncio.get_event_loop()
1968
- response = loop.run_until_complete(
1969
- self._async_get_categories_by_name(name, glossary_guid, status, start_from, page_size))
1970
- return response
1971
-
1972
- async def _async_get_category_by_guid(self, glossary_category_guid: str, effective_time: str = None,
1973
- output_format: str = 'JSON', output_format_set: str | dict = None) -> list | str:
1974
- """Retrieve the requested glossary category metadata element. The optional request body contain an effective
1975
- time for the query..
1976
-
1977
- Async version.
1978
-
1979
- Parameters
1980
- ----------
1981
- glossary_category_guid: str
1982
- The identity of the glossary category to search.
1983
- effective_time: str, optional
1984
- If specified, the category should only be returned if it was effective at the specified time.
1985
- Time format is "YYYY-MM-DDTHH:MM:SS" (ISO 8601)
1986
-
1987
- output_format: str, default = 'JSON'
1988
- Type of output to produce:
1989
- JSON - output standard json
1990
- MD - output standard markdown with no preamble
1991
- FORM - output markdown with a preamble for a form
1992
- REPORT - output markdown with a preamble for a report
1993
- output_format_set: str | dict, optional
1994
- Output format set name or dictionary. Defaults to None.
1995
-
1996
- Returns
1997
- -------
1998
- List | str
1999
-
2000
- Details for the category with the glossary category GUID.
2001
-
2002
- Raises
2003
- ------
2004
-
2005
- InvalidParameterException
2006
- If the client passes incorrect parameters on the request - such as bad URLs or invalid values
2007
- PropertyServerException
2008
- Raised by the server when an issue arises in processing a valid request
2009
- NotAuthorizedException
2010
- The principle specified by the user_id does not have authorization for the requested action
2011
-
2012
- """
2013
- output_format = output_format.upper()
2014
- url = (
2015
- f"{self.platform_url}/servers/{self.view_server}/api/open-metadata/glossary-browser/glossaries/categories/"
2016
- f"{glossary_category_guid}/retrieve")
2017
-
2018
- body = {
2019
- "class": "EffectiveTimeQueryRequestBody", "effectiveTime": effective_time,
2020
- }
2021
-
2022
- response = await self._async_make_request("POST", url, body_slimmer(body))
2023
- element = response.json().get("element", NO_CATEGORIES_FOUND)
2024
- if element == NO_CATEGORIES_FOUND:
2025
- return NO_CATEGORIES_FOUND
2026
- if output_format != 'JSON': # return a simplified markdown representation
2027
- return self.generate_categories_md(element, "GUID", output_format, output_format_set)
2028
- return response.json().get("element", NO_CATEGORIES_FOUND)
2029
-
2030
- def get_category_by_guid(self, glossary_category_guid: str, effective_time: str = None,
2031
- output_format: str = 'JSON', output_format_set: str | dict = None) -> list | str:
2032
- """Retrieve the requested glossary category metadata element. The optional request body contain an effective
2033
- time for the query..
2034
-
2035
- Parameters
2036
- ----------
2037
- glossary_category_guid: str
2038
- The identity of the glossary category to search.
2039
- effective_time: str, optional
2040
- If specified, the category should only be returned if it was effective at the specified time.
2041
- Time format is "YYYY-MM-DDTHH:MM:SS" (ISO 8601)
2042
-
2043
- output_format: str, default = 'JSON'
2044
- Type of output to produce:
2045
- JSON - output standard json
2046
- MD - output standard markdown with no preamble
2047
- FORM - output markdown with a preamble for a form
2048
- REPORT - output markdown with a preamble for a report
2049
- output_format_set: str | dict, optional
2050
- Output format set name or dictionary. Defaults to None.
2051
-
2052
- Returns
2053
- -------
2054
- List | str
2055
-
2056
- Details for the category with the glossary category GUID.
2057
-
2058
- Raises
2059
- ------
2060
-
2061
- InvalidParameterException
2062
- If the client passes incorrect parameters on the request - such as bad URLs or invalid values
2063
- PropertyServerException
2064
- Raised by the server when an issue arises in processing a valid request
2065
- NotAuthorizedException
2066
- The principle specified by the user_id does not have authorization for the requested action
2067
-
2068
- """
2069
- loop = asyncio.get_event_loop()
2070
- response = loop.run_until_complete(
2071
- self._async_get_category_by_guid(glossary_category_guid, effective_time, output_format))
2072
- return response
2073
-
2074
- async def _async_get_category_parent(self, glossary_category_guid: str, effective_time: str = None, ) -> list | str:
2075
- """Glossary categories can be organized in a hierarchy. Retrieve the parent glossary category metadata
2076
- element for the glossary category with the supplied unique identifier. If the requested category
2077
- does not have a parent category, null is returned. The optional request body contain an effective time
2078
- for the query.
2079
-
2080
- Async version.
2081
-
2082
- Parameters
2083
- ----------
2084
- glossary_category_guid: str
2085
- The identity of the glossary category to search.
2086
- effective_time: str, optional
2087
- If specified, the category should only be returned if it was effective at the specified time.
2088
- Time format is "YYYY-MM-DDTHH:MM:SS" (ISO 8601)
2089
-
2090
- If not provided, the server name associated with the instance is used.
2091
-
2092
- Returns
2093
- -------
2094
- List | str
2095
-
2096
- Details for the parent category with the glossary category GUID.
2097
-
2098
- Raises
2099
- ------
2100
-
2101
- InvalidParameterException
2102
- If the client passes incorrect parameters on the request - such as bad URLs or invalid values
2103
- PropertyServerException
2104
- Raised by the server when an issue arises in processing a valid request
2105
- NotAuthorizedException
2106
- The principle specified by the user_id does not have authorization for the requested action
2107
-
2108
- """
2109
-
2110
- url = (
2111
- f"{self.platform_url}/servers/{self.view_server}/api/open-metadata/glossary-browser/glossaries/categories/"
2112
- f"{glossary_category_guid}/parent/retrieve")
2113
-
2114
- body = {
2115
- "class": "EffectiveTimeQueryRequestBody", "effectiveTime": effective_time,
2116
- }
2117
-
2118
- response = await self._async_make_request("POST", url, body)
2119
- return response.json().get("element", "No Parent Category found")
2120
-
2121
- def get_category_parent(self, glossary_category_guid: str, effective_time: str = None, ) -> list | str:
2122
- """Glossary categories can be organized in a hierarchy. Retrieve the parent glossary category metadata
2123
- element for the glossary category with the supplied unique identifier. If the requested category
2124
- does not have a parent category, null is returned. The optional request body contain an effective time
2125
- for the query.
2126
-
2127
- Parameters
2128
- ----------
2129
- glossary_category_guid: str
2130
- The identity of the glossary category to search.
2131
- effective_time: str, optional
2132
- If specified, the category should only be returned if it was effective at the specified time.
2133
- Time format is "YYYY-MM-DDTHH:MM:SS" (ISO 8601).
2134
-
2135
- If not provided, the server name associated with the instance is used.
2136
-
2137
- Returns
2138
- -------
2139
- List | str
2140
-
2141
- Details for the parent category with the glossary category GUID.
2142
-
2143
- Raises
2144
- ------
2145
-
2146
- InvalidParameterException
2147
- If the client passes incorrect parameters on the request - such as bad URLs or invalid values
2148
- PropertyServerException
2149
- Raised by the server when an issue arises in processing a valid request
2150
- NotAuthorizedException
2151
- The principle specified by the user_id does not have authorization for the requested action
2152
-
2153
- """
2154
- loop = asyncio.get_event_loop()
2155
- response = loop.run_until_complete(self._async_get_category_parent(glossary_category_guid, effective_time))
2156
- return response
2157
-
2158
- def get_glossary_category_structure(self, glossary_guid: str, output_format: str = "DICT", output_format_set: str | dict = None) -> dict | str:
2159
- """Derive the category structure of an Egeria glossary.
2160
-
2161
- This method builds a hierarchical representation of the categories in a glossary,
2162
- showing the parent-child relationships between categories.
2163
-
2164
- Parameters
2165
- ----------
2166
- glossary_guid: str
2167
- The unique identifier of the glossary.
2168
- output_format: str, default = 'DICT'
2169
- The format of the output:
2170
- - DICT: Returns a Python dictionary structure
2171
- - LIST: Returns a markdown table
2172
- - MD: Returns a markdown outline with bullets and indentations
2173
- output_format_set: str | dict, optional
2174
- Output format set name or dictionary. Defaults to None.
2175
-
2176
- Returns
2177
- -------
2178
- dict | str
2179
- If output_format is DICT, returns a dictionary structure representing the category hierarchy.
2180
- If output_format is LIST, returns a markdown table representing the category hierarchy.
2181
- If output_format is MD, returns a markdown outline with bullets and indentations.
2182
-
2183
- Raises
2184
- ------
2185
- InvalidParameterException
2186
- If the client passes incorrect parameters on the request - such as bad URLs or invalid values
2187
- PropertyServerException
2188
- Raised by the server when an issue arises in processing a valid request
2189
- NotAuthorizedException
2190
- The principle specified by the user_id does not have authorization for the requested action
2191
- """
2192
- from pyegeria._validators import validate_guid
2193
-
2194
- validate_guid(glossary_guid)
2195
-
2196
- # Get all categories in the glossary
2197
- all_categories = self.get_categories_for_glossary(glossary_guid)
2198
- if isinstance(all_categories, str):
2199
- return NO_CATEGORIES_FOUND
2200
-
2201
- # Create a dictionary to store categories by GUID for quick lookup
2202
- categories_by_guid = {cat['elementHeader']['guid']: cat for cat in all_categories}
2203
-
2204
- # Identify root categories (categories with no parent)
2205
- root_guids = []
2206
- for cat_guid in categories_by_guid.keys():
2207
- parent = self.get_category_parent(cat_guid)
2208
- if isinstance(parent, str):
2209
- root_guids.append(cat_guid) # This category has no parent
2210
-
2211
- # Build the category tree
2212
- category_tree = []
2213
-
2214
- def build_category_tree(category_guid):
2215
- """Recursively build a category tree for a category."""
2216
- if category_guid not in categories_by_guid:
2217
- return None
2218
-
2219
- category = categories_by_guid[category_guid]
2220
- display_name = category['glossaryCategoryProperties'].get('displayName', '---')
2221
- qualified_name = category['glossaryCategoryProperties'].get('qualifiedName', '---')
2222
- description = category['glossaryCategoryProperties'].get('description', '---')
2223
-
2224
- # Get subcategories
2225
- subcategories = self.get_glossary_subcategories(category_guid)
2226
- children = []
2227
-
2228
- if isinstance(subcategories, list):
2229
- for subcat in subcategories:
2230
- subcat_guid = subcat['elementHeader']['guid']
2231
- child_tree = build_category_tree(subcat_guid)
2232
- if child_tree:
2233
- children.append(child_tree)
2234
-
2235
- # Get parent category information
2236
- parent_info = None
2237
- parent = self.get_category_parent(category_guid)
2238
- if not isinstance(parent, str):
2239
- parent_guid = parent['elementHeader']['guid']
2240
- parent_name = parent['glossaryCategoryProperties'].get('displayName', '---')
2241
- parent_info = {
2242
- 'GUID': parent_guid, 'name': parent_name
2243
- }
2244
-
2245
- return {
2246
- 'GUID': category_guid, 'name': display_name, 'qualifiedName': qualified_name,
2247
- 'description': description, 'parent': parent_info, 'children': children
2248
- }
2249
-
2250
- # Build tree for each root category
2251
- for root_guid in root_guids:
2252
- tree = build_category_tree(root_guid)
2253
- if tree:
2254
- category_tree.append(tree)
2255
-
2256
- # Format the output according to the specified output_format
2257
- if output_format == "DICT":
2258
- return {
2259
- 'glossary_guid': glossary_guid, 'categories': category_tree
2260
- }
2261
- elif output_format == "LIST":
2262
- # Generate markdown table
2263
- md_table = "| Category | Path | Description | Parent Category | Child Categories |\n"
2264
- md_table += "|---------|------|-------------|----------------|------------------|\n"
2265
-
2266
- def add_categories_to_table(categories, path=""):
2267
- nonlocal md_table
2268
- for category in categories:
2269
- category_path = f"{path}/{category['name']}" if path else category['name']
2270
-
2271
- # Get parent category name
2272
- parent_name = "None"
2273
- if category['parent']:
2274
- parent_name = category['parent']['name']
2275
-
2276
- # Get child categories names
2277
- child_names = []
2278
- for child in category['children']:
2279
- child_names.append(child['name'])
2280
- child_categories = ", ".join(child_names) if child_names else "None"
2281
-
2282
- md_table += (f"| {category['name']} | {category_path} | "
2283
- f"{self._format_for_markdown_table(category['description'])} | "
2284
- f"{parent_name} | {child_categories} |\n")
2285
- if category['children']:
2286
- add_categories_to_table(category['children'], category_path)
2287
-
2288
- add_categories_to_table(category_tree)
2289
- return md_table
2290
- elif output_format == "MD":
2291
- # Generate markdown outline with bullets and indentations
2292
- md_outline = f"# Category Structure for Glossary (GUID: {glossary_guid})\n\n"
2293
-
2294
- def add_categories_to_outline(categories, indent_level=0):
2295
- nonlocal md_outline
2296
- for category in categories:
2297
- # Add bullet with proper indentation
2298
- indent = " " * indent_level
2299
- md_outline += f"{indent}- **{category['name']}**"
2300
-
2301
- # Add description if available
2302
- if category['description'] and category['description'] != '---':
2303
- md_outline += f": {category['description']}"
2304
-
2305
- md_outline += "\n"
2306
-
2307
- # Process children with increased indentation
2308
- if category['children']:
2309
- add_categories_to_outline(category['children'], indent_level + 1)
2310
-
2311
- add_categories_to_outline(category_tree)
2312
- return md_outline
2313
- else:
2314
- return f"Unsupported output format: {output_format}. Use 'DICT', 'LIST', or 'MD'."
2315
-
2316
- #
2317
- # Terms
2318
- #
2319
-
2320
- async def _async_get_terms_for_category(self, glossary_category_guid: str, effective_time: str = None,
2321
- start_from: int = 0, page_size: int = None, ) -> list | str:
2322
- """Retrieve ALL the glossary terms in a category.
2323
- The request body also supports the specification of an effective time for the query.
2324
-
2325
- Async Version.
2326
-
2327
- Parameters
2328
- ----------
2329
- glossary_category_guid : str
2330
- Unique identifier for the glossary category to retrieve terms from.
2331
- effective_time : str, optional
2332
- If specified, the terms are returned if they are active at the `effective_time
2333
- Time format is "YYYY-MM-DDTHH:MM:SS" (ISO 8601)
2334
- start_from: int, optional defaults to 0
2335
- The page number to start retrieving elements from
2336
- page_size : int, optional defaults to None
2337
- The number of elements to retrieve
2338
- Returns
2339
- -------
2340
- [dict]
2341
- The glossary definition associated with the glossary_guid
2342
-
2343
- Raises
2344
- ------
2345
- InvalidParameterException
2346
- If the client passes incorrect parameters on the request - such as bad URLs or invalid values.
2347
- PropertyServerException
2348
- Raised by the server when an issue arises in processing a valid request.
2349
- NotAuthorizedException
2350
- The principle specified by the user_id does not have authorization for the requested action.
2351
-
2352
- """
2353
-
2354
- validate_guid(glossary_category_guid)
2355
-
2356
- if page_size is None:
2357
- page_size = self.page_size
2358
-
2359
- url = (
2360
- f"{self.platform_url}/servers/{self.view_server}/api/open-metadata/glossary-browser/glossaries/categories/"
2361
- f"{glossary_category_guid}/terms/retrieve?startFrom={start_from}&pageSize={page_size}")
2362
-
2363
- if effective_time is not None:
2364
- body = {"effectiveTime": effective_time}
2365
- response = await self._async_make_request("POST", url, body)
2366
- else:
2367
- response = await self._async_make_request("POST", url)
2368
-
2369
- return response.json().get("elementList", "No terms found")
2370
-
2371
- def get_terms_for_category(self, glossary_category_guid: str, effective_time: str = None, start_from: int = 0,
2372
- page_size: int = None, ) -> list | str:
2373
- """Retrieve ALL the glossary terms in a category.
2374
- The request body also supports the specification of an effective time for the query.
2375
-
2376
- Async Version.
2377
-
2378
- Parameters
2379
- ----------
2380
- glossary_category_guid : str
2381
- Unique identifier for the glossary category to retrieve terms from.
2382
-
2383
- effective_time : str, optional
2384
- If specified, the terms are returned if they are active at the `effective_time.
2385
- Time format is "YYYY-MM-DDTHH:MM:SS" (ISO 8601)`.
2386
- start_from: int, optional defaults to 0
2387
- The page number to start retrieving elements from
2388
- page_size : int, optional defaults to None
2389
- The number of elements to retrieve
2390
- Returns
2391
- -------
2392
- dict
2393
- The glossary definition associated with the glossary_guid
2394
-
2395
- Raises
2396
- ------
2397
- InvalidParameterException
2398
- If the client passes incorrect parameters on the request - such as bad URLs or invalid values.
2399
- PropertyServerException
2400
- Raised by the server when an issue arises in processing a valid request.
2401
- NotAuthorizedException
2402
- The principle specified by the user_id does not have authorization for the requested action.
2403
- Notes
2404
- -----
2405
- """
2406
- loop = asyncio.get_event_loop()
2407
- response = loop.run_until_complete(
2408
- self._async_get_terms_for_category(glossary_category_guid, effective_time, start_from, page_size, ))
2409
-
2410
- return response
2411
-
2412
- async def _async_get_terms_for_glossary(self, glossary_guid: str, effective_time: str = None, start_from: int = 0,
2413
- page_size: int = None, ) -> list | str:
2414
- """Retrieve the list of glossary terms associated with a glossary.
2415
- The request body also supports the specification of an effective time for the query.
2416
- Parameters
2417
- ----------
2418
- glossary_guid : str
2419
- Unique identifier for the glossary
2420
-
2421
- effective_time : str, optional
2422
- If specified, terms are potentially included if they are active at the`effective_time.
2423
- Time format is "YYYY-MM-DDTHH:MM:SS" (ISO 8601)`
2424
- start_from: int, optional defaults to 0
2425
- The page number to start retrieving elements from
2426
- page_size : int, optional defaults to None
2427
- The number of elements to retrieve
2428
- Returns
2429
- -------
2430
- dict
2431
- The glossary definition associated with the glossary_guid
2432
-
2433
- Raises
2434
- ------
2435
- InvalidParameterException
2436
- If the client passes incorrect parameters on the request - such as bad URLs or invalid values.
2437
- PropertyServerException
2438
- Raised by the server when an issue arises in processing a valid request.
2439
- NotAuthorizedException
2440
- The principle specified by the user_id does not have authorization for the requested action.
2441
- Notes
2442
- -----
2443
- """
2444
-
2445
- validate_guid(glossary_guid)
2446
-
2447
- if page_size is None:
2448
- page_size = self.page_size
2449
-
2450
- url = (f"{self.platform_url}/servers/{self.view_server}/api/open-metadata/glossary-browser/glossaries/"
2451
- f"{glossary_guid}/terms/retrieve?startFrom={start_from}&pageSize={page_size}")
2452
-
2453
- if effective_time is not None:
2454
- body = {"effectiveTime": effective_time}
2455
- response = await self._async_make_request("POST", url, body)
2456
- else:
2457
- response = await self._async_make_request("POST", url)
2458
-
2459
- return response.json().get("elementList", "No terms found")
2460
-
2461
- def get_terms_for_glossary(self, glossary_guid: str, effective_time: str = None, start_from: int = 0,
2462
- page_size: int = None, ) -> list | str:
2463
- """Retrieve the list of glossary terms associated with a glossary.
2464
- The request body also supports the specification of an effective time for the query.
2465
- Parameters
2466
- ----------
2467
- glossary_guid : str
2468
- Unique identifier for the glossary
2469
-
2470
- effective_time : str, optional
2471
- If specified, terms are potentially returned if they are active at the `effective_time`
2472
- Time format is "YYYY-MM-DDTHH:MM:SS" (ISO 8601)
2473
- start_from: int, optional defaults to 0
2474
- The page number to start retrieving elements from
2475
- page_size : int, optional defaults to None
2476
- The number of elements to retrieve
2477
- Returns
2478
- -------
2479
- dict
2480
- The glossary definition associated with the glossary_guid
2481
-
2482
- Raises
2483
- ------
2484
- InvalidParameterException
2485
- If the client passes incorrect parameters on the request - such as bad URLs or invalid values.
2486
- PropertyServerException
2487
- Raised by the server when an issue arises in processing a valid request.
2488
- NotAuthorizedException
2489
- The principle specified by the user_id does not have authorization for the requested action.
2490
- Notes
2491
- -----
2492
- """
2493
- loop = asyncio.get_event_loop()
2494
- response = loop.run_until_complete(
2495
- self._async_get_terms_for_glossary(glossary_guid, effective_time, start_from, page_size))
2496
-
2497
- return response
2498
-
2499
- async def _async_get_related_terms(self, term_guid: str, effective_time: str = None, start_from: int = 0,
2500
- page_size: int = None, output_format: str = "JSON") -> list | str:
2501
- """This call retrieves details of the glossary terms linked to this glossary term.
2502
- Notice the original org 1 glossary term is linked via the "SourcedFrom" relationship.
2503
- Parameters
2504
- ----------
2505
- term_guid : str
2506
- Unique identifier for the glossary term
2507
-
2508
- effective_time : str, optional
2509
- If specified, term relationships are included if they are active at the `effective_time`.
2510
- Time format is "YYYY-MM-DDTHH:MM:SS" (ISO 8601)
2511
- start_from: int, optional defaults to 0
2512
- The page number to start retrieving elements from
2513
- page_size : int, optional defaults to None
2514
- The number of elements to retrieve
2515
- Returns
2516
- -------
2517
- dict
2518
- The glossary definition associated with the glossary_guid
2519
-
2520
- Raises
2521
- ------
2522
- InvalidParameterException
2523
- If the client passes incorrect parameters on the request - such as bad URLs or invalid values.
2524
- PropertyServerException
2525
- Raised by the server when an issue arises in processing a valid request.
2526
- NotAuthorizedException
2527
- The principle specified by the user_id does not have authorization for the requested action.
2528
- Notes
2529
- -----
2530
- """
2531
-
2532
- validate_guid(term_guid)
2533
-
2534
- if page_size is None:
2535
- page_size = self.page_size
2536
-
2537
- url = (f"{self.platform_url}/servers/{self.view_server}/api/open-metadata/glossary-browser/glossaries/terms/"
2538
- f"{term_guid}/related-terms?startFrom={start_from}&pageSize={page_size}")
2539
-
2540
- if effective_time is not None:
2541
- body = {"effectiveTime": effective_time}
2542
- response = await self._async_make_request("POST", url, body)
2543
- else:
2544
- response = await self._async_make_request("POST", url)
2545
-
2546
- term_elements = response.json().get("elementList", NO_TERMS_FOUND)
2547
- if term_elements == NO_TERMS_FOUND:
2548
- if output_format == 'JSON':
2549
- return NO_TERMS_FOUND
2550
- elif output_format in ['MD', 'FORM', 'REPORT', 'LIST']:
2551
- return "\n# No Terms found.\n"
2552
- elif output_format == 'DICT':
2553
- return None
2554
- if output_format != "JSON": # return a simplified markdown representation
2555
- return self.generate_related_terms_md(term_elements, term_guid, output_format)
2556
- return response.json().get("elementList", NO_TERMS_FOUND)
2557
-
2558
- def get_related_terms(self, term_guid: str, effective_time: str = None, start_from: int = 0, page_size: int = None,
2559
- output_format="JSON") -> list | str:
2560
- """This call retrieves details of the glossary terms linked to this glossary term.
2561
- Notice the original org 1 glossary term is linked via the "SourcedFrom" relationship..
2562
- Parameters
2563
- ----------
2564
- term_guid : str
2565
- Unique identifier for the glossary term
2566
-
2567
- effective_time : str, optional
2568
- If specified, term relationships are included if they are active at the `effective_time`.
2569
- Time format is "YYYY-MM-DDTHH:MM:SS" (ISO 8601)
2570
- start_from: int, optional defaults to 0
2571
- The page number to start retrieving elements from
2572
- page_size : int, optional defaults to None
2573
- The number of elements to retrieve
2574
- Returns
2575
- -------
2576
- dict
2577
- The glossary definition associated with the glossary_guid
2578
-
2579
- Raises
2580
- ------
2581
- InvalidParameterException
2582
- If the client passes incorrect parameters on the request - such as bad URLs or invalid values.
2583
- PropertyServerException
2584
- Raised by the server when an issue arises in processing a valid request.
2585
- NotAuthorizedException
2586
- The principle specified by the user_id does not have authorization for the requested action.
2587
- Notes
2588
- -----
2589
- """
2590
- loop = asyncio.get_event_loop()
2591
- response = loop.run_until_complete(
2592
- self._async_get_related_terms(term_guid, effective_time, start_from, page_size, output_format))
2593
-
2594
- return response
2595
-
2596
- def generate_related_terms_md(self, term_elements: list, term_guid: str, output_format: str = 'MD', output_format_set: str | dict = None) -> str | list:
2597
- """
2598
- Generate a simplified representation of related terms.
2599
-
2600
- Args:
2601
- term_elements (list): List of term elements with relationship information
2602
- term_guid (str): GUID of the term for which to generate related terms
2603
- output_format (str): Output format (MD, LIST, DICT, etc.)
2604
- output_format_set (str | dict, optional): Output format set name or dictionary. Defaults to None.
2605
-
2606
- Returns:
2607
- str | list: Markdown string or list of dictionaries depending on output_format
2608
- """
2609
- # Get the first term's display name and qualified name
2610
- term_name = "Term"
2611
- try:
2612
- term_info = self.get_term_by_guid(term_guid, output_format="DICT")
2613
- # Handle case where term_info is a list of dictionaries
2614
- if isinstance(term_info, list) and len(term_info) > 0:
2615
- term_info = term_info[0] # Get the first term
2616
- if isinstance(term_info, dict) and 'display_name' in term_info:
2617
- term_name = term_info['display_name']
2618
- except:
2619
- # If we can't get the term info, just use the default name
2620
- pass
2621
-
2622
- # Create a list to store the simplified related terms
2623
- related_terms = []
2624
-
2625
- # Process each term element
2626
- for element in term_elements:
2627
- # Extract relationship type from the relationship header
2628
- relationship_type = element['relatedBy']['relationshipHeader']['type']['typeName']
2629
-
2630
- # Extract related term information
2631
- related_term = {
2632
- 'first_term_display_name': term_name, 'first_term_qualified_name': term_info.get('qualified_name', ''),
2633
- 'related_term_display_name': element['glossaryTermProperties'].get('displayName', ''),
2634
- 'related_term_qualified_name': element['glossaryTermProperties'].get('qualifiedName', ''),
2635
- 'relationship_type': relationship_type
2636
- }
2637
-
2638
- related_terms.append(related_term)
2639
-
2640
- # Define default columns for LIST format
2641
- default_columns = [
2642
- {'name': 'First Term', 'key': 'first_term_display_name'},
2643
- {'name': 'First Term Qualified Name', 'key': 'first_term_qualified_name'},
2644
- {'name': 'Related Term', 'key': 'related_term_display_name'},
2645
- {'name': 'Related Term Qualified Name', 'key': 'related_term_qualified_name'},
2646
- {'name': 'Relationship Type', 'key': 'relationship_type'},
2647
- ]
2648
-
2649
- # Determine the output format set
2650
- output_formats = None
2651
- if output_format_set:
2652
- if isinstance(output_format_set, str):
2653
- output_formats = select_output_format_set(output_format_set, output_format)
2654
- elif isinstance(output_format_set, dict):
2655
- output_formats = get_output_format_type_match(output_format_set, output_format)
2656
- else:
2657
- # Use default entity type to lookup the output format
2658
- output_formats = select_output_format_set("RelatedTerms", output_format)
2659
-
2660
- # Return based on output format
2661
- if output_format == 'DICT':
2662
- return related_terms
2663
-
2664
- # For MD, LIST, FORM, REPORT formats, create a markdown representation
2665
- md_output = f"# Related Terms for {term_name}\n\n"
2666
-
2667
- if output_format == 'LIST':
2668
- # If we have an output format set with columns, use those
2669
- columns = default_columns
2670
- if output_formats and 'formats' in output_formats and 'columns' in output_formats['formats']:
2671
- columns = output_formats['formats']['columns']
2672
-
2673
- # Create a table header
2674
- header_row = "| "
2675
- separator_row = "|"
2676
- for column in columns:
2677
- header_row += f"{column['name']} | "
2678
- separator_row += "------------|"
2679
-
2680
- md_output += header_row + "\n"
2681
- md_output += separator_row + "\n"
2682
-
2683
- # Add data rows
2684
- for term in related_terms:
2685
- row = "| "
2686
- for column in columns:
2687
- key = column['key']
2688
- value = term.get(key, '')
2689
- row += f"{value} | "
2690
- md_output += row + "\n"
2691
- else:
2692
- # For other formats, create a more detailed representation
2693
- for term in related_terms:
2694
- md_output += f"## {term['relationship_type']} Relationship\n\n"
2695
- md_output += (f"**First Term:** {term['first_term_display_name']} ("
2696
- f"{term['first_term_qualified_name']})\n\n")
2697
- md_output += f"**Related Term:** {term['related_term_display_name']} ({term['related_term_qualified_name']})\n\n"
2698
- md_output += "---\n\n"
2699
-
2700
- return md_output
2701
-
2702
- def get_term_details(self, term_name: str, effective_time: str = None, output_format: str = 'DICT', output_format_set: str | dict = None) -> dict | str:
2703
- """Retrieve detailed information about a term, combining basic term details and related terms.
2704
-
2705
- This method combines the term details retrieved from get_term_by_guid and the related terms
2706
- information from generate_related_terms_md.
2707
-
2708
- Parameters
2709
- ----------
2710
- term_name : str
2711
- Either the display name or the qualified name of the term to retrieve.
2712
- effective_time : str, optional
2713
- Time at which the term is active. If not specified, the current time is used.
2714
- output_format : str, default = 'DICT'
2715
- Type of output to produce:
2716
- DICT - output a dictionary with combined term details and related terms
2717
- REPORT - output a markdown report with combined term details and related terms
2718
- output_format_set : str | dict, optional
2719
- Output format set name or dictionary. Defaults to None.
2720
-
2721
- Returns
2722
- -------
2723
- dict | str
2724
- A dictionary or markdown string containing the combined term details and related terms.
2725
-
2726
- Raises
2727
- ------
2728
- InvalidParameterException
2729
- If the client passes incorrect parameters on the request - such as bad URLs or invalid values.
2730
- PropertyServerException
2731
- Raised by the server when an issue arises in processing a valid request.
2732
- NotAuthorizedException
2733
- The principle specified by the user_id does not have authorization for the requested action.
2734
- """
2735
- # Check if the output format is supported
2736
- if output_format not in ["DICT", "REPORT"]:
2737
- return f"Unsupported output format: {output_format}. Supported formats are DICT and REPORT."
2738
-
2739
- # Search for the term using the qualified name
2740
- terms = self.get_terms_by_name(term_name, effective_time=effective_time, output_format="DICT")
2741
-
2742
- # Check if we found any terms
2743
- if not terms or (isinstance(terms, str) and terms == NO_TERMS_FOUND):
2744
- return f"No term found with name: {term_name}"
2745
-
2746
- # Make sure we only have one term
2747
- if isinstance(terms, list) and len(terms) > 1:
2748
- return f"Multiple terms found with name: {term_name} - please specify the qualified name."
2749
-
2750
- term_details = terms[0]
2751
-
2752
- # Get related terms
2753
- try:
2754
- related_terms_response = self.get_related_terms(term_details.get('guid', ''), output_format="DICT")
2755
- except (InvalidParameterException, PropertyServerException, UserNotAuthorizedException):
2756
- # If we can't get related terms, set to empty list
2757
- related_terms_response = []
2758
-
2759
- # If no related terms were found, set to empty list
2760
- if isinstance(related_terms_response, str) and related_terms_response == NO_TERMS_FOUND:
2761
- related_terms = []
2762
- elif related_terms_response is None:
2763
- related_terms = []
2764
- else:
2765
- related_terms = related_terms_response
2766
-
2767
- # Combine the data
2768
- if output_format == "DICT":
2769
- # Create a combined dictionary
2770
- combined_data = {
2771
- "term_details": term_details, "related_terms": related_terms
2772
- }
2773
- return combined_data
2774
- elif output_format == "REPORT":
2775
- # Create a markdown report
2776
- md_output = f"# Term Details Report for `{term_name}` \n\n"
2777
-
2778
- # Add term details
2779
- md_output += "## Basic Term Information\n\n"
2780
- md_output += f"**Display Name:** {term_details.get('display_name', '')}\n\n"
2781
- md_output += f"**Qualified Name:** {term_details.get('qualified_name', '')}\n\n"
2782
- md_output += f"**GUID:** {term_details.get('guid', '')}\n\n"
2783
-
2784
- if 'summary' in term_details and term_details['summary']:
2785
- md_output += f"**Summary:** {term_details.get('summary', '')}\n\n"
2786
-
2787
- if 'description' in term_details and term_details['description']:
2788
- md_output += f"**Description:** {term_details.get('description', '')}\n\n"
2789
-
2790
- if 'examples' in term_details and term_details['examples']:
2791
- md_output += f"**Examples:** {term_details.get('examples', '')}\n\n"
2792
-
2793
- if 'usage' in term_details and term_details['usage']:
2794
- md_output += f"**Usage:** {term_details.get('usage', '')}\n\n"
2795
-
2796
- if 'aliases' in term_details and term_details['aliases']:
2797
- md_output += f"**Aliases:** {term_details.get('aliases', '')}\n\n"
2798
-
2799
- if 'status' in term_details and term_details['status']:
2800
- md_output += f"**Status:** {term_details.get('status', '')}\n\n"
2801
-
2802
- if 'in_glossary' in term_details and term_details['in_glossary']:
2803
- md_output += f"**Glossary:** {term_details.get('in_glossary', '')}\n\n"
2804
-
2805
- if 'categories' in term_details and term_details['categories']:
2806
- md_output += f"**Categories:** {', '.join(term_details.get('categories', []))}\n\n"
2807
-
2808
- # Add related terms
2809
- md_output += "## Related Terms\n\n"
2810
-
2811
- if not related_terms:
2812
- md_output += "No related terms found.\n\n"
2813
- else:
2814
- # Create a table for related terms
2815
- md_output += "| Related Term | Qualified Name | Relationship Type |\n"
2816
- md_output += "|--------------|---------------|-------------------|\n"
2817
-
2818
- for term in related_terms:
2819
- md_output += f"| {term.get('related_term_display_name', '')} | "
2820
- md_output += f"{term.get('related_term_qualified_name', '')} | "
2821
- md_output += f"{term.get('relationship_type', '')} |\n"
2822
-
2823
- return md_output
2824
- else:
2825
- return f"Unsupported output format: {output_format}. Supported formats are DICT and REPORT."
2826
-
2827
- async def _async_get_glossary_for_term(self, term_guid: str, effective_time: str = None) -> dict | str:
2828
- """Retrieve the glossary metadata element for the requested term. The optional request body allows you to
2829
- specify that the glossary element should only be returned if it was effective at a particular time.
2830
-
2831
- Async Version.
2832
-
2833
- Parameters
2834
- ----------
2835
- term_guid : str
2836
- The unique identifier for the term.
2837
-
2838
- effective_time : datetime, optional
2839
- If specified, the term information will be retrieved if it is active at the `effective_time`.
2840
- Time format is "YYYY-MM-DDTHH:MM:SS" (ISO 8601)
2841
-
2842
- Returns
2843
- -------
2844
- dict
2845
- The glossary information retrieved for the specified term.
2846
- Raises
2847
- ------
2848
- InvalidParameterException
2849
- If the client passes incorrect parameters on the request - such as bad URLs or invalid values.
2850
- PropertyServerException
2851
- Raised by the server when an issue arises in processing a valid request.
2852
- NotAuthorizedException
2853
- The principle specified by the user_id does not have authorization for the requested action.
2854
- Notes
2855
- -----
2856
- """
2857
-
2858
- validate_guid(term_guid)
2859
-
2860
- body = {
2861
- "class": "EffectiveTimeQueryRequestBody", "effectiveTime": effective_time,
2862
- }
2863
- url = (f"{self.platform_url}/servers/{self.view_server}/api/open-metadata/glossary-browser/glossaries/"
2864
- f"for-term/{term_guid}/retrieve")
2865
-
2866
- response = await self._async_make_request("POST", url, body_slimmer(body))
2867
- return response.json().get("element", NO_GLOSSARIES_FOUND)
2868
-
2869
- def get_glossary_for_term(self, term_guid: str, effective_time: str = None) -> dict | str:
2870
- """Retrieve the glossary metadata element for the requested term. The optional request body allows you to
2871
- specify that the glossary element should only be returned if it was effective at a particular time.
2872
-
2873
- Async Version.
2874
-
2875
- Parameters
2876
- ----------
2877
- term_guid : str
2878
- The unique identifier for the term.
2879
-
2880
- effective_time : datetime, optional
2881
- TIf specified, the term information will be retrieved if it is active at the `effective_time`.
2882
- Time format is "YYYY-MM-DDTHH:MM:SS" (ISO 8601).
2883
-
2884
- Returns
2885
- -------
2886
- dict
2887
- The glossary information retrieved for the specified term.
2888
- Raises
2889
- ------
2890
- InvalidParameterException
2891
- If the client passes incorrect parameters on the request - such as bad URLs or invalid values.
2892
- PropertyServerException
2893
- Raised by the server when an issue arises in processing a valid request.
2894
- NotAuthorizedException
2895
- The principle specified by the user_id does not have authorization for the requested action.
2896
- Notes
2897
- -----
2898
- """
2899
- loop = asyncio.get_event_loop()
2900
- response = loop.run_until_complete(self._async_get_glossary_for_term(term_guid, effective_time))
2901
- return response
2902
-
2903
- async def _async_get_terms_by_name(self, term: str, glossary_guid: str = None, status_filter: list = [],
2904
- effective_time: str = None, for_lineage: bool = False,
2905
- for_duplicate_processing: bool = False, start_from: int = 0,
2906
- page_size: int = None, output_format="JSON", output_format_set: str | dict = None) -> list:
2907
- """Retrieve glossary terms by display name or qualified name. Async Version.
2908
-
2909
- Parameters
2910
- ----------
2911
- term : str
2912
- The term to search for in the glossaries.
2913
- glossary_guid : str, optional
2914
- The GUID of the glossary to search in. If not provided, the search will be performed in all glossaries.
2915
- status_filter : list, optional
2916
- A list of status values to filter the search results. Default is an empty list, which means no filtering.
2917
-
2918
- effective_time : datetime, optional
2919
- If specified, the term information will be retrieved if it is active at the `effective_time`.
2920
- Time format is "YYYY-MM-DDTHH:MM:SS" (ISO 8601)
2921
- for_lineage : bool, optional
2922
- Flag to indicate whether the search should include lineage information. Default is False.
2923
- for_duplicate_processing : bool, optional
2924
- Flag to indicate whether the search should include duplicate processing information. Default is False.
2925
- start_from : int, optional
2926
- The index of the first term to retrieve. Default is 0.
2927
- page_size : int, optional
2928
- The number of terms to retrieve per page. If not provided, it will use the default page size.
2929
- output_format: str, default = 'JSON'
2930
- Type of output to produce:
2931
- JSON - output standard json
2932
- MD - output standard markdown with no preamble
2933
- FORM - output markdown with a preamble for a form
2934
- REPORT - output markdown with a preamble for a report
2935
- DICT - output a simplified DICT structure
2936
- output_format_set: str | dict, optional
2937
- Output format set name or dictionary. Defaults to None.
2938
-
2939
- Returns
2940
- -------
2941
- list
2942
- A list of terms matching the search criteria. If no terms are found, it returns the string "No terms found".
2943
-
2944
- Raises
2945
- ------
2946
- InvalidParameterException
2947
- If the client passes incorrect parameters on the request - such as bad URLs or invalid values.
2948
- PropertyServerException
2949
- Raised by the server when an issue arises in processing a valid request.
2950
- NotAuthorizedException
2951
- The principle specified by the user_id does not have authorization for the requested action.
2952
- """
2953
-
2954
- if page_size is None:
2955
- page_size = self.page_size
2956
-
2957
- validate_name(term)
2958
-
2959
- for_lineage_s = str(for_lineage).lower()
2960
- for_duplicate_processing_s = str(for_duplicate_processing).lower()
2961
-
2962
- body = {
2963
- "class": "GlossaryNameRequestBody", "glossaryGUID": glossary_guid, "name": term,
2964
- "effectiveTime": effective_time, "limitResultsByStatus": status_filter,
2965
- }
2966
- # body = body_slimmer(body)
2967
-
2968
- url = (f"{self.platform_url}/servers/{self.view_server}/api/open-metadata/glossary-browser/glossaries/"
2969
- f"terms/by-name?startFrom={start_from}&pageSize={page_size}&"
2970
- f"&forLineage={for_lineage_s}&forDuplicateProcessing={for_duplicate_processing_s}")
2971
-
2972
- # print(f"\n\nURL is: \n {url}\n\nBody is: \n{body}")
2973
- response = await self._async_make_request("POST", url, body_slimmer(body))
2974
- term_elements = response.json().get("elementList", NO_TERMS_FOUND)
2975
- if term_elements == NO_TERMS_FOUND:
2976
- if output_format == 'JSON':
2977
- return NO_TERMS_FOUND
2978
- elif output_format in ['MD', 'FORM', 'REPORT', 'LIST']:
2979
- return "\n# No Terms found.\n"
2980
- elif output_format == 'DICT':
2981
- return None
2982
- if output_format != "JSON": # return a simplified markdown representation
2983
- return self.generate_terms_md(term_elements, term, output_format, output_format_set)
2984
- return response.json().get("elementList", NO_TERMS_FOUND)
2985
-
2986
- def get_terms_by_name(self, term: str, glossary_guid: str = None, status_filter: list = [],
2987
- effective_time: str = None, for_lineage: bool = False, for_duplicate_processing: bool = False,
2988
- start_from: int = 0, page_size: int = None, output_format="JSON", output_format_set: str | dict = None) -> list:
2989
- """Retrieve glossary terms by display name or qualified name.
2990
-
2991
- Parameters
2992
- ----------
2993
- term : str
2994
- The term to search for in the glossaries.
2995
- glossary_guid : str, optional
2996
- The GUID of the glossary to search in. If not provided, the search will be performed in all glossaries.
2997
- status_filter : list, optional
2998
- A list of status values to filter the search results. Default is an empty list, which means no filtering.
2999
-
3000
- effective_time : datetime, optional
3001
- If specified, the term information will be retrieved if it is active at the `effective_time`.
3002
- Time format is "YYYY-MM-DDTHH:MM:SS" (ISO 8601)
3003
- for_lineage : bool, optional
3004
- Flag to indicate whether the search should include lineage information. Default is False.
3005
- for_duplicate_processing : bool, optional
3006
- Flag to indicate whether the search should include duplicate processing information. Default is False.
3007
- start_from : int, optional
3008
- The index of the first term to retrieve. Default is 0.
3009
- page_size : int, optional
3010
- The number of terms to retrieve per page. If not provided, it will use the default page size.
3011
- output_format: str, default = 'JSON'
3012
- Type of output to produce:
3013
- JSON - output standard json
3014
- MD - output standard markdown with no preamble
3015
- FORM - output markdown with a preamble for a form
3016
- REPORT - output markdown with a preamble for a report
3017
- DICT - output a simplified DICT structure
3018
- output_format_set: str | dict, optional
3019
- Output format set name or dictionary. Defaults to None.
3020
-
3021
- Returns
3022
- -------
3023
- list
3024
- A list of terms matching the search criteria. If no terms are found,
3025
- it returns the string "No terms found".
3026
-
3027
- Raises
3028
- ------
3029
- InvalidParameterException
3030
- If the client passes incorrect parameters on the request - such as bad URLs or invalid values.
3031
- PropertyServerException
3032
- Raised by the server when an issue arises in processing a valid request.
3033
- NotAuthorizedException
3034
- The principle specified by the user_id does not have authorization for the requested action.
3035
- """
3036
- loop = asyncio.get_event_loop()
3037
- response = loop.run_until_complete(
3038
- self._async_get_terms_by_name(term, glossary_guid, status_filter, effective_time, for_lineage,
3039
- for_duplicate_processing, start_from, page_size, output_format, output_format_set))
3040
- return response
3041
-
3042
- async def _async_get_term_by_guid(self, term_guid: str, output_format: str = 'JSON', output_format_set: str | dict = None) -> dict | str:
3043
- """Retrieve a term using its unique id. Async version.
3044
- Parameters
3045
- ----------
3046
- term_guid : str
3047
- The GUID of the glossary term to retrieve.
3048
- output_format: str, default = 'JSON'
3049
- Type of output to produce:
3050
- JSON - output standard json
3051
- MD - output standard markdown with no preamble
3052
- FORM - output markdown with a preamble for a form
3053
- REPORT - output markdown with a preamble for a report
3054
- output_format_set: str | dict, optional
3055
- Output format set name or dictionary. Defaults to None.
3056
-
3057
- Returns
3058
- -------
3059
- dict | str
3060
- A dict detailing the glossary term represented by the GUID. If no term is found, the string
3061
- "No term found" will be returned.
3062
-
3063
- Raises
3064
- ------
3065
- InvalidParameterException
3066
- If the client passes incorrect parameters on the request - such as bad URLs or invalid values.
3067
- PropertyServerException
3068
- Raised by the server when an issue arises in processing a valid request.
3069
- NotAuthorizedException
3070
- The principle specified by the user_id does not have authorization for the requested action.
3071
- """
3072
- output_format = output_format.upper()
3073
- validate_guid(term_guid)
3074
-
3075
- url = (f"{self.platform_url}/servers/{self.view_server}/api/open-metadata/glossary-browser/glossaries/terms/"
3076
- f"{term_guid}/retrieve")
3077
- response = await self._async_make_request("POST", url)
3078
- term_element = response.json().get("element", NO_TERMS_FOUND)
3079
- if term_element == NO_TERMS_FOUND:
3080
- return NO_TERMS_FOUND
3081
- if output_format != 'JSON': # return a simplified markdown representation
3082
- return self.generate_terms_md(term_element, "GUID", output_format, output_format_set)
3083
- return response.json().get("element", NO_TERMS_FOUND)
3084
-
3085
- def get_term_by_guid(self, term_guid: str, output_format: str = 'JSON', output_format_set: str | dict = None) -> dict | str:
3086
- """Retrieve a term using its unique id. Async version.
3087
- Parameters
3088
- ----------
3089
- term_guid : str
3090
- The GUID of the glossary term to retrieve.
3091
- output_format: str, default = 'JSON'
3092
- Type of output to produce:
3093
- JSON - output standard json
3094
- MD - output standard markdown with no preamble
3095
- FORM - output markdown with a preamble for a form
3096
- REPORT - output markdown with a preamble for a report
3097
- output_format_set: str | dict, optional
3098
- Output format set name or dictionary. Defaults to None.
3099
- Returns
3100
- -------
3101
- dict | str
3102
- A dict detailing the glossary term represented by the GUID. If no term is found, the string
3103
- "No term found" will be returned.
3104
- Raises
3105
- ------
3106
- InvalidParameterException
3107
- If the client passes incorrect parameters on the request - such as bad URLs or invalid values.
3108
- PropertyServerException
3109
- Raised by the server when an issue arises in processing a valid request.
3110
- NotAuthorizedException
3111
- The principle specified by the user_id does not have authorization for the requested action.
3112
- """
3113
-
3114
- loop = asyncio.get_event_loop()
3115
- response = loop.run_until_complete(self._async_get_term_by_guid(term_guid, output_format, output_format_set))
3116
-
3117
- return response
3118
-
3119
- async def _async_get_term_versions(self, term_guid: str, effective_time: str = None, from_time: str = None,
3120
- to_time: str = None, oldest_first: bool = False, for_lineage: bool = False,
3121
- for_duplicate_processing: bool = False, start_from: int = 0,
3122
- page_size=max_paging_size,
3123
-
3124
- ) -> list | str:
3125
- """Retrieve the versions of a glossary term. Async version.
3126
- Parameters
3127
- ----------
3128
- term_guid : str
3129
- The GUID of the glossary term to retrieve.
3130
-
3131
- start_from : int, optional
3132
- The index of the first term to retrieve. Default is 0.
3133
- page_size : int, optional
3134
- The number of terms to retrieve per page. If not provided, it will use the default page size.
3135
- Returns
3136
- -------
3137
- list | str
3138
- A [dict] detailing the glossary term represented by the GUID. If no term is found, the string
3139
- "No term found" will be returned.
3140
-
3141
- Raises
3142
- ------
3143
- InvalidParameterException
3144
- If the client passes incorrect parameters on the request - such as bad URLs or invalid values.
3145
- PropertyServerException
3146
- Raised by the server when an issue arises in processing a valid request.
3147
- NotAuthorizedException
3148
- The principle specified by the user_id does not have authorization for the requested action.
3149
-
3150
- Args:
3151
- term_guid:
3152
- effective_time:
3153
- from_time:
3154
- to_time:
3155
- oldest_first:
3156
- for_lineage:
3157
- for_duplicate_processing:
3158
- start_from:
3159
- page_size:
3160
- """
3161
-
3162
- body = {
3163
- "effective_time": effective_time, "fromTime": from_time, "toTime": to_time, "forLineage": for_lineage,
3164
- "forDuplicateProcessing": for_duplicate_processing
3165
- }
3166
-
3167
- oldest_first_s = str(oldest_first).lower()
3168
- validate_guid(term_guid)
3169
-
3170
- url = (f"{self.platform_url}/servers/{self.view_server}/api/open-metadata/glossary-browser/glossaries/terms/"
3171
- f"{term_guid}/history?startFrom={start_from}&pageSize={page_size}&oldestFirst={oldest_first_s}&"
3172
- f"forDuplicateProcessing={for_duplicate_processing}&forLineage={for_lineage}")
3173
-
3174
- response = await self._async_make_request("POST", url, body_slimmer(body))
3175
- return response.json().get("elementList", "No term found")
3176
-
3177
- def get_term_versions(self, term_guid: str, effective_time: str = None, from_time: str = None, to_time: str = None,
3178
- oldest_first: bool = False, for_lineage: bool = False, for_duplicate_processing: bool = False,
3179
- start_from: int = 0, page_size=max_paging_size, ) -> dict | str:
3180
- """Retrieve the versions of a glossary term.
3181
- Parameters
3182
- ----------
3183
- term_guid : str
3184
- The GUID of the glossary term to retrieve.
3185
-
3186
- start_from : int, optional
3187
- The index of the first term to retrieve. Default is 0.
3188
- page_size : int, optional
3189
- The number of terms to retrieve per page. If not provided, it will use the default page size.
3190
- Returns
3191
- -------
3192
- [dict] | str
3193
- A [dict] detailing the glossary term represented by the GUID. If no term is found, the string
3194
- "No term found" will be returned.
3195
-
3196
- Raises
3197
- ------
3198
- InvalidParameterException
3199
- If the client passes incorrect parameters on the request - such as bad URLs or invalid values.
3200
- PropertyServerException
3201
- Raised by the server when an issue arises in processing a valid request.
3202
- NotAuthorizedException
3203
- The principle specified by the user_id does not have authorization for the requested action.
3204
- """
3205
-
3206
- loop = asyncio.get_event_loop()
3207
- response = loop.run_until_complete(
3208
- self._async_get_term_versions(term_guid, effective_time, from_time, to_time, oldest_first, for_lineage,
3209
- for_duplicate_processing, start_from, page_size))
3210
-
3211
- return response
3212
-
3213
- async def _async_get_term_revision_logs(self, term_guid: str, start_from: int = 0, page_size=None, ) -> dict | str:
3214
- """Retrieve the revision log history for a term. Async version.
3215
- Parameters
3216
- ----------
3217
- term_guid : str
3218
- The GUID of the glossary term to retrieve.
3219
-
3220
- start_from : int, optional
3221
- The index of the first term to retrieve. Default is 0.
3222
- page_size : int, optional
3223
- The number of terms to retrieve per page. If not provided, it will use the default page size.
3224
- Returns
3225
- -------
3226
- dict | str
3227
- A dict detailing the glossary term revision log history. If no term is found, the string
3228
- "No log found" will be returned.
3229
-
3230
- Raises
3231
- ------
3232
- InvalidParameterException
3233
- If the client passes incorrect parameters on the request - such as bad URLs or invalid values.
3234
- PropertyServerException
3235
- Raised by the server when an issue arises in processing a valid request.
3236
- NotAuthorizedException
3237
- The principle specified by the user_id does not have authorization for the requested action.
3238
- """
3239
-
3240
- if page_size is None:
3241
- page_size = self.page_size
3242
-
3243
- validate_guid(term_guid)
3244
-
3245
- url = (f"{self.platform_url}/servers/{self.view_server}/api/open-metadata/glossary-browser/elements/"
3246
- f"{term_guid}/note-logs/retrieve?startFrom={start_from}&pageSize={page_size}")
3247
-
3248
- response = await self._async_make_request("POST", url)
3249
- return response.json().get("elementList", "No log found")
3250
-
3251
- def get_term_revision_logs(self, term_guid: str, start_from: int = 0, page_size=None, ) -> dict | str:
3252
- """Retrieve the revision log history for a term.
3253
- Parameters
3254
- ----------
3255
- term_guid : str
3256
- The GUID of the glossary term to retrieve.
3257
-
3258
- start_from : int, optional
3259
- The index of the first term to retrieve. Default is 0.
3260
- page_size : int, optional
3261
- The number of terms to retrieve per page. If not provided, it will use the default page size.
3262
- Returns
3263
- -------
3264
- dict | str
3265
- A dict detailing the glossary term revision log history. If no term is found, the string
3266
- "No log found" will be returned.
3267
-
3268
- Raises
3269
- ------
3270
- InvalidParameterException
3271
- If the client passes incorrect parameters on the request - such as bad URLs or invalid values.
3272
- PropertyServerException
3273
- Raised by the server when an issue arises in processing a valid request.
3274
- NotAuthorizedException
3275
- The principle specified by the user_id does not have authorization for the requested action.
3276
- """
3277
-
3278
- loop = asyncio.get_event_loop()
3279
- response = loop.run_until_complete(self._async_get_term_revision_logs(term_guid, start_from, page_size))
3280
-
3281
- return response
3282
-
3283
- async def _async_get_term_revision_history(self, term_revision_log_guid: str, start_from: int = 0,
3284
- page_size=None, ) -> dict | str:
3285
- """Retrieve the revision history for a glossary term. Async version.
3286
-
3287
- Parameters
3288
- ----------
3289
- term_revision_log_guid : str
3290
- The GUID of the glossary term revision log to retrieve.
3291
-
3292
- start_from : int, optional
3293
- The index of the first term to retrieve. Default is 0.
3294
- page_size : int, optional
3295
- The number of terms to retrieve per page. If not provided, it will use the default page size.
3296
- Returns
3297
- -------
3298
- dict | str
3299
- A dict detailing the glossary term revision history.
3300
-
3301
- Raises
3302
- ------
3303
- InvalidParameterException
3304
- If the client passes incorrect parameters on the request - such as bad URLs or invalid values.
3305
- PropertyServerException
3306
- Raised by the server when an issue arises in processing a valid request.
3307
- NotAuthorizedException
3308
- The principle specified by the user_id does not have authorization for the requested action.
3309
-
3310
-
3311
- Notes
3312
- -----
3313
- This revision history is created automatically. The text is supplied on the update request.
3314
- If no text is supplied, the value "None" is show.
3315
- """
3316
-
3317
- if page_size is None:
3318
- page_size = self.page_size
3319
-
3320
- validate_guid(term_revision_log_guid)
3321
-
3322
- url = (f"{self.platform_url}/servers/{self.view_server}/api/open-metadata/glossary-browser/note-logs/"
3323
- f"{term_revision_log_guid}/notes/retrieve?startFrom={start_from}&pageSize={page_size}")
3324
-
3325
- response = await self._async_make_request("POST", url)
3326
- return response.json().get("elementList", "No logs found")
3327
-
3328
- def get_term_revision_history(self, term_revision_log_guid: str, start_from: int = 0,
3329
- page_size=None, ) -> dict | str:
3330
- """Retrieve the revision history for a glossary term.
3331
-
3332
- Parameters
3333
- ----------
3334
- term_revision_log_guid : str
3335
- The GUID of the glossary term revision log to retrieve.
3336
-
3337
- start_from : int, optional
3338
- The index of the first term to retrieve. Default is 0.
3339
- page_size : int, optional
3340
- The number of terms to retrieve per page. If not provided, it will use the default page size.
3341
- Returns
3342
- -------
3343
- dict | str
3344
- A dict detailing the glossary term revision history.
3345
-
3346
- Raises
3347
- ------
3348
- InvalidParameterException
3349
- If the client passes incorrect parameters on the request - such as bad URLs or invalid values.
3350
- PropertyServerException
3351
- Raised by the server when an issue arises in processing a valid request.
3352
- NotAuthorizedException
3353
- The principle specified by the user_id does not have authorization for the requested action.
3354
-
3355
-
3356
- Notes
3357
- -----
3358
- This revision history is created automatically. The text is supplied on the update request.
3359
- If no text is supplied, the value "None" is show.
3360
- """
3361
-
3362
- loop = asyncio.get_event_loop()
3363
- response = loop.run_until_complete(
3364
- self._async_get_term_revision_history(term_revision_log_guid, start_from, page_size))
3365
-
3366
- return response
3367
-
3368
- def list_term_revision_history(self, term_guid: str, output_format: str = "DICT", output_format_set: str | dict = None) -> list | str:
3369
- """
3370
- Retrieve the revision history for a term.
3371
-
3372
- This method retrieves the revision logs associated with a term, and for each revision log,
3373
- retrieves the revision history. The results are formatted according to the specified output format.
3374
-
3375
- Parameters
3376
- ----------
3377
- term_guid : str
3378
- The GUID of the glossary term to retrieve the revision history for.
3379
- output_format : str, optional
3380
- The format in which to return the results. Can be "DICT", "MD", or "LIST".
3381
- Defaults to "DICT".
3382
- output_format_set : str | dict, optional
3383
- Output format set name or dictionary. Defaults to None.
3384
-
3385
- Returns
3386
- -------
3387
- list | str
3388
- If output_format is "DICT", returns a list of dictionaries containing the revision history.
3389
- If output_format is "MD", returns a markdown representation of the revision history.
3390
- If output_format is "LIST", returns a markdown table of the revision history.
3391
- If no revision logs are found, returns a string message "No revision logs found".
3392
- """
3393
- validate_guid(term_guid)
3394
-
3395
- # Get revision logs for the term
3396
- revision_logs = self.get_term_revision_logs(term_guid)
3397
- if isinstance(revision_logs, str):
3398
- return "No revision logs found"
3399
-
3400
- # Process each revision log
3401
- all_entries = []
3402
- for log in revision_logs:
3403
- log_guid = log['elementHeader']['guid']
3404
- qualified_name = log.get('properties', {}).get('qualifiedName', '---')
3405
-
3406
- # Get revision history for this log
3407
- history = self.get_term_revision_history(log_guid)
3408
- if isinstance(history, str):
3409
- continue
3410
-
3411
- # Process each entry in the history
3412
- for entry in history:
3413
- # Extract update time from the title
3414
- title = entry.get('properties', {}).get('title', '---')
3415
-
3416
- keyword_index = title.index('on')
3417
- update_time = title[keyword_index + 2:].strip()
3418
-
3419
- entry_data = {
3420
- 'qualifiedName': qualified_name, 'title': title,
3421
- 'text': entry.get('properties', {}).get('text', '---'), 'updateTime': update_time
3422
- # Use extracted date/time or fall back to title
3423
- }
3424
- all_entries.append(entry_data)
3425
-
3426
- # Sort entries by update time
3427
- sorted_entries = sorted(all_entries, key=lambda x: x['updateTime'] if x['updateTime'] != '---' else '',
3428
- reverse=True)
3429
-
3430
- # Return in the specified format
3431
- if output_format == "DICT":
3432
- return sorted_entries
3433
- elif output_format == "LIST":
3434
- # Create markdown table
3435
- if not sorted_entries:
3436
- return "No revision entries found"
3437
-
3438
- # Get headers
3439
- headers = sorted_entries[0].keys()
3440
-
3441
- # Create header row
3442
- header_row = " | ".join(headers)
3443
- separator_row = " | ".join(["---"] * len(headers))
3444
-
3445
- # Create rows
3446
- rows = []
3447
- for entry in sorted_entries:
3448
- row = " | ".join(str(entry.get(header, "---")) for header in headers)
3449
- rows.append(row)
3450
-
3451
- # Combine into table
3452
- markdown_table = f"{header_row}\n{separator_row}\n" + "\n".join(rows)
3453
- return markdown_table
3454
- elif output_format == "MD":
3455
- # Create markdown representation
3456
- if not sorted_entries:
3457
- return "No revision entries found"
3458
-
3459
- md_output = "\n"
3460
-
3461
- for entry in sorted_entries:
3462
- md_output += f"* Note Log Name: \n{entry['qualifiedName']}\n\n"
3463
- md_output += f"* Note Log Entry Title: \n{entry['title']}\n\n"
3464
- md_output += f"* Note Log Entry: \n\t{entry['text']}\n\n"
3465
- md_output += "---\n\n"
3466
-
3467
- return md_output
3468
- else:
3469
- # Default to DICT format
3470
- return sorted_entries
3471
-
3472
- def list_full_term_history(self, term_guid: str, output_format: str = "DICT", output_format_set: str | dict = None) -> list | str:
3473
- """
3474
- Retrieves and formats the entire version history of a specific term in the repository.
3475
- The version history is either returned as a list of dictionaries or in a Markdown table
3476
- format.
3477
-
3478
- The returned history includes details about the creation and update timestamps, user
3479
- information, and additional glossary term properties such as `displayName`,
3480
- `qualifiedName`, `description`, and others.
3481
-
3482
- Parameter
3483
- ---------
3484
- term_guid: The unique identifier of the glossary term for which the version
3485
- history needs to be retrieved.
3486
- output_format: The format in which the history should be returned. It can be
3487
- either "DICT" (a list of dictionaries) or "LIST" (a Markdown table).
3488
- Defaults to "DICT".
3489
- output_format_set: str | dict, optional
3490
- Output format set name or dictionary. Defaults to None.
3491
-
3492
- Returns
3493
- -------
3494
- list | str: A list of dictionaries representing the version history
3495
- (if output_format is "DICT"), or a Markdown table of the version details
3496
- (if output_format is "LIST"). If no history is found, returns a string
3497
- message "No History Found".
3498
- """
3499
- history = self.get_term_versions(term_guid)
3500
- if type(history) is str:
3501
- return "No History Found"
3502
- version_history = []
3503
- for ver in history:
3504
- create_time = ver["elementHeader"]["versions"].get("createTime", " ")
3505
- update_time = ver["elementHeader"]["versions"].get("createTime", " ")
3506
- created_by = ver["elementHeader"]["versions"].get("createdBy", " ")
3507
- updated_by = ver["elementHeader"]["versions"].get("updatedBy", "---")
3508
- version = ver["elementHeader"]["versions"].get("version")
3509
-
3510
- qualified_name = ver["glossaryTermProperties"].get("qualifiedName", ' ')
3511
- display_name = ver["glossaryTermProperties"].get("displayName", ' ')
3512
- summary = ver["glossaryTermProperties"].get("summary", ' ')
3513
- description = ver["glossaryTermProperties"].get("description", ' ')
3514
- examples = ver["glossaryTermProperties"].get("examples", ' ')
3515
- usage = ver["glossaryTermProperties"].get("usage", ' ')
3516
- version_identifier = ver["glossaryTermProperties"].get("versionIdentifier", ' ')
3517
-
3518
- version_history.append({
3519
- "version": version, "displayName": display_name, "summary": summary, "created": create_time,
3520
- "updated": update_time, "createdBy": created_by, "updatedBy": updated_by,
3521
- "qualifiedName": qualified_name, "description": description, "examples": examples, "usage": usage,
3522
- "versionIdentifier": version_identifier,
3523
- })
3524
- sorted_history = sorted(version_history, key=lambda i: i['version'], reverse=True)
3525
- if output_format == "DICT":
3526
- return sorted_history
3527
- elif output_format == "LIST":
3528
- # Get the headers from the keys of the first dictionary
3529
- headers = sorted_history[0].keys()
3530
-
3531
- # Create the header row
3532
- header_row = " | ".join(headers)
3533
- separator_row = " | ".join(["---"] * len(headers)) # Markdown separator row
3534
-
3535
- # Create the rows for the table
3536
- rows = []
3537
- for entry in sorted_history:
3538
- row = " | ".join(str(entry.get(header, "---")) for header in headers)
3539
- rows.append(row)
3540
-
3541
- # Combine everything into a Markdown table string
3542
- markdown_table = f"{header_row}\n{separator_row}\n" + "\n".join(rows)
3543
- return markdown_table
3544
- else:
3545
- return None
3546
-
3547
- async def _async_find_glossary_terms(self, search_string: str, glossary_guid: str = None, status_filter: list = [],
3548
- effective_time: str = None, starts_with: bool = False, ends_with: bool = False,
3549
- ignore_case: bool = False, for_lineage: bool = False,
3550
- for_duplicate_processing: bool = False, start_from: int = 0,
3551
- page_size: int = None, output_format: str = "JSON", output_format_set: str | dict = None) -> list | str:
3552
- """Retrieve the list of glossary term metadata elements that contain the search string.
3553
-
3554
- Parameters
3555
- ----------
3556
- search_string: str
3557
- Search string to use to find matching glossaries. If the search string is '*' then all glossaries returned.
3558
- glossary_guid str
3559
- Identifier of the glossary to search within. If None, then all glossaries are searched.
3560
- status_filter: list, default = [], optional
3561
- Filters the results by the included Term statuses (such as 'ACTIVE', 'DRAFT'). If not specified,
3562
- the results will not be filtered.
3563
- effective_time: str, [default=None], optional
3564
- If specified, the term information will be retrieved if it is active at the `effective_time`.
3565
- Time format is "YYYY-MM-DDTHH:MM:SS" (ISO 8601)
3566
-
3567
- If not provided, the server name associated with the instance is used.
3568
- starts_with : bool, [default=False], optional
3569
- Starts with the supplied string.
3570
- ends_with : bool, [default=False], optional
3571
- Ends with the supplied string
3572
- ignore_case : bool, [default=False], optional
3573
- Ignore case when searching
3574
- for_lineage : bool, [default=False], optional
3575
-
3576
- for_duplicate_processing : bool, [default=False], optional
3577
-
3578
- start_from: str, [default=0], optional
3579
- Page of results to start from
3580
- page_size : int, optional
3581
- Number of elements to return per page - if None, then default for class will be used.
3582
- output_format: str, default = 'JSON'
3583
- Type of output to produce:
3584
- JSON - output standard json
3585
- MD - output standard markdown with no preamble
3586
- FORM - output markdown with a preamble for a form
3587
- REPORT - output markdown with a preamble for a report
3588
-
3589
- Returns
3590
- -------
3591
- List | str
3592
-
3593
- A list of term definitions
3594
-
3595
- Raises
3596
- ------
3597
- InvalidParameterException
3598
- If the client passes incorrect parameters on the request - such as bad URLs or invalid values
3599
- PropertyServerException
3600
- Raised by the server when an issue arises in processing a valid request
3601
- NotAuthorizedException
3602
- The principle specified by the user_id does not have authorization for the requested action
3603
-
3604
- Notes
3605
- -----
3606
- The search string is located in the request body and is interpreted as a plain string.
3607
- The request parameters, startsWith, endsWith, and ignoreCase can be used to allow a fuzzy search.
3608
- The request body also supports the specification of a glossaryGUID to restrict the search to within a single
3609
- glossary.
3610
- """
3611
-
3612
- if page_size is None:
3613
- page_size = self.page_size
3614
- if effective_time is None:
3615
- effective_time = datetime.now().isoformat()
3616
- starts_with_s = str(starts_with).lower()
3617
- ends_with_s = str(ends_with).lower()
3618
- ignore_case_s = str(ignore_case).lower()
3619
- for_lineage_s = str(for_lineage).lower()
3620
- for_duplicate_processing_s = str(for_duplicate_processing).lower()
3621
- if search_string == "*":
3622
- search_string = None
3623
-
3624
- # validate_search_string(search_string)
3625
-
3626
- body = {
3627
- "class": "GlossarySearchStringRequestBody", "glossaryGUID": glossary_guid, "searchString": search_string,
3628
- "effectiveTime": effective_time, "limitResultsByStatus": status_filter,
3629
- }
3630
-
3631
- url = (f"{self.platform_url}/servers/{self.view_server}/api/open-metadata/glossary-browser/glossaries/"
3632
- f"terms/by-search-string?startFrom={start_from}&pageSize={page_size}&startsWith={starts_with_s}&"
3633
- f"endsWith={ends_with_s}&ignoreCase={ignore_case_s}&forLineage={for_lineage_s}&"
3634
- f"forDuplicateProcessing={for_duplicate_processing_s}")
3635
-
3636
- response = await self._async_make_request("POST", url, body_slimmer(body))
3637
- term_elements = response.json().get("elementList", NO_TERMS_FOUND)
3638
- if term_elements == NO_TERMS_FOUND:
3639
- if output_format == 'JSON':
3640
- return NO_TERMS_FOUND
3641
- elif output_format in ['MD', 'FORM', 'REPORT', 'LIST']:
3642
- return "\n# No Terms found.\n"
3643
- elif output_format == 'DICT':
3644
- return None
3645
- if output_format != "JSON": # return a simplified markdown representation
3646
- return self.generate_terms_md(term_elements, search_string, output_format, output_format_set)
3647
- return response.json().get("elementList", NO_TERMS_FOUND)
3648
-
3649
- def find_glossary_terms(self, search_string: str, glossary_guid: str = None, status_filter: list = [],
3650
- effective_time: str = None, starts_with: bool = False, ends_with: bool = False,
3651
- ignore_case: bool = False, for_lineage: bool = False,
3652
- for_duplicate_processing: bool = False, start_from: int = 0, page_size: int = None,
3653
- output_format: str = "JSON", output_format_set: str | dict = None) -> list | str:
3654
- """Retrieve the list of glossary term metadata elements that contain the search string.
3655
-
3656
- Parameters
3657
- ----------
3658
- search_string: str
3659
- Search string to use to find matching glossaries. If the search string is '*' then all glossaries
3660
- returned.
3661
- glossary_guid str
3662
- Identifier of the glossary to search within. If None, then all glossaries are searched.
3663
- status_filter: list, default = [], optional
3664
- Filters the results by the included Term statuses (such as 'ACTIVE', 'DRAFT'). If not specified,
3665
- the results will not be filtered.
3666
- effective_time: str, [default=None], optional
3667
- If specified, the term information will be retrieved if it is active at the `effective_time`.
3668
- Time format is "YYYY-MM-DDTHH:MM:SS" (ISO 8601)
3669
-
3670
- If not provided, the server name associated with the instance is used.
3671
- starts_with : bool, [default=False], optional
3672
- Starts with the supplied string.
3673
- ends_with : bool, [default=False], optional
3674
- Ends with the supplied string
3675
- ignore_case : bool, [default=False], optional
3676
- Ignore case when searching
3677
- for_lineage : bool, [default=False], optional
3678
-
3679
- for_duplicate_processing : bool, [default=False], optional
3680
-
3681
- start_from: str, [default=0], optional
3682
- Page of results to start from
3683
- page_size : int, optional
3684
- Number of elements to return per page - if None, then default for class will be used.
3685
- output_format: str, default = 'JSON'
3686
- Type of output to produce:
3687
- JSON - output standard json
3688
- MD - output standard markdown with no preamble
3689
- FORM - output markdown with a preamble for a form
3690
- REPORT - output markdown with a preamble for a report
3691
- output_format_set: str | dict, optional
3692
- Output format set name or dictionary. Defaults to None.
3693
-
3694
- Returns
3695
- -------
3696
- List | str
3697
-
3698
- A list of term definitions
3699
-
3700
- Raises
3701
- ------
3702
- InvalidParameterException
3703
- If the client passes incorrect parameters on the request - such as bad URLs or invalid values
3704
- PropertyServerException
3705
- Raised by the server when an issue arises in processing a valid request
3706
- NotAuthorizedException
3707
- The principle specified by the user_id does not have authorization for the requested action
3708
-
3709
- Notes
3710
- -----
3711
- The search string is located in the request body and is interpreted as a plain string.
3712
- The request parameters, startsWith, endsWith, and ignoreCase can be used to allow a fuzzy search.
3713
- The request body also supports the specification of a glossaryGUID to restrict the search to within a
3714
- single glossary.
3715
- """
3716
-
3717
- loop = asyncio.get_event_loop()
3718
- response = loop.run_until_complete(
3719
- self._async_find_glossary_terms(search_string, glossary_guid, status_filter, effective_time, starts_with,
3720
- ends_with, ignore_case, for_lineage, for_duplicate_processing, start_from,
3721
- page_size, output_format, output_format_set))
3722
-
3723
- return response
3724
-
3725
- #
3726
- # Feedback
3727
- #
3728
- async def _async_get_comment(self, commemt_guid: str, effective_time: str, for_lineage: bool = False,
3729
- for_duplicate_processing: bool = False, ) -> dict | list:
3730
- """Retrieve the comment specified by the comment GUID"""
3731
-
3732
- validate_guid(commemt_guid)
3733
-
3734
- if effective_time is None:
3735
- effective_time = datetime.now().isoformat()
3736
-
3737
- for_lineage_s = str(for_lineage).lower()
3738
- for_duplicate_processing_s = str(for_duplicate_processing).lower()
3739
-
3740
- body = {"effective_time": effective_time}
3741
-
3742
- url = (f"{self.platform_url}/servers/{self.view_server}/api/open-metadata/glossary-browser/comments/"
3743
- f"{commemt_guid}?forLineage={for_lineage_s}&"
3744
- f"forDuplicateProcessing={for_duplicate_processing_s}")
3745
-
3746
- # print(f"\n\nURL is: \n {url}\n\nBody is: \n{body}")
3747
-
3748
- response = await self._async_make_request("POST", url, body)
3749
- return response.json()
3750
-
3751
- async def _async_add_comment_reply(self, comment_guid: str, is_public: bool, comment_type: str, comment_text: str,
3752
- for_lineage: bool = False, for_duplicate_processing: bool = False, ) -> str:
3753
- """Reply to a comment"""
3754
-
3755
- validate_guid(comment_guid)
3756
- validate_name(comment_type)
3757
-
3758
- is_public_s = str(is_public).lower()
3759
- for_lineage_s = str(for_lineage).lower()
3760
- for_duplicate_processing_s = str(for_duplicate_processing).lower()
3761
-
3762
- body = {
3763
- "class": "CommentRequestBody", "commentType": comment_type, "commentText": comment_text,
3764
- "isPublic": is_public,
3765
- }
3766
-
3767
- url = (f"{self.platform_url}/servers/{self.view_server}/api/open-metadata/glossary-browser/comments/"
3768
- f"{comment_guid}/replies?isPublic={is_public_s}&forLineage={for_lineage_s}&"
3769
- f"forDuplicateProcessing={for_duplicate_processing_s}")
3770
-
3771
- # print(f"\n\nURL is: \n {url}\n\nBody is: \n{body}")
3772
-
3773
- response = await self._async_make_request("POST", url, body)
3774
- return response
3775
-
3776
- async def _async_update_comment(self, comment_guid: str, is_public: bool, comment_type: str, comment_text: str,
3777
- is_merge_update: bool = False, for_lineage: bool = False,
3778
- for_duplicate_processing: bool = False, ) -> str:
3779
- """Update the specified comment"""
3780
-
3781
- validate_guid(comment_guid)
3782
- validate_name(comment_type)
3783
-
3784
- is_public_s = str(is_public).lower()
3785
- for_lineage_s = str(for_lineage).lower()
3786
- for_duplicate_processing_s = str(for_duplicate_processing).lower()
3787
-
3788
- body = {
3789
- "class": "CommentRequestBody", "commentType": comment_type, "commentText": comment_text,
3790
- "isPublic": is_public,
3791
- }
3792
-
3793
- url = (f"{self.platform_url}/servers/{self.view_server}/api/open-metadata/glossary-browser/comments/"
3794
- f"{comment_guid}/replies?isPublic={is_public_s}&forLineage={for_lineage_s}&"
3795
- f"forDuplicateProcessing={for_duplicate_processing_s}")
3796
-
3797
- # print(f"\n\nURL is: \n {url}\n\nBody is: \n{body}")
3798
-
3799
- response = await self._async_make_request("POST", url, body)
3800
- return response
3801
-
3802
- async def _async_find_comment(self, search_string: str, glossary_guid: str = None, status_filter: list = [],
3803
- effective_time: str = None, starts_with: bool = False, ends_with: bool = False,
3804
- ignore_case: bool = False, for_lineage: bool = False,
3805
- for_duplicate_processing: bool = False, start_from: int = 0, page_size: int = None, ):
3806
- """Find comments by search string"""
3807
-
3808
- if page_size is None:
3809
- page_size = self.page_size
3810
- if effective_time is None:
3811
- effective_time = datetime.now().isoformat()
3812
- starts_with_s = str(starts_with).lower()
3813
- ends_with_s = str(ends_with).lower()
3814
- ignore_case_s = str(ignore_case).lower()
3815
- for_lineage_s = str(for_lineage).lower()
3816
- for_duplicate_processing_s = str(for_duplicate_processing).lower()
3817
- if search_string == "*":
3818
- search_string = None
3819
-
3820
- # validate_search_string(search_string)
3821
-
3822
- body = {
3823
- "class": "GlossarySearchStringRequestBody", "glossaryGUID": glossary_guid, "searchString": search_string,
3824
- "effectiveTime": effective_time, "limitResultsByStatus": status_filter,
3825
- }
3826
- # body = body_slimmer(body)
3827
-
3828
- url = (f"{self.platform_url}/servers/{self.view_server}/api/open-metadata/glossary-browser/glossaries/"
3829
- f"terms/by-search-string?startFrom={start_from}&pageSize={page_size}&startsWith={starts_with_s}&"
3830
- f"endsWith={ends_with_s}&ignoreCase={ignore_case_s}&forLineage={for_lineage_s}&"
3831
- f"forDuplicateProcessing={for_duplicate_processing_s}")
3832
-
3833
- # print(f"\n\nURL is: \n {url}\n\nBody is: \n{body}")
3834
-
3835
- response = await self._async_make_request("POST", url, body)
3836
- return response.json().get("elementList", "No terms found")
3837
-
3838
-
3839
- if __name__ == "__main__":
3840
- print("Main-Glossary Browser")