Skip to content

Commit

Permalink
Update existing record
Browse files Browse the repository at this point in the history
  • Loading branch information
ErnestaP committed Feb 22, 2024
1 parent ada5a93 commit adabf6d
Show file tree
Hide file tree
Showing 6 changed files with 202 additions and 17 deletions.
1 change: 0 additions & 1 deletion scoap3/articles/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ def create(self, request, *args, **kwargs):
return Response(
serializer.data, status=status.HTTP_201_CREATED, headers=headers
)
article_id = data.get("id")


class ArticleWorkflowImportView(ViewSet):
Expand Down
116 changes: 116 additions & 0 deletions scoap3/articles/tests/data/record_failing_on_airflow.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
{
"dois":[
{
"value":"10.1103/PhysRevD.109.046003"
}
],
"page_nr":[
17
],
"arxiv_eprints":[
{
"value":"2312.06750",
"categories":[
"hep-th",
"gr-qc",
"math-ph",
"math.MP"
]
}
],
"authors":[
{
"full_name":"Chatwin-Davies, Aidan",
"given_names":"Aidan",
"surname":"Chatwin-Davies",
"affiliations":[
{
"value":"Okinawa Institute of Science and Technology, 1919-1 Tancha, Onna-son, Kunigami-gun, Okinawa, 904-0495, Japan",
"organization":"Okinawa Institute of Science and Technology, 1919-1 Tancha, Onna-son, Kunigami-gun, Okinawa, 904-0495",
"country":"Japan"
}
]
},
{
"full_name":"Leung, Pompey",
"given_names":"Pompey",
"surname":"Leung",
"affiliations":[
{
"value":"Department of Physics and Astronomy, University of British Columbia, 6224 Agricultural Road, Vancouver, British Columbia, V6T 1Z1, Canada",
"organization":"Department of Physics and Astronomy, University of British Columbia, 6224 Agricultural Road, Vancouver, British Columbia, V6T 1Z1",
"country":"Canada"
}
]
},
{
"full_name":"Remmen, Grant N.",
"given_names":"Grant N.",
"surname":"Remmen",
"affiliations":[
{
"value":"Center for Cosmology and Particle Physics, Department of Physics, New York University, New York, New York, 10003, USA",
"organization":"Center for Cosmology and Particle Physics, Department of Physics, New York University, New York, New York, 10003",
"country":"USA"
}
]
}
],
"license":[
{
"url":"https://creativecommons.org/licenses/by/4.0/",
"license":"CC-BY-4.0"
}
],
"collections":[
{
"primary":"HEP"
},
{
"primary":"Citeable"
},
{
"primary":"Published"
}
],
"publication_info":[
{
"journal_title":"Physical Review D",
"journal_volume":"109",
"year":2024,
"journal_issue":"4",
"material":"article"
}
],
"abstracts":[
{
"value":"<p>Holographic screens are codimension-one hypersurfaces that extend the notion of apparent horizons to general (non-black hole) spacetimes and that display interesting thermodynamic properties. We show that if a spacetime contains a codimension-two, boundary-homologous, minimal extremal spacelike surface <math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"inline\"><mi>X</mi></math> (known as an HRT surface in <math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"inline\"><mrow><mi>AdS</mi><mo>/</mo><mi>CFT</mi></mrow></math>), then any holographic screens are sequestered to the causal wedges of <math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"inline\"><mi>X</mi></math>. That is, any single connected component of a holographic screen can be located in at most one of the causal future, causal past, inner wedge, or outer wedge of <math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"inline\"><mi>X</mi></math>. We comment on how this result informs possible coarse grained entropic interpretations of generic holographic screens, as well as on connections to semiclassical objects such as quantum extremal surfaces.</p>",
"source":"APS"
}
],
"acquisition_source":{
"source":"APS",
"method":"APS",
"date":"2024-02-08T00:00:16.954712"
},
"copyright":[
{
"year":2024,
"statement":"Published by the American Physical Society"
}
],
"imprints":[
{
"date":"2024-02-07",
"publisher":"APS"
}
],
"record_creation_date":"2024-02-08T00:00:16.954712",
"titles":[
{
"title":"Holographic screen sequestration",
"source":"APS"
}
],
"$schema":"https://repo.qa.scoap3.org/schemas/hep.json"
}
1 change: 0 additions & 1 deletion scoap3/articles/tests/data/workflow_record.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"statement": "The Author"
}
],
"control_number": "81204",
"_oai": {
"updated": "2023-10-31T08:21:45Z",
"id": "oai:repo.scoap3.org:81204",
Expand Down
53 changes: 49 additions & 4 deletions scoap3/articles/tests/test_article_views.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import json
import os
from pathlib import Path

import pytest
from django.test import TestCase
from django.urls import reverse
from rest_framework import status

from scoap3.articles.models import Article
from scoap3.articles.models import Article, ArticleIdentifier
from scoap3.users.tests.factories import UserFactory

pytestmark = pytest.mark.django_db

Expand Down Expand Up @@ -53,7 +57,6 @@ def test_update_article_from_workflow(self, client, user, shared_datadir):
)

data["titles"][0]["title"] = "New title"
data["dois"].append({"value": "10.5506/APhysPolB.54.10-A5"})
response = client.post(
reverse("api:article-workflow-import-list"),
data,
Expand All @@ -69,11 +72,13 @@ def test_update_article_from_workflow(self, client, user, shared_datadir):
]

assert article.title == "New title"
assert len(expected_dois) == 2
assert "10.5506/APhysPolB.54.10-A5" in expected_dois
assert len(expected_dois) == 1
assert "10.5506/APhysPolB.54.10-A3" in expected_dois


pytestmark = pytest.mark.django_db


class TestArticleIdentifierViewSet:
def test_get_article_identifier(self, client):
url = reverse("api:articleidentifier-list")
Expand All @@ -83,3 +88,43 @@ def test_get_article_identifier(self, client):
url = reverse("api:articleidentifier-detail", kwargs={"pk": 0})
response = client.get(url)
assert response.status_code == status.HTTP_404_NOT_FOUND


pytestmark = pytest.mark.django_db


class TestTheSameArticleCreationTwice(TestCase):
@staticmethod
def shared_datadir():
return os.path.join(
Path(__file__).parent.resolve(), "data", "record_failing_on_airflow.json"
)

def test_create_article_from_workflow(self):
user = UserFactory()
self.client.force_login(user)
with open(self.shared_datadir()) as file:
contents = file.read()
data = json.loads(contents)
response = self.client.post(
reverse("api:article-workflow-import-list"),
data,
content_type="application/json",
)
assert response.status_code == status.HTTP_200_OK

response = self.client.post(
reverse("api:article-workflow-import-list"),
data,
content_type="application/json",
)
assert response.status_code == status.HTTP_200_OK
doi = data.get("dois")[0].get("value")
assert (
len(
ArticleIdentifier.objects.filter(
identifier_type="DOI", identifier_value=doi
)
)
== 1
)
1 change: 0 additions & 1 deletion scoap3/exports/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def generate_csv_response(data, action_name, write_header=True):
writer = csv.writer(response)
if write_header:
writer.writerow(data.get("header"))
print(data)
for row in data.get("data", []):
writer.writerow(row)

Expand Down
47 changes: 37 additions & 10 deletions scoap3/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,21 @@ def _create_licenses(data):

def _create_article(data, licenses):
article_data = {
"id": data.get("control_number"),
"publication_date": data["imprints"][0].get("date"),
"title": data["titles"][0].get("title"),
"subtitle": data["titles"][0].get("subtitle", ""),
"abstract": data["abstracts"][0].get("value", ""),
}
doi = data.get("dois")[0].get("value")
if (
article_data.get("id")
and Article.objects.filter(pk=article_data["id"]).exists()
doi
and ArticleIdentifier.objects.filter(
identifier_type="DOI", identifier_value=doi
).exists()
):
article = Article.objects.get(pk=article_data["id"])
article = ArticleIdentifier.objects.get(
identifier_type="DOI", identifier_value=doi
).article_id
article.__dict__.update(**article_data)
else:
article = Article.objects.create(**article_data)
Expand Down Expand Up @@ -110,14 +114,22 @@ def _create_article_identifier(data, article):
"identifier_value": doi.get("value"),
}
ArticleIdentifier.objects.get_or_create(**article_identifier_data)

for arxiv in data.get("arxiv_eprints", []):
article_identifier_data = {
"article_id": article,
"identifier_type": "arXiv",
"identifier_value": arxiv.get("value"),
}
ArticleIdentifier.objects.get_or_create(**article_identifier_data)
doi = data.get("dois")[0].get("value")
if ArticleIdentifier.objects.filter(
identifier_type="arXiv", article_id=article
).exists():
article_identifier = ArticleIdentifier.objects.get(
article_id=article, identifier_type="arXiv"
)
article_identifier.__dict__.update(**article_identifier_data)
else:
ArticleIdentifier.objects.get_or_create(**article_identifier_data)


def _create_copyright(data, article):
Expand All @@ -128,7 +140,11 @@ def _create_copyright(data, article):
"holder": copyright.get("holder", ""),
"year": copyright.get("year"),
}
Copyright.objects.get_or_create(**copyright_data)
if Copyright.objects.filter(article_id=article).exists():
copyright = Copyright.objects.get(article_id=article)
copyright.__dict__.update(**copyright_data)
else:
Copyright.objects.get_or_create(**copyright_data)


def _create_article_arxiv_category(data, article):
Expand All @@ -141,8 +157,15 @@ def _create_article_arxiv_category(data, article):
"category": arxiv_category,
"primary": True if idx == 0 else False,
}

ArticleArxivCategory.objects.get_or_create(**article_arxiv_category_data)
if ArticleArxivCategory.objects.filter(article_id=article).exists():
article_arxiv_category = ArticleArxivCategory.objects.get(
article_id=article
)
article_arxiv_category.__dict__.update(**article_arxiv_category_data)
else:
ArticleArxivCategory.objects.get_or_create(
**article_arxiv_category_data
)


def _create_publisher(data):
Expand Down Expand Up @@ -170,7 +193,11 @@ def _create_publication_info(data, article, publishers):
"journal_issue_date": publication_info.get("journal_issue_date"),
"publisher_id": publishers[idx].id,
}
PublicationInfo.objects.get_or_create(**publication_info_data)
if PublicationInfo.objects.filter(article_id=article).exists():
publication_info = PublicationInfo.objects.get(article_id=article)
publication_info.__dict__.update(**publication_info_data)
else:
PublicationInfo.objects.get_or_create(**publication_info_data)


def _create_experimental_collaborations(data):
Expand Down

0 comments on commit adabf6d

Please sign in to comment.