Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "OpenGeodeWeb-Back"
version = "5.8.4"
version = "5.8.5-rc.1"
dynamic = ["dependencies"]
authors = [
{ name="Geode-solutions", email="[email protected]" },
Expand Down
11 changes: 6 additions & 5 deletions src/opengeodeweb_back/routes/blueprint_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
# Third party imports
import flask
import opengeode
import uuid
import werkzeug

# Local application imports
Expand Down Expand Up @@ -247,10 +246,12 @@ def save_viewable_file():
secure_filename = werkzeug.utils.secure_filename(flask.request.json["filename"])
file_path = os.path.abspath(os.path.join(UPLOAD_FOLDER, secure_filename))
data = geode_functions.load(flask.request.json["input_geode_object"], file_path)
response_data = utils_functions.create_response_with_binary_light_viewable(
flask.request.json["input_geode_object"], data, DATA_FOLDER_PATH
return flask.make_response(
utils_functions.generate_native_viewable_and_light_viewable(
flask.request.json["input_geode_object"], data, DATA_FOLDER_PATH
),
200,
)
return flask.jsonify(response_data), 200


with open(os.path.join(schemas, "create_point.json"), "r") as file:
Expand All @@ -271,7 +272,7 @@ def create_point():
builder.create_point(opengeode.Point3D([x, y, z]))
builder.set_name(title)
return flask.make_response(
utils_functions.create_response_with_binary_light_viewable(
utils_functions.generate_native_viewable_and_light_viewable(
"PointSet3D", PointSet3D, DATA_FOLDER_PATH
),
200,
Expand Down
8 changes: 0 additions & 8 deletions src/opengeodeweb_back/routes/models/blueprint_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@
vtm_component_indices_json["route"], methods=vtm_component_indices_json["methods"]
)
def uuid_to_flat_index():

print(f"uuid_to_flat_index : {flask.request=}", flush=True)
utils_functions.validate_request(flask.request, vtm_component_indices_json)
vtm_file_path = os.path.join(
flask.current_app.config["DATA_FOLDER_PATH"], flask.request.json["id"] + ".vtm"
)

tree = ET.parse(vtm_file_path)
root = tree.find("vtkMultiBlockDataSet")
uuid_to_flat_index = {}
Expand Down Expand Up @@ -60,16 +57,11 @@ def extract_model_uuids(geode_object, file_path):

@routes.route(mesh_components_json["route"], methods=mesh_components_json["methods"])
def extract_uuids_endpoint():
print(f"extract_uuids_endpoint : {flask.request=}", flush=True)

utils_functions.validate_request(flask.request, mesh_components_json)

file_path = os.path.join(
flask.current_app.config["DATA_FOLDER_PATH"], flask.request.json["filename"]
)

if not os.path.exists(file_path):
return flask.make_response({"error": "File not found"}, 404)

uuid_dict = extract_model_uuids(flask.request.json["geode_object"], file_path)
return flask.make_response({"uuid_dict": uuid_dict}, 200)
30 changes: 9 additions & 21 deletions src/opengeodeweb_back/utils_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,13 @@ def handle_exception(e):
return response


def save_native_viewable_binary_file_names(geode_object, data, folder_absolute_path):
def generate_native_viewable_and_light_viewable(
geode_object, data, folder_absolute_path
):
generated_id = str(uuid.uuid4()).replace("-", "")
name = data.name()
object_type = geode_functions.get_object_type(geode_object)

saved_native_file_path = geode_functions.save(
geode_object,
data,
Expand All @@ -160,30 +165,13 @@ def save_native_viewable_binary_file_names(geode_object, data, folder_absolute_p
f = open(saved_light_viewable_file_path, "rb")
binary_light_viewable = f.read()
f.close()
return {
"native_file_name": os.path.basename(saved_native_file_path[0]),
"viewable_file_name": os.path.basename(saved_viewable_file_path[0]),
"binary_light_viewable": str(binary_light_viewable, "utf-8"),
}


def create_response_with_binary_light_viewable(
geode_object, data, folder_absolute_path
):
generated_id = str(uuid.uuid4()).replace("-", "")
name = data.name()
object_type = geode_functions.get_object_type(geode_object)

native_file_name, viewable_file_name, binary_light_viewable = (
save_native_viewable_binary_file_names(geode_object, data, folder_absolute_path)
)

return {
"name": name,
"native_file_name": native_file_name,
"viewable_file_name": viewable_file_name,
"native_file_name": os.path.basename(saved_native_file_path[0]),
"viewable_file_name": os.path.basename(saved_viewable_file_path),
"id": generated_id,
"object_type": object_type,
"binary_light_viewable": binary_light_viewable,
"binary_light_viewable": str(binary_light_viewable, "utf-8"),
"geode_object": geode_object,
}
26 changes: 25 additions & 1 deletion tests/test_utils_functions.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Standard library imports
import re
import os

# Third party imports
import flask

# Local application imports
from src.opengeodeweb_back import utils_functions
from src.opengeodeweb_back import geode_functions, utils_functions


def test_increment_request_counter(app_context):
Expand Down Expand Up @@ -67,3 +69,25 @@ def test_handle_exception(client):
assert type(data["description"]) is str
assert type(data["name"]) is str
assert type(data["code"]) is int


def test_generate_native_viewable_and_light_viewable():
geode_object = "BRep"
folder_absolute_path = os.path.abspath("./data")
data = geode_functions.load(
geode_object, os.path.join(folder_absolute_path, "test.og_brep")
)
folder_absolute_path = "None"
result = utils_functions.generate_native_viewable_and_light_viewable(
geode_object, data, folder_absolute_path
)
assert type(result) is dict
assert type(result["name"]) is str
assert type(result["native_file_name"]) is str
assert re.match(r"[0-9a-f]{32}\.[a-zA-Z0-9]+", result["native_file_name"])
assert type(result["viewable_file_name"]) is str
assert re.match(r"[0-9a-f]{32}\.[a-zA-Z0-9]+", result["viewable_file_name"])
assert type(result["id"]) is str
assert re.match(r"[0-9a-f]{32}", result["id"])
assert type(result["object_type"]) is str
assert type(result["binary_light_viewable"]) is str