Skip to content

Commit

Permalink
Merge pull request #246 from RDFLib/david/prez-identifier-homepage-me…
Browse files Browse the repository at this point in the history
…diatypes

David/prez identifier homepage mediatypes
  • Loading branch information
lalewis1 committed Jul 24, 2024
2 parents 0849ac8 + 76c26ec commit 77e6bcc
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 7 deletions.
32 changes: 27 additions & 5 deletions prez/routers/management.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import logging
import pickle
from typing import Optional

from aiocache import caches
from fastapi import APIRouter
from fastapi import APIRouter, Query, Depends
from rdflib import BNode
from rdflib import Graph, URIRef, Literal
from rdflib.collection import Collection
Expand All @@ -11,24 +12,45 @@

from prez.cache import endpoints_graph_cache
from prez.config import settings
from prez.dependencies import get_system_repo
from prez.reference_data.prez_ns import PREZ
from prez.renderers.renderer import return_rdf
from prez.services.connegp_service import RDF_MEDIATYPES
from prez.renderers.renderer import return_rdf, return_from_graph
from prez.repositories import Repo
from prez.services.connegp_service import RDF_MEDIATYPES, MediaType, NegotiatedPMTs

router = APIRouter(tags=["Management"])
log = logging.getLogger(__name__)


@router.get("/", summary="Home page", tags=["Prez"])
async def index():
async def index(
request: Request,
system_repo: Repo = Depends(get_system_repo)
):
"""Returns the following information about the API"""
pmts = NegotiatedPMTs(
headers=request.headers,
params=request.query_params,
classes=[PREZ.Object],
system_repo=system_repo,
)
await pmts.setup()
g = Graph()
g.bind("prez", "https://prez.dev/")
g.bind("ont", "https://prez.dev/ont/")
g.add((URIRef(settings.system_uri), PREZ.version, Literal(settings.prez_version)))
g += endpoints_graph_cache
g += await return_annotation_predicates()
return await return_rdf(g, "text/turtle", profile_headers={})
return await return_from_graph(
graph=g,
mediatype=pmts.selected["mediatype"],
profile=pmts.selected["profile"],
profile_headers=pmts.generate_response_headers(),
selected_class=pmts.selected["class"],
repo=system_repo,
system_repo=system_repo
)



@router.get("/purge-tbox-cache", summary="Reset Tbox Cache")
Expand Down
21 changes: 21 additions & 0 deletions prez/services/connegp_service.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import re
from enum import Enum
from textwrap import dedent

from pydantic import BaseModel
Expand Down Expand Up @@ -35,6 +36,26 @@
"text/plain": "nt", # text/plain is the old/deprecated mimetype for n-triples
}

class MediaType(str, Enum):
turtle = "text/turtle"
n3 = "text/n3"
nt = "application/n-triples"
json_ld = "application/ld+json"
xml = "application/rdf+xml"
anot_turtle = "text/anot+turtle"
anot_n3 = "text/anot+n3"
anot_nt = "application/anot+n-triples"
anot_json_ld = "application/anot+ld+json"
anot_xml = "application/anot+rdf+xml"
# Some common but incorrect mimetypes
application_rdf = "application/rdf"
application_rdf_xml = "application/rdf xml"
application_json = "application/json"
application_ld_json = "application/ld json"
text_ttl = "text/ttl"
text_ntriples = "text/ntriples"
text_plain = "text/plain"


class TokenError(Exception):
def __init__(self, *args):
Expand Down
4 changes: 2 additions & 2 deletions prez/services/link_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import time
from string import Template

from rdflib import Graph, Literal, URIRef, DCTERMS, BNode
from rdflib import Graph, Literal, URIRef, BNode
from rdflib.namespace import SH, RDF
from sparql_grammar_pydantic import (
IRI,
Expand Down Expand Up @@ -145,7 +145,7 @@ async def add_links_to_graph_and_cache(
quads.append((uri, PREZ["link"], Literal(object_link), uri))
for uri_in_link_string, curie_in_link_string in identifiers.items():
quads.append(
(uri_in_link_string, DCTERMS.identifier, Literal(curie_in_link_string, datatype=PREZ.identifier), uri)
(uri_in_link_string, PREZ.identifier, Literal(curie_in_link_string), uri)
)
if (
members_link
Expand Down

0 comments on commit 77e6bcc

Please sign in to comment.