diff --git a/buildingmotif/api/views/model.py b/buildingmotif/api/views/model.py index 41fc930d..3c000edb 100644 --- a/buildingmotif/api/views/model.py +++ b/buildingmotif/api/views/model.py @@ -5,6 +5,7 @@ from rdflib.plugins.parsers.notation3 import BadSyntax from sqlalchemy.orm.exc import NoResultFound +from buildingmotif import get_building_motif from buildingmotif.api.serializers.model import serialize from buildingmotif.dataclasses import Library, Model, ShapeCollection @@ -163,9 +164,13 @@ def validate_model(models_id: int) -> flask.Response: except NoResultFound: return {"message": f"No model with id {models_id}"}, status.HTTP_404_NOT_FOUND + # we will read the shape collections from the input shape_collections = [] - # no body provided -- default to model manifest and default SHACL engine + # get shacl_engine from the query params, default to pyshacl + shacl_engine = request.args.get("shacl_engine", "pyshacl") + + # no body provided -- default to model manifest if request.content_length is None: shape_collections = [model.get_manifest()] else: @@ -182,7 +187,6 @@ def validate_model(models_id: int) -> flask.Response: if body is not None and not isinstance(body, dict): return {"message": "body is not dict"}, status.HTTP_400_BAD_REQUEST - shape_collections = [] body = body if body is not None else {} nonexistent_libraries = [] for library_id in body.get("library_ids", []): @@ -196,9 +200,17 @@ def validate_model(models_id: int) -> flask.Response: "message": f"Libraries with ids {nonexistent_libraries} do not exist" }, status.HTTP_400_BAD_REQUEST - # if shape_collections is empty, model.validate will default - # to the model's manifest - vaildation_context = model.validate(shape_collections) + # temporarily change the SHACL engine + bm = get_building_motif() + old_shacl_engine = bm.shacl_engine + bm.shacl_engine = shacl_engine + + # if shape_collections is empty, model.validate will default to the model's manifest + vaildation_context = model.validate( + shape_collections, error_on_missing_imports=False + ) + # change the SHACL engine back + bm.shacl_engine = old_shacl_engine return { "message": vaildation_context.report_string,