From 307728d924f107b5ee5f289f91dc0ec4d32e3c47 Mon Sep 17 00:00:00 2001 From: Pablo Tamarit Date: Mon, 14 Oct 2024 14:25:53 +0200 Subject: [PATCH] awards: rollback to use the 2nd part of funding stream as program --- invenio_vocabularies/contrib/awards/datastreams.py | 5 ++++- tests/contrib/awards/test_awards_datastreams.py | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/invenio_vocabularies/contrib/awards/datastreams.py b/invenio_vocabularies/contrib/awards/datastreams.py index 9ed455c8..0310bb4c 100644 --- a/invenio_vocabularies/contrib/awards/datastreams.py +++ b/invenio_vocabularies/contrib/awards/datastreams.py @@ -74,7 +74,10 @@ def apply(self, stream_entry, **kwargs): funding = next(iter(record.get("funding", [])), None) if funding: - program = funding.get("fundingStream", {}).get("id", "") + funding_stream_id = funding.get("fundingStream", {}).get("id", "") + # Example funding stream ID: `EC::HE::HORIZON-AG-UN`. We need the `HE` + # string, i.e. the second "part" of the identifier. + program = next(iter(funding_stream_id.split("::")[1:2]), "") if program: award["program"] = program diff --git a/tests/contrib/awards/test_awards_datastreams.py b/tests/contrib/awards/test_awards_datastreams.py index 5986ce7d..93bc67b9 100644 --- a/tests/contrib/awards/test_awards_datastreams.py +++ b/tests/contrib/awards/test_awards_datastreams.py @@ -92,7 +92,7 @@ def expected_from_award_json(): "id": "021nxhr62::0751743", "identifiers": [{"identifier": "https://test.com", "scheme": "url"}], "number": "0751743", - "program": "NSF::GEO/OAD::GEO/OCE", + "program": "GEO/OAD", "title": {"en": "Test title"}, "funder": {"id": "021nxhr62"}, "acronym": "TA", @@ -110,7 +110,7 @@ def expected_from_award_json_ec(): "title": {"en": "Test title"}, "funder": {"id": "00k4n6c32"}, "acronym": "TS", - "program": "TST::test::test", + "program": "test", }