aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gn3/api/metadata_api/wiki.py19
-rw-r--r--gn3/db/rdf/wiki.py49
2 files changed, 67 insertions, 1 deletions
diff --git a/gn3/api/metadata_api/wiki.py b/gn3/api/metadata_api/wiki.py
index 36ea03e..0e05b67 100644
--- a/gn3/api/metadata_api/wiki.py
+++ b/gn3/api/metadata_api/wiki.py
@@ -6,7 +6,8 @@ from flask import Blueprint, request, jsonify, current_app, make_response
from gn3 import db_utils
from gn3.db import wiki
from gn3.db.rdf import query_frame_and_compact
-from gn3.db.rdf.wiki import get_wiki_entries_by_symbol
+from gn3.db.rdf.wiki import (get_wiki_entries_by_symbol,
+ get_comment_history)
wiki_blueprint = Blueprint("wiki", __name__, url_prefix="wiki")
@@ -120,3 +121,19 @@ def get_species():
species_dict = wiki.get_species(cursor)
return jsonify(species_dict)
return jsonify(error="Error getting species, most likely due to DB error!"), 500
+
+
+@wiki_blueprint.route("/<int:comment_id>/history", methods=["GET"])
+def get_history(comment_id):
+ status_code = 200
+ response = get_comment_history(comment_id=comment_id,
+ sparql_uri=current_app.config["SPARQL_ENDPOINT"])
+ data = response.get("data")
+ if not data:
+ data = {}
+ status_code = 404
+ if request.headers.get("Accept") == "application/ld+json":
+ payload = make_response(response)
+ payload.headers["Content-Type"] = "application/ld+json"
+ return payload, status_code
+ return jsonify(data), status_code
diff --git a/gn3/db/rdf/wiki.py b/gn3/db/rdf/wiki.py
index b131ee7..b2235b9 100644
--- a/gn3/db/rdf/wiki.py
+++ b/gn3/db/rdf/wiki.py
@@ -91,3 +91,52 @@ CONSTRUCT {
if not data:
return results
return results
+
+
+def get_comment_history(comment_id: int, sparql_uri: str) -> dict:
+ """Get all the historical data for a given id"""
+ query = Template("""
+$prefix
+
+CONSTRUCT {
+ ?uid rdfs:label ?symbolName ;
+ gnt:reason ?reason ;
+ gnt:species ?species ;
+ dct:references ?pmid ;
+ foaf:homepage ?weburl ;
+ rdfs:comment ?comment ;
+ foaf:mbox ?email ;
+ gnt:initial ?usercode ;
+ gnt:belongsToCategory ?category ;
+ gnt:hasVersion ?versionId ;
+ rdf:type gnc:GNWikiEntry ;
+ dct:created ?created .
+} WHERE {
+ ?symbolId rdfs:label ?symbolName .
+ ?uid rdf:type gnc:GNWikiEntry ;
+ rdfs:comment ?comment ;
+ gnt:symbol ?symbolId ;
+ dct:created ?createTime ;
+ dct:hasVersion ?version ;
+ dct:identifier $comment_id ;
+ dct:identifier ?id_ .
+ OPTIONAL { ?uid gnt:reason ?reason } .
+ OPTIONAL {
+ ?uid gnt:belongsToSpecies ?speciesId .
+ ?speciesId gnt:shortName ?species .
+ } .
+ OPTIONAL { ?uid dct:references ?pubmedId . } .
+ OPTIONAL { ?uid foaf:homepage ?weburl . } .
+ OPTIONAL { ?uid gnt:initial ?usercode . } .
+ OPTIONAL { ?uid foaf:mbox ?email . } .
+ OPTIONAL { ?uid gnt:belongsToCategory ?category . } .
+ BIND (str(?version) AS ?versionId) .
+ BIND (str(?pubmedId) AS ?pmid) .
+ BIND (str(?createTime) AS ?created) .
+} ORDER BY DESC(?version) DESC(?createTime)
+""").substitute(prefix=RDF_PREFIXES, comment_id=comment_id)
+ results = query_frame_and_compact(
+ query, WIKI_CONTEXT,
+ sparql_uri
+ )
+ return results