pyegeria 5.4.0.26__py3-none-any.whl → 5.4.0.28__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 (46) hide show
  1. commands/cat/debug_log +868 -7794
  2. commands/cat/debug_log.2025-08-18_11-34-38_088636.zip +0 -0
  3. commands/cat/list_collections.py +1 -1
  4. commands/cat/list_format_set.py +6 -8
  5. commands/cli/egeria.py +2 -2
  6. commands/cli/egeria_cat.py +3 -2
  7. commands/ops/load_archive.py +2 -2
  8. md_processing/data/commands.json +7 -7
  9. md_processing/dr_egeria_inbox/dr_egeria_intro_part1.md +7 -7
  10. md_processing/dr_egeria_inbox/dr_egeria_intro_part2.md +36 -31
  11. md_processing/dr_egeria_outbox/friday/processed-2025-08-22 21:22-dr_egeria_intro_part1.md +312 -0
  12. md_processing/dr_egeria_outbox/friday/processed-2025-08-22 21:23-dr_egeria_intro_part1.md +265 -0
  13. md_processing/dr_egeria_outbox/friday/processed-2025-08-23 15:06-dr_egeria_intro_part1.md +230 -0
  14. md_processing/dr_egeria_outbox/friday/processed-2025-08-23 15:30-dr_egeria_intro_part1.md +296 -0
  15. md_processing/dr_egeria_outbox/friday/processed-2025-08-23 15:31-dr_egeria_intro_part1.md +253 -0
  16. md_processing/dr_egeria_outbox/friday/processed-2025-08-23 16:08-dr_egeria_intro_part2.md +343 -0
  17. md_processing/dr_egeria_outbox/friday/processed-2025-08-23 16:12-dr_egeria_intro_part2.md +343 -0
  18. md_processing/md_commands/glossary_commands.py +888 -951
  19. md_processing/md_commands/product_manager_commands.py +8 -270
  20. md_processing/md_commands/project_commands.py +1 -1
  21. md_processing/md_processing_utils/common_md_proc_utils.py +138 -64
  22. md_processing/md_processing_utils/common_md_utils.py +2 -1
  23. pyegeria/__init__.py +2 -3
  24. pyegeria/_client_new.py +4 -3
  25. pyegeria/_output_formats.py +5 -3
  26. pyegeria/collection_manager.py +32 -29
  27. pyegeria/{load_config.py → config.py} +7 -2
  28. pyegeria/data_designer.py +154 -194
  29. pyegeria/egeria_cat_client.py +46 -28
  30. pyegeria/egeria_client.py +71 -72
  31. pyegeria/egeria_config_client.py +37 -7
  32. pyegeria/egeria_my_client.py +45 -10
  33. pyegeria/egeria_tech_client.py +68 -57
  34. pyegeria/glossary_manager.py +495 -124
  35. pyegeria/governance_officer.py +2 -2
  36. pyegeria/logging_configuration.py +1 -4
  37. pyegeria/models.py +1 -1
  38. pyegeria/project_manager.py +359 -511
  39. pyegeria/utils.py +1 -3
  40. {pyegeria-5.4.0.26.dist-info → pyegeria-5.4.0.28.dist-info}/METADATA +1 -1
  41. {pyegeria-5.4.0.26.dist-info → pyegeria-5.4.0.28.dist-info}/RECORD +44 -38
  42. md_processing/md_processing_utils/solution_architect_log.log +0 -0
  43. pyegeria/glossary_browser.py +0 -1259
  44. {pyegeria-5.4.0.26.dist-info → pyegeria-5.4.0.28.dist-info}/LICENSE +0 -0
  45. {pyegeria-5.4.0.26.dist-info → pyegeria-5.4.0.28.dist-info}/WHEEL +0 -0
  46. {pyegeria-5.4.0.26.dist-info → pyegeria-5.4.0.28.dist-info}/entry_points.txt +0 -0
@@ -6,11 +6,24 @@ import json
6
6
  import os
7
7
  import re
8
8
  from typing import List, Optional
9
-
9
+ from loguru import logger
10
10
  from rich import print
11
11
  from rich.console import Console
12
12
  from rich.markdown import Markdown
13
13
 
14
+ from md_processing.md_processing_utils.common_md_proc_utils import (parse_upsert_command, parse_view_command,
15
+ sync_collection_memberships)
16
+ from md_processing.md_processing_utils.common_md_utils import update_element_dictionary, setup_log, set_update_body, \
17
+ set_element_status_request_body, set_prop_body, set_delete_request_body, set_rel_request_body, set_peer_gov_def_request_body, \
18
+ set_rel_request_body, set_create_body, set_collection_classifications, set_product_body
19
+
20
+ from md_processing.md_processing_utils.extraction_utils import (extract_command_plus, update_a_command)
21
+ from md_processing.md_processing_utils.md_processing_constants import (load_commands, ERROR)
22
+ from pyegeria import DEBUG_LEVEL, body_slimmer, to_pascal_case, PyegeriaException, print_basic_exception, print_exception_table
23
+ from pyegeria.egeria_tech_client import EgeriaTech
24
+
25
+
26
+
14
27
  from md_processing.md_processing_utils.common_md_utils import (debug_level, print_msg, set_debug_level,
15
28
  get_element_dictionary, update_element_dictionary,
16
29
  setup_log)
@@ -28,8 +41,8 @@ from pyegeria import body_slimmer
28
41
  from pyegeria._globals import (NO_GLOSSARIES_FOUND, NO_ELEMENTS_FOUND, NO_CATEGORIES_FOUND)
29
42
  from pyegeria.egeria_tech_client import EgeriaTech
30
43
 
31
- EGERIA_WIDTH = int(os.environ.get("EGERIA_WIDTH", "170"))
32
- console = Console(width=EGERIA_WIDTH)
44
+ # EGERIA_WIDTH = int(os.environ.get("EGERIA_WIDTH", "170"))
45
+ # console = Console(width=EGERIA_WIDTH)
33
46
  setup_log()
34
47
 
35
48
  def update_term_categories(egeria_client: EgeriaTech, term_guid: str, categories_exist: bool,
@@ -109,369 +122,364 @@ def process_glossary_upsert_command(egeria_client: EgeriaTech, txt: str, directi
109
122
 
110
123
  command, object_type, object_action = extract_command_plus(txt)
111
124
  print(Markdown(f"# {command}\n"))
112
- set_debug_level(directive)
113
-
114
- glossary_name = process_simple_attribute(txt, GLOSSARY_NAME_LABELS, ERROR)
115
- print(Markdown(
116
- f"{pre_command} `{object_action}` `{object_type}` for glossary: `\'{glossary_name}\'` with directive: `"
117
- f"{directive}` "))
118
- language = process_simple_attribute(txt, ['Language'], INFO)
119
- description = process_simple_attribute(txt, ['Description'], INFO)
120
- usage = process_simple_attribute(txt, ['Usage'], INFO)
121
- q_name = process_simple_attribute(txt, ['Qualified Name'], INFO)
122
- valid = True
123
-
124
- if glossary_name is None:
125
- valid = False
126
- known_q_name = None
127
- known_guid = None
128
- glossary_exists = False
129
- else:
130
- element_labels = GLOSSARY_NAME_LABELS
131
- element_labels.append('Display Name')
132
- known_q_name, known_guid, valid, glossary_exists = process_element_identifiers(egeria_client, object_type,
133
- element_labels, txt,
134
- object_action, None)
135
- glossary_display = (f"\n* Command: `{command}`\n\t* Glossary Name: {glossary_name}\n\t"
136
- f"* Language: {language}\n\t* Description:\n{description}\n"
137
- f"* Usage: {usage}\n")
138
-
139
- if object_action == 'Update':
140
- guid = process_simple_attribute(txt, ['GUID', 'guid', 'Guid'])
141
- glossary_display += f"* Qualified Name: `{q_name}`\n\t* GUID: {guid}\n\n"
142
- if not glossary_exists:
143
- msg = f"Glossary can't be updated; `{glossary_name}` not found"
144
- print_msg("ERROR", msg, debug_level)
145
- valid = False
146
- else:
147
- msg = f"Glossary can be updated; `{glossary_name}` found"
148
- print_msg(ALWAYS, msg, debug_level)
149
-
150
-
151
- elif object_action == "Create":
152
- if glossary_exists:
153
- msg = f"Glossary `{glossary_name}` can't be created because it already exists.\n"
154
- print_msg("ERROR", msg, debug_level)
155
- valid = False
156
- elif valid:
157
- msg = f"It is valid to create Glossary `{glossary_name}` with:\n"
158
- print_msg("ALWAYS", msg, debug_level)
159
-
160
- if directive == "display":
161
- print(Markdown(glossary_display))
162
- return None
163
-
164
- elif directive == "validate":
165
- if valid:
166
- print(Markdown(glossary_display))
167
- else:
168
- msg = f"Validation failed for Glossary `{glossary_name}`\n"
169
- print_msg(ERROR, msg, debug_level)
170
- print(Markdown(glossary_display))
171
-
172
- return valid
173
125
 
174
- elif directive == "process":
175
- if valid:
176
- print(Markdown(glossary_display))
177
- else:
178
- if glossary_exists and object_action == "Create":
179
- msg = (f"Create failed because glossary `{glossary_name}` exists - changing `Create` to `Update` in "
180
- f"processed output \n")
181
- print_msg(ERROR, msg, debug_level)
182
- print(Markdown(glossary_display))
183
- print(command_seperator)
184
- return update_a_command(txt, object_action, object_type, known_q_name, known_guid)
185
- else:
186
- return None
187
- if object_action == "Update":
188
- if not glossary_exists:
189
- print(f"\n{ERROR}Glossary `{glossary_name}` does not exist! Updating result document with Create "
190
- f"object_action\n")
191
- return update_a_command(txt, object_action, object_type, known_q_name, known_guid)
192
-
193
- body = {
194
- "class": "ReferenceableRequestBody", "elementProperties": {
195
- "class": "GlossaryProperties", "qualifiedName": known_q_name, "description": description,
196
- "language": language, "usage": usage
197
- }
198
- }
199
- egeria_client.update_glossary(known_guid, body)
200
- print_msg(ALWAYS, f"Updated Glossary `{glossary_name}` with GUID {known_guid}", debug_level)
201
- update_element_dictionary(known_q_name, {
202
- 'guid': known_guid, 'display_name': glossary_name
203
- })
204
- return egeria_client.get_glossary_by_guid(known_guid, output_format='MD')
205
- elif object_action == "Create":
206
- glossary_guid = None
207
-
208
- if glossary_exists:
209
- print(f"\nGlossary `{glossary_name}` already exists and result document updated\n")
210
- return update_a_command(txt, object_action, object_type, known_q_name, known_guid)
211
- else:
212
- glossary_guid = egeria_client.create_glossary(glossary_name, description, language, usage)
213
- glossary = egeria_client.get_glossary_by_guid(glossary_guid)
214
- if glossary == NO_GLOSSARIES_FOUND:
215
- print(f"{ERROR}Just created with GUID {glossary_guid} but Glossary not found\n")
216
- return None
217
- qualified_name = glossary['glossaryProperties']["qualifiedName"]
218
- update_element_dictionary(qualified_name, {
219
- 'guid': glossary_guid, 'display_name': glossary_name
220
- })
221
- # return update_a_command(txt, object_action, object_type, qualified_name, glossary_guid)
222
- print_msg(ALWAYS, f"Created Glossary `{glossary_name}` with GUID {glossary_guid}", debug_level)
223
- return egeria_client.get_glossary_by_guid(glossary_guid, output_format='FORM')
224
- else:
225
- return None
226
- else:
126
+ parsed_output = parse_upsert_command(egeria_client, object_type, object_action, txt, directive)
127
+ if not parsed_output:
128
+ logger.error(f"No output for `{object_action}`")
227
129
  return None
228
130
 
131
+ valid = parsed_output['valid']
132
+ exists = parsed_output['exists']
229
133
 
230
- def process_category_upsert_command(egeria_client: EgeriaTech, txt: str, directive: str = "display") -> Optional[str]:
231
- """
232
- Processes a glossary category create or update object_action by extracting key attributes such as
233
- category name, qualified, description, and anchor glossary from the given txt..
234
-
235
- :param txt: A string representing the input cell to be processed for
236
- extracting category-related attributes.
237
- :param directive: an optional string indicating the directive to be used - display, validate or execute
238
- :return: A string summarizing the outcome of the processing.
239
- """
240
- valid = True
241
- set_debug_level(directive)
242
-
243
- command, object_type, object_action = extract_command_plus(txt)
244
- print(Markdown(f"# {command}\n"))
245
-
246
- category_name = process_simple_attribute(txt, ['Category Name', 'category_name', 'Cat'])
247
- print(Markdown(f"{pre_command} `{command}` for category: `\'{category_name}\'` with directive: `{directive}` "))
248
-
249
- owning_glossary_name = extract_attribute(txt, ['Owning Glossary', 'In Glossary'])
250
- description = process_simple_attribute(txt, ['Description'])
251
- q_name = process_simple_attribute(txt, ['Qualified Name'])
134
+ qualified_name = parsed_output.get('qualified_name', None)
135
+ guid = parsed_output.get('guid', None)
252
136
 
253
- parent_category_name = process_simple_attribute(txt, PARENT_CATEGORY_LABELS, "INFO")
137
+ print(Markdown(parsed_output['display']))
254
138
 
255
- element_labels = CATEGORY_NAME_LABELS
256
- element_labels.append('Display Name')
257
- # Check if category exists (and get qname and guid)
258
- if category_name is None:
259
- valid = False
260
- known_q_name, known_guid, category_exists = None
261
- else:
262
- element_labels = CATEGORY_NAME_LABELS
263
- element_labels.append('Display Name')
264
- known_q_name, known_guid, valid, category_exists = process_element_identifiers(egeria_client, object_type,
265
- element_labels, txt,
266
- object_action, None)
267
-
268
- # Check if owning glossary exists (and get qname)
269
- if owning_glossary_name is None:
270
- valid = False
271
- known_glossary_q_name, known_glossary__guid, glossary_exists = None
139
+ logger.debug(json.dumps(parsed_output, indent=4))
272
140
 
273
- else:
274
- known_glossary_q_name, known_glossary_guid, valid, owning_glossary_exists = process_element_identifiers(
275
- egeria_client, "Glossary", GLOSSARY_NAME_LABELS, txt, EXISTS_REQUIRED, None)
141
+ attributes = parsed_output['attributes']
276
142
 
277
- if parent_category_name:
278
- _, parent_guid, parent_valid, parent_exists = get_element_by_name(egeria_client, 'Glossary Categories',
279
- parent_category_name)
280
- else:
281
- parent_guid = None
282
- parent_exists = False
283
- parent_valid = False
284
-
285
- category_display = (
286
- f"\n* Command: {command}\n\t* Category: {category_name}\n\t* In Glossary: {owning_glossary_name}\n\t"
287
- f"* Description:\n{description}\n\t* Parent Category: {parent_category_name}\n\t"
288
- f"* Qualified Name: {q_name}\n\t")
289
-
290
- if object_action == 'Update':
291
- guid = process_simple_attribute(txt, ['GUID', 'guid', 'Guid'])
292
-
293
- category_display += (f"* GUID: {guid}\n\n")
294
- if not category_exists:
295
- msg = f"Category {category_name} can't be updated; {category_name} not found."
296
- print_msg(ERROR, msg, debug_level)
297
- valid = False
298
- else:
299
- msg = f"Glossary can be updated; {category_name} found"
300
- print_msg(ALWAYS, msg, debug_level)
301
-
302
- elif object_action == "Create":
303
- if category_exists:
304
- msg = f"Category {category_name} can't be created because it already exists.\n"
305
- print_msg("ERROR", msg, debug_level)
306
- valid = False
307
- elif valid:
308
- msg = f"It is valid to create Category `{category_name}` with:\n"
309
- print_msg("ALWAYS", msg, debug_level)
143
+ display_name = attributes['Display Name'].get('value', None)
144
+ status = attributes.get('Status', {}).get('value', None)
145
+ #
310
146
 
311
147
  if directive == "display":
312
- print(Markdown(category_display))
313
148
  return None
314
-
315
149
  elif directive == "validate":
316
150
  if valid:
317
- print(Markdown(category_display))
151
+ print(Markdown(f"==> Validation of {command} completed successfully!\n"))
318
152
  else:
319
- msg = f"Validation failed for {object_type} `{category_name}`\n"
320
- print_msg(ERROR, msg, debug_level)
321
- print(Markdown(category_display))
153
+ msg = f"Validation failed for object_action `{command}`\n"
322
154
  return valid
323
155
 
324
156
  elif directive == "process":
325
- if valid:
326
- print(Markdown(category_display))
327
- else:
328
- if category_exists and object_action == "Create":
329
- msg = (f"Create failed because category `{category_name}` exists - changing `Create` to `Update` in "
330
- f"processed output \n")
331
- print_msg(ERROR, msg, debug_level)
332
- print(Markdown(category_display))
333
- return update_a_command(txt, object_action, object_type, known_q_name, known_guid)
334
- else:
335
- return None
336
-
337
- if object_action == "Update":
338
- if not category_exists:
339
- print(f"\n{ERROR}category `{category_name}` does not exist! Updating result document with Create "
340
- f"object_action\n")
341
- return update_a_command(txt, object_action, object_type, known_q_name, known_guid)
342
-
343
- # Update the basic category properties
344
- egeria_client.update_category(known_guid, category_name, description, known_q_name, None)
345
- msg = f"->Updated category `{category_name}`with GUID {known_guid}"
346
- print_msg(ALWAYS, msg, debug_level)
347
-
348
- # Update parent-child relationships
349
-
350
- update_element_dictionary(known_q_name, {
351
- 'guid': known_guid, 'display_name': category_name
352
- })
353
-
354
- category_sync = update_category_parent(egeria_client, known_guid, parent_category_name)
355
- print_msg(ALWAYS, f"Updated Category hierarchy for `{category_name}` with outcome {category_sync}",
356
- debug_level)
357
- return egeria_client.get_category_by_guid(known_guid, output_format='FORM')
358
-
359
- elif object_action == "Create":
360
- is_root = True
361
-
362
- if category_exists:
363
- msg = (f"Cannot create`{category_name}` because it already exists; result document written for "
364
- f"category update\n")
365
- print_msg(WARNING, msg, debug_level)
366
- return update_a_command(txt, object_action, object_type, known_q_name, known_guid)
367
- else:
368
- category_guid = egeria_client.create_category(known_glossary_guid, category_name, description, is_root)
369
- category_details = egeria_client.get_category_by_guid(category_guid)
370
-
371
- if category_details == NO_CATEGORIES_FOUND:
372
- msg = f"Just created category with GUID {category_guid} but category not found"
373
- print_msg(ERROR, msg, debug_level)
157
+ try:
158
+ obj = "Glossary"
159
+ # Set the property body for a glossary collection
160
+ #
161
+ prop_body = set_prop_body(obj, qualified_name, attributes)
162
+ prop_body["languager"] = attributes.get('Language', {}).get('value', None)
163
+ prop_body["usage"] = attributes.get('Usage', {}).get('value', None)
164
+
165
+ if object_action == "Update":
166
+ if not exists:
167
+ msg = (f" Element `{display_name}` does not exist! Updating result document with Create "
168
+ f"{object_action}\n")
169
+ logger.error(msg)
170
+ return update_a_command(txt, object_action, object_type, qualified_name, guid)
171
+ elif not valid:
374
172
  return None
375
-
376
- qualified_name = category_details['glossaryCategoryProperties']["qualifiedName"]
377
- update_element_dictionary(qualified_name, {
378
- 'guid': category_guid, 'display_name': category_name
379
- })
380
- print_msg(ALWAYS, f"Created Category `{category_name}` with GUID {category_guid}", debug_level)
381
- if parent_valid and parent_guid:
382
- egeria_client.set_parent_category(parent_guid, category_guid)
383
- print_msg(ALWAYS, f"Set parent category for `{category_name}` to `{parent_category_name}`",
384
- debug_level)
385
173
  else:
386
- print_msg(ERROR,
387
- f"Parent category `{parent_category_name}` not found or invalid for `{category_name}`",
388
- debug_level)
389
- return egeria_client.get_category_by_guid(category_guid, output_format='FORM')
390
- return None
391
- return None
174
+ print(Markdown(
175
+ f"==> Validation of {command} completed successfully! Proceeding to apply the changes.\n"))
392
176
 
393
177
 
394
- def update_category_parent(egeria_client, category_guid: str, parent_category_name: str = None) -> bool:
395
- """
396
- Updates the parent relationship for a category.
178
+ body = set_update_body(obj, attributes)
179
+ body['properties'] = prop_body
397
180
 
398
- If a parent category is specified, it will check if a parent is currently set.
399
- If a parent category was set and is the same as the parent category specified, no change is needed.
400
- If a parent category was set and is different from the parent_category_name, the parent category is updated.
401
- If parent_category_name is None or empty and an existing parent category was set, the parent category is removed.
181
+ egeria_client.update_collection(guid, body)
182
+ if status:
183
+ egeria_client.update_collection_status(guid, status)
402
184
 
403
- Parameters
404
- ----------
405
- egeria_client: EgeriaTech
406
- The Egeria client to use for API calls
407
- category_guid: str
408
- The GUID of the category to update
409
- parent_category_name: str, optional
410
- The name of the parent category to set, or None to remove the parent
185
+ logger.success(f"Updated {object_type} `{display_name}` with GUID {guid}\n\n___")
186
+ update_element_dictionary(qualified_name, {
187
+ 'guid': guid, 'display_name': display_name
188
+ })
189
+ return egeria_client.get_collection_by_guid(guid, element_type='Glossary',
190
+ output_format='MD', output_format_set = "DrE-Glossary")
411
191
 
412
- Returns
413
- -------
414
192
 
415
- True if successful, False otherwise.
193
+ elif object_action == "Create":
194
+ if valid is False and exists:
195
+ msg = (f" Digital Product `{display_name}` already exists and result document updated changing "
196
+ f"`Create` to `Update` in processed output\n\n___")
197
+ logger.error(msg)
198
+ return update_a_command(txt, object_action, object_type, qualified_name, guid)
416
199
 
417
- """
418
- outcome = True
419
- # Handle parent category updates
420
- if parent_category_name:
421
- # Check if a parent is currently set
422
- current_parent = egeria_client.get_category_parent(category_guid)
423
-
424
- if isinstance(current_parent, str) and "No Parent Category found" in current_parent:
425
- # No parent currently set, need to set it
426
- _, parent_guid, _, parent_exists = get_element_by_name(egeria_client, 'Glossary Categories',
427
- parent_category_name)
428
-
429
- if parent_exists and parent_guid:
430
- egeria_client.set_parent_category(parent_guid, category_guid)
431
- print_msg(ALWAYS, f"Set parent category of category to `{parent_category_name}`", debug_level)
432
- else:
433
- print_msg(ERROR, f"Parent category `{parent_category_name}` not found", debug_level)
434
- outcome = False
435
- else:
436
- # Parent is set, check if it's the same
437
- current_parent_name = current_parent.get('glossaryCategoryProperties', {}).get('qualifiedName', '')
438
-
439
- if current_parent_name != parent_category_name:
440
- # Different parent, need to update
441
- # First remove the current parent
442
- current_parent_guid = current_parent.get('elementHeader', {}).get('guid', '')
443
- if current_parent_guid:
444
- egeria_client.remove_parent_category(current_parent_guid, category_guid)
445
-
446
- # Then set the new parent
447
- _, parent_guid, _, parent_exists = get_element_by_name(egeria_client, 'Glossary Categories',
448
- parent_category_name)
449
-
450
- if parent_exists and parent_guid:
451
- egeria_client.set_parent_category(parent_guid, category_guid)
452
- print_msg(ALWAYS,
453
- f"Updated parent category from `{current_parent_name}` to `{parent_category_name}`",
454
- debug_level)
455
200
  else:
456
- print_msg(ERROR, f"Parent category `{parent_category_name}` not found", debug_level)
457
- outcome = False
458
- elif parent_category_name is None or parent_category_name == '':
459
- # Check if a parent is currently set and remove it if needed
460
- current_parent = egeria_client.get_category_parent(category_guid)
201
+ body = set_create_body(object_type,attributes)
202
+
203
+ # if this is a root or folder (maybe more in the future), then make sure that the classification is set.
204
+ body["initialClassifications"] = set_collection_classifications(object_type, attributes, ["Taxonomy", "CanonicalVocabulary"])
205
+ if object_type == "Taxonomy":
206
+ body["initialClassifications"]['Taxonomy']['organizingPrinciple'] = attributes.get('Organizing Principle', {}).get('value', None)
207
+ elif object_type == "CanonicalVocabulary":
208
+ body["initialClassifications"]['CanonicalVocabulary']['usage'] = attributes.get('Usage', {}).get('value', None)
209
+
210
+ body["properties"] = prop_body
211
+
212
+ guid = egeria_client.create_collection(body = body)
213
+ if guid:
214
+ update_element_dictionary(qualified_name, {
215
+ 'guid': guid, 'display_name': display_name
216
+ })
217
+ msg = f"Created Element `{display_name}` with GUID {guid}\n\n___"
218
+ logger.success(msg)
219
+ return egeria_client.get_collection_by_guid(guid, obj, output_format='MD')
220
+ else:
221
+ msg = f"Failed to create element `{display_name}` with GUID {guid}\n\n___"
222
+ logger.error(msg)
223
+ return None
461
224
 
462
- if not isinstance(current_parent, str) or "No Parent Category found" not in current_parent:
463
- # Parent is set, need to remove it
464
- current_parent_guid = current_parent.get('elementHeader', {}).get('guid', '')
465
- current_parent_name = current_parent.get('glossaryCategoryProperties', {}).get('qualifiedName', '')
225
+ except PyegeriaException as e:
226
+ logger.error(f"Pyegeria error performing {command}: {e}")
227
+ print_basic_exception(e)
228
+ return None
229
+ except Exception as e:
230
+ logger.error(f"Error performing {command}: {e}")
231
+ else:
232
+ return None
466
233
 
467
- if current_parent_guid:
468
- egeria_client.remove_parent_category(current_parent_guid, category_guid)
469
- print_msg(ALWAYS, f"Removed parent category `{current_parent_name}`", debug_level)
470
234
 
471
- return outcome
235
+ def process_category_upsert_command(egeria_client: EgeriaTech, txt: str, directive: str = "display") -> Optional[str]:
236
+ pass
237
+ # """
238
+ # Processes a glossary category create or update object_action by extracting key attributes such as
239
+ # category name, qualified, description, and anchor glossary from the given txt..
240
+ #
241
+ # :param txt: A string representing the input cell to be processed for
242
+ # extracting category-related attributes.
243
+ # :param directive: an optional string indicating the directive to be used - display, validate or execute
244
+ # :return: A string summarizing the outcome of the processing.
245
+ # """
246
+ # valid = True
247
+ # set_debug_level(directive)
248
+ #
249
+ # command, object_type, object_action = extract_command_plus(txt)
250
+ # print(Markdown(f"# {command}\n"))
251
+ #
252
+ # category_name = process_simple_attribute(txt, ['Category Name', 'category_name', 'Cat'])
253
+ # print(Markdown(f"{pre_command} `{command}` for category: `\'{category_name}\'` with directive: `{directive}` "))
254
+ #
255
+ # owning_glossary_name = extract_attribute(txt, ['Owning Glossary', 'In Glossary'])
256
+ # description = process_simple_attribute(txt, ['Description'])
257
+ # q_name = process_simple_attribute(txt, ['Qualified Name'])
258
+ #
259
+ # parent_category_name = process_simple_attribute(txt, PARENT_CATEGORY_LABELS, "INFO")
260
+ #
261
+ # element_labels = CATEGORY_NAME_LABELS
262
+ # element_labels.append('Display Name')
263
+ # # Check if category exists (and get qname and guid)
264
+ # if category_name is None:
265
+ # valid = False
266
+ # known_q_name, known_guid, category_exists = None
267
+ # else:
268
+ # element_labels = CATEGORY_NAME_LABELS
269
+ # element_labels.append('Display Name')
270
+ # known_q_name, known_guid, valid, category_exists = process_element_identifiers(egeria_client, object_type,
271
+ # element_labels, txt,
272
+ # object_action, None)
273
+ #
274
+ # # Check if owning glossary exists (and get qname)
275
+ # if owning_glossary_name is None:
276
+ # valid = False
277
+ # known_glossary_q_name, known_glossary__guid, glossary_exists = None
278
+ #
279
+ # else:
280
+ # known_glossary_q_name, known_glossary_guid, valid, owning_glossary_exists = process_element_identifiers(
281
+ # egeria_client, "Glossary", GLOSSARY_NAME_LABELS, txt, EXISTS_REQUIRED, None)
282
+ #
283
+ # if parent_category_name:
284
+ # _, parent_guid, parent_valid, parent_exists = get_element_by_name(egeria_client, 'Glossary Categories',
285
+ # parent_category_name)
286
+ # else:
287
+ # parent_guid = None
288
+ # parent_exists = False
289
+ # parent_valid = False
290
+ #
291
+ # category_display = (
292
+ # f"\n* Command: {command}\n\t* Category: {category_name}\n\t* In Glossary: {owning_glossary_name}\n\t"
293
+ # f"* Description:\n{description}\n\t* Parent Category: {parent_category_name}\n\t"
294
+ # f"* Qualified Name: {q_name}\n\t")
295
+ #
296
+ # if object_action == 'Update':
297
+ # guid = process_simple_attribute(txt, ['GUID', 'guid', 'Guid'])
298
+ #
299
+ # category_display += (f"* GUID: {guid}\n\n")
300
+ # if not category_exists:
301
+ # msg = f"Category {category_name} can't be updated; {category_name} not found."
302
+ # print_msg(ERROR, msg, debug_level)
303
+ # valid = False
304
+ # else:
305
+ # msg = f"Glossary can be updated; {category_name} found"
306
+ # print_msg(ALWAYS, msg, debug_level)
307
+ #
308
+ # elif object_action == "Create":
309
+ # if category_exists:
310
+ # msg = f"Category {category_name} can't be created because it already exists.\n"
311
+ # print_msg("ERROR", msg, debug_level)
312
+ # valid = False
313
+ # elif valid:
314
+ # msg = f"It is valid to create Category `{category_name}` with:\n"
315
+ # print_msg("ALWAYS", msg, debug_level)
316
+ #
317
+ # if directive == "display":
318
+ # print(Markdown(category_display))
319
+ # return None
320
+ #
321
+ # elif directive == "validate":
322
+ # if valid:
323
+ # print(Markdown(category_display))
324
+ # else:
325
+ # msg = f"Validation failed for {object_type} `{category_name}`\n"
326
+ # print_msg(ERROR, msg, debug_level)
327
+ # print(Markdown(category_display))
328
+ # return valid
329
+ #
330
+ # elif directive == "process":
331
+ # if valid:
332
+ # print(Markdown(category_display))
333
+ # else:
334
+ # if category_exists and object_action == "Create":
335
+ # msg = (f"Create failed because category `{category_name}` exists - changing `Create` to `Update` in "
336
+ # f"processed output \n")
337
+ # print_msg(ERROR, msg, debug_level)
338
+ # print(Markdown(category_display))
339
+ # return update_a_command(txt, object_action, object_type, known_q_name, known_guid)
340
+ # else:
341
+ # return None
342
+ #
343
+ # if object_action == "Update":
344
+ # if not category_exists:
345
+ # print(f"\n{ERROR}category `{category_name}` does not exist! Updating result document with Create "
346
+ # f"object_action\n")
347
+ # return update_a_command(txt, object_action, object_type, known_q_name, known_guid)
348
+ #
349
+ # # Update the basic category properties
350
+ # egeria_client.update_category(known_guid, category_name, description, known_q_name, None)
351
+ # msg = f"->Updated category `{category_name}`with GUID {known_guid}"
352
+ # print_msg(ALWAYS, msg, debug_level)
353
+ #
354
+ # # Update parent-child relationships
355
+ #
356
+ # update_element_dictionary(known_q_name, {
357
+ # 'guid': known_guid, 'display_name': category_name
358
+ # })
359
+ #
360
+ # category_sync = update_category_parent(egeria_client, known_guid, parent_category_name)
361
+ # print_msg(ALWAYS, f"Updated Category hierarchy for `{category_name}` with outcome {category_sync}",
362
+ # debug_level)
363
+ # return egeria_client.get_category_by_guid(known_guid, output_format='FORM')
364
+ #
365
+ # elif object_action == "Create":
366
+ # is_root = True
367
+ #
368
+ # if category_exists:
369
+ # msg = (f"Cannot create`{category_name}` because it already exists; result document written for "
370
+ # f"category update\n")
371
+ # print_msg(WARNING, msg, debug_level)
372
+ # return update_a_command(txt, object_action, object_type, known_q_name, known_guid)
373
+ # else:
374
+ # category_guid = egeria_client.create_category(known_glossary_guid, category_name, description, is_root)
375
+ # category_details = egeria_client.get_category_by_guid(category_guid)
376
+ #
377
+ # if category_details == NO_CATEGORIES_FOUND:
378
+ # msg = f"Just created category with GUID {category_guid} but category not found"
379
+ # print_msg(ERROR, msg, debug_level)
380
+ # return None
381
+ #
382
+ # qualified_name = category_details['glossaryCategoryProperties']["qualifiedName"]
383
+ # update_element_dictionary(qualified_name, {
384
+ # 'guid': category_guid, 'display_name': category_name
385
+ # })
386
+ # print_msg(ALWAYS, f"Created Category `{category_name}` with GUID {category_guid}", debug_level)
387
+ # if parent_valid and parent_guid:
388
+ # egeria_client.set_parent_category(parent_guid, category_guid)
389
+ # print_msg(ALWAYS, f"Set parent category for `{category_name}` to `{parent_category_name}`",
390
+ # debug_level)
391
+ # else:
392
+ # print_msg(ERROR,
393
+ # f"Parent category `{parent_category_name}` not found or invalid for `{category_name}`",
394
+ # debug_level)
395
+ # return egeria_client.get_category_by_guid(category_guid, output_format='FORM')
396
+ # return None
397
+ # return None
398
+ #
399
+ #
400
+ def update_category_parent(egeria_client, category_guid: str, parent_category_name: str = None) -> bool:
401
+ pass
402
+ # """
403
+ # Updates the parent relationship for a category.
404
+ #
405
+ # If a parent category is specified, it will check if a parent is currently set.
406
+ # If a parent category was set and is the same as the parent category specified, no change is needed.
407
+ # If a parent category was set and is different from the parent_category_name, the parent category is updated.
408
+ # If parent_category_name is None or empty and an existing parent category was set, the parent category is removed.
409
+ #
410
+ # Parameters
411
+ # ----------
412
+ # egeria_client: EgeriaTech
413
+ # The Egeria client to use for API calls
414
+ # category_guid: str
415
+ # The GUID of the category to update
416
+ # parent_category_name: str, optional
417
+ # The name of the parent category to set, or None to remove the parent
418
+ #
419
+ # Returns
420
+ # -------
421
+ #
422
+ # True if successful, False otherwise.
423
+ #
424
+ # """
425
+ # outcome = True
426
+ # # Handle parent category updates
427
+ # if parent_category_name:
428
+ # # Check if a parent is currently set
429
+ # current_parent = egeria_client.get_category_parent(category_guid)
430
+ #
431
+ # if isinstance(current_parent, str) and "No Parent Category found" in current_parent:
432
+ # # No parent currently set, need to set it
433
+ # _, parent_guid, _, parent_exists = get_element_by_name(egeria_client, 'Glossary Categories',
434
+ # parent_category_name)
435
+ #
436
+ # if parent_exists and parent_guid:
437
+ # egeria_client.set_parent_category(parent_guid, category_guid)
438
+ # print_msg(ALWAYS, f"Set parent category of category to `{parent_category_name}`", debug_level)
439
+ # else:
440
+ # print_msg(ERROR, f"Parent category `{parent_category_name}` not found", debug_level)
441
+ # outcome = False
442
+ # else:
443
+ # # Parent is set, check if it's the same
444
+ # current_parent_name = current_parent.get('glossaryCategoryProperties', {}).get('qualifiedName', '')
445
+ #
446
+ # if current_parent_name != parent_category_name:
447
+ # # Different parent, need to update
448
+ # # First remove the current parent
449
+ # current_parent_guid = current_parent.get('elementHeader', {}).get('guid', '')
450
+ # if current_parent_guid:
451
+ # egeria_client.remove_parent_category(current_parent_guid, category_guid)
452
+ #
453
+ # # Then set the new parent
454
+ # _, parent_guid, _, parent_exists = get_element_by_name(egeria_client, 'Glossary Categories',
455
+ # parent_category_name)
456
+ #
457
+ # if parent_exists and parent_guid:
458
+ # egeria_client.set_parent_category(parent_guid, category_guid)
459
+ # print_msg(ALWAYS,
460
+ # f"Updated parent category from `{current_parent_name}` to `{parent_category_name}`",
461
+ # debug_level)
462
+ # else:
463
+ # print_msg(ERROR, f"Parent category `{parent_category_name}` not found", debug_level)
464
+ # outcome = False
465
+ # elif parent_category_name is None or parent_category_name == '':
466
+ # # Check if a parent is currently set and remove it if needed
467
+ # current_parent = egeria_client.get_category_parent(category_guid)
468
+ #
469
+ # if not isinstance(current_parent, str) or "No Parent Category found" not in current_parent:
470
+ # # Parent is set, need to remove it
471
+ # current_parent_guid = current_parent.get('elementHeader', {}).get('guid', '')
472
+ # current_parent_name = current_parent.get('glossaryCategoryProperties', {}).get('qualifiedName', '')
473
+ #
474
+ # if current_parent_guid:
475
+ # egeria_client.remove_parent_category(current_parent_guid, category_guid)
476
+ # print_msg(ALWAYS, f"Removed parent category `{current_parent_name}`", debug_level)
477
+ #
478
+ # return outcome
472
479
 
473
480
 
474
481
  def process_term_upsert_command(egeria_client: EgeriaTech, txt: str, directive: str = "display") -> Optional[str]:
482
+ pass
475
483
  """
476
484
  Processes a term create or update object_action by extracting key attributes such as
477
485
  term name, summary, description, abbreviation, examples, usage, version, and status from the given cell.
@@ -481,651 +489,580 @@ def process_term_upsert_command(egeria_client: EgeriaTech, txt: str, directive:
481
489
  :param directive: an optional string indicating the directive to be used - display, validate or execute
482
490
  :return: A string summarizing the outcome of the processing.
483
491
  """
484
- valid = True
485
- categories_list = None
486
- cats_exist = False
487
- set_debug_level(directive)
488
- known_q_name = None
489
- command = extract_command(txt)
490
- print(Markdown(f"# {command}\n"))
491
-
492
- object_type = command.split(' ')[1].strip()
493
- object_action = command.split(' ')[0].strip()
494
-
495
- term_name = process_simple_attribute(txt, ['Term Name', 'Display Name'], ERROR)
496
- print(Markdown(f"{pre_command} `{command}` for term:`{term_name}` with directive: `{directive}`"))
497
- summary = process_simple_attribute(txt, ['Summary'], INFO)
498
- description = process_simple_attribute(txt, ['Description'], INFO)
499
- abbreviation = process_simple_attribute(txt, ['Abbreviation'], INFO)
500
- examples = process_simple_attribute(txt, ['Examples'], INFO)
501
- usage = process_simple_attribute(txt, ['Usage'], INFO)
502
- status = process_simple_attribute(txt, ['Status'])
503
- status = status.upper() if status else 'DRAFT'
504
- version = process_simple_attribute(txt, ['Version', "Version Identifier", "Published Version"], INFO)
505
- q_name = process_simple_attribute(txt, ['Qualified Name'], INFO)
506
-
507
- aliases = process_simple_attribute(txt, ['Aliases', 'Alias'], INFO)
508
- if aliases:
509
- alias_list = list(filter(None, re.split(r'[,\n]+', aliases.strip())))
510
- else:
511
- alias_list = None
512
-
513
- # validate term name and get existing qualified_name and guid if they exist
514
- if term_name is None:
515
- valid = False
516
- known_q_name, known_guid, term_exists = None
517
- else:
518
- element_labels = TERM_NAME_LABELS
519
- element_labels.append('Display Name')
520
- known_q_name, known_guid, valid, term_exists = process_element_identifiers(egeria_client, object_type,
521
- element_labels, txt, object_action,
522
- version)
523
-
524
- # get the glossary qualified name this term is in
525
- glossary_name = process_simple_attribute(txt, GLOSSARY_NAME_LABELS, ERROR)
526
- if glossary_name is None:
527
- valid = False
528
- known_glossary_guid = None
529
- known_glossary_q_name = None
530
- glossary_valid = False
531
- glossary_exists = False
532
- else:
533
- known_glossary_q_name, known_glossary_guid, glossary_valid, glossary_exists = process_element_identifiers(
534
- egeria_client, "Glossary", GLOSSARY_NAME_LABELS, txt, EXISTS_REQUIRED, None)
535
- if not glossary_exists or known_glossary_guid is None:
536
- glossary_valid = False
537
- valid = False
538
-
539
- # process categories, if present
540
- categories = process_simple_attribute(txt, ['Glossary Categories', 'Glossary Category', 'Category', 'Categories'])
541
- if categories: # Find information about categoriess that classify this term
542
- msg = "Checking for categories that classify this term"
543
- print_msg("DEBUG-INFO", msg, debug_level)
544
- categories_list, cat_q_name_list, cats_valid, cats_exist = process_name_list(egeria_client,
545
- 'Glossary Categories', txt,
546
- CATEGORY_NAME_LABELS)
547
- if cats_exist and cats_valid:
548
- msg = f"Found valid glossary categories to classify the term:\n\t{term_name}"
549
- print_msg("INFO", msg, debug_level)
550
- else:
551
- msg = "No valid glossary categories found."
552
- print_msg("INFO", msg, debug_level)
553
- else:
554
- cats_exist = cats_valid = False
555
- cat_q_name_list = None
556
-
557
- if object_action == "Update": # check to see if provided information exists and is consistent with existing info
558
- term_guid = process_simple_attribute(txt, GUID_LABELS)
559
- update_description = process_simple_attribute(txt, ['Update Description'])
560
- term_display = (f"\n* Command: {command}\n\t* Glossary: {known_glossary_q_name}\n\t"
561
- f"* Term Name: {term_name}\n\t* Qualified Name: {q_name}\n\t* Aliases: {aliases}\n\t"
562
- f"* Categories: {categories}\n\t"
563
- f"* Summary: {summary}\n\t* Description: {description}\n\t"
564
- f"* Abbreviation: {abbreviation}\n\t* Examples: {examples}\n\t* Usage: {usage}\n\t"
565
- f"* Version: {version}\n\t* Status: {status}\n\t* GUID: {term_guid}"
566
- f"\n\t* Update Description: {update_description}\n")
567
- if not term_exists:
568
- msg = f"Update request invalid, Term {term_name} does not exist\n"
569
- print_msg(ERROR, msg, debug_level)
570
- valid = False
571
-
572
- elif object_action == 'Create': # if the object_action is create, check that it doesn't already exist
573
- term_display = (f"\n* Command: {command}\n\t* Glossary: {known_glossary_q_name}\n\t"
574
- f"* Term Name: {term_name}\n\t* Categories: {categories}\n\t* Summary: {summary}\n\t"
575
- f"* Qualified Name: {q_name}\n\t* Aliases: {aliases}\n\t* Description: {description}\n\t"
576
- f"* Abbreviation: {abbreviation}\n\t* Examples: {examples}\n\t* Usage: {usage}\n\t"
577
- f"* Version: {version}\n\t* Status: {status}\n")
578
- if term_exists:
579
- msg = f"Term `{term_name}` cannot be created since it already exists\n"
580
- print_msg(ERROR, msg, debug_level)
581
- else:
582
- msg = f"It is valid to create Term `{term_name}`"
583
- print_msg(ALWAYS, msg, debug_level)
584
-
585
- if directive == "display":
586
- print(Markdown(term_display))
587
- return None
588
- elif directive == "validate":
589
- print(Markdown(term_display))
590
- return valid
591
- elif directive == "process":
592
- try:
593
- if not valid: # First validate the term before we process it
594
- if term_exists and object_action == "Create":
595
- msg = (f"Create failed because term `{term_name}` exists - changing `Create` to `Update` in "
596
- f"processed output \n")
597
- print_msg(ERROR, msg, debug_level)
598
- print(Markdown(term_display))
599
- return update_a_command(txt, object_action, object_type, known_q_name, known_guid)
600
- else:
601
- return None
602
-
603
- print(Markdown(term_display))
604
- if object_action == "Update" and directive == "process":
605
- if not term_exists:
606
- return None
607
- body = {
608
- "class": "ReferenceableRequestBody", "elementProperties": {
609
- "displayName": term_name, "class": "GlossaryTermProperties", "qualifiedName": known_q_name,
610
- "aliases": alias_list, "summary": summary, "description": description,
611
- "abbreviation": abbreviation, "examples": examples, "usage": usage,
612
- "publishVersionIdentifier": version, "status": status
613
- }, "updateDescription": update_description
614
- }
615
- egeria_client.update_term(known_guid, body_slimmer(body), is_merge_update=False)
616
- # if cat_exist and cat_valid:
617
- update_term_categories(egeria_client, known_guid, cats_exist, cat_q_name_list)
618
- print_msg(ALWAYS,
619
- f"\tUpdated Term `{term_name}` with GUID {known_guid}\n\tand categories `{categories}`",
620
- debug_level)
621
- return egeria_client.get_term_by_guid(known_guid,
622
- 'md') # return update_a_command(txt, object_action, object_type,
623
- # known_q_name, known_guid)
624
- elif object_action == "Update" and directive == "validate": # is sthis reachable?
625
- return egeria_client.get_term_by_guid(known_guid, 'md')
626
-
627
- elif object_action == "Create":
628
- if term_exists:
629
- msg = f"Term {term_name} exists so result document modifies term create to term update"
630
- print_msg(INFO, msg, debug_level)
631
- return update_a_command(txt, object_action, object_type, q_name, known_guid)
632
- else:
633
- ## get the guid for the glossary from the name - first look in cache
634
- cached = get_element_dictionary().get(known_glossary_q_name, None)
635
-
636
- if cached is not None:
637
- glossary_guid = cached.get('guid', None)
638
- if glossary_guid is None:
639
- msg = f"Glossary GUID for {known_glossary_q_name} not found in cache"
640
- print_msg(WARNING, msg, debug_level) # should this ever occur?
641
- return None
642
- else:
643
- glossary_guid = egeria_client.__get_guid__(qualified_name=known_glossary_q_name)
644
- if glossary_guid == NO_ELEMENTS_FOUND:
645
- msg = f"Glossary {known_glossary_q_name} not found"
646
- print_msg(WARNING, msg, debug_level)
647
- return None
648
- term_body = {
649
- "class": "ReferenceableRequestBody", "elementProperties": {
650
- "class": "GlossaryTermProperties", "qualifiedName": known_q_name, "displayName": term_name,
651
- "aliases": alias_list, "summary": summary, "description": description,
652
- "abbreviation": abbreviation, "examples": examples, "usage": usage,
653
- "publishVersionIdentifier": version
654
- # "additionalProperties":
655
- # {
656
- # "propertyName1": "xxxx",
657
- # "propertyName2": "xxxx"
658
- # }
659
- }, "initialStatus": status
660
- }
661
- term_guid = egeria_client.create_controlled_glossary_term(glossary_guid, body_slimmer(term_body))
662
- if term_guid == NO_ELEMENTS_FOUND:
663
- print(f"{ERROR}Term {term_name} not created")
664
- return None
665
- if cats_exist and categories is not None:
666
- update_term_categories(egeria_client, term_guid, cats_exist, cat_q_name_list)
667
- update_element_dictionary(known_q_name, {'guid': term_guid, 'display_name': term_name})
668
- print_msg(ALWAYS, f"Created term `{term_name}` with GUID {term_guid}", debug_level)
669
- return egeria_client.get_term_by_guid(term_guid,
670
- 'MD') # return update_a_command(txt, object_action,
671
- # object_type, q_name, term_guid)
672
- except Exception as e:
673
- print(f"{ERROR}Error creating term {term_name}: {e}")
674
- console.print_exception(show_locals=True)
675
- return None
676
- else:
677
- return None
678
-
679
492
 
680
- def process_create_term_term_relationship_command(egeria_client: EgeriaTech, txt: str, directive: str = "display") -> \
681
- Optional[str]:
682
- """ Relate two terms through the specified relationship. ."""
683
- set_debug_level(directive)
684
- valid = True
685
- command = extract_command(txt)
493
+ command, object_type, object_action = extract_command_plus(txt)
686
494
  print(Markdown(f"# {command}\n"))
687
495
 
688
- object_type = command.split(' ')[1].strip()
689
- object_action = command.split(' ')[0].strip()
690
- term1_guid = None
691
- term2_guid = None
692
-
693
- term_relationship = process_simple_attribute(txt, ["Term Relationship", "Relationship Type"], "ERROR")
694
- if term_relationship not in TERM_RELATIONSHPS:
695
- valid = False
696
-
697
- print(Markdown(
698
- f"{pre_command} `{command}` for term relationship: `{term_relationship}` with directive: `{directive}` "))
699
-
700
- term1_q_name, term1_guid, term1_valid, term1_exists = process_element_identifiers(egeria_client, object_type,
701
- ["Term 1 Name", "Term 1"], txt,
702
- "Exists Required", None)
703
-
704
- term2_q_name, term2_guid, term2_valid, term2_exists = process_element_identifiers(egeria_client, object_type,
705
- ["Term 2 Name", "Term 2"], txt,
706
- "Exists Required", None)
707
-
708
- request_display = (f"\n\t* Term 1 Qualified Name: {term1_q_name}\n\t* Term 2 Qualified Name {term2_q_name}\n\t"
709
- f"* Term Relationship: {term_relationship}")
710
-
711
- if not (term1_valid and term2_valid and term1_exists and term2_exists):
712
- valid = False
713
-
714
- if directive == "display":
715
- print(request_display)
716
- return None
717
- elif directive == "validate":
718
- print(request_display)
719
- return str(valid)
720
- elif directive == "process":
721
- try:
722
- print(request_display)
723
- if not valid: # First validate the term before we process it
724
- return None
725
- egeria_client.add_relationship_between_terms(term1_guid, term2_guid, term_relationship)
726
- print_msg(ALWAYS, f"Relationship `{term_relationship}` created", debug_level)
727
- update_md = (f"\n\n# Update Term-Term Relationship\n\n## Term 1 Name:\n\n{term1_q_name}"
728
- f"\n\n## Term 2 Name\n\n{term2_q_name}\n\n## Term Relationship:\n\n{term_relationship}")
729
- return update_md
730
-
731
-
732
- except Exception as e:
733
- print(f"{ERROR}Error performing {command}: {e}")
734
- console.print_exception(show_locals=True)
735
- return None
736
- else:
496
+ parsed_output = parse_upsert_command(egeria_client, object_type, object_action, txt, directive)
497
+ if not parsed_output:
498
+ logger.error(f"No output for `{object_action}`")
737
499
  return None
738
500
 
501
+ valid = parsed_output['valid']
502
+ exists = parsed_output['exists']
739
503
 
740
- def process_term_list_command(egeria_client: EgeriaTech, txt: str, directive: str = "display") -> Optional[str]:
741
- """ List terms as a markdown table. Filter based on optional search string. """
742
- set_debug_level(directive)
743
- valid = True
744
- command = extract_command(txt)
745
- print(Markdown(f"# {command}\n"))
504
+ qualified_name = parsed_output.get('qualified_name', None)
505
+ guid = parsed_output.get('guid', None)
746
506
 
747
- search_string = process_simple_attribute(txt, SEARCH_LABELS)
748
- if search_string is None:
749
- search_string = '*'
750
- print(Markdown(f"{pre_command} `{command}` with search string:`{search_string}` with directive: `{directive}`"))
507
+ print(Markdown(parsed_output['display']))
751
508
 
752
- glossary = process_simple_attribute(txt, ['Glossary', 'In Glossary', "Glossary Name"])
753
- if glossary is not None:
754
- _, glossary_guid, _, glossary_exists = get_element_by_name(egeria_client, "Glossary", glossary)
755
- msg = f"Found glossary `{glossary}` with GUID {glossary_guid}"
756
- print_msg(INFO, msg, debug_level)
757
- else:
758
- glossary_guid = None
759
- msg = f"No glossary found"
760
- print_msg(INFO, msg, debug_level)
509
+ logger.debug(json.dumps(parsed_output, indent=4))
761
510
 
762
- output_format = process_simple_attribute(txt, OUTPUT_LABELS)
763
- if output_format is None:
764
- output_format = "LIST"
765
- elif output_format not in ELEMENT_OUTPUT_FORMATS:
766
- valid = False
767
- print_msg(ERROR, f"Invalid output format: `{output_format}`", debug_level)
511
+ attributes = parsed_output['attributes']
768
512
 
769
- request_display = (f"\n\t* Search String: {search_string}\n\t* Glossary: {glossary}\n\t* Output Format: "
770
- f"{output_format}\n")
513
+ display_name = attributes['Display Name'].get('value', None)
514
+ status = attributes.get('Status', {}).get('value', None)
515
+ merge_update = attributes.get('Merge Update', {}).get('value', True)
516
+ #
771
517
 
772
518
  if directive == "display":
773
- print(Markdown(request_display))
774
519
  return None
775
520
  elif directive == "validate":
776
- print(Markdown(request_display))
521
+ if valid:
522
+ print(Markdown(f"==> Validation of {command} completed successfully!\n"))
523
+ else:
524
+ msg = f"Validation failed for object_action `{command}`\n"
777
525
  return valid
778
- elif directive == "process":
779
- try:
780
- print(Markdown(request_display))
781
- if not valid: # First validate the term before we process it
782
- return None
783
-
784
- term_list_md = f"\n# Term List for search string: `{search_string}`\n\n"
785
- if output_format == "DICT":
786
- struct = egeria_client.find_glossary_terms(search_string, glossary_guid, output_format=output_format)
787
- term_list_md += f"```{json.dumps(struct, indent=4)}```\n"
788
- else:
789
- term_list_md += egeria_client.find_glossary_terms(search_string, glossary_guid,
790
- output_format=output_format)
791
- print_msg("ALWAYS", f"Wrote Term List for search string: `{search_string}`", debug_level)
792
-
793
- return term_list_md
794
-
795
- md_table = egeria_client.find_glossary_terms(search_string, glossary_guid, output_format=output_format)
796
-
797
- print_msg("ALWAYS", f"Wrote Term list for search string `{search_string}`", debug_level)
798
- return md_table
799
-
800
- except Exception as e:
801
- print(f"{ERROR}Error performing {command}: {e}")
802
- console.print_exception(show_locals=True)
803
- return None
804
- else:
805
- return None
806
-
807
-
808
- def process_category_list_command(egeria_client: EgeriaTech, txt: str, directive: str = "display") -> Optional[str]:
809
- """ List terms as a markdown table. Filter based on optional search string. """
810
- set_debug_level(directive)
811
- valid = True
812
- command = extract_command(txt)
813
- print(Markdown(f"# {command}\n"))
814
526
 
815
- search_string = process_simple_attribute(txt, SEARCH_LABELS, "INFO")
816
- if search_string is None:
817
- search_string = '*'
818
- print(Markdown(f"{pre_command} `{command}` with search string:`{search_string}` with directive: `{directive}`"))
819
-
820
- output_format = process_simple_attribute(txt, OUTPUT_LABELS, "INFO")
821
- if output_format is None:
822
- output_format = "LIST"
823
- elif output_format not in ELEMENT_OUTPUT_FORMATS:
824
- valid = False
825
- print_msg(ERROR, f"Invalid output format: `{output_format}`", debug_level)
826
-
827
- request_display = f"\n\t* Search String: {search_string}\n\t* Output Format: {output_format}\n"
828
-
829
- if directive == "display":
830
- print(Markdown(request_display))
831
- return None
832
- elif directive == "validate":
833
- print(Markdown(request_display))
834
- return valid
835
527
  elif directive == "process":
836
528
  try:
837
- print(Markdown(request_display))
838
- if not valid: # First validate the term before we process it
839
- return None
840
-
841
- cat_list_md = f"\n# Category List for search string: `{search_string}`\n\n"
842
- if output_format == "DICT":
843
- struct = egeria_client.find_glossary_categories(search_string, output_format=output_format)
844
- cat_list_md += f"```{json.dumps(struct, indent=4)}```\n"
845
- else:
846
- cat_list_md += egeria_client.find_glossary_categories(search_string, output_format=output_format)
847
- print_msg("ALWAYS", f"Wrote Category List for search string: `{search_string}`", debug_level)
848
-
849
- return cat_list_md
850
-
851
- except Exception as e:
852
- print(f"{ERROR}Error performing {command}: {e}")
853
- console.print_exception(show_locals=True)
854
- return None
855
- else:
856
-
857
- return None
858
-
859
-
860
- def process_glossary_structure_command(egeria_client: EgeriaTech, txt: str, directive: str = "display") -> Optional[
861
- str]:
862
- """ List terms as a markdown table. Filter based on optional search string. """
863
- set_debug_level(directive)
864
- valid = True
865
- command = extract_command(txt)
866
- print(Markdown(f"# {command}\n"))
867
-
868
- known_glossary_guid = ""
869
-
870
- glossary_name = process_simple_attribute(txt, GLOSSARY_NAME_LABELS, "ERROR")
871
-
872
- _, known_glossary_guid, valid, _ = process_element_identifiers(egeria_client, "Glossary", GLOSSARY_NAME_LABELS, txt,
873
- EXISTS_REQUIRED, None)
874
-
875
- print(Markdown(f"{pre_command} `{command}` for glossary:`{glossary_name}` with directive: `{directive}`"))
876
-
877
- output_format = process_simple_attribute(txt, OUTPUT_LABELS, "INFO")
878
- if output_format is None:
879
- output_format = "MD"
880
- elif output_format not in ["DICT", "LIST", "MD"]:
881
- valid = False
882
- print_msg(ERROR, f"Invalid output format: `{output_format}`", debug_level)
883
-
884
- request_display = f"\n\t* Glossary name: {glossary_name}\n\t* Output Format: {output_format}\n"
529
+ obj = "GlossaryTerm"
530
+ # Set the property body for a glossary collection
531
+ #
532
+ prop_body = set_prop_body(obj, qualified_name, attributes)
533
+ prop_body["aliases"] = attributes.get('Aliases', {}).get('value', None)
534
+ prop_body["summary"] = attributes.get('Summary', {}).get('value', None)
535
+ prop_body["examples"] = attributes.get('Examples', {}).get('value', None)
536
+ prop_body["abbreviation"] = attributes.get('Abbreviation', {}).get('value', None)
537
+ prop_body["usage"] = attributes.get('Usage', {}).get('value', None)
538
+ prop_body["user_defined_status"] = attributes.get('UserDefinedStatus', {}).get('value', None)
539
+ to_be_collection_guids = [attributes.get("Glossary", {}).get("guid_list", {}),
540
+ attributes.get("Folder", {}).get("guid_list", {})]
541
+ get_method = egeria_client.get_term_by_guid
542
+ collection_types = ["Glossary", "Folder"]
543
+
544
+ if object_action == "Update":
545
+ if not exists:
546
+ msg = (f" Element `{display_name}` does not exist! Updating result document with Create "
547
+ f"{object_action}\n")
548
+ logger.error(msg)
549
+ return update_a_command(txt, object_action, object_type, qualified_name, guid)
550
+ elif not valid:
551
+ return None
552
+ else:
553
+ print(Markdown(
554
+ f"==> Validation of {command} completed successfully! Proceeding to apply the changes.\n"))
555
+
556
+ body = set_update_body(obj, attributes)
557
+ body['properties'] = prop_body
558
+
559
+ egeria_client.update_glossary_term(guid, body)
560
+ if status:
561
+ egeria_client.update_term_status(guid, status)
562
+ get_method = egeria_client.get_term_by_guid
563
+ collection_types = ["Glossary", "Folder"]
564
+ to_be_collection_guids = [attributes.get("Glossary",{}).get("guid_list",{}), attributes.get("Folder",{}).get("guid_list",{})]
565
+ sync_collection_memberships(egeria_client, guid, get_method, collection_types,
566
+ to_be_collection_guids, merge_update)
567
+ logger.success(f"Updated {object_type} `{display_name}` with GUID {guid}\n\n___")
568
+ update_element_dictionary(qualified_name, {
569
+ 'guid': guid, 'display_name': display_name
570
+ })
571
+ return egeria_client.get_term_by_guid(guid, element_type='GlossaryTerm',
572
+ output_format='MD', output_format_set="DrE-Term")
885
573
 
886
- if directive == "display":
887
- print(Markdown(request_display))
888
- return None
889
- elif directive == "validate":
890
- print(Markdown(request_display))
891
- return str(valid)
892
- elif directive == "process":
893
- try:
894
- print(Markdown(request_display))
895
- if not valid: # First validate the term before we process it
896
- return None
897
574
 
898
- glossary_structure_md = f"\n# Glossary Structure for `{glossary_name}`\n\n"
899
- if output_format == "DICT":
900
- struct = egeria_client.get_glossary_category_structure(known_glossary_guid, output_format=output_format)
901
- glossary_structure_md += f"```{json.dumps(struct, indent=4)}```\n"
902
- else:
903
- glossary_structure_md += egeria_client.get_glossary_category_structure(known_glossary_guid,
904
- output_format=output_format)
905
- print_msg("ALWAYS", f"Wrote Glossary Structure for glossary: `{glossary_name}`", debug_level)
575
+ elif object_action == "Create":
576
+ if valid is False and exists:
577
+ msg = (f" Digital Product `{display_name}` already exists and result document updated changing "
578
+ f"`Create` to `Update` in processed output\n\n___")
579
+ logger.error(msg)
580
+ return update_a_command(txt, object_action, object_type, qualified_name, guid)
906
581
 
907
- return glossary_structure_md
582
+ else:
583
+ body = set_create_body(obj,attributes)
584
+
585
+ # if this is a root or folder (maybe more in the future), then make sure that the classification is set.
586
+
587
+ body["properties"] = prop_body
588
+
589
+ guid = egeria_client.create_glossary_term(body = body)
590
+ if guid:
591
+ sync_collection_memberships(egeria_client, guid, get_method,
592
+ collection_types, to_be_collection_guids, True)
593
+ update_element_dictionary(qualified_name, {
594
+ 'guid': guid, 'display_name': display_name
595
+ })
596
+ msg = f"Created Element `{display_name}` with GUID {guid}\n\n___"
597
+ logger.success(msg)
598
+ return egeria_client.get_collection_by_guid(guid, obj, output_format='MD')
599
+ else:
600
+ msg = f"Failed to create element `{display_name}` with GUID {guid}\n\n___"
601
+ logger.error(msg)
602
+ return None
908
603
 
909
- except Exception as e:
910
- print(f"{ERROR}Error performing {command}: {e}")
911
- console.print_exception(show_locals=True)
604
+ except PyegeriaException as e:
605
+ logger.error(f"Pyegeria error performing {command}: {e}")
606
+ print_basic_exception(e)
912
607
  return None
913
- else:
914
- return None
915
-
916
-
917
- def process_glossary_list_command(egeria_client: EgeriaTech, txt: str, directive: str = "display") -> Optional[str]:
918
- """ List terms as a markdown table. Filter based on optional search string. """
919
- set_debug_level(directive)
920
- valid = True
921
- command = extract_command(txt)
922
- print(Markdown(f"# {command}\n"))
923
-
924
- search_string = process_simple_attribute(txt, SEARCH_LABELS, "INFO")
925
- if search_string is None:
926
- search_string = '*'
927
- print(Markdown(f"{pre_command} `{command}` with search string:`{search_string}` with directive: `{directive}`"))
928
- if search_string is None:
929
- search_string = '*'
930
-
931
- output_format = process_simple_attribute(txt, OUTPUT_LABELS, "INFO")
932
- if output_format is None:
933
- output_format = "LIST"
934
- elif output_format not in ELEMENT_OUTPUT_FORMATS:
935
- valid = False
936
- print_msg(ERROR, f"Invalid output format: `{output_format}`", debug_level)
937
-
938
- request_display = f"\n\t* Search String: {search_string}\n\t* Output Format: {output_format}\n"
939
-
940
- if directive == "display":
941
- print(request_display)
942
- return None
943
- elif directive == "validate":
944
- print(request_display)
945
- return valid
946
- elif directive == "process":
947
- try:
948
- print(request_display)
949
- if not valid: # First validate the term before we process it
950
- return None
951
-
952
- glossary_list_md = f"\n# Glossary List for `{search_string}`\n\n"
953
- if output_format == "DICT":
954
- struct = egeria_client.find_glossaries(search_string, output_format=output_format)
955
- glossary_list_md += f"```{json.dumps(struct, indent=4)}```\n"
956
- else:
957
- glossary_list_md += egeria_client.find_glossaries(search_string, output_format=output_format)
958
- print_msg("ALWAYS", f"Wrote Glossary List for search string: `{search_string}`", debug_level)
959
-
960
- return glossary_list_md
961
-
962
608
  except Exception as e:
963
- print(f"{ERROR}Error performing {command}: {e}")
964
- console.print_exception(show_locals=True)
965
- return None
609
+ logger.error(f"Error performing {command}: {e}")
966
610
  else:
967
611
  return None
612
+ def process_create_term_term_relationship_command(egeria_client: EgeriaTech, txt: str, directive: str = "display") -> Optional[str]:
613
+ pass
614
+ # """ Relate two terms through the specified relationship. ."""
615
+ # set_debug_level(directive)
616
+ # valid = True
617
+ # command = extract_command(txt)
618
+ # print(Markdown(f"# {command}\n"))
619
+ #
620
+ # object_type = command.split(' ')[1].strip()
621
+ # object_action = command.split(' ')[0].strip()
622
+ # term1_guid = None
623
+ # term2_guid = None
624
+ #
625
+ # term_relationship = process_simple_attribute(txt, ["Term Relationship", "Relationship Type"], "ERROR")
626
+ # if term_relationship not in TERM_RELATIONSHPS:
627
+ # valid = False
628
+ #
629
+ # print(Markdown(
630
+ # f"{pre_command} `{command}` for term relationship: `{term_relationship}` with directive: `{directive}` "))
631
+ #
632
+ # term1_q_name, term1_guid, term1_valid, term1_exists = process_element_identifiers(egeria_client, object_type,
633
+ # ["Term 1 Name", "Term 1"], txt,
634
+ # "Exists Required", None)
635
+ #
636
+ # term2_q_name, term2_guid, term2_valid, term2_exists = process_element_identifiers(egeria_client, object_type,
637
+ # ["Term 2 Name", "Term 2"], txt,
638
+ # "Exists Required", None)
639
+ #
640
+ # request_display = (f"\n\t* Term 1 Qualified Name: {term1_q_name}\n\t* Term 2 Qualified Name {term2_q_name}\n\t"
641
+ # f"* Term Relationship: {term_relationship}")
642
+ #
643
+ # if not (term1_valid and term2_valid and term1_exists and term2_exists):
644
+ # valid = False
645
+ #
646
+ # if directive == "display":
647
+ # print(request_display)
648
+ # return None
649
+ # elif directive == "validate":
650
+ # print(request_display)
651
+ # return str(valid)
652
+ # elif directive == "process":
653
+ # try:
654
+ # print(request_display)
655
+ # if not valid: # First validate the term before we process it
656
+ # return None
657
+ # egeria_client.add_relationship_between_terms(term1_guid, term2_guid, term_relationship)
658
+ # print_msg(ALWAYS, f"Relationship `{term_relationship}` created", debug_level)
659
+ # update_md = (f"\n\n# Update Term-Term Relationship\n\n## Term 1 Name:\n\n{term1_q_name}"
660
+ # f"\n\n## Term 2 Name\n\n{term2_q_name}\n\n## Term Relationship:\n\n{term_relationship}")
661
+ # return update_md
662
+ #
663
+ #
664
+ # except Exception as e:
665
+ # print(f"{ERROR}Error performing {command}: {e}")
666
+ # console.print_exception(show_locals=True)
667
+ # return None
668
+ # else:
669
+ # return None
968
670
 
969
671
 
672
+ def process_term_list_command(egeria_client: EgeriaTech, txt: str, directive: str = "display") -> Optional[str]:
673
+ pass
674
+ # """ List terms as a markdown table. Filter based on optional search string. """
675
+ # set_debug_level(directive)
676
+ # valid = True
677
+ # command = extract_command(txt)
678
+ # print(Markdown(f"# {command}\n"))
679
+ #
680
+ # search_string = process_simple_attribute(txt, SEARCH_LABELS)
681
+ # if search_string is None:
682
+ # search_string = '*'
683
+ # print(Markdown(f"{pre_command} `{command}` with search string:`{search_string}` with directive: `{directive}`"))
684
+ #
685
+ # glossary = process_simple_attribute(txt, ['Glossary', 'In Glossary', "Glossary Name"])
686
+ # if glossary is not None:
687
+ # _, glossary_guid, _, glossary_exists = get_element_by_name(egeria_client, "Glossary", glossary)
688
+ # msg = f"Found glossary `{glossary}` with GUID {glossary_guid}"
689
+ # print_msg(INFO, msg, debug_level)
690
+ # else:
691
+ # glossary_guid = None
692
+ # msg = f"No glossary found"
693
+ # print_msg(INFO, msg, debug_level)
694
+ #
695
+ # output_format = process_simple_attribute(txt, OUTPUT_LABELS)
696
+ # if output_format is None:
697
+ # output_format = "LIST"
698
+ # elif output_format not in ELEMENT_OUTPUT_FORMATS:
699
+ # valid = False
700
+ # print_msg(ERROR, f"Invalid output format: `{output_format}`", debug_level)
701
+ #
702
+ # request_display = (f"\n\t* Search String: {search_string}\n\t* Glossary: {glossary}\n\t* Output Format: "
703
+ # f"{output_format}\n")
704
+ #
705
+ # if directive == "display":
706
+ # print(Markdown(request_display))
707
+ # return None
708
+ # elif directive == "validate":
709
+ # print(Markdown(request_display))
710
+ # return valid
711
+ # elif directive == "process":
712
+ # try:
713
+ # print(Markdown(request_display))
714
+ # if not valid: # First validate the term before we process it
715
+ # return None
716
+ #
717
+ # term_list_md = f"\n# Term List for search string: `{search_string}`\n\n"
718
+ # if output_format == "DICT":
719
+ # struct = egeria_client.find_glossary_terms(search_string, glossary_guid, output_format=output_format)
720
+ # term_list_md += f"```{json.dumps(struct, indent=4)}```\n"
721
+ # else:
722
+ # term_list_md += egeria_client.find_glossary_terms(search_string, glossary_guid,
723
+ # output_format=output_format)
724
+ # print_msg("ALWAYS", f"Wrote Term List for search string: `{search_string}`", debug_level)
725
+ #
726
+ # return term_list_md
727
+ #
728
+ # md_table = egeria_client.find_glossary_terms(search_string, glossary_guid, output_format=output_format)
729
+ #
730
+ # print_msg("ALWAYS", f"Wrote Term list for search string `{search_string}`", debug_level)
731
+ # return md_table
732
+ #
733
+ # except Exception as e:
734
+ # print(f"{ERROR}Error performing {command}: {e}")
735
+ # console.print_exception(show_locals=True)
736
+ # return None
737
+ # else:
738
+ # return None
739
+ #
740
+ #
741
+ def process_category_list_command(egeria_client: EgeriaTech, txt: str, directive: str = "display") -> Optional[str]:
742
+ pass
743
+ # """ List terms as a markdown table. Filter based on optional search string. """
744
+ # set_debug_level(directive)
745
+ # valid = True
746
+ # command = extract_command(txt)
747
+ # print(Markdown(f"# {command}\n"))
748
+ #
749
+ # search_string = process_simple_attribute(txt, SEARCH_LABELS, "INFO")
750
+ # if search_string is None:
751
+ # search_string = '*'
752
+ # print(Markdown(f"{pre_command} `{command}` with search string:`{search_string}` with directive: `{directive}`"))
753
+ #
754
+ # output_format = process_simple_attribute(txt, OUTPUT_LABELS, "INFO")
755
+ # if output_format is None:
756
+ # output_format = "LIST"
757
+ # elif output_format not in ELEMENT_OUTPUT_FORMATS:
758
+ # valid = False
759
+ # print_msg(ERROR, f"Invalid output format: `{output_format}`", debug_level)
760
+ #
761
+ # request_display = f"\n\t* Search String: {search_string}\n\t* Output Format: {output_format}\n"
762
+ #
763
+ # if directive == "display":
764
+ # print(Markdown(request_display))
765
+ # return None
766
+ # elif directive == "validate":
767
+ # print(Markdown(request_display))
768
+ # return valid
769
+ # elif directive == "process":
770
+ # try:
771
+ # print(Markdown(request_display))
772
+ # if not valid: # First validate the term before we process it
773
+ # return None
774
+ #
775
+ # cat_list_md = f"\n# Category List for search string: `{search_string}`\n\n"
776
+ # if output_format == "DICT":
777
+ # struct = egeria_client.find_glossary_categories(search_string, output_format=output_format)
778
+ # cat_list_md += f"```{json.dumps(struct, indent=4)}```\n"
779
+ # else:
780
+ # cat_list_md += egeria_client.find_glossary_categories(search_string, output_format=output_format)
781
+ # print_msg("ALWAYS", f"Wrote Category List for search string: `{search_string}`", debug_level)
782
+ #
783
+ # return cat_list_md
784
+ #
785
+ # except Exception as e:
786
+ # print(f"{ERROR}Error performing {command}: {e}")
787
+ # console.print_exception(show_locals=True)
788
+ # return None
789
+ # else:
790
+ #
791
+ # return None
792
+ #
793
+ #
794
+ def process_glossary_structure_command(egeria_client: EgeriaTech, txt: str, directive: str = "display") -> Optional[str]:
795
+ pass
796
+ # """ List terms as a markdown table. Filter based on optional search string. """
797
+ # set_debug_level(directive)
798
+ # valid = True
799
+ # command = extract_command(txt)
800
+ # print(Markdown(f"# {command}\n"))
801
+ #
802
+ # known_glossary_guid = ""
803
+ #
804
+ # glossary_name = process_simple_attribute(txt, GLOSSARY_NAME_LABELS, "ERROR")
805
+ #
806
+ # _, known_glossary_guid, valid, _ = process_element_identifiers(egeria_client, "Glossary", GLOSSARY_NAME_LABELS, txt,
807
+ # EXISTS_REQUIRED, None)
808
+ #
809
+ # print(Markdown(f"{pre_command} `{command}` for glossary:`{glossary_name}` with directive: `{directive}`"))
810
+ #
811
+ # output_format = process_simple_attribute(txt, OUTPUT_LABELS, "INFO")
812
+ # if output_format is None:
813
+ # output_format = "MD"
814
+ # elif output_format not in ["DICT", "LIST", "MD"]:
815
+ # valid = False
816
+ # print_msg(ERROR, f"Invalid output format: `{output_format}`", debug_level)
817
+ #
818
+ # request_display = f"\n\t* Glossary name: {glossary_name}\n\t* Output Format: {output_format}\n"
819
+ #
820
+ # if directive == "display":
821
+ # print(Markdown(request_display))
822
+ # return None
823
+ # elif directive == "validate":
824
+ # print(Markdown(request_display))
825
+ # return str(valid)
826
+ # elif directive == "process":
827
+ # try:
828
+ # print(Markdown(request_display))
829
+ # if not valid: # First validate the term before we process it
830
+ # return None
831
+ #
832
+ # glossary_structure_md = f"\n# Glossary Structure for `{glossary_name}`\n\n"
833
+ # if output_format == "DICT":
834
+ # struct = egeria_client.get_glossary_category_structure(known_glossary_guid, output_format=output_format)
835
+ # glossary_structure_md += f"```{json.dumps(struct, indent=4)}```\n"
836
+ # else:
837
+ # glossary_structure_md += egeria_client.get_glossary_category_structure(known_glossary_guid,
838
+ # output_format=output_format)
839
+ # print_msg("ALWAYS", f"Wrote Glossary Structure for glossary: `{glossary_name}`", debug_level)
840
+ #
841
+ # return glossary_structure_md
842
+ #
843
+ # except Exception as e:
844
+ # print(f"{ERROR}Error performing {command}: {e}")
845
+ # console.print_exception(show_locals=True)
846
+ # return None
847
+ # else:
848
+ # return None
849
+ #
850
+ #
851
+ def process_glossary_list_command(egeria_client: EgeriaTech, txt: str, directive: str = "display") -> Optional[str]:
852
+ pass
853
+ # """ List terms as a markdown table. Filter based on optional search string. """
854
+ # set_debug_level(directive)
855
+ # valid = True
856
+ # command = extract_command(txt)
857
+ # print(Markdown(f"# {command}\n"))
858
+ #
859
+ # search_string = process_simple_attribute(txt, SEARCH_LABELS, "INFO")
860
+ # if search_string is None:
861
+ # search_string = '*'
862
+ # print(Markdown(f"{pre_command} `{command}` with search string:`{search_string}` with directive: `{directive}`"))
863
+ # if search_string is None:
864
+ # search_string = '*'
865
+ #
866
+ # output_format = process_simple_attribute(txt, OUTPUT_LABELS, "INFO")
867
+ # if output_format is None:
868
+ # output_format = "LIST"
869
+ # elif output_format not in ELEMENT_OUTPUT_FORMATS:
870
+ # valid = False
871
+ # print_msg(ERROR, f"Invalid output format: `{output_format}`", debug_level)
872
+ #
873
+ # request_display = f"\n\t* Search String: {search_string}\n\t* Output Format: {output_format}\n"
874
+ #
875
+ # if directive == "display":
876
+ # print(request_display)
877
+ # return None
878
+ # elif directive == "validate":
879
+ # print(request_display)
880
+ # return valid
881
+ # elif directive == "process":
882
+ # try:
883
+ # print(request_display)
884
+ # if not valid: # First validate the term before we process it
885
+ # return None
886
+ #
887
+ # glossary_list_md = f"\n# Glossary List for `{search_string}`\n\n"
888
+ # if output_format == "DICT":
889
+ # struct = egeria_client.find_glossaries(search_string, output_format=output_format)
890
+ # glossary_list_md += f"```{json.dumps(struct, indent=4)}```\n"
891
+ # else:
892
+ # glossary_list_md += egeria_client.find_glossaries(search_string, output_format=output_format)
893
+ # print_msg("ALWAYS", f"Wrote Glossary List for search string: `{search_string}`", debug_level)
894
+ #
895
+ # return glossary_list_md
896
+ #
897
+ # except Exception as e:
898
+ # print(f"{ERROR}Error performing {command}: {e}")
899
+ # console.print_exception(show_locals=True)
900
+ # return None
901
+ # else:
902
+ # return None
903
+ #
904
+ #
970
905
  def process_term_details_command(egeria_client: EgeriaTech, txt: str, directive: str = "display") -> Optional[str]:
971
- """ List terms as a markdown table. Filter based on optional search string. """
972
- set_debug_level(directive)
973
- valid = True
974
- command = extract_command(txt)
975
- print(Markdown(f"# {command}\n"))
976
- object_type = command.split(' ')[1].strip()
977
- object_action = command.split(' ')[0].strip()
978
-
979
- term_identifier = process_simple_attribute(txt, TERM_NAME_LABELS, "ERROR")
980
-
981
- print(Markdown(f"{pre_command} `{command}` for term:`{term_identifier}` with directive: `{directive}`"))
982
-
983
- output_format = process_simple_attribute(txt, OUTPUT_LABELS, "INFO")
984
- if output_format is None:
985
- output_format = "REPORT"
986
- else:
987
- output_format = output_format.upper()
988
-
989
- if output_format not in ["DICT", "REPORT"]:
990
- valid = False
991
- print_msg(ERROR, f"Invalid output format: `{output_format}`", debug_level)
992
-
993
- request_display = f"\n\t* Term Identifier: {term_identifier}\n\t* Output Format {output_format}"
994
-
995
- if directive == "display":
996
- print(request_display)
997
- return None
998
- elif directive == "validate":
999
- print(request_display)
1000
- return valid
1001
- elif directive == "process":
1002
- try:
1003
- print(request_display)
1004
- if not valid: # First validate the term before we process it
1005
- return None
1006
- output = egeria_client.get_term_details(term_identifier, output_format=output_format)
1007
- if output_format == "DICT":
1008
- output = f"```{json.dumps(output, indent=4)}```"
1009
- print_msg("ALWAYS", f"Wrote Term Details for term: `{term_identifier}`", debug_level)
1010
-
1011
- return output
1012
-
1013
- except Exception as e:
1014
- print(f"{ERROR}Error performing {command}: {e}")
1015
- console.print_exception(show_locals=True)
1016
- return None
1017
- else:
1018
- return None
1019
-
1020
-
906
+ pass
907
+ # """ List terms as a markdown table. Filter based on optional search string. """
908
+ # set_debug_level(directive)
909
+ # valid = True
910
+ # command = extract_command(txt)
911
+ # print(Markdown(f"# {command}\n"))
912
+ # object_type = command.split(' ')[1].strip()
913
+ # object_action = command.split(' ')[0].strip()
914
+ #
915
+ # term_identifier = process_simple_attribute(txt, TERM_NAME_LABELS, "ERROR")
916
+ #
917
+ # print(Markdown(f"{pre_command} `{command}` for term:`{term_identifier}` with directive: `{directive}`"))
918
+ #
919
+ # output_format = process_simple_attribute(txt, OUTPUT_LABELS, "INFO")
920
+ # if output_format is None:
921
+ # output_format = "REPORT"
922
+ # else:
923
+ # output_format = output_format.upper()
924
+ #
925
+ # if output_format not in ["DICT", "REPORT"]:
926
+ # valid = False
927
+ # print_msg(ERROR, f"Invalid output format: `{output_format}`", debug_level)
928
+ #
929
+ # request_display = f"\n\t* Term Identifier: {term_identifier}\n\t* Output Format {output_format}"
930
+ #
931
+ # if directive == "display":
932
+ # print(request_display)
933
+ # return None
934
+ # elif directive == "validate":
935
+ # print(request_display)
936
+ # return valid
937
+ # elif directive == "process":
938
+ # try:
939
+ # print(request_display)
940
+ # if not valid: # First validate the term before we process it
941
+ # return None
942
+ # output = egeria_client.get_term_details(term_identifier, output_format=output_format)
943
+ # if output_format == "DICT":
944
+ # output = f"```{json.dumps(output, indent=4)}```"
945
+ # print_msg("ALWAYS", f"Wrote Term Details for term: `{term_identifier}`", debug_level)
946
+ #
947
+ # return output
948
+ #
949
+ # except Exception as e:
950
+ # print(f"{ERROR}Error performing {command}: {e}")
951
+ # console.print_exception(show_locals=True)
952
+ # return None
953
+ # else:
954
+ # return None
955
+ #
956
+ #
1021
957
  def process_term_history_command(egeria_client: EgeriaTech, txt: str, directive: str = "display") -> Optional[str]:
1022
- """ List terms as a markdown table. Filter based on optional search string. """
1023
- set_debug_level(directive)
1024
- valid = True
1025
- command = extract_command(txt)
1026
- print(Markdown(f"# {command}\n"))
1027
- object_type = command.split(' ')[1].strip()
1028
- object_action = command.split(' ')[0].strip()
1029
-
1030
- element_labels = TERM_NAME_LABELS
1031
- element_labels.append('Display Name')
1032
-
1033
- term_name = process_simple_attribute(txt, element_labels, "ERROR")
1034
-
1035
- known_q_name, known_guid, valid, term_exists = process_element_identifiers(egeria_client, object_type,
1036
- element_labels, txt, object_action, )
1037
-
1038
- print(Markdown(f"{pre_command} `{command}` for term:`{term_name}` with directive: `{directive}`"))
1039
-
1040
- output_format = process_simple_attribute(txt, OUTPUT_LABELS, "INFO")
1041
- if output_format is None:
1042
- output_format = "LIST"
1043
- elif output_format not in ["DICT", "LIST"]:
1044
- valid = False
1045
- print_msg(ERROR, f"Invalid output format: `{output_format}`", debug_level)
1046
-
1047
- request_display = f"\n\t* Term Name: {term_name}\n\t* Output Format {output_format}\n\t* GUID: {known_guid}\n"
1048
-
1049
- if directive == "display":
1050
- print(request_display)
1051
- return None
1052
- elif directive == "validate":
1053
- print(request_display)
1054
- return valid
1055
- elif directive == "process":
1056
- try:
1057
- print(request_display)
1058
- if not valid: # First validate the term before we process it
1059
- return None
1060
- term_history_md = f"\n# Term History for `{term_name}`\n\n"
1061
- if output_format == "DICT":
1062
- struct = egeria_client.list_term_revision_history(known_guid, output_format=output_format)
1063
- term_history_md += f"```{json.dumps(struct, indent=4)}```\n"
1064
- else:
1065
- term_history_md += egeria_client.list_full_term_history(known_guid, output_format)
1066
- print_msg("ALWAYS", f"Wrote Term History for term `{term_name}`", debug_level)
1067
-
1068
- return term_history_md
1069
-
1070
- except Exception as e:
1071
- print(f"{ERROR}Error performing {command}: {e}")
1072
- console.print_exception(show_locals=True)
1073
- return None
1074
- else:
1075
- return None
1076
-
1077
-
1078
- def process_term_revision_history_command(egeria_client: EgeriaTech, txt: str, directive: str = "display") -> Optional[
1079
- str]:
1080
- """ List term revision history as a markdown table or list."""
1081
- set_debug_level(directive)
1082
- valid = True
1083
- command = extract_command(txt)
1084
- print(Markdown(f"# {command}\n"))
1085
- object_type = command.split(' ')[1].strip()
1086
- object_action = command.split(' ')[0].strip()
1087
- known_q_name = None
1088
- known_guid = None
1089
-
1090
- element_labels = TERM_NAME_LABELS
1091
-
1092
- term_name = process_simple_attribute(txt, element_labels, "ERROR")
1093
- print(Markdown(f"{pre_command} `{command}` for term: `{term_name}` with directive: `{directive}` "))
1094
-
1095
- known_q_name, known_guid, valid, _ = process_element_identifiers(egeria_client, object_type, element_labels, txt,
1096
- object_action, )
1097
- output_format = process_simple_attribute(txt, ['Output Format', 'Format'], 'INFO')
1098
- if output_format is None:
1099
- output_format = "LIST"
1100
- elif output_format not in ["DICT", "LIST", "MD"]:
1101
- valid = False
1102
- print_msg(ERROR, f"Invalid output format: `{output_format}`", debug_level)
1103
-
1104
- request_display = f"\n\t* Term Name: {term_name}\n\t* Output Format: {output_format}\n"
1105
-
1106
- if directive == "display":
1107
- print(request_display)
1108
- return None
1109
- elif directive == "validate":
1110
- print(request_display)
1111
- return str(valid)
1112
- elif directive == "process":
1113
- try:
1114
- print(request_display)
1115
- if not valid: # First validate the term before we process it
1116
- return None
1117
- term_history_md = f"\n# Term Revision History for `{term_name}`\n\n"
1118
- if output_format == "DICT":
1119
- struct = egeria_client.list_term_revision_history(known_guid, output_format)
1120
- term_history_md += f"```{json.dumps(struct, indent=4)}```\n"
1121
- else:
1122
- term_history_md += egeria_client.list_term_revision_history(known_guid, output_format)
1123
- print_msg("ALWAYS", f"Wrote Term Revision History for term `{term_name}`", debug_level)
1124
- return term_history_md
1125
-
1126
- except Exception as e:
1127
- print(f"{ERROR}Error performing {command}: {e}")
1128
- console.print_exception(show_locals=True)
1129
- return None
1130
- else:
1131
- return None
958
+ pass
959
+ # """ List terms as a markdown table. Filter based on optional search string. """
960
+ # set_debug_level(directive)
961
+ # valid = True
962
+ # command = extract_command(txt)
963
+ # print(Markdown(f"# {command}\n"))
964
+ # object_type = command.split(' ')[1].strip()
965
+ # object_action = command.split(' ')[0].strip()
966
+ #
967
+ # element_labels = TERM_NAME_LABELS
968
+ # element_labels.append('Display Name')
969
+ #
970
+ # term_name = process_simple_attribute(txt, element_labels, "ERROR")
971
+ #
972
+ # known_q_name, known_guid, valid, term_exists = process_element_identifiers(egeria_client, object_type,
973
+ # element_labels, txt, object_action, )
974
+ #
975
+ # print(Markdown(f"{pre_command} `{command}` for term:`{term_name}` with directive: `{directive}`"))
976
+ #
977
+ # output_format = process_simple_attribute(txt, OUTPUT_LABELS, "INFO")
978
+ # if output_format is None:
979
+ # output_format = "LIST"
980
+ # elif output_format not in ["DICT", "LIST"]:
981
+ # valid = False
982
+ # print_msg(ERROR, f"Invalid output format: `{output_format}`", debug_level)
983
+ #
984
+ # request_display = f"\n\t* Term Name: {term_name}\n\t* Output Format {output_format}\n\t* GUID: {known_guid}\n"
985
+ #
986
+ # if directive == "display":
987
+ # print(request_display)
988
+ # return None
989
+ # elif directive == "validate":
990
+ # print(request_display)
991
+ # return valid
992
+ # elif directive == "process":
993
+ # try:
994
+ # print(request_display)
995
+ # if not valid: # First validate the term before we process it
996
+ # return None
997
+ # term_history_md = f"\n# Term History for `{term_name}`\n\n"
998
+ # if output_format == "DICT":
999
+ # struct = egeria_client.list_term_revision_history(known_guid, output_format=output_format)
1000
+ # term_history_md += f"```{json.dumps(struct, indent=4)}```\n"
1001
+ # else:
1002
+ # term_history_md += egeria_client.list_full_term_history(known_guid, output_format)
1003
+ # print_msg("ALWAYS", f"Wrote Term History for term `{term_name}`", debug_level)
1004
+ #
1005
+ # return term_history_md
1006
+ #
1007
+ # except Exception as e:
1008
+ # print(f"{ERROR}Error performing {command}: {e}")
1009
+ # console.print_exception(show_locals=True)
1010
+ # return None
1011
+ # else:
1012
+ # return None
1013
+ #
1014
+ #
1015
+ def process_term_revision_history_command(egeria_client: EgeriaTech, txt: str, directive: str = "display") -> Optional[str]:
1016
+ pass
1017
+ # """ List term revision history as a markdown table or list."""
1018
+ # set_debug_level(directive)
1019
+ # valid = True
1020
+ # command = extract_command(txt)
1021
+ # print(Markdown(f"# {command}\n"))
1022
+ # object_type = command.split(' ')[1].strip()
1023
+ # object_action = command.split(' ')[0].strip()
1024
+ # known_q_name = None
1025
+ # known_guid = None
1026
+ #
1027
+ # element_labels = TERM_NAME_LABELS
1028
+ #
1029
+ # term_name = process_simple_attribute(txt, element_labels, "ERROR")
1030
+ # print(Markdown(f"{pre_command} `{command}` for term: `{term_name}` with directive: `{directive}` "))
1031
+ #
1032
+ # known_q_name, known_guid, valid, _ = process_element_identifiers(egeria_client, object_type, element_labels, txt,
1033
+ # object_action, )
1034
+ # output_format = process_simple_attribute(txt, ['Output Format', 'Format'], 'INFO')
1035
+ # if output_format is None:
1036
+ # output_format = "LIST"
1037
+ # elif output_format not in ["DICT", "LIST", "MD"]:
1038
+ # valid = False
1039
+ # print_msg(ERROR, f"Invalid output format: `{output_format}`", debug_level)
1040
+ #
1041
+ # request_display = f"\n\t* Term Name: {term_name}\n\t* Output Format: {output_format}\n"
1042
+ #
1043
+ # if directive == "display":
1044
+ # print(request_display)
1045
+ # return None
1046
+ # elif directive == "validate":
1047
+ # print(request_display)
1048
+ # return str(valid)
1049
+ # elif directive == "process":
1050
+ # try:
1051
+ # print(request_display)
1052
+ # if not valid: # First validate the term before we process it
1053
+ # return None
1054
+ # term_history_md = f"\n# Term Revision History for `{term_name}`\n\n"
1055
+ # if output_format == "DICT":
1056
+ # struct = egeria_client.list_term_revision_history(known_guid, output_format)
1057
+ # term_history_md += f"```{json.dumps(struct, indent=4)}```\n"
1058
+ # else:
1059
+ # term_history_md += egeria_client.list_term_revision_history(known_guid, output_format)
1060
+ # print_msg("ALWAYS", f"Wrote Term Revision History for term `{term_name}`", debug_level)
1061
+ # return term_history_md
1062
+ #
1063
+ # except Exception as e:
1064
+ # print(f"{ERROR}Error performing {command}: {e}")
1065
+ # console.print_exception(show_locals=True)
1066
+ # return None
1067
+ # else:
1068
+ # return None