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

wip #76

Merged
merged 6 commits into from
Jan 8, 2025
Merged

wip #76

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
3 changes: 2 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2022-2024 Graz University of Technology.
# Copyright (C) 2022-2025 Graz University of Technology.
#
# invenio-workflows-tugraz is free software; you can redistribute it and/or
# modify it under the terms of the MIT License; see LICENSE file for more
Expand Down Expand Up @@ -30,6 +30,7 @@
("py:class", "invenio_pure.types.PureConfigs"),
("py:class", "invenio_records_marc21.services.services.Marc21RecordService"),
("py:class", "invenio_records_resources.services.records.results.RecordItem"),
("py:class", "invenio_pure.services.services.PureRESTService"),
]

# -- General configuration ---------------------------------------------------
Expand Down
16 changes: 8 additions & 8 deletions invenio_workflows_tugraz/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@

"""Configuration file."""


from invenio_i18n import gettext as _
from invenio_rdm_records.services.pids.providers import ExternalPIDProvider

from .imoox import imoox_import_func
from .openaccess import pure_import_func, pure_sieve_func
from .openaccess import import_func, openaccess_filter
from .teachcenter import teachcenter_import_func
from .theses import (
create_func,
Expand Down Expand Up @@ -49,12 +50,6 @@
WORKFLOWS_CAMPUSONLINE_DUPLICATE_FUNC = duplicate_func
""""""

WORKFLOWS_PURE_IMPORT_FUNC = pure_import_func
"""See corresponding varaible in invenio-pure."""

WORKFLOWS_PURE_SIEVE_FUNC = pure_sieve_func
""""""

WORKFLOWS_IMOOX_REPOSITORY_IMPORT_FUNC = imoox_import_func
""""""

Expand All @@ -72,7 +67,7 @@
"required": False,
"label": _("MOODLE"),
},
"moodle-alternative": {
"moodle_alternative": {
"providers": ["moodle"],
"required": False,
"label": _("MOODLE"),
Expand All @@ -85,3 +80,8 @@

WORKFLOWS_MOODLE_REPOSITORY_IMPORT_FUNC = teachcenter_import_func
""""""

WORKFLOWS_PURE_IMPORT_FUNC = import_func
"""See corresponding varaible in invenio-pure."""

WORKFLOWS_PURE_FILTER_RECORDS = openaccess_filter()
6 changes: 3 additions & 3 deletions invenio_workflows_tugraz/openaccess/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2022-2023 Graz University of Technology.
# Copyright (C) 2022-2024 Graz University of Technology.
#
# invenio-workflows-tugraz is free software; you can redistribute it and/or
# modify it under the terms of the MIT License; see LICENSE file for more
# details.

"""Open Access Workflow."""

from .workflow import pure_import_func, pure_sieve_func
from .workflow import import_func, openaccess_filter

__all__ = ("pure_import_func", "pure_sieve_func")
__all__ = ("import_func", "openaccess_filter")
9 changes: 9 additions & 0 deletions invenio_workflows_tugraz/openaccess/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2022-2024 Graz University of Technology.
#
# invenio-workflows-tugraz is free software; you can redistribute it and/or
# modify it under the terms of the MIT License; see LICENSE file for more
# details.

"""Open Access Workflows config."""
83 changes: 49 additions & 34 deletions invenio_workflows_tugraz/openaccess/convert.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2022-2023 Graz University of Technology.
# Copyright (C) 2022-2025 Graz University of Technology.
#
# invenio-workflows-tugraz is free software; you can redistribute it and/or
# modify it under the terms of the MIT License; see LICENSE file for more
# details.

"""Open Access Workflow."""

from contextlib import suppress
from json import load
from pathlib import Path

Expand Down Expand Up @@ -43,7 +44,7 @@ def convert_attribute(
record: Marc21Metadata,
) -> None:
"""Traverse first level elements of dictionary and extract attributes."""
convert_function = getattr(self, f"convert_{attribute}", lambda _: None)
convert_function = getattr(self, f"convert_{attribute}", lambda _, __: None)
convert_function(value, record)


Expand All @@ -52,46 +53,61 @@ class Pure2Marc21(Converter):

def convert_abstract(self, value: dict, record: Marc21Metadata) -> None:
"""Add the abstract to the Marc21Metadata."""
for abstract in value["text"]:
record.emplace_field("520...", value=abstract["value"])
try:
abstract = value["de_DE"]
except KeyError:
try:
abstract = value["en_GB"]
except KeyError:
abstract = None

if abstract:
record.emplace_datafield("520...", value=abstract)

def convert_additionalLinks(self, value: list, record: Marc21Metadata) -> None:
"""Add the additionalLinks attribute to the Marc21Metadata."""
for link in value:
if "url" in link:
record.emplace_field("856.4.1.u", value=link["url"])
record.emplace_datafield("856.4.1.u", value=link["url"])

def convert_bibliographicalNote(self, value: dict, record: Marc21Metadata) -> None:
"""Add the bibliographicalNote attribute to the Marc21Metadata."""
for text in value["text"]:
record.emplace_field("500...", value=text["value"])
record.emplace_datafield("500...", value=text["value"])

def convert_edition(self, value: str, record: Marc21Metadata) -> None:
"""Add the edition attribute to the Marc21Metadata."""
record.emplace_field("250...", value=value)
record.emplace_datafield("250...", value=value)

def convert_electronicIsbns(self, value: list, record: Marc21Metadata) -> None:
"""Add the electronicIsbns attribute to the Marc21Metadata."""
record.emplace_field("020...", value=str(value[0]).strip())
record.emplace_datafield("020...", value=str(value[0]).strip())

def convert_event(self, value: dict, record: Marc21Metadata) -> None:
"""Add the event attribute to the Marc21Metadata."""
for event_name in value["name"]["text"]:
record.emplace_field("711.2..", value=event_name["value"])
record.emplace_datafield("711.2..", value=event_name["value"])

def convert_isbns(self, value: list, record: Marc21Metadata) -> None:
"""Add the isbns attribute to the Marc21Metadata."""
for isbn in value:
record.emplace_field("020...", value=isbn)
record.emplace_datafield("020...", value=isbn)

def convert_journalAssociation(self, value: dict, record: Marc21Metadata) -> None:
"""Add the journalAssociation attribute to the Marc21Metadata."""
value = value["title"]["value"]
record.emplace_field("773.0.8.t", value=value)
subfs = {}

with suppress(KeyError):
subfs["t"] = value["title"]["title"]
with suppress(KeyError):
subfs["x"] = value["issn"]["issn"]

if subfs:
record.emplace_datafield("773.0.8.", subfs=subfs)

def convert_journalNumber(self, value: str, record: Marc21Metadata) -> None:
"""Add the journalNumber attribute to the Marc21Metadata."""
record.emplace_field("773.0.8.g", value=value)
record.emplace_datafield("773.0.8.g", value=value)

def convert_keywordGroups(self, value: list, record: Marc21Metadata) -> None:
"""Add the keywordGroups attribute to the Marc21Metadata."""
Expand All @@ -101,10 +117,9 @@ def convert_keywordGroups(self, value: list, record: Marc21Metadata) -> None:

def convert_language(self, value: dict, record: Marc21Metadata) -> None:
"""Add the language attribute to the Marc21Metadata."""
for locale in value["term"]["text"]:
language = locale["value"]
language_iso6393 = self.languages[language]
record.emplace_field("041...", value=language_iso6393)
language = value["term"]["en_GB"]
language_iso6393 = self.languages[language]
record.emplace_datafield("041...", value=language_iso6393)

def convert_managingOrganisationalUnit(
self,
Expand All @@ -118,7 +133,7 @@ def convert_managingOrganisationalUnit(

def convert_numberOfPages(self, value: int, record: Marc21Metadata) -> None:
"""Add the numberOfPages attribute to the Marc21Metadata."""
record.emplace_field("300...", value=str(value))
record.emplace_datafield("300...", value=str(value))

def convert_organisationalUnits(self, value: list, record: Marc21Metadata) -> None:
"""Add the organisationalUnits attribute to the Marc21Metadata."""
Expand All @@ -130,11 +145,11 @@ def convert_organisationalUnits(self, value: list, record: Marc21Metadata) -> No
def convert_pages(self, value: str, record: Marc21Metadata) -> None:
"""Add the pages attriute to the Marc21Metadata."""
pages = value
record.emplace_field("300...", value=pages)
record.emplace_datafield("300...", value=pages)

def convert_patentNumber(self, value: str, record: Marc21Metadata) -> None:
"""Add the patentNumber attribute to the Marc21Metadata."""
record.emplace_field("013...", value=value)
record.emplace_datafield("013...", value=value)

def convert_peerReview(
self,
Expand All @@ -144,16 +159,16 @@ def convert_peerReview(
"""Add the peerReview attribute to the Marc21Metadata."""
if value:
status = "Refereed/Peer-reviewed"
record.emplace_field("500...", value=status)
record.emplace_datafield("500...", value=status)

def convert_placeOfPublication(self, value: str, record: Marc21Metadata) -> None:
"""Add the placeOfPublication attribute to the Marc21Metadata."""
record.emplace_field("264...", value=value)
record.emplace_datafield("264..1.", value=value)

def convert_publicationSeries(self, value: list, record: Marc21Metadata) -> None:
"""Add the publicationSeries attribute to the Marc21Metadata."""
for series in value:
record.emplace_field("490.0..", value=series["name"])
record.emplace_datafield("490.0..", value=series["name"])

def convert_publicationStatuses(self, value: list, record: Marc21Metadata) -> None:
"""Add the publicationStatuses attribute to the Marc21Metadata."""
Expand All @@ -164,26 +179,26 @@ def convert_publicationStatuses(self, value: list, record: Marc21Metadata) -> No
def convert_publisher(self, value: dict, record: Marc21Metadata) -> None:
"""Add the publisher attribute to the Marc21Metadata."""
for text in value["name"]["text"]:
record.emplace_field("264...b", value=text["value"])
record.emplace_datafield("264..1.b", value=text["value"])

def convert_relatedProjects(self, value: list, record: Marc21Metadata) -> None:
"""Add the relatedProjects attribute to the Marc21Metadata."""
for entry in value:
for locale in entry["name"]["text"]:
record.emplace_field("536...", value=locale["value"])
record.emplace_datafield("536...", value=locale["value"])

def convert_subTitle(self, value: dict, record: Marc21Metadata) -> None:
"""Add the subTitle attribute to the Marc21Metadata."""
record.emplace_field("245.1.0.b", value=value["value"])
record.emplace_datafield("245.1.0.b", value=value["value"])

def convert_title(self, value: dict, record: Marc21Metadata) -> None:
"""Add the title attribute to the Marc21Metadata."""
record.emplace_field("245.1.0.", value=value["value"])
record.emplace_datafield("245.1.0.", value=value["value"])

def convert_volume(self, value: str, record: Marc21Metadata) -> None:
"""Add the volume attribute to the Marc21Metadata."""
record.emplace_field("490.0..", value=value)
record.emplace_field("773.0.8.g", value=value)
record.emplace_datafield("490.0..", value=value)
record.emplace_datafield("773.0.8.g", value=value)


class KeywordGroup(Converter):
Expand All @@ -198,22 +213,22 @@ def convert_freeKeywords(self, value: list, record: Marc21Metadata) -> None:
"""Add free keywords."""
for free_keyword in value:
for word in free_keyword["freeKeywords"]:
record.emplace_field("650..4.g", value=word)
record.emplace_datafield("650..4.g", value=word)

def convert_structuredKeyword(self, value: dict, record: Marc21Metadata) -> None:
"""Add free keywords."""
for word in value["term"]["text"]:
record.emplace_field("650..4.", value=word["value"])
record.emplace_datafield("650..4.", value=word["value"])


class PublicationStatus(Converter):
"""Class to convert publication status."""

def convert_publicationDate(self, value: dict, record: Marc21Metadata) -> None:
"""Add the publication date to the Marc21Metadata."""
record.emplace_field("264...c", value=value["year"])
# without cast not serializable
record.emplace_datafield("264..1.c", value=str(value["year"]))

def convert_publicationStatus(self, value: dict, record: Marc21Metadata) -> None:
"""Add the publication status to the Marc21Metadata."""
for text in value["term"]["text"]:
record.emplace_field("250...", value=text["value"])
record.emplace_datafield("250...", value=value["term"]["de_DE"])
4 changes: 2 additions & 2 deletions invenio_workflows_tugraz/openaccess/types.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2022 Graz University of Technology.
# Copyright (C) 2022-2024 Graz University of Technology.
#
# invenio-workflows-tugraz is free software; you can redistribute it and/or
# modify it under the terms of the MIT License; see LICENSE file for more
Expand All @@ -14,4 +14,4 @@
class PureId(Marc21Category):
"""Pure ID."""

category: str = "995.subfields.d.keyword"
category: str = "024.subfields.a.keyword"
Loading
Loading