Skip to content

Commit 4b1f3e8

Browse files
authored
Merge pull request #158 from Geode-solutions/next
Next
2 parents f2659d3 + fb7d2a5 commit 4b1f3e8

File tree

6 files changed

+70
-88
lines changed

6 files changed

+70
-88
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
55

66
[project]
77
name = "OpenGeodeWeb-Back"
8-
version = "5.8.3"
8+
version = "5.8.4-rc.2"
99
dynamic = ["dependencies"]
1010
authors = [
1111
{ name="Geode-solutions", email="[email protected]" },

requirements.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ geode-simplex
99
geode-explicit
1010
geode-implicit
1111
geode-common
12-
jsonschema
12+
fastjsonschema
1313
Flask[async]
1414
Flask-Cors
1515
werkzeug

requirements.txt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ blinker==1.9.0
1414
# via flask
1515
click==8.2.1
1616
# via flask
17+
fastjsonschema==2.21.1
18+
# via -r requirements.in
1719
flask[async]==3.1.1
1820
# via
1921
# -r requirements.in
@@ -60,10 +62,6 @@ itsdangerous==2.2.0
6062
# via flask
6163
jinja2==3.1.6
6264
# via flask
63-
jsonschema==4.24.0
64-
# via -r requirements.in
65-
jsonschema-specifications==2025.4.1
66-
# via jsonschema
6765
markupsafe==3.0.2
6866
# via
6967
# flask
@@ -120,4 +118,4 @@ werkzeug==3.1.3
120118
# via
121119
# -r requirements.in
122120
# flask
123-
# flask-cors
121+
# flask-cors

src/opengeodeweb_back/routes/blueprint_routes.py

Lines changed: 7 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -241,61 +241,16 @@ def geode_objects_and_output_extensions():
241241
methods=save_viewable_file_json["methods"],
242242
)
243243
def save_viewable_file():
244+
utils_functions.validate_request(flask.request, save_viewable_file_json)
244245
UPLOAD_FOLDER = flask.current_app.config["UPLOAD_FOLDER"]
245246
DATA_FOLDER_PATH = flask.current_app.config["DATA_FOLDER_PATH"]
246-
utils_functions.validate_request(flask.request, save_viewable_file_json)
247-
248247
secure_filename = werkzeug.utils.secure_filename(flask.request.json["filename"])
249248
file_path = os.path.abspath(os.path.join(UPLOAD_FOLDER, secure_filename))
250249
data = geode_functions.load(flask.request.json["input_geode_object"], file_path)
251-
generated_id = str(uuid.uuid4()).replace("-", "")
252-
253-
name = data.name()
254-
native_extension = data.native_extension()
255-
256-
absolute_native_file_path = os.path.join(
257-
UPLOAD_FOLDER, generated_id + "." + native_extension
258-
)
259-
260-
saved_viewable_file_path = geode_functions.save_viewable(
261-
flask.request.json["input_geode_object"], data, DATA_FOLDER_PATH, generated_id
262-
)
263-
264-
saved_light_viewable_file_path = geode_functions.save_light_viewable(
265-
flask.request.json["input_geode_object"],
266-
data,
267-
DATA_FOLDER_PATH,
268-
"light_" + generated_id,
269-
)
270-
271-
f = open(saved_light_viewable_file_path, "rb")
272-
binary_light_viewable = f.read()
273-
f.close()
274-
275-
geode_functions.save(
276-
flask.request.json["input_geode_object"],
277-
data,
278-
DATA_FOLDER_PATH,
279-
generated_id + "." + native_extension,
280-
)
281-
os.remove(os.path.join(UPLOAD_FOLDER, secure_filename))
282-
object_type = geode_functions.get_object_type(
283-
flask.request.json["input_geode_object"]
284-
)
285-
286-
native_file_name = os.path.basename(absolute_native_file_path)
287-
viewable_file_name = os.path.basename(saved_viewable_file_path)
288-
return flask.make_response(
289-
{
290-
"name": name,
291-
"native_file_name": native_file_name,
292-
"viewable_file_name": viewable_file_name,
293-
"id": generated_id,
294-
"object_type": object_type,
295-
"binary_light_viewable": str(binary_light_viewable, "utf-8"),
296-
},
297-
200,
250+
response_data = utils_functions.create_response_with_binary_light_viewable(
251+
flask.request.json["input_geode_object"], data, DATA_FOLDER_PATH
298252
)
253+
return flask.jsonify(response_data), 200
299254

300255

301256
with open(os.path.join(schemas, "create_point.json"), "r") as file:
@@ -315,29 +270,10 @@ def create_point():
315270
builder = geode_functions.create_builder("PointSet3D", PointSet3D)
316271
builder.create_point(opengeode.Point3D([x, y, z]))
317272
builder.set_name(title)
318-
name = PointSet3D.name()
319-
generated_id = str(uuid.uuid4()).replace("-", "")
320-
object_type = geode_functions.get_object_type("PointSet3D")
321-
saved_native_file_path = geode_functions.save(
322-
"PointSet3D", PointSet3D, DATA_FOLDER_PATH, generated_id + ".og_pts3d"
323-
)
324-
saved_viewable_file_path = geode_functions.save_viewable(
325-
"PointSet3D", PointSet3D, DATA_FOLDER_PATH, generated_id
326-
)
327-
328-
native_file_name = os.path.basename(saved_native_file_path[0])
329-
viewable_file_name = os.path.basename(saved_viewable_file_path)
330-
331273
return flask.make_response(
332-
{
333-
"viewable_file_name": os.path.basename(saved_viewable_file_path),
334-
"id": generated_id,
335-
"name": name,
336-
"native_file_name": native_file_name,
337-
"viewable_file_name": viewable_file_name,
338-
"object_type": object_type,
339-
"geode_object": "PointSet3D",
340-
},
274+
utils_functions.create_response_with_binary_light_viewable(
275+
"PointSet3D", PointSet3D, DATA_FOLDER_PATH
276+
),
341277
200,
342278
)
343279

src/opengeodeweb_back/test_utils.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ def test_route_wrong_params(client, route, get_full_data):
1212
response = client.post(route, json=json)
1313
assert response.status_code == 400
1414
error_description = response.json["description"]
15-
assert error_description == f"Validation error: '{key}' is a required property"
15+
assert "data must contain" in error_description
16+
assert f"'{key}'" in error_description
1617

1718
json = get_full_data()
1819
json["dumb_key"] = "dumb_value"
1920
response = client.post(route, json=json)
2021
assert response.status_code == 400
2122
error_description = response.json["description"]
22-
assert (
23-
error_description
24-
== "Validation error: Additional properties are not allowed ('dumb_key' was unexpected)"
25-
)
23+
assert "data must not contain" in error_description
24+
assert "'dumb_key'" in error_description

src/opengeodeweb_back/utils_functions.py

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
import os
33
import threading
44
import time
5+
import uuid
56
import zipfile
67

78
# Third party imports
89
import flask
9-
from jsonschema import validate
10-
from jsonschema.exceptions import ValidationError
10+
import fastjsonschema
1111
import importlib.metadata as metadata
1212

1313
# Local application imports
14+
from . import geode_functions
1415

1516

1617
def increment_request_counter(current_app):
@@ -82,9 +83,11 @@ def validate_request(request, schema):
8283
json_data = {}
8384

8485
try:
85-
validate(instance=json_data, schema=schema)
86-
except ValidationError as e:
87-
flask.abort(400, f"Validation error: {e.message}")
86+
validate = fastjsonschema.compile(schema)
87+
validate(json_data)
88+
except fastjsonschema.JsonSchemaException as e:
89+
error_msg = str(e)
90+
flask.abort(400, error_msg)
8891

8992

9093
def set_interval(func, sec, args=None):
@@ -138,3 +141,49 @@ def handle_exception(e):
138141
)
139142
response.content_type = "application/json"
140143
return response
144+
145+
146+
def save_native_viewable_binary_file_names(geode_object, data, folder_absolute_path):
147+
generated_id = str(uuid.uuid4()).replace("-", "")
148+
saved_native_file_path = geode_functions.save(
149+
geode_object,
150+
data,
151+
folder_absolute_path,
152+
generated_id + "." + data.native_extension(),
153+
)
154+
saved_viewable_file_path = geode_functions.save_viewable(
155+
geode_object, data, folder_absolute_path, generated_id
156+
)
157+
saved_light_viewable_file_path = geode_functions.save_light_viewable(
158+
geode_object, data, folder_absolute_path, "light_" + generated_id
159+
)
160+
f = open(saved_light_viewable_file_path, "rb")
161+
binary_light_viewable = f.read()
162+
f.close()
163+
return {
164+
"native_file_name": os.path.basename(saved_native_file_path[0]),
165+
"viewable_file_name": os.path.basename(saved_viewable_file_path[0]),
166+
"binary_light_viewable": str(binary_light_viewable, "utf-8"),
167+
}
168+
169+
170+
def create_response_with_binary_light_viewable(
171+
geode_object, data, folder_absolute_path
172+
):
173+
generated_id = str(uuid.uuid4()).replace("-", "")
174+
name = data.name()
175+
object_type = geode_functions.get_object_type(geode_object)
176+
177+
native_file_name, viewable_file_name, binary_light_viewable = (
178+
save_native_viewable_binary_file_names(geode_object, data, folder_absolute_path)
179+
)
180+
181+
return {
182+
"name": name,
183+
"native_file_name": native_file_name,
184+
"viewable_file_name": viewable_file_name,
185+
"id": generated_id,
186+
"object_type": object_type,
187+
"binary_light_viewable": binary_light_viewable,
188+
"geode_object": geode_object,
189+
}

0 commit comments

Comments
 (0)