Skip to content

Commit

Permalink
Merge pull request #1926 from OpenEnergyPlatform/housekeeping-remove-…
Browse files Browse the repository at this point in the history
…deprecated-references-module

Remove deprecated references module / rename oekg api app
  • Loading branch information
jh-RLI authored Dec 18, 2024
2 parents 746fa1b + e3bde64 commit 8959eb2
Show file tree
Hide file tree
Showing 18 changed files with 22 additions and 18 deletions.
4 changes: 2 additions & 2 deletions docs/oeplatform-code/web-api/oekg-api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion factsheet/frontend/src/components/customTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
</Typography>
<Typography variant="body2">
The scenario bundles are stored in the Open Energy Knowledge Graph (OEKG). The OEKG can be queried using the SPARQL language. We provide a <a href="/sparql_query/gui/">User Interface</a> 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 <a href="/oekg/gui/">User Interface</a> 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.
</Typography>
</Grid>
</Grid>
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion sparql_query/apps.py → oekg/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

class SparqlQueryConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "sparql_query"
name = "oekg"
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 7 additions & 7 deletions sparql_query/tests.py → oekg/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
Expand All @@ -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
Expand Down
File renamed without changes.
File renamed without changes.
10 changes: 5 additions & 5 deletions sparql_query/views.py → oekg/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
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 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


@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.")
Expand Down
2 changes: 1 addition & 1 deletion oeplatform/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"corsheaders",
"owlready2",
"compressor",
"sparql_query",
"oekg",
)

MIDDLEWARE = (
Expand Down
3 changes: 2 additions & 1 deletion oeplatform/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
2 changes: 2 additions & 0 deletions versions/changelogs/current.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,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).

- Extract header/footer template [(#1914)](https://github.com/OpenEnergyPlatform/oeplatform/pull/1914)

## Features
Expand Down

0 comments on commit 8959eb2

Please sign in to comment.