Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Json ld #147

Merged
merged 21 commits into from
Sep 28, 2021
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
a1d07d9
Add requirement for rdflib-jsonld
antony-wilson Sep 16, 2021
1849834
Add CENTRAL_REGISTRY_URL to the settings file.
antony-wilson Sep 16, 2021
8b20c70
Add json-ld serialisation for the prov report
antony-wilson Sep 16, 2021
7883109
Add requirement for rdflib-jsonld in local-requirements.txt
antony-wilson Sep 16, 2021
9200149
update the json-ld
antony-wilson Sep 17, 2021
0f2c392
Make better use of existing vocabs
antony-wilson Sep 20, 2021
ae144b6
Add prov documentation
antony-wilson Sep 21, 2021
d0254f9
fix code repo url in prov report
antony-wilson Sep 21, 2021
42557c5
Provide a manage.py option to add example data to the database
antony-wilson Sep 9, 2021
8c8dda4
Change the example data to match the data produced for the paper.
antony-wilson Sep 15, 2021
12c8502
Remove the check on User and Group
antony-wilson Sep 16, 2021
62bff23
Update the ProvReportView comment for display on the API page
antony-wilson Sep 22, 2021
7aa3067
Merge branch 'main' into json_ld
antony-wilson Sep 22, 2021
9376606
tell SONAR to ignore 'http' in the vocab URLs
antony-wilson Sep 22, 2021
1ab29e0
appease sonarcloud
antony-wilson Sep 22, 2021
880d93e
appease sonarcloud
antony-wilson Sep 22, 2021
a135f67
fix typo "prov:person" -> "prov:Person"
antony-wilson Sep 22, 2021
7eb0af5
remove code smell "prov:usedEntity"
antony-wilson Sep 22, 2021
2293611
Remove the prov report documentation as this should be in the FDP_hugo
antony-wilson Sep 23, 2021
ec8ed02
Update rdflib in local-requirements to enable jsonld
NathanCummings Sep 23, 2021
1453bcf
increase rdflib version to 6.0.1 in requirements.txt
antony-wilson Sep 28, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
488 changes: 395 additions & 93 deletions data_management/prov.py

Large diffs are not rendered by default.

38 changes: 28 additions & 10 deletions data_management/rest/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,19 @@ def render(self, data, media_type=None, renderer_context=None):
return data


class JSONLDRenderer(renderers.BaseRenderer):
"""
Custom renderer for returning JSON-LD data.
"""
media_type = 'application/ld+json'
format = 'json-ld'
charset = 'utf8'
render_style = 'text'

def render(self, data, media_type=None, renderer_context=None):
return data


class ProvnRenderer(renderers.BaseRenderer):
"""
Custom renderer for returning PROV-N data (as defined in https://www.w3.org/TR/2013/REC-prov-n-20130430/).
Expand Down Expand Up @@ -95,27 +108,32 @@ def render(self, data, media_type=None, renderer_context=None):

class ProvReportView(views.APIView):
"""
API view for returning a PROV report for a DataProduct.
***The provenance report for a `DataProduct`.***

The provenance report can be generated as `JSON`, `JSON-LD`, `XML` or `PROV-N`.
Optionally `JPEG` and `SVG` versions of the provenance may be available.

### Query parameters:

`attributes` (optional): A boolean, when `True` (default) show additional
attributes of the objects on the image

This report can be returned as JSON (default) or XML or PROV-N using the custom
renderers. In addition if GraphViz is installed then JPEG and SVG renderers are also
available.
`aspect_ratio` (optional): A float used to define the ratio for the `JPEG` and
`SVG` images. The default is 0.71, which is equivalent to A4 landscape.

This method makes use of the following optional query parameters:
aspect_ratio: a float used to define the ratio for images
dpi: a float used to define the dpi for images
show_attributes: a boolean, shows attributes of elements when True
`dpi` (optional): A float used to define the dpi for the `JPEG` and `SVG` images

"""
try:
Dot(prog='dot').create()
# GraphViz is installed so the JPEG and SVG renderers are made available.
renderer_classes = [renderers.BrowsableAPIRenderer, renderers.JSONRenderer,
JPEGRenderer, SVGRenderer, XMLRenderer, ProvnRenderer]
JSONLDRenderer, JPEGRenderer, SVGRenderer, XMLRenderer,
ProvnRenderer]
except FileNotFoundError:
# GraphViz is not installed so the JPEG and SVG renderers are NOT available.
renderer_classes = [renderers.BrowsableAPIRenderer, renderers.JSONRenderer,
XMLRenderer, ProvnRenderer]
JSONLDRenderer, XMLRenderer, ProvnRenderer]

def get(self, request, pk):
data_product = get_object_or_404(models.DataProduct, pk=pk)
Expand Down
17 changes: 8 additions & 9 deletions data_management/tests/init_prov_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
StorageRoot,
Issue,
Namespace,
UserAuthor,
)
from django.contrib.auth import get_user_model

Expand All @@ -23,13 +24,11 @@ def reset_db():
Namespace.objects.all().delete()


def init_db(test=True):
def init_db():
user = get_user_model().objects.first()

if test:
get_user_model().objects.create(username="testusera")
get_user_model().objects.create(username="testuserb")
get_user_model().objects.create(username="testuserc")
usera = get_user_model().objects.create(username="testusera")
get_user_model().objects.create(username="testuserb")
get_user_model().objects.create(username="testuserc")

sr_github = StorageRoot.objects.create(
updated_by=user,
Expand Down Expand Up @@ -132,6 +131,7 @@ def init_db(test=True):
a1 = Author.objects.create(updated_by=user, name="Ivana Valenti")
a2 = Author.objects.create(updated_by=user, name="Maria Cipriani")
a3 = Author.objects.create(updated_by=user, name="Rosanna Massabeti")
UserAuthor.objects.get_or_create(updated_by=user, user=usera, author=a1)

o_code = Object.objects.create(updated_by=user, storage_location=sl_code)
o_code_2 = Object.objects.create(updated_by=user, storage_location=sl_code)
Expand Down Expand Up @@ -295,7 +295,7 @@ def init_db(test=True):
cr2.outputs.set([o_output_3.components.first()])

cr3 = CodeRun.objects.create(
updated_by=user,
updated_by=usera,
run_date="2021-07-17T19:21:11Z",
submission_script=o_script,
)
Expand All @@ -306,5 +306,4 @@ def init_db(test=True):


if __name__ == "__main__":
# reset_db()
init_db(test=False)
init_db()
Loading