Skip to content

Commit 605b59e

Browse files
committed
removed try/catch
removed request_json in geode_functions
1 parent 5195202 commit 605b59e

File tree

5 files changed

+27
-26
lines changed

5 files changed

+27
-26
lines changed

src/opengeodeweb_back/geode_functions.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,17 @@ def load(geode_object: str, file_absolute_path: str):
4040
return geode_object_value(geode_object)["load"](file_absolute_path)
4141

4242

43-
def data_file_path(request_json, filename):
43+
def data_file_path(data_id: str, filename: str) -> str:
4444
data_folder_path = flask.current_app.config["DATA_FOLDER_PATH"]
4545
return os.path.join(
4646
data_folder_path,
47-
request_json["id"],
47+
data_id,
4848
werkzeug.utils.secure_filename(filename),
4949
)
5050

5151

52-
def load_data(geode_object: str, request_json: dict):
53-
file_absolute_path = data_file_path(request_json, request_json["filename"])
52+
def load_data(geode_object: str, data_id: str, filename: str):
53+
file_absolute_path = data_file_path(data_id, filename)
5454
return load(geode_object, file_absolute_path)
5555

5656

src/opengeodeweb_back/routes/blueprint_routes.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,8 @@ def texture_coordinates():
286286
utils_functions.validate_request(flask.request, texture_coordinates_json)
287287
data = geode_functions.load_data(
288288
flask.request.json["input_geode_object"],
289-
flask.request.json,
289+
flask.request.json["id"],
290+
flask.request.json["filename"],
290291
)
291292

292293
texture_coordinates = data.texture_manager().texture_names()
@@ -309,7 +310,8 @@ def vertex_attribute_names():
309310
utils_functions.validate_request(flask.request, vertex_attribute_names_json)
310311
data = geode_functions.load_data(
311312
flask.request.json["input_geode_object"],
312-
flask.request.json,
313+
flask.request.json["id"],
314+
flask.request.json["filename"],
313315
)
314316

315317
vertex_attribute_names = data.vertex_attribute_manager().attribute_names()
@@ -337,7 +339,8 @@ def polygon_attribute_names():
337339
utils_functions.validate_request(flask.request, polygon_attribute_names_json)
338340
data = geode_functions.load_data(
339341
flask.request.json["input_geode_object"],
340-
flask.request.json,
342+
flask.request.json["id"],
343+
flask.request.json["filename"],
341344
)
342345

343346
polygon_attribute_names = data.polygon_attribute_manager().attribute_names()
@@ -365,7 +368,8 @@ def polyhedron_attribute_names():
365368
utils_functions.validate_request(flask.request, polyhedron_attribute_names_json)
366369
data = geode_functions.load_data(
367370
flask.request.json["input_geode_object"],
368-
flask.request.json,
371+
flask.request.json["id"],
372+
flask.request.json["filename"],
369373
)
370374

371375
polyhedron_attribute_names = data.polyhedron_attribute_manager().attribute_names()

src/opengeodeweb_back/routes/models/blueprint_models.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,11 @@
1818
)
1919
def uuid_to_flat_index():
2020
utils_functions.validate_request(flask.request, vtm_component_indices_json)
21-
try:
22-
vtm_file_path = geode_functions.data_file_path(
23-
flask.request.json,
24-
"viewable.vtm",
25-
)
26-
tree = ET.parse(vtm_file_path)
27-
except FileNotFoundError:
28-
return flask.make_response({"error": "VTM file not found"}, 404)
21+
22+
vtm_file_path = geode_functions.data_file_path(
23+
flask.request.json["id"], "viewable.vtm"
24+
)
25+
tree = ET.parse(vtm_file_path)
2926
root = tree.find("vtkMultiBlockDataSet")
3027
uuid_to_flat_index = {}
3128
current_index = 0
@@ -52,12 +49,12 @@ def extract_model_uuids(model):
5249
@routes.route(mesh_components_json["route"], methods=mesh_components_json["methods"])
5350
def extract_uuids_endpoint():
5451
utils_functions.validate_request(flask.request, mesh_components_json)
55-
try:
56-
model = geode_functions.load_data(
57-
flask.request.json["geode_object"],
58-
flask.request.json,
59-
)
60-
except FileNotFoundError:
61-
return flask.make_response({"error": "File not found"}, 404)
52+
53+
model = geode_functions.load_data(
54+
flask.request.json["geode_object"],
55+
flask.request.json["id"],
56+
flask.request.json["filename"],
57+
)
58+
6259
uuid_dict = extract_model_uuids(model)
6360
return flask.make_response({"uuid_dict": uuid_dict}, 200)

tests/test_models_routes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def test_model_mesh_components(client, test_id):
99
route = f"/models/vtm_component_indices"
1010

1111
with client.application.app_context():
12-
data_path = geode_functions.data_file_path({"id": test_id}, "viewable.vtm")
12+
data_path = geode_functions.data_file_path(test_id, "viewable.vtm")
1313
os.makedirs(os.path.dirname(data_path), exist_ok=True)
1414
shutil.copy("./tests/data/cube.vtm", data_path)
1515

@@ -33,7 +33,7 @@ def test_extract_brep_uuids(client, test_id):
3333
json_data = {"id": test_id, "geode_object": "BRep", "filename": brep_filename}
3434

3535
with client.application.app_context():
36-
data_path = geode_functions.data_file_path(json_data, brep_filename)
36+
data_path = geode_functions.data_file_path(json_data["id"], brep_filename)
3737
os.makedirs(os.path.dirname(data_path), exist_ok=True)
3838
shutil.copy(f"./tests/data/{brep_filename}", data_path)
3939
response = client.post(route, json=json_data)

tests/test_routes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def get_full_data():
174174
def test_texture_coordinates(client, test_id):
175175
with client.application.app_context():
176176
data_path = geode_functions.data_file_path(
177-
{"id": test_id, "filename": "hat.vtp"}, "hat.vtp"
177+
test_id, "hat.vtp"
178178
)
179179
os.makedirs(os.path.dirname(data_path), exist_ok=True)
180180
shutil.copy("./tests/vertex_attribute.vtp", data_path)

0 commit comments

Comments
 (0)