pyegeria 5.3.6.3__py3-none-any.whl → 5.3.6.5__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/_client.py +10 -0
- pyegeria/commands/cat/Dr-Egeria_md-orig.py +167 -0
- pyegeria/commands/cat/dr_egeria_md.py +53 -47
- pyegeria/commands/cat/get_collection.py +2 -2
- pyegeria/commands/cli/egeria.py +1 -1
- pyegeria/glossary_browser_omvs.py +49 -31
- pyegeria/glossary_manager_omvs.py +4 -5
- pyegeria/md_processing_utils.py +190 -123
- {pyegeria-5.3.6.3.dist-info → pyegeria-5.3.6.5.dist-info}/METADATA +1 -1
- {pyegeria-5.3.6.3.dist-info → pyegeria-5.3.6.5.dist-info}/RECORD +14 -14
- pyegeria/commands/cat/dr_egeria_inbox/freddie_intro.md +0 -269
- {pyegeria-5.3.6.3.dist-info → pyegeria-5.3.6.5.dist-info}/LICENSE +0 -0
- {pyegeria-5.3.6.3.dist-info → pyegeria-5.3.6.5.dist-info}/WHEEL +0 -0
- {pyegeria-5.3.6.3.dist-info → pyegeria-5.3.6.5.dist-info}/entry_points.txt +0 -0
pyegeria/md_processing_utils.py
CHANGED
@@ -8,6 +8,8 @@ This file contains functions to parse and process Egeria Markdown (Freddie)
|
|
8
8
|
import json
|
9
9
|
from jupyter_notebook_parser import JupyterNotebookParser
|
10
10
|
import nbformat
|
11
|
+
from typing import List, Optional
|
12
|
+
|
11
13
|
import os
|
12
14
|
import re
|
13
15
|
from pyegeria import EgeriaTech, NO_CATEGORIES_FOUND
|
@@ -19,18 +21,23 @@ from rich.table import Table
|
|
19
21
|
import click
|
20
22
|
from pyegeria import EgeriaTech, body_slimmer, NO_GLOSSARIES_FOUND, NO_TERMS_FOUND, NO_ELEMENTS_FOUND, NO_PROJECTS_FOUND
|
21
23
|
from pyegeria._exceptions import (InvalidParameterException, PropertyServerException, print_exception_response, )
|
22
|
-
import datetime
|
23
|
-
|
24
|
-
console = Console(width=
|
24
|
+
from datetime import datetime
|
25
|
+
EGERIA_WIDTH = int(os.environ.get("EGERIA_WIDTH", "200"))
|
26
|
+
console = Console(width=EGERIA_WIDTH)
|
25
27
|
|
26
|
-
commands = ["Create Glossary", "Update Glossary", "Create Term", "Update Term", "Create Personal Project",
|
28
|
+
commands = ["Provenance", "Create Glossary", "Update Glossary", "Create Term", "Update Term", "Create Personal Project",
|
27
29
|
"Update Personal Project", "Create Category", "Update Category"]
|
28
30
|
ERROR = "ERROR-> "
|
29
31
|
INFO = "INFO- "
|
30
32
|
WARNING = "WARNING-> "
|
31
33
|
pre_command = "\n---\n==> Processing command:"
|
34
|
+
EGERIA_LOCAL_QUALIFIER = os.environ.get("EGERIA_LOCAL_QUALIFIER", "PDR")
|
32
35
|
element_dictionary = {}
|
33
36
|
|
37
|
+
def render_markdown(markdown_text: str) -> None:
|
38
|
+
"""Renders the given markdown text in the console."""
|
39
|
+
console.print(Markdown(markdown_text))
|
40
|
+
|
34
41
|
|
35
42
|
def is_valid_iso_date(date_text) -> bool:
|
36
43
|
"""Checks if the given string is a valid ISO date."""
|
@@ -43,46 +50,53 @@ def is_valid_iso_date(date_text) -> bool:
|
|
43
50
|
|
44
51
|
def get_current_datetime_string():
|
45
52
|
"""Returns the current date and time as a human-readable string."""
|
46
|
-
now = datetime.
|
47
|
-
return now
|
53
|
+
now = datetime.now().strftime('%Y-%m-%d %H:%M')
|
54
|
+
return now
|
55
|
+
|
48
56
|
|
49
|
-
def add_term_to_categories(egeria_client: EgeriaTech, term_guid: str, categories_exist: bool,
|
57
|
+
def add_term_to_categories(egeria_client: EgeriaTech, term_guid: str, categories_exist: bool,
|
58
|
+
categories_list: List[str], element_dictionary: dict) -> None:
|
50
59
|
if categories_exist is True and categories_list is not None:
|
51
60
|
for category in categories_list:
|
52
61
|
cat_guid = None
|
53
|
-
cat_el =
|
62
|
+
cat_el = category.strip()
|
54
63
|
if cat_el in element_dictionary:
|
55
64
|
cat= element_dictionary.get(cat_el, None)
|
56
65
|
cat_guid = cat.get('guid', None) if cat else None
|
57
66
|
if cat_guid is None:
|
58
|
-
cat_guid = egeria_client.__get_guid__(
|
67
|
+
cat_guid = egeria_client.__get_guid__(qualified_name=cat_el)
|
59
68
|
egeria_client.add_term_to_category(term_guid, cat_guid)
|
60
69
|
|
61
70
|
|
62
|
-
|
63
|
-
def extract_command(block: str) -> str | None:
|
71
|
+
def extract_command(block: str) -> Optional[str]:
|
64
72
|
match = re.search(r"#(.*?)(?:##|\n|$)", block) # Using a non capturing group
|
65
73
|
if match:
|
66
74
|
return match.group(1).strip()
|
67
75
|
return None
|
68
76
|
|
69
77
|
|
70
|
-
def extract_attribute(text: str,
|
78
|
+
def extract_attribute(text: str, labels: List[str]) -> Optional[str]:
|
71
79
|
"""
|
72
80
|
Extracts the glossary name from a string.
|
73
81
|
|
74
82
|
Args:
|
75
83
|
text: The input string.
|
76
|
-
label:
|
84
|
+
label: List of equivalent labels to search for
|
77
85
|
|
78
86
|
Returns:
|
79
87
|
The glossary name, or None if not found.
|
80
88
|
"""
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
89
|
+
# Iterate over the list of labels
|
90
|
+
for label in labels:
|
91
|
+
# Construct pattern for the current label
|
92
|
+
pattern = rf"## {re.escape(label)}\n(.*?)(?:#|---|$)"
|
93
|
+
match = re.search(pattern, text, re.DOTALL)
|
94
|
+
if match:
|
95
|
+
# Extract matched text and replace consecutive \n with a single \n
|
96
|
+
extracted_text = re.sub(r'\n+', '\n', match.group(1).strip())
|
97
|
+
if not extracted_text.isspace() and extracted_text:
|
98
|
+
return extracted_text # Return the cleaned text
|
99
|
+
|
86
100
|
return None
|
87
101
|
|
88
102
|
|
@@ -90,13 +104,13 @@ def update_a_command(txt: str, command: str, obj_type: str, q_name: str, u_guid:
|
|
90
104
|
u_guid = u_guid if u_guid else " "
|
91
105
|
verb = command.split(' ')[0].strip()
|
92
106
|
action = "Update" if (verb == "Create" and u_guid is not None) else "Create"
|
93
|
-
txt = txt.replace(f"{command}", f'
|
94
|
-
txt = txt.replace('<GUID>', f'
|
95
|
-
txt = txt.replace('<Qualified Name>', f"
|
107
|
+
txt = txt.replace(f"{command}", f'{action} {obj_type}\n') # update the command
|
108
|
+
txt = txt.replace('<GUID>', f'GUID\n{u_guid}') # update with GUID
|
109
|
+
txt = txt.replace('<Qualified Name>', f"Qualified Name\n{q_name}")
|
96
110
|
if "Qualified Name" not in txt:
|
97
|
-
txt += f"\n##
|
111
|
+
txt += f"\n## Qualified Name\n{q_name}\n"
|
98
112
|
if "GUID" not in txt:
|
99
|
-
txt += f"\n##
|
113
|
+
txt += f"\n## GUID\n{u_guid}\n"
|
100
114
|
|
101
115
|
# if (command in {"Update Term", "Update Category", 'Update Glossary'}) and ("Update Description" not in txt):
|
102
116
|
# txt += '\n** Update Description\n\n\n'
|
@@ -112,9 +126,18 @@ def update_a_command(txt: str, command: str, obj_type: str, q_name: str, u_guid:
|
|
112
126
|
txt = re.sub(pattern, replacement, txt)
|
113
127
|
return txt
|
114
128
|
|
129
|
+
def process_provenance_command(file_path: str, txt: str) -> str:
|
130
|
+
"""This commands processes a provenence command by pre-pending the current file name and time to the provenance
|
131
|
+
output"""
|
132
|
+
output = (f"* Derived from processing file {file_path} on "
|
133
|
+
f"{get_current_datetime_string()}\n")
|
134
|
+
existing_prov = extract_attribute(txt,'Provenance')
|
135
|
+
existing_prov = existing_prov if existing_prov else " "
|
136
|
+
return f"\n# Provenance:\n{existing_prov}\n{output}\n"
|
137
|
+
|
115
138
|
|
116
139
|
def process_glossary_upsert_command(egeria_client: EgeriaTech, element_dictionary: dict, txt: str,
|
117
|
-
directive: str = "display") -> str
|
140
|
+
directive: str = "display") -> Optional[str]:
|
118
141
|
"""
|
119
142
|
Processes a glossary create or update command by extracting key attributes such as
|
120
143
|
glossary name, language, description, and usage from the given text.
|
@@ -128,22 +151,22 @@ def process_glossary_upsert_command(egeria_client: EgeriaTech, element_dictionar
|
|
128
151
|
object_type = command.split(' ')[1].strip()
|
129
152
|
object_action = command.split(' ')[0].strip()
|
130
153
|
|
131
|
-
glossary_name = extract_attribute(txt, 'Glossary Name')
|
154
|
+
glossary_name = extract_attribute(txt, ['Glossary Name'])
|
132
155
|
print(Markdown(f"{pre_command} `{command}` for glossary: `\'{glossary_name}\'` with directive: `{directive}` "))
|
133
|
-
language = extract_attribute(txt, 'Language')
|
134
|
-
description = extract_attribute(txt, 'Description')
|
135
|
-
usage = extract_attribute(txt, 'Usage')
|
156
|
+
language = extract_attribute(txt, ['Language'])
|
157
|
+
description = extract_attribute(txt, ['Description'])
|
158
|
+
usage = extract_attribute(txt, ['Usage'])
|
136
159
|
|
137
160
|
glossary_display = (f"\n* Command: {command}\n\t* Glossary Name: {glossary_name}\n\t"
|
138
161
|
f"* Language: {language}\n\t* Description:\n{description}\n"
|
139
162
|
f"* Usage: {usage}\n")
|
140
163
|
|
141
164
|
if object_action == 'Update':
|
142
|
-
q_name = extract_attribute(txt, 'Qualified Name')
|
143
|
-
guid = extract_attribute(txt, 'GUID')
|
165
|
+
q_name = extract_attribute(txt, ['Qualified Name'])
|
166
|
+
guid = extract_attribute(txt, ['GUID', 'guid', 'Guid'])
|
144
167
|
glossary_display += f"* Qualified Name: {q_name}\n\t* GUID: {guid}\n\n"
|
145
168
|
|
146
|
-
def validate_glossary(obj_action: str) -> tuple[bool, bool, str
|
169
|
+
def validate_glossary(obj_action: str) -> tuple[bool, bool, Optional[str], Optional[str]]:
|
147
170
|
valid = True
|
148
171
|
msg = ""
|
149
172
|
known_glossary_guid = None
|
@@ -169,7 +192,7 @@ def process_glossary_upsert_command(egeria_client: EgeriaTech, element_dictionar
|
|
169
192
|
valid = False
|
170
193
|
if len(glossary_details) == 1:
|
171
194
|
known_glossary_guid = glossary_details[0]['elementHeader'].get('guid', None)
|
172
|
-
known_q_name = glossary_details[0]['glossaryProperties'].get('qualifiedName', None)
|
195
|
+
known_q_name = glossary_details[0]['glossaryProperties'].get('qualifiedName', None).strip()
|
173
196
|
|
174
197
|
if obj_action == "Update":
|
175
198
|
|
@@ -236,11 +259,11 @@ def process_glossary_upsert_command(egeria_client: EgeriaTech, element_dictionar
|
|
236
259
|
}
|
237
260
|
egeria_client.update_glossary(known_guid, body)
|
238
261
|
print(f"\n-->Updated Glossary {glossary_name} with GUID {known_guid}")
|
239
|
-
element_dictionary[
|
240
|
-
'guid': known_guid, '
|
262
|
+
element_dictionary[known_q_name] = {
|
263
|
+
'guid': known_guid, 'display_name': glossary_name
|
241
264
|
}
|
242
265
|
# return update_a_command(txt, command, object_type, known_q_name, known_guid)
|
243
|
-
return egeria_client.get_glossary_by_guid(known_guid, output_format='
|
266
|
+
return egeria_client.get_glossary_by_guid(known_guid, output_format='MD')
|
244
267
|
elif object_action == "Create":
|
245
268
|
glossary_guid = None
|
246
269
|
|
@@ -254,15 +277,15 @@ def process_glossary_upsert_command(egeria_client: EgeriaTech, element_dictionar
|
|
254
277
|
print(f"{ERROR}Just created with GUID {glossary_guid} but Glossary not found\n")
|
255
278
|
return None
|
256
279
|
qualified_name = glossary['glossaryProperties']["qualifiedName"]
|
257
|
-
element_dictionary[
|
258
|
-
'guid': glossary_guid, '
|
280
|
+
element_dictionary[qualified_name] = {
|
281
|
+
'guid': glossary_guid, 'display_name': glossary_name
|
259
282
|
}
|
260
283
|
# return update_a_command(txt, command, object_type, qualified_name, glossary_guid)
|
261
|
-
return egeria_client.get_glossary_by_guid(glossary_guid, output_format = '
|
284
|
+
return egeria_client.get_glossary_by_guid(glossary_guid, output_format = 'MD')
|
262
285
|
|
263
286
|
|
264
287
|
def process_categories_upsert_command(egeria_client: EgeriaTech, element_dictionary: dict, txt: str,
|
265
|
-
directive: str = "display") -> str
|
288
|
+
directive: str = "display") -> Optional[str]:
|
266
289
|
"""
|
267
290
|
Processes a glossary category create or update command by extracting key attributes such as
|
268
291
|
category name, qualified, description, and anchor glossary from the given txt..
|
@@ -276,22 +299,23 @@ def process_categories_upsert_command(egeria_client: EgeriaTech, element_diction
|
|
276
299
|
object_type = command.split(' ')[1].strip()
|
277
300
|
object_action = command.split(' ')[0].strip()
|
278
301
|
|
279
|
-
category_name = extract_attribute(txt, 'Category Name')
|
302
|
+
category_name = extract_attribute(txt, ['Category Name', 'category_name', 'Cat'])
|
280
303
|
print(Markdown(f"{pre_command} `{command}` for category: `\'{category_name}\'` with directive: `{directive}` "))
|
281
|
-
|
282
|
-
description = extract_attribute(txt, 'Description')
|
283
|
-
|
284
|
-
|
304
|
+
owning_glossary_qn = extract_attribute(txt, ['Owning Glossary', '[In Glossary'])
|
305
|
+
description = extract_attribute(txt, ['Description'])
|
306
|
+
q_name = extract_attribute(txt, ['Qualified Name'])
|
307
|
+
|
308
|
+
category_display = (f"\n* Command: {command}\n\t* Category: {category_name}\n\t* In Glossary: {owning_glossary_qn}\n\t"
|
309
|
+
f"* Description:\n{description}\n\t* Qualified Name: {q_name}\n\t")
|
285
310
|
update_description = None
|
286
311
|
|
287
312
|
if object_action == 'Update':
|
288
|
-
|
289
|
-
guid = extract_attribute(txt, 'GUID')
|
313
|
+
guid = extract_attribute(txt, ['GUID','guid','Guid'])
|
290
314
|
update_description = extract_attribute(txt, 'Update Description')
|
291
|
-
category_display += (f"*
|
315
|
+
category_display += (f"* GUID: {guid}\n\n"
|
292
316
|
f"* Update Description: \n {update_description}\n\t")
|
293
317
|
|
294
|
-
def validate_category(obj_action: str) -> tuple[bool, bool, str
|
318
|
+
def validate_category(obj_action: str) -> tuple[bool, bool, Optional[str], Optional[str], Optional[str]]:
|
295
319
|
valid = True
|
296
320
|
msg = ""
|
297
321
|
known_category_guid = None
|
@@ -303,28 +327,33 @@ def process_categories_upsert_command(egeria_client: EgeriaTech, element_diction
|
|
303
327
|
category_exists = False
|
304
328
|
else:
|
305
329
|
category_exists = True
|
306
|
-
|
307
|
-
if
|
308
|
-
msg += f"* {ERROR}Owning Glossary is missing\n"
|
330
|
+
|
331
|
+
if owning_glossary_qn is None:
|
332
|
+
msg += f"* {ERROR}Owning Glossary Qualified Name is missing\n"
|
309
333
|
valid = False
|
310
334
|
|
311
|
-
elif
|
312
|
-
|
313
|
-
glossary_guid = element_dictionary[
|
314
|
-
|
335
|
+
elif owning_glossary_qn in element_dictionary: # Check to see if we already know about this glossary
|
336
|
+
glossary_name = element_dictionary[owning_glossary_qn].get('display_name', None)
|
337
|
+
glossary_guid = element_dictionary[owning_glossary_qn].get('guid', None)
|
338
|
+
|
315
339
|
else:
|
316
340
|
# need to ask Egeria if it knows the Glossary Name
|
317
|
-
glossary = egeria_client.get_glossaries_by_name(
|
341
|
+
glossary = egeria_client.get_glossaries_by_name(owning_glossary_qn)
|
318
342
|
if glossary == NO_GLOSSARIES_FOUND:
|
319
|
-
msg += f"* {ERROR}Glossary `{
|
343
|
+
msg += f"* {ERROR}Glossary `{owning_glossary_qn}` does not exist\n\n"
|
320
344
|
valid = False
|
321
345
|
else:
|
322
|
-
msg += f"* {INFO}Glossary `{
|
346
|
+
msg += f"* {INFO}Glossary `{owning_glossary_qn}` exists\n\n"
|
323
347
|
glossary_guid = glossary[0]['elementHeader'].get('guid', None)
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
}
|
348
|
+
glossary_name = glossary[0]['glossaryProperties'].get('displayName', None)
|
349
|
+
glossary_qn = glossary[0]['glossaryProperties'].get('qualifiedName', None)
|
350
|
+
if glossary_qn != owning_glossary_qn: # we were given the right qualified name - maybe a display_name
|
351
|
+
msg += f"* {ERROR}Glossary `{owning_glossary_qn}` is known by qualifiedName `{glossary_qn}`\n\n"
|
352
|
+
valid = False
|
353
|
+
else:
|
354
|
+
element_dictionary[owning_glossary_qn] = {
|
355
|
+
'guid': glossary_guid, 'display_name': glossary_name
|
356
|
+
}
|
328
357
|
|
329
358
|
if category_name is None:
|
330
359
|
msg = f"* {ERROR}Category name is missing\n"
|
@@ -396,11 +425,11 @@ def process_categories_upsert_command(egeria_client: EgeriaTech, element_diction
|
|
396
425
|
egeria_client.update_category(glossary_guid, category_name, description, known_q_name, None,
|
397
426
|
update_description)
|
398
427
|
print(f"\n-->Updated category `{category_name}`with GUID {known_guid}")
|
399
|
-
element_dictionary[
|
400
|
-
'guid': known_guid, '
|
428
|
+
element_dictionary[known_q_name] = {
|
429
|
+
'guid': known_guid, 'display_name': category_name
|
401
430
|
}
|
402
431
|
# return update_a_command(txt, command, object_type, known_q_name, known_guid)
|
403
|
-
return egeria_client.get_categories_by_guid(known_guid, output_format='
|
432
|
+
return egeria_client.get_categories_by_guid(known_guid, output_format='FORM')
|
404
433
|
|
405
434
|
elif object_action == "Create":
|
406
435
|
is_root = False
|
@@ -416,14 +445,15 @@ def process_categories_upsert_command(egeria_client: EgeriaTech, element_diction
|
|
416
445
|
print(f"{ERROR}Just created with GUID {category_guid} but category not found\n")
|
417
446
|
return None
|
418
447
|
qualified_name = category['glossaryCategoryProperties']["qualifiedName"]
|
419
|
-
element_dictionary[
|
420
|
-
'guid': category_guid, '
|
448
|
+
element_dictionary[qualified_name] = {
|
449
|
+
'guid': category_guid, 'display_name': category_name
|
421
450
|
}
|
422
451
|
# return update_a_command(txt, command, object_type, qualified_name, category_guid)
|
423
|
-
return egeria_client.get_categories_by_guid(category_guid, output_format='
|
452
|
+
return egeria_client.get_categories_by_guid(category_guid, output_format='MD')
|
453
|
+
|
424
454
|
|
425
455
|
def process_term_upsert_command(egeria_client: EgeriaTech, element_dictionary: dict, txt: str,
|
426
|
-
directive: str = "display") -> str
|
456
|
+
directive: str = "display") -> Optional[str]:
|
427
457
|
"""
|
428
458
|
Processes a term create or update command by extracting key attributes such as
|
429
459
|
term name, summary, description, abbreviation, examples, usage, version, and status from the given cell.
|
@@ -438,30 +468,39 @@ def process_term_upsert_command(egeria_client: EgeriaTech, element_dictionary: d
|
|
438
468
|
object_type = command.split(' ')[1].strip()
|
439
469
|
object_action = command.split(' ')[0].strip()
|
440
470
|
|
441
|
-
term_name = extract_attribute(txt, 'Term Name')
|
442
|
-
summary = extract_attribute(txt, 'Summary')
|
443
|
-
description = extract_attribute(txt, 'Description')
|
444
|
-
abbreviation = extract_attribute(txt, 'Abbreviation')
|
445
|
-
examples = extract_attribute(txt, 'Examples')
|
446
|
-
usage = extract_attribute(txt, 'Usage')
|
447
|
-
status = extract_attribute(txt, 'Status')
|
448
|
-
version = extract_attribute(txt, 'Version')
|
449
|
-
categories = extract_attribute(txt, 'Categories')
|
471
|
+
term_name = extract_attribute(txt, ['Term Name'])
|
472
|
+
summary = extract_attribute(txt, ['Summary'])
|
473
|
+
description = extract_attribute(txt, ['Description'])
|
474
|
+
abbreviation = extract_attribute(txt, ['Abbreviation'])
|
475
|
+
examples = extract_attribute(txt, ['Examples'])
|
476
|
+
usage = extract_attribute(txt, ['Usage'])
|
477
|
+
status = extract_attribute(txt, ['Status'])
|
478
|
+
version = extract_attribute(txt, ['Version', "Version Identifier"])
|
479
|
+
categories = extract_attribute(txt, ['Categories'])
|
480
|
+
q_name = extract_attribute(txt, ['Qualified Name'])
|
481
|
+
# q_name = q_name if q_name else " "
|
482
|
+
|
450
483
|
categories_list = None
|
451
484
|
cats_exist = True
|
452
485
|
|
453
|
-
|
486
|
+
glossary_qn = extract_attribute(txt, ['In Glossary','Owning Glossary'])
|
454
487
|
|
455
488
|
print(Markdown(f"{pre_command} `{command}` for term: `\'{term_name}\'` with directive: `{directive}`"))
|
456
489
|
|
457
|
-
def validate_term(obj_action: str) -> tuple[bool, bool, str
|
458
|
-
nonlocal version, status, categories, categories_list, cats_exist
|
490
|
+
def validate_term(obj_action: str) -> tuple[bool, bool, Optional[str], Optional[str]]:
|
491
|
+
nonlocal version, status, categories, categories_list, cats_exist, q_name
|
459
492
|
valid = True
|
460
493
|
msg = ""
|
461
494
|
known_term_guid = None
|
462
495
|
known_q_name = None
|
463
496
|
|
464
|
-
|
497
|
+
# If the user has specified a qualified_name then use it to look for matching terms.
|
498
|
+
# If not, use the display_name.
|
499
|
+
if q_name:
|
500
|
+
term_details = egeria_client.get_terms_by_name(q_name)
|
501
|
+
else:
|
502
|
+
term_details = egeria_client.get_terms_by_name(term_name)
|
503
|
+
|
465
504
|
if term_details == NO_TERMS_FOUND:
|
466
505
|
term_exists = False
|
467
506
|
else:
|
@@ -475,33 +514,51 @@ def process_term_upsert_command(egeria_client: EgeriaTech, element_dictionary: d
|
|
475
514
|
if term_name is None:
|
476
515
|
msg = f"* {ERROR}Term name is missing\n"
|
477
516
|
valid = False
|
478
|
-
if
|
479
|
-
msg += f"* {ERROR}Glossary name is missing\n"
|
517
|
+
if glossary_qn is None:
|
518
|
+
msg += f"* {ERROR}Glossary qualified name is missing\n"
|
480
519
|
valid = False
|
481
520
|
else:
|
482
|
-
|
483
|
-
|
484
|
-
glossary = egeria_client.get_glossaries_by_name(glossary_name)
|
521
|
+
if glossary_qn not in element_dictionary:
|
522
|
+
glossary = egeria_client.get_glossaries_by_name(glossary_qn) #assuming q_name?
|
485
523
|
if isinstance(glossary,str):
|
486
|
-
msg += f"* {ERROR}Glossary `{
|
524
|
+
msg += f"* {ERROR}Glossary `{glossary_qn}` is unknown\n "
|
487
525
|
valid = False
|
526
|
+
else:
|
527
|
+
element_dictionary[glossary_qn] = {
|
528
|
+
'guid': glossary[0]['elementHeader'].get('guid', None),
|
529
|
+
'display_name': glossary[0]['glossaryProperties'].get('displayName', None)
|
530
|
+
}
|
531
|
+
|
488
532
|
|
489
533
|
if categories is None:
|
490
|
-
msg += f"* {INFO}
|
534
|
+
msg += f"* {INFO} No categories found\n"
|
491
535
|
else:
|
492
536
|
categories_list = re.split(r'[,\n]+', categories)
|
493
537
|
categories = ""
|
538
|
+
new_cat_list = []
|
494
539
|
for category in categories_list:
|
495
|
-
category_el =
|
540
|
+
category_el = category.strip()
|
496
541
|
if category_el not in element_dictionary:
|
497
|
-
cat = egeria_client.get_categories_by_name(
|
542
|
+
cat = egeria_client.get_categories_by_name(category_el) # assuming qualified name?
|
498
543
|
if isinstance(cat,str):
|
499
|
-
msg += (f"* {WARNING}Category `{
|
544
|
+
msg += (f"* {WARNING}Category `{category_el}` not found -> "
|
500
545
|
f"categories for this term won't be processed!\n")
|
501
546
|
cats_exist = False
|
547
|
+
break
|
548
|
+
cat_qname = cat[0]['glossaryCategoryProperties'].get('qualifiedName', None)
|
549
|
+
category = cat_qname # use the qualified name if found
|
550
|
+
if cat_qname not in element_dictionary:
|
551
|
+
cat_guid = cat[0]['elementHeader']['guid']
|
552
|
+
cat_display_name = cat[0]['glossaryCategoryProperties'].get('displayName', None)
|
553
|
+
element_dictionary[cat_qname] = {
|
554
|
+
'guid' : cat_guid,
|
555
|
+
'displayName': cat_display_name
|
556
|
+
}
|
502
557
|
categories = f"{category}, {categories}"
|
558
|
+
new_cat_list.append(category)
|
503
559
|
if cats_exist:
|
504
560
|
categories +='\n'
|
561
|
+
categories_list = new_cat_list
|
505
562
|
else:
|
506
563
|
categories = None
|
507
564
|
|
@@ -519,8 +576,9 @@ def process_term_upsert_command(egeria_client: EgeriaTech, element_dictionary: d
|
|
519
576
|
if usage is None:
|
520
577
|
msg += f"* {INFO}Term usage is missing\n"
|
521
578
|
if version is None:
|
522
|
-
msg += f"* {INFO}Term version is missing
|
523
|
-
version = "0.0.1"
|
579
|
+
msg += f"* {INFO}Term version is missing\n"
|
580
|
+
# version = "0.0.1"
|
581
|
+
|
524
582
|
|
525
583
|
if obj_action == "Update": # check to see if provided information exists and is consistent with existing info
|
526
584
|
if not term_exists:
|
@@ -528,7 +586,8 @@ def process_term_upsert_command(egeria_client: EgeriaTech, element_dictionary: d
|
|
528
586
|
valid = False
|
529
587
|
|
530
588
|
if len(term_details) > 1 and term_exists:
|
531
|
-
msg += f"* {ERROR}More than one term with name {term_name} found
|
589
|
+
msg += (f"* {ERROR}More than one term with name {term_name} found, please specify a "
|
590
|
+
f"**Qualified Name**\n")
|
532
591
|
valid = False
|
533
592
|
elif len(term_details) == 1:
|
534
593
|
known_term_guid = term_details[0]['elementHeader'].get('guid', None)
|
@@ -537,7 +596,7 @@ def process_term_upsert_command(egeria_client: EgeriaTech, element_dictionary: d
|
|
537
596
|
msg += (f"* {ERROR}Term {term_name} qualifiedName mismatch between {q_name} and {known_q_name}\n")
|
538
597
|
valid = False
|
539
598
|
else:
|
540
|
-
msg += f"--> * Term {term_name} exists and can be updated\n"
|
599
|
+
msg += f"\n--> * Term {term_name} exists and can be updated\n"
|
541
600
|
msg += term_display
|
542
601
|
|
543
602
|
print(Markdown(msg))
|
@@ -554,15 +613,15 @@ def process_term_upsert_command(egeria_client: EgeriaTech, element_dictionary: d
|
|
554
613
|
print(Markdown(msg))
|
555
614
|
return valid, term_exists, known_term_guid, known_q_name
|
556
615
|
|
616
|
+
# Continue processing the upsert
|
557
617
|
if object_action == "Update":
|
558
618
|
term_guid = extract_attribute(txt, 'GUID')
|
559
|
-
term_guid = term_guid if term_guid else
|
560
|
-
|
561
|
-
q_name = q_name if q_name else " "
|
619
|
+
term_guid = term_guid if term_guid else None
|
620
|
+
|
562
621
|
|
563
622
|
update_description = extract_attribute(txt, 'Update Description')
|
564
623
|
update_description = update_description if update_description else " "
|
565
|
-
term_display = (f"\n* Command: {command}\n\t* Glossary: {
|
624
|
+
term_display = (f"\n* Command: {command}\n\t* Glossary: {glossary_qn}\n\t"
|
566
625
|
f"* Term Name: {term_name}\n\t* Categories: {categories}\n\t* Summary: {summary}"
|
567
626
|
f"\n\t* Description: {description}\n\t"
|
568
627
|
f"* Abbreviation: {abbreviation}\n\t* Examples: {examples}\n\t* Usage: {usage}\n\t"
|
@@ -570,7 +629,7 @@ def process_term_upsert_command(egeria_client: EgeriaTech, element_dictionary: d
|
|
570
629
|
f"{q_name}"
|
571
630
|
f"\n\t* Update Description: {update_description}\n")
|
572
631
|
else:
|
573
|
-
term_display = (f"\n* Command: {command}\n\t* Glossary: {
|
632
|
+
term_display = (f"\n* Command: {command}\n\t* Glossary: {glossary_qn}\n\t"
|
574
633
|
f"* Term Name: {term_name}\n\t* Categories: {categories}\n\t* Summary: {summary}\n\t"
|
575
634
|
f"* Description: {description}\n\t"
|
576
635
|
f"* Abbreviation: {abbreviation}\n\t* Examples: {examples}\n\t* Usage: {usage}\n\t"
|
@@ -594,11 +653,19 @@ def process_term_upsert_command(egeria_client: EgeriaTech, element_dictionary: d
|
|
594
653
|
print(f"\n-->Term {term_name} does not exist")
|
595
654
|
return None
|
596
655
|
body = {
|
597
|
-
"class": "ReferenceableRequestBody",
|
598
|
-
|
599
|
-
"
|
600
|
-
"
|
601
|
-
|
656
|
+
"class": "ReferenceableRequestBody",
|
657
|
+
"elementProperties": {
|
658
|
+
"class": "GlossaryTermProperties",
|
659
|
+
"qualifiedName": known_q_name,
|
660
|
+
"summary": summary,
|
661
|
+
"description": description,
|
662
|
+
"abbreviation": abbreviation,
|
663
|
+
"examples": examples,
|
664
|
+
"usage": usage,
|
665
|
+
"publishVersionIdentifier": version,
|
666
|
+
"status": status
|
667
|
+
},
|
668
|
+
"updateDescription": update_description
|
602
669
|
}
|
603
670
|
egeria_client.update_term(known_guid, body)
|
604
671
|
# if cats_exist is True and categories_list is not None:
|
@@ -618,23 +685,24 @@ def process_term_upsert_command(egeria_client: EgeriaTech, element_dictionary: d
|
|
618
685
|
|
619
686
|
elif object_action == "Create":
|
620
687
|
guid = None
|
621
|
-
|
688
|
+
|
689
|
+
q_name = egeria_client.__create_qualified_name__("Term",term_name, EGERIA_LOCAL_QUALIFIER)
|
622
690
|
if exists:
|
623
691
|
print(f"\n{WARNING}Term {term_name} exists and result document updated")
|
624
692
|
return update_a_command(txt, command, object_type, q_name, known_guid)
|
625
693
|
else:
|
626
694
|
## get the guid for the glossary from the name - first look locally
|
627
|
-
glossary = element_dictionary.get(
|
695
|
+
glossary = element_dictionary.get(glossary_qn, None)
|
628
696
|
|
629
697
|
if glossary is not None:
|
630
698
|
glossary_guid = glossary.get('guid', None)
|
631
699
|
if glossary_guid is None:
|
632
|
-
print(f"{ERROR}Glossary reference {
|
700
|
+
print(f"{ERROR}Glossary reference {glossary_qn} not found")
|
633
701
|
return None
|
634
702
|
else:
|
635
|
-
glossary_guid = egeria_client.__get_guid__(
|
703
|
+
glossary_guid = egeria_client.__get_guid__(qualified_name=glossary_qn)
|
636
704
|
if glossary_guid == NO_ELEMENTS_FOUND:
|
637
|
-
print(f"{ERROR}Glossary {
|
705
|
+
print(f"{ERROR}Glossary {glossary_qn} not found")
|
638
706
|
return None
|
639
707
|
term_body = {
|
640
708
|
"class": "ReferenceableRequestBody", "elementProperties": {
|
@@ -657,9 +725,8 @@ def process_term_upsert_command(egeria_client: EgeriaTech, element_dictionary: d
|
|
657
725
|
egeria_client, term_guid, cats_exist, categories_list,
|
658
726
|
element_dictionary)
|
659
727
|
print(f"\n-->Created Term {term_name} with GUID {term_guid}")
|
660
|
-
|
661
|
-
|
662
|
-
return egeria_client.get_terms_by_guid(term_guid, 'md')
|
728
|
+
element_dictionary[q_name] = {'guid': term_guid, 'display_name': term_name}
|
729
|
+
return egeria_client.get_terms_by_guid(term_guid, 'MD')
|
663
730
|
# return update_a_command(txt, command, object_type, q_name, term_guid)
|
664
731
|
except Exception as e:
|
665
732
|
print(f"{ERROR}Error creating term {term_name}: {e}")
|
@@ -682,14 +749,14 @@ def process_per_proj_upsert_command(egeria_client: EgeriaTech, element_dictionar
|
|
682
749
|
object_type = f"{object[1]} {object[2]}"
|
683
750
|
object_action = object[0]
|
684
751
|
|
685
|
-
project_name = extract_attribute(txt, 'Project Name')
|
686
|
-
description = extract_attribute(txt, 'Description')
|
687
|
-
project_identifier = extract_attribute(txt, 'Project Identifier')
|
688
|
-
project_status = extract_attribute(txt, 'Project Status')
|
689
|
-
project_phase = extract_attribute(txt, 'Project Phase')
|
690
|
-
project_health = extract_attribute(txt, 'Project Health')
|
691
|
-
start_date = extract_attribute(txt, 'Start Date')
|
692
|
-
planned_end_date = extract_attribute(txt, 'Planned End Date')
|
752
|
+
project_name = extract_attribute(txt, ['Project Name'])
|
753
|
+
description = extract_attribute(txt, ['Description'])
|
754
|
+
project_identifier = extract_attribute(txt, ['Project Identifier'])
|
755
|
+
project_status = extract_attribute(txt, ['Project Status'])
|
756
|
+
project_phase = extract_attribute(txt, ['Project Phase'])
|
757
|
+
project_health = extract_attribute(txt, ['Project Health'])
|
758
|
+
start_date = extract_attribute(txt, ['Start Date'])
|
759
|
+
planned_end_date = extract_attribute(txt, ['Planned End Date'])
|
693
760
|
print(Markdown(f"{pre_command} `\'{command}\'` for project: `{project_name}` with directive: `{directive}` "))
|
694
761
|
|
695
762
|
project_display = (f"\n* Command: {command}\n\t* Project: {project_name}\n\t"
|
@@ -812,5 +879,5 @@ def process_per_proj_upsert_command(egeria_client: EgeriaTech, element_dictionar
|
|
812
879
|
return None
|
813
880
|
|
814
881
|
q_name = project_g['projectProperties']["qualifiedName"]
|
815
|
-
element_dictionary[
|
882
|
+
element_dictionary[q_name] = {'guid': guid, 'display_name': project_name}
|
816
883
|
return update_a_command(txt, command, object_type, q_name, guid)
|