pyegeria 5.3.8.9__py3-none-any.whl → 5.3.9.1__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.
- pyegeria/__init__.py +2 -1
- pyegeria/commands/cat/dr_egeria_md.py +7 -2
- pyegeria/commands/cat/list_terms.py +3 -2
- pyegeria/glossary_browser_omvs.py +401 -135
- pyegeria/glossary_manager_omvs.py +409 -2
- pyegeria/md_processing_utils.py +610 -458
- {pyegeria-5.3.8.9.dist-info → pyegeria-5.3.9.1.dist-info}/METADATA +2 -2
- {pyegeria-5.3.8.9.dist-info → pyegeria-5.3.9.1.dist-info}/RECORD +11 -11
- {pyegeria-5.3.8.9.dist-info → pyegeria-5.3.9.1.dist-info}/LICENSE +0 -0
- {pyegeria-5.3.8.9.dist-info → pyegeria-5.3.9.1.dist-info}/WHEEL +0 -0
- {pyegeria-5.3.8.9.dist-info → pyegeria-5.3.9.1.dist-info}/entry_points.txt +0 -0
pyegeria/md_processing_utils.py
CHANGED
@@ -25,12 +25,12 @@ from pyegeria.project_manager_omvs import ProjectManager
|
|
25
25
|
EGERIA_WIDTH = int(os.environ.get("EGERIA_WIDTH", "170"))
|
26
26
|
console = Console(width=EGERIA_WIDTH)
|
27
27
|
|
28
|
-
command_list = ["Provenance", "Create Glossary", "Update Glossary", "Create Term", "Update Term", "List Terms",
|
28
|
+
command_list = ["Provenance", "Create Glossary", "Update Glossary", "Create Term", "Update Term", "List Terms", "List Term Details",
|
29
29
|
"List Glossary Terms", "List Term History", "List Term Revision History", "List Term Update History",
|
30
30
|
"List Glossary Structure", "List Glossaries", "List Categories", "List Glossary Categories",
|
31
31
|
"Create Personal Project", "Update Personal Project", "Create Category", "Update Category",
|
32
32
|
"Create Solution Blueprint", "Update Solution Blueprint", "Create Solution Component",
|
33
|
-
"Update Solution Component", ]
|
33
|
+
"Update Solution Component", "Create Term-Term Relationship", "Update Term-Term Relationship",]
|
34
34
|
# verbosity - verbose, quiet, debug
|
35
35
|
debug_level = "debug"
|
36
36
|
message_types = {
|
@@ -69,7 +69,19 @@ SEARCH_LABELS = ['Search String', 'Filter']
|
|
69
69
|
GUID_LABELS = ['GUID', 'guid']
|
70
70
|
|
71
71
|
ELEMENT_OUTPUT_FORMATS = ["LIST", "DICT", "MD", "FORM", "REPORT"]
|
72
|
-
|
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
|
+
]
|
73
85
|
|
74
86
|
def render_markdown(markdown_text: str) -> None:
|
75
87
|
"""Renders the given markdown text in the console."""
|
@@ -348,8 +360,7 @@ def update_a_command(txt: str, command: str, obj_type: str, q_name: str, u_guid:
|
|
348
360
|
verb = command.split(' ')[0].strip()
|
349
361
|
action = "Update" if (verb == "Create" and u_guid is not None) else "Create"
|
350
362
|
txt = txt.replace(f"{command}", f'{action} {obj_type}\n') # update the command
|
351
|
-
|
352
|
-
txt = txt.replace('<Qualified Name>', f"Qualified Name\n{q_name}")
|
363
|
+
|
353
364
|
if "Qualified Name" not in txt:
|
354
365
|
txt += f"\n## Qualified Name\n{q_name}\n"
|
355
366
|
if "GUID" not in txt:
|
@@ -535,8 +546,8 @@ def get_element_by_name(egeria_client, element_type: str, element_name: str) ->
|
|
535
546
|
unique = True
|
536
547
|
return el_qname, el_guid, unique, exists
|
537
548
|
|
538
|
-
# Convert element_type to plural form for method name construction # if element_type.endswith('y'): # # #
|
539
|
-
# plural_type = f"{element_type[:-1]}ies" # elif element_type.endswith('s'): # plural_type = f"{ # #
|
549
|
+
# Convert element_type to plural form for method name construction # if element_type.endswith('y'): # # # #
|
550
|
+
# plural_type = f"{element_type[:-1]}ies" # elif element_type.endswith('s'): # plural_type = f"{ # # #
|
540
551
|
# element_type}es" # else: # plural_type = f"{element_type}s" # # # Construct method name # method_name
|
541
552
|
# = f"get_{plural_type}_by_name" # # # Check if the method exists on the client # if hasattr(egeria_client,
|
542
553
|
# method_name): # # Call the method # method = getattr(egeria_client, method_name) # result = #
|
@@ -682,11 +693,11 @@ def process_blueprint_upsert_command(egeria_client: EgeriaTech, txt: str, direct
|
|
682
693
|
print_msg("ALWAYS", msg, debug_level)
|
683
694
|
|
684
695
|
# update with get blueprint by guid
|
685
|
-
return 'Would return get blueprint by guid and return md' # egeria_client.get_term_by_guid( # #
|
696
|
+
return 'Would return get blueprint by guid and return md' # egeria_client.get_term_by_guid( # # #
|
686
697
|
# known_guid, 'md')
|
687
698
|
|
688
699
|
elif object_action == "Update" and directive == "validate":
|
689
|
-
return 'Would call get_blueprint_by_guid and return md' # egeria_client.get_term_by_guid( # #
|
700
|
+
return 'Would call get_blueprint_by_guid and return md' # egeria_client.get_term_by_guid( # # #
|
690
701
|
# known_guid, 'md')
|
691
702
|
|
692
703
|
elif object_action == "Create":
|
@@ -707,12 +718,16 @@ def process_blueprint_upsert_command(egeria_client: EgeriaTech, txt: str, direct
|
|
707
718
|
update_element_dictionary(q_name, {'guid': new_guid, 'display_name': display_name})
|
708
719
|
return 'Would return get blueprint by guid results as md' # egeria_client.get_term_by_guid( #
|
709
720
|
# term_guid, 'MD')
|
721
|
+
else:
|
722
|
+
return None
|
710
723
|
|
711
724
|
except Exception as e:
|
712
725
|
msg = f"{ERROR}Error creating term {display_name}: {e}"
|
713
726
|
print_msg("ERROR", msg, debug_level)
|
714
727
|
console.print_exception(show_locals=True)
|
715
728
|
return None
|
729
|
+
else:
|
730
|
+
return None
|
716
731
|
|
717
732
|
|
718
733
|
def process_solution_component_upsert_command(egeria_client: EgeriaTech, txt: str, directive: str = "display") -> \
|
@@ -775,7 +790,10 @@ Optional[str]:
|
|
775
790
|
print_msg("INFO", msg, debug_level)
|
776
791
|
else:
|
777
792
|
parent_components, parent_qname_list, parents_valid, parent_components_exist = process_name_list(egeria_client,
|
778
|
-
|
793
|
+
'Parent '
|
794
|
+
'Components',
|
795
|
+
txt,
|
796
|
+
COMPONENT_NAME_LABELS)
|
779
797
|
if parent_components_exist and parents_valid:
|
780
798
|
msg = f"Found valid parent components that include this solution component:\n\t{parent_qname_list}"
|
781
799
|
print_msg("INFO", msg, debug_level)
|
@@ -848,11 +866,11 @@ Optional[str]:
|
|
848
866
|
msg = f"\nUpdated Solution Component `{display_name}` with GUID {known_guid}"
|
849
867
|
print_msg("ALWAYS", msg, debug_level)
|
850
868
|
# update with get solution component by guid
|
851
|
-
return 'Would return get Solution Component by guid and return md' # # #
|
869
|
+
return 'Would return get Solution Component by guid and return md' # # # #
|
852
870
|
# egeria_client.get_term_by_guid(known_guid, 'md')
|
853
871
|
|
854
872
|
elif object_action == "Update" and directive == "validate":
|
855
|
-
return 'Would call get_blueprint_by_guid and return md' # egeria_client.get_term_by_guid( # #
|
873
|
+
return 'Would call get_blueprint_by_guid and return md' # egeria_client.get_term_by_guid( # # #
|
856
874
|
# known_guid, 'md')
|
857
875
|
|
858
876
|
elif object_action == "Create":
|
@@ -870,7 +888,7 @@ Optional[str]:
|
|
870
888
|
msg = f"\nCreated Solution Component `{display_name}` with GUID {known_guid}"
|
871
889
|
print_msg("ALWAYS", msg, debug_level)
|
872
890
|
update_element_dictionary(known_q_name, {'guid': known_guid, 'display_name': display_name})
|
873
|
-
return 'Would return get solution component by guid results as md' # # #
|
891
|
+
return 'Would return get solution component by guid results as md' # # # #
|
874
892
|
# egeria_client.get_term_by_guid(term_guid, 'MD')
|
875
893
|
|
876
894
|
except Exception as e:
|
@@ -878,7 +896,8 @@ Optional[str]:
|
|
878
896
|
print_msg("ERROR", msg, debug_level)
|
879
897
|
console.print_exception(show_locals=True)
|
880
898
|
return None
|
881
|
-
|
899
|
+
else:
|
900
|
+
return None
|
882
901
|
|
883
902
|
def process_glossary_upsert_command(egeria_client: EgeriaTech, txt: str, directive: str = "display") -> Optional[str]:
|
884
903
|
"""
|
@@ -894,14 +913,15 @@ def process_glossary_upsert_command(egeria_client: EgeriaTech, txt: str, directi
|
|
894
913
|
command, object_type, object_action = extract_command_plus(txt)
|
895
914
|
set_debug_level(directive)
|
896
915
|
|
897
|
-
glossary_name = process_simple_attribute(txt, GLOSSARY_NAME_LABELS)
|
916
|
+
glossary_name = process_simple_attribute(txt, GLOSSARY_NAME_LABELS, ERROR)
|
898
917
|
print(Markdown(
|
899
918
|
f"{pre_command} `{object_action}` `{object_type}` for glossary: `\'{glossary_name}\'` with directive: `"
|
900
919
|
f"{directive}` "))
|
901
|
-
language = process_simple_attribute(txt, ['Language'])
|
902
|
-
description = process_simple_attribute(txt, ['Description'])
|
903
|
-
usage = process_simple_attribute(txt, ['Usage'])
|
904
|
-
q_name = process_simple_attribute(txt, ['Qualified Name'])
|
920
|
+
language = process_simple_attribute(txt, ['Language'], INFO)
|
921
|
+
description = process_simple_attribute(txt, ['Description'], INFO)
|
922
|
+
usage = process_simple_attribute(txt, ['Usage'], INFO)
|
923
|
+
q_name = process_simple_attribute(txt, ['Qualified Name'], INFO)
|
924
|
+
valid = True
|
905
925
|
|
906
926
|
if glossary_name is None:
|
907
927
|
valid = False
|
@@ -957,11 +977,13 @@ def process_glossary_upsert_command(egeria_client: EgeriaTech, txt: str, directi
|
|
957
977
|
if valid:
|
958
978
|
print(Markdown(glossary_display))
|
959
979
|
else:
|
960
|
-
|
961
|
-
|
962
|
-
|
963
|
-
|
964
|
-
|
980
|
+
if glossary_exists and object_action == "Create":
|
981
|
+
msg = f"Create failed because glossary `{glossary_name}` exists - changing `Create` to `Update` in processed output \n"
|
982
|
+
print_msg(ERROR, msg, debug_level)
|
983
|
+
print(Markdown(glossary_display))
|
984
|
+
return update_a_command(txt, command, object_type, known_q_name, known_guid)
|
985
|
+
else:
|
986
|
+
return None
|
965
987
|
if object_action == "Update":
|
966
988
|
if not glossary_exists:
|
967
989
|
print(f"\n{ERROR}Glossary `{glossary_name}` does not exist! Updating result document with Create "
|
@@ -1053,7 +1075,7 @@ def process_category_upsert_command(egeria_client: EgeriaTech, txt: str, directi
|
|
1053
1075
|
|
1054
1076
|
if parent_category_name:
|
1055
1077
|
_, parent_guid, parent_valid, parent_exists = get_element_by_name(egeria_client, 'Glossary Categories',
|
1056
|
-
|
1078
|
+
parent_category_name)
|
1057
1079
|
else:
|
1058
1080
|
parent_guid = None
|
1059
1081
|
parent_exists = False
|
@@ -1102,10 +1124,13 @@ def process_category_upsert_command(egeria_client: EgeriaTech, txt: str, directi
|
|
1102
1124
|
if valid:
|
1103
1125
|
print(Markdown(category_display))
|
1104
1126
|
else:
|
1105
|
-
|
1106
|
-
|
1107
|
-
|
1108
|
-
|
1127
|
+
if category_exists and object_action == "Create":
|
1128
|
+
msg = f"Create failed because category `{category_name}` exists - changing `Create` to `Update` in processed output \n"
|
1129
|
+
print_msg(ERROR, msg, debug_level)
|
1130
|
+
print(Markdown(category_display))
|
1131
|
+
return update_a_command(txt, command, object_type, known_q_name, known_guid)
|
1132
|
+
else:
|
1133
|
+
return None
|
1109
1134
|
|
1110
1135
|
if object_action == "Update":
|
1111
1136
|
if not category_exists:
|
@@ -1152,7 +1177,7 @@ def process_category_upsert_command(egeria_client: EgeriaTech, txt: str, directi
|
|
1152
1177
|
'guid': category_guid, 'display_name': category_name
|
1153
1178
|
})
|
1154
1179
|
print_msg(ALWAYS, f"Created Category `{category_name}` with GUID {category_guid}", debug_level)
|
1155
|
-
if parent_valid
|
1180
|
+
if parent_valid and parent_guid:
|
1156
1181
|
egeria_client.set_parent_category(parent_guid, category_guid)
|
1157
1182
|
print_msg(ALWAYS, f"Set parent category for `{category_name}` to `{parent_category_name}`",
|
1158
1183
|
debug_level)
|
@@ -1198,7 +1223,7 @@ def update_category_parent(egeria_client, category_guid: str, parent_category_na
|
|
1198
1223
|
if isinstance(current_parent, str) and "No Parent Category found" in current_parent:
|
1199
1224
|
# No parent currently set, need to set it
|
1200
1225
|
_, parent_guid, _, parent_exists = get_element_by_name(egeria_client, 'Glossary Categories',
|
1201
|
-
|
1226
|
+
parent_category_name)
|
1202
1227
|
|
1203
1228
|
if parent_exists and parent_guid:
|
1204
1229
|
egeria_client.set_parent_category(parent_guid, category_guid)
|
@@ -1219,7 +1244,7 @@ def update_category_parent(egeria_client, category_guid: str, parent_category_na
|
|
1219
1244
|
|
1220
1245
|
# Then set the new parent
|
1221
1246
|
_, parent_guid, _, parent_exists = get_element_by_name(egeria_client, 'Glossary Categories',
|
1222
|
-
|
1247
|
+
parent_category_name)
|
1223
1248
|
|
1224
1249
|
if parent_exists and parent_guid:
|
1225
1250
|
egeria_client.set_parent_category(parent_guid, category_guid)
|
@@ -1245,170 +1270,471 @@ def update_category_parent(egeria_client, category_guid: str, parent_category_na
|
|
1245
1270
|
return outcome
|
1246
1271
|
|
1247
1272
|
|
1248
|
-
def
|
1249
|
-
"""
|
1250
|
-
|
1273
|
+
def process_term_upsert_command(egeria_client: EgeriaTech, txt: str, directive: str = "display") -> Optional[str]:
|
1274
|
+
"""
|
1275
|
+
Processes a term create or update command by extracting key attributes such as
|
1276
|
+
term name, summary, description, abbreviation, examples, usage, version, and status from the given cell.
|
1277
|
+
|
1278
|
+
:param txt: A string representing the input cell to be processed for
|
1279
|
+
extracting glossary-related attributes.
|
1280
|
+
:param directive: an optional string indicating the directive to be used - display, validate or execute
|
1281
|
+
:return: A string summarizing the outcome of the processing.
|
1282
|
+
"""
|
1251
1283
|
valid = True
|
1284
|
+
categories_list = None
|
1285
|
+
cats_exist = False
|
1286
|
+
set_debug_level(directive)
|
1287
|
+
known_q_name = None
|
1252
1288
|
command = extract_command(txt)
|
1289
|
+
object_type = command.split(' ')[1].strip()
|
1290
|
+
object_action = command.split(' ')[0].strip()
|
1253
1291
|
|
1254
|
-
|
1255
|
-
|
1256
|
-
|
1257
|
-
|
1292
|
+
term_name = process_simple_attribute(txt, ['Term Name', 'Display Name'], ERROR)
|
1293
|
+
print(Markdown(f"{pre_command} `{command}` for term:`{term_name}` with directive: `{directive}`"))
|
1294
|
+
summary = process_simple_attribute(txt, ['Summary'],INFO)
|
1295
|
+
description = process_simple_attribute(txt, ['Description'], INFO)
|
1296
|
+
abbreviation = process_simple_attribute(txt, ['Abbreviation'], INFO)
|
1297
|
+
examples = process_simple_attribute(txt, ['Examples'], INFO)
|
1298
|
+
usage = process_simple_attribute(txt, ['Usage'], INFO)
|
1299
|
+
status = process_simple_attribute(txt, ['Status'])
|
1300
|
+
status = status.upper() if status else 'DRAFT'
|
1301
|
+
version = process_simple_attribute(txt, ['Version', "Version Identifier", "Published Version"], INFO)
|
1302
|
+
q_name = process_simple_attribute(txt, ['Qualified Name'], INFO)
|
1258
1303
|
|
1259
|
-
|
1260
|
-
if
|
1261
|
-
|
1262
|
-
msg = f"Found glossary `{glossary}` with GUID {glossary_guid}"
|
1263
|
-
print_msg(INFO, msg, debug_level)
|
1304
|
+
aliases = process_simple_attribute(txt, ['Aliases','Alias'], INFO)
|
1305
|
+
if aliases:
|
1306
|
+
alias_list = list(filter(None, re.split(r'[,\s]+', aliases.strip())))
|
1264
1307
|
else:
|
1265
|
-
|
1266
|
-
msg = f"No glossary found"
|
1267
|
-
print_msg(INFO, msg, debug_level)
|
1308
|
+
alias_list = None
|
1268
1309
|
|
1269
|
-
|
1270
|
-
|
1271
|
-
|
1272
|
-
|
1310
|
+
|
1311
|
+
|
1312
|
+
# validate term name and get existing qualified_name and guid if they exist
|
1313
|
+
if term_name is None:
|
1273
1314
|
valid = False
|
1274
|
-
|
1315
|
+
known_q_name, known_guid, term_exists = None
|
1316
|
+
else:
|
1317
|
+
element_labels = TERM_NAME_LABELS
|
1318
|
+
element_labels.append('Display Name')
|
1319
|
+
known_q_name, known_guid, valid, term_exists = process_element_identifiers(egeria_client, object_type,
|
1320
|
+
element_labels, txt, object_action,
|
1321
|
+
version)
|
1275
1322
|
|
1276
|
-
|
1277
|
-
|
1323
|
+
# get the glossary qualified name this term is in
|
1324
|
+
glossary_name = process_simple_attribute(txt, GLOSSARY_NAME_LABELS, ERROR)
|
1325
|
+
if glossary_name is None:
|
1326
|
+
valid = False
|
1327
|
+
known_glossary_guid = None
|
1328
|
+
known_glossary_q_name = None
|
1329
|
+
glossary_valid = False
|
1330
|
+
glossary_exists = False
|
1331
|
+
else:
|
1332
|
+
known_glossary_q_name, known_glossary_guid, glossary_valid, glossary_exists = process_element_identifiers(
|
1333
|
+
egeria_client, "Glossary", GLOSSARY_NAME_LABELS, txt, EXISTS_REQUIRED, None)
|
1334
|
+
|
1335
|
+
# process categories, if present
|
1336
|
+
categories = process_simple_attribute(txt, ['Glossary Categories', 'Glossary Category', 'Category', 'Categories'])
|
1337
|
+
if categories: # Find information about categoriess that classify this term
|
1338
|
+
msg = "Checking for categories that classify this term"
|
1339
|
+
print_msg("DEBUG-INFO", msg, debug_level)
|
1340
|
+
categories_list, cat_q_name_list, cats_valid, cats_exist = process_name_list(egeria_client, 'Glossary Categories',
|
1341
|
+
txt, CATEGORY_NAME_LABELS)
|
1342
|
+
if cats_exist and cats_valid:
|
1343
|
+
msg = f"Found valid glossary categories to classify the term:\n\t{term_name}"
|
1344
|
+
print_msg("INFO", msg, debug_level)
|
1345
|
+
else:
|
1346
|
+
msg = "No valid glossary categories found."
|
1347
|
+
print_msg("INFO", msg, debug_level)
|
1348
|
+
else:
|
1349
|
+
cats_exist = cats_valid = False
|
1350
|
+
cat_q_name_list = None
|
1351
|
+
|
1352
|
+
if object_action == "Update": # check to see if provided information exists and is consistent with existing info
|
1353
|
+
term_guid = process_simple_attribute(txt, GUID_LABELS)
|
1354
|
+
update_description = process_simple_attribute(txt, ['Update Description'])
|
1355
|
+
term_display = (f"\n* Command: {command}\n\t* Glossary: {known_glossary_q_name}\n\t"
|
1356
|
+
f"* Term Name: {term_name}\n\t* Qualified Name: {q_name}\n\t* Aliases: {aliases}\n\t"
|
1357
|
+
f"* Categories: {categories}\n\t"
|
1358
|
+
f"* Summary: {summary}\n\t* Description: {description}\n\t"
|
1359
|
+
f"* Abbreviation: {abbreviation}\n\t* Examples: {examples}\n\t* Usage: {usage}\n\t"
|
1360
|
+
f"* Version: {version}\n\t* Status: {status}\n\t* GUID: {term_guid}"
|
1361
|
+
f"\n\t* Update Description: {update_description}\n")
|
1362
|
+
if not term_exists:
|
1363
|
+
msg = f"Update request invalid, Term {term_name} does not exist\n"
|
1364
|
+
print_msg(ERROR, msg, debug_level)
|
1365
|
+
valid = False
|
1366
|
+
|
1367
|
+
elif object_action == 'Create': # if the command is create, check that it doesn't already exist
|
1368
|
+
term_display = (f"\n* Command: {command}\n\t* Glossary: {known_glossary_q_name}\n\t"
|
1369
|
+
f"* Term Name: {term_name}\n\t* Categories: {categories}\n\t* Summary: {summary}\n\t"
|
1370
|
+
f"* Qualified Name: {q_name}\n\t* Aliases: {aliases}\n\t* Description: {description}\n\t"
|
1371
|
+
f"* Abbreviation: {abbreviation}\n\t* Examples: {examples}\n\t* Usage: {usage}\n\t"
|
1372
|
+
f"* Version: {version}\n\t* Status: {status}\n")
|
1373
|
+
if term_exists:
|
1374
|
+
msg = f"Term `{term_name}` cannot be created since it already exists\n"
|
1375
|
+
print_msg(ERROR, msg, debug_level)
|
1376
|
+
else:
|
1377
|
+
msg = f"It is valid to create Term `{term_name}`"
|
1378
|
+
print_msg(ALWAYS, msg, debug_level)
|
1278
1379
|
|
1279
1380
|
if directive == "display":
|
1280
|
-
print(Markdown(
|
1381
|
+
print(Markdown(term_display))
|
1281
1382
|
return None
|
1282
1383
|
elif directive == "validate":
|
1283
|
-
print(Markdown(
|
1384
|
+
print(Markdown(term_display))
|
1284
1385
|
return valid
|
1285
1386
|
elif directive == "process":
|
1286
1387
|
try:
|
1287
|
-
print(Markdown(request_display))
|
1288
1388
|
if not valid: # First validate the term before we process it
|
1289
|
-
|
1290
|
-
|
1291
|
-
|
1292
|
-
|
1293
|
-
|
1294
|
-
|
1295
|
-
|
1296
|
-
term_list_md += egeria_client.find_glossary_terms(search_string, glossary_guid, output_format=output_format)
|
1297
|
-
print_msg("ALWAYS", f"Wrote Term List for search string: `{search_string}`", debug_level)
|
1298
|
-
|
1299
|
-
return term_list_md
|
1300
|
-
|
1389
|
+
if term_exists and object_action == "Create":
|
1390
|
+
msg = f"Create failed because term `{term_name}` exists - changing `Create` to `Update` in processed output \n"
|
1391
|
+
print_msg(ERROR, msg, debug_level)
|
1392
|
+
print(Markdown(term_display))
|
1393
|
+
return update_a_command(txt, command, object_type, known_q_name, known_guid)
|
1394
|
+
else:
|
1395
|
+
return None
|
1301
1396
|
|
1302
|
-
|
1397
|
+
print(Markdown(term_display))
|
1398
|
+
if object_action == "Update" and directive == "process":
|
1399
|
+
if not term_exists:
|
1400
|
+
return None
|
1401
|
+
body = {
|
1402
|
+
"class": "ReferenceableRequestBody", "elementProperties": { "displayName": term_name,
|
1403
|
+
"class": "GlossaryTermProperties", "qualifiedName": known_q_name, "aliases": alias_list, "summary": summary,
|
1404
|
+
"description": description, "abbreviation": abbreviation, "examples": examples, "usage": usage,
|
1405
|
+
"publishVersionIdentifier": version, "status": status
|
1406
|
+
}, "updateDescription": update_description
|
1407
|
+
}
|
1408
|
+
egeria_client.update_term(known_guid, body_slimmer(body), is_merge_update=False)
|
1409
|
+
# if cat_exist and cat_valid:
|
1410
|
+
update_term_categories(egeria_client, known_guid, cats_exist, cat_q_name_list)
|
1411
|
+
print_msg(ALWAYS,
|
1412
|
+
f"\tUpdated Term `{term_name}` with GUID {known_guid}\n\tand categories `{categories}`",
|
1413
|
+
debug_level)
|
1414
|
+
return egeria_client.get_term_by_guid(known_guid,
|
1415
|
+
'md') # return update_a_command(txt, command, object_type,
|
1416
|
+
# known_q_name, known_guid)
|
1417
|
+
elif object_action == "Update" and directive == "validate": # is sthis reachable?
|
1418
|
+
return egeria_client.get_term_by_guid(known_guid, 'md')
|
1303
1419
|
|
1304
|
-
|
1305
|
-
|
1420
|
+
elif object_action == "Create":
|
1421
|
+
if term_exists:
|
1422
|
+
msg = f"Term {term_name} exists so result document modifies term create to term update"
|
1423
|
+
print_msg(INFO, msg, debug_level)
|
1424
|
+
return update_a_command(txt, command, object_type, q_name, known_guid)
|
1425
|
+
else:
|
1426
|
+
## get the guid for the glossary from the name - first look in cache
|
1427
|
+
cached = get_element_dictionary().get(known_glossary_q_name, None)
|
1306
1428
|
|
1429
|
+
if cached is not None:
|
1430
|
+
glossary_guid = cached.get('guid', None)
|
1431
|
+
if glossary_guid is None:
|
1432
|
+
msg = f"Glossary GUID for {known_glossary_q_name} not found in cache"
|
1433
|
+
print_msg(WARNING, msg, debug_level) # should this ever occur?
|
1434
|
+
return None
|
1435
|
+
else:
|
1436
|
+
glossary_guid = egeria_client.__get_guid__(qualified_name=known_glossary_q_name)
|
1437
|
+
if glossary_guid == NO_ELEMENTS_FOUND:
|
1438
|
+
msg = f"Glossary {known_glossary_q_name} not found"
|
1439
|
+
print_msg(WARNING, msg, debug_level)
|
1440
|
+
return None
|
1441
|
+
term_body = {
|
1442
|
+
"class": "ReferenceableRequestBody", "elementProperties": {
|
1443
|
+
"class": "GlossaryTermProperties", "qualifiedName": known_q_name, "displayName": term_name,
|
1444
|
+
"aliases": alias_list, "summary": summary, "description": description, "abbreviation": abbreviation,
|
1445
|
+
"examples": examples, "usage": usage, "publishVersionIdentifier": version
|
1446
|
+
# "additionalProperties":
|
1447
|
+
# {
|
1448
|
+
# "propertyName1": "xxxx",
|
1449
|
+
# "propertyName2": "xxxx"
|
1450
|
+
# }
|
1451
|
+
}, "initialStatus": status
|
1452
|
+
}
|
1453
|
+
term_guid = egeria_client.create_controlled_glossary_term(glossary_guid, body_slimmer(term_body))
|
1454
|
+
if term_guid == NO_ELEMENTS_FOUND:
|
1455
|
+
print(f"{ERROR}Term {term_name} not created")
|
1456
|
+
return None
|
1457
|
+
if cats_exist and categories is not None:
|
1458
|
+
update_term_categories(egeria_client, term_guid, cats_exist, cat_q_name_list)
|
1459
|
+
update_element_dictionary(known_q_name, {'guid': term_guid, 'display_name': term_name})
|
1460
|
+
print_msg(ALWAYS, f"Created term `{term_name}` with GUID {term_guid}", debug_level)
|
1461
|
+
return egeria_client.get_term_by_guid(term_guid,
|
1462
|
+
'MD') # return update_a_command(txt, command,
|
1463
|
+
# object_type, q_name, term_guid)
|
1307
1464
|
except Exception as e:
|
1308
|
-
print(f"{ERROR}Error
|
1465
|
+
print(f"{ERROR}Error creating term {term_name}: {e}")
|
1309
1466
|
console.print_exception(show_locals=True)
|
1310
1467
|
return None
|
1311
1468
|
else:
|
1312
1469
|
return None
|
1313
1470
|
|
1314
1471
|
|
1315
|
-
|
1316
|
-
|
1472
|
+
|
1473
|
+
|
1474
|
+
def process_create_term_term_relationship_command(egeria_client: EgeriaTech, txt: str, directive: str = "display") -> Optional[str]:
|
1475
|
+
""" Relate two terms through the specified relationship. ."""
|
1317
1476
|
set_debug_level(directive)
|
1318
1477
|
valid = True
|
1319
1478
|
command = extract_command(txt)
|
1479
|
+
object_type = command.split(' ')[1].strip()
|
1480
|
+
object_action = command.split(' ')[0].strip()
|
1481
|
+
term1_guid = None
|
1482
|
+
term2_guid = None
|
1320
1483
|
|
1321
|
-
search_string = process_simple_attribute(txt, SEARCH_LABELS, "INFO")
|
1322
|
-
if search_string is None:
|
1323
|
-
search_string = '*'
|
1324
|
-
print(Markdown(f"{pre_command} `{command}` with search string:`{search_string}` with directive: `{directive}`"))
|
1325
1484
|
|
1326
|
-
|
1327
|
-
if
|
1328
|
-
output_format = "LIST"
|
1329
|
-
elif output_format not in ELEMENT_OUTPUT_FORMATS:
|
1485
|
+
term_relationship = process_simple_attribute(txt, ["Term Relationship", "Relationship Type"], "ERROR")
|
1486
|
+
if term_relationship not in TERM_RELATIONSHPS:
|
1330
1487
|
valid = False
|
1331
|
-
print_msg(ERROR, f"Invalid output format: `{output_format}`", debug_level)
|
1332
1488
|
|
1333
|
-
|
1489
|
+
print(Markdown(f"{pre_command} `{command}` for term relationship: `{term_relationship}` with directive: `{directive}` "))
|
1490
|
+
|
1491
|
+
term1_q_name, term1_guid, term1_valid, term1_exists = process_element_identifiers(egeria_client, object_type, ["Term 1 Name", "Term 1"], txt,
|
1492
|
+
"Exists Required", None )
|
1493
|
+
|
1494
|
+
term2_q_name, term2_guid, term2_valid, term2_exists = process_element_identifiers(egeria_client, object_type, ["Term 2 Name", "Term 2"], txt,
|
1495
|
+
"Exists Required", None )
|
1496
|
+
|
1497
|
+
request_display = (f"\n\t* Term 1 Qualified Name: {term1_q_name}\n\t* Term 2 Qualified Name {term2_q_name}\n\t"
|
1498
|
+
f"* Term Relationship: {term_relationship}")
|
1499
|
+
|
1500
|
+
if not(term1_valid and term2_valid and term1_exists and term2_exists):
|
1501
|
+
valid = False
|
1334
1502
|
|
1335
1503
|
if directive == "display":
|
1336
|
-
print(
|
1504
|
+
print(request_display)
|
1337
1505
|
return None
|
1338
1506
|
elif directive == "validate":
|
1339
|
-
print(
|
1340
|
-
return valid
|
1507
|
+
print(request_display)
|
1508
|
+
return str(valid)
|
1341
1509
|
elif directive == "process":
|
1342
1510
|
try:
|
1343
|
-
print(
|
1511
|
+
print(request_display)
|
1344
1512
|
if not valid: # First validate the term before we process it
|
1345
1513
|
return None
|
1514
|
+
egeria_client.add_relationship_between_terms(term1_guid, term2_guid, term_relationship)
|
1515
|
+
print_msg(ALWAYS, f"Relationship `{term_relationship}` created", debug_level)
|
1516
|
+
update_md = (f"\n\n# Update Term-Term Relationship\n\n## Term 1 Name:\n\n{term1_q_name}"
|
1517
|
+
f"\n\n## Term 2 Name\n\n{term2_q_name}\n\n## Term Relationship:\n\n{term_relationship}")
|
1518
|
+
return update_md
|
1346
1519
|
|
1347
|
-
cat_list_md = f"\n# Category List for search string: `{search_string}`\n\n"
|
1348
|
-
if output_format == "DICT":
|
1349
|
-
struct = egeria_client.find_glossary_categories(search_string, output_format=output_format)
|
1350
|
-
cat_list_md += f"{json.dumps(struct, indent=4)}\n"
|
1351
|
-
else:
|
1352
|
-
cat_list_md += egeria_client.find_glossary_categories(search_string, output_format=output_format)
|
1353
|
-
print_msg("ALWAYS", f"Wrote Category List for search string: `{search_string}`", debug_level)
|
1354
|
-
|
1355
|
-
return cat_list_md
|
1356
1520
|
|
1357
1521
|
except Exception as e:
|
1358
1522
|
print(f"{ERROR}Error performing {command}: {e}")
|
1359
1523
|
console.print_exception(show_locals=True)
|
1360
1524
|
return None
|
1361
1525
|
else:
|
1362
|
-
|
1363
1526
|
return None
|
1364
1527
|
|
1365
1528
|
|
1366
|
-
def
|
1367
|
-
|
1368
|
-
|
1369
|
-
|
1370
|
-
valid = True
|
1371
|
-
command = extract_command(txt)
|
1372
|
-
|
1373
|
-
known_glossary_guid = ""
|
1529
|
+
def process_per_proj_upsert_command(egeria_client: ProjectManager, txt: str, directive: str = "display") -> str | None:
|
1530
|
+
"""
|
1531
|
+
Processes a personal project create or update command by extracting key attributes such as
|
1532
|
+
glossary name, language, description, and usage from the given cell.
|
1374
1533
|
|
1375
|
-
|
1534
|
+
:param txt: A string representing the input cell to be processed for
|
1535
|
+
extracting glossary-related attributes.
|
1536
|
+
:param directive: an optional string indicating the directive to be used - display, validate or execute
|
1537
|
+
:return: A string summarizing the outcome of the processing.
|
1538
|
+
"""
|
1539
|
+
command = extract_command(txt)
|
1540
|
+
object = command.split()
|
1541
|
+
object_type = f"{object[1]} {object[2]}"
|
1542
|
+
object_action = object[0]
|
1543
|
+
set_debug_level(directive)
|
1376
1544
|
|
1377
|
-
|
1378
|
-
|
1545
|
+
project_name = process_simple_attribute(txt, ['Project Name'])
|
1546
|
+
description = process_simple_attribute(txt, ['Description'])
|
1547
|
+
project_identifier = process_simple_attribute(txt, ['Project Identifier'])
|
1548
|
+
project_status = process_simple_attribute(txt, ['Project Status'])
|
1549
|
+
project_phase = process_simple_attribute(txt, ['Project Phase'])
|
1550
|
+
project_health = process_simple_attribute(txt, ['Project Health'])
|
1551
|
+
start_date = process_simple_attribute(txt, ['Start Date'])
|
1552
|
+
planned_end_date = process_simple_attribute(txt, ['Planned End Date'])
|
1553
|
+
print(Markdown(f"{pre_command} `\'{command}\'` for project: `{project_name}` with directive: `{directive}` "))
|
1379
1554
|
|
1380
|
-
|
1555
|
+
project_display = (f"\n* Command: {command}\n\t* Project: {project_name}\n\t"
|
1556
|
+
f"* Status: {project_status}\n\t* Description: {description}\n\t"
|
1557
|
+
f"* Phase: {project_phase}\n\t* Health: {project_health}\n\t"
|
1558
|
+
f"* Start Date: {start_date}\n\t* Planned End Date: {planned_end_date}\n")
|
1381
1559
|
|
1382
|
-
|
1560
|
+
def validate_project(obj_action: str) -> tuple[bool, bool, str, str]:
|
1561
|
+
valid = True
|
1562
|
+
msg = ""
|
1563
|
+
known_guid = None
|
1564
|
+
known_q_name = None
|
1565
|
+
|
1566
|
+
project_details = egeria_client.get_projects_by_name(project_name)
|
1567
|
+
if project_details == NO_PROJECTS_FOUND:
|
1568
|
+
project_exists = False
|
1569
|
+
else:
|
1570
|
+
project_exists = True
|
1571
|
+
|
1572
|
+
if project_name is None:
|
1573
|
+
msg = f"* {ERROR}Project name is missing\n"
|
1574
|
+
valid = False
|
1575
|
+
if project_status is None:
|
1576
|
+
msg += f"* {INFO}No Project status found\n"
|
1577
|
+
|
1578
|
+
if description is None:
|
1579
|
+
msg += f"* {INFO}No Description found\n"
|
1580
|
+
|
1581
|
+
if project_identifier is None:
|
1582
|
+
msg += f"* {INFO}No Project Identifier found\n"
|
1583
|
+
|
1584
|
+
if project_phase is None:
|
1585
|
+
msg += f"* {INFO}No Project Phase found\n"
|
1586
|
+
|
1587
|
+
if project_health is None:
|
1588
|
+
msg += f"* {INFO}No Project Health found\n"
|
1589
|
+
|
1590
|
+
if start_date is None:
|
1591
|
+
msg += f"* {INFO}No Start Date found\n"
|
1592
|
+
elif not is_valid_iso_date(start_date):
|
1593
|
+
msg += f"* {ERROR}Start Date is not a valid ISO date of form YYYY-MM-DD\n"
|
1594
|
+
valid = False
|
1595
|
+
|
1596
|
+
if planned_end_date is None:
|
1597
|
+
msg += f"* {INFO} No Planned End Date found\n"
|
1598
|
+
elif not is_valid_iso_date(planned_end_date):
|
1599
|
+
msg += f"* {ERROR}Planned End Date is not a valid ISO date of form YYYY-MM-DD\n"
|
1600
|
+
valid = False
|
1601
|
+
|
1602
|
+
if obj_action == "Update":
|
1603
|
+
q_name = process_simple_attribute(txt, 'Qualified Name')
|
1604
|
+
|
1605
|
+
if not project_exists:
|
1606
|
+
msg += f"* {ERROR}Project {project_name} does not exist\n"
|
1607
|
+
valid = False
|
1608
|
+
if len(project_details) > 1 and project_exists:
|
1609
|
+
msg += f"* {ERROR}More than one project with name {project_name} found\n"
|
1610
|
+
valid = False
|
1611
|
+
if len(project_details) == 1:
|
1612
|
+
known_guid = project_details[0]['elementHeader'].get('guid', None)
|
1613
|
+
known_q_name = project_details[0]['glossaryProperties'].get('qualifiedName', None)
|
1614
|
+
if q_name is None:
|
1615
|
+
msg += f"* {INFO}Qualified Name is missing => can use known qualified name of {known_q_name}\n"
|
1616
|
+
valid = True
|
1617
|
+
elif q_name != known_q_name:
|
1618
|
+
msg += (f"* {ERROR}Project {project_name} qualifiedName mismatch between {q_name} and {known_q_name}\n")
|
1619
|
+
valid = False
|
1620
|
+
if valid:
|
1621
|
+
msg += project_display
|
1622
|
+
msg += f"* -->Project {project_name} exists and can be updated\n"
|
1623
|
+
else:
|
1624
|
+
msg += f"* --> validation failed\n"
|
1625
|
+
msg += '---'
|
1626
|
+
print(Markdown(msg))
|
1627
|
+
return valid, project_exists, known_guid, known_q_name
|
1628
|
+
|
1629
|
+
elif obj_action == "Create":
|
1630
|
+
if project_exists:
|
1631
|
+
msg += f"\n{ERROR}Project {project_name} already exists"
|
1632
|
+
else:
|
1633
|
+
msg += f"\n-->It is valid to create Project \'{project_name}\' with:\n"
|
1634
|
+
print(Markdown(msg))
|
1635
|
+
return valid, project_exists, known_guid, known_q_name
|
1636
|
+
|
1637
|
+
if directive == "display":
|
1638
|
+
print(Markdown(project_display))
|
1639
|
+
return None
|
1640
|
+
|
1641
|
+
elif directive == "validate":
|
1642
|
+
is_valid, exists, known_guid, known_q_name = validate_project(object_action)
|
1643
|
+
valid = is_valid if is_valid else None
|
1644
|
+
return valid
|
1645
|
+
|
1646
|
+
elif directive == "process":
|
1647
|
+
is_valid, exists, known_guid, known_q_name = validate_project(object_action)
|
1648
|
+
if not is_valid:
|
1649
|
+
return None
|
1650
|
+
if object_action == "Update":
|
1651
|
+
if not exists:
|
1652
|
+
print(f"\n\n-->Project {project_name} does not exist")
|
1653
|
+
return None
|
1654
|
+
|
1655
|
+
egeria_client.update_project(known_guid, known_q_name, project_identifier, project_name, description,
|
1656
|
+
project_status, project_phase, project_health, start_date, planned_end_date,
|
1657
|
+
False)
|
1658
|
+
print_msg(ALWAYS, f"Updated Project `{project_name}` with GUID {known_guid}", debug_level)
|
1659
|
+
return update_a_command(txt, command, object_type, known_q_name, known_guid)
|
1660
|
+
elif object_action == "Create":
|
1661
|
+
guid = None
|
1662
|
+
if exists:
|
1663
|
+
print(f"Project `{project_name}` already exists and update document created")
|
1664
|
+
return update_a_command(txt, command, object_type, known_q_name, known_guid)
|
1665
|
+
else:
|
1666
|
+
guid = egeria_client.create_project(None, None, None, False, project_name, description,
|
1667
|
+
"PersonalProject", project_identifier, True, project_status,
|
1668
|
+
project_phase, project_health, start_date, planned_end_date)
|
1669
|
+
project_g = egeria_client.get_project_by_guid(guid)
|
1670
|
+
if project_g == NO_GLOSSARIES_FOUND:
|
1671
|
+
print(f"Just created with GUID {guid} but Project not found")
|
1672
|
+
return None
|
1673
|
+
|
1674
|
+
q_name = project_g['projectProperties']["qualifiedName"]
|
1675
|
+
update_element_dictionary(q_name, {'guid': guid, 'display_name': project_name})
|
1676
|
+
print_msg(ALWAYS, f"Created project `{project_name}` with GUID {guid}", debug_level)
|
1677
|
+
return update_a_command(txt, command, object_type, q_name, guid)
|
1678
|
+
|
1679
|
+
|
1680
|
+
def process_term_list_command(egeria_client: EgeriaTech, txt: str, directive: str = "display") -> Optional[str]:
|
1681
|
+
""" List terms as a markdown table. Filter based on optional search string. """
|
1682
|
+
set_debug_level(directive)
|
1683
|
+
valid = True
|
1684
|
+
command = extract_command(txt)
|
1685
|
+
|
1686
|
+
search_string = process_simple_attribute(txt, SEARCH_LABELS)
|
1687
|
+
if search_string is None:
|
1688
|
+
search_string = '*'
|
1689
|
+
print(Markdown(f"{pre_command} `{command}` with search string:`{search_string}` with directive: `{directive}`"))
|
1690
|
+
|
1691
|
+
glossary = process_simple_attribute(txt, ['Glossary', 'In Glossary', "Glossary Name"])
|
1692
|
+
if glossary is not None:
|
1693
|
+
_, glossary_guid, _, glossary_exists = get_element_by_name(egeria_client, "Glossary", glossary)
|
1694
|
+
msg = f"Found glossary `{glossary}` with GUID {glossary_guid}"
|
1695
|
+
print_msg(INFO, msg, debug_level)
|
1696
|
+
else:
|
1697
|
+
glossary_guid = None
|
1698
|
+
msg = f"No glossary found"
|
1699
|
+
print_msg(INFO, msg, debug_level)
|
1700
|
+
|
1701
|
+
output_format = process_simple_attribute(txt, OUTPUT_LABELS)
|
1383
1702
|
if output_format is None:
|
1384
|
-
output_format = "
|
1385
|
-
elif output_format not in
|
1703
|
+
output_format = "LIST"
|
1704
|
+
elif output_format not in ELEMENT_OUTPUT_FORMATS:
|
1386
1705
|
valid = False
|
1387
1706
|
print_msg(ERROR, f"Invalid output format: `{output_format}`", debug_level)
|
1388
1707
|
|
1389
|
-
request_display = f"\n\t*
|
1708
|
+
request_display = (f"\n\t* Search String: {search_string}\n\t* Glossary: {glossary}\n\t* Output Format: "
|
1709
|
+
f"{output_format}\n")
|
1390
1710
|
|
1391
1711
|
if directive == "display":
|
1392
1712
|
print(Markdown(request_display))
|
1393
1713
|
return None
|
1394
1714
|
elif directive == "validate":
|
1395
1715
|
print(Markdown(request_display))
|
1396
|
-
return
|
1716
|
+
return valid
|
1397
1717
|
elif directive == "process":
|
1398
1718
|
try:
|
1399
1719
|
print(Markdown(request_display))
|
1400
1720
|
if not valid: # First validate the term before we process it
|
1401
1721
|
return None
|
1402
1722
|
|
1403
|
-
|
1723
|
+
term_list_md = f"\n# Term List for search string: `{search_string}`\n\n"
|
1404
1724
|
if output_format == "DICT":
|
1405
|
-
struct = egeria_client.
|
1406
|
-
|
1725
|
+
struct = egeria_client.find_glossary_terms(search_string, glossary_guid, output_format=output_format)
|
1726
|
+
term_list_md += f"```{json.dumps(struct, indent=4)}```\n"
|
1407
1727
|
else:
|
1408
|
-
|
1409
|
-
|
1728
|
+
term_list_md += egeria_client.find_glossary_terms(search_string, glossary_guid,
|
1729
|
+
output_format=output_format)
|
1730
|
+
print_msg("ALWAYS", f"Wrote Term List for search string: `{search_string}`", debug_level)
|
1410
1731
|
|
1411
|
-
return
|
1732
|
+
return term_list_md
|
1733
|
+
|
1734
|
+
md_table = egeria_client.find_glossary_terms(search_string, glossary_guid, output_format=output_format)
|
1735
|
+
|
1736
|
+
print_msg("ALWAYS", f"Wrote Term list for search string `{search_string}`", debug_level)
|
1737
|
+
return md_table
|
1412
1738
|
|
1413
1739
|
except Exception as e:
|
1414
1740
|
print(f"{ERROR}Error performing {command}: {e}")
|
@@ -1418,7 +1744,7 @@ def process_glossary_structure_command(egeria_client: EgeriaTech, txt: str, dire
|
|
1418
1744
|
return None
|
1419
1745
|
|
1420
1746
|
|
1421
|
-
def
|
1747
|
+
def process_category_list_command(egeria_client: EgeriaTech, txt: str, directive: str = "display") -> Optional[str]:
|
1422
1748
|
""" List terms as a markdown table. Filter based on optional search string. """
|
1423
1749
|
set_debug_level(directive)
|
1424
1750
|
valid = True
|
@@ -1428,8 +1754,6 @@ def process_glossary_list_command(egeria_client: EgeriaTech, txt: str, directive
|
|
1428
1754
|
if search_string is None:
|
1429
1755
|
search_string = '*'
|
1430
1756
|
print(Markdown(f"{pre_command} `{command}` with search string:`{search_string}` with directive: `{directive}`"))
|
1431
|
-
if search_string is None:
|
1432
|
-
search_string = '*'
|
1433
1757
|
|
1434
1758
|
output_format = process_simple_attribute(txt, OUTPUT_LABELS, "INFO")
|
1435
1759
|
if output_format is None:
|
@@ -1441,82 +1765,82 @@ def process_glossary_list_command(egeria_client: EgeriaTech, txt: str, directive
|
|
1441
1765
|
request_display = f"\n\t* Search String: {search_string}\n\t* Output Format: {output_format}\n"
|
1442
1766
|
|
1443
1767
|
if directive == "display":
|
1444
|
-
print(request_display)
|
1768
|
+
print(Markdown(request_display))
|
1445
1769
|
return None
|
1446
1770
|
elif directive == "validate":
|
1447
|
-
print(request_display)
|
1771
|
+
print(Markdown(request_display))
|
1448
1772
|
return valid
|
1449
1773
|
elif directive == "process":
|
1450
1774
|
try:
|
1451
|
-
print(request_display)
|
1775
|
+
print(Markdown(request_display))
|
1452
1776
|
if not valid: # First validate the term before we process it
|
1453
1777
|
return None
|
1454
1778
|
|
1455
|
-
|
1779
|
+
cat_list_md = f"\n# Category List for search string: `{search_string}`\n\n"
|
1456
1780
|
if output_format == "DICT":
|
1457
|
-
struct = egeria_client.
|
1458
|
-
|
1781
|
+
struct = egeria_client.find_glossary_categories(search_string, output_format=output_format)
|
1782
|
+
cat_list_md += f"```{json.dumps(struct, indent=4)}```\n"
|
1459
1783
|
else:
|
1460
|
-
|
1461
|
-
print_msg("ALWAYS", f"Wrote
|
1784
|
+
cat_list_md += egeria_client.find_glossary_categories(search_string, output_format=output_format)
|
1785
|
+
print_msg("ALWAYS", f"Wrote Category List for search string: `{search_string}`", debug_level)
|
1462
1786
|
|
1463
|
-
return
|
1787
|
+
return cat_list_md
|
1464
1788
|
|
1465
1789
|
except Exception as e:
|
1466
1790
|
print(f"{ERROR}Error performing {command}: {e}")
|
1467
1791
|
console.print_exception(show_locals=True)
|
1468
1792
|
return None
|
1469
1793
|
else:
|
1794
|
+
|
1470
1795
|
return None
|
1471
1796
|
|
1472
1797
|
|
1473
|
-
def
|
1798
|
+
def process_glossary_structure_command(egeria_client: EgeriaTech, txt: str, directive: str = "display") -> Optional[str]:
|
1474
1799
|
""" List terms as a markdown table. Filter based on optional search string. """
|
1475
1800
|
set_debug_level(directive)
|
1476
1801
|
valid = True
|
1477
1802
|
command = extract_command(txt)
|
1478
|
-
object_type = command.split(' ')[1].strip()
|
1479
|
-
object_action = command.split(' ')[0].strip()
|
1480
1803
|
|
1481
|
-
|
1482
|
-
element_labels.append('Display Name')
|
1804
|
+
known_glossary_guid = ""
|
1483
1805
|
|
1484
|
-
|
1806
|
+
glossary_name = process_simple_attribute(txt, GLOSSARY_NAME_LABELS, "ERROR")
|
1485
1807
|
|
1486
|
-
|
1487
|
-
|
1808
|
+
_, known_glossary_guid, valid, _ = process_element_identifiers(egeria_client, "Glossary", GLOSSARY_NAME_LABELS, txt,
|
1809
|
+
EXISTS_REQUIRED, None)
|
1488
1810
|
|
1489
|
-
print(Markdown(f"{pre_command} `{command}` for
|
1811
|
+
print(Markdown(f"{pre_command} `{command}` for glossary:`{glossary_name}` with directive: `{directive}`"))
|
1490
1812
|
|
1491
1813
|
output_format = process_simple_attribute(txt, OUTPUT_LABELS, "INFO")
|
1492
1814
|
if output_format is None:
|
1493
|
-
output_format = "
|
1494
|
-
elif output_format not in ["DICT", "LIST"]:
|
1815
|
+
output_format = "MD"
|
1816
|
+
elif output_format not in ["DICT", "LIST", "MD"]:
|
1495
1817
|
valid = False
|
1496
1818
|
print_msg(ERROR, f"Invalid output format: `{output_format}`", debug_level)
|
1497
1819
|
|
1498
|
-
request_display = f"\n\t*
|
1820
|
+
request_display = f"\n\t* Glossary name: {glossary_name}\n\t* Output Format: {output_format}\n"
|
1499
1821
|
|
1500
1822
|
if directive == "display":
|
1501
|
-
print(request_display)
|
1823
|
+
print(Markdown(request_display))
|
1502
1824
|
return None
|
1503
1825
|
elif directive == "validate":
|
1504
|
-
print(request_display)
|
1505
|
-
return valid
|
1826
|
+
print(Markdown(request_display))
|
1827
|
+
return str(valid)
|
1506
1828
|
elif directive == "process":
|
1507
1829
|
try:
|
1508
|
-
print(request_display)
|
1830
|
+
print(Markdown(request_display))
|
1509
1831
|
if not valid: # First validate the term before we process it
|
1510
1832
|
return None
|
1511
|
-
|
1833
|
+
|
1834
|
+
glossary_structure_md = f"\n# Glossary Structure for `{glossary_name}`\n\n"
|
1512
1835
|
if output_format == "DICT":
|
1513
|
-
struct = egeria_client.
|
1514
|
-
|
1836
|
+
struct = egeria_client.get_glossary_category_structure(known_glossary_guid, output_format=output_format)
|
1837
|
+
glossary_structure_md += f"```{json.dumps(struct, indent=4)}```\n"
|
1515
1838
|
else:
|
1516
|
-
|
1517
|
-
|
1839
|
+
glossary_structure_md += egeria_client.get_glossary_category_structure(known_glossary_guid,
|
1840
|
+
output_format=output_format)
|
1841
|
+
print_msg("ALWAYS", f"Wrote Glossary Structure for glossary: `{glossary_name}`", debug_level)
|
1518
1842
|
|
1519
|
-
return
|
1843
|
+
return glossary_structure_md
|
1520
1844
|
|
1521
1845
|
except Exception as e:
|
1522
1846
|
print(f"{ERROR}Error performing {command}: {e}")
|
@@ -1526,52 +1850,49 @@ def process_term_history_command(egeria_client: EgeriaTech, txt: str, directive:
|
|
1526
1850
|
return None
|
1527
1851
|
|
1528
1852
|
|
1529
|
-
def
|
1530
|
-
|
1531
|
-
""" List term revision history as a markdown table or list."""
|
1853
|
+
def process_glossary_list_command(egeria_client: EgeriaTech, txt: str, directive: str = "display") -> Optional[str]:
|
1854
|
+
""" List terms as a markdown table. Filter based on optional search string. """
|
1532
1855
|
set_debug_level(directive)
|
1533
1856
|
valid = True
|
1534
1857
|
command = extract_command(txt)
|
1535
|
-
object_type = command.split(' ')[1].strip()
|
1536
|
-
object_action = command.split(' ')[0].strip()
|
1537
|
-
known_q_name = None
|
1538
|
-
known_guid = None
|
1539
1858
|
|
1540
|
-
|
1541
|
-
|
1542
|
-
|
1543
|
-
print(Markdown(f"{pre_command} `{command}`
|
1859
|
+
search_string = process_simple_attribute(txt, SEARCH_LABELS, "INFO")
|
1860
|
+
if search_string is None:
|
1861
|
+
search_string = '*'
|
1862
|
+
print(Markdown(f"{pre_command} `{command}` with search string:`{search_string}` with directive: `{directive}`"))
|
1863
|
+
if search_string is None:
|
1864
|
+
search_string = '*'
|
1544
1865
|
|
1545
|
-
|
1546
|
-
object_action, )
|
1547
|
-
output_format = process_simple_attribute(txt, ['Output Format', 'Format'], 'INFO')
|
1866
|
+
output_format = process_simple_attribute(txt, OUTPUT_LABELS, "INFO")
|
1548
1867
|
if output_format is None:
|
1549
1868
|
output_format = "LIST"
|
1550
|
-
elif output_format not in
|
1869
|
+
elif output_format not in ELEMENT_OUTPUT_FORMATS:
|
1551
1870
|
valid = False
|
1552
1871
|
print_msg(ERROR, f"Invalid output format: `{output_format}`", debug_level)
|
1553
1872
|
|
1554
|
-
request_display = f"\n\t*
|
1873
|
+
request_display = f"\n\t* Search String: {search_string}\n\t* Output Format: {output_format}\n"
|
1555
1874
|
|
1556
1875
|
if directive == "display":
|
1557
1876
|
print(request_display)
|
1558
1877
|
return None
|
1559
1878
|
elif directive == "validate":
|
1560
1879
|
print(request_display)
|
1561
|
-
return
|
1880
|
+
return valid
|
1562
1881
|
elif directive == "process":
|
1563
1882
|
try:
|
1564
1883
|
print(request_display)
|
1565
1884
|
if not valid: # First validate the term before we process it
|
1566
1885
|
return None
|
1567
|
-
|
1886
|
+
|
1887
|
+
glossary_list_md = f"\n# Glossary List for `{search_string}`\n\n"
|
1568
1888
|
if output_format == "DICT":
|
1569
|
-
struct = egeria_client.
|
1570
|
-
|
1889
|
+
struct = egeria_client.find_glossaries(search_string, output_format=output_format)
|
1890
|
+
glossary_list_md += f"```{json.dumps(struct, indent=4)}```\n"
|
1571
1891
|
else:
|
1572
|
-
|
1573
|
-
print_msg("ALWAYS", f"Wrote
|
1574
|
-
|
1892
|
+
glossary_list_md += egeria_client.find_glossaries(search_string, output_format=output_format)
|
1893
|
+
print_msg("ALWAYS", f"Wrote Glossary List for search string: `{search_string}`", debug_level)
|
1894
|
+
|
1895
|
+
return glossary_list_md
|
1575
1896
|
|
1576
1897
|
except Exception as e:
|
1577
1898
|
print(f"{ERROR}Error performing {command}: {e}")
|
@@ -1581,333 +1902,164 @@ def process_term_revision_history_command(egeria_client: EgeriaTech, txt: str, d
|
|
1581
1902
|
return None
|
1582
1903
|
|
1583
1904
|
|
1584
|
-
def
|
1585
|
-
"""
|
1586
|
-
Processes a term create or update command by extracting key attributes such as
|
1587
|
-
term name, summary, description, abbreviation, examples, usage, version, and status from the given cell.
|
1588
|
-
|
1589
|
-
:param txt: A string representing the input cell to be processed for
|
1590
|
-
extracting glossary-related attributes.
|
1591
|
-
:param directive: an optional string indicating the directive to be used - display, validate or execute
|
1592
|
-
:return: A string summarizing the outcome of the processing.
|
1593
|
-
"""
|
1594
|
-
valid = True
|
1595
|
-
categories_list = None
|
1596
|
-
cats_exist = True
|
1905
|
+
def process_term_details_command(egeria_client: EgeriaTech, txt: str, directive: str = "display") -> Optional[str]:
|
1906
|
+
""" List terms as a markdown table. Filter based on optional search string. """
|
1597
1907
|
set_debug_level(directive)
|
1598
|
-
|
1908
|
+
valid = True
|
1599
1909
|
command = extract_command(txt)
|
1600
1910
|
object_type = command.split(' ')[1].strip()
|
1601
1911
|
object_action = command.split(' ')[0].strip()
|
1602
1912
|
|
1603
|
-
term_name = process_simple_attribute(txt, ['Term Name', 'Display Name'], ERROR)
|
1604
|
-
print(Markdown(f"{pre_command} `{command}` for term:`{term_name}` with directive: `{directive}`"))
|
1605
|
-
summary = process_simple_attribute(txt, ['Summary'])
|
1606
|
-
description = process_simple_attribute(txt, ['Description'])
|
1607
|
-
abbreviation = process_simple_attribute(txt, ['Abbreviation'])
|
1608
|
-
examples = process_simple_attribute(txt, ['Examples'])
|
1609
|
-
usage = process_simple_attribute(txt, ['Usage'])
|
1610
|
-
status = process_simple_attribute(txt, ['Status'])
|
1611
|
-
status = status.upper() if status else 'DRAFT'
|
1612
|
-
version = process_simple_attribute(txt, ['Version', "Version Identifier", "Published Version"])
|
1613
|
-
q_name = process_simple_attribute(txt, ['Qualified Name'])
|
1614
1913
|
|
1615
|
-
|
1616
|
-
if term_name is None:
|
1617
|
-
valid = False
|
1618
|
-
known_q_name, known_guid, term_exists = None
|
1619
|
-
else:
|
1620
|
-
element_labels = TERM_NAME_LABELS
|
1621
|
-
element_labels.append('Display Name')
|
1622
|
-
known_q_name, known_guid, valid, term_exists = process_element_identifiers(egeria_client, object_type,
|
1623
|
-
element_labels, txt, object_action,
|
1624
|
-
version)
|
1914
|
+
term_identifier = process_simple_attribute(txt, TERM_NAME_LABELS, "ERROR")
|
1625
1915
|
|
1626
|
-
|
1627
|
-
glossary_name = process_simple_attribute(txt, GLOSSARY_NAME_LABELS, ERROR)
|
1628
|
-
if glossary_name is None:
|
1629
|
-
valid = False
|
1630
|
-
known_glossary_guid = None
|
1631
|
-
known_glossary_q_name = None
|
1632
|
-
glossary_valid = False
|
1633
|
-
glossary_exists = False
|
1634
|
-
else:
|
1635
|
-
known_glossary_q_name, known_glossary_guid, glossary_valid, glossary_exists = process_element_identifiers(
|
1636
|
-
egeria_client, "Glossary", GLOSSARY_NAME_LABELS, txt, EXISTS_REQUIRED, None)
|
1916
|
+
print(Markdown(f"{pre_command} `{command}` for term:`{term_identifier}` with directive: `{directive}`"))
|
1637
1917
|
|
1638
|
-
|
1639
|
-
|
1640
|
-
|
1641
|
-
msg = "Checking for categories that classify this term"
|
1642
|
-
print_msg("DEBUG-INFO", msg, debug_level)
|
1643
|
-
categories_list, cat_q_name_list, cat_valid, cat_exist = process_name_list(egeria_client, 'Glossary Categories',
|
1644
|
-
txt, CATEGORY_NAME_LABELS)
|
1645
|
-
if cat_exist and cat_valid:
|
1646
|
-
msg = f"Found valid glossary categories to classify the term:\n\t{term_name}"
|
1647
|
-
print_msg("INFO", msg, debug_level)
|
1648
|
-
else:
|
1649
|
-
msg = "No valid glossary categories found."
|
1650
|
-
print_msg("INFO", msg, debug_level)
|
1918
|
+
output_format = process_simple_attribute(txt, OUTPUT_LABELS, "INFO")
|
1919
|
+
if output_format is None:
|
1920
|
+
output_format = "REPORT"
|
1651
1921
|
else:
|
1652
|
-
|
1653
|
-
cat_q_name_list = None
|
1922
|
+
output_format = output_format.upper()
|
1654
1923
|
|
1655
|
-
if
|
1656
|
-
|
1657
|
-
|
1658
|
-
term_display = (f"\n* Command: {command}\n\t* Glossary: {known_glossary_q_name}\n\t"
|
1659
|
-
f"* Term Name: {term_name}\n\t* Qualified Name: {q_name}\n\t* Categories: {categories}\n\t"
|
1660
|
-
f"* Summary: {summary}\n\t* Description: {description}\n\t"
|
1661
|
-
f"* Abbreviation: {abbreviation}\n\t* Examples: {examples}\n\t* Usage: {usage}\n\t"
|
1662
|
-
f"* Version: {version}\n\t* Status: {status}\n\t* GUID: {term_guid}"
|
1663
|
-
f"\n\t* Update Description: {update_description}\n")
|
1664
|
-
if not term_exists:
|
1665
|
-
msg = f"Update request invalid, Term {term_name} does not exist\n"
|
1666
|
-
print_msg(ERROR, msg, debug_level)
|
1667
|
-
valid = False
|
1924
|
+
if output_format not in ["DICT", "REPORT"]:
|
1925
|
+
valid = False
|
1926
|
+
print_msg(ERROR, f"Invalid output format: `{output_format}`", debug_level)
|
1668
1927
|
|
1669
|
-
|
1670
|
-
term_display = (f"\n* Command: {command}\n\t* Glossary: {known_glossary_q_name}\n\t"
|
1671
|
-
f"* Term Name: {term_name}\n\t* Categories: {categories}\n\t* Summary: {summary}\n\t"
|
1672
|
-
f"* Qualified Name: {q_name}\n\t* Description: {description}\n\t"
|
1673
|
-
f"* Abbreviation: {abbreviation}\n\t* Examples: {examples}\n\t* Usage: {usage}\n\t"
|
1674
|
-
f"* Version: {version}\n\t* Status: {status}\n")
|
1675
|
-
if term_exists:
|
1676
|
-
msg = f"Term `{term_name}` cannot be created since it already exists\n"
|
1677
|
-
print_msg(ERROR, msg, debug_level)
|
1678
|
-
else:
|
1679
|
-
msg = f"It is valid to create Term `{term_name}`"
|
1680
|
-
print_msg(ALWAYS, msg, debug_level)
|
1928
|
+
request_display = f"\n\t* Term Identifier: {term_identifier}\n\t* Output Format {output_format}"
|
1681
1929
|
|
1682
1930
|
if directive == "display":
|
1683
|
-
print(
|
1931
|
+
print(request_display)
|
1684
1932
|
return None
|
1685
1933
|
elif directive == "validate":
|
1686
|
-
print(
|
1934
|
+
print(request_display)
|
1687
1935
|
return valid
|
1688
1936
|
elif directive == "process":
|
1689
1937
|
try:
|
1938
|
+
print(request_display)
|
1690
1939
|
if not valid: # First validate the term before we process it
|
1691
1940
|
return None
|
1692
|
-
|
1693
|
-
if
|
1694
|
-
|
1695
|
-
|
1696
|
-
body = {
|
1697
|
-
"class": "ReferenceableRequestBody", "elementProperties": {
|
1698
|
-
"class": "GlossaryTermProperties", "qualifiedName": known_q_name, "summary": summary,
|
1699
|
-
"description": description, "abbreviation": abbreviation, "examples": examples, "usage": usage,
|
1700
|
-
"publishVersionIdentifier": version, "status": status
|
1701
|
-
}, "updateDescription": update_description
|
1702
|
-
}
|
1703
|
-
egeria_client.update_term(known_guid, body_slimmer(body))
|
1704
|
-
# if cat_exist and cat_valid:
|
1705
|
-
update_term_categories(egeria_client, known_guid, cats_exist, cat_q_name_list)
|
1706
|
-
print_msg(ALWAYS,
|
1707
|
-
f"\tUpdated Term `{term_name}` with GUID {known_guid}\n\tand categories `{categories}`",
|
1708
|
-
debug_level)
|
1709
|
-
return egeria_client.get_term_by_guid(known_guid,
|
1710
|
-
'md') # return update_a_command(txt, command, object_type,
|
1711
|
-
# known_q_name, known_guid)
|
1712
|
-
elif object_action == "Update" and directive == "validate": # is sthis reachable?
|
1713
|
-
return egeria_client.get_term_by_guid(known_guid, 'md')
|
1941
|
+
output = egeria_client.get_term_details(term_identifier, output_format=output_format)
|
1942
|
+
if output_format == "DICT":
|
1943
|
+
output = f"```{json.dumps(output, indent=4)}```"
|
1944
|
+
print_msg("ALWAYS", f"Wrote Term Details for term: `{term_identifier}`", debug_level)
|
1714
1945
|
|
1715
|
-
|
1716
|
-
if term_exists:
|
1717
|
-
msg = f"Term {term_name} exists so result document modifies term create to term update"
|
1718
|
-
print_msg(INFO, msg, debug_level)
|
1719
|
-
return update_a_command(txt, command, object_type, q_name, known_guid)
|
1720
|
-
else:
|
1721
|
-
## get the guid for the glossary from the name - first look in cache
|
1722
|
-
cached = get_element_dictionary().get(known_glossary_q_name, None)
|
1946
|
+
return output
|
1723
1947
|
|
1724
|
-
if cached is not None:
|
1725
|
-
glossary_guid = cached.get('guid', None)
|
1726
|
-
if glossary_guid is None:
|
1727
|
-
msg = f"Glossary GUID for {known_glossary_q_name} not found in cache"
|
1728
|
-
print_msg(WARNING, msg, debug_level) # should this ever occur?
|
1729
|
-
return None
|
1730
|
-
else:
|
1731
|
-
glossary_guid = egeria_client.__get_guid__(qualified_name=known_glossary_q_name)
|
1732
|
-
if glossary_guid == NO_ELEMENTS_FOUND:
|
1733
|
-
msg = f"Glossary {known_glossary_q_name} not found"
|
1734
|
-
print_msg(WARNING, msg, debug_level)
|
1735
|
-
return None
|
1736
|
-
term_body = {
|
1737
|
-
"class": "ReferenceableRequestBody", "elementProperties": {
|
1738
|
-
"class": "GlossaryTermProperties", "qualifiedName": known_q_name, "displayName": term_name,
|
1739
|
-
"summary": summary, "description": description, "abbreviation": abbreviation,
|
1740
|
-
"examples": examples, "usage": usage, "publishVersionIdentifier": version
|
1741
|
-
# "additionalProperties":
|
1742
|
-
# {
|
1743
|
-
# "propertyName1": "xxxx",
|
1744
|
-
# "propertyName2": "xxxx"
|
1745
|
-
# }
|
1746
|
-
}, "initialStatus": status
|
1747
|
-
}
|
1748
|
-
term_guid = egeria_client.create_controlled_glossary_term(glossary_guid, body_slimmer(term_body))
|
1749
|
-
if term_guid == NO_ELEMENTS_FOUND:
|
1750
|
-
print(f"{ERROR}Term {term_name} not created")
|
1751
|
-
return None
|
1752
|
-
if cats_exist and categories is not None:
|
1753
|
-
update_term_categories(egeria_client, term_guid, cats_exist, cat_q_name_list)
|
1754
|
-
update_element_dictionary(known_q_name, {'guid': term_guid, 'display_name': term_name})
|
1755
|
-
print_msg(ALWAYS, f"Created term `{term_name}` with GUID {term_guid}", debug_level)
|
1756
|
-
return egeria_client.get_term_by_guid(term_guid,
|
1757
|
-
'MD') # return update_a_command(txt, command,
|
1758
|
-
# object_type, q_name, term_guid)
|
1759
1948
|
except Exception as e:
|
1760
|
-
print(f"{ERROR}Error
|
1949
|
+
print(f"{ERROR}Error performing {command}: {e}")
|
1761
1950
|
console.print_exception(show_locals=True)
|
1762
1951
|
return None
|
1952
|
+
else:
|
1953
|
+
return None
|
1763
1954
|
|
1764
1955
|
|
1765
|
-
def process_per_proj_upsert_command(egeria_client: ProjectManager, txt: str, directive: str = "display") -> str | None:
|
1766
|
-
"""
|
1767
|
-
Processes a personal project create or update command by extracting key attributes such as
|
1768
|
-
glossary name, language, description, and usage from the given cell.
|
1769
1956
|
|
1770
|
-
|
1771
|
-
|
1772
|
-
:param directive: an optional string indicating the directive to be used - display, validate or execute
|
1773
|
-
:return: A string summarizing the outcome of the processing.
|
1774
|
-
"""
|
1775
|
-
command = extract_command(txt)
|
1776
|
-
object = command.split()
|
1777
|
-
object_type = f"{object[1]} {object[2]}"
|
1778
|
-
object_action = object[0]
|
1957
|
+
def process_term_history_command(egeria_client: EgeriaTech, txt: str, directive: str = "display") -> Optional[str]:
|
1958
|
+
""" List terms as a markdown table. Filter based on optional search string. """
|
1779
1959
|
set_debug_level(directive)
|
1960
|
+
valid = True
|
1961
|
+
command = extract_command(txt)
|
1962
|
+
object_type = command.split(' ')[1].strip()
|
1963
|
+
object_action = command.split(' ')[0].strip()
|
1780
1964
|
|
1781
|
-
|
1782
|
-
|
1783
|
-
project_identifier = process_simple_attribute(txt, ['Project Identifier'])
|
1784
|
-
project_status = process_simple_attribute(txt, ['Project Status'])
|
1785
|
-
project_phase = process_simple_attribute(txt, ['Project Phase'])
|
1786
|
-
project_health = process_simple_attribute(txt, ['Project Health'])
|
1787
|
-
start_date = process_simple_attribute(txt, ['Start Date'])
|
1788
|
-
planned_end_date = process_simple_attribute(txt, ['Planned End Date'])
|
1789
|
-
print(Markdown(f"{pre_command} `\'{command}\'` for project: `{project_name}` with directive: `{directive}` "))
|
1965
|
+
element_labels = TERM_NAME_LABELS
|
1966
|
+
element_labels.append('Display Name')
|
1790
1967
|
|
1791
|
-
|
1792
|
-
f"* Status: {project_status}\n\t* Description: {description}\n\t"
|
1793
|
-
f"* Phase: {project_phase}\n\t* Health: {project_health}\n\t"
|
1794
|
-
f"* Start Date: {start_date}\n\t* Planned End Date: {planned_end_date}\n")
|
1968
|
+
term_name = process_simple_attribute(txt, element_labels, "ERROR")
|
1795
1969
|
|
1796
|
-
|
1797
|
-
|
1798
|
-
msg = ""
|
1799
|
-
known_guid = None
|
1800
|
-
known_q_name = None
|
1970
|
+
known_q_name, known_guid, valid, term_exists = process_element_identifiers(egeria_client, object_type,
|
1971
|
+
element_labels, txt, object_action, )
|
1801
1972
|
|
1802
|
-
|
1803
|
-
if project_details == NO_PROJECTS_FOUND:
|
1804
|
-
project_exists = False
|
1805
|
-
else:
|
1806
|
-
project_exists = True
|
1973
|
+
print(Markdown(f"{pre_command} `{command}` for term:`{term_name}` with directive: `{directive}`"))
|
1807
1974
|
|
1808
|
-
|
1809
|
-
|
1810
|
-
|
1811
|
-
|
1812
|
-
|
1975
|
+
output_format = process_simple_attribute(txt, OUTPUT_LABELS, "INFO")
|
1976
|
+
if output_format is None:
|
1977
|
+
output_format = "LIST"
|
1978
|
+
elif output_format not in ["DICT", "LIST"]:
|
1979
|
+
valid = False
|
1980
|
+
print_msg(ERROR, f"Invalid output format: `{output_format}`", debug_level)
|
1813
1981
|
|
1814
|
-
|
1815
|
-
msg += f"* {INFO}No Description found\n"
|
1982
|
+
request_display = f"\n\t* Term Name: {term_name}\n\t* Output Format {output_format}\n\t* GUID: {known_guid}\n"
|
1816
1983
|
|
1817
|
-
|
1818
|
-
|
1984
|
+
if directive == "display":
|
1985
|
+
print(request_display)
|
1986
|
+
return None
|
1987
|
+
elif directive == "validate":
|
1988
|
+
print(request_display)
|
1989
|
+
return valid
|
1990
|
+
elif directive == "process":
|
1991
|
+
try:
|
1992
|
+
print(request_display)
|
1993
|
+
if not valid: # First validate the term before we process it
|
1994
|
+
return None
|
1995
|
+
term_history_md = f"\n# Term History for `{term_name}`\n\n"
|
1996
|
+
if output_format == "DICT":
|
1997
|
+
struct = egeria_client.list_term_revision_history(known_guid, output_format=output_format)
|
1998
|
+
term_history_md += f"```{json.dumps(struct, indent=4)}```\n"
|
1999
|
+
else:
|
2000
|
+
term_history_md += egeria_client.list_full_term_history(known_guid, output_format)
|
2001
|
+
print_msg("ALWAYS", f"Wrote Term History for term `{term_name}`", debug_level)
|
1819
2002
|
|
1820
|
-
|
1821
|
-
msg += f"* {INFO}No Project Phase found\n"
|
2003
|
+
return term_history_md
|
1822
2004
|
|
1823
|
-
|
1824
|
-
|
2005
|
+
except Exception as e:
|
2006
|
+
print(f"{ERROR}Error performing {command}: {e}")
|
2007
|
+
console.print_exception(show_locals=True)
|
2008
|
+
return None
|
2009
|
+
else:
|
2010
|
+
return None
|
1825
2011
|
|
1826
|
-
if start_date is None:
|
1827
|
-
msg += f"* {INFO}No Start Date found\n"
|
1828
|
-
elif not is_valid_iso_date(start_date):
|
1829
|
-
msg += f"* {ERROR}Start Date is not a valid ISO date of form YYYY-MM-DD\n"
|
1830
|
-
valid = False
|
1831
2012
|
|
1832
|
-
|
1833
|
-
|
1834
|
-
|
1835
|
-
|
1836
|
-
|
2013
|
+
def process_term_revision_history_command(egeria_client: EgeriaTech, txt: str, directive: str = "display") -> Optional[str]:
|
2014
|
+
""" List term revision history as a markdown table or list."""
|
2015
|
+
set_debug_level(directive)
|
2016
|
+
valid = True
|
2017
|
+
command = extract_command(txt)
|
2018
|
+
object_type = command.split(' ')[1].strip()
|
2019
|
+
object_action = command.split(' ')[0].strip()
|
2020
|
+
known_q_name = None
|
2021
|
+
known_guid = None
|
1837
2022
|
|
1838
|
-
|
1839
|
-
q_name = process_simple_attribute(txt, 'Qualified Name')
|
2023
|
+
element_labels = TERM_NAME_LABELS
|
1840
2024
|
|
1841
|
-
|
1842
|
-
|
1843
|
-
valid = False
|
1844
|
-
if len(project_details) > 1 and project_exists:
|
1845
|
-
msg += f"* {ERROR}More than one project with name {project_name} found\n"
|
1846
|
-
valid = False
|
1847
|
-
if len(project_details) == 1:
|
1848
|
-
known_guid = project_details[0]['elementHeader'].get('guid', None)
|
1849
|
-
known_q_name = project_details[0]['glossaryProperties'].get('qualifiedName', None)
|
1850
|
-
if q_name is None:
|
1851
|
-
msg += f"* {INFO}Qualified Name is missing => can use known qualified name of {known_q_name}\n"
|
1852
|
-
valid = True
|
1853
|
-
elif q_name != known_q_name:
|
1854
|
-
msg += (f"* {ERROR}Project {project_name} qualifiedName mismatch between {q_name} and {known_q_name}\n")
|
1855
|
-
valid = False
|
1856
|
-
if valid:
|
1857
|
-
msg += project_display
|
1858
|
-
msg += f"* -->Project {project_name} exists and can be updated\n"
|
1859
|
-
else:
|
1860
|
-
msg += f"* --> validation failed\n"
|
1861
|
-
msg += '---'
|
1862
|
-
print(Markdown(msg))
|
1863
|
-
return valid, project_exists, known_guid, known_q_name
|
2025
|
+
term_name = process_simple_attribute(txt, element_labels, "ERROR")
|
2026
|
+
print(Markdown(f"{pre_command} `{command}` for term: `{term_name}` with directive: `{directive}` "))
|
1864
2027
|
|
1865
|
-
|
1866
|
-
|
1867
|
-
|
1868
|
-
|
1869
|
-
|
1870
|
-
|
1871
|
-
|
2028
|
+
known_q_name, known_guid, valid, _ = process_element_identifiers(egeria_client, object_type, element_labels, txt,
|
2029
|
+
object_action, )
|
2030
|
+
output_format = process_simple_attribute(txt, ['Output Format', 'Format'], 'INFO')
|
2031
|
+
if output_format is None:
|
2032
|
+
output_format = "LIST"
|
2033
|
+
elif output_format not in ["DICT", "LIST", "MD"]:
|
2034
|
+
valid = False
|
2035
|
+
print_msg(ERROR, f"Invalid output format: `{output_format}`", debug_level)
|
2036
|
+
|
2037
|
+
request_display = f"\n\t* Term Name: {term_name}\n\t* Output Format: {output_format}\n"
|
1872
2038
|
|
1873
2039
|
if directive == "display":
|
1874
|
-
print(
|
2040
|
+
print(request_display)
|
1875
2041
|
return None
|
1876
|
-
|
1877
2042
|
elif directive == "validate":
|
1878
|
-
|
1879
|
-
valid
|
1880
|
-
return valid
|
1881
|
-
|
2043
|
+
print(request_display)
|
2044
|
+
return str(valid)
|
1882
2045
|
elif directive == "process":
|
1883
|
-
|
1884
|
-
|
1885
|
-
|
1886
|
-
if object_action == "Update":
|
1887
|
-
if not exists:
|
1888
|
-
print(f"\n\n-->Project {project_name} does not exist")
|
2046
|
+
try:
|
2047
|
+
print(request_display)
|
2048
|
+
if not valid: # First validate the term before we process it
|
1889
2049
|
return None
|
1890
|
-
|
1891
|
-
|
1892
|
-
|
1893
|
-
|
1894
|
-
print_msg(ALWAYS, f"Updated Project `{project_name}` with GUID {known_guid}", debug_level)
|
1895
|
-
return update_a_command(txt, command, object_type, known_q_name, known_guid)
|
1896
|
-
elif object_action == "Create":
|
1897
|
-
guid = None
|
1898
|
-
if exists:
|
1899
|
-
print(f"Project `{project_name}` already exists and update document created")
|
1900
|
-
return update_a_command(txt, command, object_type, known_q_name, known_guid)
|
2050
|
+
term_history_md = f"\n# Term Revision History for `{term_name}`\n\n"
|
2051
|
+
if output_format == "DICT":
|
2052
|
+
struct = egeria_client.list_term_revision_history(known_guid, output_format)
|
2053
|
+
term_history_md += f"```{json.dumps(struct, indent=4)}```\n"
|
1901
2054
|
else:
|
1902
|
-
|
1903
|
-
|
1904
|
-
|
1905
|
-
|
1906
|
-
|
1907
|
-
|
1908
|
-
|
2055
|
+
term_history_md += egeria_client.list_term_revision_history(known_guid, output_format)
|
2056
|
+
print_msg("ALWAYS", f"Wrote Term Revision History for term `{term_name}`", debug_level)
|
2057
|
+
return term_history_md
|
2058
|
+
|
2059
|
+
except Exception as e:
|
2060
|
+
print(f"{ERROR}Error performing {command}: {e}")
|
2061
|
+
console.print_exception(show_locals=True)
|
2062
|
+
return None
|
2063
|
+
else:
|
2064
|
+
return None
|
1909
2065
|
|
1910
|
-
q_name = project_g['projectProperties']["qualifiedName"]
|
1911
|
-
update_element_dictionary(q_name, {'guid': guid, 'display_name': project_name})
|
1912
|
-
print_msg(ALWAYS, f"Created project `{project_name}` with GUID {guid}", debug_level)
|
1913
|
-
return update_a_command(txt, command, object_type, q_name, guid)
|