diff --git a/classes/services/ThothWorkService.inc.php b/classes/services/ThothWorkService.inc.php index d51cc42..c4dd901 100644 --- a/classes/services/ThothWorkService.inc.php +++ b/classes/services/ThothWorkService.inc.php @@ -25,6 +25,19 @@ public function getQueryBuilder($thothClient) return new ThothWorkQueryBuilder($thothClient); } + private function getDoiResolvingUrl($doi) + { + if (empty($doi)) { + return $doi; + } + + $search = ['%', '"', '#', ' ', '<', '>', '{']; + $replace = ['%25', '%22', '%23', '%20', '%3c', '%3e', '%7b']; + $encodedDoi = str_replace($search, $replace, $doi); + + return "https://doi.org/$encodedDoi"; + } + public function getDataBySubmission($submission, $publication = null) { $request = Application::get()->getRequest(); @@ -40,7 +53,7 @@ public function getDataBySubmission($submission, $publication = null) $data['subtitle'] = $publication->getLocalizedData('subtitle'); $data['longAbstract'] = $publication->getLocalizedData('abstract'); $data['edition'] = $publication->getData('version'); - $data['doi'] = $publication->getStoredPubId('doi'); + $data['doi'] = $this->getDoiResolvingUrl($publication->getStoredPubId('doi')); $data['publicationDate'] = $publication->getData('datePublished'); $data['license'] = $publication->getData('licenseUrl'); $data['copyrightHolder'] = $publication->getLocalizedData('copyrightHolder'); @@ -74,7 +87,7 @@ public function newByChapter($chapter) $params['pageCount'] = $chapter->getPages(); $params['publicationDate'] = $chapter->getDatePublished() ?? Services::get('publication')->get($chapter->getData('publicationId'))->getData('datePublished'); - $params['doi'] = $chapter->getStoredPubId('doi'); + $params['doi'] = $this->getDoiResolvingUrl($chapter->getStoredPubId('doi')); return $this->new($params); } diff --git a/tests/classes/services/ThothWorkServiceTest.php b/tests/classes/services/ThothWorkServiceTest.php index deb430e..3387775 100644 --- a/tests/classes/services/ThothWorkServiceTest.php +++ b/tests/classes/services/ThothWorkServiceTest.php @@ -185,7 +185,7 @@ public function testCreateNewWorkBySubmission() ); $publication->setData( 'pub-id::doi', - 'https://doi.org/10.1234/0000af0000' + '10.1234/0000af0000' ); $publication->setData( 'datePublished', @@ -236,7 +236,7 @@ public function testCreateNewWorkByChapter() $chapter->setTitle('Chapter 1: Interactions Affording Distance Science Education', 'en_US'); $chapter->setDatePublished('2024-03-21'); $chapter->setPages(27); - $chapter->setStoredPubId('doi', 'https://doi.org/10.1234/jpk.14.c54'); + $chapter->setStoredPubId('doi', '10.1234/jpk.14.c54'); $thothWork = $this->workService->newByChapter($chapter); $this->assertEquals($expectedThothWork, $thothWork); diff --git a/version.xml b/version.xml index 4f8bd0c..5877024 100644 --- a/version.xml +++ b/version.xml @@ -3,8 +3,8 @@ thoth plugins.generic - 0.1.3.1 - 2024-10-22 + 0.1.3.2 + 2024-10-25 1 ThothPlugin