Skip to content

Commit 48d3099

Browse files
committed
cleaned geode_functions using data_id
adapt routes and schemas
1 parent ff05710 commit 48d3099

File tree

6 files changed

+37
-60
lines changed

6 files changed

+37
-60
lines changed

src/opengeodeweb_back/geode_functions.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from .geode_objects import geode_objects_dict
1212
from . import utils_functions
1313
from .data import Data
14+
from .database import database
1415

1516

1617
def geode_object_value(geode_object: str):
@@ -53,17 +54,9 @@ def data_file_path(data_id: str, filename: str = None) -> str:
5354
return os.path.join(data_folder_path, data_id)
5455

5556

56-
# Get data from database using data_id
57-
def get_data_info(data_id: str):
58-
data_entry = Data.query.get(data_id)
59-
if not data_entry:
60-
flask.abort(404, f"Data with id {data_id} not found")
61-
return data_entry
62-
63-
64-
# Using data_id, load data directly
6557
def load_data_by_id(data_id: str):
66-
data_entry = Data.query.get(data_id)
58+
data_entry = database.session.get(Data, data_id)
59+
print(data_entry.geode_object)
6760
if not data_entry:
6861
flask.abort(404, f"Data with id {data_id} not found")
6962

@@ -72,9 +65,12 @@ def load_data_by_id(data_id: str):
7265
return load(data_entry.geode_object, file_absolute_path)
7366

7467

75-
def load_data(geode_object: str, data_id: str, filename: str):
76-
file_absolute_path = data_file_path(data_id, filename)
77-
return load(geode_object, file_absolute_path)
68+
def get_data_info(data_id: str):
69+
from .data import Data
70+
data_entry = database.session.get(Data, data_id)
71+
if not data_entry:
72+
flask.abort(404, f"Data with id {data_id} not found")
73+
return data_entry
7874

7975

8076
def upload_file_path(filename):

src/opengeodeweb_back/routes/blueprint_routes.py

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -290,14 +290,8 @@ def create_point():
290290
)
291291
def texture_coordinates():
292292
utils_functions.validate_request(flask.request, texture_coordinates_json)
293-
data = geode_functions.load_data(
294-
flask.request.json["input_geode_object"],
295-
flask.request.json["id"],
296-
flask.request.json["filename"],
297-
)
298-
293+
data = geode_functions.load_data_by_id(flask.request.json["id"])
299294
texture_coordinates = data.texture_manager().texture_names()
300-
301295
return flask.make_response({"texture_coordinates": texture_coordinates}, 200)
302296

303297

@@ -314,14 +308,8 @@ def texture_coordinates():
314308
)
315309
def vertex_attribute_names():
316310
utils_functions.validate_request(flask.request, vertex_attribute_names_json)
317-
data = geode_functions.load_data(
318-
flask.request.json["input_geode_object"],
319-
flask.request.json["id"],
320-
flask.request.json["filename"],
321-
)
322-
311+
data = geode_functions.load_data_by_id(flask.request.json["id"])
323312
vertex_attribute_names = data.vertex_attribute_manager().attribute_names()
324-
325313
return flask.make_response(
326314
{
327315
"vertex_attribute_names": vertex_attribute_names,
@@ -343,14 +331,8 @@ def vertex_attribute_names():
343331
)
344332
def polygon_attribute_names():
345333
utils_functions.validate_request(flask.request, polygon_attribute_names_json)
346-
data = geode_functions.load_data(
347-
flask.request.json["input_geode_object"],
348-
flask.request.json["id"],
349-
flask.request.json["filename"],
350-
)
351-
334+
data = geode_functions.load_data_by_id(flask.request.json["id"])
352335
polygon_attribute_names = data.polygon_attribute_manager().attribute_names()
353-
354336
return flask.make_response(
355337
{
356338
"polygon_attribute_names": polygon_attribute_names,
@@ -372,14 +354,8 @@ def polygon_attribute_names():
372354
)
373355
def polyhedron_attribute_names():
374356
utils_functions.validate_request(flask.request, polyhedron_attribute_names_json)
375-
data = geode_functions.load_data(
376-
flask.request.json["input_geode_object"],
377-
flask.request.json["id"],
378-
flask.request.json["filename"],
379-
)
380-
357+
data = geode_functions.load_data_by_id(flask.request.json["id"])
381358
polyhedron_attribute_names = data.polyhedron_attribute_manager().attribute_names()
382-
383359
return flask.make_response(
384360
{
385361
"polyhedron_attribute_names": polyhedron_attribute_names,

src/opengeodeweb_back/routes/models/blueprint_models.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ def extract_model_uuids(model):
4949
@routes.route(mesh_components_json["route"], methods=mesh_components_json["methods"])
5050
def extract_uuids_endpoint():
5151
utils_functions.validate_request(flask.request, mesh_components_json)
52-
5352
model = geode_functions.load_data_by_id(flask.request.json["id"])
54-
5553
uuid_dict = extract_model_uuids(model)
5654
return flask.make_response({"uuid_dict": uuid_dict}, 200)

src/opengeodeweb_back/utils_functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ def generate_native_viewable_and_light_viewable_from_file(
248248
shutil.copy2(source_path, dest_path)
249249
additional_files_copied.append(additional_file.filename)
250250

251-
data = geode_functions.load_data(geode_object, temp_data_entry.id, input_filename)
251+
data = geode_functions.load(geode_object, copied_full_path)
252252

253253
database.session.delete(temp_data_entry)
254254
database.session.flush()

tests/test_models_routes.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import flask
44

55
from src.opengeodeweb_back import geode_functions
6+
from src.opengeodeweb_back.data import Data
7+
from src.opengeodeweb_back.database import database
68

79

810
def test_model_mesh_components(client, test_id):
@@ -28,14 +30,16 @@ def test_model_mesh_components(client, test_id):
2830

2931
def test_extract_brep_uuids(client, test_id):
3032
route = "/models/mesh_components"
31-
3233
brep_filename = "cube.og_brep"
33-
json_data = {"id": test_id, "geode_object": "BRep", "filename": brep_filename}
34-
35-
with client.application.app_context():
36-
data_path = geode_functions.data_file_path(json_data["id"], brep_filename)
34+
35+
with client.application.app_context():
36+
data_entry = Data.create(name="test_brep", geode_object="BRep", input_file=brep_filename)
37+
data_entry.native_file_name = brep_filename
38+
database.session.commit()
39+
data_path = geode_functions.data_file_path(test_id, brep_filename)
3740
os.makedirs(os.path.dirname(data_path), exist_ok=True)
3841
shutil.copy(f"./tests/data/{brep_filename}", data_path)
42+
json_data = {"id": test_id}
3943
response = client.post(route, json=json_data)
4044

4145
assert response.status_code == 200

tests/test_routes.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
# Local application imports
99
from src.opengeodeweb_back import geode_functions, geode_objects, test_utils
10+
from src.opengeodeweb_back.data import Data
11+
from src.opengeodeweb_back.database import database
1012

1113

1214
def test_allowed_files(client):
@@ -169,18 +171,25 @@ def get_full_data():
169171
test_utils.test_route_wrong_params(client, route, get_full_data)
170172

171173

172-
def test_texture_coordinates(client, test_id):
174+
def test_texture_coordinates(client, test_id):
173175
with client.application.app_context():
174-
data_path = geode_functions.data_file_path(test_id, "hat.vtp")
176+
data = Data.create(
177+
name="hat",
178+
geode_object="PolygonalSurface3D",
179+
input_file="hat.vtp"
180+
)
181+
data.native_file_name = "hat.vtp"
182+
database.session.commit()
183+
184+
data_path = geode_functions.data_file_path(data.id, "hat.vtp")
185+
print(data_path)
175186
os.makedirs(os.path.dirname(data_path), exist_ok=True)
176187
shutil.copy("./tests/data/hat.vtp", data_path)
177188

178189
response = client.post(
179190
"/texture_coordinates",
180191
json={
181-
"input_geode_object": "PolygonalSurface3D",
182-
"id": test_id,
183-
"filename": "hat.vtp",
192+
"id": data.id
184193
},
185194
)
186195
assert response.status_code == 200
@@ -211,9 +220,7 @@ def test_vertex_attribute_names(client, test_id):
211220

212221
def get_full_data():
213222
return {
214-
"input_geode_object": geode_object,
215223
"id": test_id,
216-
"filename": f"test.{input_extension}",
217224
}
218225

219226
response = client.post(route, json=get_full_data())
@@ -250,9 +257,7 @@ def test_polygon_attribute_names(client, test_id):
250257

251258
def get_full_data():
252259
return {
253-
"input_geode_object": geode_object,
254260
"id": test_id,
255-
"filename": f"test.{input_extension}",
256261
}
257262

258263
response = client.post(route, json=get_full_data())
@@ -289,9 +294,7 @@ def test_polyhedron_attribute_names(client, test_id):
289294

290295
def get_full_data():
291296
return {
292-
"input_geode_object": geode_object,
293297
"id": test_id,
294-
"filename": f"test.{input_extension}",
295298
}
296299

297300
response = client.post(route, json=get_full_data())

0 commit comments

Comments
 (0)