pyegeria 5.3.9.9.3__py3-none-any.whl → 5.3.9.9.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.
Files changed (58) hide show
  1. md_processing/__init__.py +49 -0
  2. md_processing/dr_egeria_inbox/archive/dr_egeria_intro.md +254 -0
  3. md_processing/dr_egeria_inbox/archive/dr_egeria_intro_more_terms.md +696 -0
  4. md_processing/dr_egeria_inbox/archive/dr_egeria_intro_part1.md +254 -0
  5. md_processing/dr_egeria_inbox/archive/dr_egeria_intro_part2.md +298 -0
  6. md_processing/dr_egeria_inbox/archive/dr_egeria_intro_part3.md +608 -0
  7. md_processing/dr_egeria_inbox/archive/dr_egeria_intro_part4.md +94 -0
  8. md_processing/dr_egeria_inbox/archive/freddie_intro.md +284 -0
  9. md_processing/dr_egeria_inbox/archive/freddie_intro_orig.md +275 -0
  10. md_processing/dr_egeria_inbox/archive/test-term.md +110 -0
  11. md_processing/dr_egeria_inbox/cat_test.md +100 -0
  12. md_processing/dr_egeria_inbox/commands.json +3252 -0
  13. md_processing/dr_egeria_inbox/data_field.md +54 -0
  14. md_processing/dr_egeria_inbox/data_spec.md +77 -0
  15. md_processing/dr_egeria_inbox/data_spec_test.md +2406 -0
  16. md_processing/dr_egeria_inbox/data_test.md +86 -0
  17. md_processing/dr_egeria_inbox/dr_egeria_intro_categories.md +168 -0
  18. md_processing/dr_egeria_inbox/dr_egeria_intro_part1.md +280 -0
  19. md_processing/dr_egeria_inbox/dr_egeria_intro_part2.md +313 -0
  20. md_processing/dr_egeria_inbox/dr_egeria_intro_part3.md +1073 -0
  21. md_processing/dr_egeria_inbox/dr_egeria_isc1.md +44 -0
  22. md_processing/dr_egeria_inbox/glossary_creation_experiment.ipynb +341 -0
  23. md_processing/dr_egeria_inbox/glossary_test1.md +324 -0
  24. md_processing/dr_egeria_inbox/rel.md +8 -0
  25. md_processing/dr_egeria_inbox/sb.md +119 -0
  26. md_processing/dr_egeria_inbox/search_test.md +39 -0
  27. md_processing/dr_egeria_inbox/solution-components.md +154 -0
  28. md_processing/dr_egeria_inbox/solution_blueprints.md +118 -0
  29. md_processing/dr_egeria_inbox/synonym_test.md +42 -0
  30. md_processing/dr_egeria_inbox/t1.md +0 -0
  31. md_processing/dr_egeria_inbox/t2.md +268 -0
  32. md_processing/dr_egeria_outbox/processed-2025-05-15 19:52-data_test.md +94 -0
  33. md_processing/dr_egeria_outbox/processed-2025-05-16 07:39-data_test.md +88 -0
  34. md_processing/dr_egeria_outbox/processed-2025-05-17 16:01-data_field.md +56 -0
  35. md_processing/dr_egeria_outbox/processed-2025-05-18 15:51-data_test.md +103 -0
  36. md_processing/dr_egeria_outbox/processed-2025-05-18 16:47-data_test.md +94 -0
  37. md_processing/dr_egeria_outbox/processed-2025-05-19 07:14-data_test.md +96 -0
  38. md_processing/dr_egeria_outbox/processed-2025-05-19 07:20-data_test.md +100 -0
  39. md_processing/dr_egeria_outbox/processed-2025-05-19 07:22-data_test.md +88 -0
  40. md_processing/dr_egeria_outbox/processed-2025-05-19 09:26-data_test.md +91 -0
  41. md_processing/dr_egeria_outbox/processed-2025-05-19 10:27-data_test.md +91 -0
  42. md_processing/md_commands/__init__.py +3 -0
  43. md_processing/md_commands/blueprint_commands.py +303 -0
  44. md_processing/md_commands/data_designer_commands.py +1183 -0
  45. md_processing/md_commands/glossary_commands.py +1144 -0
  46. md_processing/md_commands/project_commands.py +163 -0
  47. md_processing/md_processing_utils/__init__.py +4 -0
  48. md_processing/md_processing_utils/common_md_proc_utils.py +724 -0
  49. md_processing/md_processing_utils/common_md_utils.py +172 -0
  50. md_processing/md_processing_utils/extraction_utils.py +486 -0
  51. md_processing/md_processing_utils/md_processing_constants.py +122 -0
  52. md_processing/md_processing_utils/message_constants.py +19 -0
  53. pyegeria/data_designer_omvs.py +4 -3
  54. {pyegeria-5.3.9.9.3.dist-info → pyegeria-5.3.9.9.5.dist-info}/METADATA +1 -2
  55. {pyegeria-5.3.9.9.3.dist-info → pyegeria-5.3.9.9.5.dist-info}/RECORD +58 -6
  56. {pyegeria-5.3.9.9.3.dist-info → pyegeria-5.3.9.9.5.dist-info}/LICENSE +0 -0
  57. {pyegeria-5.3.9.9.3.dist-info → pyegeria-5.3.9.9.5.dist-info}/WHEEL +0 -0
  58. {pyegeria-5.3.9.9.3.dist-info → pyegeria-5.3.9.9.5.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,1183 @@
1
+ """
2
+ This file contains term-related object_action functions for processing Egeria Markdown
3
+ """
4
+ import json
5
+ import os
6
+ from typing import Optional
7
+
8
+ from rich import print
9
+ from rich.console import Console
10
+ from rich.markdown import Markdown
11
+
12
+ from md_processing.md_processing_utils.common_md_proc_utils import (parse_user_command, sync_data_dict_membership,
13
+ sync_data_spec_membership, sync_data_structure_membership, sync_term_links, sync_parent_data_field)
14
+
15
+ from md_processing.md_processing_utils.common_md_utils import print_msg, update_element_dictionary
16
+ from md_processing.md_processing_utils.extraction_utils import (extract_command, extract_command_plus, update_a_command)
17
+ from md_processing.md_processing_utils.md_processing_constants import (load_commands, ERROR)
18
+ from pyegeria import DEBUG_LEVEL, body_slimmer
19
+ from pyegeria.egeria_tech_client import EgeriaTech
20
+ from pyegeria.md_processing_utils import ALWAYS, INFO
21
+
22
+ command_definitions = os.environ.get("COMMAND_DEFINITIONS")
23
+ print("Current working directory: ", os.getcwd())
24
+ load_commands('commands.json')
25
+ debug_level = DEBUG_LEVEL
26
+
27
+ console = Console(width=int(200))
28
+
29
+ def add_member_to_data_collections(egeria_client: EgeriaTech, in_data_collection:dict, display_name: str, guid:str )-> bool:
30
+ """
31
+ Add member to data dictionaries and data specifications.
32
+ """
33
+ try:
34
+ for collection in in_data_collection.keys():
35
+ collection_name = collection
36
+ collection_valid = in_data_collection[collection].get('el_valid', False)
37
+ collection_guid = in_data_collection[collection].get('guid', None)
38
+ if collection_guid and collection_valid:
39
+ egeria_client.add_to_collection(collection_guid, guid)
40
+ msg = f"Added `{display_name}` member to `{collection_name}`"
41
+ print_msg(INFO, msg, debug_level)
42
+ return True
43
+
44
+ except Exception as e:
45
+ console.print_exception()
46
+
47
+
48
+ def find_memberships_in_collection_type(egeria_client: EgeriaTech, collection_type: str, guid: str) -> list:
49
+ """ Find the collections of a particular type that the element is a member of"""
50
+ collection_guid_list = []
51
+ collections = egeria_client.get_related_elements(guid, "CollectionMembership", "Collection")
52
+ for collection in collections:
53
+ print(collection["relationshipHeader"]['guid'])
54
+ related_el_guid = collection["relatedElement"]['elementHeader']["guid"]
55
+ coll_type = collection["relatedElement"]['properties'].get('collectionType', None)
56
+ print(coll_type)
57
+ if coll_type:
58
+ if coll_type == collection_type:
59
+ collection_guid_list.append(related_el_guid)
60
+ print(collection_guid_list)
61
+ return collection_guid_list
62
+
63
+
64
+
65
+
66
+ def update_data_collection_memberships(egeria_client: EgeriaTech, in_data_collection:dict, guid: str, replace_all_props:bool = False) -> bool:
67
+ """ update the collection membership of the element """
68
+ pass
69
+
70
+
71
+ # def update_term_categories(egeria_client: EgeriaTech, term_guid: str, current_categories: List[str],
72
+ # new_categories: List[str]) -> None:
73
+ # """
74
+ # Updates the categories of a term.
75
+ #
76
+ # Args:
77
+ # egeria_client: The Egeria client to use for the update.
78
+ # term_guid: The GUID of the term to update.
79
+ # current_categories: The current categories of the term.
80
+ # new_categories: The new categories of the term.
81
+ # """
82
+ # if new_categories: # If categories are specified, add them
83
+ # for cat in new_categories:
84
+ # if cat not in current_categories:
85
+ # egeria_client.add_term_to_category(term_guid, cat)
86
+ # msg = f"Added term {term_guid} to category {cat}"
87
+ # print_msg("DEBUG-INFO", msg, debug_level)
88
+ # # Remove any categories that are not in the new list
89
+ # for cat in current_categories:
90
+ # if cat not in new_categories:
91
+ # egeria_client.remove_term_from_category(term_guid, cat)
92
+ # msg = f"Removed term {term_guid} from category {cat}"
93
+ # print_msg("DEBUG-INFO", msg, debug_level)
94
+ # else: # No categories specified - so remove any categories a term is in
95
+ # for cat in current_categories:
96
+ # egeria_client.remove_term_from_category(term_guid, cat)
97
+ # msg = f"Removed term {term_guid} from category {cat}"
98
+ # print_msg("DEBUG-INFO", msg, debug_level)
99
+
100
+
101
+ def process_data_spec_upsert_command(egeria_client: EgeriaTech, txt: str, directive: str = "display") -> Optional[str]:
102
+ """
103
+ Processes a data specification create or update object_action by extracting key attributes such as
104
+ spec name, parent_guid, parent_relationship_type, parent_at_end_1, collection_type
105
+
106
+ :param txt: A string representing the input cell to be processed for
107
+ extracting glossary-related attributes.
108
+ :param directive: an optional string indicating the directive to be used - display, validate or execute
109
+ :return: A string summarizing the outcome of the processing.
110
+ """
111
+ from md_processing.md_processing_utils.common_md_utils import set_debug_level
112
+
113
+ set_debug_level(directive)
114
+
115
+ command, object_type, object_action = extract_command_plus(txt)
116
+
117
+ parsed_output = parse_user_command(egeria_client, object_type, object_action, txt, directive)
118
+
119
+ valid = parsed_output['valid']
120
+ exists = parsed_output['exists']
121
+
122
+ qualified_name = parsed_output.get('qualified_name', None)
123
+ guid = parsed_output.get('guid', None)
124
+
125
+ print(Markdown(parsed_output['display']))
126
+
127
+ print(json.dumps(parsed_output, indent=4))
128
+
129
+ attributes = parsed_output['attributes']
130
+ description = attributes['Description'].get('value', None)
131
+ display_name = attributes['Display Name'].get('value', None)
132
+ anchor_guid = attributes.get('Anchor ID', {}).get('guid', None)
133
+ parent_guid = attributes.get('Parent ID', {}).get('guid', None)
134
+ parent_relationship_type_name = attributes.get('Parent Relationship Type Name', {}).get('value', "CollectionMembership")
135
+ parent_at_end1 = attributes.get('Parent at End1', {}).get('value', True)
136
+
137
+ anchor_scope_guid = attributes.get('Anchor Scope GUID', {}).get('value', None)
138
+ is_own_anchor = attributes.get('Is Own Anchor', {}).get('value', True)
139
+ collection_ordering = "NAME"
140
+ order_property_name = "Something"
141
+ collection_type = object_type
142
+ replace_all_props = not attributes.get('Merge Update', {}).get('value', True)
143
+ in_data_spec_list = attributes.get('In Data Specification', {}).get('value', None)
144
+ in_data_spec_valid = attributes.get('In Data Specification', {}).get('valid', None)
145
+ in_data_spec_exists = attributes.get('In Data Specification', {}).get('exists', None)
146
+
147
+ if directive == "display":
148
+
149
+ return None
150
+ elif directive == "validate":
151
+ if valid:
152
+ print(Markdown(f"==> Validation of {command} completed successfully!\n"))
153
+ else:
154
+ msg = f"Validation failed for object_action `{command}`\n"
155
+ return valid
156
+
157
+ elif directive == "process":
158
+
159
+
160
+
161
+
162
+ try:
163
+ if object_action == "Update":
164
+ if not exists:
165
+ msg = (f" Element `{display_name}` does not exist! Updating result document with Create "
166
+ f"object_action\n")
167
+ print_msg(ERROR, msg, debug_level)
168
+ return update_a_command(txt, object_action, object_type, qualified_name, guid)
169
+ elif not valid:
170
+ return None
171
+ else:
172
+ print(Markdown(
173
+ f"==> Validation of {command} completed successfully! Proceeding to apply the changes.\n"))
174
+
175
+ egeria_client.update_collection(guid, qualified_name, display_name, description, collection_type,
176
+ collection_ordering, order_property_name, replace_all_props)
177
+ print_msg(ALWAYS, f"Updated {object_type} `{display_name}` with GUID {guid}", debug_level)
178
+ update_element_dictionary(qualified_name, {
179
+ 'guid': guid, 'display_name': display_name
180
+ })
181
+ return egeria_client.get_collection_by_guid(guid, output_format='FORM')
182
+
183
+
184
+ elif object_action == "Create":
185
+ if valid is False and exists:
186
+ msg = (f" Data Specification `{display_name}` already exists and result document updated changing "
187
+ f"`Create` to `Update` in processed output\n")
188
+ print_msg(ERROR, msg, debug_level)
189
+ return update_a_command(txt, object_action, object_type, qualified_name, guid)
190
+ elif valid is False and in_data_spec_valid is False:
191
+ msg = (f" Invalid data specification(s) `{in_data_spec_list}` "
192
+ f" perhaps they don't yet exist? - Correct and try again")
193
+ print_msg(ERROR, msg, debug_level)
194
+ else:
195
+ guid = egeria_client.create_data_spec_collection(anchor_guid, parent_guid,
196
+ parent_relationship_type_name, parent_at_end1,
197
+ display_name, description, collection_type,
198
+ anchor_scope_guid, is_own_anchor,
199
+ collection_ordering, order_property_name,
200
+ qualified_name)
201
+ if guid:
202
+
203
+ print_msg(ALWAYS, f"Created Element `{display_name}` with GUID {guid}", debug_level)
204
+
205
+ return egeria_client.get_collection_by_guid(guid, output_format='FORM')
206
+ else:
207
+ print_msg(ERROR, f"Failed to create Term `{display_name}`", debug_level)
208
+ return None
209
+
210
+ except Exception as e:
211
+ print(f"{ERROR}Error performing {command}: {e}")
212
+ Console().print_exception(show_locals=True)
213
+ return None
214
+ else:
215
+ return None
216
+
217
+
218
+ def process_data_dict_upsert_command(egeria_client: EgeriaTech, txt: str, directive: str = "display") -> Optional[str]:
219
+ """
220
+ Processes a data dictionary create or update object_action by extracting key attributes such as
221
+ spec name, parent_guid, parent_relationship_type, parent_at_end_1, collection_type
222
+
223
+ :param txt: A string representing the input cell to be processed for
224
+ extracting glossary-related attributes.
225
+ :param directive: an optional string indicating the directive to be used - display, validate or execute
226
+ :return: A string summarizing the outcome of the processing.
227
+ """
228
+ from md_processing.md_processing_utils.common_md_utils import set_debug_level
229
+
230
+ set_debug_level(directive)
231
+
232
+ command, object_type, object_action = extract_command_plus(txt)
233
+
234
+ parsed_output = parse_user_command(egeria_client, object_type, object_action, txt, directive)
235
+
236
+ valid = parsed_output['valid']
237
+ exists = parsed_output['exists']
238
+
239
+ qualified_name = parsed_output.get('qualified_name', None)
240
+ guid = parsed_output.get('guid', None)
241
+
242
+ print(Markdown(parsed_output['display']))
243
+
244
+ if directive == "display":
245
+
246
+ return None
247
+ elif directive == "validate":
248
+ if valid:
249
+ print(Markdown(f"==> Validation of {command} completed successfully!\n"))
250
+ else:
251
+ msg = f"Validation failed for object_action `{command}`\n"
252
+ return valid
253
+
254
+ elif directive == "process":
255
+ print(json.dumps(parsed_output, indent=4))
256
+
257
+ attributes = parsed_output['attributes']
258
+ description = attributes['Description'].get('value', None)
259
+ display_name = attributes['Display Name'].get('value', None)
260
+ anchor_guid = attributes.get('Anchor ID', {}).get('guid', None)
261
+ parent_guid = attributes.get('Parent ID', {}).get('guid', None)
262
+ parent_relationship_type_name = attributes.get('Parent Relationship Type Name', {}).get('value',
263
+ "CollectionMembership")
264
+ parent_at_end1 = attributes.get('Parent at End1', {}).get('value', True)
265
+
266
+ anchor_scope_guid = attributes.get('Anchor Scope GUID', {}).get('value', None)
267
+ is_own_anchor = attributes.get('Is Own Anchor', {}).get('value', True)
268
+ if parent_guid is None:
269
+ is_own_anchor = True
270
+ collection_ordering = "NAME"
271
+ order_property_name = "Something"
272
+ collection_type = object_type
273
+ replace_all_props = not attributes.get('Merge Update', {}).get('value', True)
274
+
275
+
276
+ try:
277
+ if object_action == "Update":
278
+
279
+ if not exists:
280
+ print(f"\n{ERROR}Element `{display_name}` does not exist! Updating result document with Create "
281
+ f"object_action\n")
282
+ return update_a_command(txt, object_action, object_type, qualified_name, guid)
283
+ elif not valid:
284
+ return None
285
+ else:
286
+ print(Markdown(
287
+ f"==> Validation of {command} completed successfully! Proceeding to apply the changes.\n"))
288
+
289
+ egeria_client.update_collection(guid, qualified_name, display_name, description, collection_type,
290
+ collection_ordering, order_property_name, replace_all_props)
291
+ print_msg(ALWAYS, f"Updated {object_type} `{display_name}` with GUID {guid}", debug_level)
292
+ update_element_dictionary(qualified_name, {
293
+ 'guid': guid, 'display_name': display_name
294
+ })
295
+ return egeria_client.get_collection_by_guid(guid, output_format='FORM')
296
+
297
+ elif object_action == "Create":
298
+ if valid is False and exists:
299
+ print(f"\nElement `{display_name}` already exists and result document updated changing "
300
+ f"`Create` to `Update` in processed output\n")
301
+ return update_a_command(txt, object_action, object_type, qualified_name, guid)
302
+ else:
303
+ guid = egeria_client.create_data_dictionary_collection(anchor_guid, parent_guid,
304
+ parent_relationship_type_name,
305
+ parent_at_end1, display_name, description,
306
+ collection_type, anchor_scope_guid,
307
+ is_own_anchor, collection_ordering,
308
+ order_property_name, qualified_name)
309
+ if guid:
310
+ print_msg(ALWAYS, f"Created Element `{display_name}` with GUID {guid}", debug_level)
311
+
312
+ return egeria_client.get_collection_by_guid(guid, output_format='FORM')
313
+ else:
314
+ print_msg(ERROR, f"Failed to create Term `{display_name}`", debug_level)
315
+ return None
316
+
317
+ except Exception as e:
318
+ print(f"{ERROR}Error performing {command}: {e}")
319
+ Console().print_exception(show_locals=True)
320
+ return None
321
+ else:
322
+ return None
323
+
324
+
325
+ def process_data_field_upsert_command(egeria_client: EgeriaTech, txt: str, directive: str = "display") -> Optional[str]:
326
+ """
327
+ Processes a data dictionary create or update object_action by extracting key attributes such as
328
+ spec name, parent_guid, parent_relationship_type, parent_at_end_1, collection_type
329
+
330
+ :param txt: A string representing the input cell to be processed for
331
+ extracting glossary-related attributes.
332
+ :param directive: an optional string indicating the directive to be used - display, validate or execute
333
+ :return: A string summarizing the outcome of the processing.
334
+ """
335
+ from md_processing.md_processing_utils.common_md_utils import set_debug_level
336
+
337
+ set_debug_level(directive)
338
+
339
+ command, object_type, object_action = extract_command_plus(txt)
340
+
341
+ parsed_output = parse_user_command(egeria_client, object_type, object_action, txt, directive)
342
+
343
+ valid = parsed_output['valid']
344
+ exists = parsed_output['exists']
345
+
346
+ qualified_name = parsed_output.get('qualified_name', None)
347
+ guid = parsed_output.get('guid', None)
348
+
349
+ print(Markdown(parsed_output['display']))
350
+
351
+ if directive == "display":
352
+
353
+ return None
354
+ elif directive == "validate":
355
+ if valid:
356
+ print(Markdown(f"==> Validation of {command} completed successfully!\n"))
357
+ else:
358
+ msg = f"Validation failed for object_action `{command}`\n"
359
+ return valid
360
+
361
+ elif directive == "process":
362
+ print(json.dumps(parsed_output, indent=4))
363
+ attributes = parsed_output['attributes']
364
+
365
+ external_source_guid = attributes.get('External Source Name', {}).get('guid', None)
366
+ external_source_name = attributes.get('External Source Name', {}).get('value', None)
367
+ effective_time = attributes.get('Effective Time', {}).get('value', None)
368
+ for_lineage = attributes.get('For Lineage', {}).get('value', None)
369
+ for_duplicate_processing = attributes.get('For Duplicate Processing', {}).get('value', None)
370
+ anchor_guid = attributes.get('Anchor ID', {}).get('guid', None)
371
+ is_own_anchor = attributes.get('Is Own Anchor', {}).get('value', None)
372
+ # parent_id = attributes.get('Parent ID', {}).get('value', None)
373
+ # parent_guid = attributes['Parent ID'].get('guid', None)
374
+ # parent_relationship_type_name = attributes.get('Parent Relationship Type Name', {}).get('value', None)
375
+ # parent_relationship_properties = attributes.get('Parent Relationship Properties',{}).get('value', None)
376
+ # parent_at_end1 = attributes.get('Parent at End1', {}).get('value', None)
377
+
378
+ display_name = attributes['Display Name'].get('value', None)
379
+
380
+ namespace = attributes.get('Namespace',{}).get('value', None)
381
+ description = attributes.get('Description',{}).get('value', None)
382
+ version_id = attributes.get('Version Identifier', {}).get('value', None)
383
+ aliases = attributes.get('Aliases', {}).get('value', None)
384
+ name_patterns = attributes.get('Name Patterns', {}).get('value', None)
385
+ is_nullable = attributes.get('Is Nullable', {}).get('value', None)
386
+ default_value = attributes.get('Default Value', {}).get('value', None)
387
+ data_type = attributes.get('Data Type', {}).get('value', None)
388
+ min_length = attributes.get('Minimum Length', {}).get('value', None)
389
+ length = attributes.get('Length', {}).get('value', None)
390
+ precision = attributes.get('Precision', {}).get('value', None)
391
+ ordered_values = attributes.get('Ordered Values', {}).get('value', None)
392
+ sort_order = attributes.get('Sort Order', {}).get('value', None)
393
+ additional_properties = attributes.get('Additional Properties', {}).get('value', None)
394
+ effective_from = attributes.get('Effective From', {}).get('value', None)
395
+ effective_to = attributes.get('Effective To', {}).get('value', None)
396
+
397
+ position = attributes.get('Position', {}).get('value', None)
398
+ min_cardinality = attributes.get('Minimum Cardinality', {}).get('value', None)
399
+ max_cardinality = attributes.get('Maximum Cardinality', {}).get('value', None)
400
+
401
+ in_data_structure = attributes.get('In Data Structure', {}).get('value', None)
402
+ in_data_structure_names = attributes.get('In Data Structure Names', {}).get('name_list', None)
403
+
404
+ data_class = attributes['Data Class'].get('value', None)
405
+
406
+ glossary_term = attributes['Glossary Term'].get('value', None)
407
+ glossary_term_guid = attributes['Glossary Term'].get('guid', None)
408
+
409
+ in_data_dictionary = attributes.get('In Data Dictionary', {}).get('value', None)
410
+ in_data_dictionary_names = attributes.get('In Data Dictionary Names', {}).get('name_list', None)
411
+
412
+ parent_data_field = attributes.get('Parent Data Field', {}).get('value', None)
413
+ parent_data_field_guid = attributes.get('Parent Data Field', {}).get('guid', None)
414
+
415
+ anchor_scope_guid = attributes.get('Anchor Scope GUID', {}).get('value', None)
416
+
417
+ merge_update = attributes.get('Merge Update', {}).get('value', None)
418
+
419
+
420
+ collection_ordering = "NAME"
421
+ order_property_name = "Something"
422
+ collection_type = object_type
423
+ replace_all_props = True
424
+
425
+ if not valid:
426
+ if exists and object_action == "Create":
427
+ msg = (f"Create failed because Element `{display_name}` exists - changing `Create` to `Update` in "
428
+ f"processed output \n")
429
+ print_msg(ERROR, msg, debug_level)
430
+ return update_a_command(txt, object_action, object_type, qualified_name, guid)
431
+ else:
432
+ return None
433
+ else:
434
+ print(Markdown(f"==> Validation of {command} completed successfully! Proceeding to apply the changes.\n"))
435
+
436
+ try:
437
+ if object_action == "Update":
438
+ if not exists:
439
+ print(f"\n{ERROR}Element `{display_name}` does not exist! Updating result document with Create "
440
+ f"object_action\n")
441
+ return update_a_command(txt, object_action, object_type, qualified_name, guid)
442
+
443
+ body = {
444
+ "class": "UpdateDataFieldRequestBody",
445
+ "externalSourceGUID": external_source_guid,
446
+ "externalSourceName": external_source_name,
447
+ "effectiveTime": None,
448
+ "forLineage": False,
449
+ "forDuplicateProcessing": False,
450
+ "properties": {
451
+ "class": "DataFieldProperties",
452
+ "qualifiedName": qualified_name,
453
+ "displayName": display_name,
454
+ "namespace": namespace,
455
+ "description": description,
456
+ "versionIdentifier": version_id,
457
+ "aliases": aliases,
458
+ "namePatterns": name_patterns,
459
+ "isDeprecated": False,
460
+ "isNullable": is_nullable,
461
+ "defaultValue": default_value,
462
+ "dataType": data_type,
463
+ "minimumLength": min_length,
464
+ "length": length,
465
+ "precision": precision,
466
+ "orderedValues": ordered_values,
467
+ "sortOrder": sort_order,
468
+ "additionalProperties": additional_properties,
469
+ "effectiveFrom": effective_from,
470
+ "effectiveTo": effective_to
471
+ }
472
+ }
473
+
474
+ egeria_client.update_data_field(guid, body, not merge_update)
475
+ print_msg(ALWAYS, f"Updated {object_type} `{display_name}` with GUID {guid}", debug_level)
476
+ # Update data dictionary membership
477
+ update_element_dictionary(qualified_name, {
478
+ 'guid': guid, 'display_name': display_name
479
+ })
480
+ core_props = egeria_client.get_data_field_by_guid(guid, output_format='MD')
481
+
482
+ existing_data_field = egeria_client.get_data_field_by_guid(guid, output_format='JSON')
483
+ existing_data_field_dicts = 3
484
+
485
+ # Sync membership in data dictionaries
486
+ result = sync_data_dict_membership(egeria_client, in_data_dictionary_names, in_data_dictionary, guid, object_type)
487
+ print_msg(ALWAYS, f"Will update data dictionary `{in_data_dictionary}`", debug_level)
488
+ core_props += f"\n\n## In Data Dictionary\n\n{in_data_dictionary}\n\n"
489
+
490
+ # Update data spec membership
491
+ result = sync_data_spec_membership(egeria_client, in_data_dictionary_names, in_data_dictionary, guid,
492
+ object_type)
493
+ print_msg(ALWAYS, f"Will update data dictionary `{in_data_dictionary}`", debug_level)
494
+ core_props += f"\n\n## In Data Dictionary\n\n{in_data_dictionary}\n\n"
495
+
496
+ # Sync membership in data structuress
497
+ result = sync_data_structure_membership(egeria_client, in_data_dictionary_names, in_data_dictionary, guid,
498
+ object_type)
499
+ core_props += f"\n\n## In Data Structure {in_data_structure}\n\n"
500
+
501
+ # Update glossary links
502
+ result = sync_term_links(egeria_client, glossary_term, glossary_term_guid, guid, object_type)
503
+ print_msg(ALWAYS, f"Updating glossary term to `{glossary_term}`", debug_level)
504
+
505
+ core_props += f"\n\n## Glossary Term \n\n{glossary_term}\n\n"
506
+ # Update parent field
507
+ result = sync_parent_data_field(egeria_client, parent_data_field, parent_data_field_guid, guid, object_type)
508
+
509
+ core_props += f"\n\n## Parent Data Field\n\n{parent_data_field}\n\n"
510
+
511
+ # Update data classes
512
+ print_msg(ALWAYS, f"Created Element `{display_name}` ", debug_level)
513
+
514
+
515
+ return core_props
516
+
517
+
518
+ elif object_action == "Create":
519
+ if valid is False and exists:
520
+ print(f"\nData Field `{display_name}` already exists and result document updated changing `Create` "
521
+ f"to `Update` in processed output\n")
522
+ return update_a_command(txt, object_action, object_type, qualified_name, guid)
523
+ else:
524
+ # First lets create the data field
525
+ body = {
526
+ "properties": {
527
+ "class": "DataFieldProperties", "qualifiedName": qualified_name,
528
+ "displayName": display_name, "namespace": namespace, "description": description,
529
+ "versionIdentifier": version_id, "aliases": aliases, "namePatterns": name_patterns,
530
+ "isDeprecated": False, "isNullable": is_nullable, "defaultValue": default_value,
531
+ "dataType": data_type, "minimumLength": min_length, "length": length,
532
+ "precision": precision, "orderedValues": ordered_values, "sortOrder": sort_order,
533
+ "additionalProperties": additional_properties
534
+ }
535
+ }
536
+ guid = egeria_client.create_data_field(body)
537
+ if guid:
538
+ # Now update our element dictionary with the new information
539
+ update_element_dictionary(qualified_name, {
540
+ 'guid': guid, 'display_name': display_name
541
+ })
542
+ # Start assembling the information we will present back out
543
+ core_props = egeria_client.get_data_field_by_guid(guid, output_format='MD')
544
+
545
+ # Add the field to any data dictionaries
546
+ if in_data_dictionary:
547
+ print_msg(ALWAYS, f"Will add to data dictionary `{in_data_dictionary}`", debug_level)
548
+ core_props += f"\n\n## In Data Dictionary\n\n{in_data_dictionary_names}\n\n"
549
+ # Add the field to any data structures
550
+ if in_data_structure:
551
+ core_props += f"\n\n## In Data Structure\n\n{in_data_structure_names}\n\n"
552
+ for key in in_data_structure.keys():
553
+ ds_qname = in_data_structure[key].get('known_q_name', None)
554
+ ds_guid = in_data_structure[key].get('known_guid', None)
555
+ if ds_guid is not None:
556
+ df_body = {
557
+ "class": "MemberDataFieldRequestBody", "properties": {
558
+ "class": "MemberDataFieldProperties", "dataFieldPosition": 0,
559
+ "minCardinality": 0, "maxCardinality": -1,
560
+ }
561
+ }
562
+
563
+ msg = f"Adding field to structure {ds_qname}"
564
+ print_msg(INFO, msg, debug_level)
565
+ egeria_client.link_member_data_field(ds_guid, guid, df_body)
566
+ core_props += f"\n\n## In Data Structure {in_data_structure}\n\n"
567
+
568
+ if glossary_term:
569
+ if glossary_term_guid:
570
+ glossary_body = {
571
+ "class": "MetadataSourceRequestBody", "externalSourceGUID": None,
572
+ "externalSourceName": None, "effectiveTime": None, "forLineage": False,
573
+ "forDuplicateProcessing": False
574
+ }
575
+
576
+ core_props += f"\n\n## Glossary Term \n\n{glossary_term}\n\n"
577
+ egeria_client.link_semantic_definition(guid, glossary_term_guid, glossary_body)
578
+
579
+ if parent_data_field_guid:
580
+ parent_df_body = {
581
+ "class": "MetadataSourceRequestBody", "externalSourceGUID": None,
582
+ "externalSourceName": None, "effectiveTime": None, "forLineage": False,
583
+ "forDuplicateProcessing": False
584
+ }
585
+
586
+ egeria_client.link_nested_data_field(parent_data_field_guid, guid, parent_df_body)
587
+ core_props += f"\n\n## Parent Data Field\n\n{parent_data_field}\n\n"
588
+
589
+ # Link data class
590
+ print_msg(ALWAYS, f"Created Element `{display_name}` ", debug_level)
591
+ return core_props
592
+
593
+ else:
594
+ print_msg(ERROR, f"Failed to create Term `{display_name}`", debug_level)
595
+ return None
596
+
597
+ except Exception as e:
598
+ print(f"{ERROR}Error performing {command}: {e}")
599
+ Console().print_exception(show_locals=True)
600
+ return None
601
+ else:
602
+ return None
603
+
604
+
605
+ def process_data_structure_upsert_command(egeria_client: EgeriaTech, txt: str, directive: str = "display") -> Optional[
606
+ str]:
607
+ """
608
+ Processes a data structure create or update object_action by extracting key attributes such as
609
+ spec name, parent_guid, parent_relationship_type, parent_at_end_1, collection_type
610
+
611
+ :param txt: A string representing the input cell to be processed for
612
+ extracting glossary-related attributes.
613
+ :param directive: an optional string indicating the directive to be used - display, validate or execute
614
+ :return: A string summarizing the outcome of the processing.
615
+ """
616
+ from md_processing.md_processing_utils.common_md_utils import set_debug_level
617
+
618
+ set_debug_level(directive)
619
+
620
+ command, object_type, object_action = extract_command_plus(txt)
621
+
622
+ parsed_output = parse_user_command(egeria_client, object_type, object_action, txt, directive)
623
+
624
+ valid = parsed_output['valid']
625
+ exists = parsed_output['exists']
626
+
627
+ qualified_name = parsed_output.get('qualified_name', None)
628
+ guid = parsed_output.get('guid', None)
629
+
630
+ print(Markdown(parsed_output['display']))
631
+
632
+ if directive == "display":
633
+ return None
634
+
635
+ elif directive == "validate":
636
+ if valid:
637
+ print(Markdown(f"==> Validation of {command} completed successfully!\n"))
638
+ else:
639
+ msg = f"Validation failed for object_action `{command}`\n"
640
+ return valid
641
+
642
+ elif directive == "process":
643
+ print(json.dumps(parsed_output, indent=4))
644
+ attributes = parsed_output['attributes']
645
+
646
+ external_source_guid = attributes.get('External Source Name', {}).get('guid', None)
647
+ external_source_name = attributes.get('External Source Name', {}).get('value', None)
648
+ effective_time = attributes.get('Effective Time', {}).get('value', None)
649
+ for_lineage = attributes.get('For Lineage', {}).get('value', None)
650
+ for_duplicate_processing = attributes.get('For Duplicate Processing', {}).get('value', None)
651
+ anchor_guid = attributes.get('Anchor ID', {}).get('guid', None)
652
+ is_own_anchor = attributes.get('Is Own Anchor', {}).get('value', None)
653
+ parent_id = attributes.get('Parent ID', {}).get('value', None)
654
+ parent_guid = attributes.get('Parent ID', {}).get('guid', None)
655
+ parent_relationship_type_name = attributes.get('Parent Relationship Type Name', {}).get('value', None)
656
+ parent_relationship_properties = attributes.get('Parent Relationship Properties', {}).get('value', None)
657
+ parent_at_end1 = attributes.get('Parent at End1', {}).get('value', None)
658
+
659
+ display_name = attributes['Display Name'].get('value', None)
660
+
661
+ namespace = attributes.get('Namespace', {}).get('value', None)
662
+ description = attributes.get('Description', {}).get('value', None)
663
+ version_id = attributes.get('Version Identifier', {}).get('value', None)
664
+ aliases = attributes.get('Aliases', {}).get('value', None)
665
+ name_patterns = attributes.get('Name Patterns', {}).get('value', None)
666
+ is_nullable = attributes.get('Is Nullable', {}).get('value', None)
667
+ default_value = attributes.get('Default Value', {}).get('value', None)
668
+ data_type = attributes.get('Data Type', {}).get('value', None)
669
+ min_length = attributes.get('Minimum Length', {}).get('value', None)
670
+ length = attributes.get('Length', {}).get('value', None)
671
+ precision = attributes.get('Precision', {}).get('value', None)
672
+ ordered_values = attributes.get('Ordered Values', {}).get('value', None)
673
+ sort_order = attributes.get('Sort Order', {}).get('value', None)
674
+ additional_properties = attributes.get('Additional Properties', {}).get('value', None)
675
+ effective_from = attributes.get('Effective From', {}).get('value', None)
676
+ effective_to = attributes.get('Effective To', {}).get('value', None)
677
+
678
+ position = attributes.get('Position', {}).get('value', None)
679
+ min_cardinality = attributes.get('Minimum Cardinality', {}).get('value', None)
680
+ max_cardinality = attributes.get('Maximum Cardinality', {}).get('value', None)
681
+ in_data_structure = attributes.get('In Data Structure', {}).get('value', None)
682
+ data_class = attributes.get('Data Class', {}).get('value', None)
683
+ glossary_term = attributes.get('Glossary Term', {}).get('value', None)
684
+ glossary_term_guid = attributes.get('Glossary Term', {}).get('guid', None)
685
+
686
+ # name_details_list = attributes.get("dict_list", None)
687
+
688
+ in_data_spec = attributes.get("In Data Specification", {}).get("dict_list") # this is a [dict]
689
+ data_spec_name_list = attributes.get("In Data Specification", {}).get("name_list", None)
690
+ data_spec_value_list = attributes.get("In Data Specification", {}).get("value", None)
691
+
692
+ in_data_dictionary = attributes.get('In Data Dictionary', {}).get('dict_list', None)
693
+ data_dict_name_list = attributes.get('In Data Dictionary', {}).get('name_list', None)
694
+ data_dict_value_list = attributes.get('In Data Dictionary', {}).get('value', None)
695
+
696
+ parent_data_field = attributes.get('Parent Data Field', {}).get('value', None)
697
+ parent_data_field_guid = attributes.get('Parent Data Field', {}).get('guid', None)
698
+
699
+ anchor_scope_guid = attributes.get('Anchor Scope GUID', {}).get('value', None)
700
+
701
+ collection_ordering = "NAME"
702
+ order_property_name = "Something"
703
+ collection_type = object_type
704
+ replace_all_props = True
705
+ if not valid:
706
+ if exists and object_action == "Create":
707
+ msg = (f"Create failed because Element `{display_name}` exists - changing `Create` to `Update` in "
708
+ f"processed output \n")
709
+ print_msg(ERROR, msg, debug_level)
710
+ return update_a_command(txt, object_action, object_type, qualified_name, guid)
711
+ else:
712
+ return None
713
+ elif object_action == "Update" and not exists:
714
+ print(f"\n{ERROR}Element `{display_name}` does not exist! Updating result document with Create "
715
+ f"object_action\n")
716
+ return update_a_command(txt, object_action, object_type, qualified_name, guid)
717
+
718
+ else:
719
+ print(Markdown(f"==> Validation of {command} completed successfully! Proceeding to apply the changes.\n"))
720
+
721
+ try:
722
+ if object_action == "Update":
723
+ body = {
724
+ "class": "UpdateDataStructureRequestBody",
725
+ "externalSourceGUID": external_source_guid,
726
+ "externalSourceName": external_source_name,
727
+ "effectiveTime": effective_time,
728
+ "forLineage": for_lineage,
729
+ "forDuplicateProcessing": for_duplicate_processing,
730
+ "properties": {
731
+ "class": "DataStructureProperties",
732
+ "qualifiedName": qualified_name,
733
+ "displayName": display_name,
734
+ "description": description,
735
+ "namespace": namespace,
736
+ "versionIdentifier": version_id,
737
+ "additionalProperties": additional_properties,
738
+ "effectiveFrom": effective_from,
739
+ "effectiveTo": effective_to
740
+ }
741
+ }
742
+ egeria_client.update_data_structure_w_body(guid, body, replace_all_props)
743
+ print_msg(ALWAYS, f"Updated element `{display_name}` with GUID {guid}", debug_level)
744
+ core_props = egeria_client.get_data_structure_by_guid(guid, output_format='FORM')
745
+
746
+ update_element_dictionary(qualified_name, {
747
+ 'guid': guid, 'display_name': display_name
748
+ })
749
+ update_data_collection_memberships(egeria_client, in_data_spec, guid, replace_all_props)
750
+
751
+ return egeria_client.get_data_structure_by_guid(guid, output_format='MD')
752
+
753
+ elif object_action == "Create":
754
+ if exists:
755
+ print(f"\nTerm `{display_name}` already exists and result document updated\n")
756
+ return update_a_command(txt, object_action, object_type, qualified_name, guid)
757
+ else:
758
+
759
+ body = {
760
+ "class": "NewDataStructureRequestBody", "externalSourceGUID": external_source_guid,
761
+ "externalSourceName": external_source_name, "effectiveTime": effective_time,
762
+ "forLineage": False, "forDuplicateProcessing": False, "anchorGUID": anchor_guid,
763
+ "isOwnAnchor": is_own_anchor, "parentGUID": parent_guid,
764
+ "parentRelationshipTypeName": parent_relationship_type_name,
765
+ "parentRelationshipProperties": parent_relationship_properties, "parentAtEnd1": parent_at_end1,
766
+ "properties": {
767
+ "class": "DataStructureProperties", "qualifiedName": qualified_name,
768
+ "displayName": display_name, "description": description, "namespace": namespace,
769
+ "versionIdentifier": version_id, "additionalProperties": additional_properties,
770
+ "effectiveFrom": effective_from, "effectiveTo": effective_to
771
+ }
772
+ }
773
+
774
+ guid = egeria_client.create_data_structure_w_body(body_slimmer(body))
775
+ if guid:
776
+ update_element_dictionary(qualified_name, {
777
+ 'guid': guid, 'display_name': display_name
778
+ })
779
+
780
+ core_props = egeria_client.get_data_structure_by_guid(guid, output_format='FORM')
781
+
782
+ if in_data_dictionary:
783
+ print_msg(ALWAYS, f"Will add to data dictionary(s) `{in_data_dictionary}`", debug_level)
784
+ result = add_member_to_data_collections(egeria_client, in_data_dictionary, display_name,guid )
785
+ core_props += f"\n\n## In Data Dictionary\n\n{in_data_dictionary}\n\n"
786
+ # ==>> update to use new function.
787
+ if in_data_spec:
788
+ # member_body = {
789
+ # "class": "CollectionMembershipProperties",
790
+ # "membershipRationale": "Adding data structure to data specification",
791
+ # "expression": None, "confidence": 100, "status": None, "userDefinedStatus": None,
792
+ # "steward": None, "stewardTypeName": None, "stewardPropertyName": None, "source": None,
793
+ # "notes": None,
794
+ # }
795
+ #
796
+ # if data_spec_name_list is not None:
797
+ # for el in data_spec_value_list:
798
+ # for key in el:
799
+ # ds = el[key]
800
+ # ds_qname = ds.get('known_q_name', None)
801
+ # ds_guid = ds.get('known_guid', None)
802
+ # if ds_guid is not None:
803
+ # msg = f"Adding field to Data Specification `{ds_qname}`"
804
+ # egeria_client.add_to_collection(ds_guid, guid, member_body)
805
+ # print_msg(INFO, msg, debug_level)
806
+ result = add_member_to_data_collections(egeria_client, in_data_spec, display_name,guid )
807
+
808
+ core_props += f"\n\n## In Data Specifications\n\n`{data_spec_name_list}`\n\n"
809
+
810
+ print_msg(ALWAYS, f"Created Element `{display_name}` with GUID {guid}", debug_level)
811
+
812
+ return core_props
813
+ else:
814
+ print_msg(ERROR, f"Failed to create Data Structure `{display_name}`", debug_level)
815
+ return None
816
+
817
+
818
+ except Exception as e:
819
+ print(f"{ERROR}Error performing {object_action}: {e}")
820
+ Console().print_exception(show_locals=True)
821
+ return None
822
+ else:
823
+ return None
824
+
825
+
826
+ # def process_data_field_upsert_command(egeria_client: EgeriaTech, txt: str, directive: str = "display") -> Optional[
827
+ # str]:
828
+ # """
829
+ # Processes a data structure create or update object_action by extracting key attributes such as
830
+ # spec name, parent_guid, parent_relationship_type, parent_at_end_1, collection_type
831
+ #
832
+ # :param txt: A string representing the input cell to be processed for
833
+ # extracting glossary-related attributes.
834
+ # :param directive: an optional string indicating the directive to be used - display, validate or execute
835
+ # :return: A string summarizing the outcome of the processing.
836
+ # """
837
+ #
838
+ # from md_processing.md_processing_utils.common_md_utils import set_debug_level
839
+ #
840
+ # valid = True
841
+ #
842
+ # set_debug_level(directive)
843
+ # known_q_name = None
844
+ # command, object_type, object_action = extract_command_plus(txt)
845
+
846
+ # object_action = extract_command(txt)
847
+ # object_type = object_action.split(' ')[1].strip()
848
+ # object_action = object_action.split(' ')[0].strip()
849
+
850
+ # parsed_output = parse_user_command(egeria_client, object_type, object_action, txt)
851
+
852
+
853
+ # valid = True
854
+ #
855
+ # set_debug_level(directive)
856
+ # known_q_name = None
857
+ # object_action = extract_command(txt)
858
+ # object_type = object_action.split(' ')[1].strip()
859
+ # object_action = object_action.split(' ')[0].strip()
860
+ #
861
+ # display_name_label = ['Data Structure Name', 'Display Name', 'Name']
862
+ #
863
+ # display_name = process_simple_attribute(txt, display_name_label, ERROR)
864
+ # print(Markdown(f"{pre_command} `{object_action}` for term:`{display_name}` with directive: `{directive}`"))
865
+ #
866
+ # description = process_simple_attribute(txt, ['Description'], INFO)
867
+ # data_type = process_simple_attribute(txt, ['Data Type', "Type"], WARNING)
868
+ # positoion = process_simple_attribute(txt, ['Position'], INFO)
869
+ # min_cardinalityc = process_simple_attribute(txt, ['Minimum Cardinality', 'Min Cardinality'], WARNING)
870
+ # max_cardinality= process_simple_attribute(txt, ['Maximum Cardinality', 'Max Cardinality'], INFO)
871
+ # in_data_structure = process_simple_attribute(txt, ['In Data Structure', 'In Data Struct'], INFO)
872
+ # data_class = process_simple_attribute(txt, ['Data Class','DataClass'], INFO)
873
+ # glossary_term = process_simple_attribute(txt, GLOSSARY_NAME_LABELS, INFO)
874
+ # namesspace= process_simple_attribute(txt, ['Namespace'], INFO)
875
+ # version_id = process_simple_attribute(txt, ['Version','Version Id', 'Version Identifier'], INFO)
876
+ # in_data_dict = process_simple_attribute(txt, ['In Data Dict', 'Data Dictionary', 'In Data Dictionary'], INFO)
877
+ #
878
+ # q_name = process_simple_attribute(txt, ['Qualified Name'], INFO)
879
+ #
880
+ # # validate display name and get existing qualified_name and guid if they exist
881
+ # if display_name is None:
882
+ # valid = False
883
+ # known_q_name, known_guid, exists = None, None, False
884
+ # else:
885
+ # known_q_name, known_guid, valid, exists = process_element_identifiers(egeria_client, object_type,
886
+ # display_name_label, txt, object_action,
887
+ # None)
888
+ #
889
+ # if object_action == "Update": # check to see if provided information exists and is consistent with existing info
890
+ # guid = process_simple_attribute(txt, GUID_LABELS)
891
+ #
892
+ # display = (f"\n* Command: {object_action}\n\t"
893
+ # f"* Name: {display_name}\n\t* Description: {description}\n\t"
894
+ # f"* Qualified Name: {q_name}\n\t* GUID: {guid}"
895
+ # )
896
+ #
897
+ # if not exists:
898
+ # msg = f"Update request invalid, Term {display_name} does not exist\n"
899
+ # print_msg(ERROR, msg, debug_level)
900
+ # valid = False
901
+ #
902
+ # elif object_action == 'Create': # if the object_action is create, check that it doesn't already exist
903
+ # display = (f"\n* Command: {object_action}\n\t* Glossary: {known_q_name}\n\t"
904
+ # f"* Name: {display_name}\n\t* Description: {description}\n\t"
905
+ # f"* Qualified Name: {q_name}\n\t"
906
+ # )
907
+ # if exists:
908
+ # msg = f"Element `{display_name}` cannot be created since it already exists\n"
909
+ # print_msg(ERROR, msg, debug_level)
910
+ # else:
911
+ # msg = f"It is valid to create Element `{display_name}`"
912
+ # print_msg(ALWAYS, msg, debug_level)
913
+
914
+ # if directive == "display":
915
+ # print(Markdown(display))
916
+ # return None
917
+ # elif directive == "validate":
918
+ # if valid:
919
+ # print(Markdown(display))
920
+ # else:
921
+ # msg = f"Validation failed for Term `{display_name}`\n"
922
+ # print_msg(ERROR, msg, debug_level)
923
+ # print(Markdown(display))
924
+ # return valid
925
+ #
926
+ # elif directive == "process":
927
+ # if valid:
928
+ # print(Markdown(display))
929
+ # else:
930
+ # if exists and object_action == "Create":
931
+ # msg = f"Create failed because Element `{display_name}` exists - changing `Create` to `Update` in
932
+ # processed output \n"
933
+ # print_msg(ERROR, msg, debug_level)
934
+ # print(Markdown(display))
935
+ # return update_a_command(txt, object_action, object_type, known_q_name, known_guid)
936
+ # else:
937
+ # return None
938
+ #
939
+ # try:
940
+ # if object_action == "Update":
941
+ # if not exists:
942
+ # print(f"\n{ERROR}Element `{display_name}` does not exist! Updating result document with Create "
943
+ # f"object_action\n")
944
+ # return update_a_command(txt, object_action, object_type, known_q_name, known_guid)
945
+ #
946
+ # egeria_client.update_term(known_guid, body)
947
+ # print_msg(ALWAYS, f"Updated Term `{term_name}` with GUID {known_guid}", debug_level)
948
+ # update_element_dictionary(known_q_name, {
949
+ # 'guid': known_guid, 'display_name': term_name
950
+ # })
951
+ #
952
+ # return egeria_client.get_term_by_guid(known_guid, output_format='MD')
953
+ #
954
+ # elif object_action == "Create":
955
+ # if exists:
956
+ # print(f"\nTerm `{display_name}` already exists and result document updated\n")
957
+ # return update_a_command(txt, object_action, object_type, known_q_name, known_guid)
958
+ # else:
959
+ # guid = egeria_client.create_data_spec_collection(None, None, None,
960
+ # True, display_name, description,
961
+ # collection_type, None,
962
+ # True, None)
963
+ # if guid:
964
+ # print_msg(ALWAYS, f"Created Element `{display_name}` with GUID {guid}", debug_level)
965
+ # # Add categories if specified
966
+ #
967
+ # return egeria_client.get_collection_by_guid(guid, output_format='FORM')
968
+ # else:
969
+ # print_msg(ERROR, f"Failed to create Term `{display_name}`", debug_level)
970
+ # return None
971
+ #
972
+ # except Exception as e:
973
+ # print(f"{ERROR}Error performing {object_action}: {e}")
974
+ # Console().print_exception(show_locals=True)
975
+ # return None
976
+ # else:
977
+ # return None
978
+ #
979
+ #
980
+ def process_data_dict_list_command(egeria_client: EgeriaTech, txt: str, directive: str = "display") -> Optional[str]:
981
+ """
982
+ Processes a Data Dictionary list object_action by extracting key attributes such as
983
+ search string from the given text.
984
+
985
+ :param txt: A string representing the input cell to be processed for
986
+ extracting term-related attributes.
987
+ :param directive: an optional string indicating the directive to be used - display, validate or execute
988
+ :return: A string summarizing the outcome of the processing.
989
+ """
990
+ from md_processing.md_processing_utils.common_md_utils import set_debug_level
991
+
992
+ set_debug_level(directive)
993
+ known_q_name = None
994
+ command, object_type, object_action = extract_command_plus(txt)
995
+
996
+ object_action = extract_command(txt)
997
+ set_debug_level(directive)
998
+
999
+ parsed_output = parse_user_command(egeria_client, object_action, 'View', txt)
1000
+ print(Markdown(parsed_output['display']))
1001
+ valid = parsed_output['valid']
1002
+
1003
+ if directive == "display":
1004
+ return None
1005
+ elif directive == "validate":
1006
+ if valid:
1007
+ msg = f"Validation passed for {object_action} `{object_type}`\n"
1008
+ else:
1009
+ msg = f"Validation failed for {object_action} `{object_type}`\n"
1010
+ print_msg(ERROR, msg, debug_level)
1011
+ return valid
1012
+ elif directive == "process":
1013
+ attributes = parsed_output['attributes']
1014
+ search_string = attributes.get('Search String', {}).get('value', '*')
1015
+ output_format = attributes.get('Output Format', {}).get('value', 'LIST')
1016
+ detailed = attributes.get('Detailed', {}).get('value', False)
1017
+
1018
+ try:
1019
+ if not valid: # First validate the command before we process it
1020
+ msg = f"Validation failed for {object_action} `{object_type}`\n"
1021
+ print_msg(ERROR, msg, debug_level)
1022
+ return None
1023
+
1024
+ list_md = f"\n# Data Dictionaries with filter: `{search_string}`\n\n"
1025
+ if output_format == "DICT":
1026
+ struct = egeria_client.get_classified_collections('DataDictionary', output_format=output_format)
1027
+ list_md += f"```{json.dumps(struct, indent=4)}```\n"
1028
+ else:
1029
+ list_md += egeria_client.find_collections(search_string, output_format=output_format)
1030
+ print_msg("ALWAYS", f"Wrote Dictionaries for search string: `{search_string}`", debug_level)
1031
+
1032
+ return list_md
1033
+
1034
+ except Exception as e:
1035
+ print(f"{ERROR}Error performing {command}: {e}")
1036
+ console.print_exception(show_locals=True)
1037
+ return None
1038
+ else:
1039
+ return None
1040
+
1041
+ # def process_term_details_command(egeria_client: EgeriaTech, txt: str, directive: str = "display") -> Optional[str]:
1042
+ # """
1043
+ # Processes a term details object_action by extracting key attributes such as
1044
+ # term name and output format from the given text.
1045
+ #
1046
+ # :param txt: A string representing the input cell to be processed for
1047
+ # extracting term-related attributes.
1048
+ # :param directive: an optional string indicating the directive to be used - display, validate or execute
1049
+ # :return: A string summarizing the outcome of the processing.
1050
+ # """
1051
+ # from md_processing.md_processing_utils.common_md_utils import set_debug_level
1052
+ #
1053
+ # object_action = extract_command(txt)
1054
+ # set_debug_level(directive)
1055
+ # print(Markdown(f"{pre_command} `{object_action}` with directive: `{directive}`"))
1056
+ #
1057
+ # term_name = process_simple_attribute(txt, TERM_NAME_LABELS, ERROR)
1058
+ # output_format = process_simple_attribute(txt, OUTPUT_LABELS)
1059
+ # output_format = output_format.upper() if output_format else "MD"
1060
+ # if output_format not in ELEMENT_OUTPUT_FORMATS:
1061
+ # print_msg(WARNING, f"Output format {output_format} not recognized, using MD", debug_level)
1062
+ # output_format = "MD"
1063
+ #
1064
+ # if term_name is None:
1065
+ # print_msg(ERROR, "No term name found", debug_level)
1066
+ # return None
1067
+ #
1068
+ # known_q_name, known_guid, valid, term_exists = process_element_identifiers(egeria_client, "Term",
1069
+ # TERM_NAME_LABELS, txt,
1070
+ # EXISTS_REQUIRED, None)
1071
+ # if not term_exists:
1072
+ # print_msg(ERROR, f"Term {term_name} not found", debug_level)
1073
+ # return None
1074
+ #
1075
+ # if directive == "display":
1076
+ # print(Markdown(f"\n* Command: {object_action}\n\t* Term Name: {term_name}\n\t* Output Format: {
1077
+ # output_format}"))
1078
+ # return None
1079
+ # elif directive == "validate":
1080
+ # print(Markdown(f"\n* Command: {object_action}\n\t* Term Name: {term_name}\n\t* Output Format: {
1081
+ # output_format}"))
1082
+ # return True
1083
+ # elif directive == "process":
1084
+ # print(Markdown(f"\n* Command: {object_action}\n\t* Term Name: {term_name}\n\t* Output Format: {
1085
+ # output_format}"))
1086
+ # return egeria_client.get_term_by_guid(known_guid, output_format=output_format)
1087
+ #
1088
+ #
1089
+ # def process_term_history_command(egeria_client: EgeriaTech, txt: str, directive: str = "display") -> Optional[str]:
1090
+ # """
1091
+ # Processes a term history object_action by extracting key attributes such as
1092
+ # term name and output format from the given text.
1093
+ #
1094
+ # :param txt: A string representing the input cell to be processed for
1095
+ # extracting term-related attributes.
1096
+ # :param directive: an optional string indicating the directive to be used - display, validate or execute
1097
+ # :return: A string summarizing the outcome of the processing.
1098
+ # """
1099
+ # from md_processing.md_processing_utils.common_md_utils import set_debug_level
1100
+ #
1101
+ # object_action = extract_command(txt)
1102
+ # set_debug_level(directive)
1103
+ # print(Markdown(f"{pre_command} `{object_action}` with directive: `{directive}`"))
1104
+ #
1105
+ # term_name = process_simple_attribute(txt, TERM_NAME_LABELS, ERROR)
1106
+ # output_format = process_simple_attribute(txt, OUTPUT_LABELS)
1107
+ # output_format = output_format.upper() if output_format else "MD"
1108
+ # if output_format not in ELEMENT_OUTPUT_FORMATS:
1109
+ # print_msg(WARNING, f"Output format {output_format} not recognized, using MD", debug_level)
1110
+ # output_format = "MD"
1111
+ #
1112
+ # if term_name is None:
1113
+ # print_msg(ERROR, "No term name found", debug_level)
1114
+ # return None
1115
+ #
1116
+ # known_q_name, known_guid, valid, term_exists = process_element_identifiers(egeria_client, "Term",
1117
+ # TERM_NAME_LABELS, txt,
1118
+ # EXISTS_REQUIRED, None)
1119
+ # if not term_exists:
1120
+ # print_msg(ERROR, f"Term {term_name} not found", debug_level)
1121
+ # return None
1122
+ #
1123
+ # if directive == "display":
1124
+ # print(Markdown(f"\n* Command: {object_action}\n\t* Term Name: {term_name}\n\t* Output Format: {
1125
+ # output_format}"))
1126
+ # return None
1127
+ # elif directive == "validate":
1128
+ # print(Markdown(f"\n* Command: {object_action}\n\t* Term Name: {term_name}\n\t* Output Format: {
1129
+ # output_format}"))
1130
+ # return True
1131
+ # elif directive == "process":
1132
+ # print(Markdown(f"\n* Command: {object_action}\n\t* Term Name: {term_name}\n\t* Output Format: {
1133
+ # output_format}"))
1134
+ # return egeria_client.get_term_history(known_guid, output_format=output_format)
1135
+ #
1136
+ #
1137
+ # def process_term_revision_history_command(egeria_client: EgeriaTech, txt: str, directive: str = "display") ->
1138
+ # Optional[str]:
1139
+ # """
1140
+ # Processes a term revision history object_action by extracting key attributes such as
1141
+ # term name and output format from the given text.
1142
+ #
1143
+ # :param txt: A string representing the input cell to be processed for
1144
+ # extracting term-related attributes.
1145
+ # :param directive: an optional string indicating the directive to be used - display, validate or execute
1146
+ # :return: A string summarizing the outcome of the processing.
1147
+ # """
1148
+ # from md_processing.md_processing_utils.common_md_utils import set_debug_level
1149
+ #
1150
+ # object_action = extract_command(txt)
1151
+ # set_debug_level(directive)
1152
+ # print(Markdown(f"{pre_command} `{object_action}` with directive: `{directive}`"))
1153
+ #
1154
+ # term_name = process_simple_attribute(txt, TERM_NAME_LABELS, ERROR)
1155
+ # output_format = process_simple_attribute(txt, OUTPUT_LABELS)
1156
+ # output_format = output_format.upper() if output_format else "MD"
1157
+ # if output_format not in ELEMENT_OUTPUT_FORMATS:
1158
+ # print_msg(WARNING, f"Output format {output_format} not recognized, using MD", debug_level)
1159
+ # output_format = "MD"
1160
+ #
1161
+ # if term_name is None:
1162
+ # print_msg(ERROR, "No term name found", debug_level)
1163
+ # return None
1164
+ #
1165
+ # known_q_name, known_guid, valid, term_exists = process_element_identifiers(egeria_client, "Term",
1166
+ # TERM_NAME_LABELS, txt,
1167
+ # EXISTS_REQUIRED, None)
1168
+ # if not term_exists:
1169
+ # print_msg(ERROR, f"Term {term_name} not found", debug_level)
1170
+ # return None
1171
+ #
1172
+ # if directive == "display":
1173
+ # print(Markdown(f"\n* Command: {object_action}\n\t* Term Name: {term_name}\n\t* Output Format: {
1174
+ # output_format}"))
1175
+ # return None
1176
+ # elif directive == "validate":
1177
+ # print(Markdown(f"\n* Command: {object_action}\n\t* Term Name: {term_name}\n\t* Output Format: {
1178
+ # output_format}"))
1179
+ # return True
1180
+ # elif directive == "process":
1181
+ # print(Markdown(f"\n* Command: {object_action}\n\t* Term Name: {term_name}\n\t* Output Format: {
1182
+ # output_format}"))
1183
+ # return egeria_client.get_term_revision_history(known_guid, output_format=output_format)