Skip to content

Commit

Permalink
articles: fixes import method
Browse files Browse the repository at this point in the history
Signed-off-by: pamfilos <[email protected]>
  • Loading branch information
pamfilos committed Jul 24, 2024
1 parent 3c0d988 commit 91f1f30
Show file tree
Hide file tree
Showing 4 changed files with 288 additions and 11 deletions.
115 changes: 115 additions & 0 deletions scoap3/articles/tests/data/legacy_record.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
{
"_updated": "2019-08-01T09:35:25.710805+00:00",
"license": [
{
"url": "http://creativecommons.org/licenses/by/3.0/",
"license": "CC-BY-3.0"
}
],
"copyright": [{ "statement": "The Authors" }],
"control_number": "9999",
"_oai": {
"updated": "2018-04-16T09:24:31Z",
"id": "oai:repo.scoap3.org:9999",
"sets": ["PLB"]
},
"authors": [
{
"surname": "Ballesteros",
"given_names": "Angel",
"raw_name": "Ballesteros, Angel",
"affiliations": [
{
"country": "Spain",
"value": "Departamento de Física, Universidad de Burgos, E-09001 Burgos, Spain"
}
],
"full_name": "Ballesteros, Angel",
"orcid": "0000-0003-4085-3094"
},
{
"surname": "Herranz",
"given_names": "Francisco J.",
"raw_name": "Herranz, Francisco J.",
"affiliations": [
{
"country": "Spain",
"value": "Departamento de Física, Universidad de Burgos, E-09001 Burgos, Spain"
}
],
"full_name": "Herranz, Francisco J.",
"orcid": "0000-0002-5323-616X"
},
{
"raw_name": "Naranjo, Pedro",
"affiliations": [
{
"country": "Spain",
"value": "Departamento de Física, Universidad de Burgos, E-09001 Burgos, Spain"
}
],
"surname": "Naranjo",
"given_names": "Pedro",
"full_name": "Naranjo, Pedro"
}
],
"year": "2015",
"_files": [
{
"checksum": "md5:88c7d1a2411f19747efb1a3699041e2c",
"filetype": "xml",
"bucket": "109371f9-38ae-4240-ac32-1e2e7b947248",
"version_id": "d343a079-2d1f-425d-b0d4-ac6745fa232a",
"key": "10.1016/j.physletb.2015.04.041.xml",
"size": 255820
},
{
"checksum": "md5:000cc65ea9e52be52d4ad1bd5493e87d",
"filetype": "pdf",
"bucket": "109371f9-38ae-4240-ac32-1e2e7b947248",
"version_id": "81317cbc-0874-41de-a6ad-dece089444ea",
"key": "10.1016/j.physletb.2015.04.041.pdf",
"size": 351578
},
{
"checksum": "md5:02dd280d11186230f94462d56214deeb",
"filetype": "pdf/a",
"bucket": "109371f9-38ae-4240-ac32-1e2e7b947248",
"version_id": "65caa9d3-2e35-4ba2-b653-0c81ef299eb9",
"key": "10.1016/j.physletb.2015.04.041_a.pdf",
"size": 688328
}
],
"record_creation_date": "2015-04-23T00:00:00",
"titles": [
{
"source": "Elsevier",
"title": "Towards ( 3+1 ) gravity through Drinfel'd doubles with cosmological constant"
}
],
"_created": "2018-04-15T00:45:56.757634+00:00",
"dois": [{ "value": "10.1016/j.physletb.2015.04.041" }],
"publication_info": [
{
"page_end": "43",
"page_start": "37",
"material": "article",
"journal_title": "Physics Letters B",
"year": 2015
}
],
"$schema": "http://repo.scoap3.org/schemas/hep.json",
"abstracts": [
{
"source": "Elsevier",
"value": "We present the generalisation to ( 3+1 ) dimensions of a quantum deformation of the ( 2+1 ) (Anti)-de Sitter and Poincaré Lie algebras that is compatible with the conditions imposed by the Chern–Simons formulation of ( 2+1 ) gravity. Since such compatibility is automatically fulfilled by deformations coming from Drinfel'd double structures, we believe said structures are worth being analysed also in the ( 3+1 ) scenario as a possible guiding principle towards the description of ( 3+1 ) gravity. To this aim, a canonical classical r -matrix arising from a Drinfel'd double structure for the three ( 3+1 ) Lorentzian algebras is obtained. This r -matrix turns out to be a twisted version of the one corresponding to the ( 3+1 ) κ -deformation, and the main properties of its associated noncommutative spacetime are analysed. In particular, it is shown that this new quantum spacetime is not isomorphic to the κ -Minkowski one, and that the isotropy of the quantum space coordinates can be preserved through a suitable change of basis of the quantum algebra generators. Throughout the paper the cosmological constant appears as an explicit parameter, thus allowing the (flat) Poincaré limit to be straightforwardly obtained."
}
],
"imprints": [{ "date": "2015-04-25", "publisher": "Elsevier" }],
"acquisition_source": {
"date": "2015-04-23T00:00:00",
"source": "Elsevier",
"method": "scoap3",
"submission_number": "61850faa40f811e881c402163e01809a"
}
}
115 changes: 115 additions & 0 deletions scoap3/articles/tests/data/legacy_record_update.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
{
"_updated": "2019-08-01T09:35:25.710805+00:00",
"license": [
{
"url": "http://creativecommons.org/licenses/by/3.0/",
"license": "CC-BY-3.0"
}
],
"copyright": [{ "statement": "The Authors" }],
"control_number": "9999",
"_oai": {
"updated": "2018-04-16T09:24:31Z",
"id": "oai:repo.scoap3.org:9999",
"sets": ["PLB"]
},
"authors": [
{
"surname": "Ballesteros",
"given_names": "Angel",
"raw_name": "Ballesteros, Angel",
"affiliations": [
{
"country": "Spain",
"value": "Departamento de Física, Universidad de Burgos, E-09001 Burgos, Spain"
}
],
"full_name": "Ballesteros, Angel",
"orcid": "0000-0003-4085-3094"
},
{
"surname": "Herranz",
"given_names": "Francisco J.",
"raw_name": "Herranz, Francisco J.",
"affiliations": [
{
"country": "Spain",
"value": "Departamento de Física, Universidad de Burgos, E-09001 Burgos, Spain"
}
],
"full_name": "Herranz, Francisco J.",
"orcid": "0000-0002-5323-616X"
},
{
"raw_name": "Naranjo, Pedro",
"affiliations": [
{
"country": "Spain",
"value": "Departamento de Física, Universidad de Burgos, E-09001 Burgos, Spain"
}
],
"surname": "Naranjo",
"given_names": "Pedro",
"full_name": "Naranjo, Pedro"
}
],
"year": "2015",
"_files": [
{
"checksum": "md5:88c7d1a2411f19747efb1a3699041e2c",
"filetype": "xml",
"bucket": "109371f9-38ae-4240-ac32-1e2e7b947248",
"version_id": "d343a079-2d1f-425d-b0d4-ac6745fa232a",
"key": "10.1016/j.physletb.2015.04.041.xml",
"size": 255820
},
{
"checksum": "md5:000cc65ea9e52be52d4ad1bd5493e87d",
"filetype": "pdf",
"bucket": "109371f9-38ae-4240-ac32-1e2e7b947248",
"version_id": "81317cbc-0874-41de-a6ad-dece089444ea",
"key": "10.1016/j.physletb.2015.04.041.pdf",
"size": 351578
},
{
"checksum": "md5:02dd280d11186230f94462d56214deeb",
"filetype": "pdf/a",
"bucket": "109371f9-38ae-4240-ac32-1e2e7b947248",
"version_id": "65caa9d3-2e35-4ba2-b653-0c81ef299eb9",
"key": "10.1016/j.physletb.2015.04.041_a.pdf",
"size": 688328
}
],
"record_creation_date": "2015-04-23T00:00:00",
"titles": [
{
"source": "Elsevier",
"title": "Updated: Towards ( 3+1 ) gravity through Drinfel'd doubles with cosmological constant"
}
],
"_created": "2018-04-15T00:45:56.757634+00:00",
"dois": [{ "value": "10.1016/j.physletb.2015.04.041" }],
"publication_info": [
{
"page_end": "43",
"page_start": "37",
"material": "article",
"journal_title": "Physics Letters B",
"year": 2015
}
],
"$schema": "http://repo.scoap3.org/schemas/hep.json",
"abstracts": [
{
"source": "Elsevier",
"value": "We present the generalisation to ( 3+1 ) dimensions of a quantum deformation of the ( 2+1 ) (Anti)-de Sitter and Poincaré Lie algebras that is compatible with the conditions imposed by the Chern–Simons formulation of ( 2+1 ) gravity. Since such compatibility is automatically fulfilled by deformations coming from Drinfel'd double structures, we believe said structures are worth being analysed also in the ( 3+1 ) scenario as a possible guiding principle towards the description of ( 3+1 ) gravity. To this aim, a canonical classical r -matrix arising from a Drinfel'd double structure for the three ( 3+1 ) Lorentzian algebras is obtained. This r -matrix turns out to be a twisted version of the one corresponding to the ( 3+1 ) κ -deformation, and the main properties of its associated noncommutative spacetime are analysed. In particular, it is shown that this new quantum spacetime is not isomorphic to the κ -Minkowski one, and that the isotropy of the quantum space coordinates can be preserved through a suitable change of basis of the quantum algebra generators. Throughout the paper the cosmological constant appears as an explicit parameter, thus allowing the (flat) Poincaré limit to be straightforwardly obtained."
}
],
"imprints": [{ "date": "2015-04-25", "publisher": "Elsevier" }],
"acquisition_source": {
"date": "2015-04-23T00:00:00",
"source": "Elsevier",
"method": "scoap3",
"submission_number": "61850faa40f811e881c402163e01809a"
}
}
33 changes: 33 additions & 0 deletions scoap3/articles/tests/test_article_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,39 @@ def test_create_article_from_workflow(self, client, user, shared_datadir):
== "The Effective QCD Running Coupling Constant and a Dirac Model for the Charmonium Spectrum"
)

def test_create_article_from_legacy(self, client, user, shared_datadir):
client.force_login(user)
contents = (shared_datadir / "legacy_record.json").read_text()
data = json.loads(contents)

response = client.post(
reverse("api:article-workflow-import-list"),
data,
content_type="application/json",
)
assert response.status_code == status.HTTP_200_OK

article_id = response.data["id"]

assert article_id == int(data["control_number"])
assert response.data["title"] == data["titles"][0]["title"]

contents = (shared_datadir / "legacy_record_update.json").read_text()
data_updated = json.loads(contents)

response = client.post(
reverse("api:article-workflow-import-list"),
data_updated,
content_type="application/json",
)
assert response.status_code == status.HTTP_200_OK

article_id = response.data["id"]

assert article_id == int(data_updated["control_number"])
assert response.data["title"] == data_updated["titles"][0]["title"]


def test_update_article_from_workflow(self, client, user, shared_datadir):
client.force_login(user)
contents = (shared_datadir / "workflow_record.json").read_text()
Expand Down
36 changes: 25 additions & 11 deletions scoap3/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,22 +89,36 @@ def _create_article(data, licenses):
"subtitle": data["titles"][0].get("subtitle", ""),
"abstract": data["abstracts"][0].get("value", ""),
}
if (
article_data.get("id")
and Article.objects.filter(pk=article_data["id"]).exists()
):
article = Article.objects.get(pk=article_data["id"])
article.__dict__.update(**article_data)
elif (
data.get("dois")[0].get("value")
and ArticleIdentifier.objects.filter(

doi_exists = False
doi_value = data.get("dois")[0].get("value")
if doi_value:
doi_exists = ArticleIdentifier.objects.filter(
identifier_type="DOI", identifier_value=data.get("dois")[0].get("value")
).exists()
):

# if "control_number" present, means it is a legacy record
if data.get("control_number"):
if doi_exists:
logger.info(
f"Creating article with id={data['control_number']} - "
f"Article with DOI={doi_value} already exists."
)
control_number = int(data["control_number"])
if Article.objects.filter(pk=control_number).exists():
article = Article.objects.get(pk=control_number)
article.__dict__.update(**article_data)
else:
article_data["id"] = control_number
article = Article.objects.create(**article_data)
article._created_at = data.get("_created") or data.get("record_creation_date")
# else if "doi" present, check to update a already inserted article
elif doi_exists:
article = ArticleIdentifier.objects.get(
identifier_type="DOI", identifier_value=data.get("dois")[0].get("value")
identifier_type="DOI", identifier_value=doi_value
).article_id
article.__dict__.update(**article_data)
# else create new
else:
article = Article.objects.create(**article_data)
article._created_at = data.get("_created") or data.get("record_creation_date")
Expand Down

0 comments on commit 91f1f30

Please sign in to comment.