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 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/geode_functions.py b/src/opengeodeweb_back/geode_functions.py index de58c47b..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): +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: @@ -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..1f17f826 100644 --- a/src/opengeodeweb_back/routes/blueprint_routes.py +++ b/src/opengeodeweb_back/routes/blueprint_routes.py @@ -1,18 +1,16 @@ # Standard library imports -import json import os import time # Third party imports import flask -import opengeode import werkzeug +from opengeodeweb_microservice.schemas import get_schemas_dict # 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,25 @@ name=blueprint_models.routes.name, ) -schemas = os.path.join(os.path.dirname(__file__), "schemas") - -with open( - os.path.join(schemas, "allowed_files.json"), - "r", -) as file: - allowed_files_json = json.load(file) +schemas_dict = 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(): - utils_functions.validate_request(flask.request, allowed_files_json) - extensions = geode_functions.list_input_extensions( - flask.request.get_json()["supported_feature"] - ) +def allowed_files() -> flask.Response: + utils_functions.validate_request(flask.request, schemas_dict["allowed_files"]) + 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) -with open( - os.path.join(schemas, "upload_file.json"), - "r", -) as file: - upload_file_json = 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(): +def upload_file() -> flask.Response: if flask.request.method == "OPTIONS": return flask.make_response({}, 200) @@ -68,48 +52,34 @@ def upload_file(): return flask.make_response({"message": "File uploaded"}, 201) -with open( - os.path.join(schemas, "allowed_objects.json"), - "r", -) as file: - allowed_objects_json = 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(): +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"] - ) + utils_functions.validate_request(flask.request, schemas_dict["allowed_objects"]) + 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, 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"), - "r", -) as file: - missing_files_json = 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(): - utils_functions.validate_request(flask.request, missing_files_json) - file_path = geode_functions.upload_file_path(flask.request.get_json()["filename"]) +def missing_files() -> flask.Response: + utils_functions.validate_request(flask.request, schemas_dict["missing_files"]) + params = schemas.MissingFiles.from_dict(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, ) @@ -139,22 +109,16 @@ def missing_files(): ) -with open( - os.path.join(schemas, "geographic_coordinate_systems.json"), - "r", -) as file: - geographic_coordinate_systems_json = 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(): - utils_functions.validate_request(flask.request, geographic_coordinate_systems_json) - infos = geode_functions.geographic_coordinate_systems( - flask.request.get_json()["input_geode_object"] +def crs_converter_geographic_coordinate_systems() -> flask.Response: + utils_functions.validate_request( + flask.request, schemas_dict["geographic_coordinate_systems"] ) + 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: crs = {} @@ -166,55 +130,36 @@ def crs_converter_geographic_coordinate_systems(): return flask.make_response({"crs_list": crs_list}, 200) -with open( - os.path.join(schemas, "inspect_file.json"), - "r", -) as file: - inspect_file_json = 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(): - 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 - ) +def inspect_file() -> flask.Response: + utils_functions.validate_request(flask.request, schemas_dict["inspect_file"]) + 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) 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"), - "r", -) as file: - geode_objects_and_output_extensions_json = 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(): +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"] ) - file_path = geode_functions.upload_file_path(flask.request.get_json()["filename"]) + params = schemas.GeodeObjectsAndOutputExtensions.from_dict(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}, @@ -222,57 +167,44 @@ def geode_objects_and_output_extensions(): ) -with open( - os.path.join(schemas, "save_viewable_file.json"), - "r", -) as file: - save_viewable_file_json = 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(): - utils_functions.validate_request(flask.request, save_viewable_file_json) +def save_viewable_file() -> flask.Response: + utils_functions.validate_request(flask.request, schemas_dict["save_viewable_file"]) + 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=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) - - @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(): - utils_functions.validate_request(flask.request, texture_coordinates_json) - data = geode_functions.load_data(flask.request.get_json().get("id")) +def texture_coordinates() -> flask.Response: + utils_functions.validate_request(flask.request, schemas_dict["texture_coordinates"]) + 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) -with open( - os.path.join(schemas, "vertex_attribute_names.json"), - "r", -) as file: - vertex_attribute_names_json = 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(): - utils_functions.validate_request(flask.request, vertex_attribute_names_json) - data = geode_functions.load_data(flask.request.get_json().get("id")) +def vertex_attribute_names() -> flask.Response: + utils_functions.validate_request( + flask.request, schemas_dict["vertex_attribute_names"] + ) + 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( { @@ -282,20 +214,16 @@ def vertex_attribute_names(): ) -with open( - os.path.join(schemas, "polygon_attribute_names.json"), - "r", -) as file: - polygon_attribute_names_json = 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(): - utils_functions.validate_request(flask.request, polygon_attribute_names_json) - data = geode_functions.load_data(flask.request.get_json().get("id")) +def polygon_attribute_names() -> flask.Response: + utils_functions.validate_request( + flask.request, schemas_dict["polygon_attribute_names"] + ) + 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( { @@ -305,20 +233,16 @@ def polygon_attribute_names(): ) -with open( - os.path.join(schemas, "polyhedron_attribute_names.json"), - "r", -) as file: - polyhedron_attribute_names_json = 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(): - utils_functions.validate_request(flask.request, polyhedron_attribute_names_json) - data = geode_functions.load_data(flask.request.get_json().get("id")) +def polyhedron_attribute_names() -> flask.Response: + utils_functions.validate_request( + flask.request, schemas_dict["polyhedron_attribute_names"] + ) + 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( { @@ -328,31 +252,17 @@ def polyhedron_attribute_names(): ) -with open( - os.path.join(schemas, "ping.json"), - "r", -) as file: - ping_json = json.load(file) - - @routes.route( - ping_json["route"], - methods=ping_json["methods"], + schemas_dict["ping"]["route"], + methods=schemas_dict["ping"]["methods"], ) -def ping(): - utils_functions.validate_request(flask.request, ping_json) +def ping() -> flask.Response: + 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, "kill.json"), - "r", -) as file: - kill_json = 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 bf5964da..2398833d 100644 --- a/src/opengeodeweb_back/routes/create/blueprint_create.py +++ b/src/opengeodeweb_back/routes/create/blueprint_create.py @@ -1,117 +1,71 @@ # Standard library imports -import json import os -from typing import Any, TypedDict # 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 = os.path.join(os.path.dirname(__file__), "schemas") +schemas_dict = get_schemas_dict(os.path.join(os.path.dirname(__file__), "schemas")) -# --- Type definitions --- -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) - - -@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) - - # Extract and validate data from request - params: CreatePointParams = flask.request.get_json() - name = params["name"] - x = params["x"] - y = params["y"] - z = params["z"] + utils_functions.validate_request(flask.request, schemas_dict["create_point"]) + 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(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) -# Load schema for AOI creation -with open(os.path.join(schemas, "create_aoi.json"), "r") as file: - create_aoi_json: 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) - - # Extract and validate data from request - params: CreateAOIParams = flask.request.get_json() - name = params["name"] - points = params["points"] - z = params["z"] + utils_functions.validate_request(flask.request, schemas_dict["create_aoi"]) + 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(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])) - vertex_indices.append(vertex_id) + for point in params.points: + 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( geode_object="EdgedCurve3D", data=edged_curve, ) - result["name"] = name return flask.make_response(result, 200) 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..c9a26ab0 --- /dev/null +++ b/src/opengeodeweb_back/routes/create/schemas/__init__.py @@ -0,0 +1,2 @@ +from .create_point import * +from .create_aoi import * 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..a02e5dce --- /dev/null +++ b/src/opengeodeweb_back/routes/create/schemas/create_aoi.py @@ -0,0 +1,19 @@ +from dataclasses_json import DataClassJsonMixin +from dataclasses import dataclass +from typing import List, Optional + + +@dataclass +class Point(DataClassJsonMixin): + x: float + y: float + + +@dataclass +class CreateAoi(DataClassJsonMixin): + name: str + """Name of the AOI""" + + points: List[Point] + z: float + 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 new file mode 100644 index 00000000..59032e2c --- /dev/null +++ b/src/opengeodeweb_back/routes/create/schemas/create_point.py @@ -0,0 +1,10 @@ +from dataclasses_json import DataClassJsonMixin +from dataclasses import dataclass + + +@dataclass +class CreatePoint(DataClassJsonMixin): + name: str + x: float + y: float + z: float diff --git a/src/opengeodeweb_back/routes/models/blueprint_models.py b/src/opengeodeweb_back/routes/models/blueprint_models.py index 02209f2e..ecc5e88a 100644 --- a/src/opengeodeweb_back/routes/models/blueprint_models.py +++ b/src/opengeodeweb_back/routes/models/blueprint_models.py @@ -1,29 +1,29 @@ -import json import os import xml.etree.ElementTree as ET import flask -from ... import geode_functions, utils_functions +from opengeodeweb_microservice.schemas import get_schemas_dict -routes = flask.Blueprint("models", __name__, url_prefix="/models") - - -schemas = os.path.join(os.path.dirname(__file__), "schemas") +from opengeodeweb_back import geode_functions, utils_functions +from . import schemas -with open(os.path.join(schemas, "vtm_component_indices.json"), "r") as file: - vtm_component_indices_json = json.load(file) +routes = flask.Blueprint("models", __name__, url_prefix="/models") +schemas_dict = 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(): - 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" +def uuid_to_flat_index() -> flask.Response: + utils_functions.validate_request( + flask.request, schemas_dict["vtm_component_indices"] ) + 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") + if root is None: + raise Exception("Failed to read viewable file") uuid_to_flat_index = {} current_index = 0 for elem in root.iter(): @@ -33,22 +33,17 @@ def uuid_to_flat_index(): return flask.make_response({"uuid_to_flat_index": uuid_to_flat_index}, 200) -def extract_model_uuids(model): +@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, schemas_dict["mesh_components"]) + params = schemas.MeshComponents.from_dict(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..ae37331e --- /dev/null +++ b/src/opengeodeweb_back/routes/models/schemas/__init__.py @@ -0,0 +1,2 @@ +from .vtm_component_indices import * +from .mesh_components import * 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..86e126d0 --- /dev/null +++ b/src/opengeodeweb_back/routes/models/schemas/mesh_components.py @@ -0,0 +1,7 @@ +from dataclasses_json import DataClassJsonMixin +from dataclasses import dataclass + + +@dataclass +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 new file mode 100644 index 00000000..5b447a7d --- /dev/null +++ b/src/opengeodeweb_back/routes/models/schemas/vtm_component_indices.py @@ -0,0 +1,7 @@ +from dataclasses_json import DataClassJsonMixin +from dataclasses import dataclass + + +@dataclass +class VtmComponentIndices(DataClassJsonMixin): + id: str diff --git a/src/opengeodeweb_back/routes/schemas/__init__.py b/src/opengeodeweb_back/routes/schemas/__init__.py new file mode 100644 index 00000000..406ed4cb --- /dev/null +++ b/src/opengeodeweb_back/routes/schemas/__init__.py @@ -0,0 +1,14 @@ +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 * 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..940418eb --- /dev/null +++ b/src/opengeodeweb_back/routes/schemas/allowed_files.py @@ -0,0 +1,8 @@ +from dataclasses_json import DataClassJsonMixin +from dataclasses import dataclass +from typing import Optional + + +@dataclass +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 new file mode 100644 index 00000000..3224c9e3 --- /dev/null +++ b/src/opengeodeweb_back/routes/schemas/allowed_objects.py @@ -0,0 +1,9 @@ +from dataclasses_json import DataClassJsonMixin +from dataclasses import dataclass +from typing import Optional + + +@dataclass +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 new file mode 100644 index 00000000..13d05b02 --- /dev/null +++ b/src/opengeodeweb_back/routes/schemas/geode_objects_and_output_extensions.py @@ -0,0 +1,8 @@ +from dataclasses_json import DataClassJsonMixin +from dataclasses import dataclass + + +@dataclass +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 new file mode 100644 index 00000000..422e79ff --- /dev/null +++ b/src/opengeodeweb_back/routes/schemas/geographic_coordinate_systems.py @@ -0,0 +1,7 @@ +from dataclasses_json import DataClassJsonMixin +from dataclasses import dataclass + + +@dataclass +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 new file mode 100644 index 00000000..0b354d71 --- /dev/null +++ b/src/opengeodeweb_back/routes/schemas/inspect_file.py @@ -0,0 +1,8 @@ +from dataclasses_json import DataClassJsonMixin +from dataclasses import dataclass + + +@dataclass +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 new file mode 100644 index 00000000..f2c4b045 --- /dev/null +++ b/src/opengeodeweb_back/routes/schemas/kill.py @@ -0,0 +1,7 @@ +from dataclasses_json import DataClassJsonMixin +from dataclasses import dataclass + + +@dataclass +class Kill(DataClassJsonMixin): + pass 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..205e17ec --- /dev/null +++ b/src/opengeodeweb_back/routes/schemas/missing_files.py @@ -0,0 +1,8 @@ +from dataclasses_json import DataClassJsonMixin +from dataclasses import dataclass + + +@dataclass +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 new file mode 100644 index 00000000..95ea85b7 --- /dev/null +++ b/src/opengeodeweb_back/routes/schemas/ping.py @@ -0,0 +1,7 @@ +from dataclasses_json import DataClassJsonMixin +from dataclasses import dataclass + + +@dataclass +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 new file mode 100644 index 00000000..8f045f47 --- /dev/null +++ b/src/opengeodeweb_back/routes/schemas/polygon_attribute_names.py @@ -0,0 +1,7 @@ +from dataclasses_json import DataClassJsonMixin +from dataclasses import dataclass + + +@dataclass +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 new file mode 100644 index 00000000..ee72daf5 --- /dev/null +++ b/src/opengeodeweb_back/routes/schemas/polyhedron_attribute_names.py @@ -0,0 +1,7 @@ +from dataclasses_json import DataClassJsonMixin +from dataclasses import dataclass + + +@dataclass +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 new file mode 100644 index 00000000..0493f24d --- /dev/null +++ b/src/opengeodeweb_back/routes/schemas/save_viewable_file.py @@ -0,0 +1,8 @@ +from dataclasses_json import DataClassJsonMixin +from dataclasses import dataclass + + +@dataclass +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 new file mode 100644 index 00000000..53bbd207 --- /dev/null +++ b/src/opengeodeweb_back/routes/schemas/texture_coordinates.py @@ -0,0 +1,7 @@ +from dataclasses_json import DataClassJsonMixin +from dataclasses import dataclass + + +@dataclass +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 new file mode 100644 index 00000000..2ef83d42 --- /dev/null +++ b/src/opengeodeweb_back/routes/schemas/upload_file.py @@ -0,0 +1,8 @@ +from dataclasses_json import DataClassJsonMixin +from dataclasses import dataclass +from typing import Optional + + +@dataclass +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 new file mode 100644 index 00000000..3ddb4ee9 --- /dev/null +++ b/src/opengeodeweb_back/routes/schemas/vertex_attribute_names.py @@ -0,0 +1,7 @@ +from dataclasses_json import DataClassJsonMixin +from dataclasses import dataclass + + +@dataclass +class VertexAttributeNames(DataClassJsonMixin): + id: str diff --git a/src/opengeodeweb_back/utils_functions.py b/src/opengeodeweb_back/utils_functions.py index 2f2b3d54..1e81f7a2 100644 --- a/src/opengeodeweb_back/utils_functions.py +++ b/src/opengeodeweb_back/utils_functions.py @@ -16,6 +16,7 @@ # 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 @@ -97,7 +98,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: @@ -226,8 +227,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) @@ -240,7 +239,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):