diff --git a/opengeodeweb_back_schemas.json b/opengeodeweb_back_schemas.json index ef829502..2258eed1 100644 --- a/opengeodeweb_back_schemas.json +++ b/opengeodeweb_back_schemas.json @@ -316,6 +316,24 @@ ], "additionalProperties": false }, + "edge_attribute_names": { + "$id": "opengeodeweb_back/edge_attribute_names", + "route": "/edge_attribute_names", + "methods": [ + "POST" + ], + "type": "object", + "properties": { + "id": { + "type": "string", + "minLength": 1 + } + }, + "required": [ + "id" + ], + "additionalProperties": false + }, "cell_attribute_names": { "$id": "opengeodeweb_back/cell_attribute_names", "route": "/cell_attribute_names", diff --git a/requirements.txt b/requirements.txt index 5697c0a5..08d64bdf 100644 --- a/requirements.txt +++ b/requirements.txt @@ -60,4 +60,3 @@ werkzeug==3.1.2 # flask # flask-cors -opengeodeweb-microservice==1.*,>=1.0.12 diff --git a/src/opengeodeweb_back/geode_objects/geode_graph.py b/src/opengeodeweb_back/geode_objects/geode_graph.py index 7c79f1c6..15f6e67a 100644 --- a/src/opengeodeweb_back/geode_objects/geode_graph.py +++ b/src/opengeodeweb_back/geode_objects/geode_graph.py @@ -72,3 +72,6 @@ def save_light_viewable(self, filename_without_extension: str) -> str: def inspect(self) -> object: return None + + def edge_attribute_manager(self) -> og.AttributeManager: + return self.graph.edge_attribute_manager() diff --git a/src/opengeodeweb_back/routes/blueprint_routes.py b/src/opengeodeweb_back/routes/blueprint_routes.py index 9ee41869..570ef419 100644 --- a/src/opengeodeweb_back/routes/blueprint_routes.py +++ b/src/opengeodeweb_back/routes/blueprint_routes.py @@ -23,6 +23,7 @@ from opengeodeweb_back.geode_objects import geode_objects from opengeodeweb_back.geode_objects.types import geode_object_type from opengeodeweb_back.geode_objects.geode_mesh import GeodeMesh +from opengeodeweb_back.geode_objects.geode_graph import GeodeGraph from opengeodeweb_back.geode_objects.geode_grid2d import GeodeGrid2D from opengeodeweb_back.geode_objects.geode_grid3d import GeodeGrid3D from opengeodeweb_back.geode_objects.geode_surface_mesh2d import GeodeSurfaceMesh2D @@ -292,7 +293,7 @@ def cell_attribute_names() -> flask.Response: json_data = utils_functions.validate_request( flask.request, schemas_dict["cell_attribute_names"] ) - params = schemas.PolygonAttributeNames.from_dict(json_data) + params = schemas.CellAttributeNames.from_dict(json_data) geode_object = geode_functions.load_geode_object(params.id) if not isinstance(geode_object, GeodeGrid2D | GeodeGrid3D): flask.abort(400, f"{params.id} is not a GeodeGrid") @@ -349,6 +350,27 @@ def polyhedron_attribute_names() -> flask.Response: ) +@routes.route( + schemas_dict["edge_attribute_names"]["route"], + methods=schemas_dict["edge_attribute_names"]["methods"], +) +def edge_attribute_names() -> flask.Response: + json_data = utils_functions.validate_request( + flask.request, schemas_dict["edge_attribute_names"] + ) + params = schemas.EdgeAttributeNames.from_dict(json_data) + geode_object = geode_functions.load_geode_object(params.id) + if not isinstance(geode_object, GeodeGraph): + flask.abort(400, f"{params.id} does not have edges") + edge_attribute_names = geode_object.edge_attribute_manager().attribute_names() + return flask.make_response( + { + "edge_attribute_names": edge_attribute_names, + }, + 200, + ) + + @routes.route( schemas_dict["ping"]["route"], methods=schemas_dict["ping"]["methods"], diff --git a/src/opengeodeweb_back/routes/schemas/__init__.py b/src/opengeodeweb_back/routes/schemas/__init__.py index 5d37ca18..763f0a24 100644 --- a/src/opengeodeweb_back/routes/schemas/__init__.py +++ b/src/opengeodeweb_back/routes/schemas/__init__.py @@ -13,6 +13,7 @@ from .geographic_coordinate_systems import * from .geode_objects_and_output_extensions import * from .export_project import * +from .edge_attribute_names import * from .cell_attribute_names import * from .allowed_objects import * from .allowed_files import * diff --git a/src/opengeodeweb_back/routes/schemas/edge_attribute_names.json b/src/opengeodeweb_back/routes/schemas/edge_attribute_names.json new file mode 100644 index 00000000..1caac1bb --- /dev/null +++ b/src/opengeodeweb_back/routes/schemas/edge_attribute_names.json @@ -0,0 +1,17 @@ +{ + "route": "/edge_attribute_names", + "methods": [ + "POST" + ], + "type": "object", + "properties": { + "id": { + "type": "string", + "minLength": 1 + } + }, + "required": [ + "id" + ], + "additionalProperties": false +} \ No newline at end of file diff --git a/src/opengeodeweb_back/routes/schemas/edge_attribute_names.py b/src/opengeodeweb_back/routes/schemas/edge_attribute_names.py new file mode 100644 index 00000000..92c039a5 --- /dev/null +++ b/src/opengeodeweb_back/routes/schemas/edge_attribute_names.py @@ -0,0 +1,10 @@ +from dataclasses_json import DataClassJsonMixin +from dataclasses import dataclass + + +@dataclass +class EdgeAttributeNames(DataClassJsonMixin): + def __post_init__(self) -> None: + print(self, flush=True) + + id: str diff --git a/tests/test_routes.py b/tests/test_routes.py index 58aa3321..4c84f32f 100644 --- a/tests/test_routes.py +++ b/tests/test_routes.py @@ -20,6 +20,9 @@ from opengeodeweb_back.geode_objects.geode_regular_grid2d import ( GeodeRegularGrid2D, ) +from opengeodeweb_back.geode_objects.geode_edged_curve3d import ( + GeodeEdgedCurve3D, +) base_dir = os.path.abspath(os.path.dirname(__file__)) data_dir = os.path.join(base_dir, "data") @@ -326,6 +329,33 @@ def test_polyhedron_attribute_names(client: FlaskClient, test_id: str) -> None: assert type(polyhedron_attribute_name) is str +def test_edge_attribute_names(client: FlaskClient, test_id: str) -> None: + route = f"/opengeodeweb_back/edge_attribute_names" + + with client.application.app_context(): + file = os.path.join(data_dir, "test.og_edc3d") + data = Data.create( + geode_object=GeodeEdgedCurve3D.geode_object_type(), + viewer_object=GeodeEdgedCurve3D.viewer_type(), + input_file=file, + ) + data.native_file = file + session = get_session() + if session: + session.commit() + + data_path = geode_functions.data_file_path(data.id, data.native_file) + os.makedirs(os.path.dirname(data_path), exist_ok=True) + assert os.path.exists(data_path), f"File not found at {data_path}" + response = client.post(route, json={"id": data.id}) + print(response.get_json()) + assert response.status_code == 200 + edge_attribute_names = response.get_json()["edge_attribute_names"] + assert type(edge_attribute_names) is list + for edge_attribute_name in edge_attribute_names: + assert type(edge_attribute_name) is str + + def test_database_uri_path(client: FlaskClient) -> None: app = client.application with app.app_context():