pyegeria 5.3.7.2__py3-none-any.whl → 5.3.7.8__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.
@@ -19,22 +19,30 @@ from rich.markdown import Markdown
19
19
 
20
20
  from pyegeria import body_slimmer
21
21
  from pyegeria._globals import NO_TERMS_FOUND, NO_GLOSSARIES_FOUND, NO_TERMS_FOUND, NO_ELEMENTS_FOUND, NO_PROJECTS_FOUND, NO_CATEGORIES_FOUND
22
-
22
+ from pyegeria.egeria_tech_client import EgeriaTech
23
+ # from pyegeria.md_processing_helpers import process_q_name_list
23
24
  from pyegeria.project_manager_omvs import ProjectManager
24
25
  from pyegeria.glossary_manager_omvs import GlossaryManager
26
+ from pyegeria.shared_state import get_element_dictionary, update_element_dictionary
25
27
 
26
28
  from datetime import datetime
27
- EGERIA_WIDTH = int(os.environ.get("EGERIA_WIDTH", "200"))
29
+ EGERIA_WIDTH = int(os.environ.get("EGERIA_WIDTH", "170"))
28
30
  console = Console(width=EGERIA_WIDTH)
29
31
 
30
- command_list = ["Provenance", "Create Glossary", "Update Glossary", "Create Term", "Update Term", "Create Personal Project",
31
- "Update Personal Project", "Create Category", "Update Category"]
32
+ command_list = ["Provenance",
33
+ "Create Glossary", "Update Glossary",
34
+ "Create Term", "Update Term",
35
+ "Create Personal Project", "Update Personal Project",
36
+ "Create Category", "Update Category",
37
+ "Create Solution Blueprint", "Update Solution Blueprint",
38
+ "Create Solution Component", "Update Solution Component",]
39
+
32
40
  ERROR = "ERROR-> "
33
41
  INFO = "INFO- "
34
42
  WARNING = "WARNING-> "
35
43
  pre_command = "\n---\n==> Processing command:"
36
44
 
37
- element_dictionary = {}
45
+
38
46
 
39
47
  def render_markdown(markdown_text: str) -> None:
40
48
  """Renders the given markdown text in the console."""
@@ -62,20 +70,31 @@ def add_term_to_categories(egeria_client: GlossaryManager, term_guid: str, categ
62
70
  for category in categories_list:
63
71
  cat_guid = None
64
72
  cat_el = category.strip()
65
- if cat_el in element_dictionary:
66
- cat= element_dictionary.get(cat_el, None)
73
+ element_dict = get_element_dictionary()
74
+ if cat_el in element_dict:
75
+ cat = element_dict.get(cat_el, None)
67
76
  cat_guid = cat.get('guid', None) if cat else None
68
77
  if cat_guid is None:
69
78
  cat_guid = egeria_client.__get_guid__(qualified_name=cat_el)
70
79
  egeria_client.add_term_to_category(term_guid, cat_guid)
71
80
 
72
81
 
73
- def extract_command(block: str) -> Optional[str]:
82
+ def extract_command_plus(block: str) -> tuple[str, str] | None:
74
83
  match = re.search(r"#(.*?)(?:##|\n|$)", block) # Using a non capturing group
75
84
  if match:
76
- return match.group(1).strip()
85
+ clean_match = match.group(1).strip()
86
+ parts = clean_match.split(' ')
87
+ object_action = parts[0].strip()
88
+ # Join the rest of the parts to allow object_type to be one or two words
89
+ object_type = ' '.join(parts[1:]).strip()
90
+ return object_type, object_action
77
91
  return None
78
92
 
93
+ def extract_command(block: str) -> str | None:
94
+ match = re.search(r"#(.*?)(?:##|\n|$)", block) # Using a non capturing group
95
+ if match:
96
+ return match.group(1).strip()
97
+ return None
79
98
 
80
99
  def extract_attribute(text: str, labels: List[str]) -> Optional[str]:
81
100
  """
@@ -145,6 +164,461 @@ def process_provenance_command(file_path: str, txt: [str]) -> str:
145
164
  existing_prov = existing_prov if existing_prov else " "
146
165
  return f"\n# Provenance:\n{existing_prov}\n{output}\n"
147
166
 
167
+ def process_element_identifiers(egeria_client: EgeriaTech, element_type:str, txt: str, action: str, version: str=None) \
168
+ -> tuple[str, str, str, bool, bool]:
169
+ """
170
+ Processes element identifiers by extracting display name and qualified name from the input text,
171
+ checking if the element exists in Egeria, and validating the information.
172
+
173
+ Parameters:
174
+ egeria_client: EgeriaTech
175
+ Client object for interacting with Egeria.
176
+ element_type: str
177
+ type of element to process (e.g., 'blueprint', 'category', 'term')
178
+ txt: str
179
+ A string representing the input text to be processed for extracting element identifiers.
180
+ action: str
181
+ The action command to be executed (e.g., 'Create', 'Update', 'Display', ...)
182
+ version: str, optional = None
183
+ An optional version identifier used if we need to construct the qualified name
184
+
185
+ Returns: tuple[str, str, str, bool, bool]
186
+ A tuple containing:
187
+ - qualified_name: Empty string or element identifier
188
+ - guid: Empty string or additional element information
189
+ - msg: Information or error messages about the processing
190
+ - Valid: Boolean indicating if the element information is valid
191
+ - Exists: Boolean indicating if the element exists in Egeria
192
+ """
193
+ msg = ""
194
+ guid = None
195
+ valid = True
196
+ exists = False
197
+ unique: bool | None = None
198
+ display_name = extract_attribute(txt, ["Display Name"])
199
+
200
+ qualified_name = extract_attribute(txt, ["Qualified Name"])
201
+ if qualified_name:
202
+ q_name, guid, msg, unique, exists = get_element_by_name(egeria_client,element_type,qualified_name)
203
+ # Qualified name could be different if it is being updated
204
+ else:
205
+ q_name, guid, msg, unique, exists = get_element_by_name(egeria_client,element_type,display_name)
206
+ if unique is False:
207
+ msg += f"{ERROR} Multiple elements named {display_name} found\n"
208
+ valid = False
209
+ if action == "Update" and not exists:
210
+ msg += f"* {ERROR}Element {display_name} does not exist\n"
211
+ valid = False
212
+ elif action == "Update" and exists:
213
+ msg += f"* {INFO}Element {display_name} exists\n"
214
+ elif action == "Create" and exists:
215
+ msg += f"* {ERROR}Element {display_name} already exists\n"
216
+ valid = False
217
+ elif action == "Create" and not exists:
218
+ msg += f"* {INFO}Element {display_name} does not exist and can be created\n"
219
+ if q_name is None:
220
+ q_name = egeria_client.__create_qualified_name__(element_type, display_name,
221
+ version_identifier=version)
222
+ update_element_dictionary(q_name, {'display_name': display_name})
223
+
224
+ return q_name, guid, msg, valid, exists
225
+
226
+
227
+ def get_element_by_name(egeria_client, element_type: str, element_name: str)\
228
+ ->tuple[str | None, str | None, str, bool | None, bool | None]:
229
+ """
230
+ Generalized function to retrieve an element by name based on its type.
231
+
232
+ Parameters:
233
+ egeria_client: Client
234
+ Client object for interacting with Egeria.
235
+ element_type: str
236
+ The type of element to retrieve (e.g., 'blueprint', 'category', 'term').
237
+ element_name: str
238
+ The name of the element to retrieve.
239
+
240
+ Returns:
241
+ tuple of qualified_name, guid, msg, uniqye, exists
242
+ """
243
+ unique = None
244
+ element_dict = get_element_dictionary()
245
+ if element_name in element_dict: # use information from element_dictionary
246
+ guid = element_dict[element_name].get('guid',None)
247
+ unique = True
248
+ exists = False
249
+ if guid is not None: # Found complete entry in element_dictionary
250
+ return element_name, guid, 'Found qualified name', unique, exists
251
+ else: # Missing guid from element_dictionary
252
+ guid = egeria_client.get_element_guid_by_unique_name(element_name)
253
+ if guid == NO_ELEMENTS_FOUND:
254
+ exists = False
255
+ msg = f"{INFO}No {element_type} guid found with name {element_name}\n"
256
+ return element_name, None, msg, unique, exists
257
+ else:
258
+ exists = True
259
+ update_element_dictionary(element_name, {'guid': guid})
260
+ return element_name, guid, 'Found qualified name', unique, exists
261
+
262
+ # Haven't seen this element before
263
+ property_names = ['qualifiedName', 'name', 'displayName']
264
+ open_metadata_type_name = None
265
+ details = egeria_client.get_elements_by_property_value(
266
+ element_name, property_names, open_metadata_type_name
267
+ )
268
+ if isinstance(details, str):
269
+ msg = f"{INFO}{element_type} `{element_name}` not found\n"
270
+ exists = False
271
+ return element_name, None, msg, unique, exists
272
+ if len(details) > 1:
273
+ msg = (f"{ERROR}More than one element with name {element_name} found, please specify a "
274
+ f"**Qualified Name**\n")
275
+ unique= False
276
+ exists = None
277
+ return element_name, None, msg, unique, exists
278
+
279
+ el_qname = details[0]["properties"].get('qualifiedName', None)
280
+ el_guid = details[0]['elementHeader']['guid']
281
+ el_display_name = details[0]["properties"].get('displayName', None)
282
+ update_element_dictionary(el_qname, {
283
+ 'guid': el_guid,
284
+ 'displayName': el_display_name
285
+ })
286
+ msg = f"{INFO}Found {element_type} `{element_name}`\n"
287
+ exists = True
288
+ unique = True
289
+ return el_qname, el_guid, msg, unique, exists
290
+
291
+ # Convert element_type to plural form for method name construction
292
+ # if element_type.endswith('y'):
293
+ # plural_type = f"{element_type[:-1]}ies"
294
+ # elif element_type.endswith('s'):
295
+ # plural_type = f"{element_type}es"
296
+ # else:
297
+ # plural_type = f"{element_type}s"
298
+ #
299
+ # # Construct method name
300
+ # method_name = f"get_{plural_type}_by_name"
301
+ #
302
+ # # Check if the method exists on the client
303
+ # if hasattr(egeria_client, method_name):
304
+ # # Call the method
305
+ # method = getattr(egeria_client, method_name)
306
+ # result = method(element_name)
307
+ # return result
308
+ # else:
309
+ # # Method doesn't exist
310
+ # return f"Method {method_name} not found on client"
311
+
312
+
313
+
314
+ def process_q_name_list(egeria_client: EgeriaTech, element_type: str, txt: str) -> tuple[
315
+ str | None, list | None, str | None, bool, bool]:
316
+ msg = ""
317
+ known_guid = None
318
+ valid = True
319
+ exists = False
320
+ elements = ""
321
+ new_element_list = []
322
+
323
+ elements_txt = extract_attribute(txt, [element_type])
324
+
325
+ if elements_txt is None:
326
+ msg += f"* {INFO}No {element_type}s found\n"
327
+
328
+ else:
329
+ element_list = re.split(r'[,\n]+', elements_txt)
330
+
331
+ for element in element_list:
332
+ element_el = element.strip()
333
+
334
+ # Get the element using the generalized function
335
+ known_q_name, known_guid, status_msg, el_valid, el_exists = get_element_by_name(
336
+ egeria_client, element_type, element_el)
337
+ msg += status_msg
338
+ if el_exists and el_valid:
339
+ elements = f"{element_el}, {elements}" # list of the input names
340
+ new_element_list.append(known_q_name) # list of qualified names
341
+ elif not el_exists:
342
+ msg += f"* {INFO}No {element_type} `{element_el}` found\n"
343
+ valid = False
344
+ valid = valid if el_valid is None else valid and el_valid
345
+ exists = exists and el_exists
346
+
347
+ if elements:
348
+ elements += "\n"
349
+ msg += f"* {INFO}Found {element_type}s: {elements}"
350
+ else:
351
+ msg += f"* {INFO}List contains one or more invalid elements.\n"
352
+ return elements, new_element_list, msg, valid, exists
353
+
354
+
355
+
356
+
357
+ def process_blueprint_upsert_command(egeria_client: EgeriaTech, element_dictionary: dict, txt: str,
358
+ directive: str = "display") -> Optional[str]:
359
+ """
360
+ Processes a blueprint create or update command by extracting key attributes such as
361
+ blueprint name, description, and version from the given cell.
362
+
363
+ Parameters:
364
+ egeria_client: SolutionArchitect
365
+ Client object for interacting with Egeria.
366
+ txt: str
367
+ A string representing the input cell to be processed for
368
+ extracting element attributes.
369
+ directive: str, optional, default "display"
370
+ An optional string indicating the directive to be used - display, validate or execute
371
+
372
+ Returns: str
373
+ A string summarizing the outcome of the processing.
374
+ """
375
+ object_type, object_action = extract_command_plus(txt)
376
+ element_display = ""
377
+ valid = True
378
+ msg =""
379
+
380
+ display_name = extract_attribute(txt, ['Display Name','Blueprint Name'])
381
+ description = extract_attribute(txt, ['Description'])
382
+ version = extract_attribute(txt, ['Version', "Version Identifier", "Published Version"])
383
+
384
+ print(Markdown(f"{pre_command} {object_action} `{object_type}` for Blueprint: `\'{display_name}\'` with directive: `{directive}`\n"))
385
+ if display_name is None:
386
+ msg += f"* {ERROR}Display name is missing\n"
387
+ valid = False
388
+ q_name, known_guid, exists = None
389
+ else:
390
+ q_name, known_guid, status_msg, valid, exists = process_element_identifiers(egeria_client, object_type,txt, object_action)
391
+ msg+= status_msg
392
+
393
+ if description is None:
394
+ msg += f"* {INFO}Description is missing\n"
395
+
396
+ if version is None:
397
+ msg += f"* {INFO}Term version is missing\n"
398
+
399
+ update_description = extract_attribute(txt, ['Update Description'])
400
+ if update_description is None:
401
+ msg += f"* {INFO}Update Description is missing\n"
402
+ update_description = "---"
403
+
404
+ element_display = (f"\n* Command: {object_action} {object_type}\n\t* Blueprint: {display_name}\n\t"
405
+ f"* Description: {description}\n\t"
406
+ f"* Version: {version}\n\t* Qualified Name:{q_name}\n\t* GUID: {known_guid} "
407
+ f"\n\t* Update Description: {update_description}\n")
408
+
409
+ # if object_action == "Update": # check to see if provided information exists and is consistent with existing info
410
+ # if not exists:
411
+ # msg += f"* {ERROR}Element {display_name} does not exist\n"
412
+ # valid = False
413
+
414
+ # elif object_action == 'Create': # if the command is create, check that it doesn't already exist
415
+ # if exists:
416
+ # msg += f"\n{WARNING}Element \'{display_name}\' already exists.\n"
417
+ # elif not valid:
418
+ # msg += f"\n-->Validation checks failed in creating element \'{display_name}\' with: {element_display}\n"
419
+ # else: # valid to create - update element_dictionary
420
+ # msg += f"\n-->It is valid to create element \'{display_name}\' with: {element_display}\n"
421
+ # if known_q_name is None:
422
+ # known_q_name = egeria_client.__create_qualified_name__(object_type, display_name)
423
+ # element_dictionary[known_q_name] = {'display_name': display_name}
424
+ if valid:
425
+ msg += f"\n-->It is valid to create element \'{display_name}\' with: {element_display}\n"
426
+
427
+ if directive == "display":
428
+ print(Markdown(element_display))
429
+ return None
430
+ elif directive == "validate":
431
+ print(Markdown(msg))
432
+ print(Markdown(element_display))
433
+ return valid
434
+
435
+ elif directive == "process":
436
+ print(Markdown(msg))
437
+ try:
438
+ if not valid: # First validate the term before we process it
439
+ return None
440
+
441
+ if object_action == "Update" and directive == "process":
442
+ if not exists:
443
+ print(f"\n-->Blueprint {display_name} does not exist")
444
+ return None
445
+
446
+ # call update blueprint here
447
+
448
+ print(f"\n-->Updated Blueprint {display_name} with GUID {known_guid}")
449
+ # update with get blueprint by guid
450
+ return 'Would return get blueprint by guid and return md' #egeria_client.get_terms_by_guid(known_guid, 'md')
451
+
452
+ elif object_action == "Update" and directive == "validate":
453
+ return 'Would call get_blueprint_by_guid and return md' #egeria_client.get_terms_by_guid(known_guid, 'md')
454
+
455
+ elif object_action == "Create":
456
+ if exists:
457
+ print(f"\n{WARNING}Blueprint {display_name} exists and result document updated")
458
+ return update_a_command(txt, f"{object_type}{object_action}",
459
+ object_type, q_name, known_guid)
460
+ else:
461
+ # create the blueprint
462
+ #term_guid = egeria_client.create_controlled_glossary_term(glossary_guid, term_body)
463
+ # if term_guid == NO_ELEMENTS_FOUND:
464
+ # print(f"{ERROR}Term {term_name} not created")
465
+ # return None
466
+ new_guid= f"guid:{get_current_datetime_string()}"
467
+ print(f"\n-->Created Blueprint {display_name} with GUID {new_guid}")
468
+ update_element_dictionary(q_name, {'guid': new_guid, 'display_name': display_name})
469
+ return 'Would return get blueprint by guid results as md' #egeria_client.get_terms_by_guid(term_guid, 'MD')
470
+
471
+ except Exception as e:
472
+ print(f"{ERROR}Error creating term {display_name}: {e}")
473
+ console.print_exception(show_locals=True)
474
+ return None
475
+
476
+
477
+
478
+ def process_solution_component_upsert_command(egeria_client: EgeriaTech, element_dictionary: dict, txt: str,
479
+ directive: str = "display") -> Optional[str]:
480
+ """
481
+ Processes a solution componentt create or update command by extracting key attributes such as
482
+ solution component name, description, version, solution component type etc from the given cell.
483
+
484
+ Parameters:
485
+ egeria_client: SolutionArchitect
486
+ Client object for interacting with Egeria.
487
+ txt: str
488
+ A string representing the input cell to be processed for
489
+ extracting element attributes.
490
+ directive: str, optional, default "display"
491
+ An optional string indicating the directive to be used - display, validate or execute
492
+
493
+ Returns: str
494
+ A string summarizing the outcome of the processing.
495
+ """
496
+ object_type, object_action = extract_command_plus(txt)
497
+ element_display = ""
498
+ bp_exist = True
499
+ bp_qname_list = []
500
+ parent_qname_list = []
501
+
502
+ display_name = extract_attribute(txt, ['Display Name', 'Solution Component Name'])
503
+ description = extract_attribute(txt, ['Description'])
504
+ version = extract_attribute(txt, ['Version', "Version Identifier", "Published Version"])
505
+ solution_component_type = extract_attribute(txt, ['Solution Component Type'])
506
+ planned_deployed_implementation_type = extract_attribute(txt, ['Planned Deployment Implementation Type'])
507
+ solution_blueprints = extract_attribute(txt, ['Solution Blueprints'])
508
+ parent_components = extract_attribute(txt, ['Parent Components'])
509
+
510
+ print(Markdown(
511
+ f"{pre_command} {object_action} `{object_type}` for Solution Component: `\'{display_name}\'` with directive: `{directive}`\n"))
512
+
513
+ known_q_name, known_guid, msg, valid, exists = process_element_identifiers(egeria_client, object_type,txt, object_action)
514
+
515
+ if description is None:
516
+ msg += f"* {INFO}Description is missing\n"
517
+
518
+ if version is None:
519
+ msg += f"* {INFO}Term version is missing\n"
520
+
521
+ update_description = extract_attribute(txt, ['Update Description'])
522
+ if update_description is None:
523
+ msg += f"* {INFO}Update Description is missing\n"
524
+ update_description = "---"
525
+
526
+ if solution_component_type is None:
527
+ msg += f"* {INFO}Solution Component Type is missing\n"
528
+
529
+ if planned_deployed_implementation_type is None:
530
+ msg += f"* {INFO}Planned Deployed Implementation Type is missing\n"
531
+
532
+ if solution_blueprints is None:
533
+ msg += f"* {INFO}No Solution Blueprints found\n"
534
+
535
+ else: # Find information about blueprints that include this component
536
+ solution_blueprints, bp_qname_list, msg, valid, exists = process_q_name_list(egeria_client,
537
+ 'Solution Blueprints', txt)
538
+
539
+ if parent_components is None:
540
+ msg += f"* {INFO}Parent Components are missing\n"
541
+ else:
542
+ parent_components, parent_qname_list, msg, valid, exists = process_q_name_list(egeria_client,
543
+ 'Solution Component', parent_components)
544
+
545
+ element_display = (f"\n* Command: {object_action} {object_type}\n\t* Display Name: {display_name}\n\t"
546
+ f"* Description: {description}\n\t"
547
+ f"* Version Identifier: {version}\n\t"
548
+ f"* Solution Component Type {solution_component_type}\n\t"
549
+ f"* Planned Deployment Implementation Type {planned_deployed_implementation_type}\n\t"
550
+ f"* Solution_Blueprints: {solution_blueprints}\n\t"
551
+ f"* Parent Components: {parent_components}\n\t"
552
+ f"* Qualified Name:{known_q_name}\n\t* GUID: {known_guid} "
553
+ f"\n\t* Update Description: {update_description}\n")
554
+
555
+ if object_action == "Update": # check to see if provided information exists and is consistent with existing info
556
+ if not exists:
557
+ msg += f"* {ERROR}Element {display_name} does not exist\n"
558
+ valid = False
559
+ # element_dictionary[known_q_name] = {'display_name': display_name, 'guid': known_guid}
560
+
561
+ elif object_action == 'Create': # if the command is create, check that it doesn't already exist
562
+ if exists:
563
+ msg += f"\n{WARNING}Element \'{display_name}\' already exists.\n"
564
+ elif not valid:
565
+ msg += f"\n-->Validation checks failed in creating element \'{display_name}\' with: {element_display}\n"
566
+ else: # valid to create - update element_dictionary
567
+ msg += f"\n-->It is valid to create element \'{display_name}\' with: {element_display}\n"
568
+ if known_q_name is None:
569
+ known_q_name = egeria_client.__create_qualified_name__(object_type, display_name,
570
+ version_identifier=version)
571
+ update_element_dictionary(known_q_name, {'display_name': display_name})
572
+
573
+ if directive == "display":
574
+ print(Markdown(element_display))
575
+ return None
576
+ elif directive == "validate":
577
+ print(Markdown(msg))
578
+ print(Markdown(element_display))
579
+ return valid
580
+
581
+ elif directive == "process":
582
+ print(Markdown(msg))
583
+ try:
584
+ if not valid: # First validate the term before we process it
585
+ return None
586
+
587
+ if object_action == "Update" and directive == "process":
588
+ if not exists:
589
+ print(f"\n-->Solution Component {display_name} does not exist")
590
+ return None
591
+
592
+ # call update solution component here
593
+
594
+ print(f"\n-->Updated Solution Component {display_name} with GUID {known_guid}")
595
+ # update with get solution component by guid
596
+ return 'Would return get Solution Component by guid and return md' # egeria_client.get_terms_by_guid(known_guid, 'md')
597
+
598
+ elif object_action == "Update" and directive == "validate":
599
+ return 'Would call get_blueprint_by_guid and return md' # egeria_client.get_terms_by_guid(known_guid, 'md')
600
+
601
+ elif object_action == "Create":
602
+ if exists:
603
+ print(f"\n{WARNING}Blueprint {display_name} exists and result document updated")
604
+ return update_a_command(txt, f"{object_type}{object_action}",
605
+ object_type, known_q_name, known_guid)
606
+ else:
607
+ # create the blueprint
608
+ # term_guid = egeria_client.create_controlled_glossary_term(glossary_guid, term_body)
609
+ # if term_guid == NO_ELEMENTS_FOUND:
610
+ # print(f"{ERROR}Term {term_name} not created")
611
+ # return None
612
+
613
+ print(f"\n-->Created Solution Component {display_name} with GUID {known_guid}")
614
+ update_element_dictionary(known_q_name, {'guid': known_guid, 'display_name': display_name})
615
+ return 'Would return get solution component by guid results as md' # egeria_client.get_terms_by_guid(term_guid, 'MD')
616
+
617
+ except Exception as e:
618
+ print(f"{ERROR}Error creating term {display_name}: {e}")
619
+ console.print_exception(show_locals=True)
620
+ return None
621
+
148
622
 
149
623
  def process_glossary_upsert_command(egeria_client: GlossaryManager, element_dictionary: dict, txt: str,
150
624
  directive: str = "display") -> Optional[str]:
@@ -161,7 +635,7 @@ def process_glossary_upsert_command(egeria_client: GlossaryManager, element_dict
161
635
  object_type = command.split(' ')[1].strip()
162
636
  object_action = command.split(' ')[0].strip()
163
637
 
164
- glossary_name = extract_attribute(txt, ['Glossary Name'])
638
+ glossary_name = extract_attribute(txt, ['Glossary Name','Display Name'])
165
639
  print(Markdown(f"{pre_command} `{command}` for glossary: `\'{glossary_name}\'` with directive: `{directive}` "))
166
640
  language = extract_attribute(txt, ['Language'])
167
641
  description = extract_attribute(txt, ['Description'])
@@ -177,16 +651,11 @@ def process_glossary_upsert_command(egeria_client: GlossaryManager, element_dict
177
651
  glossary_display += f"* Qualified Name: {q_name}\n\t* GUID: {guid}\n\n"
178
652
 
179
653
  def validate_glossary(obj_action: str) -> tuple[bool, bool, Optional[str], Optional[str]]:
654
+
180
655
  valid = True
181
656
  msg = ""
182
- known_glossary_guid = None
183
- known_q_name = None
184
657
 
185
- glossary_details = egeria_client.get_glossaries_by_name(glossary_name)
186
- if glossary_details == NO_GLOSSARIES_FOUND:
187
- glossary_exists = False
188
- else:
189
- glossary_exists = True
658
+ known_q_name, known_guid, msg, valid, glossary_exists = process_element_identifiers(egeria_client, object_type,txt, object_action)
190
659
 
191
660
  if glossary_name is None:
192
661
  msg = f"* {ERROR}Glossary name is missing\n"
@@ -197,13 +666,6 @@ def process_glossary_upsert_command(egeria_client: GlossaryManager, element_dict
197
666
  if description is None:
198
667
  msg += f"* {INFO}Description is missing\n"
199
668
 
200
- if len(glossary_details) > 1 and glossary_exists:
201
- msg += f"* {ERROR}More than one glossary with name {glossary_name} found\n"
202
- valid = False
203
- if len(glossary_details) == 1:
204
- known_glossary_guid = glossary_details[0]['elementHeader'].get('guid', None)
205
- known_q_name = glossary_details[0]['glossaryProperties'].get('qualifiedName', None).strip()
206
-
207
669
  if obj_action == "Update":
208
670
 
209
671
  if not glossary_exists:
@@ -220,12 +682,12 @@ def process_glossary_upsert_command(egeria_client: GlossaryManager, element_dict
220
682
  if valid:
221
683
  msg += glossary_display
222
684
  msg += f"* -->Glossary `{glossary_name}` exists and can be updated\n"
223
- element_dictionary[known_q_name] = {'display_name': glossary_name, 'guid': known_glossary_guid}
685
+ update_element_dictionary(known_q_name, {'display_name': glossary_name, 'guid': known_guid})
224
686
  else:
225
687
  msg += f"* --> validation failed\n"
226
688
 
227
689
  print(Markdown(msg))
228
- return valid, glossary_exists, known_glossary_guid, known_q_name
690
+ return valid, glossary_exists, known_guid, known_q_name
229
691
 
230
692
  elif obj_action == "Create":
231
693
  if glossary_exists:
@@ -235,10 +697,10 @@ def process_glossary_upsert_command(egeria_client: GlossaryManager, element_dict
235
697
  msg += f"-->It is valid to create Glossary \'{glossary_name}\' with:\n"
236
698
  msg += glossary_display
237
699
  expected_q_name = egeria_client.__create_qualified_name__('Glossary', glossary_name)
238
- element_dictionary[expected_q_name] = {'display_name': glossary_name}
700
+ update_element_dictionary(expected_q_name, {'display_name': glossary_name})
239
701
 
240
702
  print(Markdown(msg))
241
- return valid, glossary_exists, known_glossary_guid, known_q_name
703
+ return valid, glossary_exists, known_guid, known_q_name
242
704
 
243
705
  if directive == "display":
244
706
  print(Markdown(glossary_display))
@@ -267,9 +729,9 @@ def process_glossary_upsert_command(egeria_client: GlossaryManager, element_dict
267
729
  }
268
730
  egeria_client.update_glossary(known_guid, body)
269
731
  print(f"\n-->Updated Glossary {glossary_name} with GUID {known_guid}")
270
- element_dictionary[known_q_name] = {
732
+ update_element_dictionary(known_q_name, {
271
733
  'guid': known_guid, 'display_name': glossary_name
272
- }
734
+ })
273
735
  # return update_a_command(txt, command, object_type, known_q_name, known_guid)
274
736
  return egeria_client.get_glossary_by_guid(known_guid, output_format='MD')
275
737
  elif object_action == "Create":
@@ -285,9 +747,9 @@ def process_glossary_upsert_command(egeria_client: GlossaryManager, element_dict
285
747
  print(f"{ERROR}Just created with GUID {glossary_guid} but Glossary not found\n")
286
748
  return None
287
749
  qualified_name = glossary['glossaryProperties']["qualifiedName"]
288
- element_dictionary[qualified_name] = {
750
+ update_element_dictionary(qualified_name, {
289
751
  'guid': glossary_guid, 'display_name': glossary_name
290
- }
752
+ })
291
753
  # return update_a_command(txt, command, object_type, qualified_name, glossary_guid)
292
754
  return egeria_client.get_glossary_by_guid(glossary_guid, output_format = 'MD')
293
755
 
@@ -340,9 +802,10 @@ def process_categories_upsert_command(egeria_client: GlossaryManager, element_di
340
802
  msg += f"* {ERROR}Owning Glossary Qualified Name is missing\n"
341
803
  valid = False
342
804
 
343
- elif owning_glossary_qn in element_dictionary: # Check to see if we already know about this glossary
344
- glossary_name = element_dictionary[owning_glossary_qn].get('display_name', None)
345
- glossary_guid = element_dictionary[owning_glossary_qn].get('guid', None)
805
+ elif owning_glossary_qn in get_element_dictionary(): # Check to see if we already know about this glossary
806
+ element_dict = get_element_dictionary()
807
+ glossary_name = element_dict[owning_glossary_qn].get('display_name', None)
808
+ glossary_guid = element_dict[owning_glossary_qn].get('guid', None)
346
809
 
347
810
  else:
348
811
  # need to ask Egeria if it knows the Glossary Name
@@ -359,9 +822,9 @@ def process_categories_upsert_command(egeria_client: GlossaryManager, element_di
359
822
  msg += f"* {ERROR}Glossary `{owning_glossary_qn}` is known by qualifiedName `{glossary_qn}`\n\n"
360
823
  valid = False
361
824
  else:
362
- element_dictionary[owning_glossary_qn] = {
825
+ update_element_dictionary(owning_glossary_qn, {
363
826
  'guid': glossary_guid, 'display_name': glossary_name
364
- }
827
+ })
365
828
 
366
829
  if category_name is None:
367
830
  msg = f"* {ERROR}Category name is missing\n"
@@ -391,7 +854,7 @@ def process_categories_upsert_command(egeria_client: GlossaryManager, element_di
391
854
  if valid:
392
855
  msg += category_display
393
856
  msg += f"* -->category `{category_name}` exists and can be updated\n"
394
- element_dictionary[known_q_name] = {'display_name': glossary_name, 'guid': known_category_guid}
857
+ update_element_dictionary(known_q_name, {'display_name': glossary_name, 'guid': known_category_guid})
395
858
  else:
396
859
  msg += f"* --> validation failed\n"
397
860
 
@@ -406,7 +869,7 @@ def process_categories_upsert_command(egeria_client: GlossaryManager, element_di
406
869
  msg += f"-->It is valid to create category `{category_name}` with:\n"
407
870
  msg += category_display
408
871
  expected_q_name = egeria_client.__create_qualified_name__('Category', category_name)
409
- element_dictionary[expected_q_name] = {'display_name': category_name}
872
+ update_element_dictionary(expected_q_name, {'display_name': category_name})
410
873
 
411
874
  print(Markdown(msg))
412
875
  return valid, category_exists, known_category_guid, known_q_name, glossary_guid
@@ -436,9 +899,9 @@ def process_categories_upsert_command(egeria_client: GlossaryManager, element_di
436
899
  egeria_client.update_category(glossary_guid, category_name, description, known_q_name, None,
437
900
  update_description)
438
901
  print(f"\n-->Updated category `{category_name}`with GUID {known_guid}")
439
- element_dictionary[known_q_name] = {
902
+ update_element_dictionary(known_q_name, {
440
903
  'guid': known_guid, 'display_name': category_name
441
- }
904
+ })
442
905
  # return update_a_command(txt, command, object_type, known_q_name, known_guid)
443
906
  return egeria_client.get_categories_by_guid(known_guid, output_format='FORM')
444
907
 
@@ -456,9 +919,9 @@ def process_categories_upsert_command(egeria_client: GlossaryManager, element_di
456
919
  print(f"{ERROR}Just created with GUID {category_guid} but category not found\n")
457
920
  return None
458
921
  qualified_name = category['glossaryCategoryProperties']["qualifiedName"]
459
- element_dictionary[qualified_name] = {
922
+ update_element_dictionary(qualified_name, {
460
923
  'guid': category_guid, 'display_name': category_name
461
- }
924
+ })
462
925
  # return update_a_command(txt, command, object_type, qualified_name, category_guid)
463
926
  return egeria_client.get_categories_by_guid(category_guid, output_format='MD')
464
927
 
@@ -479,7 +942,7 @@ def process_term_upsert_command(egeria_client: GlossaryManager, element_dictiona
479
942
  object_type = command.split(' ')[1].strip()
480
943
  object_action = command.split(' ')[0].strip()
481
944
 
482
- term_name = extract_attribute(txt, ['Term Name'])
945
+ term_name = extract_attribute(txt, ['Term Name','Display Name'])
483
946
  summary = extract_attribute(txt, ['Summary'])
484
947
  description = extract_attribute(txt, ['Description'])
485
948
  abbreviation = extract_attribute(txt, ['Abbreviation'])
@@ -530,7 +993,8 @@ def process_term_upsert_command(egeria_client: GlossaryManager, element_dictiona
530
993
  valid = False
531
994
  else:
532
995
  print(f"* {INFO}Glossary qualified name is `{glossary_qn}`")
533
- if glossary_qn not in element_dictionary:
996
+ element_dict = get_element_dictionary()
997
+ if glossary_qn not in element_dict:
534
998
  glossary = egeria_client.get_glossaries_by_name(glossary_qn) #assuming q_name?
535
999
  if isinstance(glossary,str):
536
1000
  msg += f"* {ERROR}Glossary `{glossary_qn}` is unknown\n "
@@ -544,10 +1008,10 @@ def process_term_upsert_command(egeria_client: GlossaryManager, element_dictiona
544
1008
  msg += f"* {ERROR}Glossary `{glossary_qn}` has no qualifiedName\n "
545
1009
  valid = False
546
1010
  else:
547
- element_dictionary[glossary_qn] = {
1011
+ update_element_dictionary(glossary_qn, {
548
1012
  'guid': glossary[0]['elementHeader'].get('guid', None),
549
1013
  'display_name': glossary[0]['glossaryProperties'].get('displayName', None)
550
- }
1014
+ })
551
1015
 
552
1016
 
553
1017
  if categories is None:
@@ -558,7 +1022,8 @@ def process_term_upsert_command(egeria_client: GlossaryManager, element_dictiona
558
1022
  new_cat_list = []
559
1023
  for category in categories_list:
560
1024
  category_el = category.strip()
561
- if category_el not in element_dictionary:
1025
+ element_dict = get_element_dictionary()
1026
+ if category_el not in element_dict:
562
1027
  cat = egeria_client.get_categories_by_name(category_el) # assuming qualified name?
563
1028
  if isinstance(cat,str):
564
1029
  msg += (f"* {WARNING}Category `{category_el}` not found -> "
@@ -567,13 +1032,13 @@ def process_term_upsert_command(egeria_client: GlossaryManager, element_dictiona
567
1032
  break
568
1033
  cat_qname = cat[0]['glossaryCategoryProperties'].get('qualifiedName', None)
569
1034
  category = cat_qname # use the qualified name if found
570
- if cat_qname not in element_dictionary:
1035
+ if cat_qname not in element_dict:
571
1036
  cat_guid = cat[0]['elementHeader']['guid']
572
1037
  cat_display_name = cat[0]['glossaryCategoryProperties'].get('displayName', None)
573
- element_dictionary[cat_qname] = {
1038
+ update_element_dictionary(cat_qname, {
574
1039
  'guid' : cat_guid,
575
1040
  'displayName': cat_display_name
576
- }
1041
+ })
577
1042
  categories = f"{category}, {categories}"
578
1043
  new_cat_list.append(category)
579
1044
  if cats_exist:
@@ -618,7 +1083,7 @@ def process_term_upsert_command(egeria_client: GlossaryManager, element_dictiona
618
1083
  else:
619
1084
  msg += f"\n--> * Term {term_name} exists and can be updated\n"
620
1085
  msg += term_display
621
- element_dictionary[known_q_name] = {'display_name': term_name, 'guid': known_term_guid}
1086
+ update_element_dictionary(known_q_name, {'display_name': term_name, 'guid': known_term_guid})
622
1087
 
623
1088
  print(Markdown(msg))
624
1089
  return valid, term_exists, known_term_guid, known_q_name
@@ -630,9 +1095,12 @@ def process_term_upsert_command(egeria_client: GlossaryManager, element_dictiona
630
1095
  msg += f"\n-->Validation checks failed in creating Term \'{term_name}\' with: {term_display}\n"
631
1096
  else:
632
1097
  msg += f"\n-->It is valid to create Term \'{term_name}\' with: {term_display}\n"
633
- expected_q_name = egeria_client.__create_qualified_name__('Term', term_name)
634
- element_dictionary[expected_q_name] = {'display_name': term_name}
635
-
1098
+ if q_name is None:
1099
+ expected_q_name = egeria_client.__create_qualified_name__('Term',
1100
+ term_name, version_identifier=version)
1101
+ update_element_dictionary(expected_q_name, {'display_name': term_name})
1102
+ else:
1103
+ update_element_dictionary(q_name, {'display_name': term_name})
636
1104
  print(Markdown(msg))
637
1105
  return valid, term_exists, known_term_guid, known_q_name
638
1106
 
@@ -645,8 +1113,8 @@ def process_term_upsert_command(egeria_client: GlossaryManager, element_dictiona
645
1113
  update_description = extract_attribute(txt, 'Update Description')
646
1114
  update_description = update_description if update_description else " "
647
1115
  term_display = (f"\n* Command: {command}\n\t* Glossary: {glossary_qn}\n\t"
648
- f"* Term Name: {term_name}\n\t* Categories: {categories}\n\t* Summary: {summary}"
649
- f"\n\t* Description: {description}\n\t"
1116
+ f"* Term Name: {term_name}\n\t* Qualified Name: {q_name}\n\t* Categories: {categories}\n\t"
1117
+ f"* Summary: {summary}\n\t* Description: {description}\n\t"
650
1118
  f"* Abbreviation: {abbreviation}\n\t* Examples: {examples}\n\t* Usage: {usage}\n\t"
651
1119
  f"* Version: {version}\n\t* Status: {status}\n\t* GUID: {term_guid}\n\t* Qualified Name: "
652
1120
  f"{q_name}"
@@ -654,7 +1122,7 @@ def process_term_upsert_command(egeria_client: GlossaryManager, element_dictiona
654
1122
  else:
655
1123
  term_display = (f"\n* Command: {command}\n\t* Glossary: {glossary_qn}\n\t"
656
1124
  f"* Term Name: {term_name}\n\t* Categories: {categories}\n\t* Summary: {summary}\n\t"
657
- f"* Description: {description}\n\t"
1125
+ f"* Qualified Name: {q_name}\n\t* Description: {description}\n\t"
658
1126
  f"* Abbreviation: {abbreviation}\n\t* Examples: {examples}\n\t* Usage: {usage}\n\t"
659
1127
  f"* Version: {version}\n\t* Status: {status}\n")
660
1128
 
@@ -708,14 +1176,15 @@ def process_term_upsert_command(egeria_client: GlossaryManager, element_dictiona
708
1176
 
709
1177
  elif object_action == "Create":
710
1178
  guid = None
711
-
712
- q_name = egeria_client.__create_qualified_name__("Term",term_name)
1179
+ if q_name is None:
1180
+ q_name = egeria_client.__create_qualified_name__("Term",term_name,
1181
+ version_identifier=version)
713
1182
  if exists:
714
1183
  print(f"\n{WARNING}Term {term_name} exists and result document updated")
715
1184
  return update_a_command(txt, command, object_type, q_name, known_guid)
716
1185
  else:
717
1186
  ## get the guid for the glossary from the name - first look locally
718
- glossary = element_dictionary.get(glossary_qn, None)
1187
+ glossary = get_element_dictionary().get(glossary_qn, None)
719
1188
 
720
1189
  if glossary is not None:
721
1190
  glossary_guid = glossary.get('guid', None)
@@ -754,7 +1223,7 @@ def process_term_upsert_command(egeria_client: GlossaryManager, element_dictiona
754
1223
  egeria_client, term_guid, cats_exist, categories_list,
755
1224
  element_dictionary)
756
1225
  print(f"\n-->Created Term {term_name} with GUID {term_guid}")
757
- element_dictionary[q_name] = {'guid': term_guid, 'display_name': term_name}
1226
+ update_element_dictionary(q_name, {'guid': term_guid, 'display_name': term_name})
758
1227
  return egeria_client.get_terms_by_guid(term_guid, 'MD')
759
1228
  # return update_a_command(txt, command, object_type, q_name, term_guid)
760
1229
  except Exception as e:
@@ -902,11 +1371,11 @@ def process_per_proj_upsert_command(egeria_client: ProjectManager, element_dicti
902
1371
  guid = egeria_client.create_project(None, None, None, False, project_name, description,
903
1372
  "PersonalProject", project_identifier, True, project_status,
904
1373
  project_phase, project_health, start_date, planned_end_date)
905
- project_g = egeria_client.get_project(guid)
1374
+ project_g = egeria_client.get_project_by_guid(guid)
906
1375
  if project_g == NO_GLOSSARIES_FOUND:
907
1376
  print(f"Just created with GUID {guid} but Project not found")
908
1377
  return None
909
1378
 
910
1379
  q_name = project_g['projectProperties']["qualifiedName"]
911
- element_dictionary[q_name] = {'guid': guid, 'display_name': project_name}
1380
+ update_element_dictionary(q_name, {'guid': guid, 'display_name': project_name})
912
1381
  return update_a_command(txt, command, object_type, q_name, guid)