From 2c344fedd1bd02b3defadaf901b9baee463dc50c Mon Sep 17 00:00:00 2001 From: Arnaud Botella Date: Mon, 20 Oct 2025 16:14:11 +0200 Subject: [PATCH 01/14] wip --- .../routes/create/schemas/create_aoi.py | 107 ++++++++++++++++++ .../routes/create/schemas/create_point.py | 63 +++++++++++ .../routes/models/schemas/mesh_components.py | 41 +++++++ .../models/schemas/vtm_component_indices.py | 41 +++++++ .../routes/schemas/allowed_files.py | 55 +++++++++ .../routes/schemas/allowed_objects.py | 59 ++++++++++ .../geode_objects_and_output_extensions.py | 45 ++++++++ .../schemas/geographic_coordinate_systems.py | 41 +++++++ .../routes/schemas/inspect_file.py | 45 ++++++++ src/opengeodeweb_back/routes/schemas/kill.py | 34 ++++++ .../routes/schemas/missing_files.py | 45 ++++++++ src/opengeodeweb_back/routes/schemas/ping.py | 34 ++++++ .../routes/schemas/polygon_attribute_names.py | 41 +++++++ .../schemas/polyhedron_attribute_names.py | 41 +++++++ .../routes/schemas/save_viewable_file.py | 45 ++++++++ .../routes/schemas/texture_coordinates.py | 41 +++++++ .../routes/schemas/upload_file.py | 56 +++++++++ .../routes/schemas/vertex_attribute_names.py | 41 +++++++ 18 files changed, 875 insertions(+) create mode 100644 src/opengeodeweb_back/routes/create/schemas/create_aoi.py create mode 100644 src/opengeodeweb_back/routes/create/schemas/create_point.py create mode 100644 src/opengeodeweb_back/routes/models/schemas/mesh_components.py create mode 100644 src/opengeodeweb_back/routes/models/schemas/vtm_component_indices.py create mode 100644 src/opengeodeweb_back/routes/schemas/allowed_files.py create mode 100644 src/opengeodeweb_back/routes/schemas/allowed_objects.py create mode 100644 src/opengeodeweb_back/routes/schemas/geode_objects_and_output_extensions.py create mode 100644 src/opengeodeweb_back/routes/schemas/geographic_coordinate_systems.py create mode 100644 src/opengeodeweb_back/routes/schemas/inspect_file.py create mode 100644 src/opengeodeweb_back/routes/schemas/kill.py create mode 100644 src/opengeodeweb_back/routes/schemas/missing_files.py create mode 100644 src/opengeodeweb_back/routes/schemas/ping.py create mode 100644 src/opengeodeweb_back/routes/schemas/polygon_attribute_names.py create mode 100644 src/opengeodeweb_back/routes/schemas/polyhedron_attribute_names.py create mode 100644 src/opengeodeweb_back/routes/schemas/save_viewable_file.py create mode 100644 src/opengeodeweb_back/routes/schemas/texture_coordinates.py create mode 100644 src/opengeodeweb_back/routes/schemas/upload_file.py create mode 100644 src/opengeodeweb_back/routes/schemas/vertex_attribute_names.py diff --git a/src/opengeodeweb_back/routes/create/schemas/create_aoi.py b/src/opengeodeweb_back/routes/create/schemas/create_aoi.py new file mode 100644 index 00000000..18a55e4f --- /dev/null +++ b/src/opengeodeweb_back/routes/create/schemas/create_aoi.py @@ -0,0 +1,107 @@ +# type: ignore +from typing import Any, Optional, List, TypeVar, Callable, Type, cast + + +T = TypeVar("T") + + +def from_float(x: Any) -> float: + assert isinstance(x, (float, int)) and not isinstance(x, bool) + return float(x) + + +def to_float(x: Any) -> float: + assert isinstance(x, (int, float)) + return x + + +def from_str(x: Any) -> str: + assert isinstance(x, str) + return x + + +def from_none(x: Any) -> Any: + assert x is None + return x + + +def from_union(fs, x): + for f in fs: + try: + return f(x) + except: + pass + assert False + + +def from_list(f: Callable[[Any], T], x: Any) -> List[T]: + assert isinstance(x, list) + return [f(y) for y in x] + + +def to_class(c: Type[T], x: Any) -> dict: + assert isinstance(x, c) + return cast(Any, x).to_dict() + + +class Point: + x: float + y: float + + def __init__(self, x: float, y: float) -> None: + self.x = x + self.y = y + + @staticmethod + def from_dict(obj: Any) -> 'Point': + assert isinstance(obj, dict) + x = from_float(obj.get("x")) + y = from_float(obj.get("y")) + return Point(x, y) + + def to_dict(self) -> dict: + result: dict = {} + result["x"] = to_float(self.x) + result["y"] = to_float(self.y) + return result + + +class CreateAoi: + id: Optional[str] + name: str + """Name of the AOI""" + + points: List[Point] + z: float + + def __init__(self, id: Optional[str], name: str, points: List[Point], z: float) -> None: + self.id = id + self.name = name + self.points = points + self.z = z + + @staticmethod + def from_dict(obj: Any) -> 'CreateAoi': + assert isinstance(obj, dict) + id = from_union([from_str, from_none], obj.get("id")) + name = from_str(obj.get("name")) + points = from_list(Point.from_dict, obj.get("points")) + z = from_float(obj.get("z")) + return CreateAoi(id, name, points, z) + + def to_dict(self) -> dict: + result: dict = {} + if self.id is not None: + result["id"] = from_union([from_str, from_none], self.id) + result["name"] = from_str(self.name) + result["points"] = from_list(lambda x: to_class(Point, x), self.points) + result["z"] = to_float(self.z) + return result + + +def create_aoi_from_dict(s: Any) -> CreateAoi: + return CreateAoi.from_dict(s) + + +def create_aoi_to_dict(x: CreateAoi) -> Any: + return to_class(CreateAoi, x) diff --git a/src/opengeodeweb_back/routes/create/schemas/create_point.py b/src/opengeodeweb_back/routes/create/schemas/create_point.py new file mode 100644 index 00000000..ae6f891f --- /dev/null +++ b/src/opengeodeweb_back/routes/create/schemas/create_point.py @@ -0,0 +1,63 @@ +# type: ignore +from typing import Any, TypeVar, Type, cast + + +T = TypeVar("T") + + +def from_str(x: Any) -> str: + assert isinstance(x, str) + return x + + +def from_float(x: Any) -> float: + assert isinstance(x, (float, int)) and not isinstance(x, bool) + return float(x) + + +def to_float(x: Any) -> float: + assert isinstance(x, (int, float)) + return x + + +def to_class(c: Type[T], x: Any) -> dict: + assert isinstance(x, c) + return cast(Any, x).to_dict() + + +class CreatePoint: + name: str + x: float + y: float + z: float + + def __init__(self, name: str, x: float, y: float, z: float) -> None: + self.name = name + self.x = x + self.y = y + self.z = z + + @staticmethod + def from_dict(obj: Any) -> 'CreatePoint': + assert isinstance(obj, dict) + name = from_str(obj.get("name")) + x = from_float(obj.get("x")) + y = from_float(obj.get("y")) + z = from_float(obj.get("z")) + return CreatePoint(name, x, y, z) + + def to_dict(self) -> dict: + result: dict = {} + result["name"] = from_str(self.name) + result["x"] = to_float(self.x) + result["y"] = to_float(self.y) + result["z"] = to_float(self.z) + return result + + +def create_point_from_dict(s: Any) -> CreatePoint: + return CreatePoint.from_dict(s) + + +def create_point_to_dict(x: CreatePoint) -> Any: + return to_class(CreatePoint, x) diff --git a/src/opengeodeweb_back/routes/models/schemas/mesh_components.py b/src/opengeodeweb_back/routes/models/schemas/mesh_components.py new file mode 100644 index 00000000..c82f475b --- /dev/null +++ b/src/opengeodeweb_back/routes/models/schemas/mesh_components.py @@ -0,0 +1,41 @@ +# type: ignore +from typing import Any, TypeVar, Type, cast + + +T = TypeVar("T") + + +def from_str(x: Any) -> str: + assert isinstance(x, str) + return x + + +def to_class(c: Type[T], x: Any) -> dict: + assert isinstance(x, c) + return cast(Any, x).to_dict() + + +class MeshComponents: + id: str + + def __init__(self, id: str) -> None: + self.id = id + + @staticmethod + def from_dict(obj: Any) -> 'MeshComponents': + assert isinstance(obj, dict) + id = from_str(obj.get("id")) + return MeshComponents(id) + + def to_dict(self) -> dict: + result: dict = {} + result["id"] = from_str(self.id) + return result + + +def mesh_components_from_dict(s: Any) -> MeshComponents: + return MeshComponents.from_dict(s) + + +def mesh_components_to_dict(x: MeshComponents) -> Any: + return to_class(MeshComponents, x) diff --git a/src/opengeodeweb_back/routes/models/schemas/vtm_component_indices.py b/src/opengeodeweb_back/routes/models/schemas/vtm_component_indices.py new file mode 100644 index 00000000..ea594bec --- /dev/null +++ b/src/opengeodeweb_back/routes/models/schemas/vtm_component_indices.py @@ -0,0 +1,41 @@ +# type: ignore +from typing import Any, TypeVar, Type, cast + + +T = TypeVar("T") + + +def from_str(x: Any) -> str: + assert isinstance(x, str) + return x + + +def to_class(c: Type[T], x: Any) -> dict: + assert isinstance(x, c) + return cast(Any, x).to_dict() + + +class VtmComponentIndices: + id: str + + def __init__(self, id: str) -> None: + self.id = id + + @staticmethod + def from_dict(obj: Any) -> 'VtmComponentIndices': + assert isinstance(obj, dict) + id = from_str(obj.get("id")) + return VtmComponentIndices(id) + + def to_dict(self) -> dict: + result: dict = {} + result["id"] = from_str(self.id) + return result + + +def vtm_component_indices_from_dict(s: Any) -> VtmComponentIndices: + return VtmComponentIndices.from_dict(s) + + +def vtm_component_indices_to_dict(x: VtmComponentIndices) -> Any: + return to_class(VtmComponentIndices, x) diff --git a/src/opengeodeweb_back/routes/schemas/allowed_files.py b/src/opengeodeweb_back/routes/schemas/allowed_files.py new file mode 100644 index 00000000..244294d2 --- /dev/null +++ b/src/opengeodeweb_back/routes/schemas/allowed_files.py @@ -0,0 +1,55 @@ +# type: ignore +from typing import Optional, Any, TypeVar, Type, cast + + +T = TypeVar("T") + + +def from_none(x: Any) -> Any: + assert x is None + return x + + +def from_str(x: Any) -> str: + assert isinstance(x, str) + return x + + +def from_union(fs, x): + for f in fs: + try: + return f(x) + except: + pass + assert False + + +def to_class(c: Type[T], x: Any) -> dict: + assert isinstance(x, c) + return cast(Any, x).to_dict() + + +class AllowedFiles: + supported_feature: Optional[str] + + def __init__(self, supported_feature: Optional[str]) -> None: + self.supported_feature = supported_feature + + @staticmethod + def from_dict(obj: Any) -> 'AllowedFiles': + assert isinstance(obj, dict) + supported_feature = from_union([from_none, from_str], obj.get("supported_feature")) + return AllowedFiles(supported_feature) + + def to_dict(self) -> dict: + result: dict = {} + result["supported_feature"] = from_union([from_none, from_str], self.supported_feature) + return result + + +def allowed_files_from_dict(s: Any) -> AllowedFiles: + return AllowedFiles.from_dict(s) + + +def allowed_files_to_dict(x: AllowedFiles) -> Any: + return to_class(AllowedFiles, x) diff --git a/src/opengeodeweb_back/routes/schemas/allowed_objects.py b/src/opengeodeweb_back/routes/schemas/allowed_objects.py new file mode 100644 index 00000000..e0ac7916 --- /dev/null +++ b/src/opengeodeweb_back/routes/schemas/allowed_objects.py @@ -0,0 +1,59 @@ +# type: ignore +from typing import Optional, Any, TypeVar, Type, cast + + +T = TypeVar("T") + + +def from_str(x: Any) -> str: + assert isinstance(x, str) + return x + + +def from_none(x: Any) -> Any: + assert x is None + return x + + +def from_union(fs, x): + for f in fs: + try: + return f(x) + except: + pass + assert False + + +def to_class(c: Type[T], x: Any) -> dict: + assert isinstance(x, c) + return cast(Any, x).to_dict() + + +class AllowedObjects: + filename: str + supported_feature: Optional[str] + + def __init__(self, filename: str, supported_feature: Optional[str]) -> None: + self.filename = filename + self.supported_feature = supported_feature + + @staticmethod + def from_dict(obj: Any) -> 'AllowedObjects': + assert isinstance(obj, dict) + filename = from_str(obj.get("filename")) + supported_feature = from_union([from_none, from_str], obj.get("supported_feature")) + return AllowedObjects(filename, supported_feature) + + def to_dict(self) -> dict: + result: dict = {} + result["filename"] = from_str(self.filename) + result["supported_feature"] = from_union([from_none, from_str], self.supported_feature) + return result + + +def allowed_objects_from_dict(s: Any) -> AllowedObjects: + return AllowedObjects.from_dict(s) + + +def allowed_objects_to_dict(x: AllowedObjects) -> Any: + return to_class(AllowedObjects, x) diff --git a/src/opengeodeweb_back/routes/schemas/geode_objects_and_output_extensions.py b/src/opengeodeweb_back/routes/schemas/geode_objects_and_output_extensions.py new file mode 100644 index 00000000..418b0a54 --- /dev/null +++ b/src/opengeodeweb_back/routes/schemas/geode_objects_and_output_extensions.py @@ -0,0 +1,45 @@ +# type: ignore +from typing import Any, TypeVar, Type, cast + + +T = TypeVar("T") + + +def from_str(x: Any) -> str: + assert isinstance(x, str) + return x + + +def to_class(c: Type[T], x: Any) -> dict: + assert isinstance(x, c) + return cast(Any, x).to_dict() + + +class GeodeObjectsAndOutputExtensions: + filename: str + input_geode_object: str + + def __init__(self, filename: str, input_geode_object: str) -> None: + self.filename = filename + self.input_geode_object = input_geode_object + + @staticmethod + def from_dict(obj: Any) -> 'GeodeObjectsAndOutputExtensions': + assert isinstance(obj, dict) + filename = from_str(obj.get("filename")) + input_geode_object = from_str(obj.get("input_geode_object")) + return GeodeObjectsAndOutputExtensions(filename, input_geode_object) + + def to_dict(self) -> dict: + result: dict = {} + result["filename"] = from_str(self.filename) + result["input_geode_object"] = from_str(self.input_geode_object) + return result + + +def geode_objects_and_output_extensions_from_dict(s: Any) -> GeodeObjectsAndOutputExtensions: + return GeodeObjectsAndOutputExtensions.from_dict(s) + + +def geode_objects_and_output_extensions_to_dict(x: GeodeObjectsAndOutputExtensions) -> Any: + return to_class(GeodeObjectsAndOutputExtensions, x) diff --git a/src/opengeodeweb_back/routes/schemas/geographic_coordinate_systems.py b/src/opengeodeweb_back/routes/schemas/geographic_coordinate_systems.py new file mode 100644 index 00000000..99a50bbc --- /dev/null +++ b/src/opengeodeweb_back/routes/schemas/geographic_coordinate_systems.py @@ -0,0 +1,41 @@ +# type: ignore +from typing import Any, TypeVar, Type, cast + + +T = TypeVar("T") + + +def from_str(x: Any) -> str: + assert isinstance(x, str) + return x + + +def to_class(c: Type[T], x: Any) -> dict: + assert isinstance(x, c) + return cast(Any, x).to_dict() + + +class GeographicCoordinateSystems: + input_geode_object: str + + def __init__(self, input_geode_object: str) -> None: + self.input_geode_object = input_geode_object + + @staticmethod + def from_dict(obj: Any) -> 'GeographicCoordinateSystems': + assert isinstance(obj, dict) + input_geode_object = from_str(obj.get("input_geode_object")) + return GeographicCoordinateSystems(input_geode_object) + + def to_dict(self) -> dict: + result: dict = {} + result["input_geode_object"] = from_str(self.input_geode_object) + return result + + +def geographic_coordinate_systems_from_dict(s: Any) -> GeographicCoordinateSystems: + return GeographicCoordinateSystems.from_dict(s) + + +def geographic_coordinate_systems_to_dict(x: GeographicCoordinateSystems) -> Any: + return to_class(GeographicCoordinateSystems, x) diff --git a/src/opengeodeweb_back/routes/schemas/inspect_file.py b/src/opengeodeweb_back/routes/schemas/inspect_file.py new file mode 100644 index 00000000..8a4d62b4 --- /dev/null +++ b/src/opengeodeweb_back/routes/schemas/inspect_file.py @@ -0,0 +1,45 @@ +# type: ignore +from typing import Any, TypeVar, Type, cast + + +T = TypeVar("T") + + +def from_str(x: Any) -> str: + assert isinstance(x, str) + return x + + +def to_class(c: Type[T], x: Any) -> dict: + assert isinstance(x, c) + return cast(Any, x).to_dict() + + +class InspectFile: + filename: str + input_geode_object: str + + def __init__(self, filename: str, input_geode_object: str) -> None: + self.filename = filename + self.input_geode_object = input_geode_object + + @staticmethod + def from_dict(obj: Any) -> 'InspectFile': + assert isinstance(obj, dict) + filename = from_str(obj.get("filename")) + input_geode_object = from_str(obj.get("input_geode_object")) + return InspectFile(filename, input_geode_object) + + def to_dict(self) -> dict: + result: dict = {} + result["filename"] = from_str(self.filename) + result["input_geode_object"] = from_str(self.input_geode_object) + return result + + +def inspect_file_from_dict(s: Any) -> InspectFile: + return InspectFile.from_dict(s) + + +def inspect_file_to_dict(x: InspectFile) -> Any: + return to_class(InspectFile, x) diff --git a/src/opengeodeweb_back/routes/schemas/kill.py b/src/opengeodeweb_back/routes/schemas/kill.py new file mode 100644 index 00000000..06c80da7 --- /dev/null +++ b/src/opengeodeweb_back/routes/schemas/kill.py @@ -0,0 +1,34 @@ +# type: ignore +from typing import Any, TypeVar, Type, cast + + +T = TypeVar("T") + + +def to_class(c: Type[T], x: Any) -> dict: + assert isinstance(x, c) + return cast(Any, x).to_dict() + + +class Kill: + pass + + def __init__(self, ) -> None: + pass + + @staticmethod + def from_dict(obj: Any) -> 'Kill': + assert isinstance(obj, dict) + return Kill() + + def to_dict(self) -> dict: + result: dict = {} + return result + + +def kill_from_dict(s: Any) -> Kill: + return Kill.from_dict(s) + + +def kill_to_dict(x: Kill) -> Any: + return to_class(Kill, x) diff --git a/src/opengeodeweb_back/routes/schemas/missing_files.py b/src/opengeodeweb_back/routes/schemas/missing_files.py new file mode 100644 index 00000000..382c3a01 --- /dev/null +++ b/src/opengeodeweb_back/routes/schemas/missing_files.py @@ -0,0 +1,45 @@ +# type: ignore +from typing import Any, TypeVar, Type, cast + + +T = TypeVar("T") + + +def from_str(x: Any) -> str: + assert isinstance(x, str) + return x + + +def to_class(c: Type[T], x: Any) -> dict: + assert isinstance(x, c) + return cast(Any, x).to_dict() + + +class MissingFiles: + filename: str + input_geode_object: str + + def __init__(self, filename: str, input_geode_object: str) -> None: + self.filename = filename + self.input_geode_object = input_geode_object + + @staticmethod + def from_dict(obj: Any) -> 'MissingFiles': + assert isinstance(obj, dict) + filename = from_str(obj.get("filename")) + input_geode_object = from_str(obj.get("input_geode_object")) + return MissingFiles(filename, input_geode_object) + + def to_dict(self) -> dict: + result: dict = {} + result["filename"] = from_str(self.filename) + result["input_geode_object"] = from_str(self.input_geode_object) + return result + + +def missing_files_from_dict(s: Any) -> MissingFiles: + return MissingFiles.from_dict(s) + + +def missing_files_to_dict(x: MissingFiles) -> Any: + return to_class(MissingFiles, x) diff --git a/src/opengeodeweb_back/routes/schemas/ping.py b/src/opengeodeweb_back/routes/schemas/ping.py new file mode 100644 index 00000000..78a75dd4 --- /dev/null +++ b/src/opengeodeweb_back/routes/schemas/ping.py @@ -0,0 +1,34 @@ +# type: ignore +from typing import Any, TypeVar, Type, cast + + +T = TypeVar("T") + + +def to_class(c: Type[T], x: Any) -> dict: + assert isinstance(x, c) + return cast(Any, x).to_dict() + + +class Ping: + pass + + def __init__(self, ) -> None: + pass + + @staticmethod + def from_dict(obj: Any) -> 'Ping': + assert isinstance(obj, dict) + return Ping() + + def to_dict(self) -> dict: + result: dict = {} + return result + + +def ping_from_dict(s: Any) -> Ping: + return Ping.from_dict(s) + + +def ping_to_dict(x: Ping) -> Any: + return to_class(Ping, x) diff --git a/src/opengeodeweb_back/routes/schemas/polygon_attribute_names.py b/src/opengeodeweb_back/routes/schemas/polygon_attribute_names.py new file mode 100644 index 00000000..6cef2921 --- /dev/null +++ b/src/opengeodeweb_back/routes/schemas/polygon_attribute_names.py @@ -0,0 +1,41 @@ +# type: ignore +from typing import Any, TypeVar, Type, cast + + +T = TypeVar("T") + + +def from_str(x: Any) -> str: + assert isinstance(x, str) + return x + + +def to_class(c: Type[T], x: Any) -> dict: + assert isinstance(x, c) + return cast(Any, x).to_dict() + + +class PolygonAttributeNames: + id: str + + def __init__(self, id: str) -> None: + self.id = id + + @staticmethod + def from_dict(obj: Any) -> 'PolygonAttributeNames': + assert isinstance(obj, dict) + id = from_str(obj.get("id")) + return PolygonAttributeNames(id) + + def to_dict(self) -> dict: + result: dict = {} + result["id"] = from_str(self.id) + return result + + +def polygon_attribute_names_from_dict(s: Any) -> PolygonAttributeNames: + return PolygonAttributeNames.from_dict(s) + + +def polygon_attribute_names_to_dict(x: PolygonAttributeNames) -> Any: + return to_class(PolygonAttributeNames, x) diff --git a/src/opengeodeweb_back/routes/schemas/polyhedron_attribute_names.py b/src/opengeodeweb_back/routes/schemas/polyhedron_attribute_names.py new file mode 100644 index 00000000..d15ab524 --- /dev/null +++ b/src/opengeodeweb_back/routes/schemas/polyhedron_attribute_names.py @@ -0,0 +1,41 @@ +# type: ignore +from typing import Any, TypeVar, Type, cast + + +T = TypeVar("T") + + +def from_str(x: Any) -> str: + assert isinstance(x, str) + return x + + +def to_class(c: Type[T], x: Any) -> dict: + assert isinstance(x, c) + return cast(Any, x).to_dict() + + +class PolyhedronAttributeNames: + id: str + + def __init__(self, id: str) -> None: + self.id = id + + @staticmethod + def from_dict(obj: Any) -> 'PolyhedronAttributeNames': + assert isinstance(obj, dict) + id = from_str(obj.get("id")) + return PolyhedronAttributeNames(id) + + def to_dict(self) -> dict: + result: dict = {} + result["id"] = from_str(self.id) + return result + + +def polyhedron_attribute_names_from_dict(s: Any) -> PolyhedronAttributeNames: + return PolyhedronAttributeNames.from_dict(s) + + +def polyhedron_attribute_names_to_dict(x: PolyhedronAttributeNames) -> Any: + return to_class(PolyhedronAttributeNames, x) diff --git a/src/opengeodeweb_back/routes/schemas/save_viewable_file.py b/src/opengeodeweb_back/routes/schemas/save_viewable_file.py new file mode 100644 index 00000000..cab4c3e5 --- /dev/null +++ b/src/opengeodeweb_back/routes/schemas/save_viewable_file.py @@ -0,0 +1,45 @@ +# type: ignore +from typing import Any, TypeVar, Type, cast + + +T = TypeVar("T") + + +def from_str(x: Any) -> str: + assert isinstance(x, str) + return x + + +def to_class(c: Type[T], x: Any) -> dict: + assert isinstance(x, c) + return cast(Any, x).to_dict() + + +class SaveViewableFile: + filename: str + input_geode_object: str + + def __init__(self, filename: str, input_geode_object: str) -> None: + self.filename = filename + self.input_geode_object = input_geode_object + + @staticmethod + def from_dict(obj: Any) -> 'SaveViewableFile': + assert isinstance(obj, dict) + filename = from_str(obj.get("filename")) + input_geode_object = from_str(obj.get("input_geode_object")) + return SaveViewableFile(filename, input_geode_object) + + def to_dict(self) -> dict: + result: dict = {} + result["filename"] = from_str(self.filename) + result["input_geode_object"] = from_str(self.input_geode_object) + return result + + +def save_viewable_file_from_dict(s: Any) -> SaveViewableFile: + return SaveViewableFile.from_dict(s) + + +def save_viewable_file_to_dict(x: SaveViewableFile) -> Any: + return to_class(SaveViewableFile, x) diff --git a/src/opengeodeweb_back/routes/schemas/texture_coordinates.py b/src/opengeodeweb_back/routes/schemas/texture_coordinates.py new file mode 100644 index 00000000..d994bfe0 --- /dev/null +++ b/src/opengeodeweb_back/routes/schemas/texture_coordinates.py @@ -0,0 +1,41 @@ +# type: ignore +from typing import Any, TypeVar, Type, cast + + +T = TypeVar("T") + + +def from_str(x: Any) -> str: + assert isinstance(x, str) + return x + + +def to_class(c: Type[T], x: Any) -> dict: + assert isinstance(x, c) + return cast(Any, x).to_dict() + + +class TextureCoordinates: + id: str + + def __init__(self, id: str) -> None: + self.id = id + + @staticmethod + def from_dict(obj: Any) -> 'TextureCoordinates': + assert isinstance(obj, dict) + id = from_str(obj.get("id")) + return TextureCoordinates(id) + + def to_dict(self) -> dict: + result: dict = {} + result["id"] = from_str(self.id) + return result + + +def texture_coordinates_from_dict(s: Any) -> TextureCoordinates: + return TextureCoordinates.from_dict(s) + + +def texture_coordinates_to_dict(x: TextureCoordinates) -> Any: + return to_class(TextureCoordinates, x) diff --git a/src/opengeodeweb_back/routes/schemas/upload_file.py b/src/opengeodeweb_back/routes/schemas/upload_file.py new file mode 100644 index 00000000..2e1b832e --- /dev/null +++ b/src/opengeodeweb_back/routes/schemas/upload_file.py @@ -0,0 +1,56 @@ +# type: ignore +from typing import Optional, Any, TypeVar, Type, cast + + +T = TypeVar("T") + + +def from_str(x: Any) -> str: + assert isinstance(x, str) + return x + + +def from_none(x: Any) -> Any: + assert x is None + return x + + +def from_union(fs, x): + for f in fs: + try: + return f(x) + except: + pass + assert False + + +def to_class(c: Type[T], x: Any) -> dict: + assert isinstance(x, c) + return cast(Any, x).to_dict() + + +class UploadFile: + filename: Optional[str] + + def __init__(self, filename: Optional[str]) -> None: + self.filename = filename + + @staticmethod + def from_dict(obj: Any) -> 'UploadFile': + assert isinstance(obj, dict) + filename = from_union([from_str, from_none], obj.get("filename")) + return UploadFile(filename) + + def to_dict(self) -> dict: + result: dict = {} + if self.filename is not None: + result["filename"] = from_union([from_str, from_none], self.filename) + return result + + +def upload_file_from_dict(s: Any) -> UploadFile: + return UploadFile.from_dict(s) + + +def upload_file_to_dict(x: UploadFile) -> Any: + return to_class(UploadFile, x) diff --git a/src/opengeodeweb_back/routes/schemas/vertex_attribute_names.py b/src/opengeodeweb_back/routes/schemas/vertex_attribute_names.py new file mode 100644 index 00000000..8b9e23c9 --- /dev/null +++ b/src/opengeodeweb_back/routes/schemas/vertex_attribute_names.py @@ -0,0 +1,41 @@ +# type: ignore +from typing import Any, TypeVar, Type, cast + + +T = TypeVar("T") + + +def from_str(x: Any) -> str: + assert isinstance(x, str) + return x + + +def to_class(c: Type[T], x: Any) -> dict: + assert isinstance(x, c) + return cast(Any, x).to_dict() + + +class VertexAttributeNames: + id: str + + def __init__(self, id: str) -> None: + self.id = id + + @staticmethod + def from_dict(obj: Any) -> 'VertexAttributeNames': + assert isinstance(obj, dict) + id = from_str(obj.get("id")) + return VertexAttributeNames(id) + + def to_dict(self) -> dict: + result: dict = {} + result["id"] = from_str(self.id) + return result + + +def vertex_attribute_names_from_dict(s: Any) -> VertexAttributeNames: + return VertexAttributeNames.from_dict(s) + + +def vertex_attribute_names_to_dict(x: VertexAttributeNames) -> Any: + return to_class(VertexAttributeNames, x) From 1810fc37f321e6b6645a003a1b75d131fb3c661c Mon Sep 17 00:00:00 2001 From: BotellaA <3213882+BotellaA@users.noreply.github.com> Date: Mon, 20 Oct 2025 14:15:45 +0000 Subject: [PATCH 02/14] Apply prepare changes --- requirements.txt | 1 - .../routes/create/schemas/create_aoi.py | 8 +++++--- .../routes/create/schemas/create_point.py | 2 +- .../routes/models/schemas/mesh_components.py | 2 +- .../routes/models/schemas/vtm_component_indices.py | 2 +- src/opengeodeweb_back/routes/schemas/allowed_files.py | 10 +++++++--- .../routes/schemas/allowed_objects.py | 10 +++++++--- .../schemas/geode_objects_and_output_extensions.py | 10 +++++++--- .../routes/schemas/geographic_coordinate_systems.py | 2 +- src/opengeodeweb_back/routes/schemas/inspect_file.py | 2 +- src/opengeodeweb_back/routes/schemas/kill.py | 6 ++++-- src/opengeodeweb_back/routes/schemas/missing_files.py | 2 +- src/opengeodeweb_back/routes/schemas/ping.py | 6 ++++-- .../routes/schemas/polygon_attribute_names.py | 2 +- .../routes/schemas/polyhedron_attribute_names.py | 2 +- .../routes/schemas/save_viewable_file.py | 2 +- .../routes/schemas/texture_coordinates.py | 2 +- src/opengeodeweb_back/routes/schemas/upload_file.py | 2 +- .../routes/schemas/vertex_attribute_names.py | 2 +- 19 files changed, 46 insertions(+), 29 deletions(-) diff --git a/requirements.txt b/requirements.txt index 09877b29..4e85944d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -60,4 +60,3 @@ werkzeug==3.1.2 # flask # flask-cors -opengeodeweb-microservice==1.*,>=1.0.5 diff --git a/src/opengeodeweb_back/routes/create/schemas/create_aoi.py b/src/opengeodeweb_back/routes/create/schemas/create_aoi.py index 18a55e4f..439b09f2 100644 --- a/src/opengeodeweb_back/routes/create/schemas/create_aoi.py +++ b/src/opengeodeweb_back/routes/create/schemas/create_aoi.py @@ -53,7 +53,7 @@ def __init__(self, x: float, y: float) -> None: self.y = y @staticmethod - def from_dict(obj: Any) -> 'Point': + def from_dict(obj: Any) -> "Point": assert isinstance(obj, dict) x = from_float(obj.get("x")) y = from_float(obj.get("y")) @@ -74,14 +74,16 @@ class CreateAoi: points: List[Point] z: float - def __init__(self, id: Optional[str], name: str, points: List[Point], z: float) -> None: + def __init__( + self, id: Optional[str], name: str, points: List[Point], z: float + ) -> None: self.id = id self.name = name self.points = points self.z = z @staticmethod - def from_dict(obj: Any) -> 'CreateAoi': + def from_dict(obj: Any) -> "CreateAoi": assert isinstance(obj, dict) id = from_union([from_str, from_none], obj.get("id")) name = from_str(obj.get("name")) diff --git a/src/opengeodeweb_back/routes/create/schemas/create_point.py b/src/opengeodeweb_back/routes/create/schemas/create_point.py index ae6f891f..76347712 100644 --- a/src/opengeodeweb_back/routes/create/schemas/create_point.py +++ b/src/opengeodeweb_back/routes/create/schemas/create_point.py @@ -38,7 +38,7 @@ def __init__(self, name: str, x: float, y: float, z: float) -> None: self.z = z @staticmethod - def from_dict(obj: Any) -> 'CreatePoint': + def from_dict(obj: Any) -> "CreatePoint": assert isinstance(obj, dict) name = from_str(obj.get("name")) x = from_float(obj.get("x")) diff --git a/src/opengeodeweb_back/routes/models/schemas/mesh_components.py b/src/opengeodeweb_back/routes/models/schemas/mesh_components.py index c82f475b..14971c2c 100644 --- a/src/opengeodeweb_back/routes/models/schemas/mesh_components.py +++ b/src/opengeodeweb_back/routes/models/schemas/mesh_components.py @@ -22,7 +22,7 @@ def __init__(self, id: str) -> None: self.id = id @staticmethod - def from_dict(obj: Any) -> 'MeshComponents': + def from_dict(obj: Any) -> "MeshComponents": assert isinstance(obj, dict) id = from_str(obj.get("id")) return MeshComponents(id) diff --git a/src/opengeodeweb_back/routes/models/schemas/vtm_component_indices.py b/src/opengeodeweb_back/routes/models/schemas/vtm_component_indices.py index ea594bec..62c0d8eb 100644 --- a/src/opengeodeweb_back/routes/models/schemas/vtm_component_indices.py +++ b/src/opengeodeweb_back/routes/models/schemas/vtm_component_indices.py @@ -22,7 +22,7 @@ def __init__(self, id: str) -> None: self.id = id @staticmethod - def from_dict(obj: Any) -> 'VtmComponentIndices': + def from_dict(obj: Any) -> "VtmComponentIndices": assert isinstance(obj, dict) id = from_str(obj.get("id")) return VtmComponentIndices(id) diff --git a/src/opengeodeweb_back/routes/schemas/allowed_files.py b/src/opengeodeweb_back/routes/schemas/allowed_files.py index 244294d2..93fc8369 100644 --- a/src/opengeodeweb_back/routes/schemas/allowed_files.py +++ b/src/opengeodeweb_back/routes/schemas/allowed_files.py @@ -36,14 +36,18 @@ def __init__(self, supported_feature: Optional[str]) -> None: self.supported_feature = supported_feature @staticmethod - def from_dict(obj: Any) -> 'AllowedFiles': + def from_dict(obj: Any) -> "AllowedFiles": assert isinstance(obj, dict) - supported_feature = from_union([from_none, from_str], obj.get("supported_feature")) + supported_feature = from_union( + [from_none, from_str], obj.get("supported_feature") + ) return AllowedFiles(supported_feature) def to_dict(self) -> dict: result: dict = {} - result["supported_feature"] = from_union([from_none, from_str], self.supported_feature) + result["supported_feature"] = from_union( + [from_none, from_str], self.supported_feature + ) return result diff --git a/src/opengeodeweb_back/routes/schemas/allowed_objects.py b/src/opengeodeweb_back/routes/schemas/allowed_objects.py index e0ac7916..0d24194a 100644 --- a/src/opengeodeweb_back/routes/schemas/allowed_objects.py +++ b/src/opengeodeweb_back/routes/schemas/allowed_objects.py @@ -38,16 +38,20 @@ def __init__(self, filename: str, supported_feature: Optional[str]) -> None: self.supported_feature = supported_feature @staticmethod - def from_dict(obj: Any) -> 'AllowedObjects': + def from_dict(obj: Any) -> "AllowedObjects": assert isinstance(obj, dict) filename = from_str(obj.get("filename")) - supported_feature = from_union([from_none, from_str], obj.get("supported_feature")) + supported_feature = from_union( + [from_none, from_str], obj.get("supported_feature") + ) return AllowedObjects(filename, supported_feature) def to_dict(self) -> dict: result: dict = {} result["filename"] = from_str(self.filename) - result["supported_feature"] = from_union([from_none, from_str], self.supported_feature) + result["supported_feature"] = from_union( + [from_none, from_str], self.supported_feature + ) return result diff --git a/src/opengeodeweb_back/routes/schemas/geode_objects_and_output_extensions.py b/src/opengeodeweb_back/routes/schemas/geode_objects_and_output_extensions.py index 418b0a54..7ef7f617 100644 --- a/src/opengeodeweb_back/routes/schemas/geode_objects_and_output_extensions.py +++ b/src/opengeodeweb_back/routes/schemas/geode_objects_and_output_extensions.py @@ -24,7 +24,7 @@ def __init__(self, filename: str, input_geode_object: str) -> None: self.input_geode_object = input_geode_object @staticmethod - def from_dict(obj: Any) -> 'GeodeObjectsAndOutputExtensions': + def from_dict(obj: Any) -> "GeodeObjectsAndOutputExtensions": assert isinstance(obj, dict) filename = from_str(obj.get("filename")) input_geode_object = from_str(obj.get("input_geode_object")) @@ -37,9 +37,13 @@ def to_dict(self) -> dict: return result -def geode_objects_and_output_extensions_from_dict(s: Any) -> GeodeObjectsAndOutputExtensions: +def geode_objects_and_output_extensions_from_dict( + s: Any, +) -> GeodeObjectsAndOutputExtensions: return GeodeObjectsAndOutputExtensions.from_dict(s) -def geode_objects_and_output_extensions_to_dict(x: GeodeObjectsAndOutputExtensions) -> Any: +def geode_objects_and_output_extensions_to_dict( + x: GeodeObjectsAndOutputExtensions, +) -> Any: return to_class(GeodeObjectsAndOutputExtensions, x) diff --git a/src/opengeodeweb_back/routes/schemas/geographic_coordinate_systems.py b/src/opengeodeweb_back/routes/schemas/geographic_coordinate_systems.py index 99a50bbc..1d3563f8 100644 --- a/src/opengeodeweb_back/routes/schemas/geographic_coordinate_systems.py +++ b/src/opengeodeweb_back/routes/schemas/geographic_coordinate_systems.py @@ -22,7 +22,7 @@ def __init__(self, input_geode_object: str) -> None: self.input_geode_object = input_geode_object @staticmethod - def from_dict(obj: Any) -> 'GeographicCoordinateSystems': + def from_dict(obj: Any) -> "GeographicCoordinateSystems": assert isinstance(obj, dict) input_geode_object = from_str(obj.get("input_geode_object")) return GeographicCoordinateSystems(input_geode_object) diff --git a/src/opengeodeweb_back/routes/schemas/inspect_file.py b/src/opengeodeweb_back/routes/schemas/inspect_file.py index 8a4d62b4..c9b30579 100644 --- a/src/opengeodeweb_back/routes/schemas/inspect_file.py +++ b/src/opengeodeweb_back/routes/schemas/inspect_file.py @@ -24,7 +24,7 @@ def __init__(self, filename: str, input_geode_object: str) -> None: self.input_geode_object = input_geode_object @staticmethod - def from_dict(obj: Any) -> 'InspectFile': + def from_dict(obj: Any) -> "InspectFile": assert isinstance(obj, dict) filename = from_str(obj.get("filename")) input_geode_object = from_str(obj.get("input_geode_object")) diff --git a/src/opengeodeweb_back/routes/schemas/kill.py b/src/opengeodeweb_back/routes/schemas/kill.py index 06c80da7..96ada023 100644 --- a/src/opengeodeweb_back/routes/schemas/kill.py +++ b/src/opengeodeweb_back/routes/schemas/kill.py @@ -13,11 +13,13 @@ def to_class(c: Type[T], x: Any) -> dict: class Kill: pass - def __init__(self, ) -> None: + def __init__( + self, + ) -> None: pass @staticmethod - def from_dict(obj: Any) -> 'Kill': + def from_dict(obj: Any) -> "Kill": assert isinstance(obj, dict) return Kill() diff --git a/src/opengeodeweb_back/routes/schemas/missing_files.py b/src/opengeodeweb_back/routes/schemas/missing_files.py index 382c3a01..c93b2a64 100644 --- a/src/opengeodeweb_back/routes/schemas/missing_files.py +++ b/src/opengeodeweb_back/routes/schemas/missing_files.py @@ -24,7 +24,7 @@ def __init__(self, filename: str, input_geode_object: str) -> None: self.input_geode_object = input_geode_object @staticmethod - def from_dict(obj: Any) -> 'MissingFiles': + def from_dict(obj: Any) -> "MissingFiles": assert isinstance(obj, dict) filename = from_str(obj.get("filename")) input_geode_object = from_str(obj.get("input_geode_object")) diff --git a/src/opengeodeweb_back/routes/schemas/ping.py b/src/opengeodeweb_back/routes/schemas/ping.py index 78a75dd4..9916d92c 100644 --- a/src/opengeodeweb_back/routes/schemas/ping.py +++ b/src/opengeodeweb_back/routes/schemas/ping.py @@ -13,11 +13,13 @@ def to_class(c: Type[T], x: Any) -> dict: class Ping: pass - def __init__(self, ) -> None: + def __init__( + self, + ) -> None: pass @staticmethod - def from_dict(obj: Any) -> 'Ping': + def from_dict(obj: Any) -> "Ping": assert isinstance(obj, dict) return Ping() diff --git a/src/opengeodeweb_back/routes/schemas/polygon_attribute_names.py b/src/opengeodeweb_back/routes/schemas/polygon_attribute_names.py index 6cef2921..80778d3d 100644 --- a/src/opengeodeweb_back/routes/schemas/polygon_attribute_names.py +++ b/src/opengeodeweb_back/routes/schemas/polygon_attribute_names.py @@ -22,7 +22,7 @@ def __init__(self, id: str) -> None: self.id = id @staticmethod - def from_dict(obj: Any) -> 'PolygonAttributeNames': + def from_dict(obj: Any) -> "PolygonAttributeNames": assert isinstance(obj, dict) id = from_str(obj.get("id")) return PolygonAttributeNames(id) diff --git a/src/opengeodeweb_back/routes/schemas/polyhedron_attribute_names.py b/src/opengeodeweb_back/routes/schemas/polyhedron_attribute_names.py index d15ab524..f60215fb 100644 --- a/src/opengeodeweb_back/routes/schemas/polyhedron_attribute_names.py +++ b/src/opengeodeweb_back/routes/schemas/polyhedron_attribute_names.py @@ -22,7 +22,7 @@ def __init__(self, id: str) -> None: self.id = id @staticmethod - def from_dict(obj: Any) -> 'PolyhedronAttributeNames': + def from_dict(obj: Any) -> "PolyhedronAttributeNames": assert isinstance(obj, dict) id = from_str(obj.get("id")) return PolyhedronAttributeNames(id) diff --git a/src/opengeodeweb_back/routes/schemas/save_viewable_file.py b/src/opengeodeweb_back/routes/schemas/save_viewable_file.py index cab4c3e5..a33a00fb 100644 --- a/src/opengeodeweb_back/routes/schemas/save_viewable_file.py +++ b/src/opengeodeweb_back/routes/schemas/save_viewable_file.py @@ -24,7 +24,7 @@ def __init__(self, filename: str, input_geode_object: str) -> None: self.input_geode_object = input_geode_object @staticmethod - def from_dict(obj: Any) -> 'SaveViewableFile': + def from_dict(obj: Any) -> "SaveViewableFile": assert isinstance(obj, dict) filename = from_str(obj.get("filename")) input_geode_object = from_str(obj.get("input_geode_object")) diff --git a/src/opengeodeweb_back/routes/schemas/texture_coordinates.py b/src/opengeodeweb_back/routes/schemas/texture_coordinates.py index d994bfe0..5aa9fb66 100644 --- a/src/opengeodeweb_back/routes/schemas/texture_coordinates.py +++ b/src/opengeodeweb_back/routes/schemas/texture_coordinates.py @@ -22,7 +22,7 @@ def __init__(self, id: str) -> None: self.id = id @staticmethod - def from_dict(obj: Any) -> 'TextureCoordinates': + def from_dict(obj: Any) -> "TextureCoordinates": assert isinstance(obj, dict) id = from_str(obj.get("id")) return TextureCoordinates(id) diff --git a/src/opengeodeweb_back/routes/schemas/upload_file.py b/src/opengeodeweb_back/routes/schemas/upload_file.py index 2e1b832e..384da7cf 100644 --- a/src/opengeodeweb_back/routes/schemas/upload_file.py +++ b/src/opengeodeweb_back/routes/schemas/upload_file.py @@ -36,7 +36,7 @@ def __init__(self, filename: Optional[str]) -> None: self.filename = filename @staticmethod - def from_dict(obj: Any) -> 'UploadFile': + def from_dict(obj: Any) -> "UploadFile": assert isinstance(obj, dict) filename = from_union([from_str, from_none], obj.get("filename")) return UploadFile(filename) diff --git a/src/opengeodeweb_back/routes/schemas/vertex_attribute_names.py b/src/opengeodeweb_back/routes/schemas/vertex_attribute_names.py index 8b9e23c9..bbc873a6 100644 --- a/src/opengeodeweb_back/routes/schemas/vertex_attribute_names.py +++ b/src/opengeodeweb_back/routes/schemas/vertex_attribute_names.py @@ -22,7 +22,7 @@ def __init__(self, id: str) -> None: self.id = id @staticmethod - def from_dict(obj: Any) -> 'VertexAttributeNames': + def from_dict(obj: Any) -> "VertexAttributeNames": assert isinstance(obj, dict) id = from_str(obj.get("id")) return VertexAttributeNames(id) From 2b0a9837a40b22222508b8cd9347b57dfafa841d Mon Sep 17 00:00:00 2001 From: Arnaud Botella Date: Mon, 20 Oct 2025 16:46:36 +0200 Subject: [PATCH 03/14] test create --- .../routes/create/blueprint_create.py | 49 +++++-------------- 1 file changed, 11 insertions(+), 38 deletions(-) diff --git a/src/opengeodeweb_back/routes/create/blueprint_create.py b/src/opengeodeweb_back/routes/create/blueprint_create.py index bf5964da..cb1bb6c2 100644 --- a/src/opengeodeweb_back/routes/create/blueprint_create.py +++ b/src/opengeodeweb_back/routes/create/blueprint_create.py @@ -9,6 +9,8 @@ # Local application imports from opengeodeweb_back import geode_functions, utils_functions +from .schemas.create_aoi import CreateAoi +from .schemas.create_point import CreatePoint routes = flask.Blueprint("create", __name__, url_prefix="/create") schemas = os.path.join(os.path.dirname(__file__), "schemas") @@ -17,24 +19,6 @@ type SchemaDict = dict[str, Any] -class PointDict(TypedDict): - x: float - y: float - - -class CreatePointParams(TypedDict): - name: str - x: float - y: float - z: float - - -class CreateAOIParams(TypedDict): - name: str - points: list[PointDict] - z: float - - # Load schemas with open(os.path.join(schemas, "create_point.json"), "r") as file: create_point_json: SchemaDict = json.load(file) @@ -45,27 +29,20 @@ def create_point() -> flask.Response: """Endpoint to create a single point in 3D space.""" print(f"create_point : {flask.request=}", flush=True) utils_functions.validate_request(flask.request, create_point_json) - - # Extract and validate data from request - params: CreatePointParams = flask.request.get_json() - name = params["name"] - x = params["x"] - y = params["y"] - z = params["z"] + params = CreatePoint.from_dict(flask.request.get_json()) # Create the point class_ = geode_functions.geode_object_class("PointSet3D") pointset = class_.create() builder = geode_functions.create_builder("PointSet3D", pointset) - builder.set_name(name) - builder.create_point(opengeode.Point3D([x, y, z])) + builder.set_name(params.name) + builder.create_point(opengeode.Point3D([params.x, params.y, params.z])) # Save and get info result = utils_functions.generate_native_viewable_and_light_viewable_from_object( geode_object="PointSet3D", data=pointset, ) - result["name"] = name return flask.make_response(result, 200) @@ -79,23 +56,20 @@ def create_aoi() -> flask.Response: """Endpoint to create an Area of Interest (AOI) as an EdgedCurve3D.""" print(f"create_aoi : {flask.request=}", flush=True) utils_functions.validate_request(flask.request, create_aoi_json) - - # Extract and validate data from request - params: CreateAOIParams = flask.request.get_json() - name = params["name"] - points = params["points"] - z = params["z"] + params = CreateAoi.from_dict(flask.request.get_json()) # Create the edged curve class_ = geode_functions.geode_object_class("EdgedCurve3D") edged_curve = class_.create() builder = geode_functions.create_builder("EdgedCurve3D", edged_curve) - builder.set_name(name) + builder.set_name(params.name) # Create vertices first vertex_indices: list[int] = [] - for point in points: - vertex_id = builder.create_point(opengeode.Point3D([point["x"], point["y"], z])) + for point in params.points: + vertex_id = builder.create_point( + opengeode.Point3D([point["x"], point["y"], params.z]) + ) vertex_indices.append(vertex_id) # Create edges between consecutive vertices and close the loop @@ -113,5 +87,4 @@ def create_aoi() -> flask.Response: geode_object="EdgedCurve3D", data=edged_curve, ) - result["name"] = name return flask.make_response(result, 200) From e51cdc2c63b62b57ab7173fcf4854162a92a8c18 Mon Sep 17 00:00:00 2001 From: Arnaud Botella Date: Mon, 20 Oct 2025 17:05:07 +0200 Subject: [PATCH 04/14] test --- .../routes/create/blueprint_create.py | 4 ++-- .../routes/create/schemas/create_aoi.py | 1 - .../routes/create/schemas/create_point.py | 2 +- .../routes/models/schemas/mesh_components.py | 2 +- .../routes/models/schemas/vtm_component_indices.py | 2 +- src/opengeodeweb_back/routes/schemas/allowed_files.py | 10 +++------- .../routes/schemas/allowed_objects.py | 10 +++------- .../schemas/geode_objects_and_output_extensions.py | 10 +++------- .../routes/schemas/geographic_coordinate_systems.py | 2 +- src/opengeodeweb_back/routes/schemas/inspect_file.py | 2 +- src/opengeodeweb_back/routes/schemas/kill.py | 6 ++---- src/opengeodeweb_back/routes/schemas/missing_files.py | 2 +- src/opengeodeweb_back/routes/schemas/ping.py | 6 ++---- .../routes/schemas/polygon_attribute_names.py | 2 +- .../routes/schemas/polyhedron_attribute_names.py | 2 +- .../routes/schemas/save_viewable_file.py | 2 +- .../routes/schemas/texture_coordinates.py | 2 +- src/opengeodeweb_back/routes/schemas/upload_file.py | 2 +- .../routes/schemas/vertex_attribute_names.py | 2 +- 19 files changed, 27 insertions(+), 44 deletions(-) diff --git a/src/opengeodeweb_back/routes/create/blueprint_create.py b/src/opengeodeweb_back/routes/create/blueprint_create.py index cb1bb6c2..c4becdf8 100644 --- a/src/opengeodeweb_back/routes/create/blueprint_create.py +++ b/src/opengeodeweb_back/routes/create/blueprint_create.py @@ -9,8 +9,8 @@ # Local application imports from opengeodeweb_back import geode_functions, utils_functions -from .schemas.create_aoi import CreateAoi -from .schemas.create_point import CreatePoint +from opengeodeweb_back.routes.create.schemas.create_aoi import CreateAoi +from opengeodeweb_back.routes.create.schemas.create_point import CreatePoint routes = flask.Blueprint("create", __name__, url_prefix="/create") schemas = os.path.join(os.path.dirname(__file__), "schemas") diff --git a/src/opengeodeweb_back/routes/create/schemas/create_aoi.py b/src/opengeodeweb_back/routes/create/schemas/create_aoi.py index 439b09f2..b61729d7 100644 --- a/src/opengeodeweb_back/routes/create/schemas/create_aoi.py +++ b/src/opengeodeweb_back/routes/create/schemas/create_aoi.py @@ -1,4 +1,3 @@ -# type: ignore from typing import Any, Optional, List, TypeVar, Callable, Type, cast diff --git a/src/opengeodeweb_back/routes/create/schemas/create_point.py b/src/opengeodeweb_back/routes/create/schemas/create_point.py index 76347712..ae6f891f 100644 --- a/src/opengeodeweb_back/routes/create/schemas/create_point.py +++ b/src/opengeodeweb_back/routes/create/schemas/create_point.py @@ -38,7 +38,7 @@ def __init__(self, name: str, x: float, y: float, z: float) -> None: self.z = z @staticmethod - def from_dict(obj: Any) -> "CreatePoint": + def from_dict(obj: Any) -> 'CreatePoint': assert isinstance(obj, dict) name = from_str(obj.get("name")) x = from_float(obj.get("x")) diff --git a/src/opengeodeweb_back/routes/models/schemas/mesh_components.py b/src/opengeodeweb_back/routes/models/schemas/mesh_components.py index 14971c2c..c82f475b 100644 --- a/src/opengeodeweb_back/routes/models/schemas/mesh_components.py +++ b/src/opengeodeweb_back/routes/models/schemas/mesh_components.py @@ -22,7 +22,7 @@ def __init__(self, id: str) -> None: self.id = id @staticmethod - def from_dict(obj: Any) -> "MeshComponents": + def from_dict(obj: Any) -> 'MeshComponents': assert isinstance(obj, dict) id = from_str(obj.get("id")) return MeshComponents(id) diff --git a/src/opengeodeweb_back/routes/models/schemas/vtm_component_indices.py b/src/opengeodeweb_back/routes/models/schemas/vtm_component_indices.py index 62c0d8eb..ea594bec 100644 --- a/src/opengeodeweb_back/routes/models/schemas/vtm_component_indices.py +++ b/src/opengeodeweb_back/routes/models/schemas/vtm_component_indices.py @@ -22,7 +22,7 @@ def __init__(self, id: str) -> None: self.id = id @staticmethod - def from_dict(obj: Any) -> "VtmComponentIndices": + def from_dict(obj: Any) -> 'VtmComponentIndices': assert isinstance(obj, dict) id = from_str(obj.get("id")) return VtmComponentIndices(id) diff --git a/src/opengeodeweb_back/routes/schemas/allowed_files.py b/src/opengeodeweb_back/routes/schemas/allowed_files.py index 93fc8369..244294d2 100644 --- a/src/opengeodeweb_back/routes/schemas/allowed_files.py +++ b/src/opengeodeweb_back/routes/schemas/allowed_files.py @@ -36,18 +36,14 @@ def __init__(self, supported_feature: Optional[str]) -> None: self.supported_feature = supported_feature @staticmethod - def from_dict(obj: Any) -> "AllowedFiles": + def from_dict(obj: Any) -> 'AllowedFiles': assert isinstance(obj, dict) - supported_feature = from_union( - [from_none, from_str], obj.get("supported_feature") - ) + supported_feature = from_union([from_none, from_str], obj.get("supported_feature")) return AllowedFiles(supported_feature) def to_dict(self) -> dict: result: dict = {} - result["supported_feature"] = from_union( - [from_none, from_str], self.supported_feature - ) + result["supported_feature"] = from_union([from_none, from_str], self.supported_feature) return result diff --git a/src/opengeodeweb_back/routes/schemas/allowed_objects.py b/src/opengeodeweb_back/routes/schemas/allowed_objects.py index 0d24194a..e0ac7916 100644 --- a/src/opengeodeweb_back/routes/schemas/allowed_objects.py +++ b/src/opengeodeweb_back/routes/schemas/allowed_objects.py @@ -38,20 +38,16 @@ def __init__(self, filename: str, supported_feature: Optional[str]) -> None: self.supported_feature = supported_feature @staticmethod - def from_dict(obj: Any) -> "AllowedObjects": + def from_dict(obj: Any) -> 'AllowedObjects': assert isinstance(obj, dict) filename = from_str(obj.get("filename")) - supported_feature = from_union( - [from_none, from_str], obj.get("supported_feature") - ) + supported_feature = from_union([from_none, from_str], obj.get("supported_feature")) return AllowedObjects(filename, supported_feature) def to_dict(self) -> dict: result: dict = {} result["filename"] = from_str(self.filename) - result["supported_feature"] = from_union( - [from_none, from_str], self.supported_feature - ) + result["supported_feature"] = from_union([from_none, from_str], self.supported_feature) return result diff --git a/src/opengeodeweb_back/routes/schemas/geode_objects_and_output_extensions.py b/src/opengeodeweb_back/routes/schemas/geode_objects_and_output_extensions.py index 7ef7f617..418b0a54 100644 --- a/src/opengeodeweb_back/routes/schemas/geode_objects_and_output_extensions.py +++ b/src/opengeodeweb_back/routes/schemas/geode_objects_and_output_extensions.py @@ -24,7 +24,7 @@ def __init__(self, filename: str, input_geode_object: str) -> None: self.input_geode_object = input_geode_object @staticmethod - def from_dict(obj: Any) -> "GeodeObjectsAndOutputExtensions": + def from_dict(obj: Any) -> 'GeodeObjectsAndOutputExtensions': assert isinstance(obj, dict) filename = from_str(obj.get("filename")) input_geode_object = from_str(obj.get("input_geode_object")) @@ -37,13 +37,9 @@ def to_dict(self) -> dict: return result -def geode_objects_and_output_extensions_from_dict( - s: Any, -) -> GeodeObjectsAndOutputExtensions: +def geode_objects_and_output_extensions_from_dict(s: Any) -> GeodeObjectsAndOutputExtensions: return GeodeObjectsAndOutputExtensions.from_dict(s) -def geode_objects_and_output_extensions_to_dict( - x: GeodeObjectsAndOutputExtensions, -) -> Any: +def geode_objects_and_output_extensions_to_dict(x: GeodeObjectsAndOutputExtensions) -> Any: return to_class(GeodeObjectsAndOutputExtensions, x) diff --git a/src/opengeodeweb_back/routes/schemas/geographic_coordinate_systems.py b/src/opengeodeweb_back/routes/schemas/geographic_coordinate_systems.py index 1d3563f8..99a50bbc 100644 --- a/src/opengeodeweb_back/routes/schemas/geographic_coordinate_systems.py +++ b/src/opengeodeweb_back/routes/schemas/geographic_coordinate_systems.py @@ -22,7 +22,7 @@ def __init__(self, input_geode_object: str) -> None: self.input_geode_object = input_geode_object @staticmethod - def from_dict(obj: Any) -> "GeographicCoordinateSystems": + def from_dict(obj: Any) -> 'GeographicCoordinateSystems': assert isinstance(obj, dict) input_geode_object = from_str(obj.get("input_geode_object")) return GeographicCoordinateSystems(input_geode_object) diff --git a/src/opengeodeweb_back/routes/schemas/inspect_file.py b/src/opengeodeweb_back/routes/schemas/inspect_file.py index c9b30579..8a4d62b4 100644 --- a/src/opengeodeweb_back/routes/schemas/inspect_file.py +++ b/src/opengeodeweb_back/routes/schemas/inspect_file.py @@ -24,7 +24,7 @@ def __init__(self, filename: str, input_geode_object: str) -> None: self.input_geode_object = input_geode_object @staticmethod - def from_dict(obj: Any) -> "InspectFile": + def from_dict(obj: Any) -> 'InspectFile': assert isinstance(obj, dict) filename = from_str(obj.get("filename")) input_geode_object = from_str(obj.get("input_geode_object")) diff --git a/src/opengeodeweb_back/routes/schemas/kill.py b/src/opengeodeweb_back/routes/schemas/kill.py index 96ada023..06c80da7 100644 --- a/src/opengeodeweb_back/routes/schemas/kill.py +++ b/src/opengeodeweb_back/routes/schemas/kill.py @@ -13,13 +13,11 @@ def to_class(c: Type[T], x: Any) -> dict: class Kill: pass - def __init__( - self, - ) -> None: + def __init__(self, ) -> None: pass @staticmethod - def from_dict(obj: Any) -> "Kill": + def from_dict(obj: Any) -> 'Kill': assert isinstance(obj, dict) return Kill() diff --git a/src/opengeodeweb_back/routes/schemas/missing_files.py b/src/opengeodeweb_back/routes/schemas/missing_files.py index c93b2a64..382c3a01 100644 --- a/src/opengeodeweb_back/routes/schemas/missing_files.py +++ b/src/opengeodeweb_back/routes/schemas/missing_files.py @@ -24,7 +24,7 @@ def __init__(self, filename: str, input_geode_object: str) -> None: self.input_geode_object = input_geode_object @staticmethod - def from_dict(obj: Any) -> "MissingFiles": + def from_dict(obj: Any) -> 'MissingFiles': assert isinstance(obj, dict) filename = from_str(obj.get("filename")) input_geode_object = from_str(obj.get("input_geode_object")) diff --git a/src/opengeodeweb_back/routes/schemas/ping.py b/src/opengeodeweb_back/routes/schemas/ping.py index 9916d92c..78a75dd4 100644 --- a/src/opengeodeweb_back/routes/schemas/ping.py +++ b/src/opengeodeweb_back/routes/schemas/ping.py @@ -13,13 +13,11 @@ def to_class(c: Type[T], x: Any) -> dict: class Ping: pass - def __init__( - self, - ) -> None: + def __init__(self, ) -> None: pass @staticmethod - def from_dict(obj: Any) -> "Ping": + def from_dict(obj: Any) -> 'Ping': assert isinstance(obj, dict) return Ping() diff --git a/src/opengeodeweb_back/routes/schemas/polygon_attribute_names.py b/src/opengeodeweb_back/routes/schemas/polygon_attribute_names.py index 80778d3d..6cef2921 100644 --- a/src/opengeodeweb_back/routes/schemas/polygon_attribute_names.py +++ b/src/opengeodeweb_back/routes/schemas/polygon_attribute_names.py @@ -22,7 +22,7 @@ def __init__(self, id: str) -> None: self.id = id @staticmethod - def from_dict(obj: Any) -> "PolygonAttributeNames": + def from_dict(obj: Any) -> 'PolygonAttributeNames': assert isinstance(obj, dict) id = from_str(obj.get("id")) return PolygonAttributeNames(id) diff --git a/src/opengeodeweb_back/routes/schemas/polyhedron_attribute_names.py b/src/opengeodeweb_back/routes/schemas/polyhedron_attribute_names.py index f60215fb..d15ab524 100644 --- a/src/opengeodeweb_back/routes/schemas/polyhedron_attribute_names.py +++ b/src/opengeodeweb_back/routes/schemas/polyhedron_attribute_names.py @@ -22,7 +22,7 @@ def __init__(self, id: str) -> None: self.id = id @staticmethod - def from_dict(obj: Any) -> "PolyhedronAttributeNames": + def from_dict(obj: Any) -> 'PolyhedronAttributeNames': assert isinstance(obj, dict) id = from_str(obj.get("id")) return PolyhedronAttributeNames(id) diff --git a/src/opengeodeweb_back/routes/schemas/save_viewable_file.py b/src/opengeodeweb_back/routes/schemas/save_viewable_file.py index a33a00fb..cab4c3e5 100644 --- a/src/opengeodeweb_back/routes/schemas/save_viewable_file.py +++ b/src/opengeodeweb_back/routes/schemas/save_viewable_file.py @@ -24,7 +24,7 @@ def __init__(self, filename: str, input_geode_object: str) -> None: self.input_geode_object = input_geode_object @staticmethod - def from_dict(obj: Any) -> "SaveViewableFile": + def from_dict(obj: Any) -> 'SaveViewableFile': assert isinstance(obj, dict) filename = from_str(obj.get("filename")) input_geode_object = from_str(obj.get("input_geode_object")) diff --git a/src/opengeodeweb_back/routes/schemas/texture_coordinates.py b/src/opengeodeweb_back/routes/schemas/texture_coordinates.py index 5aa9fb66..d994bfe0 100644 --- a/src/opengeodeweb_back/routes/schemas/texture_coordinates.py +++ b/src/opengeodeweb_back/routes/schemas/texture_coordinates.py @@ -22,7 +22,7 @@ def __init__(self, id: str) -> None: self.id = id @staticmethod - def from_dict(obj: Any) -> "TextureCoordinates": + def from_dict(obj: Any) -> 'TextureCoordinates': assert isinstance(obj, dict) id = from_str(obj.get("id")) return TextureCoordinates(id) diff --git a/src/opengeodeweb_back/routes/schemas/upload_file.py b/src/opengeodeweb_back/routes/schemas/upload_file.py index 384da7cf..2e1b832e 100644 --- a/src/opengeodeweb_back/routes/schemas/upload_file.py +++ b/src/opengeodeweb_back/routes/schemas/upload_file.py @@ -36,7 +36,7 @@ def __init__(self, filename: Optional[str]) -> None: self.filename = filename @staticmethod - def from_dict(obj: Any) -> "UploadFile": + def from_dict(obj: Any) -> 'UploadFile': assert isinstance(obj, dict) filename = from_union([from_str, from_none], obj.get("filename")) return UploadFile(filename) diff --git a/src/opengeodeweb_back/routes/schemas/vertex_attribute_names.py b/src/opengeodeweb_back/routes/schemas/vertex_attribute_names.py index bbc873a6..8b9e23c9 100644 --- a/src/opengeodeweb_back/routes/schemas/vertex_attribute_names.py +++ b/src/opengeodeweb_back/routes/schemas/vertex_attribute_names.py @@ -22,7 +22,7 @@ def __init__(self, id: str) -> None: self.id = id @staticmethod - def from_dict(obj: Any) -> "VertexAttributeNames": + def from_dict(obj: Any) -> 'VertexAttributeNames': assert isinstance(obj, dict) id = from_str(obj.get("id")) return VertexAttributeNames(id) From 97763ebdc66fab143da65e109027024c7100f15a Mon Sep 17 00:00:00 2001 From: BotellaA <3213882+BotellaA@users.noreply.github.com> Date: Mon, 20 Oct 2025 15:05:45 +0000 Subject: [PATCH 05/14] Apply prepare changes --- .../routes/create/schemas/create_point.py | 2 +- .../routes/models/schemas/mesh_components.py | 2 +- .../routes/models/schemas/vtm_component_indices.py | 2 +- src/opengeodeweb_back/routes/schemas/allowed_files.py | 10 +++++++--- .../routes/schemas/allowed_objects.py | 10 +++++++--- .../schemas/geode_objects_and_output_extensions.py | 10 +++++++--- .../routes/schemas/geographic_coordinate_systems.py | 2 +- src/opengeodeweb_back/routes/schemas/inspect_file.py | 2 +- src/opengeodeweb_back/routes/schemas/kill.py | 6 ++++-- src/opengeodeweb_back/routes/schemas/missing_files.py | 2 +- src/opengeodeweb_back/routes/schemas/ping.py | 6 ++++-- .../routes/schemas/polygon_attribute_names.py | 2 +- .../routes/schemas/polyhedron_attribute_names.py | 2 +- .../routes/schemas/save_viewable_file.py | 2 +- .../routes/schemas/texture_coordinates.py | 2 +- src/opengeodeweb_back/routes/schemas/upload_file.py | 2 +- .../routes/schemas/vertex_attribute_names.py | 2 +- 17 files changed, 41 insertions(+), 25 deletions(-) diff --git a/src/opengeodeweb_back/routes/create/schemas/create_point.py b/src/opengeodeweb_back/routes/create/schemas/create_point.py index ae6f891f..76347712 100644 --- a/src/opengeodeweb_back/routes/create/schemas/create_point.py +++ b/src/opengeodeweb_back/routes/create/schemas/create_point.py @@ -38,7 +38,7 @@ def __init__(self, name: str, x: float, y: float, z: float) -> None: self.z = z @staticmethod - def from_dict(obj: Any) -> 'CreatePoint': + def from_dict(obj: Any) -> "CreatePoint": assert isinstance(obj, dict) name = from_str(obj.get("name")) x = from_float(obj.get("x")) diff --git a/src/opengeodeweb_back/routes/models/schemas/mesh_components.py b/src/opengeodeweb_back/routes/models/schemas/mesh_components.py index c82f475b..14971c2c 100644 --- a/src/opengeodeweb_back/routes/models/schemas/mesh_components.py +++ b/src/opengeodeweb_back/routes/models/schemas/mesh_components.py @@ -22,7 +22,7 @@ def __init__(self, id: str) -> None: self.id = id @staticmethod - def from_dict(obj: Any) -> 'MeshComponents': + def from_dict(obj: Any) -> "MeshComponents": assert isinstance(obj, dict) id = from_str(obj.get("id")) return MeshComponents(id) diff --git a/src/opengeodeweb_back/routes/models/schemas/vtm_component_indices.py b/src/opengeodeweb_back/routes/models/schemas/vtm_component_indices.py index ea594bec..62c0d8eb 100644 --- a/src/opengeodeweb_back/routes/models/schemas/vtm_component_indices.py +++ b/src/opengeodeweb_back/routes/models/schemas/vtm_component_indices.py @@ -22,7 +22,7 @@ def __init__(self, id: str) -> None: self.id = id @staticmethod - def from_dict(obj: Any) -> 'VtmComponentIndices': + def from_dict(obj: Any) -> "VtmComponentIndices": assert isinstance(obj, dict) id = from_str(obj.get("id")) return VtmComponentIndices(id) diff --git a/src/opengeodeweb_back/routes/schemas/allowed_files.py b/src/opengeodeweb_back/routes/schemas/allowed_files.py index 244294d2..93fc8369 100644 --- a/src/opengeodeweb_back/routes/schemas/allowed_files.py +++ b/src/opengeodeweb_back/routes/schemas/allowed_files.py @@ -36,14 +36,18 @@ def __init__(self, supported_feature: Optional[str]) -> None: self.supported_feature = supported_feature @staticmethod - def from_dict(obj: Any) -> 'AllowedFiles': + def from_dict(obj: Any) -> "AllowedFiles": assert isinstance(obj, dict) - supported_feature = from_union([from_none, from_str], obj.get("supported_feature")) + supported_feature = from_union( + [from_none, from_str], obj.get("supported_feature") + ) return AllowedFiles(supported_feature) def to_dict(self) -> dict: result: dict = {} - result["supported_feature"] = from_union([from_none, from_str], self.supported_feature) + result["supported_feature"] = from_union( + [from_none, from_str], self.supported_feature + ) return result diff --git a/src/opengeodeweb_back/routes/schemas/allowed_objects.py b/src/opengeodeweb_back/routes/schemas/allowed_objects.py index e0ac7916..0d24194a 100644 --- a/src/opengeodeweb_back/routes/schemas/allowed_objects.py +++ b/src/opengeodeweb_back/routes/schemas/allowed_objects.py @@ -38,16 +38,20 @@ def __init__(self, filename: str, supported_feature: Optional[str]) -> None: self.supported_feature = supported_feature @staticmethod - def from_dict(obj: Any) -> 'AllowedObjects': + def from_dict(obj: Any) -> "AllowedObjects": assert isinstance(obj, dict) filename = from_str(obj.get("filename")) - supported_feature = from_union([from_none, from_str], obj.get("supported_feature")) + supported_feature = from_union( + [from_none, from_str], obj.get("supported_feature") + ) return AllowedObjects(filename, supported_feature) def to_dict(self) -> dict: result: dict = {} result["filename"] = from_str(self.filename) - result["supported_feature"] = from_union([from_none, from_str], self.supported_feature) + result["supported_feature"] = from_union( + [from_none, from_str], self.supported_feature + ) return result diff --git a/src/opengeodeweb_back/routes/schemas/geode_objects_and_output_extensions.py b/src/opengeodeweb_back/routes/schemas/geode_objects_and_output_extensions.py index 418b0a54..7ef7f617 100644 --- a/src/opengeodeweb_back/routes/schemas/geode_objects_and_output_extensions.py +++ b/src/opengeodeweb_back/routes/schemas/geode_objects_and_output_extensions.py @@ -24,7 +24,7 @@ def __init__(self, filename: str, input_geode_object: str) -> None: self.input_geode_object = input_geode_object @staticmethod - def from_dict(obj: Any) -> 'GeodeObjectsAndOutputExtensions': + def from_dict(obj: Any) -> "GeodeObjectsAndOutputExtensions": assert isinstance(obj, dict) filename = from_str(obj.get("filename")) input_geode_object = from_str(obj.get("input_geode_object")) @@ -37,9 +37,13 @@ def to_dict(self) -> dict: return result -def geode_objects_and_output_extensions_from_dict(s: Any) -> GeodeObjectsAndOutputExtensions: +def geode_objects_and_output_extensions_from_dict( + s: Any, +) -> GeodeObjectsAndOutputExtensions: return GeodeObjectsAndOutputExtensions.from_dict(s) -def geode_objects_and_output_extensions_to_dict(x: GeodeObjectsAndOutputExtensions) -> Any: +def geode_objects_and_output_extensions_to_dict( + x: GeodeObjectsAndOutputExtensions, +) -> Any: return to_class(GeodeObjectsAndOutputExtensions, x) diff --git a/src/opengeodeweb_back/routes/schemas/geographic_coordinate_systems.py b/src/opengeodeweb_back/routes/schemas/geographic_coordinate_systems.py index 99a50bbc..1d3563f8 100644 --- a/src/opengeodeweb_back/routes/schemas/geographic_coordinate_systems.py +++ b/src/opengeodeweb_back/routes/schemas/geographic_coordinate_systems.py @@ -22,7 +22,7 @@ def __init__(self, input_geode_object: str) -> None: self.input_geode_object = input_geode_object @staticmethod - def from_dict(obj: Any) -> 'GeographicCoordinateSystems': + def from_dict(obj: Any) -> "GeographicCoordinateSystems": assert isinstance(obj, dict) input_geode_object = from_str(obj.get("input_geode_object")) return GeographicCoordinateSystems(input_geode_object) diff --git a/src/opengeodeweb_back/routes/schemas/inspect_file.py b/src/opengeodeweb_back/routes/schemas/inspect_file.py index 8a4d62b4..c9b30579 100644 --- a/src/opengeodeweb_back/routes/schemas/inspect_file.py +++ b/src/opengeodeweb_back/routes/schemas/inspect_file.py @@ -24,7 +24,7 @@ def __init__(self, filename: str, input_geode_object: str) -> None: self.input_geode_object = input_geode_object @staticmethod - def from_dict(obj: Any) -> 'InspectFile': + def from_dict(obj: Any) -> "InspectFile": assert isinstance(obj, dict) filename = from_str(obj.get("filename")) input_geode_object = from_str(obj.get("input_geode_object")) diff --git a/src/opengeodeweb_back/routes/schemas/kill.py b/src/opengeodeweb_back/routes/schemas/kill.py index 06c80da7..96ada023 100644 --- a/src/opengeodeweb_back/routes/schemas/kill.py +++ b/src/opengeodeweb_back/routes/schemas/kill.py @@ -13,11 +13,13 @@ def to_class(c: Type[T], x: Any) -> dict: class Kill: pass - def __init__(self, ) -> None: + def __init__( + self, + ) -> None: pass @staticmethod - def from_dict(obj: Any) -> 'Kill': + def from_dict(obj: Any) -> "Kill": assert isinstance(obj, dict) return Kill() diff --git a/src/opengeodeweb_back/routes/schemas/missing_files.py b/src/opengeodeweb_back/routes/schemas/missing_files.py index 382c3a01..c93b2a64 100644 --- a/src/opengeodeweb_back/routes/schemas/missing_files.py +++ b/src/opengeodeweb_back/routes/schemas/missing_files.py @@ -24,7 +24,7 @@ def __init__(self, filename: str, input_geode_object: str) -> None: self.input_geode_object = input_geode_object @staticmethod - def from_dict(obj: Any) -> 'MissingFiles': + def from_dict(obj: Any) -> "MissingFiles": assert isinstance(obj, dict) filename = from_str(obj.get("filename")) input_geode_object = from_str(obj.get("input_geode_object")) diff --git a/src/opengeodeweb_back/routes/schemas/ping.py b/src/opengeodeweb_back/routes/schemas/ping.py index 78a75dd4..9916d92c 100644 --- a/src/opengeodeweb_back/routes/schemas/ping.py +++ b/src/opengeodeweb_back/routes/schemas/ping.py @@ -13,11 +13,13 @@ def to_class(c: Type[T], x: Any) -> dict: class Ping: pass - def __init__(self, ) -> None: + def __init__( + self, + ) -> None: pass @staticmethod - def from_dict(obj: Any) -> 'Ping': + def from_dict(obj: Any) -> "Ping": assert isinstance(obj, dict) return Ping() diff --git a/src/opengeodeweb_back/routes/schemas/polygon_attribute_names.py b/src/opengeodeweb_back/routes/schemas/polygon_attribute_names.py index 6cef2921..80778d3d 100644 --- a/src/opengeodeweb_back/routes/schemas/polygon_attribute_names.py +++ b/src/opengeodeweb_back/routes/schemas/polygon_attribute_names.py @@ -22,7 +22,7 @@ def __init__(self, id: str) -> None: self.id = id @staticmethod - def from_dict(obj: Any) -> 'PolygonAttributeNames': + def from_dict(obj: Any) -> "PolygonAttributeNames": assert isinstance(obj, dict) id = from_str(obj.get("id")) return PolygonAttributeNames(id) diff --git a/src/opengeodeweb_back/routes/schemas/polyhedron_attribute_names.py b/src/opengeodeweb_back/routes/schemas/polyhedron_attribute_names.py index d15ab524..f60215fb 100644 --- a/src/opengeodeweb_back/routes/schemas/polyhedron_attribute_names.py +++ b/src/opengeodeweb_back/routes/schemas/polyhedron_attribute_names.py @@ -22,7 +22,7 @@ def __init__(self, id: str) -> None: self.id = id @staticmethod - def from_dict(obj: Any) -> 'PolyhedronAttributeNames': + def from_dict(obj: Any) -> "PolyhedronAttributeNames": assert isinstance(obj, dict) id = from_str(obj.get("id")) return PolyhedronAttributeNames(id) diff --git a/src/opengeodeweb_back/routes/schemas/save_viewable_file.py b/src/opengeodeweb_back/routes/schemas/save_viewable_file.py index cab4c3e5..a33a00fb 100644 --- a/src/opengeodeweb_back/routes/schemas/save_viewable_file.py +++ b/src/opengeodeweb_back/routes/schemas/save_viewable_file.py @@ -24,7 +24,7 @@ def __init__(self, filename: str, input_geode_object: str) -> None: self.input_geode_object = input_geode_object @staticmethod - def from_dict(obj: Any) -> 'SaveViewableFile': + def from_dict(obj: Any) -> "SaveViewableFile": assert isinstance(obj, dict) filename = from_str(obj.get("filename")) input_geode_object = from_str(obj.get("input_geode_object")) diff --git a/src/opengeodeweb_back/routes/schemas/texture_coordinates.py b/src/opengeodeweb_back/routes/schemas/texture_coordinates.py index d994bfe0..5aa9fb66 100644 --- a/src/opengeodeweb_back/routes/schemas/texture_coordinates.py +++ b/src/opengeodeweb_back/routes/schemas/texture_coordinates.py @@ -22,7 +22,7 @@ def __init__(self, id: str) -> None: self.id = id @staticmethod - def from_dict(obj: Any) -> 'TextureCoordinates': + def from_dict(obj: Any) -> "TextureCoordinates": assert isinstance(obj, dict) id = from_str(obj.get("id")) return TextureCoordinates(id) diff --git a/src/opengeodeweb_back/routes/schemas/upload_file.py b/src/opengeodeweb_back/routes/schemas/upload_file.py index 2e1b832e..384da7cf 100644 --- a/src/opengeodeweb_back/routes/schemas/upload_file.py +++ b/src/opengeodeweb_back/routes/schemas/upload_file.py @@ -36,7 +36,7 @@ def __init__(self, filename: Optional[str]) -> None: self.filename = filename @staticmethod - def from_dict(obj: Any) -> 'UploadFile': + def from_dict(obj: Any) -> "UploadFile": assert isinstance(obj, dict) filename = from_union([from_str, from_none], obj.get("filename")) return UploadFile(filename) diff --git a/src/opengeodeweb_back/routes/schemas/vertex_attribute_names.py b/src/opengeodeweb_back/routes/schemas/vertex_attribute_names.py index 8b9e23c9..bbc873a6 100644 --- a/src/opengeodeweb_back/routes/schemas/vertex_attribute_names.py +++ b/src/opengeodeweb_back/routes/schemas/vertex_attribute_names.py @@ -22,7 +22,7 @@ def __init__(self, id: str) -> None: self.id = id @staticmethod - def from_dict(obj: Any) -> 'VertexAttributeNames': + def from_dict(obj: Any) -> "VertexAttributeNames": assert isinstance(obj, dict) id = from_str(obj.get("id")) return VertexAttributeNames(id) From b737e914af96c2e81f6c78a5da38c84aaa5d7406 Mon Sep 17 00:00:00 2001 From: Arnaud Botella Date: Mon, 20 Oct 2025 20:10:39 +0200 Subject: [PATCH 06/14] test --- .../routes/create/blueprint_create.py | 6 +- .../routes/create/schemas/create_aoi.py | 100 +----------------- .../routes/create/schemas/create_point.py | 58 +--------- .../routes/models/schemas/mesh_components.py | 39 +------ .../models/schemas/vtm_component_indices.py | 39 +------ .../routes/schemas/allowed_files.py | 60 +---------- .../routes/schemas/allowed_objects.py | 63 +---------- .../geode_objects_and_output_extensions.py | 46 +------- .../schemas/geographic_coordinate_systems.py | 39 +------ .../routes/schemas/inspect_file.py | 42 +------- src/opengeodeweb_back/routes/schemas/kill.py | 34 +----- .../routes/schemas/missing_files.py | 42 +------- src/opengeodeweb_back/routes/schemas/ping.py | 34 +----- .../routes/schemas/polygon_attribute_names.py | 39 +------ .../schemas/polyhedron_attribute_names.py | 39 +------ .../routes/schemas/save_viewable_file.py | 42 +------- .../routes/schemas/texture_coordinates.py | 39 +------ .../routes/schemas/upload_file.py | 57 +--------- .../routes/schemas/vertex_attribute_names.py | 39 +------ 19 files changed, 48 insertions(+), 809 deletions(-) diff --git a/src/opengeodeweb_back/routes/create/blueprint_create.py b/src/opengeodeweb_back/routes/create/blueprint_create.py index c4becdf8..f021c034 100644 --- a/src/opengeodeweb_back/routes/create/blueprint_create.py +++ b/src/opengeodeweb_back/routes/create/blueprint_create.py @@ -29,7 +29,7 @@ def create_point() -> flask.Response: """Endpoint to create a single point in 3D space.""" print(f"create_point : {flask.request=}", flush=True) utils_functions.validate_request(flask.request, create_point_json) - params = CreatePoint.from_dict(flask.request.get_json()) + params = CreatePoint(**flask.request.get_json()) # Create the point class_ = geode_functions.geode_object_class("PointSet3D") @@ -56,7 +56,7 @@ def create_aoi() -> flask.Response: """Endpoint to create an Area of Interest (AOI) as an EdgedCurve3D.""" print(f"create_aoi : {flask.request=}", flush=True) utils_functions.validate_request(flask.request, create_aoi_json) - params = CreateAoi.from_dict(flask.request.get_json()) + params = CreateAoi(**flask.request.get_json()) # Create the edged curve class_ = geode_functions.geode_object_class("EdgedCurve3D") @@ -68,7 +68,7 @@ def create_aoi() -> flask.Response: vertex_indices: list[int] = [] for point in params.points: vertex_id = builder.create_point( - opengeode.Point3D([point["x"], point["y"], params.z]) + opengeode.Point3D([point.x, point.y, params.z]) ) vertex_indices.append(vertex_id) diff --git a/src/opengeodeweb_back/routes/create/schemas/create_aoi.py b/src/opengeodeweb_back/routes/create/schemas/create_aoi.py index b61729d7..dfe92e75 100644 --- a/src/opengeodeweb_back/routes/create/schemas/create_aoi.py +++ b/src/opengeodeweb_back/routes/create/schemas/create_aoi.py @@ -1,108 +1,18 @@ -from typing import Any, Optional, List, TypeVar, Callable, Type, cast - - -T = TypeVar("T") - - -def from_float(x: Any) -> float: - assert isinstance(x, (float, int)) and not isinstance(x, bool) - return float(x) - - -def to_float(x: Any) -> float: - assert isinstance(x, (int, float)) - return x - - -def from_str(x: Any) -> str: - assert isinstance(x, str) - return x - - -def from_none(x: Any) -> Any: - assert x is None - return x - - -def from_union(fs, x): - for f in fs: - try: - return f(x) - except: - pass - assert False - - -def from_list(f: Callable[[Any], T], x: Any) -> List[T]: - assert isinstance(x, list) - return [f(y) for y in x] - - -def to_class(c: Type[T], x: Any) -> dict: - assert isinstance(x, c) - return cast(Any, x).to_dict() +from dataclasses import dataclass +from typing import List, Optional +@dataclass class Point: x: float y: float - def __init__(self, x: float, y: float) -> None: - self.x = x - self.y = y - - @staticmethod - def from_dict(obj: Any) -> "Point": - assert isinstance(obj, dict) - x = from_float(obj.get("x")) - y = from_float(obj.get("y")) - return Point(x, y) - - def to_dict(self) -> dict: - result: dict = {} - result["x"] = to_float(self.x) - result["y"] = to_float(self.y) - return result - +@dataclass class CreateAoi: - id: Optional[str] name: str """Name of the AOI""" points: List[Point] z: float - - def __init__( - self, id: Optional[str], name: str, points: List[Point], z: float - ) -> None: - self.id = id - self.name = name - self.points = points - self.z = z - - @staticmethod - def from_dict(obj: Any) -> "CreateAoi": - assert isinstance(obj, dict) - id = from_union([from_str, from_none], obj.get("id")) - name = from_str(obj.get("name")) - points = from_list(Point.from_dict, obj.get("points")) - z = from_float(obj.get("z")) - return CreateAoi(id, name, points, z) - - def to_dict(self) -> dict: - result: dict = {} - if self.id is not None: - result["id"] = from_union([from_str, from_none], self.id) - result["name"] = from_str(self.name) - result["points"] = from_list(lambda x: to_class(Point, x), self.points) - result["z"] = to_float(self.z) - return result - - -def create_aoi_from_dict(s: Any) -> CreateAoi: - return CreateAoi.from_dict(s) - - -def create_aoi_to_dict(x: CreateAoi) -> Any: - return to_class(CreateAoi, x) + id: Optional[str] = None diff --git a/src/opengeodeweb_back/routes/create/schemas/create_point.py b/src/opengeodeweb_back/routes/create/schemas/create_point.py index 76347712..5fc45e47 100644 --- a/src/opengeodeweb_back/routes/create/schemas/create_point.py +++ b/src/opengeodeweb_back/routes/create/schemas/create_point.py @@ -1,63 +1,9 @@ -# type: ignore -from typing import Any, TypeVar, Type, cast - - -T = TypeVar("T") - - -def from_str(x: Any) -> str: - assert isinstance(x, str) - return x - - -def from_float(x: Any) -> float: - assert isinstance(x, (float, int)) and not isinstance(x, bool) - return float(x) - - -def to_float(x: Any) -> float: - assert isinstance(x, (int, float)) - return x - - -def to_class(c: Type[T], x: Any) -> dict: - assert isinstance(x, c) - return cast(Any, x).to_dict() +from dataclasses import dataclass +@dataclass class CreatePoint: name: str x: float y: float z: float - - def __init__(self, name: str, x: float, y: float, z: float) -> None: - self.name = name - self.x = x - self.y = y - self.z = z - - @staticmethod - def from_dict(obj: Any) -> "CreatePoint": - assert isinstance(obj, dict) - name = from_str(obj.get("name")) - x = from_float(obj.get("x")) - y = from_float(obj.get("y")) - z = from_float(obj.get("z")) - return CreatePoint(name, x, y, z) - - def to_dict(self) -> dict: - result: dict = {} - result["name"] = from_str(self.name) - result["x"] = to_float(self.x) - result["y"] = to_float(self.y) - result["z"] = to_float(self.z) - return result - - -def create_point_from_dict(s: Any) -> CreatePoint: - return CreatePoint.from_dict(s) - - -def create_point_to_dict(x: CreatePoint) -> Any: - return to_class(CreatePoint, x) diff --git a/src/opengeodeweb_back/routes/models/schemas/mesh_components.py b/src/opengeodeweb_back/routes/models/schemas/mesh_components.py index 14971c2c..229a5a27 100644 --- a/src/opengeodeweb_back/routes/models/schemas/mesh_components.py +++ b/src/opengeodeweb_back/routes/models/schemas/mesh_components.py @@ -1,41 +1,6 @@ -# type: ignore -from typing import Any, TypeVar, Type, cast - - -T = TypeVar("T") - - -def from_str(x: Any) -> str: - assert isinstance(x, str) - return x - - -def to_class(c: Type[T], x: Any) -> dict: - assert isinstance(x, c) - return cast(Any, x).to_dict() +from dataclasses import dataclass +@dataclass class MeshComponents: id: str - - def __init__(self, id: str) -> None: - self.id = id - - @staticmethod - def from_dict(obj: Any) -> "MeshComponents": - assert isinstance(obj, dict) - id = from_str(obj.get("id")) - return MeshComponents(id) - - def to_dict(self) -> dict: - result: dict = {} - result["id"] = from_str(self.id) - return result - - -def mesh_components_from_dict(s: Any) -> MeshComponents: - return MeshComponents.from_dict(s) - - -def mesh_components_to_dict(x: MeshComponents) -> Any: - return to_class(MeshComponents, x) diff --git a/src/opengeodeweb_back/routes/models/schemas/vtm_component_indices.py b/src/opengeodeweb_back/routes/models/schemas/vtm_component_indices.py index 62c0d8eb..fe0aca65 100644 --- a/src/opengeodeweb_back/routes/models/schemas/vtm_component_indices.py +++ b/src/opengeodeweb_back/routes/models/schemas/vtm_component_indices.py @@ -1,41 +1,6 @@ -# type: ignore -from typing import Any, TypeVar, Type, cast - - -T = TypeVar("T") - - -def from_str(x: Any) -> str: - assert isinstance(x, str) - return x - - -def to_class(c: Type[T], x: Any) -> dict: - assert isinstance(x, c) - return cast(Any, x).to_dict() +from dataclasses import dataclass +@dataclass class VtmComponentIndices: id: str - - def __init__(self, id: str) -> None: - self.id = id - - @staticmethod - def from_dict(obj: Any) -> "VtmComponentIndices": - assert isinstance(obj, dict) - id = from_str(obj.get("id")) - return VtmComponentIndices(id) - - def to_dict(self) -> dict: - result: dict = {} - result["id"] = from_str(self.id) - return result - - -def vtm_component_indices_from_dict(s: Any) -> VtmComponentIndices: - return VtmComponentIndices.from_dict(s) - - -def vtm_component_indices_to_dict(x: VtmComponentIndices) -> Any: - return to_class(VtmComponentIndices, x) diff --git a/src/opengeodeweb_back/routes/schemas/allowed_files.py b/src/opengeodeweb_back/routes/schemas/allowed_files.py index 93fc8369..1129a507 100644 --- a/src/opengeodeweb_back/routes/schemas/allowed_files.py +++ b/src/opengeodeweb_back/routes/schemas/allowed_files.py @@ -1,59 +1,7 @@ -# type: ignore -from typing import Optional, Any, TypeVar, Type, cast - - -T = TypeVar("T") - - -def from_none(x: Any) -> Any: - assert x is None - return x - - -def from_str(x: Any) -> str: - assert isinstance(x, str) - return x - - -def from_union(fs, x): - for f in fs: - try: - return f(x) - except: - pass - assert False - - -def to_class(c: Type[T], x: Any) -> dict: - assert isinstance(x, c) - return cast(Any, x).to_dict() +from dataclasses import dataclass +from typing import Optional +@dataclass class AllowedFiles: - supported_feature: Optional[str] - - def __init__(self, supported_feature: Optional[str]) -> None: - self.supported_feature = supported_feature - - @staticmethod - def from_dict(obj: Any) -> "AllowedFiles": - assert isinstance(obj, dict) - supported_feature = from_union( - [from_none, from_str], obj.get("supported_feature") - ) - return AllowedFiles(supported_feature) - - def to_dict(self) -> dict: - result: dict = {} - result["supported_feature"] = from_union( - [from_none, from_str], self.supported_feature - ) - return result - - -def allowed_files_from_dict(s: Any) -> AllowedFiles: - return AllowedFiles.from_dict(s) - - -def allowed_files_to_dict(x: AllowedFiles) -> Any: - return to_class(AllowedFiles, x) + supported_feature: Optional[str] = None diff --git a/src/opengeodeweb_back/routes/schemas/allowed_objects.py b/src/opengeodeweb_back/routes/schemas/allowed_objects.py index 0d24194a..9f104bae 100644 --- a/src/opengeodeweb_back/routes/schemas/allowed_objects.py +++ b/src/opengeodeweb_back/routes/schemas/allowed_objects.py @@ -1,63 +1,8 @@ -# type: ignore -from typing import Optional, Any, TypeVar, Type, cast - - -T = TypeVar("T") - - -def from_str(x: Any) -> str: - assert isinstance(x, str) - return x - - -def from_none(x: Any) -> Any: - assert x is None - return x - - -def from_union(fs, x): - for f in fs: - try: - return f(x) - except: - pass - assert False - - -def to_class(c: Type[T], x: Any) -> dict: - assert isinstance(x, c) - return cast(Any, x).to_dict() +from dataclasses import dataclass +from typing import Optional +@dataclass class AllowedObjects: filename: str - supported_feature: Optional[str] - - def __init__(self, filename: str, supported_feature: Optional[str]) -> None: - self.filename = filename - self.supported_feature = supported_feature - - @staticmethod - def from_dict(obj: Any) -> "AllowedObjects": - assert isinstance(obj, dict) - filename = from_str(obj.get("filename")) - supported_feature = from_union( - [from_none, from_str], obj.get("supported_feature") - ) - return AllowedObjects(filename, supported_feature) - - def to_dict(self) -> dict: - result: dict = {} - result["filename"] = from_str(self.filename) - result["supported_feature"] = from_union( - [from_none, from_str], self.supported_feature - ) - return result - - -def allowed_objects_from_dict(s: Any) -> AllowedObjects: - return AllowedObjects.from_dict(s) - - -def allowed_objects_to_dict(x: AllowedObjects) -> Any: - return to_class(AllowedObjects, x) + supported_feature: Optional[str] = None diff --git a/src/opengeodeweb_back/routes/schemas/geode_objects_and_output_extensions.py b/src/opengeodeweb_back/routes/schemas/geode_objects_and_output_extensions.py index 7ef7f617..5c1990e7 100644 --- a/src/opengeodeweb_back/routes/schemas/geode_objects_and_output_extensions.py +++ b/src/opengeodeweb_back/routes/schemas/geode_objects_and_output_extensions.py @@ -1,49 +1,7 @@ -# type: ignore -from typing import Any, TypeVar, Type, cast - - -T = TypeVar("T") - - -def from_str(x: Any) -> str: - assert isinstance(x, str) - return x - - -def to_class(c: Type[T], x: Any) -> dict: - assert isinstance(x, c) - return cast(Any, x).to_dict() +from dataclasses import dataclass +@dataclass class GeodeObjectsAndOutputExtensions: filename: str input_geode_object: str - - def __init__(self, filename: str, input_geode_object: str) -> None: - self.filename = filename - self.input_geode_object = input_geode_object - - @staticmethod - def from_dict(obj: Any) -> "GeodeObjectsAndOutputExtensions": - assert isinstance(obj, dict) - filename = from_str(obj.get("filename")) - input_geode_object = from_str(obj.get("input_geode_object")) - return GeodeObjectsAndOutputExtensions(filename, input_geode_object) - - def to_dict(self) -> dict: - result: dict = {} - result["filename"] = from_str(self.filename) - result["input_geode_object"] = from_str(self.input_geode_object) - return result - - -def geode_objects_and_output_extensions_from_dict( - s: Any, -) -> GeodeObjectsAndOutputExtensions: - return GeodeObjectsAndOutputExtensions.from_dict(s) - - -def geode_objects_and_output_extensions_to_dict( - x: GeodeObjectsAndOutputExtensions, -) -> Any: - return to_class(GeodeObjectsAndOutputExtensions, x) diff --git a/src/opengeodeweb_back/routes/schemas/geographic_coordinate_systems.py b/src/opengeodeweb_back/routes/schemas/geographic_coordinate_systems.py index 1d3563f8..3a10c7f5 100644 --- a/src/opengeodeweb_back/routes/schemas/geographic_coordinate_systems.py +++ b/src/opengeodeweb_back/routes/schemas/geographic_coordinate_systems.py @@ -1,41 +1,6 @@ -# type: ignore -from typing import Any, TypeVar, Type, cast - - -T = TypeVar("T") - - -def from_str(x: Any) -> str: - assert isinstance(x, str) - return x - - -def to_class(c: Type[T], x: Any) -> dict: - assert isinstance(x, c) - return cast(Any, x).to_dict() +from dataclasses import dataclass +@dataclass class GeographicCoordinateSystems: input_geode_object: str - - def __init__(self, input_geode_object: str) -> None: - self.input_geode_object = input_geode_object - - @staticmethod - def from_dict(obj: Any) -> "GeographicCoordinateSystems": - assert isinstance(obj, dict) - input_geode_object = from_str(obj.get("input_geode_object")) - return GeographicCoordinateSystems(input_geode_object) - - def to_dict(self) -> dict: - result: dict = {} - result["input_geode_object"] = from_str(self.input_geode_object) - return result - - -def geographic_coordinate_systems_from_dict(s: Any) -> GeographicCoordinateSystems: - return GeographicCoordinateSystems.from_dict(s) - - -def geographic_coordinate_systems_to_dict(x: GeographicCoordinateSystems) -> Any: - return to_class(GeographicCoordinateSystems, x) diff --git a/src/opengeodeweb_back/routes/schemas/inspect_file.py b/src/opengeodeweb_back/routes/schemas/inspect_file.py index c9b30579..c118122b 100644 --- a/src/opengeodeweb_back/routes/schemas/inspect_file.py +++ b/src/opengeodeweb_back/routes/schemas/inspect_file.py @@ -1,45 +1,7 @@ -# type: ignore -from typing import Any, TypeVar, Type, cast - - -T = TypeVar("T") - - -def from_str(x: Any) -> str: - assert isinstance(x, str) - return x - - -def to_class(c: Type[T], x: Any) -> dict: - assert isinstance(x, c) - return cast(Any, x).to_dict() +from dataclasses import dataclass +@dataclass class InspectFile: filename: str input_geode_object: str - - def __init__(self, filename: str, input_geode_object: str) -> None: - self.filename = filename - self.input_geode_object = input_geode_object - - @staticmethod - def from_dict(obj: Any) -> "InspectFile": - assert isinstance(obj, dict) - filename = from_str(obj.get("filename")) - input_geode_object = from_str(obj.get("input_geode_object")) - return InspectFile(filename, input_geode_object) - - def to_dict(self) -> dict: - result: dict = {} - result["filename"] = from_str(self.filename) - result["input_geode_object"] = from_str(self.input_geode_object) - return result - - -def inspect_file_from_dict(s: Any) -> InspectFile: - return InspectFile.from_dict(s) - - -def inspect_file_to_dict(x: InspectFile) -> Any: - return to_class(InspectFile, x) diff --git a/src/opengeodeweb_back/routes/schemas/kill.py b/src/opengeodeweb_back/routes/schemas/kill.py index 96ada023..0452cd35 100644 --- a/src/opengeodeweb_back/routes/schemas/kill.py +++ b/src/opengeodeweb_back/routes/schemas/kill.py @@ -1,36 +1,6 @@ -# type: ignore -from typing import Any, TypeVar, Type, cast - - -T = TypeVar("T") - - -def to_class(c: Type[T], x: Any) -> dict: - assert isinstance(x, c) - return cast(Any, x).to_dict() +from dataclasses import dataclass +@dataclass class Kill: pass - - def __init__( - self, - ) -> None: - pass - - @staticmethod - def from_dict(obj: Any) -> "Kill": - assert isinstance(obj, dict) - return Kill() - - def to_dict(self) -> dict: - result: dict = {} - return result - - -def kill_from_dict(s: Any) -> Kill: - return Kill.from_dict(s) - - -def kill_to_dict(x: Kill) -> Any: - return to_class(Kill, x) diff --git a/src/opengeodeweb_back/routes/schemas/missing_files.py b/src/opengeodeweb_back/routes/schemas/missing_files.py index c93b2a64..d167421e 100644 --- a/src/opengeodeweb_back/routes/schemas/missing_files.py +++ b/src/opengeodeweb_back/routes/schemas/missing_files.py @@ -1,45 +1,7 @@ -# type: ignore -from typing import Any, TypeVar, Type, cast - - -T = TypeVar("T") - - -def from_str(x: Any) -> str: - assert isinstance(x, str) - return x - - -def to_class(c: Type[T], x: Any) -> dict: - assert isinstance(x, c) - return cast(Any, x).to_dict() +from dataclasses import dataclass +@dataclass class MissingFiles: filename: str input_geode_object: str - - def __init__(self, filename: str, input_geode_object: str) -> None: - self.filename = filename - self.input_geode_object = input_geode_object - - @staticmethod - def from_dict(obj: Any) -> "MissingFiles": - assert isinstance(obj, dict) - filename = from_str(obj.get("filename")) - input_geode_object = from_str(obj.get("input_geode_object")) - return MissingFiles(filename, input_geode_object) - - def to_dict(self) -> dict: - result: dict = {} - result["filename"] = from_str(self.filename) - result["input_geode_object"] = from_str(self.input_geode_object) - return result - - -def missing_files_from_dict(s: Any) -> MissingFiles: - return MissingFiles.from_dict(s) - - -def missing_files_to_dict(x: MissingFiles) -> Any: - return to_class(MissingFiles, x) diff --git a/src/opengeodeweb_back/routes/schemas/ping.py b/src/opengeodeweb_back/routes/schemas/ping.py index 9916d92c..a448c1da 100644 --- a/src/opengeodeweb_back/routes/schemas/ping.py +++ b/src/opengeodeweb_back/routes/schemas/ping.py @@ -1,36 +1,6 @@ -# type: ignore -from typing import Any, TypeVar, Type, cast - - -T = TypeVar("T") - - -def to_class(c: Type[T], x: Any) -> dict: - assert isinstance(x, c) - return cast(Any, x).to_dict() +from dataclasses import dataclass +@dataclass class Ping: pass - - def __init__( - self, - ) -> None: - pass - - @staticmethod - def from_dict(obj: Any) -> "Ping": - assert isinstance(obj, dict) - return Ping() - - def to_dict(self) -> dict: - result: dict = {} - return result - - -def ping_from_dict(s: Any) -> Ping: - return Ping.from_dict(s) - - -def ping_to_dict(x: Ping) -> Any: - return to_class(Ping, x) diff --git a/src/opengeodeweb_back/routes/schemas/polygon_attribute_names.py b/src/opengeodeweb_back/routes/schemas/polygon_attribute_names.py index 80778d3d..76846c1c 100644 --- a/src/opengeodeweb_back/routes/schemas/polygon_attribute_names.py +++ b/src/opengeodeweb_back/routes/schemas/polygon_attribute_names.py @@ -1,41 +1,6 @@ -# type: ignore -from typing import Any, TypeVar, Type, cast - - -T = TypeVar("T") - - -def from_str(x: Any) -> str: - assert isinstance(x, str) - return x - - -def to_class(c: Type[T], x: Any) -> dict: - assert isinstance(x, c) - return cast(Any, x).to_dict() +from dataclasses import dataclass +@dataclass class PolygonAttributeNames: id: str - - def __init__(self, id: str) -> None: - self.id = id - - @staticmethod - def from_dict(obj: Any) -> "PolygonAttributeNames": - assert isinstance(obj, dict) - id = from_str(obj.get("id")) - return PolygonAttributeNames(id) - - def to_dict(self) -> dict: - result: dict = {} - result["id"] = from_str(self.id) - return result - - -def polygon_attribute_names_from_dict(s: Any) -> PolygonAttributeNames: - return PolygonAttributeNames.from_dict(s) - - -def polygon_attribute_names_to_dict(x: PolygonAttributeNames) -> Any: - return to_class(PolygonAttributeNames, x) diff --git a/src/opengeodeweb_back/routes/schemas/polyhedron_attribute_names.py b/src/opengeodeweb_back/routes/schemas/polyhedron_attribute_names.py index f60215fb..0fde7ac5 100644 --- a/src/opengeodeweb_back/routes/schemas/polyhedron_attribute_names.py +++ b/src/opengeodeweb_back/routes/schemas/polyhedron_attribute_names.py @@ -1,41 +1,6 @@ -# type: ignore -from typing import Any, TypeVar, Type, cast - - -T = TypeVar("T") - - -def from_str(x: Any) -> str: - assert isinstance(x, str) - return x - - -def to_class(c: Type[T], x: Any) -> dict: - assert isinstance(x, c) - return cast(Any, x).to_dict() +from dataclasses import dataclass +@dataclass class PolyhedronAttributeNames: id: str - - def __init__(self, id: str) -> None: - self.id = id - - @staticmethod - def from_dict(obj: Any) -> "PolyhedronAttributeNames": - assert isinstance(obj, dict) - id = from_str(obj.get("id")) - return PolyhedronAttributeNames(id) - - def to_dict(self) -> dict: - result: dict = {} - result["id"] = from_str(self.id) - return result - - -def polyhedron_attribute_names_from_dict(s: Any) -> PolyhedronAttributeNames: - return PolyhedronAttributeNames.from_dict(s) - - -def polyhedron_attribute_names_to_dict(x: PolyhedronAttributeNames) -> Any: - return to_class(PolyhedronAttributeNames, x) diff --git a/src/opengeodeweb_back/routes/schemas/save_viewable_file.py b/src/opengeodeweb_back/routes/schemas/save_viewable_file.py index a33a00fb..e3ead724 100644 --- a/src/opengeodeweb_back/routes/schemas/save_viewable_file.py +++ b/src/opengeodeweb_back/routes/schemas/save_viewable_file.py @@ -1,45 +1,7 @@ -# type: ignore -from typing import Any, TypeVar, Type, cast - - -T = TypeVar("T") - - -def from_str(x: Any) -> str: - assert isinstance(x, str) - return x - - -def to_class(c: Type[T], x: Any) -> dict: - assert isinstance(x, c) - return cast(Any, x).to_dict() +from dataclasses import dataclass +@dataclass class SaveViewableFile: filename: str input_geode_object: str - - def __init__(self, filename: str, input_geode_object: str) -> None: - self.filename = filename - self.input_geode_object = input_geode_object - - @staticmethod - def from_dict(obj: Any) -> "SaveViewableFile": - assert isinstance(obj, dict) - filename = from_str(obj.get("filename")) - input_geode_object = from_str(obj.get("input_geode_object")) - return SaveViewableFile(filename, input_geode_object) - - def to_dict(self) -> dict: - result: dict = {} - result["filename"] = from_str(self.filename) - result["input_geode_object"] = from_str(self.input_geode_object) - return result - - -def save_viewable_file_from_dict(s: Any) -> SaveViewableFile: - return SaveViewableFile.from_dict(s) - - -def save_viewable_file_to_dict(x: SaveViewableFile) -> Any: - return to_class(SaveViewableFile, x) diff --git a/src/opengeodeweb_back/routes/schemas/texture_coordinates.py b/src/opengeodeweb_back/routes/schemas/texture_coordinates.py index 5aa9fb66..fbee6890 100644 --- a/src/opengeodeweb_back/routes/schemas/texture_coordinates.py +++ b/src/opengeodeweb_back/routes/schemas/texture_coordinates.py @@ -1,41 +1,6 @@ -# type: ignore -from typing import Any, TypeVar, Type, cast - - -T = TypeVar("T") - - -def from_str(x: Any) -> str: - assert isinstance(x, str) - return x - - -def to_class(c: Type[T], x: Any) -> dict: - assert isinstance(x, c) - return cast(Any, x).to_dict() +from dataclasses import dataclass +@dataclass class TextureCoordinates: id: str - - def __init__(self, id: str) -> None: - self.id = id - - @staticmethod - def from_dict(obj: Any) -> "TextureCoordinates": - assert isinstance(obj, dict) - id = from_str(obj.get("id")) - return TextureCoordinates(id) - - def to_dict(self) -> dict: - result: dict = {} - result["id"] = from_str(self.id) - return result - - -def texture_coordinates_from_dict(s: Any) -> TextureCoordinates: - return TextureCoordinates.from_dict(s) - - -def texture_coordinates_to_dict(x: TextureCoordinates) -> Any: - return to_class(TextureCoordinates, x) diff --git a/src/opengeodeweb_back/routes/schemas/upload_file.py b/src/opengeodeweb_back/routes/schemas/upload_file.py index 384da7cf..6c10a217 100644 --- a/src/opengeodeweb_back/routes/schemas/upload_file.py +++ b/src/opengeodeweb_back/routes/schemas/upload_file.py @@ -1,56 +1,7 @@ -# type: ignore -from typing import Optional, Any, TypeVar, Type, cast - - -T = TypeVar("T") - - -def from_str(x: Any) -> str: - assert isinstance(x, str) - return x - - -def from_none(x: Any) -> Any: - assert x is None - return x - - -def from_union(fs, x): - for f in fs: - try: - return f(x) - except: - pass - assert False - - -def to_class(c: Type[T], x: Any) -> dict: - assert isinstance(x, c) - return cast(Any, x).to_dict() +from dataclasses import dataclass +from typing import Optional +@dataclass class UploadFile: - filename: Optional[str] - - def __init__(self, filename: Optional[str]) -> None: - self.filename = filename - - @staticmethod - def from_dict(obj: Any) -> "UploadFile": - assert isinstance(obj, dict) - filename = from_union([from_str, from_none], obj.get("filename")) - return UploadFile(filename) - - def to_dict(self) -> dict: - result: dict = {} - if self.filename is not None: - result["filename"] = from_union([from_str, from_none], self.filename) - return result - - -def upload_file_from_dict(s: Any) -> UploadFile: - return UploadFile.from_dict(s) - - -def upload_file_to_dict(x: UploadFile) -> Any: - return to_class(UploadFile, x) + filename: Optional[str] = None diff --git a/src/opengeodeweb_back/routes/schemas/vertex_attribute_names.py b/src/opengeodeweb_back/routes/schemas/vertex_attribute_names.py index bbc873a6..a205f08d 100644 --- a/src/opengeodeweb_back/routes/schemas/vertex_attribute_names.py +++ b/src/opengeodeweb_back/routes/schemas/vertex_attribute_names.py @@ -1,41 +1,6 @@ -# type: ignore -from typing import Any, TypeVar, Type, cast - - -T = TypeVar("T") - - -def from_str(x: Any) -> str: - assert isinstance(x, str) - return x - - -def to_class(c: Type[T], x: Any) -> dict: - assert isinstance(x, c) - return cast(Any, x).to_dict() +from dataclasses import dataclass +@dataclass class VertexAttributeNames: id: str - - def __init__(self, id: str) -> None: - self.id = id - - @staticmethod - def from_dict(obj: Any) -> "VertexAttributeNames": - assert isinstance(obj, dict) - id = from_str(obj.get("id")) - return VertexAttributeNames(id) - - def to_dict(self) -> dict: - result: dict = {} - result["id"] = from_str(self.id) - return result - - -def vertex_attribute_names_from_dict(s: Any) -> VertexAttributeNames: - return VertexAttributeNames.from_dict(s) - - -def vertex_attribute_names_to_dict(x: VertexAttributeNames) -> Any: - return to_class(VertexAttributeNames, x) From 00a6f45a5aaec6f0b2e461f64d0b9514af6944ff Mon Sep 17 00:00:00 2001 From: Arnaud Botella Date: Mon, 20 Oct 2025 21:39:46 +0200 Subject: [PATCH 07/14] fix(Schemas): using typed schemas --- src/opengeodeweb_back/geode_functions.py | 4 +- .../routes/blueprint_routes.py | 152 +++++++++--------- .../routes/create/blueprint_create.py | 20 +-- .../routes/create/schemas/__init__.py | 2 + .../routes/models/blueprint_models.py | 44 +++-- .../routes/models/schemas/__init__.py | 2 + .../routes/schemas/__init__.py | 14 ++ src/opengeodeweb_back/utils_functions.py | 4 +- 8 files changed, 126 insertions(+), 116 deletions(-) create mode 100644 src/opengeodeweb_back/routes/create/schemas/__init__.py create mode 100644 src/opengeodeweb_back/routes/models/schemas/__init__.py create mode 100644 src/opengeodeweb_back/routes/schemas/__init__.py diff --git a/src/opengeodeweb_back/geode_functions.py b/src/opengeodeweb_back/geode_functions.py index de58c47b..f96b7074 100644 --- a/src/opengeodeweb_back/geode_functions.py +++ b/src/opengeodeweb_back/geode_functions.py @@ -175,7 +175,7 @@ def filter_geode_objects(key: str = None): return geode_objects_filtered_list -def list_input_extensions(key: str = None): +def list_input_extensions(key: str | None = None): extensions_list = [] geode_objects_filtered_list = filter_geode_objects(key) for geode_object in geode_objects_filtered_list: @@ -192,7 +192,7 @@ def has_creator(geode_object: str, extension: str): def list_geode_objects( file_absolute_path: str, - key: str = None, + key: str | None = None, ): return_dict = {} file_extension = utils_functions.extension_from_filename( diff --git a/src/opengeodeweb_back/routes/blueprint_routes.py b/src/opengeodeweb_back/routes/blueprint_routes.py index 5683c3c8..ab66f903 100644 --- a/src/opengeodeweb_back/routes/blueprint_routes.py +++ b/src/opengeodeweb_back/routes/blueprint_routes.py @@ -5,14 +5,12 @@ # Third party imports import flask -import opengeode import werkzeug # Local application imports -from .. import geode_functions, utils_functions -from opengeodeweb_microservice.database.data import Data -from opengeodeweb_microservice.database.connection import get_session +from opengeodeweb_back import geode_functions, utils_functions from .models import blueprint_models +from . import schemas routes = flask.Blueprint("routes", __name__, url_prefix="/opengeodeweb_back") @@ -23,39 +21,38 @@ name=blueprint_models.routes.name, ) -schemas = os.path.join(os.path.dirname(__file__), "schemas") +schemas_folder = os.path.join(os.path.dirname(__file__), "schemas") with open( - os.path.join(schemas, "allowed_files.json"), + os.path.join(schemas_folder, "allowed_files.json"), "r", ) as file: - allowed_files_json = json.load(file) + allowed_files_json: utils_functions.SchemaDict = json.load(file) @routes.route( allowed_files_json["route"], methods=allowed_files_json["methods"], ) -def allowed_files(): +def allowed_files() -> flask.Response: utils_functions.validate_request(flask.request, allowed_files_json) - extensions = geode_functions.list_input_extensions( - flask.request.get_json()["supported_feature"] - ) + params = schemas.AllowedFiles(**flask.request.get_json()) + extensions = geode_functions.list_input_extensions(params.supported_feature) return flask.make_response({"extensions": extensions}, 200) with open( - os.path.join(schemas, "upload_file.json"), + os.path.join(schemas_folder, "upload_file.json"), "r", ) as file: - upload_file_json = json.load(file) + upload_file_json: utils_functions.SchemaDict = json.load(file) @routes.route( upload_file_json["route"], methods=upload_file_json["methods"], ) -def upload_file(): +def upload_file() -> flask.Response: if flask.request.method == "OPTIONS": return flask.make_response({}, 200) @@ -69,47 +66,47 @@ def upload_file(): with open( - os.path.join(schemas, "allowed_objects.json"), + os.path.join(schemas_folder, "allowed_objects.json"), "r", ) as file: - allowed_objects_json = json.load(file) + allowed_objects_json: utils_functions.SchemaDict = json.load(file) @routes.route( allowed_objects_json["route"], methods=allowed_objects_json["methods"], ) -def allowed_objects(): +def allowed_objects() -> flask.Response: if flask.request.method == "OPTIONS": return flask.make_response({}, 200) utils_functions.validate_request(flask.request, allowed_objects_json) - file_absolute_path = geode_functions.upload_file_path( - flask.request.get_json()["filename"] - ) + params = schemas.AllowedObjects(**flask.request.get_json()) + file_absolute_path = geode_functions.upload_file_path(params.filename) allowed_objects = geode_functions.list_geode_objects( - file_absolute_path, flask.request.get_json()["supported_feature"] + file_absolute_path, params.supported_feature ) return flask.make_response({"allowed_objects": allowed_objects}, 200) with open( - os.path.join(schemas, "missing_files.json"), + os.path.join(schemas_folder, "missing_files.json"), "r", ) as file: - missing_files_json = json.load(file) + missing_files_json: utils_functions.SchemaDict = json.load(file) @routes.route( missing_files_json["route"], methods=missing_files_json["methods"], ) -def missing_files(): +def missing_files() -> flask.Response: utils_functions.validate_request(flask.request, missing_files_json) - file_path = geode_functions.upload_file_path(flask.request.get_json()["filename"]) + params = schemas.MissingFiles(**flask.request.get_json()) + file_path = geode_functions.upload_file_path(params.filename) additional_files = geode_functions.additional_files( - flask.request.get_json()["input_geode_object"], + params.input_geode_object, file_path, ) @@ -140,21 +137,20 @@ def missing_files(): with open( - os.path.join(schemas, "geographic_coordinate_systems.json"), + os.path.join(schemas_folder, "geographic_coordinate_systems.json"), "r", ) as file: - geographic_coordinate_systems_json = json.load(file) + geographic_coordinate_systems_json: utils_functions.SchemaDict = json.load(file) @routes.route( geographic_coordinate_systems_json["route"], methods=geographic_coordinate_systems_json["methods"], ) -def crs_converter_geographic_coordinate_systems(): +def crs_converter_geographic_coordinate_systems() -> flask.Response: utils_functions.validate_request(flask.request, geographic_coordinate_systems_json) - infos = geode_functions.geographic_coordinate_systems( - flask.request.get_json()["input_geode_object"] - ) + params = schemas.GeographicCoordinateSystems(**flask.request.get_json()) + infos = geode_functions.geographic_coordinate_systems(params.input_geode_object) crs_list = [] for info in infos: crs = {} @@ -167,54 +163,51 @@ def crs_converter_geographic_coordinate_systems(): with open( - os.path.join(schemas, "inspect_file.json"), + os.path.join(schemas_folder, "inspect_file.json"), "r", ) as file: - inspect_file_json = json.load(file) + inspect_file_json: utils_functions.SchemaDict = json.load(file) @routes.route( inspect_file_json["route"], methods=inspect_file_json["methods"], ) -def inspect_file(): +def inspect_file() -> flask.Response: utils_functions.validate_request(flask.request, inspect_file_json) - - file_path = geode_functions.upload_file_path(flask.request.get_json()["filename"]) - data = geode_functions.load( - flask.request.get_json()["input_geode_object"], file_path - ) - class_inspector = geode_functions.inspect( - flask.request.get_json()["input_geode_object"], data - ) + params = schemas.InspectFile(**flask.request.get_json()) + file_path = geode_functions.upload_file_path(params.filename) + data = geode_functions.load(params.input_geode_object, file_path) + class_inspector = geode_functions.inspect(params.input_geode_object, data) inspection_result = geode_functions.get_inspector_children(class_inspector) return flask.make_response({"inspection_result": inspection_result}, 200) with open( - os.path.join(schemas, "geode_objects_and_output_extensions.json"), + os.path.join(schemas_folder, "geode_objects_and_output_extensions.json"), "r", ) as file: - geode_objects_and_output_extensions_json = json.load(file) + geode_objects_and_output_extensions_json: utils_functions.SchemaDict = json.load( + file + ) @routes.route( geode_objects_and_output_extensions_json["route"], methods=geode_objects_and_output_extensions_json["methods"], ) -def geode_objects_and_output_extensions(): +def geode_objects_and_output_extensions() -> flask.Response: utils_functions.validate_request( flask.request, geode_objects_and_output_extensions_json ) - file_path = geode_functions.upload_file_path(flask.request.get_json()["filename"]) + params = schemas.GeodeObjectsAndOutputExtensions(**flask.request.get_json()) + file_path = geode_functions.upload_file_path(params.filename) data = geode_functions.load( - flask.request.get_json()["input_geode_object"], + params.input_geode_object, file_path, ) geode_objects_and_output_extensions = ( - geode_functions.geode_objects_output_extensions( - flask.request.get_json()["input_geode_object"], data - ) + geode_functions.geode_objects_output_extensions(params.input_geode_object, data) ) return flask.make_response( {"geode_objects_and_output_extensions": geode_objects_and_output_extensions}, @@ -223,56 +216,59 @@ def geode_objects_and_output_extensions(): with open( - os.path.join(schemas, "save_viewable_file.json"), + os.path.join(schemas_folder, "save_viewable_file.json"), "r", ) as file: - save_viewable_file_json = json.load(file) + save_viewable_file_json: utils_functions.SchemaDict = json.load(file) @routes.route( save_viewable_file_json["route"], methods=save_viewable_file_json["methods"], ) -def save_viewable_file(): +def save_viewable_file() -> flask.Response: utils_functions.validate_request(flask.request, save_viewable_file_json) + params = schemas.SaveViewableFile(**flask.request.get_json()) return flask.make_response( utils_functions.generate_native_viewable_and_light_viewable_from_file( - geode_object=flask.request.get_json()["input_geode_object"], - input_filename=flask.request.get_json()["filename"], + geode_object=params.input_geode_object, + input_filename=params.filename, ), 200, ) -with open(os.path.join(schemas, "texture_coordinates.json"), "r") as file: - texture_coordinates_json = json.load(file) +with open(os.path.join(schemas_folder, "texture_coordinates.json"), "r") as file: + texture_coordinates_json: utils_functions.SchemaDict = json.load(file) @routes.route( texture_coordinates_json["route"], methods=texture_coordinates_json["methods"], ) -def texture_coordinates(): +def texture_coordinates() -> flask.Response: utils_functions.validate_request(flask.request, texture_coordinates_json) - data = geode_functions.load_data(flask.request.get_json().get("id")) + params = schemas.TextureCoordinates(**flask.request.get_json()) + data = geode_functions.load_data(params.id) texture_coordinates = data.texture_manager().texture_names() return flask.make_response({"texture_coordinates": texture_coordinates}, 200) with open( - os.path.join(schemas, "vertex_attribute_names.json"), + os.path.join(schemas_folder, "vertex_attribute_names.json"), "r", ) as file: - vertex_attribute_names_json = json.load(file) + vertex_attribute_names_json: utils_functions.SchemaDict = json.load(file) @routes.route( vertex_attribute_names_json["route"], methods=vertex_attribute_names_json["methods"], ) -def vertex_attribute_names(): +def vertex_attribute_names() -> flask.Response: utils_functions.validate_request(flask.request, vertex_attribute_names_json) - data = geode_functions.load_data(flask.request.get_json().get("id")) + params = schemas.VertexAttributeNames(**flask.request.get_json()) + data = geode_functions.load_data(params.id) vertex_attribute_names = data.vertex_attribute_manager().attribute_names() return flask.make_response( { @@ -283,19 +279,20 @@ def vertex_attribute_names(): with open( - os.path.join(schemas, "polygon_attribute_names.json"), + os.path.join(schemas_folder, "polygon_attribute_names.json"), "r", ) as file: - polygon_attribute_names_json = json.load(file) + polygon_attribute_names_json: utils_functions.SchemaDict = json.load(file) @routes.route( polygon_attribute_names_json["route"], methods=polygon_attribute_names_json["methods"], ) -def polygon_attribute_names(): +def polygon_attribute_names() -> flask.Response: utils_functions.validate_request(flask.request, polygon_attribute_names_json) - data = geode_functions.load_data(flask.request.get_json().get("id")) + params = schemas.PolygonAttributeNames(**flask.request.get_json()) + data = geode_functions.load_data(params.id) polygon_attribute_names = data.polygon_attribute_manager().attribute_names() return flask.make_response( { @@ -306,19 +303,20 @@ def polygon_attribute_names(): with open( - os.path.join(schemas, "polyhedron_attribute_names.json"), + os.path.join(schemas_folder, "polyhedron_attribute_names.json"), "r", ) as file: - polyhedron_attribute_names_json = json.load(file) + polyhedron_attribute_names_json: utils_functions.SchemaDict = json.load(file) @routes.route( polyhedron_attribute_names_json["route"], methods=polyhedron_attribute_names_json["methods"], ) -def polyhedron_attribute_names(): +def polyhedron_attribute_names() -> flask.Response: utils_functions.validate_request(flask.request, polyhedron_attribute_names_json) - data = geode_functions.load_data(flask.request.get_json().get("id")) + params = schemas.PolyhedronAttributeNames(**flask.request.get_json()) + data = geode_functions.load_data(params.id) polyhedron_attribute_names = data.polyhedron_attribute_manager().attribute_names() return flask.make_response( { @@ -329,27 +327,27 @@ def polyhedron_attribute_names(): with open( - os.path.join(schemas, "ping.json"), + os.path.join(schemas_folder, "ping.json"), "r", ) as file: - ping_json = json.load(file) + ping_json: utils_functions.SchemaDict = json.load(file) @routes.route( ping_json["route"], methods=ping_json["methods"], ) -def ping(): +def ping() -> flask.Response: utils_functions.validate_request(flask.request, ping_json) flask.current_app.config.update(LAST_PING_TIME=time.time()) return flask.make_response({"message": "Flask server is running"}, 200) with open( - os.path.join(schemas, "kill.json"), + os.path.join(schemas_folder, "kill.json"), "r", ) as file: - kill_json = json.load(file) + kill_json: utils_functions.SchemaDict = json.load(file) @routes.route(kill_json["route"], methods=kill_json["methods"]) diff --git a/src/opengeodeweb_back/routes/create/blueprint_create.py b/src/opengeodeweb_back/routes/create/blueprint_create.py index f021c034..42ccc6aa 100644 --- a/src/opengeodeweb_back/routes/create/blueprint_create.py +++ b/src/opengeodeweb_back/routes/create/blueprint_create.py @@ -9,19 +9,15 @@ # Local application imports from opengeodeweb_back import geode_functions, utils_functions -from opengeodeweb_back.routes.create.schemas.create_aoi import CreateAoi -from opengeodeweb_back.routes.create.schemas.create_point import CreatePoint +from . import schemas routes = flask.Blueprint("create", __name__, url_prefix="/create") -schemas = os.path.join(os.path.dirname(__file__), "schemas") - -# --- Type definitions --- -type SchemaDict = dict[str, Any] +schemas_folder = os.path.join(os.path.dirname(__file__), "schemas") # Load schemas -with open(os.path.join(schemas, "create_point.json"), "r") as file: - create_point_json: SchemaDict = json.load(file) +with open(os.path.join(schemas_folder, "create_point.json"), "r") as file: + create_point_json: utils_functions.SchemaDict = json.load(file) @routes.route(create_point_json["route"], methods=create_point_json["methods"]) @@ -29,7 +25,7 @@ def create_point() -> flask.Response: """Endpoint to create a single point in 3D space.""" print(f"create_point : {flask.request=}", flush=True) utils_functions.validate_request(flask.request, create_point_json) - params = CreatePoint(**flask.request.get_json()) + params = schemas.CreatePoint(**flask.request.get_json()) # Create the point class_ = geode_functions.geode_object_class("PointSet3D") @@ -47,8 +43,8 @@ def create_point() -> flask.Response: # Load schema for AOI creation -with open(os.path.join(schemas, "create_aoi.json"), "r") as file: - create_aoi_json: SchemaDict = json.load(file) +with open(os.path.join(schemas_folder, "create_aoi.json"), "r") as file: + create_aoi_json: utils_functions.SchemaDict = json.load(file) @routes.route(create_aoi_json["route"], methods=create_aoi_json["methods"]) @@ -56,7 +52,7 @@ def create_aoi() -> flask.Response: """Endpoint to create an Area of Interest (AOI) as an EdgedCurve3D.""" print(f"create_aoi : {flask.request=}", flush=True) utils_functions.validate_request(flask.request, create_aoi_json) - params = CreateAoi(**flask.request.get_json()) + params = schemas.CreateAoi(**flask.request.get_json()) # Create the edged curve class_ = geode_functions.geode_object_class("EdgedCurve3D") diff --git a/src/opengeodeweb_back/routes/create/schemas/__init__.py b/src/opengeodeweb_back/routes/create/schemas/__init__.py new file mode 100644 index 00000000..8dd0b149 --- /dev/null +++ b/src/opengeodeweb_back/routes/create/schemas/__init__.py @@ -0,0 +1,2 @@ +from .create_aoi import * +from .create_point import * diff --git a/src/opengeodeweb_back/routes/models/blueprint_models.py b/src/opengeodeweb_back/routes/models/blueprint_models.py index 02209f2e..e465d0f2 100644 --- a/src/opengeodeweb_back/routes/models/blueprint_models.py +++ b/src/opengeodeweb_back/routes/models/blueprint_models.py @@ -2,28 +2,28 @@ import os import xml.etree.ElementTree as ET import flask -from ... import geode_functions, utils_functions - -routes = flask.Blueprint("models", __name__, url_prefix="/models") +from opengeodeweb_back import geode_functions, utils_functions +from . import schemas -schemas = os.path.join(os.path.dirname(__file__), "schemas") +routes = flask.Blueprint("models", __name__, url_prefix="/models") +schemas_folder = os.path.join(os.path.dirname(__file__), "schemas") -with open(os.path.join(schemas, "vtm_component_indices.json"), "r") as file: - vtm_component_indices_json = json.load(file) +with open(os.path.join(schemas_folder, "vtm_component_indices.json"), "r") as file: + vtm_component_indices_json: utils_functions.SchemaDict = json.load(file) @routes.route( vtm_component_indices_json["route"], methods=vtm_component_indices_json["methods"] ) -def uuid_to_flat_index(): +def uuid_to_flat_index() -> flask.Response: utils_functions.validate_request(flask.request, vtm_component_indices_json) - - vtm_file_path = geode_functions.data_file_path( - flask.request.get_json().get("id"), "viewable.vtm" - ) + params = schemas.VtmComponentIndices(**flask.request.get_json()) + vtm_file_path = geode_functions.data_file_path(params.id, "viewable.vtm") tree = ET.parse(vtm_file_path) root = tree.find("vtkMultiBlockDataSet") + if not root: + raise Exception("Failed to read viewable file") uuid_to_flat_index = {} current_index = 0 for elem in root.iter(): @@ -33,22 +33,18 @@ def uuid_to_flat_index(): return flask.make_response({"uuid_to_flat_index": uuid_to_flat_index}, 200) -def extract_model_uuids(model): +with open(os.path.join(schemas_folder, "mesh_components.json"), "r") as file: + mesh_components_json: utils_functions.SchemaDict = json.load(file) + + +@routes.route(mesh_components_json["route"], methods=mesh_components_json["methods"]) +def extract_uuids_endpoint() -> flask.Response: + utils_functions.validate_request(flask.request, mesh_components_json) + params = schemas.MeshComponents(**flask.request.get_json()) + model = geode_functions.load_data(params.id) mesh_components = model.mesh_components() uuid_dict = {} for mesh_component, ids in mesh_components.items(): component_name = mesh_component.get() uuid_dict[component_name] = [id.string() for id in ids] - return uuid_dict - - -with open(os.path.join(schemas, "mesh_components.json"), "r") as file: - mesh_components_json = json.load(file) - - -@routes.route(mesh_components_json["route"], methods=mesh_components_json["methods"]) -def extract_uuids_endpoint(): - utils_functions.validate_request(flask.request, mesh_components_json) - model = geode_functions.load_data(flask.request.get_json().get("id")) - uuid_dict = extract_model_uuids(model) return flask.make_response({"uuid_dict": uuid_dict}, 200) diff --git a/src/opengeodeweb_back/routes/models/schemas/__init__.py b/src/opengeodeweb_back/routes/models/schemas/__init__.py new file mode 100644 index 00000000..ac9e0588 --- /dev/null +++ b/src/opengeodeweb_back/routes/models/schemas/__init__.py @@ -0,0 +1,2 @@ +from .mesh_components import * +from .vtm_component_indices import * diff --git a/src/opengeodeweb_back/routes/schemas/__init__.py b/src/opengeodeweb_back/routes/schemas/__init__.py new file mode 100644 index 00000000..926464ad --- /dev/null +++ b/src/opengeodeweb_back/routes/schemas/__init__.py @@ -0,0 +1,14 @@ +from .allowed_files import * +from .allowed_objects import * +from .geode_objects_and_output_extensions import * +from .geographic_coordinate_systems import * +from .inspect_file import * +from .kill import * +from .missing_files import * +from .ping import * +from .polygon_attribute_names import * +from .polyhedron_attribute_names import * +from .save_viewable_file import * +from .texture_coordinates import * +from .upload_file import * +from .vertex_attribute_names import * diff --git a/src/opengeodeweb_back/utils_functions.py b/src/opengeodeweb_back/utils_functions.py index 2f2b3d54..2fada2aa 100644 --- a/src/opengeodeweb_back/utils_functions.py +++ b/src/opengeodeweb_back/utils_functions.py @@ -19,6 +19,8 @@ from opengeodeweb_microservice.database.data import Data from opengeodeweb_microservice.database.connection import get_session +type SchemaDict = dict[str, str] + def increment_request_counter(current_app: flask.Flask) -> None: if "REQUEST_COUNTER" in current_app.config: @@ -97,7 +99,7 @@ def versions(list_packages: list[str]) -> list[dict[str, str]]: return list_with_versions -def validate_request(request: flask.Request, schema: dict[str, str]) -> None: +def validate_request(request: flask.Request, schema: SchemaDict) -> None: json_data = request.get_json(force=True, silent=True) if json_data is None: From 644db202c6c9a242df91c13c38b9771bb6e17b6b Mon Sep 17 00:00:00 2001 From: Arnaud Botella Date: Mon, 20 Oct 2025 21:42:35 +0200 Subject: [PATCH 08/14] mypy --- src/opengeodeweb_back/geode_functions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/opengeodeweb_back/geode_functions.py b/src/opengeodeweb_back/geode_functions.py index f96b7074..c9e8fbbd 100644 --- a/src/opengeodeweb_back/geode_functions.py +++ b/src/opengeodeweb_back/geode_functions.py @@ -175,7 +175,7 @@ def filter_geode_objects(key: str = None): return geode_objects_filtered_list -def list_input_extensions(key: str | None = None): +def list_input_extensions(key: str | None = None) -> list[str]: extensions_list = [] geode_objects_filtered_list = filter_geode_objects(key) for geode_object in geode_objects_filtered_list: From a0306ad20faf0afccf9ecc6995ac45ada0b57aac Mon Sep 17 00:00:00 2001 From: Arnaud Botella Date: Tue, 21 Oct 2025 08:57:46 +0200 Subject: [PATCH 09/14] better --- .../routes/blueprint_routes.py | 186 +++++------------- .../routes/create/blueprint_create.py | 27 ++- .../routes/models/blueprint_models.py | 27 +-- src/opengeodeweb_back/utils_functions.py | 13 ++ 4 files changed, 89 insertions(+), 164 deletions(-) diff --git a/src/opengeodeweb_back/routes/blueprint_routes.py b/src/opengeodeweb_back/routes/blueprint_routes.py index ab66f903..ea36606b 100644 --- a/src/opengeodeweb_back/routes/blueprint_routes.py +++ b/src/opengeodeweb_back/routes/blueprint_routes.py @@ -21,36 +21,25 @@ name=blueprint_models.routes.name, ) -schemas_folder = os.path.join(os.path.dirname(__file__), "schemas") - -with open( - os.path.join(schemas_folder, "allowed_files.json"), - "r", -) as file: - allowed_files_json: utils_functions.SchemaDict = json.load(file) +schemas_dict = utils_functions.get_schemas_dict( + os.path.join(os.path.dirname(__file__), "schemas") +) @routes.route( - allowed_files_json["route"], - methods=allowed_files_json["methods"], + schemas_dict["allowed_files"]["route"], + methods=schemas_dict["allowed_files"]["methods"], ) def allowed_files() -> flask.Response: - utils_functions.validate_request(flask.request, allowed_files_json) + utils_functions.validate_request(flask.request, schemas_dict["allowed_files"]) params = schemas.AllowedFiles(**flask.request.get_json()) extensions = geode_functions.list_input_extensions(params.supported_feature) return flask.make_response({"extensions": extensions}, 200) -with open( - os.path.join(schemas_folder, "upload_file.json"), - "r", -) as file: - upload_file_json: utils_functions.SchemaDict = json.load(file) - - @routes.route( - upload_file_json["route"], - methods=upload_file_json["methods"], + schemas_dict["upload_file"]["route"], + methods=schemas_dict["upload_file"]["methods"], ) def upload_file() -> flask.Response: if flask.request.method == "OPTIONS": @@ -65,22 +54,15 @@ def upload_file() -> flask.Response: return flask.make_response({"message": "File uploaded"}, 201) -with open( - os.path.join(schemas_folder, "allowed_objects.json"), - "r", -) as file: - allowed_objects_json: utils_functions.SchemaDict = json.load(file) - - @routes.route( - allowed_objects_json["route"], - methods=allowed_objects_json["methods"], + schemas_dict["allowed_objects"]["route"], + methods=schemas_dict["allowed_objects"]["methods"], ) def allowed_objects() -> flask.Response: if flask.request.method == "OPTIONS": return flask.make_response({}, 200) - utils_functions.validate_request(flask.request, allowed_objects_json) + utils_functions.validate_request(flask.request, schemas_dict["allowed_objects"]) params = schemas.AllowedObjects(**flask.request.get_json()) file_absolute_path = geode_functions.upload_file_path(params.filename) allowed_objects = geode_functions.list_geode_objects( @@ -89,19 +71,12 @@ def allowed_objects() -> flask.Response: return flask.make_response({"allowed_objects": allowed_objects}, 200) -with open( - os.path.join(schemas_folder, "missing_files.json"), - "r", -) as file: - missing_files_json: utils_functions.SchemaDict = json.load(file) - - @routes.route( - missing_files_json["route"], - methods=missing_files_json["methods"], + schemas_dict["missing_files"]["route"], + methods=schemas_dict["missing_files"]["methods"], ) def missing_files() -> flask.Response: - utils_functions.validate_request(flask.request, missing_files_json) + utils_functions.validate_request(flask.request, schemas_dict["missing_files"]) params = schemas.MissingFiles(**flask.request.get_json()) file_path = geode_functions.upload_file_path(params.filename) @@ -136,19 +111,14 @@ def missing_files() -> flask.Response: ) -with open( - os.path.join(schemas_folder, "geographic_coordinate_systems.json"), - "r", -) as file: - geographic_coordinate_systems_json: utils_functions.SchemaDict = json.load(file) - - @routes.route( - geographic_coordinate_systems_json["route"], - methods=geographic_coordinate_systems_json["methods"], + schemas_dict["geographic_coordinate_systems"]["route"], + methods=schemas_dict["geographic_coordinate_systems"]["methods"], ) def crs_converter_geographic_coordinate_systems() -> flask.Response: - utils_functions.validate_request(flask.request, geographic_coordinate_systems_json) + utils_functions.validate_request( + flask.request, schemas_dict["geographic_coordinate_systems"] + ) params = schemas.GeographicCoordinateSystems(**flask.request.get_json()) infos = geode_functions.geographic_coordinate_systems(params.input_geode_object) crs_list = [] @@ -162,19 +132,12 @@ def crs_converter_geographic_coordinate_systems() -> flask.Response: return flask.make_response({"crs_list": crs_list}, 200) -with open( - os.path.join(schemas_folder, "inspect_file.json"), - "r", -) as file: - inspect_file_json: utils_functions.SchemaDict = json.load(file) - - @routes.route( - inspect_file_json["route"], - methods=inspect_file_json["methods"], + schemas_dict["inspect_file"]["route"], + methods=schemas_dict["inspect_file"]["methods"], ) def inspect_file() -> flask.Response: - utils_functions.validate_request(flask.request, inspect_file_json) + utils_functions.validate_request(flask.request, schemas_dict["inspect_file"]) params = schemas.InspectFile(**flask.request.get_json()) file_path = geode_functions.upload_file_path(params.filename) data = geode_functions.load(params.input_geode_object, file_path) @@ -183,22 +146,13 @@ def inspect_file() -> flask.Response: return flask.make_response({"inspection_result": inspection_result}, 200) -with open( - os.path.join(schemas_folder, "geode_objects_and_output_extensions.json"), - "r", -) as file: - geode_objects_and_output_extensions_json: utils_functions.SchemaDict = json.load( - file - ) - - @routes.route( - geode_objects_and_output_extensions_json["route"], - methods=geode_objects_and_output_extensions_json["methods"], + schemas_dict["geode_objects_and_output_extensions"]["route"], + methods=schemas_dict["geode_objects_and_output_extensions"]["methods"], ) def geode_objects_and_output_extensions() -> flask.Response: utils_functions.validate_request( - flask.request, geode_objects_and_output_extensions_json + flask.request, schemas_dict["geode_objects_and_output_extensions"] ) params = schemas.GeodeObjectsAndOutputExtensions(**flask.request.get_json()) file_path = geode_functions.upload_file_path(params.filename) @@ -215,19 +169,12 @@ def geode_objects_and_output_extensions() -> flask.Response: ) -with open( - os.path.join(schemas_folder, "save_viewable_file.json"), - "r", -) as file: - save_viewable_file_json: utils_functions.SchemaDict = json.load(file) - - @routes.route( - save_viewable_file_json["route"], - methods=save_viewable_file_json["methods"], + schemas_dict["save_viewable_file"]["route"], + methods=schemas_dict["save_viewable_file"]["methods"], ) def save_viewable_file() -> flask.Response: - utils_functions.validate_request(flask.request, save_viewable_file_json) + utils_functions.validate_request(flask.request, schemas_dict["save_viewable_file"]) params = schemas.SaveViewableFile(**flask.request.get_json()) return flask.make_response( utils_functions.generate_native_viewable_and_light_viewable_from_file( @@ -238,35 +185,26 @@ def save_viewable_file() -> flask.Response: ) -with open(os.path.join(schemas_folder, "texture_coordinates.json"), "r") as file: - texture_coordinates_json: utils_functions.SchemaDict = json.load(file) - - @routes.route( - texture_coordinates_json["route"], - methods=texture_coordinates_json["methods"], + schemas_dict["texture_coordinates"]["route"], + methods=schemas_dict["texture_coordinates"]["methods"], ) def texture_coordinates() -> flask.Response: - utils_functions.validate_request(flask.request, texture_coordinates_json) + utils_functions.validate_request(flask.request, schemas_dict["texture_coordinates"]) params = schemas.TextureCoordinates(**flask.request.get_json()) data = geode_functions.load_data(params.id) texture_coordinates = data.texture_manager().texture_names() return flask.make_response({"texture_coordinates": texture_coordinates}, 200) -with open( - os.path.join(schemas_folder, "vertex_attribute_names.json"), - "r", -) as file: - vertex_attribute_names_json: utils_functions.SchemaDict = json.load(file) - - @routes.route( - vertex_attribute_names_json["route"], - methods=vertex_attribute_names_json["methods"], + schemas_dict["vertex_attribute_names"]["route"], + methods=schemas_dict["vertex_attribute_names"]["methods"], ) def vertex_attribute_names() -> flask.Response: - utils_functions.validate_request(flask.request, vertex_attribute_names_json) + utils_functions.validate_request( + flask.request, schemas_dict["vertex_attribute_names"] + ) params = schemas.VertexAttributeNames(**flask.request.get_json()) data = geode_functions.load_data(params.id) vertex_attribute_names = data.vertex_attribute_manager().attribute_names() @@ -278,19 +216,14 @@ def vertex_attribute_names() -> flask.Response: ) -with open( - os.path.join(schemas_folder, "polygon_attribute_names.json"), - "r", -) as file: - polygon_attribute_names_json: utils_functions.SchemaDict = json.load(file) - - @routes.route( - polygon_attribute_names_json["route"], - methods=polygon_attribute_names_json["methods"], + schemas_dict["polygon_attribute_names"]["route"], + methods=schemas_dict["polygon_attribute_names"]["methods"], ) def polygon_attribute_names() -> flask.Response: - utils_functions.validate_request(flask.request, polygon_attribute_names_json) + utils_functions.validate_request( + flask.request, schemas_dict["polygon_attribute_names"] + ) params = schemas.PolygonAttributeNames(**flask.request.get_json()) data = geode_functions.load_data(params.id) polygon_attribute_names = data.polygon_attribute_manager().attribute_names() @@ -302,19 +235,14 @@ def polygon_attribute_names() -> flask.Response: ) -with open( - os.path.join(schemas_folder, "polyhedron_attribute_names.json"), - "r", -) as file: - polyhedron_attribute_names_json: utils_functions.SchemaDict = json.load(file) - - @routes.route( - polyhedron_attribute_names_json["route"], - methods=polyhedron_attribute_names_json["methods"], + schemas_dict["polyhedron_attribute_names"]["route"], + methods=schemas_dict["polyhedron_attribute_names"]["methods"], ) def polyhedron_attribute_names() -> flask.Response: - utils_functions.validate_request(flask.request, polyhedron_attribute_names_json) + utils_functions.validate_request( + flask.request, schemas_dict["polyhedron_attribute_names"] + ) params = schemas.PolyhedronAttributeNames(**flask.request.get_json()) data = geode_functions.load_data(params.id) polyhedron_attribute_names = data.polyhedron_attribute_manager().attribute_names() @@ -326,31 +254,17 @@ def polyhedron_attribute_names() -> flask.Response: ) -with open( - os.path.join(schemas_folder, "ping.json"), - "r", -) as file: - ping_json: utils_functions.SchemaDict = json.load(file) - - @routes.route( - ping_json["route"], - methods=ping_json["methods"], + schemas_dict["ping"]["route"], + methods=schemas_dict["ping"]["methods"], ) def ping() -> flask.Response: - utils_functions.validate_request(flask.request, ping_json) + utils_functions.validate_request(flask.request, schemas_dict["ping"]) flask.current_app.config.update(LAST_PING_TIME=time.time()) return flask.make_response({"message": "Flask server is running"}, 200) -with open( - os.path.join(schemas_folder, "kill.json"), - "r", -) as file: - kill_json: utils_functions.SchemaDict = json.load(file) - - -@routes.route(kill_json["route"], methods=kill_json["methods"]) +@routes.route(schemas_dict["kill"]["route"], methods=schemas_dict["kill"]["methods"]) def kill() -> flask.Response: print("Manual server kill, shutting down...", flush=True) os._exit(0) diff --git a/src/opengeodeweb_back/routes/create/blueprint_create.py b/src/opengeodeweb_back/routes/create/blueprint_create.py index 42ccc6aa..5bec3fff 100644 --- a/src/opengeodeweb_back/routes/create/blueprint_create.py +++ b/src/opengeodeweb_back/routes/create/blueprint_create.py @@ -12,19 +12,19 @@ from . import schemas routes = flask.Blueprint("create", __name__, url_prefix="/create") -schemas_folder = os.path.join(os.path.dirname(__file__), "schemas") +schemas_dict = utils_functions.get_schemas_dict( + os.path.join(os.path.dirname(__file__), "schemas") +) -# Load schemas -with open(os.path.join(schemas_folder, "create_point.json"), "r") as file: - create_point_json: utils_functions.SchemaDict = json.load(file) - - -@routes.route(create_point_json["route"], methods=create_point_json["methods"]) +@routes.route( + schemas_dict["create_point"]["route"], + methods=schemas_dict["create_point"]["methods"], +) def create_point() -> flask.Response: """Endpoint to create a single point in 3D space.""" print(f"create_point : {flask.request=}", flush=True) - utils_functions.validate_request(flask.request, create_point_json) + utils_functions.validate_request(flask.request, schemas_dict["create_point"]) params = schemas.CreatePoint(**flask.request.get_json()) # Create the point @@ -42,16 +42,13 @@ def create_point() -> flask.Response: return flask.make_response(result, 200) -# Load schema for AOI creation -with open(os.path.join(schemas_folder, "create_aoi.json"), "r") as file: - create_aoi_json: utils_functions.SchemaDict = json.load(file) - - -@routes.route(create_aoi_json["route"], methods=create_aoi_json["methods"]) +@routes.route( + schemas_dict["create_aoi"]["route"], methods=schemas_dict["create_aoi"]["methods"] +) def create_aoi() -> flask.Response: """Endpoint to create an Area of Interest (AOI) as an EdgedCurve3D.""" print(f"create_aoi : {flask.request=}", flush=True) - utils_functions.validate_request(flask.request, create_aoi_json) + utils_functions.validate_request(flask.request, schemas_dict["create_aoi"]) params = schemas.CreateAoi(**flask.request.get_json()) # Create the edged curve diff --git a/src/opengeodeweb_back/routes/models/blueprint_models.py b/src/opengeodeweb_back/routes/models/blueprint_models.py index e465d0f2..a432f2a1 100644 --- a/src/opengeodeweb_back/routes/models/blueprint_models.py +++ b/src/opengeodeweb_back/routes/models/blueprint_models.py @@ -7,22 +7,24 @@ from . import schemas routes = flask.Blueprint("models", __name__, url_prefix="/models") -schemas_folder = os.path.join(os.path.dirname(__file__), "schemas") - -with open(os.path.join(schemas_folder, "vtm_component_indices.json"), "r") as file: - vtm_component_indices_json: utils_functions.SchemaDict = json.load(file) +schemas_dict = utils_functions.get_schemas_dict( + os.path.join(os.path.dirname(__file__), "schemas") +) @routes.route( - vtm_component_indices_json["route"], methods=vtm_component_indices_json["methods"] + schemas_dict["vtm_component_indices"]["route"], + methods=schemas_dict["vtm_component_indices"]["methods"], ) def uuid_to_flat_index() -> flask.Response: - utils_functions.validate_request(flask.request, vtm_component_indices_json) + utils_functions.validate_request( + flask.request, schemas_dict["vtm_component_indices"] + ) params = schemas.VtmComponentIndices(**flask.request.get_json()) vtm_file_path = geode_functions.data_file_path(params.id, "viewable.vtm") tree = ET.parse(vtm_file_path) root = tree.find("vtkMultiBlockDataSet") - if not root: + if root is None: raise Exception("Failed to read viewable file") uuid_to_flat_index = {} current_index = 0 @@ -33,13 +35,12 @@ def uuid_to_flat_index() -> flask.Response: return flask.make_response({"uuid_to_flat_index": uuid_to_flat_index}, 200) -with open(os.path.join(schemas_folder, "mesh_components.json"), "r") as file: - mesh_components_json: utils_functions.SchemaDict = json.load(file) - - -@routes.route(mesh_components_json["route"], methods=mesh_components_json["methods"]) +@routes.route( + schemas_dict["mesh_components"]["route"], + methods=schemas_dict["mesh_components"]["methods"], +) def extract_uuids_endpoint() -> flask.Response: - utils_functions.validate_request(flask.request, mesh_components_json) + utils_functions.validate_request(flask.request, schemas_dict["mesh_components"]) params = schemas.MeshComponents(**flask.request.get_json()) model = geode_functions.load_data(params.id) mesh_components = model.mesh_components() diff --git a/src/opengeodeweb_back/utils_functions.py b/src/opengeodeweb_back/utils_functions.py index 2fada2aa..502eb449 100644 --- a/src/opengeodeweb_back/utils_functions.py +++ b/src/opengeodeweb_back/utils_functions.py @@ -1,5 +1,7 @@ # Standard library imports import os +import glob +import json import threading import time import zipfile @@ -22,6 +24,17 @@ type SchemaDict = dict[str, str] +def get_schemas_dict(path: str) -> dict[str, SchemaDict]: + schemas_dict: dict[str, SchemaDict] = {} + for json_file in glob.glob(os.path.join(path, "*.json")): + last_point = json_file.rfind(".") + filename = json_file[: -len(json_file) + last_point] + with open(os.path.join(path, json_file), "r") as file: + file_content = json.load(file) + schemas_dict[filename] = file_content + return schemas_dict + + def increment_request_counter(current_app: flask.Flask) -> None: if "REQUEST_COUNTER" in current_app.config: REQUEST_COUNTER = int(current_app.config.get("REQUEST_COUNTER", 0)) From 6d5a2a9d5b93c430c018d7a7183b8b7c0b05d13c Mon Sep 17 00:00:00 2001 From: Arnaud Botella Date: Tue, 21 Oct 2025 10:09:19 +0200 Subject: [PATCH 10/14] fix --- .../routes/blueprint_routes.py | 22 ++++++++-------- .../routes/create/blueprint_create.py | 25 ++++++------------- .../routes/create/schemas/create_aoi.py | 5 ++-- .../routes/create/schemas/create_point.py | 3 ++- .../routes/models/blueprint_models.py | 4 +-- .../routes/models/schemas/mesh_components.py | 3 ++- .../models/schemas/vtm_component_indices.py | 3 ++- .../routes/schemas/allowed_files.py | 3 ++- .../routes/schemas/allowed_objects.py | 3 ++- .../geode_objects_and_output_extensions.py | 3 ++- .../schemas/geographic_coordinate_systems.py | 3 ++- .../routes/schemas/inspect_file.py | 3 ++- src/opengeodeweb_back/routes/schemas/kill.py | 3 ++- .../routes/schemas/missing_files.py | 3 ++- src/opengeodeweb_back/routes/schemas/ping.py | 3 ++- .../routes/schemas/polygon_attribute_names.py | 3 ++- .../schemas/polyhedron_attribute_names.py | 3 ++- .../routes/schemas/save_viewable_file.py | 3 ++- .../routes/schemas/texture_coordinates.py | 3 ++- .../routes/schemas/upload_file.py | 3 ++- .../routes/schemas/vertex_attribute_names.py | 3 ++- src/opengeodeweb_back/utils_functions.py | 8 ++---- tests/test_utils_functions.py | 2 +- 23 files changed, 61 insertions(+), 56 deletions(-) diff --git a/src/opengeodeweb_back/routes/blueprint_routes.py b/src/opengeodeweb_back/routes/blueprint_routes.py index ea36606b..da0d917e 100644 --- a/src/opengeodeweb_back/routes/blueprint_routes.py +++ b/src/opengeodeweb_back/routes/blueprint_routes.py @@ -32,7 +32,7 @@ ) def allowed_files() -> flask.Response: utils_functions.validate_request(flask.request, schemas_dict["allowed_files"]) - params = schemas.AllowedFiles(**flask.request.get_json()) + params = schemas.AllowedFiles.from_dict(flask.request.get_json()) extensions = geode_functions.list_input_extensions(params.supported_feature) return flask.make_response({"extensions": extensions}, 200) @@ -63,7 +63,7 @@ def allowed_objects() -> flask.Response: return flask.make_response({}, 200) utils_functions.validate_request(flask.request, schemas_dict["allowed_objects"]) - params = schemas.AllowedObjects(**flask.request.get_json()) + params = schemas.AllowedObjects.from_dict(flask.request.get_json()) file_absolute_path = geode_functions.upload_file_path(params.filename) allowed_objects = geode_functions.list_geode_objects( file_absolute_path, params.supported_feature @@ -77,7 +77,7 @@ def allowed_objects() -> flask.Response: ) def missing_files() -> flask.Response: utils_functions.validate_request(flask.request, schemas_dict["missing_files"]) - params = schemas.MissingFiles(**flask.request.get_json()) + params = schemas.MissingFiles.from_dict(flask.request.get_json()) file_path = geode_functions.upload_file_path(params.filename) additional_files = geode_functions.additional_files( @@ -119,7 +119,7 @@ def crs_converter_geographic_coordinate_systems() -> flask.Response: utils_functions.validate_request( flask.request, schemas_dict["geographic_coordinate_systems"] ) - params = schemas.GeographicCoordinateSystems(**flask.request.get_json()) + params = schemas.GeographicCoordinateSystems.from_dict(flask.request.get_json()) infos = geode_functions.geographic_coordinate_systems(params.input_geode_object) crs_list = [] for info in infos: @@ -138,7 +138,7 @@ def crs_converter_geographic_coordinate_systems() -> flask.Response: ) def inspect_file() -> flask.Response: utils_functions.validate_request(flask.request, schemas_dict["inspect_file"]) - params = schemas.InspectFile(**flask.request.get_json()) + params = schemas.InspectFile.from_dict(flask.request.get_json()) file_path = geode_functions.upload_file_path(params.filename) data = geode_functions.load(params.input_geode_object, file_path) class_inspector = geode_functions.inspect(params.input_geode_object, data) @@ -154,7 +154,7 @@ def geode_objects_and_output_extensions() -> flask.Response: utils_functions.validate_request( flask.request, schemas_dict["geode_objects_and_output_extensions"] ) - params = schemas.GeodeObjectsAndOutputExtensions(**flask.request.get_json()) + params = schemas.GeodeObjectsAndOutputExtensions.from_dict(flask.request.get_json()) file_path = geode_functions.upload_file_path(params.filename) data = geode_functions.load( params.input_geode_object, @@ -175,7 +175,7 @@ def geode_objects_and_output_extensions() -> flask.Response: ) def save_viewable_file() -> flask.Response: utils_functions.validate_request(flask.request, schemas_dict["save_viewable_file"]) - params = schemas.SaveViewableFile(**flask.request.get_json()) + params = schemas.SaveViewableFile.from_dict(flask.request.get_json()) return flask.make_response( utils_functions.generate_native_viewable_and_light_viewable_from_file( geode_object=params.input_geode_object, @@ -191,7 +191,7 @@ def save_viewable_file() -> flask.Response: ) def texture_coordinates() -> flask.Response: utils_functions.validate_request(flask.request, schemas_dict["texture_coordinates"]) - params = schemas.TextureCoordinates(**flask.request.get_json()) + params = schemas.TextureCoordinates.from_dict(flask.request.get_json()) data = geode_functions.load_data(params.id) texture_coordinates = data.texture_manager().texture_names() return flask.make_response({"texture_coordinates": texture_coordinates}, 200) @@ -205,7 +205,7 @@ def vertex_attribute_names() -> flask.Response: utils_functions.validate_request( flask.request, schemas_dict["vertex_attribute_names"] ) - params = schemas.VertexAttributeNames(**flask.request.get_json()) + params = schemas.VertexAttributeNames.from_dict(flask.request.get_json()) data = geode_functions.load_data(params.id) vertex_attribute_names = data.vertex_attribute_manager().attribute_names() return flask.make_response( @@ -224,7 +224,7 @@ def polygon_attribute_names() -> flask.Response: utils_functions.validate_request( flask.request, schemas_dict["polygon_attribute_names"] ) - params = schemas.PolygonAttributeNames(**flask.request.get_json()) + params = schemas.PolygonAttributeNames.from_dict(flask.request.get_json()) data = geode_functions.load_data(params.id) polygon_attribute_names = data.polygon_attribute_manager().attribute_names() return flask.make_response( @@ -243,7 +243,7 @@ def polyhedron_attribute_names() -> flask.Response: utils_functions.validate_request( flask.request, schemas_dict["polyhedron_attribute_names"] ) - params = schemas.PolyhedronAttributeNames(**flask.request.get_json()) + params = schemas.PolyhedronAttributeNames.from_dict(flask.request.get_json()) data = geode_functions.load_data(params.id) polyhedron_attribute_names = data.polyhedron_attribute_manager().attribute_names() return flask.make_response( diff --git a/src/opengeodeweb_back/routes/create/blueprint_create.py b/src/opengeodeweb_back/routes/create/blueprint_create.py index 5bec3fff..a56c4b3e 100644 --- a/src/opengeodeweb_back/routes/create/blueprint_create.py +++ b/src/opengeodeweb_back/routes/create/blueprint_create.py @@ -25,11 +25,10 @@ def create_point() -> flask.Response: """Endpoint to create a single point in 3D space.""" print(f"create_point : {flask.request=}", flush=True) utils_functions.validate_request(flask.request, schemas_dict["create_point"]) - params = schemas.CreatePoint(**flask.request.get_json()) + params = schemas.CreatePoint.from_dict(flask.request.get_json()) # Create the point - class_ = geode_functions.geode_object_class("PointSet3D") - pointset = class_.create() + pointset = geode_functions.geode_object_class("PointSet3D").create() builder = geode_functions.create_builder("PointSet3D", pointset) builder.set_name(params.name) builder.create_point(opengeode.Point3D([params.x, params.y, params.z])) @@ -49,31 +48,23 @@ def create_aoi() -> flask.Response: """Endpoint to create an Area of Interest (AOI) as an EdgedCurve3D.""" print(f"create_aoi : {flask.request=}", flush=True) utils_functions.validate_request(flask.request, schemas_dict["create_aoi"]) - params = schemas.CreateAoi(**flask.request.get_json()) + params = schemas.CreateAoi.from_dict(flask.request.get_json()) # Create the edged curve - class_ = geode_functions.geode_object_class("EdgedCurve3D") - edged_curve = class_.create() + edged_curve = geode_functions.geode_object_class("EdgedCurve3D").create() builder = geode_functions.create_builder("EdgedCurve3D", edged_curve) builder.set_name(params.name) # Create vertices first - vertex_indices: list[int] = [] for point in params.points: - vertex_id = builder.create_point( - opengeode.Point3D([point.x, point.y, params.z]) - ) - vertex_indices.append(vertex_id) + pp = opengeode.Point3D([point.x, point.y, params.z]) + builder.create_point(opengeode.Point3D([point.x, point.y, params.z])) # Create edges between consecutive vertices and close the loop - num_vertices = len(vertex_indices) + num_vertices = len(params.points) for i in range(num_vertices): next_i = (i + 1) % num_vertices - edge_id = builder.create_edge() - builder.set_edge_vertex(opengeode.EdgeVertex(edge_id, 0), vertex_indices[i]) - builder.set_edge_vertex( - opengeode.EdgeVertex(edge_id, 1), vertex_indices[next_i] - ) + builder.create_edge_with_vertices(i, next_i) # Save and get info result = utils_functions.generate_native_viewable_and_light_viewable_from_object( diff --git a/src/opengeodeweb_back/routes/create/schemas/create_aoi.py b/src/opengeodeweb_back/routes/create/schemas/create_aoi.py index dfe92e75..a02e5dce 100644 --- a/src/opengeodeweb_back/routes/create/schemas/create_aoi.py +++ b/src/opengeodeweb_back/routes/create/schemas/create_aoi.py @@ -1,15 +1,16 @@ +from dataclasses_json import DataClassJsonMixin from dataclasses import dataclass from typing import List, Optional @dataclass -class Point: +class Point(DataClassJsonMixin): x: float y: float @dataclass -class CreateAoi: +class CreateAoi(DataClassJsonMixin): name: str """Name of the AOI""" diff --git a/src/opengeodeweb_back/routes/create/schemas/create_point.py b/src/opengeodeweb_back/routes/create/schemas/create_point.py index 5fc45e47..59032e2c 100644 --- a/src/opengeodeweb_back/routes/create/schemas/create_point.py +++ b/src/opengeodeweb_back/routes/create/schemas/create_point.py @@ -1,8 +1,9 @@ +from dataclasses_json import DataClassJsonMixin from dataclasses import dataclass @dataclass -class CreatePoint: +class CreatePoint(DataClassJsonMixin): name: str x: float y: float diff --git a/src/opengeodeweb_back/routes/models/blueprint_models.py b/src/opengeodeweb_back/routes/models/blueprint_models.py index a432f2a1..9c844bbc 100644 --- a/src/opengeodeweb_back/routes/models/blueprint_models.py +++ b/src/opengeodeweb_back/routes/models/blueprint_models.py @@ -20,7 +20,7 @@ def uuid_to_flat_index() -> flask.Response: utils_functions.validate_request( flask.request, schemas_dict["vtm_component_indices"] ) - params = schemas.VtmComponentIndices(**flask.request.get_json()) + params = schemas.VtmComponentIndices.from_dict(flask.request.get_json()) vtm_file_path = geode_functions.data_file_path(params.id, "viewable.vtm") tree = ET.parse(vtm_file_path) root = tree.find("vtkMultiBlockDataSet") @@ -41,7 +41,7 @@ def uuid_to_flat_index() -> flask.Response: ) def extract_uuids_endpoint() -> flask.Response: utils_functions.validate_request(flask.request, schemas_dict["mesh_components"]) - params = schemas.MeshComponents(**flask.request.get_json()) + params = schemas.MeshComponents.from_dict(flask.request.get_json()) model = geode_functions.load_data(params.id) mesh_components = model.mesh_components() uuid_dict = {} diff --git a/src/opengeodeweb_back/routes/models/schemas/mesh_components.py b/src/opengeodeweb_back/routes/models/schemas/mesh_components.py index 229a5a27..86e126d0 100644 --- a/src/opengeodeweb_back/routes/models/schemas/mesh_components.py +++ b/src/opengeodeweb_back/routes/models/schemas/mesh_components.py @@ -1,6 +1,7 @@ +from dataclasses_json import DataClassJsonMixin from dataclasses import dataclass @dataclass -class MeshComponents: +class MeshComponents(DataClassJsonMixin): id: str diff --git a/src/opengeodeweb_back/routes/models/schemas/vtm_component_indices.py b/src/opengeodeweb_back/routes/models/schemas/vtm_component_indices.py index fe0aca65..5b447a7d 100644 --- a/src/opengeodeweb_back/routes/models/schemas/vtm_component_indices.py +++ b/src/opengeodeweb_back/routes/models/schemas/vtm_component_indices.py @@ -1,6 +1,7 @@ +from dataclasses_json import DataClassJsonMixin from dataclasses import dataclass @dataclass -class VtmComponentIndices: +class VtmComponentIndices(DataClassJsonMixin): id: str diff --git a/src/opengeodeweb_back/routes/schemas/allowed_files.py b/src/opengeodeweb_back/routes/schemas/allowed_files.py index 1129a507..940418eb 100644 --- a/src/opengeodeweb_back/routes/schemas/allowed_files.py +++ b/src/opengeodeweb_back/routes/schemas/allowed_files.py @@ -1,7 +1,8 @@ +from dataclasses_json import DataClassJsonMixin from dataclasses import dataclass from typing import Optional @dataclass -class AllowedFiles: +class AllowedFiles(DataClassJsonMixin): supported_feature: Optional[str] = None diff --git a/src/opengeodeweb_back/routes/schemas/allowed_objects.py b/src/opengeodeweb_back/routes/schemas/allowed_objects.py index 9f104bae..3224c9e3 100644 --- a/src/opengeodeweb_back/routes/schemas/allowed_objects.py +++ b/src/opengeodeweb_back/routes/schemas/allowed_objects.py @@ -1,8 +1,9 @@ +from dataclasses_json import DataClassJsonMixin from dataclasses import dataclass from typing import Optional @dataclass -class AllowedObjects: +class AllowedObjects(DataClassJsonMixin): filename: str supported_feature: Optional[str] = None diff --git a/src/opengeodeweb_back/routes/schemas/geode_objects_and_output_extensions.py b/src/opengeodeweb_back/routes/schemas/geode_objects_and_output_extensions.py index 5c1990e7..13d05b02 100644 --- a/src/opengeodeweb_back/routes/schemas/geode_objects_and_output_extensions.py +++ b/src/opengeodeweb_back/routes/schemas/geode_objects_and_output_extensions.py @@ -1,7 +1,8 @@ +from dataclasses_json import DataClassJsonMixin from dataclasses import dataclass @dataclass -class GeodeObjectsAndOutputExtensions: +class GeodeObjectsAndOutputExtensions(DataClassJsonMixin): filename: str input_geode_object: str diff --git a/src/opengeodeweb_back/routes/schemas/geographic_coordinate_systems.py b/src/opengeodeweb_back/routes/schemas/geographic_coordinate_systems.py index 3a10c7f5..422e79ff 100644 --- a/src/opengeodeweb_back/routes/schemas/geographic_coordinate_systems.py +++ b/src/opengeodeweb_back/routes/schemas/geographic_coordinate_systems.py @@ -1,6 +1,7 @@ +from dataclasses_json import DataClassJsonMixin from dataclasses import dataclass @dataclass -class GeographicCoordinateSystems: +class GeographicCoordinateSystems(DataClassJsonMixin): input_geode_object: str diff --git a/src/opengeodeweb_back/routes/schemas/inspect_file.py b/src/opengeodeweb_back/routes/schemas/inspect_file.py index c118122b..0b354d71 100644 --- a/src/opengeodeweb_back/routes/schemas/inspect_file.py +++ b/src/opengeodeweb_back/routes/schemas/inspect_file.py @@ -1,7 +1,8 @@ +from dataclasses_json import DataClassJsonMixin from dataclasses import dataclass @dataclass -class InspectFile: +class InspectFile(DataClassJsonMixin): filename: str input_geode_object: str diff --git a/src/opengeodeweb_back/routes/schemas/kill.py b/src/opengeodeweb_back/routes/schemas/kill.py index 0452cd35..f2c4b045 100644 --- a/src/opengeodeweb_back/routes/schemas/kill.py +++ b/src/opengeodeweb_back/routes/schemas/kill.py @@ -1,6 +1,7 @@ +from dataclasses_json import DataClassJsonMixin from dataclasses import dataclass @dataclass -class Kill: +class Kill(DataClassJsonMixin): pass diff --git a/src/opengeodeweb_back/routes/schemas/missing_files.py b/src/opengeodeweb_back/routes/schemas/missing_files.py index d167421e..205e17ec 100644 --- a/src/opengeodeweb_back/routes/schemas/missing_files.py +++ b/src/opengeodeweb_back/routes/schemas/missing_files.py @@ -1,7 +1,8 @@ +from dataclasses_json import DataClassJsonMixin from dataclasses import dataclass @dataclass -class MissingFiles: +class MissingFiles(DataClassJsonMixin): filename: str input_geode_object: str diff --git a/src/opengeodeweb_back/routes/schemas/ping.py b/src/opengeodeweb_back/routes/schemas/ping.py index a448c1da..95ea85b7 100644 --- a/src/opengeodeweb_back/routes/schemas/ping.py +++ b/src/opengeodeweb_back/routes/schemas/ping.py @@ -1,6 +1,7 @@ +from dataclasses_json import DataClassJsonMixin from dataclasses import dataclass @dataclass -class Ping: +class Ping(DataClassJsonMixin): pass diff --git a/src/opengeodeweb_back/routes/schemas/polygon_attribute_names.py b/src/opengeodeweb_back/routes/schemas/polygon_attribute_names.py index 76846c1c..8f045f47 100644 --- a/src/opengeodeweb_back/routes/schemas/polygon_attribute_names.py +++ b/src/opengeodeweb_back/routes/schemas/polygon_attribute_names.py @@ -1,6 +1,7 @@ +from dataclasses_json import DataClassJsonMixin from dataclasses import dataclass @dataclass -class PolygonAttributeNames: +class PolygonAttributeNames(DataClassJsonMixin): id: str diff --git a/src/opengeodeweb_back/routes/schemas/polyhedron_attribute_names.py b/src/opengeodeweb_back/routes/schemas/polyhedron_attribute_names.py index 0fde7ac5..ee72daf5 100644 --- a/src/opengeodeweb_back/routes/schemas/polyhedron_attribute_names.py +++ b/src/opengeodeweb_back/routes/schemas/polyhedron_attribute_names.py @@ -1,6 +1,7 @@ +from dataclasses_json import DataClassJsonMixin from dataclasses import dataclass @dataclass -class PolyhedronAttributeNames: +class PolyhedronAttributeNames(DataClassJsonMixin): id: str diff --git a/src/opengeodeweb_back/routes/schemas/save_viewable_file.py b/src/opengeodeweb_back/routes/schemas/save_viewable_file.py index e3ead724..0493f24d 100644 --- a/src/opengeodeweb_back/routes/schemas/save_viewable_file.py +++ b/src/opengeodeweb_back/routes/schemas/save_viewable_file.py @@ -1,7 +1,8 @@ +from dataclasses_json import DataClassJsonMixin from dataclasses import dataclass @dataclass -class SaveViewableFile: +class SaveViewableFile(DataClassJsonMixin): filename: str input_geode_object: str diff --git a/src/opengeodeweb_back/routes/schemas/texture_coordinates.py b/src/opengeodeweb_back/routes/schemas/texture_coordinates.py index fbee6890..53bbd207 100644 --- a/src/opengeodeweb_back/routes/schemas/texture_coordinates.py +++ b/src/opengeodeweb_back/routes/schemas/texture_coordinates.py @@ -1,6 +1,7 @@ +from dataclasses_json import DataClassJsonMixin from dataclasses import dataclass @dataclass -class TextureCoordinates: +class TextureCoordinates(DataClassJsonMixin): id: str diff --git a/src/opengeodeweb_back/routes/schemas/upload_file.py b/src/opengeodeweb_back/routes/schemas/upload_file.py index 6c10a217..2ef83d42 100644 --- a/src/opengeodeweb_back/routes/schemas/upload_file.py +++ b/src/opengeodeweb_back/routes/schemas/upload_file.py @@ -1,7 +1,8 @@ +from dataclasses_json import DataClassJsonMixin from dataclasses import dataclass from typing import Optional @dataclass -class UploadFile: +class UploadFile(DataClassJsonMixin): filename: Optional[str] = None diff --git a/src/opengeodeweb_back/routes/schemas/vertex_attribute_names.py b/src/opengeodeweb_back/routes/schemas/vertex_attribute_names.py index a205f08d..3ddb4ee9 100644 --- a/src/opengeodeweb_back/routes/schemas/vertex_attribute_names.py +++ b/src/opengeodeweb_back/routes/schemas/vertex_attribute_names.py @@ -1,6 +1,7 @@ +from dataclasses_json import DataClassJsonMixin from dataclasses import dataclass @dataclass -class VertexAttributeNames: +class VertexAttributeNames(DataClassJsonMixin): id: str diff --git a/src/opengeodeweb_back/utils_functions.py b/src/opengeodeweb_back/utils_functions.py index 502eb449..14bb51ab 100644 --- a/src/opengeodeweb_back/utils_functions.py +++ b/src/opengeodeweb_back/utils_functions.py @@ -27,11 +27,10 @@ def get_schemas_dict(path: str) -> dict[str, SchemaDict]: schemas_dict: dict[str, SchemaDict] = {} for json_file in glob.glob(os.path.join(path, "*.json")): - last_point = json_file.rfind(".") - filename = json_file[: -len(json_file) + last_point] + filename = os.path.basename(json_file) with open(os.path.join(path, json_file), "r") as file: file_content = json.load(file) - schemas_dict[filename] = file_content + schemas_dict[os.path.splitext(filename)[0]] = file_content return schemas_dict @@ -241,8 +240,6 @@ def generate_native_viewable_and_light_viewable_from_object( data_entry = Data.create( geode_object=geode_object, viewer_object=geode_functions.get_object_type(geode_object), - input_file="", - additional_files=[], ) data_path = create_data_folder_from_id(data_entry.id) return save_all_viewables_and_return_info(geode_object, data, data_entry, data_path) @@ -255,7 +252,6 @@ def generate_native_viewable_and_light_viewable_from_file( geode_object=geode_object, viewer_object=geode_functions.get_object_type(geode_object), input_file=input_filename, - additional_files=[], ) data_path = create_data_folder_from_id(data_entry.id) diff --git a/tests/test_utils_functions.py b/tests/test_utils_functions.py index 87c457ec..162af7bc 100644 --- a/tests/test_utils_functions.py +++ b/tests/test_utils_functions.py @@ -183,7 +183,7 @@ def test_generate_native_viewable_and_light_viewable_from_object(client): assert re.match(r"[0-9a-f]{32}", result["id"]) assert isinstance(result["object_type"], str) assert isinstance(result["binary_light_viewable"], str) - assert result["input_file"] == "" + assert result["input_file"] == None def test_generate_native_viewable_and_light_viewable_from_file(client): From b8b316088c7008ccda8c2bf31f8fdfd00e08a2a9 Mon Sep 17 00:00:00 2001 From: Arnaud Botella Date: Tue, 21 Oct 2025 10:13:28 +0200 Subject: [PATCH 11/14] auto initi --- .../routes/create/schemas/__init__.py | 2 +- .../routes/models/schemas/__init__.py | 2 +- .../routes/schemas/__init__.py | 26 +++++++++---------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/opengeodeweb_back/routes/create/schemas/__init__.py b/src/opengeodeweb_back/routes/create/schemas/__init__.py index 8dd0b149..c9a26ab0 100644 --- a/src/opengeodeweb_back/routes/create/schemas/__init__.py +++ b/src/opengeodeweb_back/routes/create/schemas/__init__.py @@ -1,2 +1,2 @@ -from .create_aoi import * from .create_point import * +from .create_aoi import * diff --git a/src/opengeodeweb_back/routes/models/schemas/__init__.py b/src/opengeodeweb_back/routes/models/schemas/__init__.py index ac9e0588..ae37331e 100644 --- a/src/opengeodeweb_back/routes/models/schemas/__init__.py +++ b/src/opengeodeweb_back/routes/models/schemas/__init__.py @@ -1,2 +1,2 @@ -from .mesh_components import * from .vtm_component_indices import * +from .mesh_components import * diff --git a/src/opengeodeweb_back/routes/schemas/__init__.py b/src/opengeodeweb_back/routes/schemas/__init__.py index 926464ad..406ed4cb 100644 --- a/src/opengeodeweb_back/routes/schemas/__init__.py +++ b/src/opengeodeweb_back/routes/schemas/__init__.py @@ -1,14 +1,14 @@ -from .allowed_files import * -from .allowed_objects import * -from .geode_objects_and_output_extensions import * -from .geographic_coordinate_systems import * -from .inspect_file import * -from .kill import * -from .missing_files import * -from .ping import * -from .polygon_attribute_names import * -from .polyhedron_attribute_names import * -from .save_viewable_file import * -from .texture_coordinates import * -from .upload_file import * from .vertex_attribute_names import * +from .upload_file import * +from .texture_coordinates import * +from .save_viewable_file import * +from .polyhedron_attribute_names import * +from .polygon_attribute_names import * +from .ping import * +from .missing_files import * +from .kill import * +from .inspect_file import * +from .geographic_coordinate_systems import * +from .geode_objects_and_output_extensions import * +from .allowed_objects import * +from .allowed_files import * From 614f94b8ef55337d7ae3e5bfe73a6a8150ef7569 Mon Sep 17 00:00:00 2001 From: Arnaud Botella Date: Tue, 21 Oct 2025 10:25:39 +0200 Subject: [PATCH 12/14] less import --- src/opengeodeweb_back/routes/blueprint_routes.py | 1 - src/opengeodeweb_back/routes/create/blueprint_create.py | 2 -- src/opengeodeweb_back/routes/models/blueprint_models.py | 1 - 3 files changed, 4 deletions(-) diff --git a/src/opengeodeweb_back/routes/blueprint_routes.py b/src/opengeodeweb_back/routes/blueprint_routes.py index da0d917e..0a377788 100644 --- a/src/opengeodeweb_back/routes/blueprint_routes.py +++ b/src/opengeodeweb_back/routes/blueprint_routes.py @@ -1,5 +1,4 @@ # Standard library imports -import json import os import time diff --git a/src/opengeodeweb_back/routes/create/blueprint_create.py b/src/opengeodeweb_back/routes/create/blueprint_create.py index a56c4b3e..5fdc2c4a 100644 --- a/src/opengeodeweb_back/routes/create/blueprint_create.py +++ b/src/opengeodeweb_back/routes/create/blueprint_create.py @@ -1,7 +1,5 @@ # Standard library imports -import json import os -from typing import Any, TypedDict # Third party imports import flask diff --git a/src/opengeodeweb_back/routes/models/blueprint_models.py b/src/opengeodeweb_back/routes/models/blueprint_models.py index 9c844bbc..d3f20945 100644 --- a/src/opengeodeweb_back/routes/models/blueprint_models.py +++ b/src/opengeodeweb_back/routes/models/blueprint_models.py @@ -1,4 +1,3 @@ -import json import os import xml.etree.ElementTree as ET import flask From f19134bd358a8ef59c9c0feeafb4f4d09cbd0de6 Mon Sep 17 00:00:00 2001 From: Arnaud Botella Date: Wed, 22 Oct 2025 12:39:13 +0200 Subject: [PATCH 13/14] edit ignore --- .gitignore | 1 - opengeodeweb_back_schemas.json | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 opengeodeweb_back_schemas.json diff --git a/.gitignore b/.gitignore index 36f06792..169e0e35 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,3 @@ uploads node_modules .mypy_cache *.db -opengeodeweb_back_schemas.json diff --git a/opengeodeweb_back_schemas.json b/opengeodeweb_back_schemas.json new file mode 100644 index 00000000..3faa1408 --- /dev/null +++ b/opengeodeweb_back_schemas.json @@ -0,0 +1,3 @@ +{ + "opengeodeweb_back": {} +} \ No newline at end of file From 36935cf52cb6410456696a34c2dd89723e9bd4ab Mon Sep 17 00:00:00 2001 From: Arnaud Botella Date: Wed, 22 Oct 2025 13:47:02 +0200 Subject: [PATCH 14/14] update --- src/opengeodeweb_back/routes/blueprint_routes.py | 5 ++--- .../routes/create/blueprint_create.py | 5 ++--- .../routes/models/blueprint_models.py | 5 ++--- src/opengeodeweb_back/utils_functions.py | 15 +-------------- 4 files changed, 7 insertions(+), 23 deletions(-) diff --git a/src/opengeodeweb_back/routes/blueprint_routes.py b/src/opengeodeweb_back/routes/blueprint_routes.py index 0a377788..1f17f826 100644 --- a/src/opengeodeweb_back/routes/blueprint_routes.py +++ b/src/opengeodeweb_back/routes/blueprint_routes.py @@ -5,6 +5,7 @@ # Third party imports import flask import werkzeug +from opengeodeweb_microservice.schemas import get_schemas_dict # Local application imports from opengeodeweb_back import geode_functions, utils_functions @@ -20,9 +21,7 @@ name=blueprint_models.routes.name, ) -schemas_dict = utils_functions.get_schemas_dict( - os.path.join(os.path.dirname(__file__), "schemas") -) +schemas_dict = get_schemas_dict(os.path.join(os.path.dirname(__file__), "schemas")) @routes.route( diff --git a/src/opengeodeweb_back/routes/create/blueprint_create.py b/src/opengeodeweb_back/routes/create/blueprint_create.py index 5fdc2c4a..2398833d 100644 --- a/src/opengeodeweb_back/routes/create/blueprint_create.py +++ b/src/opengeodeweb_back/routes/create/blueprint_create.py @@ -4,15 +4,14 @@ # Third party imports import flask import opengeode +from opengeodeweb_microservice.schemas import get_schemas_dict # Local application imports from opengeodeweb_back import geode_functions, utils_functions from . import schemas routes = flask.Blueprint("create", __name__, url_prefix="/create") -schemas_dict = utils_functions.get_schemas_dict( - os.path.join(os.path.dirname(__file__), "schemas") -) +schemas_dict = get_schemas_dict(os.path.join(os.path.dirname(__file__), "schemas")) @routes.route( diff --git a/src/opengeodeweb_back/routes/models/blueprint_models.py b/src/opengeodeweb_back/routes/models/blueprint_models.py index d3f20945..ecc5e88a 100644 --- a/src/opengeodeweb_back/routes/models/blueprint_models.py +++ b/src/opengeodeweb_back/routes/models/blueprint_models.py @@ -1,14 +1,13 @@ import os import xml.etree.ElementTree as ET import flask +from opengeodeweb_microservice.schemas import get_schemas_dict from opengeodeweb_back import geode_functions, utils_functions from . import schemas routes = flask.Blueprint("models", __name__, url_prefix="/models") -schemas_dict = utils_functions.get_schemas_dict( - os.path.join(os.path.dirname(__file__), "schemas") -) +schemas_dict = get_schemas_dict(os.path.join(os.path.dirname(__file__), "schemas")) @routes.route( diff --git a/src/opengeodeweb_back/utils_functions.py b/src/opengeodeweb_back/utils_functions.py index 14bb51ab..1e81f7a2 100644 --- a/src/opengeodeweb_back/utils_functions.py +++ b/src/opengeodeweb_back/utils_functions.py @@ -1,7 +1,5 @@ # Standard library imports import os -import glob -import json import threading import time import zipfile @@ -18,21 +16,10 @@ # Local application imports from . import geode_functions +from opengeodeweb_microservice.schemas import SchemaDict from opengeodeweb_microservice.database.data import Data from opengeodeweb_microservice.database.connection import get_session -type SchemaDict = dict[str, str] - - -def get_schemas_dict(path: str) -> dict[str, SchemaDict]: - schemas_dict: dict[str, SchemaDict] = {} - for json_file in glob.glob(os.path.join(path, "*.json")): - filename = os.path.basename(json_file) - with open(os.path.join(path, json_file), "r") as file: - file_content = json.load(file) - schemas_dict[os.path.splitext(filename)[0]] = file_content - return schemas_dict - def increment_request_counter(current_app: flask.Flask) -> None: if "REQUEST_COUNTER" in current_app.config: