Skip to content

Commit f58f296

Browse files
committed
add uuid dict logic
1 parent 8461b4a commit f58f296

File tree

5 files changed

+88
-13
lines changed

5 files changed

+88
-13
lines changed

src/opengeodeweb_back/routes/models/blueprint_models.py

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
import os
33
import xml.etree.ElementTree as ET
44
import flask
5-
65
from src.opengeodeweb_back import geode_functions, utils_functions
6+
from opengeode import model
77

88
routes = flask.Blueprint("models", __name__)
99

@@ -23,13 +23,13 @@ def teardown_request(exception):
2323

2424
schemas = os.path.join(os.path.dirname(__file__), "schemas")
2525

26-
with open(os.path.join(schemas, "components.json"), "r") as file:
27-
components_json = json.load(file)
26+
with open(os.path.join(schemas, "mesh_components.json"), "r") as file:
27+
mesh_components_json = json.load(file)
2828

2929

30-
@routes.route(components_json["route"], methods=components_json["methods"])
31-
def print_vtm_file():
32-
utils_functions.validate_request(flask.request, components_json)
30+
@routes.route(mesh_components_json["route"], methods=mesh_components_json["methods"])
31+
def uuid_to_flat_index():
32+
utils_functions.validate_request(flask.request, mesh_components_json)
3333
vtm_file_path = os.path.join(
3434
flask.current_app.config["DATA_FOLDER_PATH"], flask.request.json["id"] + ".vtm"
3535
)
@@ -50,3 +50,45 @@ def print_vtm_file():
5050
{"uuid_to_flat_index": uuid_to_flat_index},
5151
200,
5252
)
53+
54+
55+
def extract_model_uuids(geode_object, file_path):
56+
model = geode_functions.load(geode_object, file_path)
57+
components = {
58+
"blocks": getattr(model, "blocks", lambda: [])(),
59+
"lines": getattr(model, "lines", lambda: [])(),
60+
"surfaces": getattr(model, "surfaces", lambda: [])(),
61+
"corners": getattr(model, "corners", lambda: [])(),
62+
}
63+
64+
uuid_dict = {
65+
key: [
66+
component.id().string()
67+
for component in components[key]
68+
if hasattr(component, "id")
69+
]
70+
for key in components
71+
if components[key]
72+
}
73+
74+
print(f"{uuid_dict=}", flush=True)
75+
return uuid_dict
76+
77+
78+
with open(os.path.join(schemas, "components_types.json"), "r") as file:
79+
components_types_json = json.load(file)
80+
81+
82+
@routes.route(components_types_json["route"], methods=components_types_json["methods"])
83+
def extract_uuids_endpoint():
84+
utils_functions.validate_request(flask.request, components_types_json)
85+
86+
file_path = os.path.join(
87+
flask.current_app.config["DATA_FOLDER_PATH"], flask.request.json["filename"]
88+
)
89+
90+
if not os.path.exists(file_path):
91+
return flask.make_response({"error": "File not found"}, 404)
92+
93+
uuid_dict = extract_model_uuids(flask.request.json["geode_object"], file_path)
94+
return flask.make_response(uuid_dict, 200)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"route": "/components_types",
3+
"methods": [
4+
"POST"
5+
],
6+
"type": "object",
7+
"properties": {
8+
"filename": {
9+
"type": "string"
10+
},
11+
"geode_object": {
12+
"type": "string"
13+
}
14+
},
15+
"required": [
16+
"filename",
17+
"geode_object"
18+
],
19+
"additionalProperties": false
20+
}

src/opengeodeweb_back/routes/models/schemas/components.json renamed to src/opengeodeweb_back/routes/models/schemas/mesh_components.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"route": "/components",
2+
"route": "/mesh_components",
33
"methods": [
44
"POST"
55
],

tests/data/cube.og_brep

463 KB
Binary file not shown.

tests/test_models_routes.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import os
2-
32
from werkzeug.datastructures import FileStorage
4-
53
from src.opengeodeweb_back import geode_functions, geode_objects, test_utils
64

75

8-
def test_model_components(client):
9-
route = f"/models/components"
6+
def test_model_mesh_components(client):
7+
route = f"/models/mesh_components"
108
get_full_data = lambda: {"id": "cube"}
119
json = get_full_data()
1210
response = client.post(route, json=json)
@@ -19,5 +17,20 @@ def test_model_components(client):
1917
assert indices[0] == 1
2018
assert all(indices[i] == indices[i - 1] + 1 for i in range(1, len(indices)))
2119

22-
# Test all params
23-
test_utils.test_route_wrong_params(client, route, get_full_data)
20+
21+
def test_extract_brep_uuids(client):
22+
route = "/models/components_types"
23+
json_data = {"filename": "cube.og_brep", "geode_object": "BRep"}
24+
25+
response = client.post(route, json=json_data)
26+
27+
assert response.status_code == 200
28+
uuid_dict = response.json
29+
assert isinstance(uuid_dict, dict)
30+
assert (
31+
"blocks" in uuid_dict
32+
or "lines" in uuid_dict
33+
or "surfaces" in uuid_dict
34+
or "corners" in uuid_dict
35+
)
36+
assert False

0 commit comments

Comments
 (0)