pyegeria 5.4.8.2__py3-none-any.whl → 5.4.8.4__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.
@@ -8,16 +8,13 @@ from datetime import datetime
8
8
  from loguru import logger
9
9
  from pydantic import ValidationError
10
10
 
11
- from .md_commands.project_commands import process_link_project_dependency_command
11
+ from md_processing.md_commands.project_commands import process_link_project_dependency_command
12
+
12
13
 
13
- log_format = "{time} | {level} | {function} | {line} | {message} | {extra}"
14
- logger.remove()
15
- logger.add(sys.stderr, level="ERROR", format=log_format, colorize=True)
16
- logger.add("debug_log.log", rotation="1 day", retention="1 week", compression="zip", level="INFO", format=log_format,
17
- colorize=True)
18
14
 
19
15
  from rich import print
20
16
  from rich.console import Console
17
+ from md_processing.md_commands.product_manager_commands import process_csv_element_upsert_command
21
18
 
22
19
  from md_processing import (extract_command, process_glossary_upsert_command, process_term_upsert_command,
23
20
  process_provenance_command, get_current_datetime_string,
@@ -69,6 +66,11 @@ EGERIA_ROOT_PATH = os.environ.get("EGERIA_ROOT_PATH", "../../")
69
66
  EGERIA_INBOX_PATH = os.environ.get("EGERIA_INBOX_PATH", "md_processing/dr_egeria_inbox")
70
67
  EGERIA_OUTBOX_PATH = os.environ.get("EGERIA_OUTBOX_PATH", "md_processing/dr_egeria_outbox")
71
68
 
69
+ log_format = "{time} | {level} | {function} | {line} | {message} | {extra}"
70
+ logger.remove()
71
+ logger.add(sys.stderr, level="ERROR", format=log_format, colorize=True)
72
+ logger.add("debug_log.log", rotation="1 day", retention="1 week", compression="zip", level="INFO", format=log_format,
73
+ colorize=True)
72
74
 
73
75
  @logger.catch
74
76
  def process_md_file(input_file: str, output_folder:str, directive: str, server: str, url: str, userid: str,
@@ -1,8 +1,10 @@
1
1
  """
2
2
  This file contains blueprint/solution-related object_action functions for processing Egeria Markdown
3
3
  """
4
+
4
5
  import json
5
6
  import sys
7
+ from datetime import datetime
6
8
  from typing import Optional
7
9
 
8
10
  from loguru import logger
@@ -13,7 +15,7 @@ from rich.markdown import Markdown
13
15
 
14
16
  from md_processing.md_processing_utils.common_md_proc_utils import (parse_upsert_command, parse_view_command)
15
17
  from md_processing.md_processing_utils.common_md_utils import update_element_dictionary, set_element_prop_body, \
16
- set_update_body, set_create_body
18
+ set_update_body, set_create_body, add_search_keywords, add_note_in_dr_e
17
19
  from md_processing.md_processing_utils.extraction_utils import (extract_command_plus, update_a_command)
18
20
  from md_processing.md_processing_utils.md_processing_constants import (load_commands)
19
21
  from pyegeria import body_slimmer, EgeriaTech, PyegeriaException, print_basic_exception
@@ -68,7 +70,7 @@ def sync_chain_related_elements(egeria_client: EgeriaTech, guid:str, in_supply_c
68
70
  @logger.catch
69
71
  def sync_component_related_elements(egeria_client: EgeriaTech, object_type: str,
70
72
  supply_chain_guids: list, parent_component_guids: list,
71
- actor_guids: list, in_blueprint_guids: list, guid: str, qualified_name: str,
73
+ actor_guids: list, in_blueprint_guids: list, keywords: list[str], guid: str, qualified_name: str,
72
74
  display_name: str, merge_update: bool = True) -> None:
73
75
  """Sync a components related elements.
74
76
 
@@ -81,12 +83,15 @@ def sync_component_related_elements(egeria_client: EgeriaTech, object_type: str,
81
83
  as_is_blueprints = set(rel_el_list.get("blueprint_guids", []))
82
84
  as_is_parent_components = set(rel_el_list.get("parent_component_guids", []))
83
85
  as_is_supply_chains = set(rel_el_list.get("supply_chain_guids", []))
86
+ as_is_keywords_list = set(rel_el_list.get("keywords_list", {}))
87
+ as_is_keywords = set(rel_el_list.get("keywords_list", {}).keys())
84
88
 
85
89
 
86
90
  to_be_actors = set(actor_guids) if actor_guids is not None else set()
87
91
  to_be_blueprints = set(in_blueprint_guids) if in_blueprint_guids is not None else set()
88
92
  to_be_parent_components = set(parent_component_guids) if parent_component_guids is not None else set()
89
93
  to_be_supply_chains = set(supply_chain_guids) if supply_chain_guids is not None else set()
94
+ to_be_keywords_list = set(keywords) if keywords is not None else set()
90
95
 
91
96
 
92
97
  logger.trace(
@@ -94,6 +99,22 @@ def sync_component_related_elements(egeria_client: EgeriaTech, object_type: str,
94
99
  logger.trace(f"as_is_actors: {list(as_is_actors)} to_be_actors: {list(to_be_actors)}")
95
100
  logger.trace(f"as_is_blueprints: {list(as_is_blueprints)} to_be_blueprints: {list(to_be_blueprints)}")
96
101
 
102
+ keywords_to_add = to_be_keywords_list - as_is_keywords
103
+ logger.trace(f"keywords_to_add: {list(keywords_to_add)}")
104
+ if len(keywords_to_add) > 0:
105
+ for ds in keywords_to_add:
106
+ egeria_client.add_search_keyword_to_element(guid, ds)
107
+ msg = f"Added `{ds}` to component `{guid}`"
108
+ logger.trace(msg)
109
+
110
+ keywords_to_remove = as_is_keywords_list - to_be_keywords_list
111
+ logger.trace(f"keyword_to_remove: {list(keywords_to_remove)}")
112
+ if len(keywords_to_remove) > 0:
113
+ for ds in keywords_to_remove: ## change structure of get related elements to return pairs of keywords and guids
114
+ egeria_client.remove_search_keyword(rel_el_list['keywords_list'][ds])
115
+ msg = f"Removed `{ds}` from component `{guid}`"
116
+ logger.trace(msg)
117
+
97
118
  parent_components_to_remove = as_is_parent_components - to_be_parent_components
98
119
  logger.trace(f"sub_components_to_remove: {list(parent_components_to_remove)}")
99
120
  if len(parent_components_to_remove) > 0:
@@ -102,6 +123,8 @@ def sync_component_related_elements(egeria_client: EgeriaTech, object_type: str,
102
123
  msg = f"Removed `{display_name}` from component `{ds}`"
103
124
  logger.trace(msg)
104
125
 
126
+
127
+
105
128
  parent_components_to_add = to_be_parent_components - as_is_parent_components
106
129
  logger.trace(f"parent_components_to_add: {list(parent_components_to_add)}")
107
130
  if len(parent_components_to_add) > 0:
@@ -186,6 +209,9 @@ def sync_component_related_elements(egeria_client: EgeriaTech, object_type: str,
186
209
  msg = f"Added `{in_blueprint_guids}` to `{display_name}`"
187
210
  logger.trace(msg)
188
211
 
212
+ if keywords:
213
+ add_search_keywords(egeria_client, guid, keywords)
214
+
189
215
  if supply_chain_guids:
190
216
  body = {
191
217
  "class": "NewRelationshipRequestBody",
@@ -268,7 +294,7 @@ def process_blueprint_upsert_command(egeria_client: EgeriaTech, txt: str, direct
268
294
 
269
295
  qualified_name = parsed_output.get('qualified_name', None)
270
296
  guid = parsed_output.get('guid', None)
271
-
297
+ journal_entry = parsed_output.get('Journey Entry', {}.get('value', None))
272
298
  print(Markdown(parsed_output['display']))
273
299
 
274
300
  logger.debug(json.dumps(parsed_output, indent=4))
@@ -276,7 +302,7 @@ def process_blueprint_upsert_command(egeria_client: EgeriaTech, txt: str, direct
276
302
  attributes = parsed_output['attributes']
277
303
  description = attributes.get('Description', {}).get('value', None)
278
304
  display_name = attributes['Display Name'].get('value', None)
279
-
305
+ search_keywords = attributes['Search Keywords'].get('value', None)
280
306
 
281
307
 
282
308
 
@@ -328,6 +354,8 @@ def process_blueprint_upsert_command(egeria_client: EgeriaTech, txt: str, direct
328
354
  logger.success(msg)
329
355
  sync_blueprint_related_elements(egeria_client, object_type, component_guids, guid, qualified_name,
330
356
  display_name, replace_all_props)
357
+
358
+ journal_entry_guid = add_note_in_dr_e(egeria_client, qualified_name, display_name, journal_entry)
331
359
  logger.success(f"===> Updated {object_type} `{display_name}` related elements\n\n")
332
360
  return egeria_client.get_solution_blueprints_by_name(qualified_name, output_format='MD', report_spec = "Solution-Blueprint-DrE")
333
361
 
@@ -360,7 +388,8 @@ def process_blueprint_upsert_command(egeria_client: EgeriaTech, txt: str, direct
360
388
  update_element_dictionary(qualified_name, {
361
389
  'guid': guid, 'display_name': display_name
362
390
  })
363
- msg = f"Created Element `{display_name}` with GUID {guid}\n\n___"
391
+ journal_entry_guid = add_note_in_dr_e(egeria_client, qualified_name, display_name, journal_entry)
392
+ msg = f"\n\nCreated Element `{display_name}` with GUID {guid}\n\n___"
364
393
  print(Markdown(msg))
365
394
  logger.success(msg)
366
395
  return egeria_client.get_solution_blueprint_by_guid(guid, output_format='MD', report_spec = "Solution-Blueprint-DrE")
@@ -413,6 +442,9 @@ def process_solution_component_upsert_command(egeria_client: EgeriaTech, txt: st
413
442
  solution_component_type = attributes.get('Solution Component Type', {}).get('value', None)
414
443
  planned_deployed_impl_type = attributes.get('Planned Deployed Implementation Type', {}).get('value', None)
415
444
  initial_status = attributes.get('Status', {}).get('value', None)
445
+ url = attributes.get('URL', {}).get('value', None)
446
+ search_keywords = attributes.get('Search Keywords', {}).get('value', None)
447
+ journal_entry = attributes.get('Journal Entry', {}).get('value', None)
416
448
  user_defined_status = attributes.get('User Defined Status', {}).get('value', None)
417
449
  if initial_status != "OTHER":
418
450
  user_defined_status = None
@@ -499,22 +531,27 @@ def process_solution_component_upsert_command(egeria_client: EgeriaTech, txt: st
499
531
  "additionalProperties": additional_properties,
500
532
  "extendedProperties": extended_properties,
501
533
  "effectiveFrom": effective_from,
502
- "effectiveTo": effective_to
534
+ "effectiveTo": effective_to,
535
+ "URL": url
503
536
  }
504
537
  })
505
538
 
506
539
  egeria_client.update_solution_component(guid, body)
507
- logger.success(f"==>Updated {object_type} `{display_name}` with GUID {guid}\n")
540
+ msg = f"\n==>Updated {object_type} `{display_name}` with GUID {guid}\n"
541
+ logger.success(msg)
542
+ print(Markdown(msg))
508
543
  update_element_dictionary(qualified_name, {
509
544
  'guid': guid, 'display_name': display_name
510
545
  })
511
546
  # Sync Parent Components and Blueprints
512
547
  sync_component_related_elements(egeria_client, object_type ,
513
548
  in_supply_chain_guids,parent_component_guids,actor_guids,
514
- in_blueprint_guids, guid, qualified_name,
549
+ in_blueprint_guids, search_keywords, guid, qualified_name,
515
550
  display_name,
516
551
  merge_update)
517
- logger.success(f"==>Updated {object_type} `{display_name}` with related elements")
552
+
553
+ if journal_entry:
554
+ journal_entry_guid = add_note_in_dr_e(egeria_client, qualified_name, display_name, journal_entry)
518
555
  return egeria_client.get_solution_component_by_guid(guid, output_format='MD', report_spec = "Solution-Component-DrE")
519
556
 
520
557
 
@@ -551,7 +588,8 @@ def process_solution_component_upsert_command(egeria_client: EgeriaTech, txt: st
551
588
  "additionalProperties": additional_properties,
552
589
  "extendedProperties": extended_properties,
553
590
  "effectiveFrom": effective_from,
554
- "effectiveTo": effective_to
591
+ "effectiveTo": effective_to,
592
+ "URL": url
555
593
  },
556
594
  "initialStatus": initial_status,
557
595
  "externalSourceGUID": external_source_guid,
@@ -566,8 +604,13 @@ def process_solution_component_upsert_command(egeria_client: EgeriaTech, txt: st
566
604
  update_element_dictionary(qualified_name, {
567
605
  'guid': guid, 'display_name': display_name
568
606
  })
569
- msg = f"Created Element `{display_name}` with GUID {guid}\n\n___"
607
+ msg = f"\n\n==> Created Element `{display_name}` with GUID {guid}\n\n___"
570
608
  logger.success(msg)
609
+ print(Markdown(msg))
610
+
611
+ if search_keywords:
612
+ add_search_keywords(egeria_client, guid, search_keywords)
613
+
571
614
  if in_component_guids:
572
615
  for comp in in_component_guids:
573
616
  egeria_client.link_subcomponent(comp, guid, None)
@@ -591,6 +634,8 @@ def process_solution_component_upsert_command(egeria_client: EgeriaTech, txt: st
591
634
  egeria_client.link_design_to_implementation(isc, guid, None)
592
635
  msg = f"Added `{display_name}`to supply chain `{in_supply_chain_names}`"
593
636
  logger.trace(msg)
637
+ journal_entry_guid = add_note_in_dr_e(egeria_client, qualified_name, display_name,
638
+ journal_entry)
594
639
 
595
640
  return egeria_client.get_solution_component_by_guid(guid, output_format='MD')
596
641
  else:
@@ -762,6 +807,7 @@ def process_information_supply_chain_upsert_command(egeria_client: EgeriaTech, t
762
807
  description = attributes.get('Description', {}).get('value', None)
763
808
  display_name = attributes['Display Name'].get('value', None)
764
809
  version_identifier = attributes.get('Version Identifier', {}).get('value', None)
810
+ journal_entry = attributes.get('Journal Entry', {}).get('Value', None)
765
811
  effective_time = attributes.get('Effective Time', {}).get('value', None)
766
812
  effective_from = attributes.get('Effective From', {}).get('value', None)
767
813
  effective_to = attributes.get('Effective To', {}).get('value', None)
@@ -836,8 +882,9 @@ def process_information_supply_chain_upsert_command(egeria_client: EgeriaTech, t
836
882
  update_element_dictionary(qualified_name, {
837
883
  'guid': guid, 'display_name': display_name
838
884
  })
885
+ journal_entry_guid = add_note_in_dr_e(egeria_client, qualified_name, display_name, journal_entry)
839
886
 
840
- # logger.success(f"===> Updated {object_type} `{display_name}` related elements\n\n")
887
+ logger.success(f"===> Updated {object_type} `{display_name}` related elements\n\n")
841
888
  return egeria_client.get_info_supply_chain_by_guid(guid, output_format='MD')
842
889
 
843
890
 
@@ -890,6 +937,8 @@ def process_information_supply_chain_upsert_command(egeria_client: EgeriaTech, t
890
937
  if len(in_supply_chain_guids) > 0:
891
938
  for nested_chain in in_supply_chain_guids:
892
939
  egeria_client.compose_info_supply_chains(guid, nested_chain)
940
+ journal_entry_guid = add_note_in_dr_e(egeria_client, qualified_name, display_name,
941
+ journal_entry)
893
942
 
894
943
  msg = f"==>Created Element `{display_name}` with GUID {guid}\n"
895
944
  logger.success(msg)
@@ -13,7 +13,7 @@ from rich import print
13
13
  from rich.markdown import Markdown
14
14
  from rich.console import Console
15
15
  from pyegeria.utils import parse_to_dict
16
-
16
+ from pyegeria.config import settings
17
17
  from md_processing.md_processing_utils.common_md_utils import (get_current_datetime_string, get_element_dictionary,
18
18
  update_element_dictionary,
19
19
  split_tb_string, str_to_bool, )
@@ -33,15 +33,19 @@ from pyegeria import EgeriaTech, select_report_spec, PyegeriaException, print_ba
33
33
 
34
34
  from pyegeria._globals import DEBUG_LEVEL
35
35
 
36
+ debug_level = DEBUG_LEVEL
37
+ global COMMAND_DEFINITIONS
38
+
39
+ user_config = settings.User_Profile
36
40
 
37
41
  # Constants
38
42
  EGERIA_WIDTH = int(os.environ.get("EGERIA_WIDTH", "200"))
39
- EGERIA_USAGE_LEVEL = os.environ.get("EGERIA_USAGE_LEVEL", "Advanced")
43
+ EGERIA_USAGE_LEVEL = os.environ.get("EGERIA_USAGE_LEVEL", user_config.egeria_usage_level)
40
44
  LOCAL_QUALIFIER = os.environ.get("EGERIA_LOCAL_QUALIFIER", None)
41
45
  console = Console(width=EGERIA_WIDTH)
42
46
 
43
- debug_level = DEBUG_LEVEL
44
- global COMMAND_DEFINITIONS
47
+
48
+
45
49
 
46
50
 
47
51
  @logger.catch
@@ -11,6 +11,8 @@ from loguru import logger
11
11
  from rich import print
12
12
  from rich.console import Console
13
13
  from rich.markdown import Markdown
14
+
15
+ from pyegeria import Client2, PyegeriaException, egeria_client
14
16
  from pyegeria.utils import (camel_to_title_case, body_slimmer)
15
17
  from pyegeria._globals import DEBUG_LEVEL
16
18
  from md_processing.md_processing_utils.message_constants import message_types
@@ -538,4 +540,41 @@ def set_object_classifications(object_type: str, attributes: dict, obj_types: li
538
540
  if classifications:
539
541
  for classification in classifications:
540
542
  body[classification] = {"class" : f"{classification}Properties"}
541
- return body
543
+ return body
544
+
545
+ def add_search_keywords(client: Client2, element_guid: str, keywords: list[str]):
546
+ """Add a search keyword to an element. Throw an exception if a problem is encountered.
547
+
548
+ Args:
549
+ client (Client2): The Egeria client instance.
550
+ element_guid (str): The GUID of the element to add the keyword to.
551
+ keyword (str): The search keyword to add.
552
+
553
+ Returns:
554
+ None
555
+ """
556
+ try:
557
+ for keyword in keywords:
558
+ client.add_search_keyword_to_element(element_guid, keyword)
559
+ print("Added keyword `{}` to element `{}`".format(keyword, element_guid))
560
+
561
+ except PyegeriaException as e:
562
+ context = {
563
+ "readon" : "Exception encountered executing add_search_keyword",
564
+ "element_guid": element_guid,
565
+ "keyword": keyword,
566
+ "exception": str(e)
567
+ }
568
+ raise PyegeriaException(context = context)
569
+
570
+ def add_note_in_dr_e(client: Client2, qualified_name: str, display_name: str, journal_entry: str)-> str:
571
+ if journal_entry:
572
+ note_log_qn = f"{qualified_name}-NoteLog"
573
+ note_log_display_name = f"{display_name}-NoteLog"
574
+ note_display_name = f"{qualified_name}-Journal-Entry-{datetime.now().strftime('%Y-%m-%d %H:%M')}"
575
+ journal_entry_guid = client.add_journal_entry(note_log_qn, qualified_name, note_log_display_name, note_display_name,
576
+ journal_entry)
577
+ logger.info(f"Added journal entry `{journal_entry_guid}` to `{qualified_name}`")
578
+ return journal_entry_guid
579
+ else:
580
+ return None