Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
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
7 changes: 4 additions & 3 deletions src/opengeodeweb_back/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class Data(Base):
id: Mapped[str] = mapped_column(
String, primary_key=True, default=lambda: str(uuid.uuid4()).replace("-", "")
)
name: Mapped[str] = mapped_column(String, nullable=False)
native_file_name: Mapped[str] = mapped_column(String, nullable=False)
viewable_file_name: Mapped[str] = mapped_column(String, nullable=False)
geode_object: Mapped[str] = mapped_column(String, nullable=False)
Expand All @@ -21,7 +20,6 @@ class Data(Base):

@staticmethod
def create(
name: str,
geode_object: str,
input_file: str | None = None,
additional_files: list[str] | None = None,
Expand All @@ -30,7 +28,6 @@ def create(
additional_files = additional_files if additional_files is not None else []

data_entry = Data(
name=name,
geode_object=geode_object,
input_file=input_file,
additional_files=additional_files,
Expand All @@ -42,3 +39,7 @@ def create(
database.session.add(data_entry)
database.session.flush()
return data_entry

@staticmethod
def get(data_id: str) -> "Data | None":
return database.session.get(Data, data_id)
34 changes: 24 additions & 10 deletions src/opengeodeweb_back/geode_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
import opengeode as og # type: ignore
import werkzeug
import flask
from typing import Any

# Local application imports
from .geode_objects import geode_objects_dict
from . import utils_functions
from .data import Data
from .database import database


def geode_object_value(geode_object: str):
Expand Down Expand Up @@ -45,21 +48,32 @@ def load(geode_object: str, file_absolute_path: str):
return geode_object_value(geode_object)["load"](file_absolute_path)


def data_file_path(data_id: str, filename: str) -> str:
def data_file_path(data_id: str, filename: str = "") -> str:
data_folder_path = flask.current_app.config["DATA_FOLDER_PATH"]
return os.path.join(
data_folder_path,
data_id,
werkzeug.utils.secure_filename(filename),
)
if filename:
return os.path.join(data_folder_path, data_id, filename)
return os.path.join(data_folder_path, data_id)


def load_data(data_id: str) -> Any:
data_entry = Data.get(data_id)
if not data_entry:
flask.abort(404, f"Data with id {data_id} not found")

file_absolute_path = data_file_path(data_id, data_entry.native_file_name)
return load(data_entry.geode_object, file_absolute_path)


def get_data_info(data_id: str) -> Data:
from .data import Data

def load_data(geode_object: str, data_id: str, filename: str):
file_absolute_path = data_file_path(data_id, filename)
return load(geode_object, file_absolute_path)
data_entry = Data.get(data_id)
if not data_entry:
flask.abort(404, f"Data with id {data_id} not found")
return data_entry


def upload_file_path(filename):
def upload_file_path(filename: str) -> str:
upload_folder = flask.current_app.config["UPLOAD_FOLDER"]
secure_filename = werkzeug.utils.secure_filename(filename)
return os.path.abspath(os.path.join(upload_folder, secure_filename))
Expand Down
70 changes: 24 additions & 46 deletions src/opengeodeweb_back/routes/blueprint_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def teardown_request(exception):
def allowed_files():
utils_functions.validate_request(flask.request, allowed_files_json)
extensions = geode_functions.list_input_extensions(
flask.request.json["supported_feature"]
flask.request.get_json()["supported_feature"]
)
return flask.make_response({"extensions": extensions}, 200)

Expand Down Expand Up @@ -99,10 +99,10 @@ def allowed_objects():

utils_functions.validate_request(flask.request, allowed_objects_json)
file_absolute_path = geode_functions.upload_file_path(
flask.request.json["filename"]
flask.request.get_json()["filename"]
)
allowed_objects = geode_functions.list_geode_objects(
file_absolute_path, flask.request.json["supported_feature"]
file_absolute_path, flask.request.get_json()["supported_feature"]
)
return flask.make_response({"allowed_objects": allowed_objects}, 200)

Expand All @@ -120,10 +120,10 @@ def allowed_objects():
)
def missing_files():
utils_functions.validate_request(flask.request, missing_files_json)
file_path = geode_functions.upload_file_path(flask.request.json["filename"])
file_path = geode_functions.upload_file_path(flask.request.get_json()["filename"])

additional_files = geode_functions.additional_files(
flask.request.json["input_geode_object"],
flask.request.get_json()["input_geode_object"],
file_path,
)

Expand Down Expand Up @@ -167,7 +167,7 @@ def missing_files():
def crs_converter_geographic_coordinate_systems():
utils_functions.validate_request(flask.request, geographic_coordinate_systems_json)
infos = geode_functions.geographic_coordinate_systems(
flask.request.json["input_geode_object"]
flask.request.get_json()["input_geode_object"]
)
crs_list = []
for info in infos:
Expand All @@ -194,10 +194,12 @@ def crs_converter_geographic_coordinate_systems():
def inspect_file():
utils_functions.validate_request(flask.request, inspect_file_json)

file_path = geode_functions.upload_file_path(flask.request.json["filename"])
data = geode_functions.load(flask.request.json["input_geode_object"], file_path)
file_path = geode_functions.upload_file_path(flask.request.get_json()["filename"])
data = geode_functions.load(
flask.request.get_json()["input_geode_object"], file_path
)
class_inspector = geode_functions.inspect(
flask.request.json["input_geode_object"], data
flask.request.get_json()["input_geode_object"], data
)
inspection_result = geode_functions.get_inspector_children(class_inspector)
return flask.make_response({"inspection_result": inspection_result}, 200)
Expand All @@ -218,14 +220,14 @@ def geode_objects_and_output_extensions():
utils_functions.validate_request(
flask.request, geode_objects_and_output_extensions_json
)
file_path = geode_functions.upload_file_path(flask.request.json["filename"])
file_path = geode_functions.upload_file_path(flask.request.get_json()["filename"])
data = geode_functions.load(
flask.request.json["input_geode_object"],
flask.request.get_json()["input_geode_object"],
file_path,
)
geode_objects_and_output_extensions = (
geode_functions.geode_objects_output_extensions(
flask.request.json["input_geode_object"], data
flask.request.get_json()["input_geode_object"], data
)
)
return flask.make_response(
Expand All @@ -249,8 +251,8 @@ def save_viewable_file():
utils_functions.validate_request(flask.request, save_viewable_file_json)
return flask.make_response(
utils_functions.generate_native_viewable_and_light_viewable_from_file(
geode_object=flask.request.json["input_geode_object"],
input_filename=flask.request.json["filename"],
geode_object=flask.request.get_json()["input_geode_object"],
input_filename=flask.request.get_json()["filename"],
),
200,
)
Expand All @@ -263,10 +265,10 @@ def save_viewable_file():
@routes.route(create_point_json["route"], methods=create_point_json["methods"])
def create_point():
utils_functions.validate_request(flask.request, create_point_json)
title = flask.request.json["title"]
x = flask.request.json["x"]
y = flask.request.json["y"]
z = flask.request.json["z"]
title = flask.request.get_json()["title"]
x = flask.request.get_json()["x"]
y = flask.request.get_json()["y"]
z = flask.request.get_json()["z"]
class_ = geode_functions.geode_object_class("PointSet3D")
PointSet3D = class_.create()
builder = geode_functions.create_builder("PointSet3D", PointSet3D)
Expand All @@ -290,14 +292,8 @@ def create_point():
)
def texture_coordinates():
utils_functions.validate_request(flask.request, texture_coordinates_json)
data = geode_functions.load_data(
flask.request.json["input_geode_object"],
flask.request.json["id"],
flask.request.json["filename"],
)

data = geode_functions.load_data(flask.request.get_json().get("id"))
texture_coordinates = data.texture_manager().texture_names()

return flask.make_response({"texture_coordinates": texture_coordinates}, 200)


Expand All @@ -314,14 +310,8 @@ def texture_coordinates():
)
def vertex_attribute_names():
utils_functions.validate_request(flask.request, vertex_attribute_names_json)
data = geode_functions.load_data(
flask.request.json["input_geode_object"],
flask.request.json["id"],
flask.request.json["filename"],
)

data = geode_functions.load_data(flask.request.get_json().get("id"))
vertex_attribute_names = data.vertex_attribute_manager().attribute_names()

return flask.make_response(
{
"vertex_attribute_names": vertex_attribute_names,
Expand All @@ -343,14 +333,8 @@ def vertex_attribute_names():
)
def polygon_attribute_names():
utils_functions.validate_request(flask.request, polygon_attribute_names_json)
data = geode_functions.load_data(
flask.request.json["input_geode_object"],
flask.request.json["id"],
flask.request.json["filename"],
)

data = geode_functions.load_data(flask.request.get_json().get("id"))
polygon_attribute_names = data.polygon_attribute_manager().attribute_names()

return flask.make_response(
{
"polygon_attribute_names": polygon_attribute_names,
Expand All @@ -372,14 +356,8 @@ def polygon_attribute_names():
)
def polyhedron_attribute_names():
utils_functions.validate_request(flask.request, polyhedron_attribute_names_json)
data = geode_functions.load_data(
flask.request.json["input_geode_object"],
flask.request.json["id"],
flask.request.json["filename"],
)

data = geode_functions.load_data(flask.request.get_json().get("id"))
polyhedron_attribute_names = data.polyhedron_attribute_manager().attribute_names()

return flask.make_response(
{
"polyhedron_attribute_names": polyhedron_attribute_names,
Expand Down
10 changes: 2 additions & 8 deletions src/opengeodeweb_back/routes/models/blueprint_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def uuid_to_flat_index():
utils_functions.validate_request(flask.request, vtm_component_indices_json)

vtm_file_path = geode_functions.data_file_path(
flask.request.json["id"], "viewable.vtm"
flask.request.get_json().get("id"), "viewable.vtm"
)
tree = ET.parse(vtm_file_path)
root = tree.find("vtkMultiBlockDataSet")
Expand Down Expand Up @@ -49,12 +49,6 @@ def extract_model_uuids(model):
@routes.route(mesh_components_json["route"], methods=mesh_components_json["methods"])
def extract_uuids_endpoint():
utils_functions.validate_request(flask.request, mesh_components_json)

model = geode_functions.load_data(
flask.request.json["geode_object"],
flask.request.json["id"],
flask.request.json["filename"],
)

model = geode_functions.load_data(flask.request.get_json().get("id"))
uuid_dict = extract_model_uuids(model)
return flask.make_response({"uuid_dict": uuid_dict}, 200)
12 changes: 1 addition & 11 deletions src/opengeodeweb_back/routes/models/schemas/mesh_components.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,10 @@
"id": {
"type": "string",
"minLength": 1
},
"filename": {
"type": "string",
"minLength": 1
},
"geode_object": {
"type": "string",
"minLength": 1
}
},
"required": [
"id",
"filename",
"geode_object"
"id"
],
"additionalProperties": false
}
10 changes: 0 additions & 10 deletions src/opengeodeweb_back/routes/schemas/polygon_attribute_names.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,12 @@
],
"type": "object",
"properties": {
"input_geode_object": {
"type": "string",
"minLength": 1
},
"filename": {
"type": "string",
"minLength": 1
},
"id": {
"type": "string",
"minLength": 1
}
},
"required": [
"input_geode_object",
"filename",
"id"
],
"additionalProperties": false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,12 @@
],
"type": "object",
"properties": {
"input_geode_object": {
"type": "string",
"minLength": 1
},
"filename": {
"type": "string",
"minLength": 1
},
"id": {
"type": "string",
"minLength": 1
}
},
"required": [
"input_geode_object",
"filename",
"id"
],
"additionalProperties": false
Expand Down
12 changes: 1 addition & 11 deletions src/opengeodeweb_back/routes/schemas/texture_coordinates.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,13 @@
],
"type": "object",
"properties": {
"input_geode_object": {
"type": "string",
"minLength": 1
},
"filename": {
"type": "string",
"minLength": 1
},
"id": {
"type": "string",
"minLength": 1
}
},
"required": [
"input_geode_object",
"id",
"filename"
"id"
],
"additionalProperties": false
}
10 changes: 0 additions & 10 deletions src/opengeodeweb_back/routes/schemas/vertex_attribute_names.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,12 @@
],
"type": "object",
"properties": {
"input_geode_object": {
"type": "string",
"minLength": 1
},
"filename": {
"type": "string",
"minLength": 1
},
"id": {
"type": "string",
"minLength": 1
}
},
"required": [
"input_geode_object",
"filename",
"id"
],
"additionalProperties": false
Expand Down
Loading
Loading