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

bibtex: refactor default entry type. #1617

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
44 changes: 44 additions & 0 deletions invenio_rdm_records/fixtures/data/vocabularies/resource_types.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
openaire_type: publication
eurepo: info:eu-repo/semantics/other
schema.org: https://schema.org/CreativeWork
bibtex: misc
subtype: ""
type: publication
title:
Expand All @@ -26,6 +27,7 @@
openaire_type: publication
eurepo: info:eu-repo/semantics/technicalDocumentation
schema.org: https://schema.org/Collection
bibtex: misc
subtype: publication-annotationcollection
type: publication
title:
Expand All @@ -44,6 +46,7 @@
openaire_type: publication
eurepo: info:eu-repo/semantics/book
schema.org: https://schema.org/Book
bibtex: book
subtype: publication-book
type: publication
title:
Expand All @@ -62,6 +65,7 @@
openaire_type: publication
eurepo: info:eu-repo/semantics/bookPart
schema.org: https://schema.org/ScholarlyArticle
bibtex: misc
subtype: publication-section
type: publication
title:
Expand All @@ -80,6 +84,7 @@
openaire_type: publication
eurepo: info:eu-repo/semantics/conferencePaper
schema.org: https://schema.org/ScholarlyArticle
bibtex: inproceedings
subtype: publication-conferencepaper
type: publication
title:
Expand All @@ -98,6 +103,7 @@
openaire_type: publication
eurepo: info:eu-repo/semantics/conferenceProceedings
schema.org: https://schema.org/ScholarlyArticle
bibtex: misc
subtype: publication-conferenceproceeding
type: publication
title:
Expand All @@ -116,6 +122,7 @@
openaire_type: publication
eurepo: info:eu-repo/semantics/technicalDocumentation
schema.org: https://schema.org/CreativeWork
bibtex: misc
subtype: publication-datamanagementplan
type: publication
title:
Expand All @@ -134,6 +141,7 @@
openaire_type: publication
eurepo: info:eu-repo/semantics/article
schema.org: https://schema.org/ScholarlyArticle
bibtex: misc
subtype: publication-journal
type: publication
title:
Expand All @@ -152,6 +160,7 @@
openaire_type: publication
eurepo: info:eu-repo/semantics/article
schema.org: https://schema.org/ScholarlyArticle
bibtex: article
subtype: publication-article
type: publication
title:
Expand All @@ -170,6 +179,7 @@
openaire_type: publication
eurepo: info:eu-repo/semantics/patent
schema.org: https://schema.org/CreativeWork
bibtex: misc
subtype: publication-patent
type: publication
title:
Expand All @@ -188,6 +198,7 @@
openaire_type: publication
eurepo: info:eu-repo/semantics/review
schema.org: https://schema.org/ScholarlyArticle
bibtex: misc
subtype: publication-peerreview
type: publication
title:
Expand All @@ -206,6 +217,7 @@
openaire_type: publication
eurepo: info:eu-repo/semantics/preprint
schema.org: https://schema.org/ScholarlyArticle
bibtex: unpublished
subtype: publication-preprint
type: publication
title:
Expand All @@ -224,6 +236,7 @@
openaire_type: publication
eurepo: info:eu-repo/semantics/report
schema.org: https://schema.org/CreativeWork
bibtex: misc
subtype: publication-deliverable
type: publication
title:
Expand All @@ -242,6 +255,7 @@
openaire_type: publication
eurepo: info:eu-repo/semantics/report
schema.org: https://schema.org/CreativeWork
bibtex: misc
subtype: publication-milestone
type: publication
title:
Expand All @@ -260,6 +274,7 @@
openaire_type: publication
eurepo: info:eu-repo/semantics/researchProposal
schema.org: https://schema.org/CreativeWork
bibtex: misc
subtype: publication-proposal
type: publication
title:
Expand All @@ -278,6 +293,7 @@
openaire_type: publication
eurepo: info:eu-repo/semantics/report
schema.org: https://schema.org/ScholarlyArticle
bibtex: misc
subtype: publication-report
type: publication
title:
Expand All @@ -296,6 +312,7 @@
openaire_type: publication
eurepo: info:eu-repo/semantics/technicalDocumentation
schema.org: https://schema.org/CreativeWork
bibtex: misc
subtype: publication-softwaredocumentation
type: publication
title:
Expand All @@ -314,6 +331,7 @@
openaire_type: publication
eurepo: info:eu-repo/semantics/other
schema.org: https://schema.org/ScholarlyArticle
bibtex: misc
subtype: publication-taxonomictreatment
type: publication
title:
Expand All @@ -332,6 +350,7 @@
openaire_type: publication
eurepo: info:eu-repo/semantics/technicalDocumentation
schema.org: https://schema.org/ScholarlyArticle
bibtex: manual
subtype: publication-technicalnote
type: publication
title:
Expand All @@ -350,6 +369,7 @@
openaire_type: publication
eurepo: info:eu-repo/semantics/doctoralThesis
schema.org: https://schema.org/ScholarlyArticle
bibtex: phdthesis
subtype: publication-thesis
type: publication
title:
Expand All @@ -368,6 +388,7 @@
openaire_type: publication
eurepo: info:eu-repo/semantics/workingPaper
schema.org: https://schema.org/ScholarlyArticle
bibtex: unpublished
subtype: publication-workingpaper
type: publication
title:
Expand All @@ -386,6 +407,7 @@
openaire_type: publication
eurepo: info:eu-repo/semantics/workingPaper
schema.org: https://schema.org/ScholarlyArticle
bibtex: misc
subtype: publication-datapaper
type: publication
title:
Expand All @@ -404,6 +426,7 @@
openaire_type: publication
eurepo: info:eu-repo/semantics/other
schema.org: https://schema.org/thesis
bibtex: misc
subtype: publication-dissertation
type: publication
title:
Expand All @@ -422,6 +445,7 @@
openaire_type: publication
eurepo: info:eu-repo/semantics/other
schema.org: https://schema.org/other
bibtex: misc
subtype: publication-standard
type: publication
title:
Expand All @@ -440,6 +464,7 @@
openaire_type: publication
eurepo: info:eu-repo/semantics/other
schema.org: https://schema.org/CreativeWork
bibtex: misc
subtype: publication-other
type: publication
title:
Expand All @@ -458,6 +483,7 @@
openaire_type: publication
eurepo: info:eu-repo/semantics/conferencePoster
schema.org: https://schema.org/CreativeWork
bibtex: misc
subtype: ""
type: poster
title:
Expand All @@ -476,6 +502,7 @@
openaire_type: publication
eurepo: info:eu-repo/semantics/lecture
schema.org: https://schema.org/PresentationDigitalDocument
bibtex: misc
subtype: ""
type: presentation
title:
Expand All @@ -494,6 +521,7 @@
openaire_type: publication
eurepo: info:eu-repo/semantics/other
schema.org: https://schema.org/event
bibtex: misc
subtype: ""
type: event
title:
Expand All @@ -512,6 +540,7 @@
openaire_type: dataset
eurepo: info:eu-repo/semantics/other
schema.org: https://schema.org/Dataset
bibtex: dataset
subtype: ""
type: dataset
title:
Expand All @@ -530,6 +559,7 @@
openaire_type: dataset
eurepo: info:eu-repo/semantics/other
schema.org: https://schema.org/ImageObject
bibtex: misc
subtype: ""
type: image
title:
Expand All @@ -548,6 +578,7 @@
openaire_type: dataset
eurepo: info:eu-repo/semantics/other
schema.org: https://schema.org/ImageObject
bibtex: misc
subtype: image-figure
type: image
title:
Expand All @@ -566,6 +597,7 @@
openaire_type: dataset
eurepo: info:eu-repo/semantics/other
schema.org: https://schema.org/ImageObject
bibtex: misc
subtype: image-plot
type: image
title:
Expand All @@ -584,6 +616,7 @@
openaire_type: dataset
eurepo: info:eu-repo/semantics/other
schema.org: https://schema.org/ImageObject
bibtex: misc
subtype: image-drawing
type: image
title:
Expand All @@ -602,6 +635,7 @@
openaire_type: dataset
eurepo: info:eu-repo/semantics/other
schema.org: https://schema.org/ImageObject
bibtex: misc
subtype: image-diagram
type: image
title:
Expand All @@ -620,6 +654,7 @@
openaire_type: dataset
eurepo: info:eu-repo/semantics/other
schema.org: https://schema.org/Photograph
bibtex: misc
subtype: image-photo
type: image
title:
Expand All @@ -638,6 +673,7 @@
openaire_type: dataset
eurepo: info:eu-repo/semantics/other
schema.org: https://schema.org/ImageObject
bibtex: misc
subtype: image-other
type: image
title:
Expand All @@ -656,6 +692,7 @@
openaire_type: dataset
eurepo: info:eu-repo/semantics/other
schema.org: https://schema.org/CreativeWork
bibtex: misc
subtype: ""
type: model
title:
Expand All @@ -674,6 +711,7 @@
openaire_type: dataset
eurepo: info:eu-repo/semantics/other
schema.org: https://schema.org/MediaObject
bibtex: misc
subtype: ""
type: video
title:
Expand All @@ -692,6 +730,7 @@
openaire_type: software
eurepo: info:eu-repo/semantics/other
schema.org: https://schema.org/SoftwareSourceCode
bibtex: software
subtype: ""
type: software
title:
Expand All @@ -710,6 +749,7 @@
openaire_type: other
eurepo: info:eu-repo/semantics/lecture
schema.org: https://schema.org/CreativeWork
bibtex: misc
subtype: ""
type: lesson
title:
Expand All @@ -728,6 +768,7 @@
openaire_type: software
eurepo: info:eu-repo/semantics/other
schema.org: https://schema.org/SoftwareSourceCode
bibtex: misc
subtype: software-computationalnotebook
type: software
title:
Expand All @@ -746,6 +787,7 @@
openaire_type: other
eurepo: info:eu-repo/semantics/other
schema.org: https://schema.org/CreativeWork
bibtex: misc
subtype: ""
type: other
title:
Expand All @@ -764,6 +806,7 @@
openaire_type: other
eurepo: info:eu-repo/semantics/other
schema.org: https://schema.org/CreativeWork
bibtex: misc
subtype: ""
type: physicalobject
title:
Expand All @@ -782,6 +825,7 @@
openaire_type: other
eurepo: info:eu-repo/semantics/other
schema.org: https://schema.org/CreativeWork
bibtex: misc
subtype: ""
type: workflow
title:
Expand Down
21 changes: 14 additions & 7 deletions invenio_rdm_records/resources/serializers/bibtex/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
import textwrap

from flask_resources.serializers import BaseSerializerSchema
from invenio_access.permissions import system_identity
from invenio_i18n import lazy_gettext as _
from invenio_vocabularies.proxies import current_service as vocab_service
from marshmallow import fields, post_dump
from slugify import slugify

Expand Down Expand Up @@ -63,13 +66,17 @@ class BibTexSchema(BaseSerializerSchema, CommonFieldsMixin):
}
"""Maps resource types to formats."""

@property
def default_entry_type(self):
"""Read-only property that defines the default bibtex entry type to be used.
def get_default_entry_type(self, resource_type):
"""Retrieves the default entry type for the given resource type.

The default type can be used when a resource type is not explicitely defined in ``format_mapper``.
The value is read from the vocabulary.
"""
return BibTexFormatter.misc
vocab = vocab_service.read(
system_identity, ("resourcetypes", resource_type), expand=True
).to_dict()
bibtex_type = vocab["props"]["bibtex"]
entry = self.entry_mapper.get(bibtex_type, BibTexFormatter.misc)
return entry

def get_date_created(self, obj):
"""Get date last updated."""
Expand Down Expand Up @@ -189,8 +196,8 @@ def _get_bibtex_entry(self, resource_type, fields_map):

:returns: an object with the bibtex fields for the resource types.
"""
# Every resource type is mapped to a default
entry = self.default_entry_type
# Every resource type is mapped to a default as defined by the resource type vocabulary.
entry = self.get_default_entry_type(resource_type)
if entries := self.entry_mapper.get(resource_type):
for _entry in entries:
success = all([fields_map.get(f) for f in _entry["req_fields"]])
Expand Down
Loading