Skip to content

Commit 9be3237

Browse files
authored
Merge pull request #211 from Geode-solutions/fix/context_menu_edged_curve
fix(edgeAttribute): adding edge_attribute schema, blueprint for Edged…
2 parents 9d45525 + 38a040d commit 9be3237

8 files changed

Lines changed: 102 additions & 2 deletions

File tree

opengeodeweb_back_schemas.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,24 @@
316316
],
317317
"additionalProperties": false
318318
},
319+
"edge_attribute_names": {
320+
"$id": "opengeodeweb_back/edge_attribute_names",
321+
"route": "/edge_attribute_names",
322+
"methods": [
323+
"POST"
324+
],
325+
"type": "object",
326+
"properties": {
327+
"id": {
328+
"type": "string",
329+
"minLength": 1
330+
}
331+
},
332+
"required": [
333+
"id"
334+
],
335+
"additionalProperties": false
336+
},
319337
"cell_attribute_names": {
320338
"$id": "opengeodeweb_back/cell_attribute_names",
321339
"route": "/cell_attribute_names",

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,3 @@ werkzeug==3.1.2
6060
# flask
6161
# flask-cors
6262

63-
opengeodeweb-microservice==1.*,>=1.0.12

src/opengeodeweb_back/geode_objects/geode_graph.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,6 @@ def save_light_viewable(self, filename_without_extension: str) -> str:
7272

7373
def inspect(self) -> object:
7474
return None
75+
76+
def edge_attribute_manager(self) -> og.AttributeManager:
77+
return self.graph.edge_attribute_manager()

src/opengeodeweb_back/routes/blueprint_routes.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from opengeodeweb_back.geode_objects import geode_objects
2424
from opengeodeweb_back.geode_objects.types import geode_object_type
2525
from opengeodeweb_back.geode_objects.geode_mesh import GeodeMesh
26+
from opengeodeweb_back.geode_objects.geode_graph import GeodeGraph
2627
from opengeodeweb_back.geode_objects.geode_grid2d import GeodeGrid2D
2728
from opengeodeweb_back.geode_objects.geode_grid3d import GeodeGrid3D
2829
from opengeodeweb_back.geode_objects.geode_surface_mesh2d import GeodeSurfaceMesh2D
@@ -292,7 +293,7 @@ def cell_attribute_names() -> flask.Response:
292293
json_data = utils_functions.validate_request(
293294
flask.request, schemas_dict["cell_attribute_names"]
294295
)
295-
params = schemas.PolygonAttributeNames.from_dict(json_data)
296+
params = schemas.CellAttributeNames.from_dict(json_data)
296297
geode_object = geode_functions.load_geode_object(params.id)
297298
if not isinstance(geode_object, GeodeGrid2D | GeodeGrid3D):
298299
flask.abort(400, f"{params.id} is not a GeodeGrid")
@@ -349,6 +350,27 @@ def polyhedron_attribute_names() -> flask.Response:
349350
)
350351

351352

353+
@routes.route(
354+
schemas_dict["edge_attribute_names"]["route"],
355+
methods=schemas_dict["edge_attribute_names"]["methods"],
356+
)
357+
def edge_attribute_names() -> flask.Response:
358+
json_data = utils_functions.validate_request(
359+
flask.request, schemas_dict["edge_attribute_names"]
360+
)
361+
params = schemas.EdgeAttributeNames.from_dict(json_data)
362+
geode_object = geode_functions.load_geode_object(params.id)
363+
if not isinstance(geode_object, GeodeGraph):
364+
flask.abort(400, f"{params.id} does not have edges")
365+
edge_attribute_names = geode_object.edge_attribute_manager().attribute_names()
366+
return flask.make_response(
367+
{
368+
"edge_attribute_names": edge_attribute_names,
369+
},
370+
200,
371+
)
372+
373+
352374
@routes.route(
353375
schemas_dict["ping"]["route"],
354376
methods=schemas_dict["ping"]["methods"],

src/opengeodeweb_back/routes/schemas/__init__.py

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

tests/test_routes.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
from opengeodeweb_back.geode_objects.geode_regular_grid2d import (
2121
GeodeRegularGrid2D,
2222
)
23+
from opengeodeweb_back.geode_objects.geode_edged_curve3d import (
24+
GeodeEdgedCurve3D,
25+
)
2326

2427
base_dir = os.path.abspath(os.path.dirname(__file__))
2528
data_dir = os.path.join(base_dir, "data")
@@ -326,6 +329,33 @@ def test_polyhedron_attribute_names(client: FlaskClient, test_id: str) -> None:
326329
assert type(polyhedron_attribute_name) is str
327330

328331

332+
def test_edge_attribute_names(client: FlaskClient, test_id: str) -> None:
333+
route = f"/opengeodeweb_back/edge_attribute_names"
334+
335+
with client.application.app_context():
336+
file = os.path.join(data_dir, "test.og_edc3d")
337+
data = Data.create(
338+
geode_object=GeodeEdgedCurve3D.geode_object_type(),
339+
viewer_object=GeodeEdgedCurve3D.viewer_type(),
340+
input_file=file,
341+
)
342+
data.native_file = file
343+
session = get_session()
344+
if session:
345+
session.commit()
346+
347+
data_path = geode_functions.data_file_path(data.id, data.native_file)
348+
os.makedirs(os.path.dirname(data_path), exist_ok=True)
349+
assert os.path.exists(data_path), f"File not found at {data_path}"
350+
response = client.post(route, json={"id": data.id})
351+
print(response.get_json())
352+
assert response.status_code == 200
353+
edge_attribute_names = response.get_json()["edge_attribute_names"]
354+
assert type(edge_attribute_names) is list
355+
for edge_attribute_name in edge_attribute_names:
356+
assert type(edge_attribute_name) is str
357+
358+
329359
def test_database_uri_path(client: FlaskClient) -> None:
330360
app = client.application
331361
with app.app_context():

0 commit comments

Comments
 (0)