Skip to content

Commit 529cf57

Browse files
authored
Merge pull request #171 from dwolfson/v6-tests
Working on test and debugging for product_manager and digital_business.
2 parents 895a0b4 + ae7022e commit 529cf57

8 files changed

+356
-52
lines changed

pyegeria/_server_client.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4772,7 +4772,7 @@ def validate_new_classification_request(self, body: dict | NewClassificationRequ
47724772
return validated_body
47734773

47744774
@dynamic_catch
4775-
def validate_delete_element_request(self, body: dict | DeleteElementRequestBody,
4775+
def validate_delete_element_request(self, body: dict | DeleteElementRequestBody = None,
47764776
cascade_delete: bool = False) -> DeleteElementRequestBody | None:
47774777
if isinstance(body, DeleteElementRequestBody):
47784778
validated_body = body
@@ -5140,11 +5140,12 @@ async def _async_new_classification_request(self, url: str, prop: list[str] = No
51405140
@dynamic_catch
51415141
async def _async_delete_element_request(self, url: str, body: dict | DeleteElementRequestBody = None,
51425142
cascade_delete: bool = False) -> None:
5143-
validated_body = self.validate_delete_element_request(body, cascade_delete)
5144-
if validated_body:
5145-
json_body = validated_body.model_dump_json(indent=2, exclude_none=True)
5146-
logger.info(json_body)
5147-
await self._async_make_request("POST", url, json_body)
5143+
if body:
5144+
validated_body = self.validate_delete_element_request(body, cascade_delete)
5145+
if validated_body:
5146+
json_body = validated_body.model_dump_json(indent=2, exclude_none=True)
5147+
logger.info(json_body)
5148+
await self._async_make_request("POST", url, json_body)
51485149
else:
51495150
await self._async_make_request("POST", url)
51505151

pyegeria/digital_business.py

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import asyncio
1212
from typing import Optional
1313

14+
from pyegeria import CollectionManager
1415
from pyegeria._server_client import ServerClient
1516
from pyegeria._exceptions import PyegeriaInvalidParameterException
1617
from pyegeria._globals import NO_GUID_RETURNED
@@ -24,13 +25,14 @@
2425
NewClassificationRequestBody,
2526
DeleteClassificationRequestBody
2627
)
28+
2729
from pyegeria.utils import dynamic_catch, body_slimmer
2830
from loguru import logger
2931

3032
EGERIA_LOCAL_QUALIFIER = app_settings.User_Profile.egeria_local_qualifier
3133

3234

33-
class DigitalBusiness(ServerClient):
35+
class DigitalBusiness(CollectionManager):
3436
"""
3537
Manage business capabilities, their lifecycle, and their digital support relationships.
3638
@@ -116,13 +118,13 @@ def _prepare_body(self, body: Optional[dict | NewElementRequestBody | UpdateElem
116118
@dynamic_catch
117119
async def _async_create_business_capability(
118120
self,
119-
body: Optional[dict | NewElementRequestBody] = None,
121+
body: Optional[dict | NewElementRequestBody],
120122
) -> str:
121123
"""Create a new business capability collection. Async version.
122124
123125
Parameters
124126
----------
125-
body : dict | NewElementRequestBody, optional
127+
body : dict | NewElementRequestBody
126128
Request body containing business capability properties.
127129
128130
Returns
@@ -162,18 +164,18 @@ async def _async_create_business_capability(
162164
"forDuplicateProcessing" : false,
163165
}
164166
"""
165-
url = f"{self.digital_business_command_root}/business-capabilities"
167+
url = f"{self.digital_business_command_root}/collections"
166168
return await self._async_create_element_body_request(url, ["BusinessCapabilityProperties"], body)
167169

168170
def create_business_capability(
169171
self,
170-
body: Optional[dict | NewElementRequestBody] = None,
172+
body: Optional[dict | NewElementRequestBody],
171173
) -> str:
172174
"""Create a new business capability collection. Sync version.
173175
174176
Parameters
175177
----------
176-
body : dict | NewElementRequestBody, optional
178+
body : dict | NewElementRequestBody
177179
Request body containing business capability properties.
178180
179181
Returns
@@ -218,7 +220,7 @@ async def _async_update_business_capability(
218220
PyegeriaNotAuthorizedException
219221
If the user is not authorized for the requested action.
220222
"""
221-
url = f"{self.digital_business_command_root}/business-capabilities/{business_capability_guid}/update"
223+
url = f"{self.digital_business_command_root}/collections/{business_capability_guid}/update"
222224
await self._async_update_element_body_request(url, ["BusinessCapabilityProperties"], body)
223225

224226
def update_business_capability(
@@ -282,7 +284,7 @@ async def _async_delete_business_capability(
282284
PyegeriaNotAuthorizedException
283285
If the user is not authorized for the requested action.
284286
"""
285-
url = f"{self.digital_business_command_root}/business-capabilities/{business_capability_guid}/delete"
287+
url = f"{self.digital_business_command_root}/collections/{business_capability_guid}/delete"
286288
await self._async_delete_element_request(url, body, cascade)
287289

288290
def delete_business_capability(
@@ -354,11 +356,11 @@ async def _async_get_business_capability_by_guid(
354356
PyegeriaNotAuthorizedException
355357
If the user is not authorized for the requested action.
356358
"""
357-
url = f"{self.digital_business_command_root}/business-capabilities/{business_capability_guid}/retrieve"
359+
url = f"{self.digital_business_command_root}/collections/{business_capability_guid}/retrieve"
358360
response = await self._async_get_guid_request(
359361
url,
360362
_type="BusinessCapability",
361-
_gen_output=None,
363+
_gen_output=self._generate_collection_output,
362364
output_format=output_format,
363365
report_spec=report_spec,
364366
body=body,
@@ -442,11 +444,11 @@ async def _async_get_business_capabilities_by_name(
442444
PyegeriaException
443445
If there are issues in communications, message format, or Egeria errors.
444446
"""
445-
url = f"{self.digital_business_command_root}/business-capabilities/by-name"
447+
url = f"{self.digital_business_command_root}/collections/by-name"
446448
response = await self._async_get_name_request(
447449
url,
448450
_type="BusinessCapability",
449-
_gen_output=None,
451+
_gen_output=self._generate_collection_output,
450452
filter_string=filter_string,
451453
classification_names=classification_names,
452454
start_from=start_from,
@@ -511,8 +513,8 @@ async def _async_find_business_capabilities(
511513
ends_with: bool = False,
512514
ignore_case: bool = True,
513515
anchor_domain: Optional[str] = None,
514-
metadata_element_type: Optional[str] = None,
515-
metadata_element_subtype: Optional[str] = None,
516+
metadata_element_type: Optional[str] = "BusinessCapability",
517+
metadata_element_subtype: Optional[list[str]] = None,
516518
skip_relationships: Optional[list[str]] = None,
517519
include_only_relationships: Optional[list[str]] = None,
518520
skip_classified_elements: Optional[list[str]] = None,
@@ -594,11 +596,11 @@ async def _async_find_business_capabilities(
594596
PyegeriaException
595597
If there are issues in communications, message format, or Egeria errors.
596598
"""
597-
url = f"{self.digital_business_command_root}/business-capabilities/by-search-string"
599+
url = f"{self.digital_business_command_root}/collections/by-search-string"
598600
response = await self._async_find_request(
599601
url,
600602
_type="BusinessCapability",
601-
_gen_output=None,
603+
_gen_output=self._generate_collection_output,
602604
search_string=search_string,
603605
starts_with=starts_with,
604606
ends_with=ends_with,
@@ -633,8 +635,8 @@ def find_business_capabilities(
633635
ends_with: bool = False,
634636
ignore_case: bool = True,
635637
anchor_domain: Optional[str] = None,
636-
metadata_element_type: Optional[str] = None,
637-
metadata_element_subtype: Optional[str] = None,
638+
metadata_element_type: Optional[str] = "BusinessCapability",
639+
metadata_element_subtype: Optional[list[str]] = None,
638640
skip_relationships: Optional[list[str]] = None,
639641
include_only_relationships: Optional[list[str]] = None,
640642
skip_classified_elements: Optional[list[str]] = None,
@@ -718,14 +720,14 @@ def find_business_capabilities(
718720
"""
719721
loop = asyncio.get_event_loop()
720722
return loop.run_until_complete(
721-
self._async_find_business_capabilities(
722-
search_string, starts_with, ends_with, ignore_case, anchor_domain,
723-
metadata_element_type, metadata_element_subtype, skip_relationships,
724-
include_only_relationships, skip_classified_elements, include_only_classified_elements,
725-
graph_query_depth, governance_zone_filter, as_of_time, effective_time,
726-
relationship_page_size, limit_results_by_status, sequencing_order,
727-
sequencing_property, start_from, page_size, output_format, report_spec, body
728-
)
723+
self._async_find_business_capabilities(search_string, starts_with, ends_with, ignore_case, anchor_domain,
724+
metadata_element_type, metadata_element_subtype, skip_relationships,
725+
include_only_relationships, skip_classified_elements,
726+
include_only_classified_elements, graph_query_depth,
727+
governance_zone_filter, as_of_time, effective_time,
728+
relationship_page_size, limit_results_by_status, sequencing_order,
729+
sequencing_property, start_from, page_size, output_format,
730+
report_spec, body)
729731
)
730732

731733
#

pyegeria/output_formatter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1076,7 +1076,7 @@ def _generate_default_output(self, elements: dict | list[dict], search_string: s
10761076
output_format: str = 'DICT',
10771077
report_format: dict | str | None = None,
10781078
**kwargs) -> str | list[dict]:
1079-
entity_type = 'Referenceable'
1079+
entity_type = 'Referenceable' if element_type_name is None else element_type_name
10801080
# Backward compatibility: accept legacy kwarg
10811081
if report_format is None and isinstance(kwargs, dict) and 'report_spec' in kwargs:
10821082
report_format = kwargs.get('report_spec')

pyegeria/product_manager.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import asyncio
1212
from typing import Optional
1313

14+
from pyegeria import CollectionManager
1415
from pyegeria._server_client import ServerClient
1516
from pyegeria._exceptions import PyegeriaInvalidParameterException
1617
from pyegeria._globals import NO_GUID_RETURNED
@@ -28,7 +29,7 @@
2829
EGERIA_LOCAL_QUALIFIER = app_settings.User_Profile.egeria_local_qualifier
2930

3031

31-
class ProductManager(ServerClient):
32+
class ProductManager(CollectionManager):
3233
"""
3334
Manage digital products, digital product catalogs, and their relationships.
3435
@@ -425,7 +426,7 @@ async def _async_get_digital_product_by_guid(
425426
response = await self._async_get_guid_request(
426427
url,
427428
_type="DigitalProduct",
428-
_gen_output=None,
429+
_gen_output=self._generate_collection_output,
429430
output_format=output_format,
430431
report_spec=report_spec,
431432
body=body,
@@ -472,7 +473,7 @@ def get_digital_product_by_guid(
472473
@dynamic_catch
473474
async def _async_get_digital_products_by_name(
474475
self,
475-
filter_string: Optional[str] = None,
476+
filter_string: str,
476477
classification_names: Optional[list[str]] = None,
477478
body: Optional[dict] = None,
478479
start_from: int = 0,
@@ -484,7 +485,7 @@ async def _async_get_digital_products_by_name(
484485
485486
Parameters
486487
----------
487-
filter_string : str, optional
488+
filter_string : str
488489
Name to use to find matching digital products.
489490
classification_names : list[str], optional
490491
List of classification names to filter on.
@@ -513,7 +514,7 @@ async def _async_get_digital_products_by_name(
513514
response = await self._async_get_name_request(
514515
url,
515516
_type="DigitalProduct",
516-
_gen_output=None,
517+
_gen_output=self._generate_collection_output,
517518
filter_string=filter_string,
518519
classification_names=classification_names,
519520
start_from=start_from,
@@ -526,7 +527,7 @@ async def _async_get_digital_products_by_name(
526527

527528
def get_digital_products_by_name(
528529
self,
529-
filter_string: Optional[str] = None,
530+
filter_string: str,
530531
classification_names: Optional[list[str]] = None,
531532
body: Optional[dict] = None,
532533
start_from: int = 0,
@@ -538,7 +539,7 @@ def get_digital_products_by_name(
538539
539540
Parameters
540541
----------
541-
filter_string : str, optional
542+
filter_string : str
542543
Name to use to find matching digital products.
543544
classification_names : list[str], optional
544545
List of classification names to filter on.
@@ -668,7 +669,7 @@ async def _async_find_digital_products(
668669
response = await self._async_find_request(
669670
url,
670671
_type="DigitalProduct",
671-
_gen_output=None,
672+
_gen_output=self._generate_collection_output,
672673
search_string=search_string,
673674
starts_with=starts_with,
674675
ends_with=ends_with,

tests/test_collection_manager_omvs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def test_find_collections(self):
114114
start_time = time.perf_counter()
115115
search_string = "*"
116116
classification_name = None
117-
element_type = ["CollectionFolder"]
117+
element_type = ["DigitalProduct"]
118118
output_format = "DICT"
119119
report_spec = "BasicCollections"
120120

0 commit comments

Comments
 (0)