Skip to content

Commit c2027ff

Browse files
committed
feat(geodeObjectInheritance): Blueprint to return a inheritance relaated objects list from geode_object string
1 parent 357f641 commit c2027ff

5 files changed

Lines changed: 113 additions & 0 deletions

File tree

src/opengeodeweb_back/routes/blueprint_routes.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,3 +608,52 @@ def import_extension() -> flask.Response:
608608
},
609609
200,
610610
)
611+
612+
613+
@routes.route(
614+
schemas_dict["geode_object_inheritance"]["route"],
615+
methods=schemas_dict["geode_object_inheritance"]["methods"],
616+
)
617+
def geode_object_inheritance() -> flask.Response:
618+
json_data = utils_functions.validate_request(
619+
flask.request, schemas_dict["geode_object_inheritance"]
620+
)
621+
params = schemas.GeodeObjectInheritance.from_dict(json_data)
622+
geode_object_type = params.geode_object_type
623+
target_class = geode_functions.geode_object_from_string(geode_object_type)
624+
print(f"Inheritance for {geode_object_type} ({target_class.__name__})")
625+
626+
def get_all_bases(geode_class: type) -> set[type]:
627+
bases = set()
628+
for base_class in geode_class.__bases__:
629+
if base_class is not object:
630+
bases.add(base_class)
631+
bases.update(get_all_bases(base_class))
632+
return bases
633+
634+
def get_all_subclasses(geode_class: type) -> set[type]:
635+
subclasses = set()
636+
for subclass_class in geode_class.__subclasses__():
637+
subclasses.add(subclass_class)
638+
subclasses.update(get_all_subclasses(subclass_class))
639+
return subclasses
640+
641+
# Extract all related Geode classes (parents and children)
642+
bases = get_all_bases(target_class)
643+
subclasses = get_all_subclasses(target_class)
644+
print(f"Bases found: {[base_class.__name__ for base_class in bases]}")
645+
print(
646+
f"Subclasses found: {[subclass_class.__name__ for subclass_class in subclasses]}"
647+
)
648+
649+
all_related_classes = bases | subclasses
650+
all_related_classes.add(target_class)
651+
652+
# Filter GeodeObjectType to only include registered related objects
653+
geode_inheritances = []
654+
for geode_object_type_str, geode_class in geode_objects.items():
655+
if geode_class in all_related_classes:
656+
geode_inheritances.append(geode_object_type_str)
657+
658+
print(f"Geode Object inheritances: {geode_inheritances}")
659+
return flask.make_response({"geode_inheritances": geode_inheritances}, 200)

src/opengeodeweb_back/routes/schemas/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from .import_project import *
1212
from .import_extension import *
1313
from .geographic_coordinate_systems import *
14+
from .geode_object_inheritance import *
1415
from .geode_objects_and_output_extensions import *
1516
from .export_project import *
1617
from .edge_attribute_names import *
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"route": "/geode_object_inheritance",
3+
"methods": [
4+
"POST"
5+
],
6+
"type": "object",
7+
"properties": {
8+
"geode_object_type": {
9+
"type": "string",
10+
"minLength": 1
11+
}
12+
},
13+
"required": [
14+
"geode_object_type"
15+
],
16+
"additionalProperties": false
17+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from dataclasses_json import DataClassJsonMixin
2+
from dataclasses import dataclass
3+
4+
5+
@dataclass
6+
class GeodeObjectInheritance(DataClassJsonMixin):
7+
def __post_init__(self) -> None:
8+
print(self, flush=True)
9+
10+
geode_object_type: str

tests/test_routes.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,3 +379,39 @@ def test_database_uri_path(client: FlaskClient) -> None:
379379
assert app.config["SQLALCHEMY_DATABASE_URI"] == expected_uri
380380

381381
assert os.path.exists(expected_db_path)
382+
383+
384+
def test_geode_object_inheritance(client: FlaskClient) -> None:
385+
route = "/opengeodeweb_back/geode_object_inheritance"
386+
# Test BRep
387+
response = client.post(route, json={"geode_object_type": "BRep"})
388+
assert response.status_code == 200
389+
geode_inheritances = response.get_json()["geode_inheritances"]
390+
assert "BRep" in geode_inheritances
391+
# Descendants
392+
assert "StructuralModel" in geode_inheritances
393+
assert "ImplicitStructuralModel" in geode_inheritances
394+
395+
# Test CrossSection
396+
response = client.post(route, json={"geode_object_type": "CrossSection"})
397+
assert response.status_code == 200
398+
geode_inheritances = response.get_json()["geode_inheritances"]
399+
assert "CrossSection" in geode_inheritances
400+
# Parent
401+
assert "Section" in geode_inheritances
402+
# Descendant
403+
assert "ImplicitCrossSection" in geode_inheritances
404+
405+
# Test PolyhedralSolid3D
406+
response = client.post(route, json={"geode_object_type": "PolyhedralSolid3D"})
407+
assert response.status_code == 200
408+
geode_inheritances = response.get_json()["geode_inheritances"]
409+
assert "PolyhedralSolid3D" in geode_inheritances
410+
# Parent
411+
assert "VertexSet" in geode_inheritances
412+
413+
# Test all params
414+
def get_full_data() -> test_utils.JsonData:
415+
return {"geode_object_type": "BRep"}
416+
417+
test_utils.test_route_wrong_params(client, route, get_full_data)

0 commit comments

Comments
 (0)