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