From ae97e00f76adbff57ec17739b6373ab2a17b9188 Mon Sep 17 00:00:00 2001 From: Jhon Date: Wed, 6 Nov 2024 16:56:01 -0400 Subject: [PATCH 1/6] Adds unit test for Open Alex client Issue: documentacao-e-tarefas/scielo#715 Signed-off-by: Jhon --- tests/clients/OpenAlexClientTest.php | 100 +++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 tests/clients/OpenAlexClientTest.php diff --git a/tests/clients/OpenAlexClientTest.php b/tests/clients/OpenAlexClientTest.php new file mode 100644 index 0000000..32cd79d --- /dev/null +++ b/tests/clients/OpenAlexClientTest.php @@ -0,0 +1,100 @@ + 42, + null => 0, + '10.987/131415' => 31 + ]; + private $submissions; + + public function setUp(): void + { + $this->submissions = $this->createTestSubmissions(); + $this->mockGuzzleClient = $this->createMockGuzzleClient(); + $this->crossrefClient = new CrossrefClient($this->mockGuzzleClient); + } + + private function createMockGuzzleClient() + { + $mockResponses = []; + + foreach ($this->mapDoiCitationsCount as $doi => $citationsCount) { + if (empty($doi)) { + continue; + } + + $responseBody = [ + 'id' => 'https://openalex.org/asdjakdfja', + 'doi' => "https://doi.org/$doi", + 'cited_by_count' => $citationsCount + ]; + $mockResponses[] = new Response(200, [], json_encode($responseBody)); + } + + $mockHandler = new MockHandler($mockResponses); + $guzzleClient = new Client(['handler' => $mockHandler]); + + return $guzzleClient; + } + + private function createTestSubmissions(): array + { + $submissions = []; + $submissionId = 10; + + foreach ($this->mapDoiCitationsCount as $doi => $citationsCount) { + $submissions[] = $this->createSubmission($submissionId++, $doi); + } + + return $submissions; + } + + private function createSubmission(int $submissionId, ?string $doi): Submission + { + $submission = new Submission(); + $submission->setData('id', $submissionId); + $publication = new Publication(); + $publication->setData('id', $submissionId + 2); + + if (!is_nulL($doi)) { + $doiObject = Repo::doi()->newDataObject([ + 'doi' => $doi, + 'contextId' => $this->contextId + ]); + + $publication->setData('doiObject', $doiObject); + } + + $submission->setData('currentPublicationId', $publication->getId()); + $submission->setData('publications', [$publication]); + return $submission; + } + + public function testGetSubmissionCitationsCount() + { + $submissionsCitationsCount = $this->crossrefClient->getSubmissionsCitationsCount($this->submissions); + + foreach ($this->submissions as $submission) { + $doi = $submission->getCurrentPublication()->getDoi(); + $submissionId = $submission->getId(); + + $this->assertEquals($this->mapDoiCitationsCount[$doi], $submissionsCitationsCount[$submissionId]); + } + } +} From 048b6effceedcbaa07e2df9f93904a19639a6f30 Mon Sep 17 00:00:00 2001 From: Jhon Date: Wed, 6 Nov 2024 17:19:14 -0400 Subject: [PATCH 2/6] Creates Open Alex client Issue: documentacao-e-tarefas/scielo#715 Signed-off-by: Jhon --- classes/clients/OpenAlexClient.php | 72 ++++++++++++++++++++++++++++ tests/clients/OpenAlexClientTest.php | 2 +- 2 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 classes/clients/OpenAlexClient.php diff --git a/classes/clients/OpenAlexClient.php b/classes/clients/OpenAlexClient.php new file mode 100644 index 0000000..0b0df5a --- /dev/null +++ b/classes/clients/OpenAlexClient.php @@ -0,0 +1,72 @@ +guzzleClient = $guzzleClient; + } else { + $this->guzzleClient = Application::get()->getHttpClient(); + } + } + + public function getSubmissionsCitationsCount(array $submissions): array + { + $requests = []; + $citationsCount = []; + + foreach ($submissions as $submission) { + $publication = $submission->getCurrentPublication(); + $doi = $publication->getDoi(); + + if (empty($doi)) { + $citationsCount[$submission->getId()] = 0; + continue; + } + + $requestUrl = htmlspecialchars(self::OPEN_ALEX_API_URL . "?filter=doi:$doi"); + $requests[$submission->getId()] = new Request( + 'GET', + $requestUrl, + [ + 'headers' => ['Accept' => 'application/json'], + ] + ); + } + + $pool = new Pool($this->guzzleClient, $requests, [ + 'concurrency' => 5, + 'fulfilled' => function ($response, $index) use (&$citationsCount) { + $responseJson = json_decode($response->getBody(), true); + $recordDoi = $responseJson['doi']; + + if (empty($recordDoi)) { + $citationsCount[$index] = 0; + return; + } + + $citationsCount[$index] = (int) $responseJson['cited_by_count']; + }, + 'rejected' => function ($reason, $index) use (&$citationsCount) { + $citationsCount[$index] = 0; + }, + ]); + + $promise = $pool->promise(); + $promise->wait(); + + return $citationsCount; + } +} diff --git a/tests/clients/OpenAlexClientTest.php b/tests/clients/OpenAlexClientTest.php index 32cd79d..72d98c5 100644 --- a/tests/clients/OpenAlexClientTest.php +++ b/tests/clients/OpenAlexClientTest.php @@ -27,7 +27,7 @@ public function setUp(): void { $this->submissions = $this->createTestSubmissions(); $this->mockGuzzleClient = $this->createMockGuzzleClient(); - $this->crossrefClient = new CrossrefClient($this->mockGuzzleClient); + $this->crossrefClient = new OpenAlexClient($this->mockGuzzleClient); } private function createMockGuzzleClient() From 9bb99363465cf2c4fc30fa79e80b50b6840b1811 Mon Sep 17 00:00:00 2001 From: Jhon Date: Wed, 6 Nov 2024 17:36:27 -0400 Subject: [PATCH 3/6] Adds OpenAlex citations count to report row Issue: documentacao-e-tarefas/scielo#715 Signed-off-by: Jhon --- classes/SubmissionRowBuilder.php | 3 ++- classes/SubmissionWithCitations.php | 10 ++++++++++ classes/SubmissionsCitationsReport.php | 3 ++- locale/en/locale.po | 3 +++ locale/es/locale.po | 5 ++++- locale/pt_BR/locale.po | 3 +++ tests/SubmissionRowBuilderTest.php | 7 +++++-- tests/SubmissionWithCitationsTest.php | 4 +++- tests/SubmissionsCitationsReportTest.php | 7 +++++-- 9 files changed, 37 insertions(+), 8 deletions(-) diff --git a/classes/SubmissionRowBuilder.php b/classes/SubmissionRowBuilder.php index 415ab67..b5e2734 100644 --- a/classes/SubmissionRowBuilder.php +++ b/classes/SubmissionRowBuilder.php @@ -28,7 +28,8 @@ public function buildRow($context, $submissionWithCitations): array $doi, $isScieloJournal, $submissionWithCitations->getCrossrefCitationsCount(), - $submissionWithCitations->getEuropePmcCitationsCount() + $submissionWithCitations->getEuropePmcCitationsCount(), + $submissionWithCitations->getOpenAlexCitationsCount() ]; } diff --git a/classes/SubmissionWithCitations.php b/classes/SubmissionWithCitations.php index 4d62b3b..a466441 100644 --- a/classes/SubmissionWithCitations.php +++ b/classes/SubmissionWithCitations.php @@ -47,6 +47,16 @@ public function getEuropePmcCitationsCount(): int return $this->getData('europePmcCitationsCount'); } + public function setOpenAlexCitationsCount(int $openAlexCitationsCount) + { + $this->setData('openAlexCitationsCount', $openAlexCitationsCount); + } + + public function getOpenAlexCitationsCount(): int + { + return $this->getData('openAlexCitationsCount'); + } + public static function __set_state($dump) { $obj = new SubmissionWithCitations(); diff --git a/classes/SubmissionsCitationsReport.php b/classes/SubmissionsCitationsReport.php index 7cb1585..7b4053e 100644 --- a/classes/SubmissionsCitationsReport.php +++ b/classes/SubmissionsCitationsReport.php @@ -33,7 +33,8 @@ private function getHeaders(): array __('metadata.property.displayName.doi'), __('plugins.reports.submissionsCitationsReport.scieloJournal'), __('plugins.reports.submissionsCitationsReport.crossrefCitationsCount'), - __('plugins.reports.submissionsCitationsReport.europePmcCitationsCount') + __('plugins.reports.submissionsCitationsReport.europePmcCitationsCount'), + __('plugins.reports.submissionsCitationsReport.openAlexCitationsCount') ]; } diff --git a/locale/en/locale.po b/locale/en/locale.po index f3632e9..7dab0eb 100644 --- a/locale/en/locale.po +++ b/locale/en/locale.po @@ -12,3 +12,6 @@ msgstr "CrossRef citations count" msgid "plugins.reports.submissionsCitationsReport.europePmcCitationsCount" msgstr "Europe PMC citations count" + +msgid "plugins.reports.submissionsCitationsReport.openAlexCitationsCount" +msgstr "OpenAlex citations count" diff --git a/locale/es/locale.po b/locale/es/locale.po index d647d4a..e2122d6 100644 --- a/locale/es/locale.po +++ b/locale/es/locale.po @@ -11,4 +11,7 @@ msgid "plugins.reports.submissionsCitationsReport.crossrefCitationsCount" msgstr "Número de citas en CrossRef" msgid "plugins.reports.submissionsCitationsReport.europePmcCitationsCount" -msgstr "Número de citas en Europe PMC" \ No newline at end of file +msgstr "Número de citas en Europe PMC" + +msgid "plugins.reports.submissionsCitationsReport.openAlexCitationsCount" +msgstr "Número de citas en OpenAlex" \ No newline at end of file diff --git a/locale/pt_BR/locale.po b/locale/pt_BR/locale.po index 79e960a..c0613b4 100644 --- a/locale/pt_BR/locale.po +++ b/locale/pt_BR/locale.po @@ -12,3 +12,6 @@ msgstr "Número de citações em CrossRef" msgid "plugins.reports.submissionsCitationsReport.europePmcCitationsCount" msgstr "Número de citações em Europe PMC" + +msgid "plugins.reports.submissionsCitationsReport.openAlexCitationsCount" +msgstr "Número de citações em OpenAlex" diff --git a/tests/SubmissionRowBuilderTest.php b/tests/SubmissionRowBuilderTest.php index 10f982a..63e716c 100644 --- a/tests/SubmissionRowBuilderTest.php +++ b/tests/SubmissionRowBuilderTest.php @@ -76,6 +76,7 @@ private function createSubmissionWithCitations(): SubmissionWithCitations $submissionWithCitations->setSubmission($this->submission); $submissionWithCitations->setCrossrefCitationsCount(51); $submissionWithCitations->setEuropePmcCitationsCount(16); + $submissionWithCitations->setOpenAlexCitationsCount(23); return $submissionWithCitations; } @@ -167,7 +168,8 @@ public function testBuildSubmissionRow(): void '10.666/949494', __('common.no'), 51, - 16 + 16, + 23 ]; $this->assertEquals($expectedRow, $rowBuilder->buildRow($context, $this->submissionWithCitations)); @@ -194,7 +196,8 @@ public function testBuildSubmissionRowWithScieloJournal(): void '10.666/949494', __('common.yes'), 51, - 16 + 16, + 23 ]; $this->assertEquals($expectedRow, $rowBuilder->buildRow($context, $this->submissionWithCitations)); diff --git a/tests/SubmissionWithCitationsTest.php b/tests/SubmissionWithCitationsTest.php index 897ada0..c57eeb7 100644 --- a/tests/SubmissionWithCitationsTest.php +++ b/tests/SubmissionWithCitationsTest.php @@ -21,6 +21,7 @@ private function createSubmissionWithCitations() $submissionWithCitations->setSubmissionId(7890); $submissionWithCitations->setCrossrefCitationsCount(49); $submissionWithCitations->setEuropePmcCitationsCount(14); + $submissionWithCitations->setOpenAlexCitationsCount(21); return $submissionWithCitations; } @@ -30,7 +31,8 @@ public function testGetObjectData(): void $expectedData = [ 'submissionId' => 7890, 'crossrefCitationsCount' => 49, - 'europePmcCitationsCount' => 14 + 'europePmcCitationsCount' => 14, + 'openAlexCitationsCount' => 21 ]; $this->assertEquals($expectedData, $this->submissionWithCitations->_data); } diff --git a/tests/SubmissionsCitationsReportTest.php b/tests/SubmissionsCitationsReportTest.php index 587c9ff..eac18a8 100644 --- a/tests/SubmissionsCitationsReportTest.php +++ b/tests/SubmissionsCitationsReportTest.php @@ -89,6 +89,7 @@ private function createSubmissionWithCitations(): SubmissionWithCitations $submissionWithCitations->setSubmission($this->submission); $submissionWithCitations->setCrossrefCitationsCount(52); $submissionWithCitations->setEuropePmcCitationsCount(17); + $submissionWithCitations->setOpenAlexCitationsCount(24); return $submissionWithCitations; } @@ -128,7 +129,8 @@ public function testGeneratedCsvHasHeaders(): void __('metadata.property.displayName.doi'), __('plugins.reports.submissionsCitationsReport.scieloJournal'), __('plugins.reports.submissionsCitationsReport.crossrefCitationsCount'), - __('plugins.reports.submissionsCitationsReport.europePmcCitationsCount') + __('plugins.reports.submissionsCitationsReport.europePmcCitationsCount'), + __('plugins.reports.submissionsCitationsReport.openAlexCitationsCount') ]; $this->assertEquals($expectedRow, $firstRow); @@ -156,7 +158,8 @@ public function testGeneratedCsvHasSubmissionRow(): void '10.666/949494', __('common.no'), 52, - 17 + 17, + 24 ]; $this->assertEquals($expectedRow, $secondRow); From 44b2601c29f6f3f1e3a0927b0aead1a840c296c0 Mon Sep 17 00:00:00 2001 From: Jhon Date: Thu, 7 Nov 2024 14:26:59 -0400 Subject: [PATCH 4/6] Builds report with number of citations in OpenAlex service Issue: documentacao-e-tarefas/scielo#715 Signed-off-by: Jhon --- classes/SubmissionsCitationsReportBuilder.php | 12 +++++++++++- classes/clients/OpenAlexClient.php | 7 ++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/classes/SubmissionsCitationsReportBuilder.php b/classes/SubmissionsCitationsReportBuilder.php index 60bbfdd..339c9d6 100644 --- a/classes/SubmissionsCitationsReportBuilder.php +++ b/classes/SubmissionsCitationsReportBuilder.php @@ -7,6 +7,7 @@ use APP\submission\Submission; use APP\plugins\reports\submissionsCitationsReport\classes\clients\CrossrefClient; use APP\plugins\reports\submissionsCitationsReport\classes\clients\EuropePmcClient; +use APP\plugins\reports\submissionsCitationsReport\classes\clients\OpenAlexClient; use APP\plugins\reports\submissionsCitationsReport\classes\SubmissionsCitationsReport; use APP\plugins\reports\submissionsCitationsReport\classes\SubmissionWithCitations; @@ -63,16 +64,25 @@ public function retrieveSubmissionsWithCitations(int $contextId): array $europePmcClient = new EuropePmcClient(); $submissionsEuropePmcCitationsCount = $europePmcClient->getSubmissionsCitationsCount($submissions); + $openAlexClient = new OpenAlexClient(); + $submissionsOpenAlexCitationsCount = $openAlexClient->getSubmissionsCitationsCount($submissions); + $submissionsWithCitations = []; foreach ($submissions as $submission) { $crossrefCitationsCount = $submissionsCrossrefCitationsCount[$submission->getId()]; $europePmcCitationsCount = $submissionsEuropePmcCitationsCount[$submission->getId()]; + $openAlexCitationsCount = $submissionsOpenAlexCitationsCount[$submission->getId()]; - if ($crossrefCitationsCount > 0 || $europePmcCitationsCount > 0) { + if ( + $crossrefCitationsCount > 0 + || $europePmcCitationsCount > 0 + || $openAlexCitationsCount > 0 + ) { $submissionWithCitations = new SubmissionWithCitations(); $submissionWithCitations->setSubmissionId($submission->getId()); $submissionWithCitations->setCrossrefCitationsCount($crossrefCitationsCount); $submissionWithCitations->setEuropePmcCitationsCount($europePmcCitationsCount); + $submissionWithCitations->setOpenAlexCitationsCount($openAlexCitationsCount); $submissionsWithCitations[$submission->getId()] = $submissionWithCitations; } diff --git a/classes/clients/OpenAlexClient.php b/classes/clients/OpenAlexClient.php index 0b0df5a..7884d60 100644 --- a/classes/clients/OpenAlexClient.php +++ b/classes/clients/OpenAlexClient.php @@ -29,14 +29,15 @@ public function getSubmissionsCitationsCount(array $submissions): array foreach ($submissions as $submission) { $publication = $submission->getCurrentPublication(); - $doi = $publication->getDoi(); + $doiObject = $publication->getData('doiObject'); - if (empty($doi)) { + if (empty($doiObject)) { $citationsCount[$submission->getId()] = 0; continue; } - $requestUrl = htmlspecialchars(self::OPEN_ALEX_API_URL . "?filter=doi:$doi"); + $doiResolvingUrl = $doiObject->getResolvingUrl(); + $requestUrl = htmlspecialchars(self::OPEN_ALEX_API_URL . "/$doiResolvingUrl?select=doi,cited_by_count"); $requests[$submission->getId()] = new Request( 'GET', $requestUrl, From ba32fa728296c717955d395c33eb22bf8dfee76b Mon Sep 17 00:00:00 2001 From: Jhon Date: Thu, 7 Nov 2024 14:30:44 -0400 Subject: [PATCH 5/6] Updates version.xml Issue: documentacao-e-tarefas/scielo#715 Signed-off-by: Jhon --- version.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/version.xml b/version.xml index bfc3882..a426529 100644 --- a/version.xml +++ b/version.xml @@ -13,6 +13,6 @@ submissionsCitationsReport plugins.reports - 1.1.0.0 - 2024-10-23 + 1.2.0.0 + 2024-11-07 From d367c09af91f89b7bb03502491a3efd5d5090539 Mon Sep 17 00:00:00 2001 From: Jhon Date: Thu, 7 Nov 2024 14:37:19 -0400 Subject: [PATCH 6/6] Fixes error in OpenAlex client Issue: documentacao-e-tarefas/scielo#715 Signed-off-by: Jhon --- classes/clients/OpenAlexClient.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/clients/OpenAlexClient.php b/classes/clients/OpenAlexClient.php index 7884d60..3bb83f8 100644 --- a/classes/clients/OpenAlexClient.php +++ b/classes/clients/OpenAlexClient.php @@ -31,7 +31,7 @@ public function getSubmissionsCitationsCount(array $submissions): array $publication = $submission->getCurrentPublication(); $doiObject = $publication->getData('doiObject'); - if (empty($doiObject)) { + if (empty($doiObject->getDoi())) { $citationsCount[$submission->getId()] = 0; continue; }