Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 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
8 changes: 5 additions & 3 deletions src/opengeodeweb_back/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ 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)
# 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 +21,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 +29,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 +40,7 @@ def create(
database.session.add(data_entry)
database.session.flush()
return data_entry

@classmethod
def get(cls, data_id: str) -> "Data | None":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@classmethod
def get(cls, data_id: str) -> "Data | None":
@staticmethod
def get(data_id: str) -> "Data | None":

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Les 2 fonctionnent, mais si on choisit d'utiliser @staticmethod, c'est un peu différent : fonction ne dépendant pas de la classe et il faut ré adapter les appels à la méthode get en précisant le model Data en paramètre
Je vais faire un commit avec les changements nécessaires
@BotellaA

return database.session.get(cls, data_id)
32 changes: 23 additions & 9 deletions src/opengeodeweb_back/geode_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
# 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,18 +47,30 @@ 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 = None) -> 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_by_id(data_id: str):
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):
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):
Expand Down
32 changes: 4 additions & 28 deletions src/opengeodeweb_back/routes/blueprint_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,14 +290,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_by_id(flask.request.json["id"])
texture_coordinates = data.texture_manager().texture_names()

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


Expand All @@ -314,14 +308,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_by_id(flask.request.json["id"])
vertex_attribute_names = data.vertex_attribute_manager().attribute_names()

return flask.make_response(
{
"vertex_attribute_names": vertex_attribute_names,
Expand All @@ -343,14 +331,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_by_id(flask.request.json["id"])
polygon_attribute_names = data.polygon_attribute_manager().attribute_names()

return flask.make_response(
{
"polygon_attribute_names": polygon_attribute_names,
Expand All @@ -372,14 +354,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_by_id(flask.request.json["id"])
polyhedron_attribute_names = data.polyhedron_attribute_manager().attribute_names()

return flask.make_response(
{
"polyhedron_attribute_names": polyhedron_attribute_names,
Expand Down
8 changes: 1 addition & 7 deletions src/opengeodeweb_back/routes/models/blueprint_models.py
Original file line number Diff line number Diff line change
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_by_id(flask.request.json["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
5 changes: 1 addition & 4 deletions src/opengeodeweb_back/utils_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ def save_all_viewables_and_return_info(
additional_files = []

data_entry = Data.create(
name=data.name(),
geode_object=geode_object,
input_file=input_file,
additional_files=additional_files,
Expand All @@ -197,7 +196,6 @@ def save_all_viewables_and_return_info(
database.session.commit()

return {
"name": data_entry.name,
"native_file_name": data_entry.native_file_name,
"viewable_file_name": data_entry.viewable_file_name,
"id": data_entry.id,
Expand All @@ -219,7 +217,6 @@ def generate_native_viewable_and_light_viewable_from_file(
geode_object: str, input_filename: str
) -> dict[str, Any]:
temp_data_entry = Data.create(
name="temp",
geode_object=geode_object,
input_file=input_filename,
additional_files=[],
Expand Down Expand Up @@ -248,7 +245,7 @@ def generate_native_viewable_and_light_viewable_from_file(
shutil.copy2(source_path, dest_path)
additional_files_copied.append(additional_file.filename)

data = geode_functions.load_data(geode_object, temp_data_entry.id, input_filename)
data = geode_functions.load(geode_object, copied_full_path)

database.session.delete(temp_data_entry)
database.session.flush()
Expand Down
12 changes: 9 additions & 3 deletions tests/test_models_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import flask

from src.opengeodeweb_back import geode_functions
from src.opengeodeweb_back.data import Data
from src.opengeodeweb_back.database import database


def test_model_mesh_components(client, test_id):
Expand All @@ -28,14 +30,18 @@ def test_model_mesh_components(client, test_id):

def test_extract_brep_uuids(client, test_id):
route = "/models/mesh_components"

brep_filename = "cube.og_brep"
json_data = {"id": test_id, "geode_object": "BRep", "filename": brep_filename}

with client.application.app_context():
data_path = geode_functions.data_file_path(json_data["id"], brep_filename)
data_entry = Data.create(geode_object="BRep", input_file=brep_filename)
data_entry.native_file_name = brep_filename
database.session.commit()

data_path = geode_functions.data_file_path(data_entry.id, brep_filename)
os.makedirs(os.path.dirname(data_path), exist_ok=True)
shutil.copy(f"./tests/data/{brep_filename}", data_path)

json_data = {"id": data_entry.id}
response = client.post(route, json=json_data)

assert response.status_code == 200
Expand Down
Loading
Loading