10
10
"""Routes for record-related pages provided by Invenio-App-RDM."""
11
11
12
12
from functools import wraps
13
- from itertools import islice
14
13
15
14
from flask import current_app , g , make_response , redirect , request , session , url_for
16
15
from flask_login import login_required
20
19
from invenio_communities .proxies import current_communities
21
20
from invenio_pidstore .errors import PIDDoesNotExistError
22
21
from invenio_rdm_records .proxies import current_rdm_records
23
- from invenio_rdm_records .resources .serializers .utils import get_vocabulary_props
22
+ from invenio_rdm_records .resources .serializers .signposting import FAIRSignpostingProfileLvl1Serializer
24
23
from invenio_records_resources .services .errors import PermissionDeniedError
25
24
from sqlalchemy .orm .exc import NoResultFound
26
25
27
- from invenio_app_rdm .urls import download_url_for , export_url_for , record_url_for
26
+ from invenio_app_rdm .urls import record_url_for
28
27
29
28
30
29
def service ():
@@ -374,81 +373,6 @@ def _get_header(rel, value, link_type=None):
374
373
return header
375
374
376
375
377
- def _get_signposting_cite_as (record ):
378
- """Release self url points to RDM record.
379
-
380
- It points to DataCite URL if the integration is enabled, otherwise it points to the HTML URL.
381
- """
382
- doi_url = record ["links" ].get ("doi" )
383
- html_url = record ["links" ]["self_html" ]
384
- return _get_header ("cite-as" , doi_url or html_url )
385
-
386
-
387
- def _get_signposting_types (record ):
388
- resource_type = record ["metadata" ]["resource_type" ]
389
- props = get_vocabulary_props (
390
- "resourcetypes" ,
391
- [
392
- "props.schema.org" ,
393
- ],
394
- resource_type ["id" ],
395
- )
396
- url_schema_org = props .get ("schema.org" )
397
- return [
398
- _get_header ("type" , url_schema_org ),
399
- _get_header ("type" , "https://schema.org/AboutPage" ),
400
- ]
401
-
402
-
403
- def _get_signposting_authors (record ):
404
- authors = []
405
- # Limit authors to the first 10.
406
- for creator in islice (record ["metadata" ]["creators" ], 0 , 10 ):
407
- for identifier in creator ["person_or_org" ].get ("identifiers" , []):
408
- if identifier ["scheme" ] == "orcid" :
409
- authors .append (
410
- _get_header (
411
- "author" , "https://orcid.org/" + identifier ["identifier" ]
412
- )
413
- )
414
- return authors
415
-
416
-
417
- def _get_signposting_describedbys (pid_value ):
418
- describedbys = []
419
- for export_format , val in current_app .config .get (
420
- "APP_RDM_RECORD_EXPORTERS" , {}
421
- ).items ():
422
- url = export_url_for (pid_value = pid_value , export_format = export_format )
423
- content_type = val ["content-type" ]
424
- describedbys .append (_get_header ("describedby" , url , content_type ))
425
- return describedbys
426
-
427
-
428
- def _get_signposting_licenses (record ):
429
- licenses = []
430
- for right in record ["metadata" ].get ("rights" , []):
431
- # First try to get `props.url` from the standard licenses,
432
- # then try to get the optional `link` from the custom license.
433
- url = right .get ("props" , {}).get ("url" ) or right .get ("link" )
434
- if url :
435
- licenses .append (_get_header ("license" , url ))
436
- return licenses
437
-
438
-
439
- def _get_signposting_items (files , pid_value ):
440
- items = []
441
- # Checking if the user has access to the potentially restricted files.
442
- if files :
443
- # Limiting the iteration to 100 files maximum.
444
- # The `entries` key does not exist if files are not enabled.
445
- for file in islice (files .to_dict ().get ("entries" , []), 0 , 100 ):
446
- url = download_url_for (pid_value = pid_value , filename = file ["key" ])
447
- items .append (_get_header ("item" , url , file ["mimetype" ]))
448
-
449
- return items
450
-
451
-
452
376
def _get_signposting_collection (pid_value ):
453
377
ui_url = record_url_for (pid_value = pid_value )
454
378
return _get_header ("collection" , ui_url , "text/html" )
@@ -472,21 +396,11 @@ def view(*args, **kwargs):
472
396
response = make_response (f (* args , ** kwargs ))
473
397
474
398
# Relies on other decorators having operated before it
475
- pid_value = kwargs ["pid_value" ]
476
399
record = kwargs ["record" ]
477
- files = kwargs ["files" ]
478
400
479
- signposting_headers = [
480
- _get_signposting_cite_as (record ),
481
- * _get_signposting_types (record ),
482
- * _get_signposting_authors (record ),
483
- * _get_signposting_describedbys (pid_value ),
484
- * _get_signposting_licenses (record ),
485
- * _get_signposting_items (files , pid_value ),
486
- _get_signposting_linkset (pid_value ),
487
- ]
401
+ signposting_headers = FAIRSignpostingProfileLvl1Serializer ().serialize_object (record .to_dict ())
488
402
489
- response .headers ["Link" ] = " , " . join ( signposting_headers )
403
+ response .headers ["Link" ] = signposting_headers
490
404
491
405
return response
492
406
0 commit comments