Skip to content

Commit d44312a

Browse files
committed
fix graph name handling
1 parent c5bdfb3 commit d44312a

1 file changed

Lines changed: 33 additions & 11 deletions

File tree

buildingmotif/api/views/model.py

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,19 @@ def get_model_manifest(models_id: int) -> flask.Response:
192192
if flask.request.method == "GET":
193193
ttl_body = g.serialize(format="ttl")
194194
# Collect all owl:imports objects as URIs
195-
library_uris = sorted(list({str(o) for _, _, o in g.triples((None, OWL.imports, None))}))
195+
library_uris = sorted(
196+
list({str(o) for _, _, o in g.triples((None, OWL.imports, None))})
197+
)
196198

197199
# Content negotiation: return JSON only if explicitly requested
198-
best = request.accept_mimetypes.best_match(["application/json", "text/turtle", "text/plain"])
200+
best = request.accept_mimetypes.best_match(
201+
["application/json", "text/turtle", "text/plain"]
202+
)
199203
if best == "application/json":
200-
return jsonify({"body": ttl_body, "library_uris": library_uris}), status.HTTP_200_OK
204+
return (
205+
jsonify({"body": ttl_body, "library_uris": library_uris}),
206+
status.HTTP_200_OK,
207+
)
201208
return ttl_body, status.HTTP_200_OK
202209

203210
# POST: update/replace manifest
@@ -215,18 +222,26 @@ def get_model_manifest(models_id: int) -> flask.Response:
215222
library_ids = body.get("library_ids", []) or []
216223
library_uris_in = body.get("library_uris", []) or []
217224

218-
if not isinstance(library_ids, list) or not all(isinstance(x, int) for x in library_ids):
219-
return {"message": "library_ids must be an array of integers"}, status.HTTP_400_BAD_REQUEST
220-
if not isinstance(library_uris_in, list) or not all(isinstance(x, str) for x in library_uris_in):
221-
return {"message": "library_uris must be an array of strings"}, status.HTTP_400_BAD_REQUEST
225+
if not isinstance(library_ids, list) or not all(
226+
isinstance(x, int) for x in library_ids
227+
):
228+
return {
229+
"message": "library_ids must be an array of integers"
230+
}, status.HTTP_400_BAD_REQUEST
231+
if not isinstance(library_uris_in, list) or not all(
232+
isinstance(x, str) for x in library_uris_in
233+
):
234+
return {
235+
"message": "library_uris must be an array of strings"
236+
}, status.HTTP_400_BAD_REQUEST
222237

223238
# Resolve library_ids to shape collection identifiers (URIs)
224239
nonexistent_libraries = []
225240
resolved_uris = []
226241
for lib_id in library_ids:
227242
try:
228-
db_lib = current_app.building_motif.table_connection.get_db_library(lib_id)
229-
ident = db_lib.shape_collection.graph_id
243+
db_lib = Library.load(lib_id)
244+
ident = db_lib.get_shape_collection().graph_name
230245
if ident is not None:
231246
resolved_uris.append(str(ident))
232247
except LibraryNotFound:
@@ -297,7 +312,9 @@ def manage_manifest_imports(models_id: int) -> flask.Response:
297312
return jsonify({"library_ids": library_ids}), status.HTTP_200_OK
298313

299314
if request.content_type != "application/json":
300-
return {"message": "request content type must be json"}, status.HTTP_400_BAD_REQUEST
315+
return {
316+
"message": "request content type must be json"
317+
}, status.HTTP_400_BAD_REQUEST
301318

302319
try:
303320
body = request.json or {}
@@ -327,7 +344,12 @@ def manage_manifest_imports(models_id: int) -> flask.Response:
327344

328345
logger.info(f"Selected templates for model {models_id}: {selected_template_ids}")
329346

330-
return jsonify({"library_ids": library_ids, "selected_template_ids": selected_template_ids}), status.HTTP_200_OK
347+
return (
348+
jsonify(
349+
{"library_ids": library_ids, "selected_template_ids": selected_template_ids}
350+
),
351+
status.HTTP_200_OK,
352+
)
331353

332354

333355
@blueprint.route("/<models_id>/validate", methods=(["POST"]))

0 commit comments

Comments
 (0)