pyegeria 5.3.8.8__py3-none-any.whl → 5.3.8.10__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.
@@ -4,7 +4,7 @@ This file contains functions to parse and process Egeria Markdown (Freddie)
4
4
 
5
5
 
6
6
  """
7
-
7
+ import json
8
8
  import os
9
9
  import re
10
10
  import sys
@@ -16,8 +16,7 @@ from rich.console import Console
16
16
  from rich.markdown import Markdown
17
17
 
18
18
  from pyegeria import body_slimmer
19
- from pyegeria._globals import (NO_GLOSSARIES_FOUND, NO_ELEMENTS_FOUND, NO_PROJECTS_FOUND, \
20
- NO_CATEGORIES_FOUND)
19
+ from pyegeria._globals import (NO_GLOSSARIES_FOUND, NO_ELEMENTS_FOUND, NO_PROJECTS_FOUND, NO_CATEGORIES_FOUND)
21
20
  from pyegeria.dr_egeria_state import get_element_dictionary, update_element_dictionary, find_key_with_value
22
21
  from pyegeria.egeria_tech_client import EgeriaTech
23
22
  # from pyegeria.md_processing_helpers import process_q_name_list
@@ -27,12 +26,11 @@ EGERIA_WIDTH = int(os.environ.get("EGERIA_WIDTH", "170"))
27
26
  console = Console(width=EGERIA_WIDTH)
28
27
 
29
28
  command_list = ["Provenance", "Create Glossary", "Update Glossary", "Create Term", "Update Term", "List Terms",
30
- "List Glossary Terms", "List Term History", "Term Journal Report", "List Glossary Structure",
31
- "List Glossaries", "List Categories", "List Glossary Categories",
32
- "Create Personal Project", "Update Personal Project", "Create Category",
33
- "Update Category", "Create Solution Blueprint", "Update Solution Blueprint",
34
- "Create Solution Component", "Update Solution Component", "Update Category Structure",
35
- ]
29
+ "List Glossary Terms", "List Term History", "List Term Revision History", "List Term Update History",
30
+ "List Glossary Structure", "List Glossaries", "List Categories", "List Glossary Categories",
31
+ "Create Personal Project", "Update Personal Project", "Create Category", "Update Category",
32
+ "Create Solution Blueprint", "Update Solution Blueprint", "Create Solution Component",
33
+ "Update Solution Component", "Create Term-Term Relationship", "Update Term-Term Relationship",]
36
34
  # verbosity - verbose, quiet, debug
37
35
  debug_level = "debug"
38
36
  message_types = {
@@ -51,7 +49,8 @@ GLOSSARY_NAME_LABELS = ["Glossary Name", "Glossary", "Glossaries", "Owning Gloss
51
49
  CATEGORY_NAME_LABELS = ["Glossary Category Name", "Glossary Category", "Glossary Categories", "Category Name",
52
50
  "Category", "Categories"]
53
51
  PARENT_CATEGORY_LABELS = ["Parent Category Name", "Parent Category", "parent category name", "parent category"]
54
- CHILD_CATEGORY_LABELS = ["Child Categories", "Child Category", "child category names", "child categories", "Child Category Names"]
52
+ CHILD_CATEGORY_LABELS = ["Child Categories", "Child Category", "child category names", "child categories",
53
+ "Child Category Names"]
55
54
  TERM_NAME_LABELS = ["Glossary Term Name", "Glossary Term", "Glossary Terms", "Term Name", "Term", "Terms", "Term Names"]
56
55
  PROJECT_NAME_LABELS = ["Project Name", "Project", "Project Names", "Projects"]
57
56
  BLUEPRINT_NAME_LABELS = ["Solution Blueprint Name", "Solution Blueprint", "Solution Blueprints", "Blueprint Name",
@@ -65,8 +64,24 @@ SOLUTION_ACTOR_ROLE_LABELS = ["Solution Actor Role Name", "Solution Actor Role N
65
64
  SOLUTION_LINKING_ROLE_LABELS = ["Solution Linking Role Name", "Solution Linking Role Names", "Solution Linking Role",
66
65
  "Solution Linking Roles", "Linking Role Name", "Linking Role", "Linking Roles",
67
66
  "Linking Role Names"]
67
+ OUTPUT_LABELS = ["Output", "Output Format"]
68
+ SEARCH_LABELS = ['Search String', 'Filter']
68
69
  GUID_LABELS = ['GUID', 'guid']
69
70
 
71
+ ELEMENT_OUTPUT_FORMATS = ["LIST", "DICT", "MD", "FORM", "REPORT"]
72
+ TERM_RELATIONSHPS = [
73
+ "Synonym",
74
+ "Translation",
75
+ "PreferredTerm",
76
+ "TermISATYPEOFRelationship",
77
+ "TermTYPEDBYRelationship",
78
+ "Antonym",
79
+ "ReplacementTerm",
80
+ "ValidValue",
81
+ "TermHASARelationship",
82
+ "RelatedTerm",
83
+ "ISARelationship"
84
+ ]
70
85
 
71
86
  def render_markdown(markdown_text: str) -> None:
72
87
  """Renders the given markdown text in the console."""
@@ -152,12 +167,13 @@ def update_term_categories(egeria_client: EgeriaTech, term_guid: str, categories
152
167
  egeria_client.remove_term_from_category(term_guid, cat)
153
168
  msg = f"Removed term {term_guid} from category {cat}"
154
169
  print_msg("DEBUG-INFO", msg, debug_level)
155
- else: # No categories specified - so remove any categories a term is in
170
+ else: # No categories specified - so remove any categories a term is in
156
171
  for cat in current_categories:
157
172
  egeria_client.remove_term_from_category(term_guid, cat)
158
173
  msg = f"Removed term {term_guid} from category {cat}"
159
174
  print_msg("DEBUG-INFO", msg, debug_level)
160
175
 
176
+
161
177
  def extract_command_plus(block: str) -> tuple[str, str, str] | None:
162
178
  """
163
179
  Extracts a multi-word object and its associated action from the given block of text.
@@ -291,7 +307,7 @@ def print_msg(msg_level: str, msg: str, verbosity: str):
291
307
  sys.exit(1)
292
308
 
293
309
 
294
- def process_simple_attribute(txt: str, labels: [str], if_missing: str = INFO) -> str | None:
310
+ def process_simple_attribute(txt: str, labels: list[str], if_missing: str = INFO) -> str | None:
295
311
  """Process a simple attribute based on the provided labels and if_missing value.
296
312
  Extract the attribute value from the text and return it if it exists.
297
313
  If it doesn`t exist, return None and print an error message with severity of if_missing.
@@ -531,17 +547,17 @@ def get_element_by_name(egeria_client, element_type: str, element_name: str) ->
531
547
  unique = True
532
548
  return el_qname, el_guid, unique, exists
533
549
 
534
- # Convert element_type to plural form for method name construction # if element_type.endswith('y'): # #
535
- # plural_type = f"{element_type[:-1]}ies" # elif element_type.endswith('s'): # plural_type = f"{ #
550
+ # Convert element_type to plural form for method name construction # if element_type.endswith('y'): # # # #
551
+ # plural_type = f"{element_type[:-1]}ies" # elif element_type.endswith('s'): # plural_type = f"{ # # #
536
552
  # element_type}es" # else: # plural_type = f"{element_type}s" # # # Construct method name # method_name
537
553
  # = f"get_{plural_type}_by_name" # # # Check if the method exists on the client # if hasattr(egeria_client,
538
554
  # method_name): # # Call the method # method = getattr(egeria_client, method_name) # result = #
539
- # method(element_name) # return result # else: # # Method doesn't exist # return f"Method { #
555
+ # method(element_name) # return result # else: # # Method doesn't exist # return f"Method { # #
540
556
  # method_name} not found on client"
541
557
 
542
558
 
543
- def process_name_list(egeria_client: EgeriaTech, element_type: str, txt: str, element_labels: list[str]) -> tuple[str, list[
544
- Any], bool | Any, bool | None | Any] | None:
559
+ def process_name_list(egeria_client: EgeriaTech, element_type: str, txt: str, element_labels: list[str]) -> tuple[str,
560
+ list[Any], bool | Any, bool | None | Any] | None:
545
561
  """
546
562
  Processes a list of names specified in the given text, retrieves details for each
547
563
  element based on the provided type, and generates a list of valid qualified names.
@@ -678,11 +694,11 @@ def process_blueprint_upsert_command(egeria_client: EgeriaTech, txt: str, direct
678
694
  print_msg("ALWAYS", msg, debug_level)
679
695
 
680
696
  # update with get blueprint by guid
681
- return 'Would return get blueprint by guid and return md' # egeria_client.get_term_by_guid( #
697
+ return 'Would return get blueprint by guid and return md' # egeria_client.get_term_by_guid( # # #
682
698
  # known_guid, 'md')
683
699
 
684
700
  elif object_action == "Update" and directive == "validate":
685
- return 'Would call get_blueprint_by_guid and return md' # egeria_client.get_term_by_guid( #
701
+ return 'Would call get_blueprint_by_guid and return md' # egeria_client.get_term_by_guid( # # #
686
702
  # known_guid, 'md')
687
703
 
688
704
  elif object_action == "Create":
@@ -703,15 +719,20 @@ def process_blueprint_upsert_command(egeria_client: EgeriaTech, txt: str, direct
703
719
  update_element_dictionary(q_name, {'guid': new_guid, 'display_name': display_name})
704
720
  return 'Would return get blueprint by guid results as md' # egeria_client.get_term_by_guid( #
705
721
  # term_guid, 'MD')
722
+ else:
723
+ return None
706
724
 
707
725
  except Exception as e:
708
726
  msg = f"{ERROR}Error creating term {display_name}: {e}"
709
727
  print_msg("ERROR", msg, debug_level)
710
728
  console.print_exception(show_locals=True)
711
729
  return None
730
+ else:
731
+ return None
712
732
 
713
733
 
714
- def process_solution_component_upsert_command(egeria_client: EgeriaTech, txt: str, directive: str = "display") -> Optional[str]:
734
+ def process_solution_component_upsert_command(egeria_client: EgeriaTech, txt: str, directive: str = "display") -> \
735
+ Optional[str]:
715
736
  """
716
737
  Processes a solution componentt create or update command by extracting key attributes such as
717
738
  solution component name, description, version, solution component type etc from the given cell.
@@ -757,9 +778,8 @@ def process_solution_component_upsert_command(egeria_client: EgeriaTech, txt: st
757
778
  if solution_blueprints: # Find information about blueprints that include this component
758
779
  msg = "Checking for blueprints that include this solution component"
759
780
  print_msg("DEBUG-INFO", msg, debug_level)
760
- solution_blueprints, bp_qname_list, bp_valid, bp_exist = process_name_list(egeria_client,
761
- 'Solution Blueprints', txt,
762
- BLUEPRINT_NAME_LABELS)
781
+ solution_blueprints, bp_qname_list, bp_valid, bp_exist = process_name_list(egeria_client, 'Solution Blueprints',
782
+ txt, BLUEPRINT_NAME_LABELS)
763
783
  if bp_exist and bp_valid:
764
784
  msg = f"Found valid blueprints that include this solution component:\n\t{solution_blueprints}"
765
785
  print_msg("INFO", msg, debug_level)
@@ -770,8 +790,11 @@ def process_solution_component_upsert_command(egeria_client: EgeriaTech, txt: st
770
790
  msg = f"Parent Components are missing"
771
791
  print_msg("INFO", msg, debug_level)
772
792
  else:
773
- parent_components, parent_qname_list, parents_valid, parent_components_exist = process_name_list(
774
- egeria_client, 'Parent Components', txt, COMPONENT_NAME_LABELS)
793
+ parent_components, parent_qname_list, parents_valid, parent_components_exist = process_name_list(egeria_client,
794
+ 'Parent '
795
+ 'Components',
796
+ txt,
797
+ COMPONENT_NAME_LABELS)
775
798
  if parent_components_exist and parents_valid:
776
799
  msg = f"Found valid parent components that include this solution component:\n\t{parent_qname_list}"
777
800
  print_msg("INFO", msg, debug_level)
@@ -844,11 +867,11 @@ def process_solution_component_upsert_command(egeria_client: EgeriaTech, txt: st
844
867
  msg = f"\nUpdated Solution Component `{display_name}` with GUID {known_guid}"
845
868
  print_msg("ALWAYS", msg, debug_level)
846
869
  # update with get solution component by guid
847
- return 'Would return get Solution Component by guid and return md' # #
870
+ return 'Would return get Solution Component by guid and return md' # # # #
848
871
  # egeria_client.get_term_by_guid(known_guid, 'md')
849
872
 
850
873
  elif object_action == "Update" and directive == "validate":
851
- return 'Would call get_blueprint_by_guid and return md' # egeria_client.get_term_by_guid( #
874
+ return 'Would call get_blueprint_by_guid and return md' # egeria_client.get_term_by_guid( # # #
852
875
  # known_guid, 'md')
853
876
 
854
877
  elif object_action == "Create":
@@ -866,7 +889,7 @@ def process_solution_component_upsert_command(egeria_client: EgeriaTech, txt: st
866
889
  msg = f"\nCreated Solution Component `{display_name}` with GUID {known_guid}"
867
890
  print_msg("ALWAYS", msg, debug_level)
868
891
  update_element_dictionary(known_q_name, {'guid': known_guid, 'display_name': display_name})
869
- return 'Would return get solution component by guid results as md' # #
892
+ return 'Would return get solution component by guid results as md' # # # #
870
893
  # egeria_client.get_term_by_guid(term_guid, 'MD')
871
894
 
872
895
  except Exception as e:
@@ -874,7 +897,8 @@ def process_solution_component_upsert_command(egeria_client: EgeriaTech, txt: st
874
897
  print_msg("ERROR", msg, debug_level)
875
898
  console.print_exception(show_locals=True)
876
899
  return None
877
-
900
+ else:
901
+ return None
878
902
 
879
903
  def process_glossary_upsert_command(egeria_client: EgeriaTech, txt: str, directive: str = "display") -> Optional[str]:
880
904
  """
@@ -890,14 +914,15 @@ def process_glossary_upsert_command(egeria_client: EgeriaTech, txt: str, directi
890
914
  command, object_type, object_action = extract_command_plus(txt)
891
915
  set_debug_level(directive)
892
916
 
893
- glossary_name = process_simple_attribute(txt, GLOSSARY_NAME_LABELS)
917
+ glossary_name = process_simple_attribute(txt, GLOSSARY_NAME_LABELS, ERROR)
894
918
  print(Markdown(
895
919
  f"{pre_command} `{object_action}` `{object_type}` for glossary: `\'{glossary_name}\'` with directive: `"
896
920
  f"{directive}` "))
897
- language = process_simple_attribute(txt, ['Language'])
898
- description = process_simple_attribute(txt, ['Description'])
899
- usage = process_simple_attribute(txt, ['Usage'])
900
- q_name = process_simple_attribute(txt, ['Qualified Name'])
921
+ language = process_simple_attribute(txt, ['Language'], INFO)
922
+ description = process_simple_attribute(txt, ['Description'], INFO)
923
+ usage = process_simple_attribute(txt, ['Usage'], INFO)
924
+ q_name = process_simple_attribute(txt, ['Qualified Name'], INFO)
925
+ valid = True
901
926
 
902
927
  if glossary_name is None:
903
928
  valid = False
@@ -960,9 +985,8 @@ def process_glossary_upsert_command(egeria_client: EgeriaTech, txt: str, directi
960
985
 
961
986
  if object_action == "Update":
962
987
  if not glossary_exists:
963
- print(
964
- f"\n{ERROR}Glossary `{glossary_name}` does not exist! Updating result document with Create "
965
- f"command\n")
988
+ print(f"\n{ERROR}Glossary `{glossary_name}` does not exist! Updating result document with Create "
989
+ f"command\n")
966
990
  return update_a_command(txt, command, object_type, known_q_name, known_guid)
967
991
 
968
992
  body = {
@@ -996,6 +1020,10 @@ def process_glossary_upsert_command(egeria_client: EgeriaTech, txt: str, directi
996
1020
  # return update_a_command(txt, command, object_type, qualified_name, glossary_guid)
997
1021
  print_msg(ALWAYS, f"Created Glossary `{glossary_name}` with GUID {glossary_guid}", debug_level)
998
1022
  return egeria_client.get_glossary_by_guid(glossary_guid, output_format='MD')
1023
+ else:
1024
+ return None
1025
+ else:
1026
+ return None
999
1027
 
1000
1028
 
1001
1029
  def process_category_upsert_command(egeria_client: EgeriaTech, txt: str, directive: str = "display") -> Optional[str]:
@@ -1022,7 +1050,6 @@ def process_category_upsert_command(egeria_client: EgeriaTech, txt: str, directi
1022
1050
 
1023
1051
  parent_category_name = process_simple_attribute(txt, PARENT_CATEGORY_LABELS, "INFO")
1024
1052
 
1025
-
1026
1053
  element_labels = CATEGORY_NAME_LABELS
1027
1054
  element_labels.append('Display Name')
1028
1055
  # Check if category exists (and get qname and guid)
@@ -1036,7 +1063,6 @@ def process_category_upsert_command(egeria_client: EgeriaTech, txt: str, directi
1036
1063
  element_labels, txt,
1037
1064
  object_action, None)
1038
1065
 
1039
-
1040
1066
  # Check if owning glossary exists (and get qname)
1041
1067
  if owning_glossary_name is None:
1042
1068
  valid = False
@@ -1047,8 +1073,8 @@ def process_category_upsert_command(egeria_client: EgeriaTech, txt: str, directi
1047
1073
  egeria_client, "Glossary", GLOSSARY_NAME_LABELS, txt, EXISTS_REQUIRED, None)
1048
1074
 
1049
1075
  if parent_category_name:
1050
- _, parent_guid, parent_valid, parent_exists = get_element_by_name(
1051
- egeria_client, 'Glossary Categories', parent_category_name)
1076
+ _, parent_guid, parent_valid, parent_exists = get_element_by_name(egeria_client, 'Glossary Categories',
1077
+ parent_category_name)
1052
1078
  else:
1053
1079
  parent_guid = None
1054
1080
  parent_exists = False
@@ -1120,9 +1146,9 @@ def process_category_upsert_command(egeria_client: EgeriaTech, txt: str, directi
1120
1146
  })
1121
1147
  print_msg(ALWAYS, f"Updated Category `{category_name}` with GUID {known_guid}", debug_level)
1122
1148
 
1123
- category_sync = update_category_parent(egeria_client, known_guid,
1124
- parent_category_name)
1125
- print_msg(ALWAYS, f"Updated Category hierarchy for `{category_name}` with outcome {category_sync}", debug_level)
1149
+ category_sync = update_category_parent(egeria_client, known_guid, parent_category_name)
1150
+ print_msg(ALWAYS, f"Updated Category hierarchy for `{category_name}` with outcome {category_sync}",
1151
+ debug_level)
1126
1152
  return egeria_client.get_category_by_guid(known_guid, output_format='FORM')
1127
1153
 
1128
1154
  elif object_action == "Create":
@@ -1149,9 +1175,12 @@ def process_category_upsert_command(egeria_client: EgeriaTech, txt: str, directi
1149
1175
  print_msg(ALWAYS, f"Created Category `{category_name}` with GUID {category_guid}", debug_level)
1150
1176
  if parent_valid & parent_exists:
1151
1177
  egeria_client.set_parent_category(parent_guid, category_guid)
1152
- print_msg(ALWAYS, f"Set parent category for `{category_name}` to `{parent_category_name}`", debug_level)
1178
+ print_msg(ALWAYS, f"Set parent category for `{category_name}` to `{parent_category_name}`",
1179
+ debug_level)
1153
1180
  else:
1154
- print_msg(ERROR, f"Parent category `{parent_category_name}` not found or invalid for `{category_name}`", debug_level)
1181
+ print_msg(ERROR,
1182
+ f"Parent category `{parent_category_name}` not found or invalid for `{category_name}`",
1183
+ debug_level)
1155
1184
  return egeria_client.get_category_by_guid(category_guid, output_format='FORM')
1156
1185
  return None
1157
1186
  return None
@@ -1189,8 +1218,8 @@ def update_category_parent(egeria_client, category_guid: str, parent_category_na
1189
1218
 
1190
1219
  if isinstance(current_parent, str) and "No Parent Category found" in current_parent:
1191
1220
  # No parent currently set, need to set it
1192
- parent_q_name, parent_guid, parent_valid, parent_exists = get_element_by_name(
1193
- egeria_client, 'Glossary Categories', parent_category_name)
1221
+ _, parent_guid, _, parent_exists = get_element_by_name(egeria_client, 'Glossary Categories',
1222
+ parent_category_name)
1194
1223
 
1195
1224
  if parent_exists and parent_guid:
1196
1225
  egeria_client.set_parent_category(parent_guid, category_guid)
@@ -1210,12 +1239,14 @@ def update_category_parent(egeria_client, category_guid: str, parent_category_na
1210
1239
  egeria_client.remove_parent_category(current_parent_guid, category_guid)
1211
1240
 
1212
1241
  # Then set the new parent
1213
- parent_q_name, parent_guid, parent_valid, parent_exists = get_element_by_name(
1214
- egeria_client, 'Glossary Categories', parent_category_name)
1242
+ _, parent_guid, _, parent_exists = get_element_by_name(egeria_client, 'Glossary Categories',
1243
+ parent_category_name)
1215
1244
 
1216
1245
  if parent_exists and parent_guid:
1217
1246
  egeria_client.set_parent_category(parent_guid, category_guid)
1218
- print_msg(ALWAYS, f"Updated parent category from `{current_parent_name}` to `{parent_category_name}`", debug_level)
1247
+ print_msg(ALWAYS,
1248
+ f"Updated parent category from `{current_parent_name}` to `{parent_category_name}`",
1249
+ debug_level)
1219
1250
  else:
1220
1251
  print_msg(ERROR, f"Parent category `{parent_category_name}` not found", debug_level)
1221
1252
  outcome = False
@@ -1232,208 +1263,9 @@ def update_category_parent(egeria_client, category_guid: str, parent_category_na
1232
1263
  egeria_client.remove_parent_category(current_parent_guid, category_guid)
1233
1264
  print_msg(ALWAYS, f"Removed parent category `{current_parent_name}`", debug_level)
1234
1265
 
1235
-
1236
1266
  return outcome
1237
1267
 
1238
1268
 
1239
-
1240
-
1241
- def process_term_list_command(egeria_client: EgeriaTech, txt: str, directive: str = "display") -> Optional[str]:
1242
- """ List terms as a markdown table. Filter based on optional search string. """
1243
- set_debug_level(directive)
1244
- valid = True
1245
- command = extract_command(txt)
1246
- object_type = command.split(' ')[1].strip()
1247
- object_action = command.split(' ')[0].strip()
1248
- known_glossary_q = ""
1249
- known_glossary_guid = ""
1250
- glossary_exists = False
1251
- glossary_valid = False
1252
-
1253
-
1254
- search_string = process_simple_attribute(txt, ['Search String', 'Filter'])
1255
- if search_string is None:
1256
- search_string = '*'
1257
- print(Markdown(f"{pre_command} `{command}` with search string:`{search_string}` with directive: `{directive}`"))
1258
-
1259
- glossary = process_simple_attribute(txt, ['Glossary', 'In Glossary'])
1260
- if glossary is not None:
1261
- _, glossary_guid, _, glossary_exists = get_element_by_name(
1262
- egeria_client, "Glossary", glossary)
1263
- msg = f"Found glossary `{glossary}` with GUID {glossary_guid}"
1264
- print_msg(INFO, msg, debug_level)
1265
- else:
1266
- glossary_guid= None
1267
- msg = f"No glossary found"
1268
- print_msg(INFO, msg, debug_level)
1269
-
1270
-
1271
- request_display = f"\n* Search String: {search_string}\n* Glossary: {glossary}\n"
1272
-
1273
- if directive == "display":
1274
- print(Markdown(request_display))
1275
- return None
1276
- elif directive == "validate":
1277
- print(Markdown(request_display))
1278
- return valid
1279
- elif directive == "process":
1280
- try:
1281
- print(Markdown(request_display))
1282
- if not valid: # First validate the term before we process it
1283
- return None
1284
-
1285
- md_table = egeria_client.find_glossary_terms(search_string,glossary_guid, output_format = "LIST")
1286
-
1287
- return md_table
1288
-
1289
- except Exception as e:
1290
- print(f"{ERROR}Error creating Glossary Term list: {e}")
1291
- console.print_exception(show_locals=True)
1292
- return None
1293
-
1294
- def process_category_list_command(egeria_client: EgeriaTech, element_dictionary: dict, txt: str,
1295
- directive: str = "display") -> Optional[str]:
1296
- """ List terms as a markdown table. Filter based on optional search string. """
1297
- set_debug_level(directive)
1298
- valid = True
1299
- command = extract_command(txt)
1300
- object_type = command.split(' ')[1].strip()
1301
- object_action = command.split(' ')[0].strip()
1302
- known_glossary_q = ""
1303
- known_glossary_guid = ""
1304
- glossary_exists = False
1305
- glossary_valid = False
1306
-
1307
-
1308
- search_string = process_simple_attribute(txt, ['Search String', 'Filter'])
1309
- if search_string is None:
1310
- search_string = '*'
1311
- print(Markdown(f"{pre_command} `{command}` with search string:`{search_string}` with directive: `{directive}`"))
1312
-
1313
- # glossary = process_simple_attribute(txt, ['Glossary', 'In Glossary'])
1314
- # if glossary is not None:
1315
- # _, glossary_guid, _, glossary_exists = get_element_by_name(
1316
- # egeria_client, "Glossary", glossary)
1317
- # msg = f"Found glossary `{glossary}` with GUID {glossary_guid}"
1318
- # print_msg(INFO, msg, debug_level)
1319
- # else:
1320
- # glossary_guid= None
1321
- # msg = f"No glossary found"
1322
- # print_msg(INFO, msg, debug_level)
1323
-
1324
-
1325
- request_display = f"\n* Search String: {search_string}\n"
1326
-
1327
- if directive == "display":
1328
- print(Markdown(request_display))
1329
- return None
1330
- elif directive == "validate":
1331
- print(Markdown(request_display))
1332
- return valid
1333
- elif directive == "process":
1334
- try:
1335
- print(Markdown(request_display))
1336
- if not valid: # First validate the term before we process it
1337
- return None
1338
- md_table = egeria_client.find_glossary_categories(search_string, output_format = "LIST")
1339
-
1340
- return md_table
1341
-
1342
- except Exception as e:
1343
- print(f"{ERROR}Error creating Glossary Category list: {e}")
1344
- console.print_exception(show_locals=True)
1345
- return None
1346
-
1347
- def process_glossary_list_command(egeria_client: EgeriaTech, element_dictionary: dict, txt: str,
1348
- directive: str = "display") -> Optional[str]:
1349
- """ List terms as a markdown table. Filter based on optional search string. """
1350
- set_debug_level(directive)
1351
- valid = True
1352
- command = extract_command(txt)
1353
- object_type = command.split(' ')[1].strip()
1354
- object_action = command.split(' ')[0].strip()
1355
- known_glossary_q = ""
1356
- known_glossary_guid = ""
1357
- glossary_exists = False
1358
- glossary_valid = False
1359
-
1360
-
1361
- search_string = process_simple_attribute(txt, ['Search String', 'Filter'])
1362
- if search_string is None:
1363
- search_string = '*'
1364
- print(Markdown(f"{pre_command} `{command}` with search string:`{search_string}` with directive: `{directive}`"))
1365
-
1366
-
1367
- request_display = f"\n* Search String: {search_string}\n"
1368
-
1369
- if directive == "display":
1370
- print(request_display)
1371
- return None
1372
- elif directive == "validate":
1373
- print(request_display)
1374
- return valid
1375
- elif directive == "process":
1376
- try:
1377
- print(request_display)
1378
- if not valid: # First validate the term before we process it
1379
- return None
1380
-
1381
- md_table = egeria_client.find_glossaries(search_string, output_format = "LIST")
1382
-
1383
- return md_table
1384
-
1385
- except Exception as e:
1386
- print(f"{ERROR}Error creating Glossary list: {e}")
1387
- console.print_exception(show_locals=True)
1388
- return None
1389
-
1390
- def process_term_history_command(egeria_client: EgeriaTech, txt: str, directive: str = "display") -> Optional[str]:
1391
- """ List terms as a markdown table. Filter based on optional search string. """
1392
- set_debug_level(directive)
1393
- valid = True
1394
- command = extract_command(txt)
1395
- object_type = command.split(' ')[1].strip()
1396
- object_action = command.split(' ')[0].strip()
1397
-
1398
- element_labels = TERM_NAME_LABELS
1399
- element_labels.append('Display Name')
1400
-
1401
- term_name = process_simple_attribute(txt, element_labels, "ERROR")
1402
- print(Markdown(f"{pre_command} `{command}` for term: `\'{term_name}\'` with directive: `{directive}` "))
1403
-
1404
- known_q_name, known_guid, valid, term_exists = process_element_identifiers(egeria_client, object_type,
1405
- element_labels, txt, object_action,
1406
- )
1407
-
1408
- print(Markdown(f"{pre_command} `{command}` for term:`{term_name}` with directive: `{directive}`"))
1409
-
1410
-
1411
- request_display = f"\n\t* Term Name: {term_name}\n\t* Qualified Name: {known_q_name}\n\t* GUID: {known_guid}\n"
1412
-
1413
- if directive == "display":
1414
- print(request_display)
1415
- return None
1416
- elif directive == "validate":
1417
- print(request_display)
1418
- return valid
1419
- elif directive == "process":
1420
- try:
1421
- print(request_display)
1422
- if not valid: # First validate the term before we process it
1423
- return None
1424
- term_history_md = f"\n# Term History for `{term_name}`\n\n"
1425
- term_history_md += egeria_client.list_full_term_history(known_guid, 'LIST')
1426
-
1427
- return term_history_md
1428
-
1429
- except Exception as e:
1430
- print(f"{ERROR}Error creating Glossary list: {e}")
1431
- console.print_exception(show_locals=True)
1432
- return None
1433
-
1434
-
1435
-
1436
-
1437
1269
  def process_term_upsert_command(egeria_client: EgeriaTech, txt: str, directive: str = "display") -> Optional[str]:
1438
1270
  """
1439
1271
  Processes a term create or update command by extracting key attributes such as
@@ -1446,7 +1278,7 @@ def process_term_upsert_command(egeria_client: EgeriaTech, txt: str, directive:
1446
1278
  """
1447
1279
  valid = True
1448
1280
  categories_list = None
1449
- cats_exist = True
1281
+ cats_exist = False
1450
1282
  set_debug_level(directive)
1451
1283
  known_q_name = None
1452
1284
  command = extract_command(txt)
@@ -1455,15 +1287,23 @@ def process_term_upsert_command(egeria_client: EgeriaTech, txt: str, directive:
1455
1287
 
1456
1288
  term_name = process_simple_attribute(txt, ['Term Name', 'Display Name'], ERROR)
1457
1289
  print(Markdown(f"{pre_command} `{command}` for term:`{term_name}` with directive: `{directive}`"))
1458
- summary = process_simple_attribute(txt, ['Summary'])
1459
- description = process_simple_attribute(txt, ['Description'])
1460
- abbreviation = process_simple_attribute(txt, ['Abbreviation'])
1461
- examples = process_simple_attribute(txt, ['Examples'])
1462
- usage = process_simple_attribute(txt, ['Usage'])
1290
+ summary = process_simple_attribute(txt, ['Summary'],INFO)
1291
+ description = process_simple_attribute(txt, ['Description'], INFO)
1292
+ abbreviation = process_simple_attribute(txt, ['Abbreviation'], INFO)
1293
+ examples = process_simple_attribute(txt, ['Examples'], INFO)
1294
+ usage = process_simple_attribute(txt, ['Usage'], INFO)
1463
1295
  status = process_simple_attribute(txt, ['Status'])
1464
1296
  status = status.upper() if status else 'DRAFT'
1465
- version = process_simple_attribute(txt, ['Version', "Version Identifier", "Published Version"])
1466
- q_name = process_simple_attribute(txt, ['Qualified Name'])
1297
+ version = process_simple_attribute(txt, ['Version', "Version Identifier", "Published Version"], INFO)
1298
+ q_name = process_simple_attribute(txt, ['Qualified Name'], INFO)
1299
+
1300
+ aliases = process_simple_attribute(txt, ['Aliases'], INFO)
1301
+ if aliases:
1302
+ alias_list = list(filter(None, re.split(r'[,\s]+', aliases.strip())))
1303
+ else:
1304
+ alias_list = None
1305
+
1306
+
1467
1307
 
1468
1308
  # validate term name and get existing qualified_name and guid if they exist
1469
1309
  if term_name is None:
@@ -1493,24 +1333,24 @@ def process_term_upsert_command(egeria_client: EgeriaTech, txt: str, directive:
1493
1333
  if categories: # Find information about categoriess that classify this term
1494
1334
  msg = "Checking for categories that classify this term"
1495
1335
  print_msg("DEBUG-INFO", msg, debug_level)
1496
- categories_list, cat_q_name_list, cat_valid, cat_exist = process_name_list(egeria_client,
1497
- 'Glossary Categories', txt,
1498
- CATEGORY_NAME_LABELS)
1499
- if cat_exist and cat_valid:
1336
+ categories_list, cat_q_name_list, cats_valid, cats_exist = process_name_list(egeria_client, 'Glossary Categories',
1337
+ txt, CATEGORY_NAME_LABELS)
1338
+ if cats_exist and cats_valid:
1500
1339
  msg = f"Found valid glossary categories to classify the term:\n\t{term_name}"
1501
1340
  print_msg("INFO", msg, debug_level)
1502
1341
  else:
1503
1342
  msg = "No valid glossary categories found."
1504
1343
  print_msg("INFO", msg, debug_level)
1505
1344
  else:
1506
- cat_exist = cat_valid = False
1345
+ cats_exist = cats_valid = False
1507
1346
  cat_q_name_list = None
1508
1347
 
1509
1348
  if object_action == "Update": # check to see if provided information exists and is consistent with existing info
1510
1349
  term_guid = process_simple_attribute(txt, GUID_LABELS)
1511
1350
  update_description = process_simple_attribute(txt, ['Update Description'])
1512
1351
  term_display = (f"\n* Command: {command}\n\t* Glossary: {known_glossary_q_name}\n\t"
1513
- f"* Term Name: {term_name}\n\t* Qualified Name: {q_name}\n\t* Categories: {categories}\n\t"
1352
+ f"* Term Name: {term_name}\n\t* Qualified Name: {q_name}\n\t* Aliases: {aliases}\n\t"
1353
+ f"* Categories: {categories}\n\t"
1514
1354
  f"* Summary: {summary}\n\t* Description: {description}\n\t"
1515
1355
  f"* Abbreviation: {abbreviation}\n\t* Examples: {examples}\n\t* Usage: {usage}\n\t"
1516
1356
  f"* Version: {version}\n\t* Status: {status}\n\t* GUID: {term_guid}"
@@ -1523,7 +1363,7 @@ def process_term_upsert_command(egeria_client: EgeriaTech, txt: str, directive:
1523
1363
  elif object_action == 'Create': # if the command is create, check that it doesn't already exist
1524
1364
  term_display = (f"\n* Command: {command}\n\t* Glossary: {known_glossary_q_name}\n\t"
1525
1365
  f"* Term Name: {term_name}\n\t* Categories: {categories}\n\t* Summary: {summary}\n\t"
1526
- f"* Qualified Name: {q_name}\n\t* Description: {description}\n\t"
1366
+ f"* Qualified Name: {q_name}\n\t* Aliases: {aliases}\n\t* Description: {description}\n\t"
1527
1367
  f"* Abbreviation: {abbreviation}\n\t* Examples: {examples}\n\t* Usage: {usage}\n\t"
1528
1368
  f"* Version: {version}\n\t* Status: {status}\n")
1529
1369
  if term_exists:
@@ -1548,20 +1388,20 @@ def process_term_upsert_command(egeria_client: EgeriaTech, txt: str, directive:
1548
1388
  if not term_exists:
1549
1389
  return None
1550
1390
  body = {
1551
- "class": "ReferenceableRequestBody", "elementProperties": {
1552
- "class": "GlossaryTermProperties", "qualifiedName": known_q_name, "summary": summary,
1391
+ "class": "ReferenceableRequestBody", "elementProperties": { "displayName": term_name,
1392
+ "class": "GlossaryTermProperties", "qualifiedName": known_q_name, "aliases": alias_list, "summary": summary,
1553
1393
  "description": description, "abbreviation": abbreviation, "examples": examples, "usage": usage,
1554
1394
  "publishVersionIdentifier": version, "status": status
1555
1395
  }, "updateDescription": update_description
1556
1396
  }
1557
- egeria_client.update_term(known_guid, body_slimmer(body))
1397
+ egeria_client.update_term(known_guid, body_slimmer(body), is_merge_update=False)
1558
1398
  # if cat_exist and cat_valid:
1559
1399
  update_term_categories(egeria_client, known_guid, cats_exist, cat_q_name_list)
1560
1400
  print_msg(ALWAYS,
1561
1401
  f"\tUpdated Term `{term_name}` with GUID {known_guid}\n\tand categories `{categories}`",
1562
1402
  debug_level)
1563
1403
  return egeria_client.get_term_by_guid(known_guid,
1564
- 'md') # return update_a_command(txt, command, object_type,
1404
+ 'md') # return update_a_command(txt, command, object_type,
1565
1405
  # known_q_name, known_guid)
1566
1406
  elif object_action == "Update" and directive == "validate": # is sthis reachable?
1567
1407
  return egeria_client.get_term_by_guid(known_guid, 'md')
@@ -1590,7 +1430,7 @@ def process_term_upsert_command(egeria_client: EgeriaTech, txt: str, directive:
1590
1430
  term_body = {
1591
1431
  "class": "ReferenceableRequestBody", "elementProperties": {
1592
1432
  "class": "GlossaryTermProperties", "qualifiedName": known_q_name, "displayName": term_name,
1593
- "summary": summary, "description": description, "abbreviation": abbreviation,
1433
+ "aliases": alias_list, "summary": summary, "description": description, "abbreviation": abbreviation,
1594
1434
  "examples": examples, "usage": usage, "publishVersionIdentifier": version
1595
1435
  # "additionalProperties":
1596
1436
  # {
@@ -1608,12 +1448,72 @@ def process_term_upsert_command(egeria_client: EgeriaTech, txt: str, directive:
1608
1448
  update_element_dictionary(known_q_name, {'guid': term_guid, 'display_name': term_name})
1609
1449
  print_msg(ALWAYS, f"Created term `{term_name}` with GUID {term_guid}", debug_level)
1610
1450
  return egeria_client.get_term_by_guid(term_guid,
1611
- 'MD') # return update_a_command(txt, command,
1451
+ 'MD') # return update_a_command(txt, command,
1612
1452
  # object_type, q_name, term_guid)
1613
1453
  except Exception as e:
1614
1454
  print(f"{ERROR}Error creating term {term_name}: {e}")
1615
1455
  console.print_exception(show_locals=True)
1616
1456
  return None
1457
+ else:
1458
+ return None
1459
+
1460
+
1461
+
1462
+
1463
+ def process_create_term_term_relationship_command(egeria_client: EgeriaTech, txt: str, directive: str = "display") -> Optional[str]:
1464
+ """ Relate two terms through the specified relationship. ."""
1465
+ set_debug_level(directive)
1466
+ valid = True
1467
+ command = extract_command(txt)
1468
+ object_type = command.split(' ')[1].strip()
1469
+ object_action = command.split(' ')[0].strip()
1470
+ term1_guid = None
1471
+ term2_guid = None
1472
+
1473
+
1474
+ term_relationship = process_simple_attribute(txt, ["Term Relationship"], "ERROR")
1475
+ if term_relationship not in TERM_RELATIONSHPS:
1476
+ valid = False
1477
+
1478
+ print(Markdown(f"{pre_command} `{command}` for term relationship: `{term_relationship}` with directive: `{directive}` "))
1479
+
1480
+ term1_q_name, term1_guid, term1_valid, term1_exists = process_element_identifiers(egeria_client, object_type, ["Term 1 Name"], txt,
1481
+ "Exists Required", None )
1482
+
1483
+ term2_q_name, term2_guid, term2_valid, term2_exists = process_element_identifiers(egeria_client, object_type, ["Term 2 Name"], txt,
1484
+ "Exists Required", None )
1485
+
1486
+ request_display = (f"\n\t* Term 1 Qualified Name: {term1_q_name}\n\t* Term 2 Qualified Name {term2_q_name}\n\t"
1487
+ f"* Term Relationship: {term_relationship}")
1488
+
1489
+ if not(term1_valid and term2_valid and term1_exists and term2_exists):
1490
+ valid = False
1491
+
1492
+ if directive == "display":
1493
+ print(request_display)
1494
+ return None
1495
+ elif directive == "validate":
1496
+ print(request_display)
1497
+ return str(valid)
1498
+ elif directive == "process":
1499
+ try:
1500
+ print(request_display)
1501
+ if not valid: # First validate the term before we process it
1502
+ return None
1503
+ egeria_client.add_relationship_between_terms(term1_guid, term2_guid, term_relationship)
1504
+ print_msg(ALWAYS, f"Relationship `{term_relationship}` created", debug_level)
1505
+ update_md = (f"\n\n# Update Term-Term Relationship\n\n## Term 1 Name:\n\n{term1_q_name}"
1506
+ f"\n\n## Term 2 Name\n\n{term2_q_name}\n\n## Term Relationship:\n\n{term_relationship}")
1507
+ return update_md
1508
+
1509
+
1510
+ except Exception as e:
1511
+ print(f"{ERROR}Error performing {command}: {e}")
1512
+ console.print_exception(show_locals=True)
1513
+ return None
1514
+ else:
1515
+ return None
1516
+
1617
1517
 
1618
1518
 
1619
1519
  def process_per_proj_upsert_command(egeria_client: ProjectManager, txt: str, directive: str = "display") -> str | None:
@@ -1765,3 +1665,339 @@ def process_per_proj_upsert_command(egeria_client: ProjectManager, txt: str, dir
1765
1665
  update_element_dictionary(q_name, {'guid': guid, 'display_name': project_name})
1766
1666
  print_msg(ALWAYS, f"Created project `{project_name}` with GUID {guid}", debug_level)
1767
1667
  return update_a_command(txt, command, object_type, q_name, guid)
1668
+
1669
+
1670
+ def process_term_list_command(egeria_client: EgeriaTech, txt: str, directive: str = "display") -> Optional[str]:
1671
+ """ List terms as a markdown table. Filter based on optional search string. """
1672
+ set_debug_level(directive)
1673
+ valid = True
1674
+ command = extract_command(txt)
1675
+
1676
+ search_string = process_simple_attribute(txt, SEARCH_LABELS)
1677
+ if search_string is None:
1678
+ search_string = '*'
1679
+ print(Markdown(f"{pre_command} `{command}` with search string:`{search_string}` with directive: `{directive}`"))
1680
+
1681
+ glossary = process_simple_attribute(txt, ['Glossary', 'In Glossary'])
1682
+ if glossary is not None:
1683
+ _, glossary_guid, _, glossary_exists = get_element_by_name(egeria_client, "Glossary", glossary)
1684
+ msg = f"Found glossary `{glossary}` with GUID {glossary_guid}"
1685
+ print_msg(INFO, msg, debug_level)
1686
+ else:
1687
+ glossary_guid = None
1688
+ msg = f"No glossary found"
1689
+ print_msg(INFO, msg, debug_level)
1690
+
1691
+ output_format = process_simple_attribute(txt, OUTPUT_LABELS)
1692
+ if output_format is None:
1693
+ output_format = "LIST"
1694
+ elif output_format not in ELEMENT_OUTPUT_FORMATS:
1695
+ valid = False
1696
+ print_msg(ERROR, f"Invalid output format: `{output_format}`", debug_level)
1697
+
1698
+ request_display = (f"\n\t* Search String: {search_string}\n\t* Glossary: {glossary}\n\t* Output Format: "
1699
+ f"{output_format}\n")
1700
+
1701
+ if directive == "display":
1702
+ print(Markdown(request_display))
1703
+ return None
1704
+ elif directive == "validate":
1705
+ print(Markdown(request_display))
1706
+ return valid
1707
+ elif directive == "process":
1708
+ try:
1709
+ print(Markdown(request_display))
1710
+ if not valid: # First validate the term before we process it
1711
+ return None
1712
+
1713
+ term_list_md = f"\n# Term List for search string: `{search_string}`\n\n"
1714
+ if output_format == "DICT":
1715
+ struct = egeria_client.find_glossary_terms(search_string, glossary_guid, output_format=output_format)
1716
+ term_list_md += f"```{json.dumps(struct, indent=4)}```\n"
1717
+ else:
1718
+ term_list_md += egeria_client.find_glossary_terms(search_string, glossary_guid,
1719
+ output_format=output_format)
1720
+ print_msg("ALWAYS", f"Wrote Term List for search string: `{search_string}`", debug_level)
1721
+
1722
+ return term_list_md
1723
+
1724
+ md_table = egeria_client.find_glossary_terms(search_string, glossary_guid, output_format=output_format)
1725
+
1726
+ print_msg("ALWAYS", f"Wrote Term list for search string `{search_string}`", debug_level)
1727
+ return md_table
1728
+
1729
+ except Exception as e:
1730
+ print(f"{ERROR}Error performing {command}: {e}")
1731
+ console.print_exception(show_locals=True)
1732
+ return None
1733
+ else:
1734
+ return None
1735
+
1736
+
1737
+ def process_category_list_command(egeria_client: EgeriaTech, txt: str, directive: str = "display") -> Optional[str]:
1738
+ """ List terms as a markdown table. Filter based on optional search string. """
1739
+ set_debug_level(directive)
1740
+ valid = True
1741
+ command = extract_command(txt)
1742
+
1743
+ search_string = process_simple_attribute(txt, SEARCH_LABELS, "INFO")
1744
+ if search_string is None:
1745
+ search_string = '*'
1746
+ print(Markdown(f"{pre_command} `{command}` with search string:`{search_string}` with directive: `{directive}`"))
1747
+
1748
+ output_format = process_simple_attribute(txt, OUTPUT_LABELS, "INFO")
1749
+ if output_format is None:
1750
+ output_format = "LIST"
1751
+ elif output_format not in ELEMENT_OUTPUT_FORMATS:
1752
+ valid = False
1753
+ print_msg(ERROR, f"Invalid output format: `{output_format}`", debug_level)
1754
+
1755
+ request_display = f"\n\t* Search String: {search_string}\n\t* Output Format: {output_format}\n"
1756
+
1757
+ if directive == "display":
1758
+ print(Markdown(request_display))
1759
+ return None
1760
+ elif directive == "validate":
1761
+ print(Markdown(request_display))
1762
+ return valid
1763
+ elif directive == "process":
1764
+ try:
1765
+ print(Markdown(request_display))
1766
+ if not valid: # First validate the term before we process it
1767
+ return None
1768
+
1769
+ cat_list_md = f"\n# Category List for search string: `{search_string}`\n\n"
1770
+ if output_format == "DICT":
1771
+ struct = egeria_client.find_glossary_categories(search_string, output_format=output_format)
1772
+ cat_list_md += f"```{json.dumps(struct, indent=4)}```\n"
1773
+ else:
1774
+ cat_list_md += egeria_client.find_glossary_categories(search_string, output_format=output_format)
1775
+ print_msg("ALWAYS", f"Wrote Category List for search string: `{search_string}`", debug_level)
1776
+
1777
+ return cat_list_md
1778
+
1779
+ except Exception as e:
1780
+ print(f"{ERROR}Error performing {command}: {e}")
1781
+ console.print_exception(show_locals=True)
1782
+ return None
1783
+ else:
1784
+
1785
+ return None
1786
+
1787
+
1788
+ def process_glossary_structure_command(egeria_client: EgeriaTech, txt: str, directive: str = "display") -> Optional[str]:
1789
+ """ List terms as a markdown table. Filter based on optional search string. """
1790
+ set_debug_level(directive)
1791
+ valid = True
1792
+ command = extract_command(txt)
1793
+
1794
+ known_glossary_guid = ""
1795
+
1796
+ glossary_name = process_simple_attribute(txt, GLOSSARY_NAME_LABELS, "ERROR")
1797
+
1798
+ _, known_glossary_guid, valid, _ = process_element_identifiers(egeria_client, "Glossary", GLOSSARY_NAME_LABELS, txt,
1799
+ EXISTS_REQUIRED, None)
1800
+
1801
+ print(Markdown(f"{pre_command} `{command}` for glossary:`{glossary_name}` with directive: `{directive}`"))
1802
+
1803
+ output_format = process_simple_attribute(txt, OUTPUT_LABELS, "INFO")
1804
+ if output_format is None:
1805
+ output_format = "MD"
1806
+ elif output_format not in ["DICT", "LIST", "MD"]:
1807
+ valid = False
1808
+ print_msg(ERROR, f"Invalid output format: `{output_format}`", debug_level)
1809
+
1810
+ request_display = f"\n\t* Glossary name: {glossary_name}\n\t* Output Format: {output_format}\n"
1811
+
1812
+ if directive == "display":
1813
+ print(Markdown(request_display))
1814
+ return None
1815
+ elif directive == "validate":
1816
+ print(Markdown(request_display))
1817
+ return str(valid)
1818
+ elif directive == "process":
1819
+ try:
1820
+ print(Markdown(request_display))
1821
+ if not valid: # First validate the term before we process it
1822
+ return None
1823
+
1824
+ glossary_structure_md = f"\n# Glossary Structure for `{glossary_name}`\n\n"
1825
+ if output_format == "DICT":
1826
+ struct = egeria_client.get_glossary_category_structure(known_glossary_guid, output_format=output_format)
1827
+ glossary_structure_md += f"```{json.dumps(struct, indent=4)}```\n"
1828
+ else:
1829
+ glossary_structure_md += egeria_client.get_glossary_category_structure(known_glossary_guid,
1830
+ output_format=output_format)
1831
+ print_msg("ALWAYS", f"Wrote Glossary Structure for glossary: `{glossary_name}`", debug_level)
1832
+
1833
+ return glossary_structure_md
1834
+
1835
+ except Exception as e:
1836
+ print(f"{ERROR}Error performing {command}: {e}")
1837
+ console.print_exception(show_locals=True)
1838
+ return None
1839
+ else:
1840
+ return None
1841
+
1842
+
1843
+ def process_glossary_list_command(egeria_client: EgeriaTech, txt: str, directive: str = "display") -> Optional[str]:
1844
+ """ List terms as a markdown table. Filter based on optional search string. """
1845
+ set_debug_level(directive)
1846
+ valid = True
1847
+ command = extract_command(txt)
1848
+
1849
+ search_string = process_simple_attribute(txt, SEARCH_LABELS, "INFO")
1850
+ if search_string is None:
1851
+ search_string = '*'
1852
+ print(Markdown(f"{pre_command} `{command}` with search string:`{search_string}` with directive: `{directive}`"))
1853
+ if search_string is None:
1854
+ search_string = '*'
1855
+
1856
+ output_format = process_simple_attribute(txt, OUTPUT_LABELS, "INFO")
1857
+ if output_format is None:
1858
+ output_format = "LIST"
1859
+ elif output_format not in ELEMENT_OUTPUT_FORMATS:
1860
+ valid = False
1861
+ print_msg(ERROR, f"Invalid output format: `{output_format}`", debug_level)
1862
+
1863
+ request_display = f"\n\t* Search String: {search_string}\n\t* Output Format: {output_format}\n"
1864
+
1865
+ if directive == "display":
1866
+ print(request_display)
1867
+ return None
1868
+ elif directive == "validate":
1869
+ print(request_display)
1870
+ return valid
1871
+ elif directive == "process":
1872
+ try:
1873
+ print(request_display)
1874
+ if not valid: # First validate the term before we process it
1875
+ return None
1876
+
1877
+ glossary_list_md = f"\n# Glossary List for `{search_string}`\n\n"
1878
+ if output_format == "DICT":
1879
+ struct = egeria_client.find_glossaries(search_string, output_format=output_format)
1880
+ glossary_list_md += f"```{json.dumps(struct, indent=4)}```\n"
1881
+ else:
1882
+ glossary_list_md += egeria_client.find_glossaries(search_string, output_format=output_format)
1883
+ print_msg("ALWAYS", f"Wrote Glossary List for search string: `{search_string}`", debug_level)
1884
+
1885
+ return glossary_list_md
1886
+
1887
+ except Exception as e:
1888
+ print(f"{ERROR}Error performing {command}: {e}")
1889
+ console.print_exception(show_locals=True)
1890
+ return None
1891
+ else:
1892
+ return None
1893
+
1894
+
1895
+ def process_term_history_command(egeria_client: EgeriaTech, txt: str, directive: str = "display") -> Optional[str]:
1896
+ """ List terms as a markdown table. Filter based on optional search string. """
1897
+ set_debug_level(directive)
1898
+ valid = True
1899
+ command = extract_command(txt)
1900
+ object_type = command.split(' ')[1].strip()
1901
+ object_action = command.split(' ')[0].strip()
1902
+
1903
+ element_labels = TERM_NAME_LABELS
1904
+ element_labels.append('Display Name')
1905
+
1906
+ term_name = process_simple_attribute(txt, element_labels, "ERROR")
1907
+
1908
+ known_q_name, known_guid, valid, term_exists = process_element_identifiers(egeria_client, object_type,
1909
+ element_labels, txt, object_action, )
1910
+
1911
+ print(Markdown(f"{pre_command} `{command}` for term:`{term_name}` with directive: `{directive}`"))
1912
+
1913
+ output_format = process_simple_attribute(txt, OUTPUT_LABELS, "INFO")
1914
+ if output_format is None:
1915
+ output_format = "LIST"
1916
+ elif output_format not in ["DICT", "LIST"]:
1917
+ valid = False
1918
+ print_msg(ERROR, f"Invalid output format: `{output_format}`", debug_level)
1919
+
1920
+ request_display = f"\n\t* Term Name: {term_name}\n\t* Output Format {output_format}\n\t* GUID: {known_guid}\n"
1921
+
1922
+ if directive == "display":
1923
+ print(request_display)
1924
+ return None
1925
+ elif directive == "validate":
1926
+ print(request_display)
1927
+ return valid
1928
+ elif directive == "process":
1929
+ try:
1930
+ print(request_display)
1931
+ if not valid: # First validate the term before we process it
1932
+ return None
1933
+ term_history_md = f"\n# Term History for `{term_name}`\n\n"
1934
+ if output_format == "DICT":
1935
+ struct = egeria_client.list_term_revision_history(known_guid, output_format=output_format)
1936
+ term_history_md += f"```{json.dumps(struct, indent=4)}```\n"
1937
+ else:
1938
+ term_history_md += egeria_client.list_full_term_history(known_guid, output_format)
1939
+ print_msg("ALWAYS", f"Wrote Term History for term `{term_name}`", debug_level)
1940
+
1941
+ return term_history_md
1942
+
1943
+ except Exception as e:
1944
+ print(f"{ERROR}Error performing {command}: {e}")
1945
+ console.print_exception(show_locals=True)
1946
+ return None
1947
+ else:
1948
+ return None
1949
+
1950
+
1951
+ def process_term_revision_history_command(egeria_client: EgeriaTech, txt: str, directive: str = "display") -> Optional[str]:
1952
+ """ List term revision history as a markdown table or list."""
1953
+ set_debug_level(directive)
1954
+ valid = True
1955
+ command = extract_command(txt)
1956
+ object_type = command.split(' ')[1].strip()
1957
+ object_action = command.split(' ')[0].strip()
1958
+ known_q_name = None
1959
+ known_guid = None
1960
+
1961
+ element_labels = TERM_NAME_LABELS
1962
+
1963
+ term_name = process_simple_attribute(txt, element_labels, "ERROR")
1964
+ print(Markdown(f"{pre_command} `{command}` for term: `{term_name}` with directive: `{directive}` "))
1965
+
1966
+ known_q_name, known_guid, valid, _ = process_element_identifiers(egeria_client, object_type, element_labels, txt,
1967
+ object_action, )
1968
+ output_format = process_simple_attribute(txt, ['Output Format', 'Format'], 'INFO')
1969
+ if output_format is None:
1970
+ output_format = "LIST"
1971
+ elif output_format not in ["DICT", "LIST", "MD"]:
1972
+ valid = False
1973
+ print_msg(ERROR, f"Invalid output format: `{output_format}`", debug_level)
1974
+
1975
+ request_display = f"\n\t* Term Name: {term_name}\n\t* Output Format: {output_format}\n"
1976
+
1977
+ if directive == "display":
1978
+ print(request_display)
1979
+ return None
1980
+ elif directive == "validate":
1981
+ print(request_display)
1982
+ return str(valid)
1983
+ elif directive == "process":
1984
+ try:
1985
+ print(request_display)
1986
+ if not valid: # First validate the term before we process it
1987
+ return None
1988
+ term_history_md = f"\n# Term Revision History for `{term_name}`\n\n"
1989
+ if output_format == "DICT":
1990
+ struct = egeria_client.list_term_revision_history(known_guid, output_format)
1991
+ term_history_md += f"```{json.dumps(struct, indent=4)}```\n"
1992
+ else:
1993
+ term_history_md += egeria_client.list_term_revision_history(known_guid, output_format)
1994
+ print_msg("ALWAYS", f"Wrote Term Revision History for term `{term_name}`", debug_level)
1995
+ return term_history_md
1996
+
1997
+ except Exception as e:
1998
+ print(f"{ERROR}Error performing {command}: {e}")
1999
+ console.print_exception(show_locals=True)
2000
+ return None
2001
+ else:
2002
+ return None
2003
+