Skip to content

Commit

Permalink
awards: add "program" field
Browse files Browse the repository at this point in the history
  • Loading branch information
slint authored and zzacharo committed Sep 14, 2023
1 parent 62c9e87 commit a6c5b76
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 0 deletions.
9 changes: 9 additions & 0 deletions invenio_vocabularies/contrib/awards/datastreams.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ def apply(self, stream_entry, **kwargs):

award["id"] = f"{funder_id}::{code}"

funding = next(iter(record.get("funding", [])), None)
if funding:
funding_stream_id = funding.get("funding_stream", {}).get("id", "")
# Example funding stream ID: `EC::HE::HORIZON-AG-UN`. We need the `EC`
# string, i.e. the second "part" of the identifier.
program = next(iter(funding_stream_id.split("::")[1:2]), "")
if program:
award["program"] = program

identifiers = []
if funder_id == awards_ec_ror_id:
identifiers.append(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
},
"acronym": {
"type": "string"
},
"program": {
"type": "string"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
"acronym": {
"type": "keyword"
},
"program": {
"type": "keyword"
},
"funder": {
"type": "object",
"properties": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
"acronym": {
"type": "keyword"
},
"program": {
"type": "keyword"
},
"funder": {
"type": "object",
"properties": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
"acronym": {
"type": "keyword"
},
"program": {
"type": "keyword"
},
"funder": {
"type": "object",
"properties": {
Expand Down
2 changes: 2 additions & 0 deletions invenio_vocabularies/contrib/awards/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class AwardSchema(BaseVocabularySchema):

acronym = SanitizedUnicode()

program = SanitizedUnicode()

id = SanitizedUnicode(
validate=validate.Length(min=1, error=_("PID cannot be blank."))
)
Expand Down
2 changes: 2 additions & 0 deletions tests/contrib/awards/test_awards_datastreams.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def expected_from_award_json():
"title": {"en": "Test title"},
"funder": {"id": "021nxhr62"},
"acronym": "TA",
"program": "GEO/OAD",
}


Expand All @@ -107,6 +108,7 @@ def expected_from_award_json_ec():
"title": {"en": "Test title"},
"funder": {"id": "00k4n6c32"},
"acronym": "TS",
"program": "test",
}


Expand Down

0 comments on commit a6c5b76

Please sign in to comment.