From 79b15f59f2c4126392c8defe5810ad2189577367 Mon Sep 17 00:00:00 2001 From: Jonas Huber Date: Sat, 14 Dec 2024 19:59:38 +0100 Subject: [PATCH 1/8] fix sparql query endpoint documentation --- docs/oeplatform-code/web-api/oekg-api/index.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/oeplatform-code/web-api/oekg-api/index.md b/docs/oeplatform-code/web-api/oekg-api/index.md index b53504570..d0fa9a347 100644 --- a/docs/oeplatform-code/web-api/oekg-api/index.md +++ b/docs/oeplatform-code/web-api/oekg-api/index.md @@ -576,14 +576,14 @@ The `uid` should belong to an existing bundle in OEKG. The remaining fields are ### The SPARQL endpoint for OEKG -`https://openenergy-platform.org/knowledge/oekg_main` +`https://openenergyplatform.org/oekg/sparql/` Here is an example of how to query the Open Energy Knowledge Graph (OEKG) using SPARQL. ```python import requests -sparql_endpoint = "https://openenergy-platform.org/knowledge/oekg_main" +sparql_endpoint = "https://openenergy-platform.org/oekg/sparql/" sparql_query = { "query": """SELECT ?s ?p ?o WHERE { From f5f5134eb7e052c4516e3cd0195f417e4974b655 Mon Sep 17 00:00:00 2001 From: Jonas Huber Date: Sat, 14 Dec 2024 20:02:18 +0100 Subject: [PATCH 2/8] update template text --- factsheet/frontend/src/components/customTable.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/factsheet/frontend/src/components/customTable.js b/factsheet/frontend/src/components/customTable.js index c7a460d8d..8d931e504 100644 --- a/factsheet/frontend/src/components/customTable.js +++ b/factsheet/frontend/src/components/customTable.js @@ -256,7 +256,8 @@ function EnhancedTableToolbar(props) { In a nutshell: A scenario bundle provides you with all relevant information to understand a scenario's context and to ease a potential re-use of quantitative data for your own purposes. - The scenario bundles are stored in the Open Energy Knowledge Graph (OEKG). The OEKG can be queried using the SPARQL language. We provide a User Interface to simplify this rather technical task. + The scenario bundles are stored in the Open Energy Knowledge Graph (OEKG). The OEKG can be queried using the SPARQL language. We provide a User Interface to simplify this rather technical task. + If you want to send your own SPARQL query you can do this by send a request to the http-api endpoint. From 3e6aaa6fa93f53c8577e91250578032e2415a66c Mon Sep 17 00:00:00 2001 From: Jonas Huber Date: Sat, 14 Dec 2024 20:05:37 +0100 Subject: [PATCH 3/8] update app name --- oeplatform/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oeplatform/settings.py b/oeplatform/settings.py index dcd24c22f..3bead7421 100644 --- a/oeplatform/settings.py +++ b/oeplatform/settings.py @@ -62,7 +62,7 @@ "corsheaders", "owlready2", "compressor", - "sparql_query", + "oekg", ) MIDDLEWARE = ( From 06552325a537544323c8811b7a0098393e88a8e1 Mon Sep 17 00:00:00 2001 From: Jonas Huber Date: Sat, 14 Dec 2024 20:05:53 +0100 Subject: [PATCH 4/8] rename app name --- oeplatform/urls.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/oeplatform/urls.py b/oeplatform/urls.py index 1427dbc5d..d5dc2ebb3 100644 --- a/oeplatform/urls.py +++ b/oeplatform/urls.py @@ -13,6 +13,7 @@ 1. Add an import: from blog import urls as blog_urls 2. Add a URL to urlpatterns: re_path(r'^blog/', include(blog_urls)) """ + from django.conf.urls import include from django.conf.urls.static import static from django.urls import path, re_path @@ -35,5 +36,5 @@ re_path(r"^viewer/oeo/", include("oeo_viewer.urls")), re_path(r"^scenario-bundles/", include("factsheet.urls")), re_path(r"^tutorials/.*", redirect_tutorial), - re_path(r"^sparql_query/", include("sparql_query.urls")), + re_path(r"^oekg/", include("oekg.urls")), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) From 5355fa8a8053d73fe2ca06a3b189ba00f6c30b5a Mon Sep 17 00:00:00 2001 From: Jonas Huber Date: Sat, 14 Dec 2024 20:06:08 +0100 Subject: [PATCH 5/8] rename app directory --- {sparql_query => oekg}/__init__.py | 0 {sparql_query => oekg}/admin.py | 0 {sparql_query => oekg}/apps.py | 2 +- {sparql_query => oekg}/migrations/__init__.py | 0 {sparql_query => oekg}/models.py | 0 .../static/sparql_ui/vendor/yasgui-2.5.0/README.md | 0 .../static/sparql_ui/vendor/yasgui-2.5.0/css/yasgui.min.css | 0 .../static/sparql_ui/vendor/yasgui-2.5.0/js/yasgui.min.js | 0 .../templates/sparql_query => oekg/templates/oekg}/main.html | 0 {sparql_query => oekg}/tests.py | 0 {sparql_query => oekg}/urls.py | 0 {sparql_query => oekg}/utils.py | 0 {sparql_query => oekg}/views.py | 4 ++-- 13 files changed, 3 insertions(+), 3 deletions(-) rename {sparql_query => oekg}/__init__.py (100%) rename {sparql_query => oekg}/admin.py (100%) rename {sparql_query => oekg}/apps.py (83%) rename {sparql_query => oekg}/migrations/__init__.py (100%) rename {sparql_query => oekg}/models.py (100%) rename {sparql_query => oekg}/static/sparql_ui/vendor/yasgui-2.5.0/README.md (100%) rename {sparql_query => oekg}/static/sparql_ui/vendor/yasgui-2.5.0/css/yasgui.min.css (100%) rename {sparql_query => oekg}/static/sparql_ui/vendor/yasgui-2.5.0/js/yasgui.min.js (100%) rename {sparql_query/templates/sparql_query => oekg/templates/oekg}/main.html (100%) rename {sparql_query => oekg}/tests.py (100%) rename {sparql_query => oekg}/urls.py (100%) rename {sparql_query => oekg}/utils.py (100%) rename {sparql_query => oekg}/views.py (89%) diff --git a/sparql_query/__init__.py b/oekg/__init__.py similarity index 100% rename from sparql_query/__init__.py rename to oekg/__init__.py diff --git a/sparql_query/admin.py b/oekg/admin.py similarity index 100% rename from sparql_query/admin.py rename to oekg/admin.py diff --git a/sparql_query/apps.py b/oekg/apps.py similarity index 83% rename from sparql_query/apps.py rename to oekg/apps.py index 5727189a1..18f194688 100644 --- a/sparql_query/apps.py +++ b/oekg/apps.py @@ -3,4 +3,4 @@ class SparqlQueryConfig(AppConfig): default_auto_field = "django.db.models.BigAutoField" - name = "sparql_query" + name = "oekg" diff --git a/sparql_query/migrations/__init__.py b/oekg/migrations/__init__.py similarity index 100% rename from sparql_query/migrations/__init__.py rename to oekg/migrations/__init__.py diff --git a/sparql_query/models.py b/oekg/models.py similarity index 100% rename from sparql_query/models.py rename to oekg/models.py diff --git a/sparql_query/static/sparql_ui/vendor/yasgui-2.5.0/README.md b/oekg/static/sparql_ui/vendor/yasgui-2.5.0/README.md similarity index 100% rename from sparql_query/static/sparql_ui/vendor/yasgui-2.5.0/README.md rename to oekg/static/sparql_ui/vendor/yasgui-2.5.0/README.md diff --git a/sparql_query/static/sparql_ui/vendor/yasgui-2.5.0/css/yasgui.min.css b/oekg/static/sparql_ui/vendor/yasgui-2.5.0/css/yasgui.min.css similarity index 100% rename from sparql_query/static/sparql_ui/vendor/yasgui-2.5.0/css/yasgui.min.css rename to oekg/static/sparql_ui/vendor/yasgui-2.5.0/css/yasgui.min.css diff --git a/sparql_query/static/sparql_ui/vendor/yasgui-2.5.0/js/yasgui.min.js b/oekg/static/sparql_ui/vendor/yasgui-2.5.0/js/yasgui.min.js similarity index 100% rename from sparql_query/static/sparql_ui/vendor/yasgui-2.5.0/js/yasgui.min.js rename to oekg/static/sparql_ui/vendor/yasgui-2.5.0/js/yasgui.min.js diff --git a/sparql_query/templates/sparql_query/main.html b/oekg/templates/oekg/main.html similarity index 100% rename from sparql_query/templates/sparql_query/main.html rename to oekg/templates/oekg/main.html diff --git a/sparql_query/tests.py b/oekg/tests.py similarity index 100% rename from sparql_query/tests.py rename to oekg/tests.py diff --git a/sparql_query/urls.py b/oekg/urls.py similarity index 100% rename from sparql_query/urls.py rename to oekg/urls.py diff --git a/sparql_query/utils.py b/oekg/utils.py similarity index 100% rename from sparql_query/utils.py rename to oekg/utils.py diff --git a/sparql_query/views.py b/oekg/views.py similarity index 89% rename from sparql_query/views.py rename to oekg/views.py index b5d9b0968..ab6ad3a03 100644 --- a/sparql_query/views.py +++ b/oekg/views.py @@ -5,11 +5,11 @@ from django.views.decorators.http import require_GET from oeplatform.settings import OEKG_SPARQL_ENDPOINT_URL -from sparql_query.utils import validate_sparql_query +from oekg.utils import validate_sparql_query def main_view(request): - response = render(request, "sparql_query/main.html") + response = render(request, "oekg/main.html") response["Content-Type"] = "text/html; charset=utf-8" return response From d56634242ce0244fedb6cbb736cfbd98fa230d45 Mon Sep 17 00:00:00 2001 From: Jonas Huber Date: Mon, 16 Dec 2024 22:57:45 +0100 Subject: [PATCH 6/8] change oekg sparql endpoint view method to post --- oekg/views.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/oekg/views.py b/oekg/views.py index ab6ad3a03..8291ea4a9 100644 --- a/oekg/views.py +++ b/oekg/views.py @@ -2,7 +2,7 @@ from django.core.exceptions import SuspiciousOperation from django.http import HttpResponseBadRequest, JsonResponse from django.shortcuts import render -from django.views.decorators.http import require_GET +from django.views.decorators.http import require_POST from oeplatform.settings import OEKG_SPARQL_ENDPOINT_URL from oekg.utils import validate_sparql_query @@ -14,9 +14,9 @@ def main_view(request): return response -@require_GET +@require_POST def sparql_endpoint(request): - sparql_query = request.GET.get("query", "") + sparql_query = request.POST.get("query", "") if not sparql_query: return HttpResponseBadRequest("Missing 'query' parameter.") From e77a6e1c5134da45671f0e5040e6f93451a74e84 Mon Sep 17 00:00:00 2001 From: Jonas Huber Date: Mon, 16 Dec 2024 23:02:05 +0100 Subject: [PATCH 7/8] update changelog --- versions/changelogs/current.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/versions/changelogs/current.md b/versions/changelogs/current.md index b3cf57279..33e47f1ee 100644 --- a/versions/changelogs/current.md +++ b/versions/changelogs/current.md @@ -6,6 +6,8 @@ - Removed the outdated & unmaintained references module that was intended to handle bibtex files and store them in a django model [(#1913)](https://github.com/OpenEnergyPlatform/oeplatform/pull/1913). +- Change sparql endpoint for OEKG to use the http post method to match the expected usage [(#1913)](https://github.com/OpenEnergyPlatform/oeplatform/pull/1913). + ## Features ## Bugs From e3bde64155f13613da66a4fbfca60e825a3e7157 Mon Sep 17 00:00:00 2001 From: Jonas Huber Date: Mon, 16 Dec 2024 23:29:01 +0100 Subject: [PATCH 8/8] adapt tests with changed http method: post --- oekg/tests.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/oekg/tests.py b/oekg/tests.py index 9f2e4e3c6..d63a1699d 100644 --- a/oekg/tests.py +++ b/oekg/tests.py @@ -12,15 +12,15 @@ def setUp(self): "sparql_endpoint" ) # Ensure your URL name matches the one in your urls.py - @patch("requests.get") - def test_valid_sparql_query(self, mock_get): + @patch("requests.post") + def test_valid_sparql_query(self, mock_post): mock_response = Mock() mock_response.status_code = 200 mock_response.json.return_value = { "head": {"vars": ["sub", "pred", "obj"]}, "results": {"bindings": []}, } - mock_get.return_value = mock_response + mock_post.return_value = mock_response query = """ PREFIX rdf: @@ -31,21 +31,21 @@ def test_valid_sparql_query(self, mock_get): LIMIT 10 """ - response = self.client.get(self.endpoint_url, {"query": query}) + response = self.client.post(self.endpoint_url, {"query": query}) self.assertEqual(response.status_code, 200) json_response = response.json() self.assertIn("head", json_response) self.assertIn("results", json_response) - @patch("requests.get") - def test_invalid_sparql_query_delete(self, mock_get): + @patch("requests.post") + def test_invalid_sparql_query_delete(self, mock_post): query = """ DELETE WHERE { ?sub ?pred ?obj . } """ - response = self.client.get(self.endpoint_url, {"query": query}) + response = self.client.post(self.endpoint_url, {"query": query}) self.assertEqual( response.status_code, 400 ) # Expecting 400 Bad Request for invalid queries