Skip to content

Commit 24451fc

Browse files
authored
Merge pull request #25 from eea/develop
Release: organisation name to provenances RestAPI endpoint
2 parents 46a9a99 + 4e8901c commit 24451fc

3 files changed

Lines changed: 27 additions & 4 deletions

File tree

docs/HISTORY.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
Changelog
22
=========
33

4+
13.4 - (2023-08-18)
5+
---------------------------
6+
* Feature: Add **organisation** name to **@provenances** RestAPI endpoint
7+
[avoinea refs #157787]
8+
49
13.3 - (2022-04-20)
510
---------------------------
611
* Change: IMultiDataProvenance default provenances to ExternalDataSpec and Data relatedItems

eea/app/visualization/restapi/data/provenance/get.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
""" RestAPI GET enpoints
22
"""
3+
from plone import api
34
from zope.publisher.interfaces import IPublishTraverse
45
from zope.interface import implementer
56
from zope.interface import Interface
@@ -9,6 +10,7 @@
910
from plone.restapi.interfaces import IExpandableElement
1011
from eea.app.visualization.interfaces import IDataProvenance
1112
from eea.app.visualization.interfaces import IMultiDataProvenance
13+
from eea.app.visualization.cache import ramcache
1214
from Products.CMFPlone.interfaces import IPloneSiteRoot
1315

1416

@@ -21,6 +23,18 @@ def __init__(self, context, request):
2123
self.context = context
2224
self.request = request
2325

26+
@ramcache(lambda *args: "organisations", lifetime=86400)
27+
def organisations(self):
28+
""" Get a mapping of organisations url to title
29+
"""
30+
organisations = {}
31+
brains = api.content.find(portal_type='Organisation')
32+
for brain in brains:
33+
org = brain.getObject()
34+
url = getattr(org, 'organisationUrl', '')
35+
organisations[url] = brain.Title
36+
return organisations
37+
2438
def __call__(self, expand=False):
2539
result = {"provenances": {
2640
"@id": "{}/@provenances".format(self.context.absolute_url()),
@@ -32,13 +46,16 @@ def __call__(self, expand=False):
3246
if IPloneSiteRoot.providedBy(self.context):
3347
return result
3448

49+
organisations = self.organisations()
3550
result['provenances']['items'] = []
3651

3752
# Get IMultiDataProvenance
3853
multi = queryAdapter(self.context, IMultiDataProvenance)
3954
if multi:
40-
provenances = json_compatible(multi.provenances)
41-
result['provenances']['items'].extend(provenances)
55+
for provenance in multi.provenances:
56+
owner = provenance.get('owner', '')
57+
provenance['organisation'] = organisations.get(owner, '')
58+
result['provenances']['items'].append(json_compatible(provenance))
4259

4360
source = queryAdapter(self.context, IDataProvenance)
4461
if (getattr(source, 'link', None) and
@@ -47,7 +64,8 @@ def __call__(self, expand=False):
4764
provenance = {
4865
"title": json_compatible(source.title),
4966
"owner": json_compatible(source.owner),
50-
"link": json_compatible(source.link)
67+
"link": json_compatible(source.link),
68+
"organisation": json_compatible(organisations.get(source.owner, ''))
5169
}
5270

5371
if getattr(source, "copyrights", None):

eea/app/visualization/version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
13.3
1+
13.4

0 commit comments

Comments
 (0)