From bd7bb27cd685bb32738079fe5891eadac7f61d85 Mon Sep 17 00:00:00 2001 From: LinaKind Date: Thu, 19 Dec 2024 13:14:29 +0000 Subject: [PATCH] Support elifeAssessmentTerms in the ArticleVoR https://github.com/elifesciences/issues/issues/9034 --- src/Serializer/ArticleVoRNormalizer.php | 23 ++++++++++++++++++- test/Serializer/ArticleVoRNormalizerTest.php | 13 ++++++----- .../PromotionalCollectionNormalizerTest.php | 2 +- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/Serializer/ArticleVoRNormalizer.php b/src/Serializer/ArticleVoRNormalizer.php index 80940d37..edf1be4f 100644 --- a/src/Serializer/ArticleVoRNormalizer.php +++ b/src/Serializer/ArticleVoRNormalizer.php @@ -12,6 +12,7 @@ use eLife\ApiSdk\Model\ArticleVersion; use eLife\ApiSdk\Model\ArticleVoR; use eLife\ApiSdk\Model\Block; +use eLife\ApiSdk\Model\ElifeAssessment; use eLife\ApiSdk\Model\Model; use eLife\ApiSdk\Model\PublicReview; use eLife\ApiSdk\Model\Reference; @@ -43,6 +44,7 @@ protected function denormalizeArticle( $data['elifeAssessment']['doi'] ?? null, $data['elifeAssessment']['id'] ?? null ); + $elifeAssessment = $this->denormalizer->denormalize($data['elifeAssessment'], ElifeAssessment::class, $format, $context); } if ($article) { @@ -310,7 +312,8 @@ protected function denormalizeArticle( $elifeAssessmentScietyUri, $data['recommendationsForAuthors'], $recommendationsForAuthorsTitle, - $data['publicReviews'] + $data['publicReviews'], + $elifeAssessment ?? null ); } @@ -475,6 +478,15 @@ protected function normalizeArticle( })->toArray(); } + if ($article->getElifeAssessment()) { + if ($article->getElifeAssessment()->getSignificance() !== null) { + $data['elifeAssessment']['significance'] = $article->getElifeAssessment()->getSignificance(); + } + if ($article->getElifeAssessment()->getStrength() !== null) { + $data['elifeAssessment']['strength'] = $article->getElifeAssessment()->getStrength(); + } + } + if (empty($context['snippet'])) { if ($article->getElifeAssessmentArticleSection()) { $data['elifeAssessment'] = [ @@ -501,6 +513,15 @@ protected function normalizeArticle( } } + if ($article->getElifeAssessment()) { + if ($article->getElifeAssessment()->getSignificance() !== null) { + $data['elifeAssessment']['significance'] = $article->getElifeAssessment()->getSignificance(); + } + if ($article->getElifeAssessment()->getStrength() !== null) { + $data['elifeAssessment']['strength'] = $article->getElifeAssessment()->getStrength(); + } + } + if ($article->getRecommendationsForAuthors()) { $data['recommendationsForAuthors'] = [ 'title' => $article->getRecommendationsForAuthorsTitle(), diff --git a/test/Serializer/ArticleVoRNormalizerTest.php b/test/Serializer/ArticleVoRNormalizerTest.php index cff73f78..afca25cc 100644 --- a/test/Serializer/ArticleVoRNormalizerTest.php +++ b/test/Serializer/ArticleVoRNormalizerTest.php @@ -150,7 +150,7 @@ public function normalizeProvider() : array ->withDecisionLetter(promise_for(new ArticleSection(new ArraySequence([new Paragraph('Article 09560 decision letter text')]), '10.7554/eLife.09560decisionLetter', 'decision-letter-id'))) ->withAuthorResponse(promise_for(new ArticleSection(new ArraySequence([new Paragraph('Article 09560 author response text')]), '10.7554/eLife.09560authorResponse', 'author-response-id'))) ->withElifeAssessmentArticleSection(new ArticleSection(new ArraySequence([new Paragraph('Article 09560 elife assessment text')]), '10.7554/eLife.09560elifeAssessment', 'elife-assessment-id')) -// ->withElifeAssessment(new ElifeAssessment(['important'], ['solid'])) + ->withElifeAssessment(new ElifeAssessment(['important'], ['solid'])) ->withRecommendationsForAuthors(promise_for(new ArticleSection(new ArraySequence([new Paragraph('Article 09560 recommendations for authors text')]), '10.7554/eLife.09560recommendationsForAuthors', 'recommendations-for-authors-id'))) ->withPublicReviews(new ArraySequence([new PublicReview('Public review 1', new ArraySequence([new Paragraph('Public review 1 content')]))])) ->__invoke(), @@ -449,8 +449,8 @@ public function normalizeProvider() : array 'scietyUri' => 'https://elife-assessment.com', 'doi' => '10.7554/eLife.09560elifeAssessment', 'id' => 'elife-assessment-id', -// 'significance' => ['important'], -// 'strength' => ['solid'], + 'significance' => ['important'], + 'strength' => ['solid'], ], 'recommendationsForAuthors' => [ 'title' => 'Recommendations for authors', @@ -526,6 +526,7 @@ function ($test) { ->withDecisionLetterDescription(new EmptySequence()) ->withPromiseOfAuthorResponse(null) ->withElifeAssessmentArticleSection(null) + ->withElifeAssessment(null) ->withElifeAssessmentTitle(null) ->withElifeAssessmentScietyUri(null) ->withPromiseOfRecommendationsForAuthors(null) @@ -584,7 +585,7 @@ function ($test) { ->withDecisionLetter(promise_for(new ArticleSection(new ArraySequence([new Paragraph('Article 09560 decision letter text')]), '10.7554/eLife.09560decisionLetter', 'decision-letter-id'))) ->withDecisionLetterDescription(new ArraySequence([new Paragraph('Article 09560 decision letter description')])) ->withAuthorResponse(promise_for(new ArticleSection(new ArraySequence([new Paragraph('Article 09560 author response text')]), '10.7554/eLife.09560authorResponse', 'author-response-id'))) -// ->withElifeAssessment(new ElifeAssessment(['landmark'], ['solid'])) + ->withElifeAssessment(new ElifeAssessment(['landmark'], ['solid'])) ->withElifeAssessmentArticleSection(new ArticleSection(new ArraySequence([new Paragraph('Article 09560 elife assessment text')]), '10.7554/eLife.09560elifeAssessment', 'elife-assessment-id')) ->withElifeAssessmentTitle('eLife assessment') ->withElifeAssessmentScietyUri('https://elife-assessment-09560.com') @@ -666,8 +667,8 @@ function ($test) { 'text' => 'Article 09560 elife assessment text', ], ], -// 'significance' => ['landmark'], -// 'strength' => ['solid'], + 'significance' => ['landmark'], + 'strength' => ['solid'], ] ], function (ApiTestCase $test) { diff --git a/test/Serializer/PromotionalCollectionNormalizerTest.php b/test/Serializer/PromotionalCollectionNormalizerTest.php index ffb7f21b..8cfa9eff 100644 --- a/test/Serializer/PromotionalCollectionNormalizerTest.php +++ b/test/Serializer/PromotionalCollectionNormalizerTest.php @@ -668,7 +668,7 @@ function (ApiTestCase $test) { $test->mockSubjectCall('biophysics-structural-biology', true); $test->mockArticleCall('14107', true, false, 1); }, - ], + ], 'complete snippet' => [ Builder::for(PromotionalCollection::class) ->withId('1')