11""" RestAPI GET enpoints
22"""
3+ from plone import api
34from zope .publisher .interfaces import IPublishTraverse
45from zope .interface import implementer
56from zope .interface import Interface
910from plone .restapi .interfaces import IExpandableElement
1011from eea .app .visualization .interfaces import IDataProvenance
1112from eea .app .visualization .interfaces import IMultiDataProvenance
13+ from eea .app .visualization .cache import ramcache
1214from 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 ):
0 commit comments