From a3033ee33482fde60ac00a72e509daeb551ce68e Mon Sep 17 00:00:00 2001 From: Thiago Brasil Date: Thu, 23 Jan 2025 15:36:06 -0400 Subject: [PATCH 01/10] Added thoth-client-php dependency Issue: documentacao-e-tarefas/desenvolvimento_e_infra#929 Signed-off-by: Thiago Brasil --- composer.json | 3 +- composer.lock | 647 +++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 643 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index 84515fe..6b34f23 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,6 @@ { "require": { - "biblys/isbn": "~3.0" + "biblys/isbn": "~3.0", + "thoth-pub/thoth-client-php": "^1.3" } } diff --git a/composer.lock b/composer.lock index 2ac77c3..b5752fc 100644 --- a/composer.lock +++ b/composer.lock @@ -4,20 +4,20 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "30bd5da4e33de53f4f7c5b93d76d158f", + "content-hash": "09deefcd27232a76bd10f46805907590", "packages": [ { "name": "biblys/isbn", - "version": "3.2.9", + "version": "3.2.10", "source": { "type": "git", "url": "https://github.com/biblys/isbn.git", - "reference": "88decabdccce7eed3f298f826e3365a00f895a05" + "reference": "a580e0068b380b86f622b9136698a1155f8072a7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/biblys/isbn/zipball/88decabdccce7eed3f298f826e3365a00f895a05", - "reference": "88decabdccce7eed3f298f826e3365a00f895a05", + "url": "https://api.github.com/repos/biblys/isbn/zipball/a580e0068b380b86f622b9136698a1155f8072a7", + "reference": "a580e0068b380b86f622b9136698a1155f8072a7", "shasum": "" }, "require": { @@ -55,7 +55,7 @@ ], "support": { "issues": "https://github.com/biblys/isbn/issues", - "source": "https://github.com/biblys/isbn/tree/3.2.9" + "source": "https://github.com/biblys/isbn/tree/3.2.10" }, "funding": [ { @@ -64,6 +64,641 @@ } ], "time": "2022-11-26T00:00:00+00:00" + }, + { + "name": "guzzlehttp/guzzle", + "version": "7.9.2", + "source": { + "type": "git", + "url": "https://github.com/guzzle/guzzle.git", + "reference": "d281ed313b989f213357e3be1a179f02196ac99b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/d281ed313b989f213357e3be1a179f02196ac99b", + "reference": "d281ed313b989f213357e3be1a179f02196ac99b", + "shasum": "" + }, + "require": { + "ext-json": "*", + "guzzlehttp/promises": "^1.5.3 || ^2.0.3", + "guzzlehttp/psr7": "^2.7.0", + "php": "^7.2.5 || ^8.0", + "psr/http-client": "^1.0", + "symfony/deprecation-contracts": "^2.2 || ^3.0" + }, + "provide": { + "psr/http-client-implementation": "1.0" + }, + "require-dev": { + "bamarni/composer-bin-plugin": "^1.8.2", + "ext-curl": "*", + "guzzle/client-integration-tests": "3.0.2", + "php-http/message-factory": "^1.1", + "phpunit/phpunit": "^8.5.39 || ^9.6.20", + "psr/log": "^1.1 || ^2.0 || ^3.0" + }, + "suggest": { + "ext-curl": "Required for CURL handler support", + "ext-intl": "Required for Internationalized Domain Name (IDN) support", + "psr/log": "Required for using the Log middleware" + }, + "type": "library", + "extra": { + "bamarni-bin": { + "bin-links": true, + "forward-command": false + } + }, + "autoload": { + "files": [ + "src/functions_include.php" + ], + "psr-4": { + "GuzzleHttp\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + }, + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "Jeremy Lindblom", + "email": "jeremeamia@gmail.com", + "homepage": "https://github.com/jeremeamia" + }, + { + "name": "George Mponos", + "email": "gmponos@gmail.com", + "homepage": "https://github.com/gmponos" + }, + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com", + "homepage": "https://github.com/Nyholm" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com", + "homepage": "https://github.com/sagikazarmark" + }, + { + "name": "Tobias Schultze", + "email": "webmaster@tubo-world.de", + "homepage": "https://github.com/Tobion" + } + ], + "description": "Guzzle is a PHP HTTP client library", + "keywords": [ + "client", + "curl", + "framework", + "http", + "http client", + "psr-18", + "psr-7", + "rest", + "web service" + ], + "support": { + "issues": "https://github.com/guzzle/guzzle/issues", + "source": "https://github.com/guzzle/guzzle/tree/7.9.2" + }, + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://github.com/Nyholm", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/guzzle", + "type": "tidelift" + } + ], + "time": "2024-07-24T11:22:20+00:00" + }, + { + "name": "guzzlehttp/promises", + "version": "2.0.4", + "source": { + "type": "git", + "url": "https://github.com/guzzle/promises.git", + "reference": "f9c436286ab2892c7db7be8c8da4ef61ccf7b455" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/promises/zipball/f9c436286ab2892c7db7be8c8da4ef61ccf7b455", + "reference": "f9c436286ab2892c7db7be8c8da4ef61ccf7b455", + "shasum": "" + }, + "require": { + "php": "^7.2.5 || ^8.0" + }, + "require-dev": { + "bamarni/composer-bin-plugin": "^1.8.2", + "phpunit/phpunit": "^8.5.39 || ^9.6.20" + }, + "type": "library", + "extra": { + "bamarni-bin": { + "bin-links": true, + "forward-command": false + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Promise\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + }, + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com", + "homepage": "https://github.com/Nyholm" + }, + { + "name": "Tobias Schultze", + "email": "webmaster@tubo-world.de", + "homepage": "https://github.com/Tobion" + } + ], + "description": "Guzzle promises library", + "keywords": [ + "promise" + ], + "support": { + "issues": "https://github.com/guzzle/promises/issues", + "source": "https://github.com/guzzle/promises/tree/2.0.4" + }, + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://github.com/Nyholm", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/promises", + "type": "tidelift" + } + ], + "time": "2024-10-17T10:06:22+00:00" + }, + { + "name": "guzzlehttp/psr7", + "version": "2.7.0", + "source": { + "type": "git", + "url": "https://github.com/guzzle/psr7.git", + "reference": "a70f5c95fb43bc83f07c9c948baa0dc1829bf201" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/a70f5c95fb43bc83f07c9c948baa0dc1829bf201", + "reference": "a70f5c95fb43bc83f07c9c948baa0dc1829bf201", + "shasum": "" + }, + "require": { + "php": "^7.2.5 || ^8.0", + "psr/http-factory": "^1.0", + "psr/http-message": "^1.1 || ^2.0", + "ralouphie/getallheaders": "^3.0" + }, + "provide": { + "psr/http-factory-implementation": "1.0", + "psr/http-message-implementation": "1.0" + }, + "require-dev": { + "bamarni/composer-bin-plugin": "^1.8.2", + "http-interop/http-factory-tests": "0.9.0", + "phpunit/phpunit": "^8.5.39 || ^9.6.20" + }, + "suggest": { + "laminas/laminas-httphandlerrunner": "Emit PSR-7 responses" + }, + "type": "library", + "extra": { + "bamarni-bin": { + "bin-links": true, + "forward-command": false + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Psr7\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + }, + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "George Mponos", + "email": "gmponos@gmail.com", + "homepage": "https://github.com/gmponos" + }, + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com", + "homepage": "https://github.com/Nyholm" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com", + "homepage": "https://github.com/sagikazarmark" + }, + { + "name": "Tobias Schultze", + "email": "webmaster@tubo-world.de", + "homepage": "https://github.com/Tobion" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com", + "homepage": "https://sagikazarmark.hu" + } + ], + "description": "PSR-7 message implementation that also provides common utility methods", + "keywords": [ + "http", + "message", + "psr-7", + "request", + "response", + "stream", + "uri", + "url" + ], + "support": { + "issues": "https://github.com/guzzle/psr7/issues", + "source": "https://github.com/guzzle/psr7/tree/2.7.0" + }, + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://github.com/Nyholm", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/psr7", + "type": "tidelift" + } + ], + "time": "2024-07-18T11:15:46+00:00" + }, + { + "name": "psr/http-client", + "version": "1.0.3", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-client.git", + "reference": "bb5906edc1c324c9a05aa0873d40117941e5fa90" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-client/zipball/bb5906edc1c324c9a05aa0873d40117941e5fa90", + "reference": "bb5906edc1c324c9a05aa0873d40117941e5fa90", + "shasum": "" + }, + "require": { + "php": "^7.0 || ^8.0", + "psr/http-message": "^1.0 || ^2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Client\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP clients", + "homepage": "https://github.com/php-fig/http-client", + "keywords": [ + "http", + "http-client", + "psr", + "psr-18" + ], + "support": { + "source": "https://github.com/php-fig/http-client" + }, + "time": "2023-09-23T14:17:50+00:00" + }, + { + "name": "psr/http-factory", + "version": "1.1.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-factory.git", + "reference": "2b4765fddfe3b508ac62f829e852b1501d3f6e8a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-factory/zipball/2b4765fddfe3b508ac62f829e852b1501d3f6e8a", + "reference": "2b4765fddfe3b508ac62f829e852b1501d3f6e8a", + "shasum": "" + }, + "require": { + "php": ">=7.1", + "psr/http-message": "^1.0 || ^2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "PSR-17: Common interfaces for PSR-7 HTTP message factories", + "keywords": [ + "factory", + "http", + "message", + "psr", + "psr-17", + "psr-7", + "request", + "response" + ], + "support": { + "source": "https://github.com/php-fig/http-factory" + }, + "time": "2024-04-15T12:06:14+00:00" + }, + { + "name": "psr/http-message", + "version": "2.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-message.git", + "reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-message/zipball/402d35bcb92c70c026d1a6a9883f06b2ead23d71", + "reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP messages", + "homepage": "https://github.com/php-fig/http-message", + "keywords": [ + "http", + "http-message", + "psr", + "psr-7", + "request", + "response" + ], + "support": { + "source": "https://github.com/php-fig/http-message/tree/2.0" + }, + "time": "2023-04-04T09:54:51+00:00" + }, + { + "name": "ralouphie/getallheaders", + "version": "3.0.3", + "source": { + "type": "git", + "url": "https://github.com/ralouphie/getallheaders.git", + "reference": "120b605dfeb996808c31b6477290a714d356e822" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822", + "reference": "120b605dfeb996808c31b6477290a714d356e822", + "shasum": "" + }, + "require": { + "php": ">=5.6" + }, + "require-dev": { + "php-coveralls/php-coveralls": "^2.1", + "phpunit/phpunit": "^5 || ^6.5" + }, + "type": "library", + "autoload": { + "files": [ + "src/getallheaders.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ralph Khattar", + "email": "ralph.khattar@gmail.com" + } + ], + "description": "A polyfill for getallheaders.", + "support": { + "issues": "https://github.com/ralouphie/getallheaders/issues", + "source": "https://github.com/ralouphie/getallheaders/tree/develop" + }, + "time": "2019-03-08T08:55:37+00:00" + }, + { + "name": "symfony/deprecation-contracts", + "version": "v3.0.2", + "source": { + "type": "git", + "url": "https://github.com/symfony/deprecation-contracts.git", + "reference": "26954b3d62a6c5fd0ea8a2a00c0353a14978d05c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/26954b3d62a6c5fd0ea8a2a00c0353a14978d05c", + "reference": "26954b3d62a6c5fd0ea8a2a00c0353a14978d05c", + "shasum": "" + }, + "require": { + "php": ">=8.0.2" + }, + "type": "library", + "extra": { + "thanks": { + "url": "https://github.com/symfony/contracts", + "name": "symfony/contracts" + }, + "branch-alias": { + "dev-main": "3.0-dev" + } + }, + "autoload": { + "files": [ + "function.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "A generic function and convention to trigger deprecation notices", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/deprecation-contracts/tree/v3.0.2" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2022-01-02T09:55:41+00:00" + }, + { + "name": "thoth-pub/thoth-client-php", + "version": "1.3.1", + "source": { + "type": "git", + "url": "https://github.com/thoth-pub/thoth-client-php.git", + "reference": "14887cfb4fbd0f8ed0955a1d586afc51639824df" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thoth-pub/thoth-client-php/zipball/14887cfb4fbd0f8ed0955a1d586afc51639824df", + "reference": "14887cfb4fbd0f8ed0955a1d586afc51639824df", + "shasum": "" + }, + "require": { + "guzzlehttp/guzzle": "^7.0", + "php": ">=7.4" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^3.64", + "phpunit/phpunit": "^9.6" + }, + "type": "library", + "autoload": { + "psr-4": { + "ThothApi\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "description": "PHP client for Thoth's GraphQL and REST APIs.", + "support": { + "issues": "https://github.com/thoth-pub/thoth-client-php/issues", + "source": "https://github.com/thoth-pub/thoth-client-php/tree/1.3.1" + }, + "time": "2025-01-23T19:23:45+00:00" } ], "packages-dev": [], From c4bf7538bb08bfda99e2001cc7136f74698064a9 Mon Sep 17 00:00:00 2001 From: Thiago Brasil Date: Thu, 23 Jan 2025 16:42:55 -0400 Subject: [PATCH 02/10] Fixed code check in Gitlab CI Issue: documentacao-e-tarefas/desenvolvimento_e_infra#929 Signed-off-by: Thiago Brasil --- .gitlab-ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3807210..e144cd3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -11,3 +11,6 @@ include: .unit_test_template: before_script: - composer install + +code_formatting_check: + image: ubuntu:22.04 From 96838842c9502b0208719fe957e6bc62e474e16e Mon Sep 17 00:00:00 2001 From: Thiago Brasil Date: Thu, 23 Jan 2025 16:51:13 -0400 Subject: [PATCH 03/10] Implements a simple dependency injection container Issue: documentacao-e-tarefas/desenvolvimento_e_infra#929 Signed-off-by: Thiago Brasil --- classes/container/Container.inc.php | 45 ++++++++ classes/container/ContainerProvider.inc.php | 19 ++++ classes/container/ThothContainer.inc.php | 35 ++++++ .../container/ThothContainerProvider.inc.php | 103 ++++++++++++++++++ tests/classes/container/ContainerTest.php | 87 +++++++++++++++ .../classes/container/ThothContainerTest.php | 48 ++++++++ 6 files changed, 337 insertions(+) create mode 100644 classes/container/Container.inc.php create mode 100644 classes/container/ContainerProvider.inc.php create mode 100644 classes/container/ThothContainer.inc.php create mode 100644 classes/container/ThothContainerProvider.inc.php create mode 100644 tests/classes/container/ContainerTest.php create mode 100644 tests/classes/container/ThothContainerTest.php diff --git a/classes/container/Container.inc.php b/classes/container/Container.inc.php new file mode 100644 index 0000000..b44773a --- /dev/null +++ b/classes/container/Container.inc.php @@ -0,0 +1,45 @@ +bindings[$id] = $factory; + } + + public function get($id) + { + if (!isset($this->bindings[$id])) { + throw new Exception("Target binding \"$id\" does not exist."); + } + + $factory = $this->bindings[$id]; + + return $factory($this); + } + + public function backup($id) + { + return $this->bindings[$id]; + } + + public function register($containerProvider) + { + $containerProvider->register($this); + } +} diff --git a/classes/container/ContainerProvider.inc.php b/classes/container/ContainerProvider.inc.php new file mode 100644 index 0000000..ef959a6 --- /dev/null +++ b/classes/container/ContainerProvider.inc.php @@ -0,0 +1,19 @@ +register(new ThothContainerProvider()); + } + + public static function getInstance() + { + if (self::$instance === null) { + self::$instance = new self(); + } + return self::$instance; + } +} diff --git a/classes/container/ThothContainerProvider.inc.php b/classes/container/ThothContainerProvider.inc.php new file mode 100644 index 0000000..24ce726 --- /dev/null +++ b/classes/container/ThothContainerProvider.inc.php @@ -0,0 +1,103 @@ +set('config', function ($container) { + $pluginSettingsDao = & DAORegistry::getDAO('PluginSettingsDAO'); + $contextId = Application::get()->getRequest()->getContext()->getId(); + + $testEnvironment = $pluginSettingsDao->getSetting($contextId, 'ThothPlugin', 'testEnvironment'); + $email = $pluginSettingsDao->getSetting($contextId, 'ThothPlugin', 'email'); + $password = $pluginSettingsDao->getSetting($contextId, 'ThothPlugin', 'password'); + + return [ + 'testEnvironment' => $testEnvironment, + 'email' => $email, + 'password' => APIKeyEncryption::decryptString($password) + ]; + }); + + $container->set('client', function ($container) { + $config = $container->get('config'); + + $httpConfig = []; + if ($config['testEnvironment']) { + $httpConfig['base_uri'] = 'http://localhost:8000/'; + } + + $client = new Client($httpConfig); + return $client->login($config['email'], $config['password']); + }); + + $container->set('affiliationService', function ($container) { + return new ThothAffiliationService(); + }); + + $container->set('contributionService', function ($container) { + return new ThothContributionService(); + }); + + $container->set('contributorService', function ($container) { + return new ThothContributorService(); + }); + + $container->set('institutionService', function ($container) { + return new ThothInstitutionService(); + }); + + $container->set('languageService', function ($container) { + return new ThothLanguageService(); + }); + + $container->set('locationService', function ($container) { + return new ThothLocationService(); + }); + + $container->set('publicationService', function ($container) { + return new ThothPublicationService(); + }); + + $container->set('referenceService', function ($container) { + return new ThothReferenceService(); + }); + + $container->set('subjectService', function ($container) { + return new ThothSubjectService(); + }); + + $container->set('workService', function ($container) { + return new ThothWorkService(); + }); + } +} diff --git a/tests/classes/container/ContainerTest.php b/tests/classes/container/ContainerTest.php new file mode 100644 index 0000000..b54877f --- /dev/null +++ b/tests/classes/container/ContainerTest.php @@ -0,0 +1,87 @@ +set('class', function ($container) { + return new class () { + public function foo() + { + return 'foo'; + } + }; + }); + + $class = $container->get('class'); + + $this->assertEquals('foo', $class->foo()); + } + + public function testBackupContainerBinding() + { + $callable = function () { + return 'foo'; + }; + + $container = new Container(); + $container->set('foo', $callable); + + $fooBackup = $container->backup('foo'); + + $this->assertSame($callable, $fooBackup); + } + + public function testInvalidBindingThrownException() + { + $this->expectException(Exception::class); + $this->expectExceptionMessage('Target binding "class" does not exist.'); + + $container = new Container(); + $container->get('class'); + } + + public function testRegisterInstancesFromProvider() + { + $provider = new class () implements ContainerProvider { + public function register($container) + { + $container->set('class', function ($container) { + return new class () { + public function foo() + { + return 'foo'; + } + }; + }); + } + }; + + $container = new Container(); + $container->register($provider); + + $class = $container->get('class'); + + $this->assertEquals('foo', $class->foo()); + } +} diff --git a/tests/classes/container/ThothContainerTest.php b/tests/classes/container/ThothContainerTest.php new file mode 100644 index 0000000..67266d8 --- /dev/null +++ b/tests/classes/container/ThothContainerTest.php @@ -0,0 +1,48 @@ +assertInstanceOf(ThothContainer::class, $firstContainer); + $this->assertSame($firstContainer, $secondContainer); + } + + public function testReplaceContainerBinding() + { + ThothContainer::getInstance()->set('foo', function () { + return 'foo'; + }); + + $fooFoo = ThothContainer::getInstance()->get('foo'); + + ThothContainer::getInstance()->set('foo', function () { + return 'bar'; + }); + + $fooBar = ThothContainer::getInstance()->get('foo'); + + $this->assertEquals('foo', $fooFoo); + $this->assertEquals('bar', $fooBar); + } +} From d36f57198bfe3a5201b61ae49001854a84033eb7 Mon Sep 17 00:00:00 2001 From: Thiago Brasil Date: Thu, 23 Jan 2025 17:59:43 -0400 Subject: [PATCH 04/10] Updated composer dependencies Issue: documentacao-e-tarefas/desenvolvimento_e_infra#929 Signed-off-by: Thiago Brasil --- composer.lock | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/composer.lock b/composer.lock index b5752fc..3adeab3 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "09deefcd27232a76bd10f46805907590", + "content-hash": "4baef975536654fc9fc4eccb7e548ad9", "packages": [ { "name": "biblys/isbn", @@ -67,7 +67,7 @@ }, { "name": "guzzlehttp/guzzle", - "version": "7.9.2", + "version": "7.8.2", "source": { "type": "git", "url": "https://github.com/guzzle/guzzle.git", @@ -499,16 +499,16 @@ }, { "name": "psr/http-message", - "version": "2.0", + "version": "1.1", "source": { "type": "git", "url": "https://github.com/php-fig/http-message.git", - "reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71" + "reference": "cb6ce4845ce34a8ad9e68117c10ee90a29919eba" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/http-message/zipball/402d35bcb92c70c026d1a6a9883f06b2ead23d71", - "reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71", + "url": "https://api.github.com/repos/php-fig/http-message/zipball/cb6ce4845ce34a8ad9e68117c10ee90a29919eba", + "reference": "cb6ce4845ce34a8ad9e68117c10ee90a29919eba", "shasum": "" }, "require": { @@ -517,7 +517,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0.x-dev" + "dev-master": "1.1.x-dev" } }, "autoload": { @@ -532,7 +532,7 @@ "authors": [ { "name": "PHP-FIG", - "homepage": "https://www.php-fig.org/" + "homepage": "http://www.php-fig.org/" } ], "description": "Common interface for HTTP messages", @@ -546,9 +546,9 @@ "response" ], "support": { - "source": "https://github.com/php-fig/http-message/tree/2.0" + "source": "https://github.com/php-fig/http-message/tree/1.1" }, - "time": "2023-04-04T09:54:51+00:00" + "time": "2023-04-04T09:50:52+00:00" }, { "name": "ralouphie/getallheaders", From b23d70e6dfc1c1ba251630a347bf7f52742077be Mon Sep 17 00:00:00 2001 From: Thiago Brasil Date: Thu, 23 Jan 2025 18:05:23 -0400 Subject: [PATCH 05/10] Removed plugin implementation of Thoth client Issue: documentacao-e-tarefas/desenvolvimento_e_infra#929 Signed-off-by: Thiago Brasil --- lib/thothAPI/ThothAccount.inc.php | 73 ---- lib/thothAPI/ThothClient.inc.php | 361 ------------------ lib/thothAPI/ThothGraphQL.inc.php | 89 ----- lib/thothAPI/ThothMutation.inc.php | 63 --- lib/thothAPI/ThothQuery.inc.php | 55 --- lib/thothAPI/ThothQueryFields.inc.php | 106 ----- .../exceptions/ThothException.inc.php | 27 -- lib/thothAPI/models/ThothAffiliation.inc.php | 72 ---- lib/thothAPI/models/ThothContribution.inc.php | 157 -------- lib/thothAPI/models/ThothContributor.inc.php | 96 ----- lib/thothAPI/models/ThothImprint.inc.php | 84 ---- lib/thothAPI/models/ThothInstitution.inc.php | 84 ---- lib/thothAPI/models/ThothLanguage.inc.php | 94 ----- lib/thothAPI/models/ThothLocation.inc.php | 107 ------ lib/thothAPI/models/ThothModel.inc.php | 47 --- lib/thothAPI/models/ThothPublication.inc.php | 99 ----- lib/thothAPI/models/ThothPublisher.inc.php | 72 ---- lib/thothAPI/models/ThothReference.inc.php | 72 ---- lib/thothAPI/models/ThothSubject.inc.php | 93 ----- lib/thothAPI/models/ThothWork.inc.php | 232 ----------- lib/thothAPI/models/ThothWorkRelation.inc.php | 93 ----- 21 files changed, 2176 deletions(-) delete mode 100644 lib/thothAPI/ThothAccount.inc.php delete mode 100644 lib/thothAPI/ThothClient.inc.php delete mode 100644 lib/thothAPI/ThothGraphQL.inc.php delete mode 100644 lib/thothAPI/ThothMutation.inc.php delete mode 100644 lib/thothAPI/ThothQuery.inc.php delete mode 100644 lib/thothAPI/ThothQueryFields.inc.php delete mode 100644 lib/thothAPI/exceptions/ThothException.inc.php delete mode 100644 lib/thothAPI/models/ThothAffiliation.inc.php delete mode 100644 lib/thothAPI/models/ThothContribution.inc.php delete mode 100644 lib/thothAPI/models/ThothContributor.inc.php delete mode 100644 lib/thothAPI/models/ThothImprint.inc.php delete mode 100644 lib/thothAPI/models/ThothInstitution.inc.php delete mode 100644 lib/thothAPI/models/ThothLanguage.inc.php delete mode 100644 lib/thothAPI/models/ThothLocation.inc.php delete mode 100644 lib/thothAPI/models/ThothModel.inc.php delete mode 100644 lib/thothAPI/models/ThothPublication.inc.php delete mode 100644 lib/thothAPI/models/ThothPublisher.inc.php delete mode 100644 lib/thothAPI/models/ThothReference.inc.php delete mode 100644 lib/thothAPI/models/ThothSubject.inc.php delete mode 100644 lib/thothAPI/models/ThothWork.inc.php delete mode 100644 lib/thothAPI/models/ThothWorkRelation.inc.php diff --git a/lib/thothAPI/ThothAccount.inc.php b/lib/thothAPI/ThothAccount.inc.php deleted file mode 100644 index 5b12193..0000000 --- a/lib/thothAPI/ThothAccount.inc.php +++ /dev/null @@ -1,73 +0,0 @@ -httpClient = $httpClient; - $this->accountEndpoint = $thothEndpoint . self::THOTH_ACCOUNT_ENDPOINT; - $this->authEndpoint = $thothEndpoint . self::THOTH_AUTH_ENDPOINT; - } - - public function getToken($email, $password) - { - $payload = ['email' => $email, 'password' => $password]; - - try { - $response = $this->httpClient->post($this->authEndpoint, ['json' => $payload]); - } catch (RequestException $e) { - $returnMessage = $e->getMessage(); - if ($e->hasResponse()) { - $returnMessage = $e->getResponse()->getBody()->getContents(); - } - throw new ThothException($returnMessage, $e->getCode()); - } - - return json_decode($response->getBody())->token; - } - - public function getDetails($token) - { - try { - $response = $this->httpClient->get( - $this->accountEndpoint, - ['headers' => ['Authorization' => 'Bearer ' . $token]] - ); - } catch (RequestException $e) { - $returnMessage = $e->getMessage(); - if ($e->hasResponse()) { - $returnMessage = $e->getResponse()->getBody()->getContents(); - } - throw new ThothException($returnMessage, $e->getCode()); - } - - return json_decode($response->getBody(), true); - } -} diff --git a/lib/thothAPI/ThothClient.inc.php b/lib/thothAPI/ThothClient.inc.php deleted file mode 100644 index 95254eb..0000000 --- a/lib/thothAPI/ThothClient.inc.php +++ /dev/null @@ -1,361 +0,0 @@ -endpoint = $testEnvironment ? self::THOTH_TEST_ENDPOINT : self::THOTH_ENDPOINT; - $this->httpClient = $httpClient ?? Application::get()->getHttpClient(); - } - - public function login($email, $password) - { - $account = new ThothAccount($this->endpoint, $this->httpClient); - $this->token = $account->getToken($email, $password); - } - - public function linkedPublishers() - { - $account = new ThothAccount($this->endpoint, $this->httpClient); - $details = $account->getDetails($this->token); - return $details['resourceAccess']['linkedPublishers']; - } - - public function mutation($name, $data, $returnValue = null, $enumeratedFields = [], $nested = true) - { - if ($data instanceof ThothModel) { - $enumeratedFields = $data->getEnumeratedValues(); - $returnValue = $data->getReturnValue(); - $data = $data->getData(); - } - $mutation = new ThothMutation($name, $data, $returnValue, $enumeratedFields, $nested); - $graphql = new ThothGraphQL($this->endpoint, $this->httpClient, $this->token); - return $mutation->run($graphql); - } - - public function query($name, $params, $fields) - { - $query = new ThothQuery($name, $params, $fields); - $graphql = new ThothGraphQL($this->endpoint, $this->httpClient); - return $query->run($graphql); - } - - public function createAffiliation($affiliation) - { - return $this->mutation('createAffiliation', $affiliation); - } - - public function createWork($work) - { - return $this->mutation('createWork', $work); - } - - public function createContributor($contributor) - { - return $this->mutation('createContributor', $contributor); - } - - public function createContribution($contribution) - { - return $this->mutation('createContribution', $contribution); - } - - public function createWorkRelation($workRelation) - { - return $this->mutation('createWorkRelation', $workRelation); - } - - public function createPublication($publication) - { - return $this->mutation('createPublication', $publication); - } - - public function createLocation($location) - { - return $this->mutation('createLocation', $location); - } - - public function createSubject($subject) - { - return $this->mutation('createSubject', $subject); - } - - public function createLanguage($language) - { - return $this->mutation('createLanguage', $language); - } - - public function createReference($reference) - { - return $this->mutation('createReference', $reference); - } - - public function updateWork($work) - { - return $this->mutation('updateWork', $work); - } - - public function updatePublication($publication) - { - return $this->mutation('updatePublication', $publication); - } - - public function updateContribution($contribution) - { - return $this->mutation('updateContribution', $contribution); - } - - public function deleteWork($workId) - { - $data = ['workId' => $workId]; - return $this->mutation('deleteWork', $data, 'workId', [], false); - } - - public function deleteContribution($contributionId) - { - $data = ['contributionId' => $contributionId]; - return $this->mutation('deleteContribution', $data, 'contributionId', [], false); - } - - public function deleteSubject($subjectId) - { - $data = ['subjectId' => $subjectId]; - return $this->mutation('deleteSubject', $data, 'subjectId', [], false); - } - - public function deleteReference($referenceId) - { - $data = ['referenceId' => $referenceId]; - return $this->mutation('deleteReference', $data, 'referenceId', [], false); - } - - public function deletePublication($publicationId) - { - $data = ['publicationId' => $publicationId]; - return $this->mutation('deletePublication', $data, 'publicationId', [], false); - } - - public function deleteLocation($locationId) - { - $data = ['locationId' => $locationId]; - return $this->mutation('deleteLocation', $data, 'locationId', [], false); - } - - public function contribution($contributionId) - { - $this->addParameter($params, 'contributionId', $contributionId, true); - $fields = ThothQueryFields::contribution(); - - return $this->query('contribution', $params, $fields); - } - - public function contributions($args = []) - { - $defaultArgs = [ - 'limit' => 100, - 'offset' => 0, - 'order' => [], - 'publishers' => [], - 'contributionTypes' => [] - ]; - - $args = array_merge($defaultArgs, $args); - - $this->addParameter($params, 'limit', $args['limit']); - $this->addParameter($params, 'offset', $args['offset']); - $this->addParameter($params, 'order', $args['order']); - $this->addParameter($params, 'publishers', $args['publishers'], true); - $this->addParameter($params, 'contributionTypes', $args['contributionTypes'], true); - $fields = ThothQueryFields::contribution(); - - return $this->query('contributions', $params, $fields); - } - - public function contributor($contributorId) - { - $this->addParameter($params, 'contributorId', $contributorId, true); - $fields = ThothQueryFields::contributor(); - - return $this->query('contributor', $params, $fields); - } - - public function contributors($args = []) - { - $defaultArgs = [ - 'limit' => 100, - 'offset' => 0, - 'filter' => '', - 'order' => [] - ]; - - $args = array_merge($defaultArgs, $args); - - $this->addParameter($params, 'limit', $args['limit']); - $this->addParameter($params, 'offset', $args['offset']); - $this->addParameter($params, 'filter', $args['filter'], true); - $this->addParameter($params, 'order', $args['order']); - $fields = ThothQueryFields::contributor(); - - return $this->query('contributors', $params, $fields); - } - - public function institution($institutionId) - { - $this->addParameter($params, 'institutionId', $institutionId, true); - $fields = ThothQueryFields::institution(); - - return $this->query('institution', $params, $fields); - } - - public function institutions($args = []) - { - $defaultArgs = [ - 'limit' => 100, - 'offset' => 0, - 'filter' => '', - 'order' => [] - ]; - - $args = array_merge($defaultArgs, $args); - - $this->addParameter($params, 'limit', $args['limit']); - $this->addParameter($params, 'offset', $args['offset']); - $this->addParameter($params, 'filter', $args['filter'], true); - $this->addParameter($params, 'order', $args['order']); - $fields = ThothQueryFields::institution(); - - return $this->query('institutions', $params, $fields); - } - - public function imprint($imprintId) - { - $this->addParameter($params, 'imprintId', $imprintId, true); - $fields = ThothQueryFields::imprint(); - - return $this->query('imprint', $params, $fields); - } - - public function imprints($args = []) - { - $defaultArgs = [ - 'limit' => 100, - 'offset' => 0, - 'filter' => '', - 'order' => [], - 'publishers' => [] - ]; - - $args = array_merge($defaultArgs, $args); - - $this->addParameter($params, 'limit', $args['limit']); - $this->addParameter($params, 'offset', $args['offset']); - $this->addParameter($params, 'filter', $args['filter'], true); - $this->addParameter($params, 'order', $args['order']); - $this->addParameter($params, 'publishers', $args['publishers'], true); - $fields = ThothQueryFields::imprint(); - - return $this->query('imprints', $params, $fields); - } - - public function publisher($publisherId) - { - $this->addParameter($params, 'publisherId', $publisherId, true); - $fields = ThothQueryFields::publisher(); - - return $this->query('publisher', $params, $fields); - } - - public function publishers($args = []) - { - $defaultArgs = [ - 'limit' => 100, - 'offset' => 0, - 'filter' => '', - 'order' => [], - 'publishers' => [] - ]; - - $args = array_merge($defaultArgs, $args); - - $this->addParameter($params, 'limit', $args['limit']); - $this->addParameter($params, 'offset', $args['offset']); - $this->addParameter($params, 'filter', $args['filter'], true); - $this->addParameter($params, 'order', $args['order']); - $this->addParameter($params, 'publishers', $args['publishers'], true); - $fields = ThothQueryFields::publisher(); - - return $this->query('publishers', $params, $fields); - } - - public function work($workId) - { - $this->addParameter($params, 'workId', $workId, true); - $fields = ThothQueryFields::work(); - - return $this->query('work', $params, $fields); - } - - private function addParameter(&$params, $key, $value, $enclosed = false) - { - if ($value == '' || (is_array($value) && empty($value))) { - return; - } - - $params = $params ?? []; - - if (is_array($value)) { - $params[] = (array_values($value) !== $value) ? - sprintf( - '%s:{%s}', - $key, - implode(',', array_map(function ($subKey, $subValue) { - return sprintf('%s:%s', $subKey, $subValue); - }, array_keys($value), array_values($value))) - ) : - sprintf( - '%s:[%s]', - $key, - implode(',', $enclosed ? array_map([$this, 'encloseValue'], $value) : $value) - ); - return; - } - - $params[] = sprintf('%s:%s', $key, $enclosed ? $this->encloseValue($value) : $value); - return; - } - - private function encloseValue($value) - { - return json_encode($value); - } -} diff --git a/lib/thothAPI/ThothGraphQL.inc.php b/lib/thothAPI/ThothGraphQL.inc.php deleted file mode 100644 index 3c180a8..0000000 --- a/lib/thothAPI/ThothGraphQL.inc.php +++ /dev/null @@ -1,89 +0,0 @@ -httpClient = $httpClient; - $this->endpoint = $thothEndpoint . self::THOTH_GRAPHQL_ENDPOINT; - $this->token = $token; - } - - public function execute($query) - { - $payload = [ - 'query' => $query, - ]; - - $options = [ - 'headers' => [ - 'Accept' => 'application/json', - 'Content-Type' => 'application/json' - ], - 'json' => $payload - ]; - - if ($this->token) { - $options['headers']['Authorization'] = 'Bearer ' . $this->token; - } - - try { - $response = $this->httpClient->post($this->endpoint, $options); - } catch (RequestException $e) { - throw new ThothException($this->getReturnMessage($e), $e->getCode()); - } - - $responseBody = json_decode($response->getBody()->getContents(), true); - - if ($error = $this->getResponseError($responseBody)) { - throw new ThothException($error, $response->getStatusCode()); - } - - return $responseBody['data']; - } - - private function getReturnMessage($exception) - { - $returnMessage = $exception->getMessage(); - if ($exception->hasResponse()) { - $errors = json_decode($exception->getResponse()->getBody())->errors; - $error = array_shift($errors); - $returnMessage = $error->message; - } - return $returnMessage; - } - - private function getResponseError($responseBody) - { - if (!array_key_exists('errors', $responseBody)) { - return null; - } - - $error = array_shift($responseBody['errors']); - - return $error['message']; - } -} diff --git a/lib/thothAPI/ThothMutation.inc.php b/lib/thothAPI/ThothMutation.inc.php deleted file mode 100644 index 8e4c706..0000000 --- a/lib/thothAPI/ThothMutation.inc.php +++ /dev/null @@ -1,63 +0,0 @@ -name = $name; - $this->returnValue = $returnValue; - $this->mutation = $this->prepare($data, $enumeratedValues, $nested); - } - - private function prepare($data, $enumeratedValues, $nested) - { - $mutationQuery = $nested ? 'mutation{%s(data:{%s}){%s}}' : 'mutation{%s(%s){%s}}'; - $fields = []; - foreach ($data as $attribute => $value) { - $fields[] = sprintf( - '%s: %s', - $attribute, - $this->sanitize($attribute, $value, $enumeratedValues) - ); - } - - $mutation = sprintf( - $mutationQuery, - $this->name, - implode(',', $fields), - $this->returnValue - ); - - return $mutation; - } - - private function sanitize($attribute, $value, $enumeratedValues) - { - return in_array($attribute, $enumeratedValues) ? $value : json_encode($value); - } - - public function run($graphQlClient) - { - $result = $graphQlClient->execute($this->mutation); - return $result[$this->name][$this->returnValue]; - } -} diff --git a/lib/thothAPI/ThothQuery.inc.php b/lib/thothAPI/ThothQuery.inc.php deleted file mode 100644 index c711097..0000000 --- a/lib/thothAPI/ThothQuery.inc.php +++ /dev/null @@ -1,55 +0,0 @@ -queryName = $queryName; - $this->params = implode(',', $params); - $this->fields = $this->formatFields($fields); - } - - private function formatFields($fields) - { - return implode(',', array_map(function ($key, $field) { - return is_array($field) ? sprintf('%s{%s}', $key, $this->formatFields($field)) : $field; - }, array_keys($fields), array_values($fields))); - } - - public function prepare() - { - $query = sprintf( - 'query{%s(%s){%s}}', - $this->queryName, - $this->params, - $this->fields - ); - return $query; - } - - public function run($graphqlClient) - { - $query = $this->prepare(); - $result = $graphqlClient->execute($query); - return $result[$this->queryName]; - } -} diff --git a/lib/thothAPI/ThothQueryFields.inc.php b/lib/thothAPI/ThothQueryFields.inc.php deleted file mode 100644 index 3e5171d..0000000 --- a/lib/thothAPI/ThothQueryFields.inc.php +++ /dev/null @@ -1,106 +0,0 @@ -getProperties(ReflectionProperty::IS_PRIVATE); - - return array_map(function ($prop) { - return $prop->getName(); - }, $properties); - } -} diff --git a/lib/thothAPI/exceptions/ThothException.inc.php b/lib/thothAPI/exceptions/ThothException.inc.php deleted file mode 100644 index 03fdd5d..0000000 --- a/lib/thothAPI/exceptions/ThothException.inc.php +++ /dev/null @@ -1,27 +0,0 @@ -error = $error; - parent::__construct('Failed to send the request to Thoth: ' . $error, $code); - } - - public function getError() - { - return $this->error; - } -} diff --git a/lib/thothAPI/models/ThothAffiliation.inc.php b/lib/thothAPI/models/ThothAffiliation.inc.php deleted file mode 100644 index ed6629b..0000000 --- a/lib/thothAPI/models/ThothAffiliation.inc.php +++ /dev/null @@ -1,72 +0,0 @@ -affiliationId; - } - - public function setId($affiliationId) - { - $this->affiliationId = $affiliationId; - } - - public function getContributionId() - { - return $this->contributionId; - } - - public function setContributionId($contributionId) - { - $this->contributionId = $contributionId; - } - - public function getInstitutionId() - { - return $this->institutionId; - } - - public function setInstitutionId($institutionId) - { - $this->institutionId = $institutionId; - } - - public function getAffiliationOrdinal() - { - return $this->affiliationOrdinal; - } - - public function setAffiliationOrdinal($affiliationOrdinal) - { - $this->affiliationOrdinal = $affiliationOrdinal; - } -} diff --git a/lib/thothAPI/models/ThothContribution.inc.php b/lib/thothAPI/models/ThothContribution.inc.php deleted file mode 100644 index 4bc2114..0000000 --- a/lib/thothAPI/models/ThothContribution.inc.php +++ /dev/null @@ -1,157 +0,0 @@ -contributionId; - } - - public function setId($contributionId) - { - $this->contributionId = $contributionId; - } - - public function getWorkId() - { - return $this->workId; - } - - public function setWorkId($workId) - { - $this->workId = $workId; - } - - public function getContributorId() - { - return $this->contributorId; - } - - public function setContributorId($contributorId) - { - $this->contributorId = $contributorId; - } - - public function getContributionType() - { - return $this->contributionType; - } - - public function setContributionType($contributionType) - { - $this->contributionType = $contributionType; - } - - public function getMainContribution() - { - return $this->mainContribution; - } - - public function setMainContribution($mainContribution) - { - $this->mainContribution = $mainContribution; - } - - public function getContributionOrdinal() - { - return $this->contributionOrdinal; - } - - public function setContributionOrdinal($contributionOrdinal) - { - $this->contributionOrdinal = $contributionOrdinal; - } - - public function getFirstName() - { - return $this->firstName; - } - - public function setFirstName($firstName) - { - $this->firstName = $firstName; - } - - public function getLastName() - { - return $this->lastName; - } - - public function setLastName($lastName) - { - $this->lastName = $lastName; - } - - public function getFullName() - { - return $this->fullName; - } - - public function setFullName($fullName) - { - $this->fullName = $fullName; - } - - public function getBiography() - { - return $this->biography; - } - - public function setBiography($biography) - { - $this->biography = $biography; - } -} diff --git a/lib/thothAPI/models/ThothContributor.inc.php b/lib/thothAPI/models/ThothContributor.inc.php deleted file mode 100644 index 0fbdb3c..0000000 --- a/lib/thothAPI/models/ThothContributor.inc.php +++ /dev/null @@ -1,96 +0,0 @@ -contributorId; - } - - public function setId($id) - { - $this->contributorId = $id; - } - - public function getFirstName() - { - return $this->firstName; - } - - public function setFirstName($firstName) - { - $this->firstName = $firstName; - } - - public function getLastName() - { - return $this->lastName; - } - - public function setLastName($lastName) - { - $this->lastName = $lastName; - } - - public function getFullName() - { - return $this->fullName; - } - - public function setFullName($fullName) - { - $this->fullName = $fullName; - } - - public function getOrcid() - { - return $this->orcid; - } - - public function setOrcid($orcid) - { - $this->orcid = $orcid; - } - - public function getWebsite() - { - return $this->website; - } - - public function setWebsite($website) - { - $this->website = $website; - } -} diff --git a/lib/thothAPI/models/ThothImprint.inc.php b/lib/thothAPI/models/ThothImprint.inc.php deleted file mode 100644 index 62be69a..0000000 --- a/lib/thothAPI/models/ThothImprint.inc.php +++ /dev/null @@ -1,84 +0,0 @@ -imprintId; - } - - public function setId($imprintId) - { - $this->imprintId = $imprintId; - } - - public function getPublisherId() - { - return $this->publisherId; - } - - public function setPublisherId($publisherId) - { - $this->publisherId = $publisherId; - } - - public function getImprintName() - { - return $this->imprintName; - } - - public function setImprintName($imprintName) - { - $this->imprintName = $imprintName; - } - - public function getImprintUrl() - { - return $this->imprintUrl; - } - - public function setImprintUrl($imprintUrl) - { - $this->imprintUrl = $imprintUrl; - } - - public function getCrossmarkDoi() - { - return $this->crossmarkDoi; - } - - public function setCrossmarkDoi($crossmarkDoi) - { - $this->crossmarkDoi = $crossmarkDoi; - } -} diff --git a/lib/thothAPI/models/ThothInstitution.inc.php b/lib/thothAPI/models/ThothInstitution.inc.php deleted file mode 100644 index 4a161c0..0000000 --- a/lib/thothAPI/models/ThothInstitution.inc.php +++ /dev/null @@ -1,84 +0,0 @@ -institutionId; - } - - public function setId($institutionId) - { - $this->institutionId = $institutionId; - } - - public function getInstitutionName() - { - return $this->institutionName; - } - - public function setInstitutionName($institutionName) - { - $this->institutionName = $institutionName; - } - - public function getInstitutionDoi() - { - return $this->institutionDoi; - } - - public function setInstitutionDoi($institutionDoi) - { - $this->institutionDoi = $institutionDoi; - } - - public function getCountryCode() - { - return $this->countryCode; - } - - public function setCountryCode($countryCode) - { - $this->countryCode = $countryCode; - } - - public function getRor() - { - return $this->ror; - } - - public function setRor($ror) - { - $this->ror = $ror; - } -} diff --git a/lib/thothAPI/models/ThothLanguage.inc.php b/lib/thothAPI/models/ThothLanguage.inc.php deleted file mode 100644 index 8a5395d..0000000 --- a/lib/thothAPI/models/ThothLanguage.inc.php +++ /dev/null @@ -1,94 +0,0 @@ -languageId; - } - - public function setId($languageId) - { - $this->languageId = $languageId; - } - - public function getWorkId() - { - return $this->workId; - } - - public function setWorkId($workId) - { - $this->workId = $workId; - } - - public function getLanguageCode() - { - return $this->languageCode; - } - - public function setLanguageCode($languageCode) - { - $this->languageCode = $languageCode; - } - - public function getLanguageRelation() - { - return $this->languageRelation; - } - - public function setLanguageRelation($languageRelation) - { - $this->languageRelation = $languageRelation; - } - - public function getMainLanguage() - { - return $this->mainLanguage; - } - - public function setMainLanguage($mainLanguage) - { - $this->mainLanguage = $mainLanguage; - } -} diff --git a/lib/thothAPI/models/ThothLocation.inc.php b/lib/thothAPI/models/ThothLocation.inc.php deleted file mode 100644 index ff8e8a7..0000000 --- a/lib/thothAPI/models/ThothLocation.inc.php +++ /dev/null @@ -1,107 +0,0 @@ -locationId; - } - - public function setId($locationId) - { - $this->locationId = $locationId; - } - - public function getPublicationId() - { - return $this->publicationId; - } - - public function setPublicationId($publicationId) - { - $this->publicationId = $publicationId; - } - - public function getLandingPage() - { - return $this->landingPage; - } - - public function setLandingPage($landingPage) - { - $this->landingPage = $landingPage; - } - - public function getFullTextUrl() - { - return $this->fullTextUrl; - } - - public function setFullTextUrl($fullTextUrl) - { - $this->fullTextUrl = $fullTextUrl; - } - - public function getLocationPlatform() - { - return $this->locationPlatform; - } - - public function setLocationPlatform($locationPlatform) - { - $this->locationPlatform = $locationPlatform; - } - - public function getCanonical() - { - return $this->canonical; - } - - public function setCanonical($canonical) - { - $this->canonical = $canonical; - } -} diff --git a/lib/thothAPI/models/ThothModel.inc.php b/lib/thothAPI/models/ThothModel.inc.php deleted file mode 100644 index 0427443..0000000 --- a/lib/thothAPI/models/ThothModel.inc.php +++ /dev/null @@ -1,47 +0,0 @@ -getProperties(ReflectionProperty::IS_PRIVATE); - - $attributes = []; - - foreach ($properties as $property) { - $property->setAccessible(true); - $value = $property->getValue($this); - if ($value === null || (is_string($value) && trim($value) === '')) { - continue; - } - $attributes[$property->getName()] = $value; - } - - return $attributes; - } -} diff --git a/lib/thothAPI/models/ThothPublication.inc.php b/lib/thothAPI/models/ThothPublication.inc.php deleted file mode 100644 index eeccba9..0000000 --- a/lib/thothAPI/models/ThothPublication.inc.php +++ /dev/null @@ -1,99 +0,0 @@ -publicationId; - } - - public function setId($publicationId) - { - $this->publicationId = $publicationId; - } - - public function getWorkId() - { - return $this->workId; - } - - public function setWorkId($workId) - { - $this->workId = $workId; - } - - public function getPublicationType() - { - return $this->publicationType; - } - - public function setPublicationType($publicationType) - { - $this->publicationType = $publicationType; - } - - public function getIsbn() - { - return $this->isbn; - } - - public function setIsbn($isbn) - { - $this->isbn = $isbn; - } -} diff --git a/lib/thothAPI/models/ThothPublisher.inc.php b/lib/thothAPI/models/ThothPublisher.inc.php deleted file mode 100644 index c3d29cc..0000000 --- a/lib/thothAPI/models/ThothPublisher.inc.php +++ /dev/null @@ -1,72 +0,0 @@ -publisherId; - } - - public function setId($publisherId) - { - $this->publisherId = $publisherId; - } - - public function getPublisherName() - { - return $this->publisherName; - } - - public function setPublisherName($publisherName) - { - $this->publisherName = $publisherName; - } - - public function getPublisherShortname() - { - return $this->publisherShortname; - } - - public function setPublisherShortname($publisherShortname) - { - $this->publisherShortname = $publisherShortname; - } - - public function getPublisherUrl() - { - return $this->publisherUrl; - } - - public function setPublisherUrl($publisherUrl) - { - $this->publisherUrl = $publisherUrl; - } -} diff --git a/lib/thothAPI/models/ThothReference.inc.php b/lib/thothAPI/models/ThothReference.inc.php deleted file mode 100644 index 7cf2af0..0000000 --- a/lib/thothAPI/models/ThothReference.inc.php +++ /dev/null @@ -1,72 +0,0 @@ -referenceId; - } - - public function setId($referenceId) - { - $this->referenceId = $referenceId; - } - - public function getWorkId() - { - return $this->workId; - } - - public function setWorkId($workId) - { - $this->workId = $workId; - } - - public function getReferenceOrdinal() - { - return $this->referenceOrdinal; - } - - public function setReferenceOrdinal($referenceOrdinal) - { - $this->referenceOrdinal = $referenceOrdinal; - } - - public function getUnstructuredCitation() - { - return $this->unstructuredCitation; - } - - public function setUnstructuredCitation($unstructuredCitation) - { - $this->unstructuredCitation = $unstructuredCitation; - } -} diff --git a/lib/thothAPI/models/ThothSubject.inc.php b/lib/thothAPI/models/ThothSubject.inc.php deleted file mode 100644 index 7817ffb..0000000 --- a/lib/thothAPI/models/ThothSubject.inc.php +++ /dev/null @@ -1,93 +0,0 @@ -subjectId; - } - - public function setId($subjectId) - { - $this->subjectId = $subjectId; - } - - public function getWorkId() - { - return $this->workId; - } - - public function setWorkId($workId) - { - $this->workId = $workId; - } - - public function getSubjectType() - { - return $this->subjectType; - } - - public function setSubjectType($subjectType) - { - $this->subjectType = $subjectType; - } - - public function getSubjectCode() - { - return $this->subjectCode; - } - - public function setSubjectCode($subjectCode) - { - $this->subjectCode = $subjectCode; - } - - public function getSubjectOrdinal() - { - return $this->subjectOrdinal; - } - - public function setSubjectOrdinal($subjectOrdinal) - { - $this->subjectOrdinal = $subjectOrdinal; - } -} diff --git a/lib/thothAPI/models/ThothWork.inc.php b/lib/thothAPI/models/ThothWork.inc.php deleted file mode 100644 index 74970ad..0000000 --- a/lib/thothAPI/models/ThothWork.inc.php +++ /dev/null @@ -1,232 +0,0 @@ -workId; - } - - public function setId($workId) - { - $this->workId = $workId; - } - - public function getWorkType() - { - return $this->workType; - } - - public function setWorkType($workType) - { - $this->workType = $workType; - } - - public function getWorkStatus() - { - return $this->workStatus; - } - - public function setWorkStatus($workStatus) - { - $this->workStatus = $workStatus; - } - - public function getFullTitle() - { - return $this->fullTitle; - } - - public function setFullTitle($fullTitle) - { - $this->fullTitle = $fullTitle; - } - - public function getTitle() - { - return $this->title; - } - - public function setTitle($title) - { - $this->title = $title; - } - - public function getSubtitle() - { - return $this->subtitle; - } - - public function setSubtitle($subtitle) - { - $this->subtitle = $subtitle; - } - - public function getEdition() - { - return $this->edition; - } - - public function setEdition($edition) - { - $this->edition = $edition; - } - - public function getImprintId() - { - return $this->imprintId; - } - - public function setImprintId($imprintId) - { - $this->imprintId = $imprintId; - } - - public function getDoi() - { - return $this->doi; - } - - public function setDoi($doi) - { - $this->doi = $doi; - } - - public function getPublicationDate() - { - return $this->publicationDate; - } - - public function setPublicationDate($publicationDate) - { - $this->publicationDate = $publicationDate; - } - - public function getPageCount() - { - return $this->pageCount; - } - - public function setPageCount($pageCount) - { - $this->pageCount = $pageCount; - } - - public function getLicense() - { - return $this->license; - } - - public function setLicense($license) - { - $this->license = $license; - } - - public function getCopyrightHolder() - { - return $this->copyrightHolder; - } - - public function setCopyrightHolder($copyrightHolder) - { - $this->copyrightHolder = $copyrightHolder; - } - - public function getLandingPage() - { - return $this->landingPage; - } - - public function setLandingPage($landingPage) - { - $this->landingPage = $landingPage; - } - - public function getLongAbstract() - { - return $this->longAbstract; - } - - public function setLongAbstract($longAbstract) - { - $this->longAbstract = $longAbstract; - } - - public function getCoverUrl() - { - return $this->coverUrl; - } - - public function setCoverUrl($coverUrl) - { - $this->coverUrl = $coverUrl; - } -} diff --git a/lib/thothAPI/models/ThothWorkRelation.inc.php b/lib/thothAPI/models/ThothWorkRelation.inc.php deleted file mode 100644 index 36ddd9a..0000000 --- a/lib/thothAPI/models/ThothWorkRelation.inc.php +++ /dev/null @@ -1,93 +0,0 @@ -workRelationId; - } - - public function setId($workRelationId) - { - $this->workRelationId = $workRelationId; - } - - public function getRelatorWorkId() - { - return $this->relatorWorkId; - } - - public function setRelatorWorkId($relatorWorkId) - { - $this->relatorWorkId = $relatorWorkId; - } - - public function getRelatedWorkId() - { - return $this->relatedWorkId; - } - - public function setRelatedWorkId($relatedWorkId) - { - $this->relatedWorkId = $relatedWorkId; - } - - public function getRelationType() - { - return $this->relationType; - } - - public function setRelationType($relationType) - { - $this->relationType = $relationType; - } - - public function getRelationOrdinal() - { - return $this->relationOrdinal; - } - - public function setRelationOrdinal($relationOrdinal) - { - $this->relationOrdinal = $relationOrdinal; - } -} From 1cda58dcf31a92417e01039e2f4401e48e1b1f5b Mon Sep 17 00:00:00 2001 From: Thiago Brasil Date: Mon, 27 Jan 2025 18:27:57 -0400 Subject: [PATCH 06/10] Refactoring code to use thoth-client-php library Issue: documentacao-e-tarefas/desenvolvimento_e_infra#929 Signed-off-by: Thiago Brasil --- ThothPlugin.inc.php | 23 - ThothSettingsForm.inc.php | 19 +- classes/ThothRegister.inc.php | 71 +- classes/ThothUpdater.inc.php | 10 +- classes/ThothValidator.inc.php | 4 +- classes/components/forms/RegisterForm.inc.php | 6 +- classes/facades/ThothService.inc.php | 31 +- .../services/ThothAffiliationService.inc.php | 14 +- .../services/ThothContributionService.inc.php | 22 +- .../services/ThothContributorService.inc.php | 16 +- .../services/ThothInstitutionService.inc.php | 10 +- classes/services/ThothLanguageService.inc.php | 10 +- classes/services/ThothLocationService.inc.php | 21 +- .../services/ThothPublicationService.inc.php | 17 +- .../services/ThothReferenceService.inc.php | 14 +- classes/services/ThothSubjectService.inc.php | 17 +- classes/services/ThothWorkService.inc.php | 218 ++++-- .../ThothWorkQueryBuilder.inc.php | 104 --- controllers/modal/RegisterHandler.inc.php | 10 +- .../services/ThothAffiliationServiceTest.php | 25 +- .../services/ThothContributionServiceTest.php | 25 +- .../services/ThothContributorServiceTest.php | 33 +- .../services/ThothInstitutionServiceTest.php | 22 +- .../services/ThothLanguageServiceTest.php | 10 +- .../services/ThothLocationServiceTest.php | 16 +- .../services/ThothPublicationServiceTest.php | 16 +- .../services/ThothReferenceServiceTest.php | 15 +- .../services/ThothSubjectServiceTest.php | 12 +- .../classes/services/ThothWorkServiceTest.php | 64 +- .../ThothWorkQueryBuilderTest.php | 209 ------ tests/fixtures/accountDetails.json | 1 - tests/fixtures/contribution.json | 1 - tests/fixtures/contributions.json | 1 - tests/fixtures/contributor.json | 1 - tests/fixtures/contributors.json | 1 - tests/fixtures/imprint.json | 1 - tests/fixtures/imprints.json | 1 - tests/fixtures/institution.json | 1 - tests/fixtures/institutions.json | 1 - tests/fixtures/publisher.json | 1 - tests/fixtures/publishers.json | 1 - tests/fixtures/work.json | 1 - tests/fixtures/workWithContributions.json | 1 - tests/thoth/ThothAccountTest.php | 101 --- tests/thoth/ThothClientTest.php | 672 ------------------ tests/thoth/ThothGraphQLTest.php | 144 ---- tests/thoth/ThothMutationTest.php | 57 -- tests/thoth/ThothQueryTest.php | 100 --- tests/thoth/models/ThothAffiliationTest.php | 51 -- tests/thoth/models/ThothContributionTest.php | 87 --- tests/thoth/models/ThothContributorTest.php | 65 -- tests/thoth/models/ThothImprintTest.php | 55 -- tests/thoth/models/ThothInstitutionTest.php | 53 -- tests/thoth/models/ThothLanguageTest.php | 55 -- tests/thoth/models/ThothLocationTest.php | 77 -- tests/thoth/models/ThothPublicationTest.php | 51 -- tests/thoth/models/ThothPublisherTest.php | 51 -- tests/thoth/models/ThothReferenceTest.php | 64 -- tests/thoth/models/ThothSubjectTest.php | 55 -- tests/thoth/models/ThothWorkRelationTest.php | 59 -- tests/thoth/models/ThothWorkTest.php | 109 --- 61 files changed, 468 insertions(+), 2535 deletions(-) delete mode 100644 classes/services/queryBuilders/ThothWorkQueryBuilder.inc.php delete mode 100644 tests/classes/services/queryBuilders/ThothWorkQueryBuilderTest.php delete mode 100644 tests/fixtures/accountDetails.json delete mode 100644 tests/fixtures/contribution.json delete mode 100644 tests/fixtures/contributions.json delete mode 100644 tests/fixtures/contributor.json delete mode 100644 tests/fixtures/contributors.json delete mode 100644 tests/fixtures/imprint.json delete mode 100644 tests/fixtures/imprints.json delete mode 100644 tests/fixtures/institution.json delete mode 100644 tests/fixtures/institutions.json delete mode 100644 tests/fixtures/publisher.json delete mode 100644 tests/fixtures/publishers.json delete mode 100644 tests/fixtures/work.json delete mode 100644 tests/fixtures/workWithContributions.json delete mode 100644 tests/thoth/ThothAccountTest.php delete mode 100644 tests/thoth/ThothClientTest.php delete mode 100644 tests/thoth/ThothGraphQLTest.php delete mode 100644 tests/thoth/ThothMutationTest.php delete mode 100644 tests/thoth/ThothQueryTest.php delete mode 100644 tests/thoth/models/ThothAffiliationTest.php delete mode 100644 tests/thoth/models/ThothContributionTest.php delete mode 100644 tests/thoth/models/ThothContributorTest.php delete mode 100644 tests/thoth/models/ThothImprintTest.php delete mode 100644 tests/thoth/models/ThothInstitutionTest.php delete mode 100644 tests/thoth/models/ThothLanguageTest.php delete mode 100644 tests/thoth/models/ThothLocationTest.php delete mode 100644 tests/thoth/models/ThothPublicationTest.php delete mode 100644 tests/thoth/models/ThothPublisherTest.php delete mode 100644 tests/thoth/models/ThothReferenceTest.php delete mode 100644 tests/thoth/models/ThothSubjectTest.php delete mode 100644 tests/thoth/models/ThothWorkRelationTest.php delete mode 100644 tests/thoth/models/ThothWorkTest.php diff --git a/ThothPlugin.inc.php b/ThothPlugin.inc.php index db1525d..62a12db 100644 --- a/ThothPlugin.inc.php +++ b/ThothPlugin.inc.php @@ -16,7 +16,6 @@ * @brief Plugin for integration with Thoth for communication and synchronization of book data between the two platforms */ -use APP\plugins\generic\thoth\classes\APIKeyEncryption; use PKP\core\JSONMessage; import('lib.pkp.classes.plugins.GenericPlugin'); @@ -24,7 +23,6 @@ import('plugins.generic.thoth.classes.ThothNotification'); import('plugins.generic.thoth.classes.ThothRegister'); import('plugins.generic.thoth.classes.ThothUpdater'); -import('plugins.generic.thoth.lib.thothAPI.exceptions.ThothException'); class ThothPlugin extends GenericPlugin { @@ -125,25 +123,4 @@ public function manage($args, $request) } return parent::manage($args, $request); } - - public function getThothClient($contextId = null) - { - $contextId = $contextId ?? Application::get()->getRequest()->getContext()->getId(); - - $email = $this->getSetting($contextId, 'email'); - $password = $this->getSetting($contextId, 'password'); - - if (!$email || !$password) { - throw new ThothException('Credentials not configured', 0); - } - - $password = APIKeyEncryption::decryptString($password); - $testEnvironment = $this->getSetting($contextId, 'testEnvironment'); - - import('plugins.generic.thoth.lib.thothAPI.ThothClient'); - $thothClient = new ThothClient($testEnvironment); - $thothClient->login($email, $password); - - return $thothClient; - } } diff --git a/ThothSettingsForm.inc.php b/ThothSettingsForm.inc.php index d4a9364..a78ee57 100644 --- a/ThothSettingsForm.inc.php +++ b/ThothSettingsForm.inc.php @@ -21,8 +21,8 @@ use PKP\form\validation\FormValidatorCSRF; use PKP\form\validation\FormValidatorCustom; use PKP\form\validation\FormValidatorPost; - -import('plugins.generic.thoth.lib.thothAPI.ThothClient'); +use ThothApi\Exception\QueryException; +use ThothApi\GraphQL\Client; class ThothSettingsForm extends Form { @@ -53,13 +53,16 @@ public function __construct($plugin, $contextId) function ($password) use ($form) { $email = trim($this->getData('email')); $testEnvironment = $this->getData('testEnvironment'); - $thothClient = new ThothClient($testEnvironment); + $httpConfig = []; + if ($testEnvironment) { + $httpConfig['base_uri'] = 'http://localhost:8000/'; + } + + $client = new Client($httpConfig); + try { - $thothClient->login( - $email, - $password - ); - } catch (ThothException $e) { + $client->login($email, $password); + } catch (QueryException $e) { return false; } return true; diff --git a/classes/ThothRegister.inc.php b/classes/ThothRegister.inc.php index ad0a240..0142933 100644 --- a/classes/ThothRegister.inc.php +++ b/classes/ThothRegister.inc.php @@ -18,6 +18,7 @@ use APP\i18n\AppLocale; use APP\notification\Notification; use PKP\security\Role; +use ThothApi\Exception\QueryException; import('plugins.generic.thoth.classes.facades.ThothService'); import('plugins.generic.thoth.classes.ThothValidator'); @@ -69,12 +70,13 @@ public function addThothField($hookName, $form) $errors = []; try { - $thothClient = $this->plugin->getThothClient($submission->getData('contextId')); - $publishers = $thothClient->linkedPublishers(); + $thothClient = ThothContainer::getInstance()->get('client'); + $thothAccountDetails = $thothClient->accountDetails(); + $publishers = $thothAccountDetails['resourceAccess']['linkedPublishers']; $imprints = $thothClient->imprints(['publishers' => array_column($publishers, 'publisherId')]); - } catch (ThothException $e) { + } catch (QueryException $e) { $errors[] = __('plugins.generic.thoth.connectionError'); - error_log($e->getMessage()); + error_log('Failed to send the request to Thoth: ' . $e->getMessage()); } if (empty($errors)) { @@ -101,8 +103,8 @@ public function addThothField($hookName, $form) $imprintOptions = []; foreach ($imprints as $imprint) { $imprintOptions[] = [ - 'value' => $imprint['imprintId'], - 'label' => $imprint['imprintName'] + 'value' => $imprint->getImprintId(), + 'label' => $imprint->getImprintName() ]; } @@ -120,53 +122,9 @@ public function addThothField($hookName, $form) 'required' => true, 'showWhen' => 'registerConfirmation', 'groupId' => 'default', - 'value' => $imprints[0]['imprintId'] ?? null + 'value' => $imprintOptions[0]['value'] ?? null ])); - // return false; - - // try { - // $thothClient = $this->plugin->getThothClient($submission->getData('contextId')); - // $publishers = $thothClient->linkedPublishers(); - // $imprints = $thothClient->imprints(['publishers' => array_column($publishers, 'publisherId')]); - - // $imprintOptions = []; - // foreach ($imprints as $imprint) { - // $imprintOptions[] = [ - // 'value' => $imprint['imprintId'], - // 'label' => $imprint['imprintName'] - // ]; - // } - - // $form->addField(new \PKP\components\forms\FieldOptions('registerConfirmation', [ - // 'label' => __('plugins.generic.thoth.register.label'), - // 'options' => [ - // ['value' => true, 'label' => __('plugins.generic.thoth.register.confirmation')] - // ], - // 'value' => false, - // 'groupId' => 'default', - // ])) - // ->addField(new \PKP\components\forms\FieldSelect('imprint', [ - // 'label' => __('plugins.generic.thoth.imprint'), - // 'options' => $imprintOptions, - // 'required' => true, - // 'showWhen' => 'registerConfirmation', - // 'groupId' => 'default', - // 'value' => $imprints[0]['imprintId'] ?? null - // ])); - // } catch (ThothException $e) { - // $warningIconHtml = ''; - // $noticeMsg = __('plugins.generic.thoth.connectionError'); - // $msg = '
' . $warningIconHtml . $noticeMsg . '
'; - - // $form->addField(new \PKP\components\forms\FieldHTML('registerNotice', [ - // 'description' => $msg, - // 'groupId' => 'default', - // ])); - - // error_log($e->getMessage()); - // } - return false; } @@ -249,23 +207,22 @@ public function registerWork($submission, $imprint) } try { - $thothClient = $this->plugin->getThothClient($submissionContext->getId()); - $thothBook = ThothService::work()->registerBook($thothClient, $submission, $imprint); - Repo::submission()->edit($submission, ['thothWorkId' => $thothBook->getId()]); + $thothBook = ThothService::work()->registerBook($submission, $imprint); + Repo::submission()->edit($submission, ['thothWorkId' => $thothBook->getWorkId()]); ThothNotification::notify( $request, $submission, Notification::NOTIFICATION_TYPE_SUCCESS, 'plugins.generic.thoth.register.success' ); - } catch (ThothException $e) { - error_log($e->getMessage()); + } catch (QueryException $e) { + error_log('Failed to send the request to Thoth: ' . $e->getMessage()); ThothNotification::notify( $request, $submission, Notification::NOTIFICATION_TYPE_ERROR, 'plugins.generic.thoth.register.error', - $e->getError() + $e->getMessage() ); } } diff --git a/classes/ThothUpdater.inc.php b/classes/ThothUpdater.inc.php index d68d49c..3a63647 100644 --- a/classes/ThothUpdater.inc.php +++ b/classes/ThothUpdater.inc.php @@ -16,6 +16,7 @@ use APP\facades\Repo; use APP\notification\Notification; +use ThothApi\Exception\QueryException; import('plugins.generic.thoth.classes.facades.ThothService'); @@ -41,22 +42,21 @@ public function updateWork($hookName, $args) } try { - $thothClient = $this->plugin->getThothClient($submission->getData('contextId')); - ThothService::work()->updateBook($thothClient, $thothWorkId, $submission, $publication); + ThothService::work()->updateBook($thothWorkId, $submission, $publication); ThothNotification::notify( $request, $submission, Notification::NOTIFICATION_TYPE_SUCCESS, 'plugins.generic.thoth.update.success' ); - } catch (ThothException $e) { - error_log($e->getMessage()); + } catch (QueryException $e) { + error_log('Failed to send the request to Thoth: ' . $e->getMessage()); ThothNotification::notify( $request, $submission, Notification::NOTIFICATION_TYPE_ERROR, 'plugins.generic.thoth.update.error', - $e->getError() + $e->getMessage() ); } diff --git a/classes/ThothValidator.inc.php b/classes/ThothValidator.inc.php index 99950d4..a178eac 100644 --- a/classes/ThothValidator.inc.php +++ b/classes/ThothValidator.inc.php @@ -45,7 +45,9 @@ public static function validateIsbn($publicationFormats) foreach ($publicationFormats as $publicationFormat) { try { $isbn = ThothService::publication()->getIsbnByPublicationFormat($publicationFormat); - Isbn::validateAsIsbn13($isbn); + if ($isbn !== null) { + Isbn::validateAsIsbn13($isbn); + } } catch (Exception $e) { $errors[] = __('plugins.generic.thoth.validation.isbn', [ 'isbn' => $isbn, diff --git a/classes/components/forms/RegisterForm.inc.php b/classes/components/forms/RegisterForm.inc.php index 8ee19a1..ab876f4 100644 --- a/classes/components/forms/RegisterForm.inc.php +++ b/classes/components/forms/RegisterForm.inc.php @@ -59,8 +59,8 @@ public function __construct($action, $imprints, $errors) $imprintOptions = []; foreach ($imprints as $imprint) { $imprintOptions[] = [ - 'value' => $imprint['imprintId'], - 'label' => $imprint['imprintName'] + 'value' => $imprint->getImprintId(), + 'label' => $imprint->getImprintName() ]; } @@ -86,7 +86,7 @@ public function __construct($action, $imprints, $errors) 'options' => $imprintOptions, 'required' => true, 'groupId' => 'default', - 'value' => $imprints[0]['imprintId'] ?? null + 'value' => $imprintOptions[0]['value'] ?? null ])); } diff --git a/classes/facades/ThothService.inc.php b/classes/facades/ThothService.inc.php index 8b495fd..59baba7 100644 --- a/classes/facades/ThothService.inc.php +++ b/classes/facades/ThothService.inc.php @@ -14,66 +14,57 @@ * @brief This facade provides access to all Services for Thoth. */ -import('plugins.generic.thoth.classes.services.ThothAffiliationService'); -import('plugins.generic.thoth.classes.services.ThothContributionService'); -import('plugins.generic.thoth.classes.services.ThothContributorService'); -import('plugins.generic.thoth.classes.services.ThothInstitutionService'); -import('plugins.generic.thoth.classes.services.ThothLanguageService'); -import('plugins.generic.thoth.classes.services.ThothLocationService'); -import('plugins.generic.thoth.classes.services.ThothPublicationService'); -import('plugins.generic.thoth.classes.services.ThothReferenceService'); -import('plugins.generic.thoth.classes.services.ThothSubjectService'); -import('plugins.generic.thoth.classes.services.ThothWorkService'); +import('plugins.generic.thoth.classes.container.ThothContainer'); class ThothService { public static function affiliation() { - return app(ThothAffiliationService::class); + return ThothContainer::getInstance()->get('affiliationService'); } public static function contribution() { - return app(ThothContributionService::class); + return ThothContainer::getInstance()->get('contributionService'); } public static function contributor() { - return app(ThothContributorService::class); + return ThothContainer::getInstance()->get('contributorService'); } public static function institution() { - return app(ThothInstitutionService::class); + return ThothContainer::getInstance()->get('institutionService'); } public static function language() { - return app(ThothLanguageService::class); + return ThothContainer::getInstance()->get('languageService'); } public static function location() { - return app(ThothLocationService::class); + return ThothContainer::getInstance()->get('locationService'); } public static function publication() { - return app(ThothPublicationService::class); + return ThothContainer::getInstance()->get('publicationService'); } public static function reference() { - return app(ThothReferenceService::class); + return ThothContainer::getInstance()->get('referenceService'); } public static function subject() { - return app(ThothSubjectService::class); + return ThothContainer::getInstance()->get('subjectService'); } public static function work() { - return app(ThothWorkService::class); + return ThothContainer::getInstance()->get('workService'); } } diff --git a/classes/services/ThothAffiliationService.inc.php b/classes/services/ThothAffiliationService.inc.php index f5b3d4b..cd7c3aa 100644 --- a/classes/services/ThothAffiliationService.inc.php +++ b/classes/services/ThothAffiliationService.inc.php @@ -14,24 +14,25 @@ * @brief Helper class that encapsulates business logic for Thoth affiliations */ +use ThothApi\GraphQL\Models\Affiliation as ThothAffiliation; + import('plugins.generic.thoth.classes.facades.ThothService'); -import('plugins.generic.thoth.lib.thothAPI.models.ThothAffiliation'); class ThothAffiliationService { public function new($params) { $thothAffiliation = new ThothAffiliation(); - $thothAffiliation->setId($params['affiliationId'] ?? null); + $thothAffiliation->setAffiliationId($params['affiliationId'] ?? null); $thothAffiliation->setContributionId($params['contributionId']); $thothAffiliation->setInstitutionId($params['institutionId']); $thothAffiliation->setAffiliationOrdinal($params['affiliationOrdinal']); return $thothAffiliation; } - public function register($thothClient, $affiliation, $thothContributionId) + public function register($affiliation, $thothContributionId) { - $thothInstitutions = ThothService::institution()->getMany($thothClient, [ + $thothInstitutions = ThothService::institution()->getMany([ 'limit' => 1, 'filter' => $affiliation ]); @@ -43,12 +44,13 @@ public function register($thothClient, $affiliation, $thothContributionId) $thothInstitution = array_shift($thothInstitutions); $thothAffiliation = $this->new([ 'contributionId' => $thothContributionId, - 'institutionId' => $thothInstitution->getId(), + 'institutionId' => $thothInstitution->getInstitutionId(), 'affiliationOrdinal' => 1 ]); + $thothClient = ThothContainer::getInstance()->get('client'); $thothAffiliationId = $thothClient->createAffiliation($thothAffiliation); - $thothAffiliation->setId($thothAffiliationId); + $thothAffiliation->setAffiliationId($thothAffiliationId); return $thothAffiliation; } diff --git a/classes/services/ThothContributionService.inc.php b/classes/services/ThothContributionService.inc.php index 6efc3b0..428326b 100644 --- a/classes/services/ThothContributionService.inc.php +++ b/classes/services/ThothContributionService.inc.php @@ -15,9 +15,9 @@ */ use APP\facades\Repo; +use ThothApi\GraphQL\Models\Contribution as ThothContribution; import('plugins.generic.thoth.classes.facades.ThothService'); -import('plugins.generic.thoth.lib.thothAPI.models.ThothContribution'); import('classes.core.Services'); class ThothContributionService @@ -25,7 +25,7 @@ class ThothContributionService public function new($params) { $contribution = new ThothContribution(); - $contribution->setId($params['contributionId'] ?? null); + $contribution->setContributionId($params['contributionId'] ?? null); $contribution->setWorkId($params['workId'] ?? null); $contribution->setContributorId($params['contributorId'] ?? null); $contribution->setContributionType($params['contributionType']); @@ -60,7 +60,7 @@ public function getDataByAuthor($author) return $data; } - public function register($thothClient, $author, $thothWorkId) + public function register($author, $thothWorkId) { $contribution = $this->newByAuthor($author); $contribution->setWorkId($thothWorkId); @@ -69,7 +69,7 @@ public function register($thothClient, $author, $thothWorkId) return; } - $contributors = ThothService::contributor()->getMany($thothClient, [ + $contributors = ThothService::contributor()->getMany([ 'limit' => 1, 'filter' => (!empty($author->getOrcid())) ? $author->getOrcid() : @@ -77,23 +77,25 @@ public function register($thothClient, $author, $thothWorkId) ]); $contributor = empty($contributors) ? - ThothService::contributor()->register($thothClient, $author) : + ThothService::contributor()->register($author) : array_shift($contributors); - $contribution->setContributorId($contributor->getId()); + $contribution->setContributorId($contributor->getContributorId()); + $thothClient = ThothContainer::getInstance()->get('client'); $contributionId = $thothClient->createContribution($contribution); - $contribution->setId($contributionId); + $contribution->setContributionId($contributionId); if ($affiliation = $author->getLocalizedAffiliation()) { - ThothService::affiliation()->register($thothClient, $affiliation, $contributionId); + ThothService::affiliation()->register($affiliation, $contributionId); } return $contribution; } - public function updateContributions($thothClient, $thothContributions, $publication, $thothWorkId) + public function updateContributions($thothContributions, $publication, $thothWorkId) { + $thothClient = ThothContainer::getInstance()->get('client'); $authors = $publication->getData('authors'); $publicationContributions = array_map(function ($author) { @@ -108,7 +110,7 @@ public function updateContributions($thothClient, $thothContributions, $publicat foreach ($authors as $author) { $publicationContribution = $this->getDataByAuthor($author); if (!$thothContribution = $this->contributionInList($publicationContribution, $thothContributions)) { - $this->register($thothClient, $author, $thothWorkId); + $this->register($author, $thothWorkId); continue; } if ($thothContribution['biography'] !== $publicationContribution['biography']) { diff --git a/classes/services/ThothContributorService.inc.php b/classes/services/ThothContributorService.inc.php index f796abe..ec0bc7a 100644 --- a/classes/services/ThothContributorService.inc.php +++ b/classes/services/ThothContributorService.inc.php @@ -14,14 +14,14 @@ * @brief Helper class that encapsulates business logic for Thoth contributors */ -import('plugins.generic.thoth.lib.thothAPI.models.ThothContributor'); +use ThothApi\GraphQL\Models\Contributor as ThothContributor; class ThothContributorService { public function new($params) { $contributor = new ThothContributor(); - $contributor->setId($params['contributorId'] ?? null); + $contributor->setContributorId($params['contributorId'] ?? null); $contributor->setFirstName($params['firstName'] ?? null); $contributor->setLastName($params['lastName']); $contributor->setFullName($params['fullName']); @@ -41,20 +41,20 @@ public function newByAuthor($author) return $this->new($params); } - public function register($thothClient, $author) + public function register($author) { $contributor = $this->newByAuthor($author); + $thothClient = ThothContainer::getInstance()->get('client'); $contributorId = $thothClient->createContributor($contributor); - $contributor->setId($contributorId); + $contributor->setContributorId($contributorId); return $contributor; } - public function getMany($thothClient, $params = []) + public function getMany($params = []) { - $contributorsData = $thothClient->contributors($params); - - return array_map([$this, 'new'], $contributorsData); + $thothClient = ThothContainer::getInstance()->get('client'); + return $thothClient->contributors($params); } } diff --git a/classes/services/ThothInstitutionService.inc.php b/classes/services/ThothInstitutionService.inc.php index 9221cfd..62ca7ac 100644 --- a/classes/services/ThothInstitutionService.inc.php +++ b/classes/services/ThothInstitutionService.inc.php @@ -14,14 +14,14 @@ * @brief Helper class that encapsulates business logic for Thoth institutions */ -import('plugins.generic.thoth.lib.thothAPI.models.ThothInstitution'); +use ThothApi\GraphQL\Models\Institution as ThothInstitution; class ThothInstitutionService { public function new($params) { $thothInstitution = new ThothInstitution(); - $thothInstitution->setId($params['institutionId']); + $thothInstitution->setInstitutionId($params['institutionId']); $thothInstitution->setInstitutionName($params['institutionName']); $thothInstitution->setInstitutionDoi($params['institutionDoi']); $thothInstitution->setCountryCode($params['countryCode']); @@ -29,9 +29,9 @@ public function new($params) return $thothInstitution; } - public function getMany($thothClient, $params = []) + public function getMany($params = []) { - $institutionsData = $thothClient->institutions($params); - return array_map([$this, 'new'], $institutionsData); + $thothClient = ThothContainer::getInstance()->get('client'); + return $thothClient->institutions($params); } } diff --git a/classes/services/ThothLanguageService.inc.php b/classes/services/ThothLanguageService.inc.php index 2ef4e63..2085908 100644 --- a/classes/services/ThothLanguageService.inc.php +++ b/classes/services/ThothLanguageService.inc.php @@ -15,15 +15,14 @@ */ use PKP\i18n\LocaleConversion; - -import('plugins.generic.thoth.lib.thothAPI.models.ThothLanguage'); +use ThothApi\GraphQL\Models\Language as ThothLanguage; class ThothLanguageService { public function new($params) { $thothLanguage = new ThothLanguage(); - $thothLanguage->setId($params['languageId'] ?? null); + $thothLanguage->setLanguageId($params['languageId'] ?? null); $thothLanguage->setWorkId($params['workId'] ?? null); $thothLanguage->setLanguageCode($params['languageCode']); $thothLanguage->setLanguageRelation($params['languageRelation']); @@ -31,7 +30,7 @@ public function new($params) return $thothLanguage; } - public function register($thothClient, $submissionLocale, $thothWorkId) + public function register($submissionLocale, $thothWorkId) { $thothLanguage = $this->new([ 'workId' => $thothWorkId, @@ -40,8 +39,9 @@ public function register($thothClient, $submissionLocale, $thothWorkId) 'mainLanguage' => true ]); + $thothClient = ThothContainer::getInstance()->get('client'); $thothLanguageId = $thothClient->createLanguage($thothLanguage); - $thothLanguage->setId($thothLanguageId); + $thothLanguage->setLanguageId($thothLanguageId); return $thothLanguage; } diff --git a/classes/services/ThothLocationService.inc.php b/classes/services/ThothLocationService.inc.php index f2480b5..b515390 100644 --- a/classes/services/ThothLocationService.inc.php +++ b/classes/services/ThothLocationService.inc.php @@ -16,8 +16,7 @@ use APP\core\Application; use APP\facades\Repo; - -import('plugins.generic.thoth.lib.thothAPI.models.ThothLocation'); +use ThothApi\GraphQL\Models\Location as ThothLocation; class ThothLocationService { @@ -64,7 +63,7 @@ public function getDataByPublicationFormat($publicationFormat, $fileId = null) public function new($params) { $thothLocation = new ThothLocation(); - $thothLocation->setId($params['locationId'] ?? null); + $thothLocation->setLocationId($params['locationId'] ?? null); $thothLocation->setPublicationId($params['publicationId'] ?? null); $thothLocation->setLandingPage($params['landingPage']); $thothLocation->setFullTextUrl($params['fullTextUrl']); @@ -74,25 +73,23 @@ public function new($params) return $thothLocation; } - public function register($thothClient, $publicationFormat, $thothPublicationId, $fileId = null, $canonical = true) + public function register($publicationFormat, $thothPublicationId, $fileId = null, $canonical = true) { $thothLocation = $this->newByPublicationFormat($publicationFormat, $fileId); $thothLocation->setPublicationId($thothPublicationId); $thothLocation->setCanonical($canonical); + $thothClient = ThothContainer::getInstance()->get('client'); $thothLocationId = $thothClient->createLocation($thothLocation); - $thothLocation->setId($thothLocationId); + $thothLocation->setLocationId($thothLocationId); return $thothLocation; } - public function updateLocations( - $thothClient, - $thothLocations, - $publicationFormat, - $thothPublicationId, - $chapterId = null - ) { + public function updateLocations($thothLocations, $publicationFormat, $thothPublicationId, $chapterId = null) + { + $thothClient = ThothContainer::getInstance()->get('client'); + $files = array_filter( iterator_to_array(Repo::submissionFile() ->getCollector() diff --git a/classes/services/ThothPublicationService.inc.php b/classes/services/ThothPublicationService.inc.php index 559b511..931c5f9 100644 --- a/classes/services/ThothPublicationService.inc.php +++ b/classes/services/ThothPublicationService.inc.php @@ -16,9 +16,9 @@ use APP\core\Application; use APP\facades\Repo; +use ThothApi\GraphQL\Models\Publication as ThothPublication; import('plugins.generic.thoth.classes.facades.ThothService'); -import('plugins.generic.thoth.lib.thothAPI.models.ThothPublication'); class ThothPublicationService { @@ -34,7 +34,7 @@ public function newByPublicationFormat($publicationFormat) public function new($params) { $publication = new ThothPublication(); - $publication->setId($params['publicationId'] ?? null); + $publication->setPublicationId($params['publicationId'] ?? null); $publication->setWorkId($params['workId'] ?? null); $publication->setPublicationType($params['publicationType']); $publication->setIsbn($params['isbn'] ?? null); @@ -42,7 +42,7 @@ public function new($params) return $publication; } - public function register($thothClient, $publicationFormat, $workId, $chapterId = null) + public function register($publicationFormat, $workId, $chapterId = null) { $thothPublication = $this->newByPublicationFormat($publicationFormat); $thothPublication->setWorkId($workId); @@ -51,11 +51,12 @@ public function register($thothClient, $publicationFormat, $workId, $chapterId = $thothPublication->setIsbn(null); } + $thothClient = ThothContainer::getInstance()->get('client'); $thothPublicationId = $thothClient->createPublication($thothPublication); - $thothPublication->setId($thothPublicationId); + $thothPublication->setPublicationId($thothPublicationId); if ($publicationFormat->getRemoteUrl()) { - ThothService::location()->register($thothClient, $publicationFormat, $thothPublicationId); + ThothService::location()->register($publicationFormat, $thothPublicationId); return $thothPublication; } @@ -75,7 +76,6 @@ function ($file) use ($chapterId) { $canonical = true; foreach ($files as $file) { ThothService::location()->register( - $thothClient, $publicationFormat, $thothPublicationId, $file->getId(), @@ -87,7 +87,7 @@ function ($file) use ($chapterId) { return $thothPublication; } - public function updateBookPublications($thothClient, $thothPublications, $publication, $thothWorkId) + public function updateBookPublications($thothPublications, $publication, $thothWorkId) { $publicationFormats = Application::getRepresentationDao() ->getApprovedByPublicationId($publication->getId()) @@ -113,7 +113,7 @@ public function updateBookPublications($thothClient, $thothPublications, $public }); if (empty($result)) { - $this->register($thothClient, $publicationFormat, $thothWorkId); + $this->register($publicationFormat, $thothWorkId); continue; } @@ -125,7 +125,6 @@ public function updateBookPublications($thothClient, $thothPublications, $public } ThothService::location()->updateLocations( - $thothClient, $thothPublication['locations'], $publicationFormat, $thothPublication['publicationId'] diff --git a/classes/services/ThothReferenceService.inc.php b/classes/services/ThothReferenceService.inc.php index 1f8a1eb..cdffa05 100644 --- a/classes/services/ThothReferenceService.inc.php +++ b/classes/services/ThothReferenceService.inc.php @@ -17,17 +17,17 @@ use APP\facades\Repo; use PKP\citation\Citation; use PKP\citation\CitationListTokenizerFilter; +use ThothApi\GraphQL\Models\Reference as ThothReference; import('lib.pkp.classes.citation.Citation'); import('lib.pkp.classes.citation.CitationListTokenizerFilter'); -import('plugins.generic.thoth.lib.thothAPI.models.ThothReference'); class ThothReferenceService { public function new($params) { $thothReference = new ThothReference(); - $thothReference->setId($params['referenceId'] ?? null); + $thothReference->setReferenceId($params['referenceId'] ?? null); $thothReference->setWorkId($params['workId'] ?? null); $thothReference->setReferenceOrdinal($params['referenceOrdinal']); $thothReference->setUnstructuredCitation($params['unstructuredCitation']); @@ -42,18 +42,19 @@ public function newByCitation($citation) return $this->new($params); } - public function register($thothClient, $citation, $thothWorkId) + public function register($citation, $thothWorkId) { $thothReference = $this->newByCitation($citation); $thothReference->setWorkId($thothWorkId); + $thothClient = ThothContainer::getInstance()->get('client'); $thothReferenceId = $thothClient->createReference($thothReference); - $thothReference->setId($thothReferenceId); + $thothReference->setReferenceId($thothReferenceId); return $thothReference; } - public function updateReferences($thothClient, $thothReferences, $publication, $thothWorkId) + public function updateReferences($thothReferences, $publication, $thothWorkId) { $oldPublication = Repo::publication()->get($publication->getId()); @@ -61,6 +62,7 @@ public function updateReferences($thothClient, $thothReferences, $publication, $ return; } + $thothClient = ThothContainer::getInstance()->get('client'); foreach ($thothReferences as $thothReference) { $thothClient->deleteReference($thothReference['referenceId']); } @@ -76,7 +78,7 @@ public function updateReferences($thothClient, $thothReferences, $publication, $ if (!empty(trim($citationString))) { $citation = new Citation($citationString); $citation->setSequence($order + 1); - $this->register($thothClient, $citation, $thothWorkId); + $this->register($citation, $thothWorkId); } } } diff --git a/classes/services/ThothSubjectService.inc.php b/classes/services/ThothSubjectService.inc.php index 0197d35..7f7200c 100644 --- a/classes/services/ThothSubjectService.inc.php +++ b/classes/services/ThothSubjectService.inc.php @@ -15,15 +15,14 @@ */ use APP\facades\Repo; - -import('plugins.generic.thoth.lib.thothAPI.models.ThothSubject'); +use ThothApi\GraphQL\Models\Subject as ThothSubject; class ThothSubjectService { public function new($params) { $thothSubject = new ThothSubject(); - $thothSubject->setId($params['subjectId'] ?? null); + $thothSubject->setSubjectId($params['subjectId'] ?? null); $thothSubject->setWorkId($params['workId'] ?? null); $thothSubject->setSubjectType($params['subjectType']); $thothSubject->setSubjectCode($params['subjectCode']); @@ -31,7 +30,7 @@ public function new($params) return $thothSubject; } - public function registerKeyword($thothClient, $submissionKeyword, $thothWorkId, $seq = 1) + public function registerKeyword($submissionKeyword, $thothWorkId, $seq = 1) { $thothSubject = $this->new([ 'workId' => $thothWorkId, @@ -40,13 +39,14 @@ public function registerKeyword($thothClient, $submissionKeyword, $thothWorkId, 'subjectOrdinal' => $seq ]); + $thothClient = ThothContainer::getInstance()->get('client'); $thothSubjectId = $thothClient->createSubject($thothSubject); - $thothSubject->setId($thothSubjectId); + $thothSubject->setSubjectId($thothSubjectId); return $thothSubject; } - public function updateKeywords($thothClient, $thothKeywords, $publication, $thothWorkId) + public function updateKeywords($thothKeywords, $publication, $thothWorkId) { $submission = Repo::submission()->get($publication->getData('submissionId')); $locale = $submission->getLocale(); @@ -56,8 +56,9 @@ public function updateKeywords($thothClient, $thothKeywords, $publication, $thot return; } - $localizedKeywords = $keywords[$locale]; + $thothClient = ThothContainer::getInstance()->get('client'); + $localizedKeywords = $keywords[$locale]; $thothKeywordData = array_column($thothKeywords, 'subjectCode', 'subjectId'); foreach ($thothKeywordData as $subjectId => $subjectCode) { if (!in_array($subjectCode, $localizedKeywords)) { @@ -67,7 +68,7 @@ public function updateKeywords($thothClient, $thothKeywords, $publication, $thot foreach ($localizedKeywords as $order => $keyword) { if (!in_array($keyword, $thothKeywordData)) { - $this->registerKeyword($thothClient, $keyword, $thothWorkId, $order + 1); + $this->registerKeyword($keyword, $thothWorkId, $order + 1); } } } diff --git a/classes/services/ThothWorkService.inc.php b/classes/services/ThothWorkService.inc.php index b6affbe..4b2ce8a 100644 --- a/classes/services/ThothWorkService.inc.php +++ b/classes/services/ThothWorkService.inc.php @@ -18,19 +18,13 @@ use APP\facades\Repo; use APP\submission\Submission; use PKP\db\DAORegistry; +use ThothApi\GraphQL\Models\Work as ThothWork; +use ThothApi\GraphQL\Models\WorkRelation as ThothWorkRelation; import('plugins.generic.thoth.classes.facades.ThothService'); -import('plugins.generic.thoth.lib.thothAPI.models.ThothWork'); -import('plugins.generic.thoth.lib.thothAPI.models.ThothWorkRelation'); -import('plugins.generic.thoth.classes.services.queryBuilders.ThothWorkQueryBuilder'); class ThothWorkService { - public function getQueryBuilder($thothClient) - { - return new ThothWorkQueryBuilder($thothClient); - } - public function getDataBySubmission($submission, $publication = null) { $request = Application::get()->getRequest(); @@ -94,7 +88,7 @@ public function newByChapter($chapter) public function new($params) { $work = new ThothWork(); - $work->setId($params['workId'] ?? null); + $work->setWorkId($params['workId'] ?? null); $work->setImprintId($params['imprintId'] ?? null); $work->setWorkType($params['workType']); $work->setWorkType($params['workType']); @@ -105,7 +99,7 @@ public function new($params) $work->setEdition($params['edition'] ?? null); $work->setPublicationDate($params['publicationDate'] ?? null); $work->setSubtitle($params['subtitle'] ?? null); - $work->setPageCount($params['pageCount'] ?? null); + $work->setPageCount(!empty($params['pageCount']) ? (int) $params['pageCount'] : null); $work->setDoi($params['doi'] ?? null); $work->setLicense($params['license'] ?? null); $work->setCopyrightHolder($params['copyrightHolder'] ?? null); @@ -115,19 +109,20 @@ public function new($params) return $work; } - public function get($thothClient, $thothWorkId) + public function get($thothWorkId) { - $thothWorkData = $thothClient->work($thothWorkId); - return $this->new($thothWorkData); + $thothClient = ThothContainer::getInstance()->get('client'); + return $thothClient->work($thothWorkId); } - public function registerBook($thothClient, $submission, $thothImprintId) + public function registerBook($submission, $thothImprintId) { $thothBook = $this->newBySubmission($submission); $thothBook->setImprintId($thothImprintId); + $thothClient = ThothContainer::getInstance()->get('client'); $thothBookId = $thothClient->createWork($thothBook); - $thothBook->setId($thothBookId); + $thothBook->setWorkId($thothBookId); $publication = $submission->getCurrentPublication(); @@ -135,52 +130,53 @@ public function registerBook($thothClient, $submission, $thothImprintId) ->filterByPublicationIds([$publication->getId()]) ->getMany(); foreach ($authors as $author) { - ThothService::contribution()->register($thothClient, $author, $thothBookId); + ThothService::contribution()->register($author, $thothBookId); } $chapterDAO = DAORegistry::getDAO('ChapterDAO'); $chapters = $chapterDAO->getByPublicationId($publication->getId())->toArray(); foreach ($chapters as $chapter) { - $this->registerWorkRelation($thothClient, $chapter, $thothImprintId, $thothBookId); + $this->registerWorkRelation($chapter, $thothImprintId, $thothBookId); } $publicationFormatDao = DAORegistry::getDAO('PublicationFormatDAO'); $publicationFormats = $publicationFormatDao->getApprovedByPublicationId($publication->getId())->toArray(); foreach ($publicationFormats as $publicationFormat) { if ($publicationFormat->getIsAvailable()) { - ThothService::publication()->register($thothClient, $publicationFormat, $thothBookId); + ThothService::publication()->register($publicationFormat, $thothBookId); } } $locale = $submission->getData('locale'); - ThothService::language()->register($thothClient, $locale, $thothBookId); + ThothService::language()->register($locale, $thothBookId); $keywords = $publication->getData('keywords'); foreach ($keywords[$locale] ?? [] as $seq => $keyword) { - ThothService::subject()->registerKeyword($thothClient, $keyword, $thothBookId, $seq + 1); + ThothService::subject()->registerKeyword($keyword, $thothBookId, $seq + 1); } $citations = DAORegistry::getDAO('CitationDAO') ->getByPublicationId($publication->getId()) ->toArray(); foreach ($citations as $citation) { - ThothService::reference()->register($thothClient, $citation, $thothBookId); + ThothService::reference()->register($citation, $thothBookId); } return $thothBook; } - public function registerChapter($thothClient, $chapter, $thothImprintId) + public function registerChapter($chapter, $thothImprintId) { $thothChapter = $this->newByChapter($chapter); $thothChapter->setImprintId($thothImprintId); + $thothClient = ThothContainer::getInstance()->get('client'); $thothChapterId = $thothClient->createWork($thothChapter); - $thothChapter->setId($thothChapterId); + $thothChapter->setWorkId($thothChapterId); $authors = $chapter->getAuthors()->toArray(); foreach ($authors as $author) { - ThothService::contribution()->register($thothClient, $author, $thothChapterId); + ThothService::contribution()->register($author, $thothChapterId); } $publication = Repo::publication()->get($chapter->getData('publicationId')); @@ -200,7 +196,6 @@ function ($a) use ($chapter) { $publicationFormat = $publicationFormatDao->getById($file->getData('assocId')); if ($publicationFormat->getIsAvailable()) { ThothService::publication()->register( - $thothClient, $publicationFormat, $thothChapterId, $chapter->getId() @@ -211,41 +206,38 @@ function ($a) use ($chapter) { return $thothChapter; } - public function registerWorkRelation($thothClient, $chapter, $thothImprintId, $relatedWorkId) + public function registerWorkRelation($chapter, $thothImprintId, $relatedWorkId) { - $thothChapter = $this->registerChapter($thothClient, $chapter, $thothImprintId); + $thothChapter = $this->registerChapter($chapter, $thothImprintId); $relation = new ThothWorkRelation(); - $relation->setRelatorWorkId($thothChapter->getId()); + $relation->setRelatorWorkId($thothChapter->getWorkId()); $relation->setRelatedWorkId($relatedWorkId); $relation->setRelationType(ThothWorkRelation::RELATION_TYPE_IS_CHILD_OF); $relation->setRelationOrdinal($chapter->getSequence() + 1); + $thothClient = ThothContainer::getInstance()->get('client'); $relationId = $thothClient->createWorkRelation($relation); - $relation->setId($relationId); + $relation->setWorkRelationId($relationId); return $relation; } - public function updateBook($thothClient, $thothWorkId, $submission, $publication) + public function updateBook($thothWorkId, $submission, $publication) { - $thothWorkData = []; - $thothWorkData = $this->getQueryBuilder($thothClient) - ->includeContributions() - ->includeRelations(true) - ->includeSubjects() - ->includeReferences() - ->includePublications(true) - ->get($thothWorkId); - $newThothWork = $this->new(array_merge( + $thothClient = ThothContainer::getInstance()->get('client'); + + $thothData = $thothClient->rawQuery($this->getCompleteWorkQuery(), ['workId' => $thothWorkId]); + $thothWorkData = $thothData['work']; + $submissionData = $this->getDataBySubmission($submission, $publication); + $mergedWorkData = array_merge( $thothWorkData, - $this->getDataBySubmission($submission, $publication) - )); - $thothClient->updateWork($newThothWork); + $submissionData + ); + $newThothWork = $this->new($mergedWorkData); if (isset($thothWorkData['contributions'])) { ThothService::contribution()->updateContributions( - $thothClient, $thothWorkData['contributions'], $publication, $thothWorkId @@ -254,7 +246,6 @@ public function updateBook($thothClient, $thothWorkId, $submission, $publication if (isset($thothWorkData['relations'])) { $this->updateRelations( - $thothClient, $thothWorkData['relations'], $publication, $thothWorkId, @@ -264,7 +255,6 @@ public function updateBook($thothClient, $thothWorkId, $submission, $publication if (isset($thothWorkData['subjects'])) { ThothService::subject()->updateKeywords( - $thothClient, $thothWorkData['subjects'], $publication, $thothWorkId @@ -273,7 +263,6 @@ public function updateBook($thothClient, $thothWorkId, $submission, $publication if (isset($thothWorkData['references'])) { ThothService::reference()->updateReferences( - $thothClient, $thothWorkData['references'], $publication, $thothWorkId @@ -282,7 +271,6 @@ public function updateBook($thothClient, $thothWorkId, $submission, $publication if (isset($thothWorkData['publications'])) { ThothService::publication()->updateBookPublications( - $thothClient, $thothWorkData['publications'], $publication, $thothWorkId @@ -292,7 +280,7 @@ public function updateBook($thothClient, $thothWorkId, $submission, $publication return $newThothWork; } - public function updateRelations($thothClient, $thothRelations, $publication, $thothWorkId, $thothImprintId) + public function updateRelations($thothRelations, $publication, $thothWorkId, $thothImprintId) { $chapterDAO = DAORegistry::getDAO('ChapterDAO'); $chapters = $chapterDAO->getByPublicationId($publication->getId())->toArray(); @@ -301,19 +289,22 @@ public function updateRelations($thothClient, $thothRelations, $publication, $th return; } + $thothClient = ThothContainer::getInstance()->get('client'); + $thothRelationsData = []; foreach ($thothRelations as $thothRelation) { - $relatedWork = $thothRelation['relatedWork']; - $fullTitle = $relatedWork['fullTitle']; - $thothRelationsData[$fullTitle] = $relatedWork; + $relationFullTitle = $thothRelation['relatedWork']['fullTitle']; + $thothRelationsData[$relationFullTitle] = $thothRelation; } + $chapterTitles = array_map(function ($chapter) { return $chapter->getLocalizedFullTitle(); }, $chapters); foreach ($thothRelationsData as $fullTitle => $relatedWork) { if (!in_array($fullTitle, $chapterTitles)) { - $thothClient->deleteWork($relatedWork['workId']); + error_log(print_r($relatedWork, true)); + $thothClient->deleteWork($relatedWork['relatedWorkId']); } } @@ -323,7 +314,7 @@ public function updateRelations($thothClient, $thothRelations, $publication, $th foreach ($chapters as $chapter) { $chapterTitle = $chapter->getLocalizedFullTitle(); if (!isset($thothRelationsData[$chapterTitle])) { - $this->registerWorkRelation($thothClient, $chapter, $thothImprintId, $thothWorkId); + $this->registerWorkRelation($chapter, $thothImprintId, $thothWorkId); } } } @@ -337,4 +328,125 @@ public function getWorkTypeBySubmissionWorkType($submissionWorkType) return $workTypeMapping[$submissionWorkType]; } + + private function getCompleteWorkQuery() + { + return <<thothClient = $thothClient; - - $this->fields = ThothQueryFields::work(); - } - - public function includeContributions($withContributors = false, $withAffiliation = false) - { - $fields = [ - 'contributions' => ThothQueryFields::contribution() - ]; - - if ($withContributors) { - $fields['contributions']['contributor'] = ThothQueryFields::contributor(); - } - - if ($withAffiliation) { - $fields['contributions']['affiliations'] = ThothQueryFields::affiliation(); - } - - $this->fields = array_merge($this->fields, $fields); - return $this; - } - - public function includeRelations($withWork = false) - { - $fields = [ - 'relations' => ThothQueryFields::workRelation() - ]; - - if ($withWork) { - $fields['relations']['relatedWork'] = ThothQueryFields::work(); - } - - $this->fields = array_merge($this->fields, $fields); - return $this; - } - - public function includeSubjects() - { - $fields = [ - 'subjects' => ThothQueryFields::subject() - ]; - - $this->fields = array_merge($this->fields, $fields); - return $this; - } - - public function includeReferences() - { - $fields = [ - 'references' => ThothQueryFields::reference() - ]; - - $this->fields = array_merge($this->fields, $fields); - return $this; - } - - public function includePublications($withLocations = false) - { - $fields = [ - 'publications' => ThothQueryFields::publication() - ]; - - if ($withLocations) { - $fields['publications']['locations'] = ThothQueryFields::location(); - } - - $this->fields = array_merge($this->fields, $fields); - return $this; - } - - public function get($workId) - { - $params = [sprintf('workId:"%s"', $workId)]; - - return $this->thothClient->query('work', $params, $this->fields); - } -} diff --git a/controllers/modal/RegisterHandler.inc.php b/controllers/modal/RegisterHandler.inc.php index b36a8bc..d5080bf 100644 --- a/controllers/modal/RegisterHandler.inc.php +++ b/controllers/modal/RegisterHandler.inc.php @@ -88,14 +88,16 @@ public function register($args, $request) $errors = []; try { - $thothClient = $plugin->getThothClient($submissionContext->getId()); - $publishers = $thothClient->linkedPublishers(); + $thothClient = ThothContainer::getInstance()->get('client'); + $thothAccountDetails = $thothClient->accountDetails(); + $publishers = $thothAccountDetails['resourceAccess']['linkedPublishers']; + $imprints = $thothClient->imprints(['publishers' => array_column($publishers, 'publisherId')]); $errors = array_merge(ThothValidator::validate($this->submission), $errors); - } catch (ThothException $e) { + } catch (QueryException $e) { $errors[] = __('plugins.generic.thoth.connectionError'); - error_log($e->getMessage()); + error_log('Failed to send the request to Thoth: ' . $e->getMessage()); } $plugin->import('classes.components.forms.RegisterForm'); diff --git a/tests/classes/services/ThothAffiliationServiceTest.php b/tests/classes/services/ThothAffiliationServiceTest.php index 3423a90..36529fd 100644 --- a/tests/classes/services/ThothAffiliationServiceTest.php +++ b/tests/classes/services/ThothAffiliationServiceTest.php @@ -17,29 +17,34 @@ */ use PKP\tests\PKPTestCase; +use ThothApi\GraphQL\Client; +use ThothApi\GraphQL\Models\Affiliation as ThothAffiliation; import('plugins.generic.thoth.classes.services.ThothAffiliationService'); -import('plugins.generic.thoth.lib.thothAPI.models.ThothAffiliation'); -import('plugins.generic.thoth.lib.thothAPI.ThothClient'); class ThothAffiliationServiceTest extends PKPTestCase { + private $clientFactoryBackup; + private $configFactoryBackup; + protected function setUp(): void { parent::setUp(); + $this->clientFactoryBackup = ThothContainer::getInstance()->backup('client'); $this->affiliationService = new ThothAffiliationService(); } protected function tearDown(): void { unset($this->affiliationService); + ThothContainer::getInstance()->set('client', $this->clientFactoryBackup); parent::tearDown(); } public function testCreateNewAffiliation() { $expectedThothAffiliation = new ThothAffiliation(); - $expectedThothAffiliation->setId('42d407e2-fd07-4c45-853d-74ddfc0a02a8'); + $expectedThothAffiliation->setAffiliationId('42d407e2-fd07-4c45-853d-74ddfc0a02a8'); $expectedThothAffiliation->setContributionId('8b4a7128-c483-459c-bb5d-89bf553ddf21'); $expectedThothAffiliation->setInstitutionId('918ab03e-248b-4cc8-8bf6-1f0c1166d98d'); $expectedThothAffiliation->setAffiliationOrdinal(1); @@ -59,12 +64,12 @@ public function testCreateNewAffiliation() public function testRegisterInstitution() { $expectedThothAffiliation = new ThothAffiliation(); - $expectedThothAffiliation->setId('0e721ddc-4ea5-453a-8590-e236a5f2db9b'); + $expectedThothAffiliation->setAffiliationId('0e721ddc-4ea5-453a-8590-e236a5f2db9b'); $expectedThothAffiliation->setContributionId('5c0a1fcb-2785-407e-8671-95c662bea559'); $expectedThothAffiliation->setInstitutionId('8ae6f820-b1ef-400c-852a-729c942bf8f2'); $expectedThothAffiliation->setAffiliationOrdinal(1); - $mockThothClient = $this->getMockBuilder(ThothClient::class) + $mockThothClient = $this->getMockBuilder(Client::class) ->setMethods(['createAffiliation','institutions']) ->getMock(); $mockThothClient->expects($this->any()) @@ -73,17 +78,21 @@ public function testRegisterInstitution() $mockThothClient->expects($this->any()) ->method('institutions') ->will($this->returnValue([ - [ + new ThothAffiliation([ 'institutionId' => '8ae6f820-b1ef-400c-852a-729c942bf8f2', 'institutionName' => 'Aalborg University', 'institutionDoi' => 'https://doi.org/10.13039/501100002702', 'countryCode' => 'DNK', 'ror' => 'https://ror.org/04m5j1k67' - ] + ]) ])); + ThothContainer::getInstance()->set('client', function () use ($mockThothClient) { + return $mockThothClient; + }); + + $thothAffiliation = $this->affiliationService->register( - $mockThothClient, 'Aalborg University', '5c0a1fcb-2785-407e-8671-95c662bea559' ); diff --git a/tests/classes/services/ThothContributionServiceTest.php b/tests/classes/services/ThothContributionServiceTest.php index 887640c..aeb7ad1 100644 --- a/tests/classes/services/ThothContributionServiceTest.php +++ b/tests/classes/services/ThothContributionServiceTest.php @@ -19,15 +19,21 @@ use APP\publication\Repository as PublicationRepository; use PKP\tests\PKPTestCase; use PKP\userGroup\Repository as UserGroupRepository; +use ThothApi\GraphQL\Client as ThothClient; +use ThothApi\GraphQL\Models\Contribution as ThothContribution; +use ThothApi\GraphQL\Models\Contributor as ThothContributor; import('plugins.generic.thoth.classes.services.ThothContributionService'); -import('plugins.generic.thoth.lib.thothAPI.ThothClient'); class ThothContributionServiceTest extends PKPTestCase { + private $clientFactoryBackup; + private $configFactoryBackup; + protected function setUp(): void { parent::setUp(); + $this->clientFactoryBackup = ThothContainer::getInstance()->backup('client'); $this->contributionService = new ThothContributionService(); $this->setUpMockEnvironment(); } @@ -35,6 +41,7 @@ protected function setUp(): void protected function tearDown(): void { unset($this->contributionService); + ThothContainer::getInstance()->set('client', $this->clientFactoryBackup); parent::tearDown(); } @@ -162,7 +169,7 @@ public function testCreateNewContribution() public function testRegisterContribution() { $expectedContribution = new ThothContribution(); - $expectedContribution->setId('67afac83-b015-4f32-9576-60b665a9e685'); + $expectedContribution->setContributionId('67afac83-b015-4f32-9576-60b665a9e685'); $expectedContribution->setWorkId('45a6622c-a306-4559-bb77-25367dc881b8'); $expectedContribution->setContributorId('f70f709e-2137-4c87-a2e5-d52b263759ec'); $expectedContribution->setContributionType(ThothContribution::CONTRIBUTION_TYPE_AUTHOR); @@ -171,6 +178,7 @@ public function testRegisterContribution() $expectedContribution->setFirstName('Michael'); $expectedContribution->setLastName('Wilson'); $expectedContribution->setFullName('Michael Wilson'); + $expectedContribution->setBiography(''); $authorMock = Mockery::mock(\APP\author\Author::class) ->makePartial() @@ -198,15 +206,20 @@ public function testRegisterContribution() $mockThothClient->expects($this->any()) ->method('contributors') ->will($this->returnValue([ - [ + new ThothContributor([ 'contributorId' => 'f70f709e-2137-4c87-a2e5-d52b263759ec', 'lastName' => 'Wilson', - 'fullName' => 'Michael Wilson' - ] + 'fullName' => 'Michael Wilson', + 'biography' => '' + ]) ])); + ThothContainer::getInstance()->set('client', function () use ($mockThothClient) { + return $mockThothClient; + }); + + $contribution = $this->contributionService->register( - $mockThothClient, $authorMock, '45a6622c-a306-4559-bb77-25367dc881b8' ); diff --git a/tests/classes/services/ThothContributorServiceTest.php b/tests/classes/services/ThothContributorServiceTest.php index 7c8c32b..9c4d9a6 100644 --- a/tests/classes/services/ThothContributorServiceTest.php +++ b/tests/classes/services/ThothContributorServiceTest.php @@ -17,24 +17,30 @@ */ use PKP\tests\PKPTestCase; +use ThothApi\GraphQL\Models\Contributor as ThothContributor; import('plugins.generic.thoth.classes.services.ThothContributorService'); -import('plugins.generic.thoth.lib.thothAPI.ThothClient'); class ThothContributorServiceTest extends PKPTestCase { + private $clientFactoryBackup; + private $configFactoryBackup; + protected function setUp(): void { parent::setUp(); + $this->clientFactoryBackup = ThothContainer::getInstance()->backup('client'); $this->contributorService = new ThothContributorService(); } protected function tearDown(): void { unset($this->contributorService); + ThothContainer::getInstance()->set('client', $this->clientFactoryBackup); parent::tearDown(); } + public function testCreateNewContributor() { $expectedContributor = new ThothContributor(); @@ -88,7 +94,7 @@ public function testCreateNewContributorByAuthor() public function testRegisterContributor() { $expectedContributor = new ThothContributor(); - $expectedContributor->setId('f70f709e-2137-4c87-a2e5-d52b263759ec'); + $expectedContributor->setContributorId('f70f709e-2137-4c87-a2e5-d52b263759ec'); $expectedContributor->setFirstName('Brian'); $expectedContributor->setLastName('Dupuis'); $expectedContributor->setFullName('Brian Dupuis'); @@ -115,7 +121,11 @@ public function testRegisterContributor() ->method('createContributor') ->will($this->returnValue('f70f709e-2137-4c87-a2e5-d52b263759ec')); - $contributor = $this->contributorService->register($mockThothClient, $authorMock); + ThothContainer::getInstance()->set('client', function () use ($mockThothClient) { + return $mockThothClient; + }); + + $contributor = $this->contributorService->register($authorMock); $this->assertEquals($expectedContributor, $contributor); } @@ -123,14 +133,14 @@ public function testGetManyContributors() { $expectedContributors = []; $expectedContributors[] = new ThothContributor(); - $expectedContributors[0]->setId('59383141-fff9-46e2-bc66-f71e42189380'); + $expectedContributors[0]->setContributorId('59383141-fff9-46e2-bc66-f71e42189380'); $expectedContributors[0]->setFirstName('Brenna Clarke'); $expectedContributors[0]->setLastName('Gray'); $expectedContributors[0]->setFullName('Brenna Clarke Gray'); $expectedContributors[0]->setOrcid('https://orcid.org/0000-0002-6079-0484'); $expectedContributors[0]->setWebsite('http://brennaclarkegray.ca'); $expectedContributors[] = new ThothContributor(); - $expectedContributors[1]->setId('5b0d32d4-bfd9-4db1-88fb-4cb91bdaf246'); + $expectedContributors[1]->setContributorId('5b0d32d4-bfd9-4db1-88fb-4cb91bdaf246'); $expectedContributors[1]->setFirstName('Dilton Oliveira de'); $expectedContributors[1]->setLastName('Araújo'); $expectedContributors[1]->setFullName('Dilton Oliveira de Araújo'); @@ -144,24 +154,27 @@ public function testGetManyContributors() $mockThothClient->expects($this->any()) ->method('contributors') ->will($this->returnValue([ - [ + new ThothContributor([ 'contributorId' => '59383141-fff9-46e2-bc66-f71e42189380', 'firstName' => 'Brenna Clarke', 'lastName' => 'Gray', 'fullName' => 'Brenna Clarke Gray', 'orcid' => 'https://orcid.org/0000-0002-6079-0484', 'website' => 'http://brennaclarkegray.ca' - ], - [ + ]), + new ThothContributor([ 'contributorId' => '5b0d32d4-bfd9-4db1-88fb-4cb91bdaf246', 'firstName' => 'Dilton Oliveira de', 'lastName' => 'Araújo', 'fullName' => 'Dilton Oliveira de Araújo', - 'orcid' => null, 'website' => 'http://buscatextual.cnpq.br/buscatextual/visualizacv.do?id=B00408' - ] + ]) ])); + ThothContainer::getInstance()->set('client', function () use ($mockThothClient) { + return $mockThothClient; + }); + $contributors = $this->contributorService->getMany($mockThothClient); $this->assertEquals($expectedContributors, $contributors); diff --git a/tests/classes/services/ThothInstitutionServiceTest.php b/tests/classes/services/ThothInstitutionServiceTest.php index 8761067..0d144cd 100644 --- a/tests/classes/services/ThothInstitutionServiceTest.php +++ b/tests/classes/services/ThothInstitutionServiceTest.php @@ -17,29 +17,33 @@ */ use PKP\tests\PKPTestCase; +use ThothApi\GraphQL\Models\Institution as ThothInstitution; import('plugins.generic.thoth.classes.services.ThothInstitutionService'); -import('plugins.generic.thoth.lib.thothAPI.models.ThothInstitution'); -import('plugins.generic.thoth.lib.thothAPI.ThothClient'); class ThothInstitutionServiceTest extends PKPTestCase { + private $clientFactoryBackup; + private $configFactoryBackup; + protected function setUp(): void { parent::setUp(); + $this->clientFactoryBackup = ThothContainer::getInstance()->backup('client'); $this->institutionService = new ThothInstitutionService(); } protected function tearDown(): void { unset($this->institutionService); + ThothContainer::getInstance()->set('client', $this->clientFactoryBackup); parent::tearDown(); } public function testCreateNewInstitution() { $expectedThothInstitution = new ThothInstitution(); - $expectedThothInstitution->setId('6e451aef-e496-4730-ac86-9f60d8ef4c55'); + $expectedThothInstitution->setInstitutionId('6e451aef-e496-4730-ac86-9f60d8ef4c55'); $expectedThothInstitution->setInstitutionName('National Science Foundation'); $expectedThothInstitution->setInstitutionDoi('https://doi.org/10.13039/100000001'); $expectedThothInstitution->setCountryCode('USA'); @@ -62,7 +66,7 @@ public function testGetManyInstitutions() { $expectedThothInstitutions = []; $expectedThothInstitutions[] = new ThothInstitution(); - $expectedThothInstitutions[0]->setId('f014c35a-31d8-453c-b356-d4912a87e52e'); + $expectedThothInstitutions[0]->setInstitutionId('f014c35a-31d8-453c-b356-d4912a87e52e'); $expectedThothInstitutions[0]->setInstitutionName('United States Department of Defense'); $expectedThothInstitutions[0]->setInstitutionDoi('https://doi.org/10.13039/100000005'); $expectedThothInstitutions[0]->setCountryCode('USA'); @@ -76,16 +80,20 @@ public function testGetManyInstitutions() $mockThothClient->expects($this->any()) ->method('institutions') ->will($this->returnValue([ - [ + new ThothInstitution([ 'institutionId' => 'f014c35a-31d8-453c-b356-d4912a87e52e', 'institutionName' => 'United States Department of Defense', 'institutionDoi' => 'https://doi.org/10.13039/100000005', 'countryCode' => 'USA', 'ror' => 'https://ror.org/0447fe631' - ] + ]) ])); - $thothInstitutions = $this->institutionService->getMany($mockThothClient); + ThothContainer::getInstance()->set('client', function () use ($mockThothClient) { + return $mockThothClient; + }); + + $thothInstitutions = $this->institutionService->getMany(); $this->assertEquals($expectedThothInstitutions, $thothInstitutions); } diff --git a/tests/classes/services/ThothLanguageServiceTest.php b/tests/classes/services/ThothLanguageServiceTest.php index cca44ef..dbd29c7 100644 --- a/tests/classes/services/ThothLanguageServiceTest.php +++ b/tests/classes/services/ThothLanguageServiceTest.php @@ -17,9 +17,9 @@ */ use PKP\tests\PKPTestCase; +use ThothApi\GraphQL\Models\Language as ThothLanguage; import('plugins.generic.thoth.classes.services.ThothLanguageService'); -import('plugins.generic.thoth.lib.thothAPI.ThothClient'); class ThothLanguageServiceTest extends PKPTestCase { @@ -58,7 +58,7 @@ public function testRegisterLanguage() $workId = '0600200b-865b-4706-a7e5-b5861a60dbc4'; $expectedThothLanguage = new ThothLanguage(); - $expectedThothLanguage->setId('47b9ecbe-98af-4c01-8b5c-0c222e996429'); + $expectedThothLanguage->setLanguageId('47b9ecbe-98af-4c01-8b5c-0c222e996429'); $expectedThothLanguage->setWorkId($workId); $expectedThothLanguage->setLanguageCode('ENG'); $expectedThothLanguage->setLanguageRelation(ThothLanguage::LANGUAGE_RELATION_ORIGINAL); @@ -75,7 +75,11 @@ public function testRegisterLanguage() ->method('createLanguage') ->will($this->returnValue('47b9ecbe-98af-4c01-8b5c-0c222e996429')); - $thothLanguage = $this->languageService->register($mockThothClient, $submissionLocale, $workId); + ThothContainer::getInstance()->set('client', function () use ($mockThothClient) { + return $mockThothClient; + }); + + $thothLanguage = $this->languageService->register($submissionLocale, $workId); $this->assertEquals($expectedThothLanguage, $thothLanguage); } } diff --git a/tests/classes/services/ThothLocationServiceTest.php b/tests/classes/services/ThothLocationServiceTest.php index 59b1749..7b958ee 100644 --- a/tests/classes/services/ThothLocationServiceTest.php +++ b/tests/classes/services/ThothLocationServiceTest.php @@ -21,15 +21,19 @@ use PKP\core\PKPRequest; use PKP\core\Registry; use PKP\tests\PKPTestCase; +use ThothApi\GraphQL\Models\Location as ThothLocation; import('plugins.generic.thoth.classes.services.ThothLocationService'); -import('plugins.generic.thoth.lib.thothAPI.ThothClient'); class ThothLocationServiceTest extends PKPTestCase { + private $clientFactoryBackup; + private $configFactoryBackup; + protected function setUp(): void { parent::setUp(); + $this->clientFactoryBackup = ThothContainer::getInstance()->backup('client'); $this->locationService = new ThothLocationService(); $this->setUpMockEnvironment(); } @@ -37,6 +41,7 @@ protected function setUp(): void protected function tearDown(): void { unset($this->locationService); + ThothContainer::getInstance()->set('client', $this->clientFactoryBackup); parent::tearDown(); } @@ -127,7 +132,7 @@ public function testRegisterLocation() $thothPublicationId = '8ac3e585-c32a-42d7-bd36-ef42ee397e6e'; $expectedLocation = new ThothLocation(); - $expectedLocation->setId('03b0367d-bba3-4e26-846a-4c36d3920db2'); + $expectedLocation->setLocationId('03b0367d-bba3-4e26-846a-4c36d3920db2'); $expectedLocation->setPublicationId($thothPublicationId); $expectedLocation->setLandingPage('https://omp.publicknowledgeproject.org/press/catalog/book/23'); $expectedLocation->setFullTextUrl('https://www.bookstore.com/site/books/book5'); @@ -156,7 +161,12 @@ public function testRegisterLocation() ->method('createLocation') ->will($this->returnValue('03b0367d-bba3-4e26-846a-4c36d3920db2')); - $location = $this->locationService->register($mockThothClient, $publicationFormatMock, $thothPublicationId); + ThothContainer::getInstance()->set('client', function () use ($mockThothClient) { + return $mockThothClient; + }); + + + $location = $this->locationService->register($publicationFormatMock, $thothPublicationId); $this->assertEquals($expectedLocation, $location); } } diff --git a/tests/classes/services/ThothPublicationServiceTest.php b/tests/classes/services/ThothPublicationServiceTest.php index 65d602d..4f5866a 100644 --- a/tests/classes/services/ThothPublicationServiceTest.php +++ b/tests/classes/services/ThothPublicationServiceTest.php @@ -20,20 +20,27 @@ use PKP\db\DAORegistry; use PKP\db\DAOResultFactory; use PKP\tests\PKPTestCase; +use ThothApi\GraphQL\Client as ThothClient; +use ThothApi\GraphQL\Models\Publication as ThothPublication; import('plugins.generic.thoth.classes.services.ThothPublicationService'); class ThothPublicationServiceTest extends PKPTestCase { + private $clientFactoryBackup; + private $configFactoryBackup; + protected function setUp(): void { parent::setUp(); + $this->clientFactoryBackup = ThothContainer::getInstance()->backup('client'); $this->publicationService = new ThothPublicationService(); } protected function tearDown(): void { unset($this->publicationService); + ThothContainer::getInstance()->set('client', $this->clientFactoryBackup); parent::tearDown(); } @@ -179,7 +186,7 @@ public function testRegisterPublication() $workId = '2a065323-76cd-4f54-b83b-19f2a925f426'; $expectedPublication = new ThothPublication(); - $expectedPublication->setId('80359118-9b33-4cf4-a4b4-8784e6d4375a'); + $expectedPublication->setPublicationId('80359118-9b33-4cf4-a4b4-8784e6d4375a'); $expectedPublication->setWorkId($workId); $expectedPublication->setPublicationType(ThothPublication::PUBLICATION_TYPE_HTML); $expectedPublication->setIsbn('978-1-912656-00-4'); @@ -214,7 +221,12 @@ public function testRegisterPublication() ->method('createPublication') ->will($this->returnValue('80359118-9b33-4cf4-a4b4-8784e6d4375a')); - $publication = $this->publicationService->register($mockThothClient, $publicationFormat, $workId); + ThothContainer::getInstance()->set('client', function () use ($mockThothClient) { + return $mockThothClient; + }); + + + $publication = $this->publicationService->register($publicationFormat, $workId); $this->assertEquals($expectedPublication, $publication); } } diff --git a/tests/classes/services/ThothReferenceServiceTest.php b/tests/classes/services/ThothReferenceServiceTest.php index 88e935a..65f4e6c 100644 --- a/tests/classes/services/ThothReferenceServiceTest.php +++ b/tests/classes/services/ThothReferenceServiceTest.php @@ -18,20 +18,27 @@ use PKP\db\DAORegistry; use PKP\tests\PKPTestCase; +use ThothApi\GraphQL\Client as ThothClient; +use ThothApi\GraphQL\Models\Reference as ThothReference; import('plugins.generic.thoth.classes.services.ThothReferenceService'); class ThothReferenceServiceTest extends PKPTestCase { + private $clientFactoryBackup; + private $configFactoryBackup; + protected function setUp(): void { parent::setUp(); + $this->clientFactoryBackup = ThothContainer::getInstance()->backup('client'); $this->referenceService = new ThothReferenceService(); } protected function tearDown(): void { unset($this->referenceService); + ThothContainer::getInstance()->set('client', $this->clientFactoryBackup); parent::tearDown(); } @@ -82,7 +89,7 @@ public function testRegisterReference() 'DOI: https://doi.org/10.1001/archinte.163.4.487 PMID: https://www.ncbi.nlm.nih.gov/pubmed/12588210'; $expectedThothReference = new ThothReference(); - $expectedThothReference->setId('c9521541-6676-4cf4-ad6d-06299682718b'); + $expectedThothReference->setReferenceId('c9521541-6676-4cf4-ad6d-06299682718b'); $expectedThothReference->setWorkId($workId); $expectedThothReference->setReferenceOrdinal(3); $expectedThothReference->setUnstructuredCitation($rawCitation); @@ -100,7 +107,11 @@ public function testRegisterReference() ->method('createReference') ->will($this->returnValue('c9521541-6676-4cf4-ad6d-06299682718b')); - $thothReference = $this->referenceService->register($mockThothClient, $citation, $workId); + ThothContainer::getInstance()->set('client', function () use ($mockThothClient) { + return $mockThothClient; + }); + + $thothReference = $this->referenceService->register($citation, $workId); $this->assertEquals($expectedThothReference, $thothReference); } } diff --git a/tests/classes/services/ThothSubjectServiceTest.php b/tests/classes/services/ThothSubjectServiceTest.php index 1e8e6e7..4cd1e3d 100644 --- a/tests/classes/services/ThothSubjectServiceTest.php +++ b/tests/classes/services/ThothSubjectServiceTest.php @@ -17,6 +17,8 @@ */ use PKP\tests\PKPTestCase; +use ThothApi\GraphQL\Client as ThothClient; +use ThothApi\GraphQL\Models\Subject as ThothSubject; import('plugins.generic.thoth.classes.services.ThothSubjectService'); @@ -37,7 +39,7 @@ protected function tearDown(): void public function testCreateNewThothSubject() { $expectedThothSubject = new ThothSubject(); - $expectedThothSubject->setId('6a9cdd5a-5877-433e-8063-9af0617eaa17'); + $expectedThothSubject->setSubjectId('6a9cdd5a-5877-433e-8063-9af0617eaa17'); $expectedThothSubject->setWorkId('1ef03055-2890-429a-b870-f9671711bcc4'); $expectedThothSubject->setSubjectType(ThothSubject::SUBJECT_TYPE_KEYWORD); $expectedThothSubject->setSubjectCode('Psychology'); @@ -61,7 +63,7 @@ public function testRegisterKeyword() $workId = '1ef03055-2890-429a-b870-f9671711bcc4'; $expectedThothKeyword = new ThothSubject(); - $expectedThothKeyword->setId('6a9cdd5a-5877-433e-8063-9af0617eaa17'); + $expectedThothKeyword->setSubjectId('6a9cdd5a-5877-433e-8063-9af0617eaa17'); $expectedThothKeyword->setWorkId($workId); $expectedThothKeyword->setSubjectType(ThothSubject::SUBJECT_TYPE_KEYWORD); $expectedThothKeyword->setSubjectCode('Psychology'); @@ -78,7 +80,11 @@ public function testRegisterKeyword() ->method('createSubject') ->will($this->returnValue('6a9cdd5a-5877-433e-8063-9af0617eaa17')); - $thothKeyword = $this->subjectService->registerKeyword($mockThothClient, $submissionKeyword, $workId); + ThothContainer::getInstance()->set('client', function () use ($mockThothClient) { + return $mockThothClient; + }); + + $thothKeyword = $this->subjectService->registerKeyword($submissionKeyword, $workId); $this->assertEquals($expectedThothKeyword, $thothKeyword); } } diff --git a/tests/classes/services/ThothWorkServiceTest.php b/tests/classes/services/ThothWorkServiceTest.php index ecc5048..29436e5 100644 --- a/tests/classes/services/ThothWorkServiceTest.php +++ b/tests/classes/services/ThothWorkServiceTest.php @@ -24,10 +24,11 @@ use PKP\core\Registry; use PKP\db\DAORegistry; use PKP\tests\PKPTestCase; +use ThothApi\GraphQL\Client as ThothClient; +use ThothApi\GraphQL\Models\Work as ThothWork; +use ThothApi\GraphQL\Models\WorkRelation as ThothWorkRelation; import('plugins.generic.thoth.classes.services.ThothWorkService'); -import('plugins.generic.thoth.lib.thothAPI.models.ThothWork'); -import('plugins.generic.thoth.lib.thothAPI.ThothClient'); class ThothWorkServiceTest extends PKPTestCase { @@ -113,7 +114,8 @@ private function setUpMockEnvironment() 'deleteContribution', 'createLanguage', 'createWorkRelation', - 'query' + 'work', + 'rawQuery' ]) ->getMock(); $mockThothClient->expects($this->any()) @@ -132,15 +134,30 @@ private function setUpMockEnvironment() ->method('createWorkRelation') ->will($this->returnValue('3e587b61-58f1-4064-bf80-e40e5c924d27')); $mockThothClient->expects($this->any()) - ->method('query') - ->will($this->returnValue([ + ->method('work') + ->will($this->returnValue(new ThothWork([ 'workId' => '39e399fb-cd40-461d-97cf-cf7f3a14cc48', 'imprintId' => '145369a6-916a-4107-ba0f-ce28137659c2', 'workType' => ThothWork::WORK_TYPE_BOOK_CHAPTER, 'workStatus' => ThothWork::WORK_STATUS_ACTIVE, 'fullTitle' => '10. Modification and Enhancement of Consciousness', 'title' => '10. Modification and Enhancement of Consciousness' - ])); + ]))); + $mockThothClient->expects($this->any()) + ->method('rawQuery') + ->will($this->returnValue( + [ + 'work' => [ + 'workId' => '39e399fb-cd40-461d-97cf-cf7f3a14cc48', + 'imprintId' => '145369a6-916a-4107-ba0f-ce28137659c2', + 'workType' => ThothWork::WORK_TYPE_BOOK_CHAPTER, + 'workStatus' => ThothWork::WORK_STATUS_ACTIVE, + 'fullTitle' => '10. Modification and Enhancement of Consciousness', + 'title' => '10. Modification and Enhancement of Consciousness' + ] + ] + )); + return $mockThothClient; } @@ -310,7 +327,7 @@ public function testCreateNewWork() public function testGetWork() { $expectedThothWork = new ThothWork(); - $expectedThothWork->setId('39e399fb-cd40-461d-97cf-cf7f3a14cc48'); + $expectedThothWork->setWorkId('39e399fb-cd40-461d-97cf-cf7f3a14cc48'); $expectedThothWork->setImprintId('145369a6-916a-4107-ba0f-ce28137659c2'); $expectedThothWork->setWorkType(ThothWork::WORK_TYPE_BOOK_CHAPTER); $expectedThothWork->setWorkStatus(ThothWork::WORK_STATUS_ACTIVE); @@ -318,8 +335,11 @@ public function testGetWork() $expectedThothWork->setFullTitle('10. Modification and Enhancement of Consciousness'); $mockThothClient = $this->setUpMockEnvironment(); + ThothContainer::getInstance()->set('client', function () use ($mockThothClient) { + return $mockThothClient; + }); - $thothWork = $this->workService->get($mockThothClient, '39e399fb-cd40-461d-97cf-cf7f3a14cc48'); + $thothWork = $this->workService->get('39e399fb-cd40-461d-97cf-cf7f3a14cc48'); $this->assertEquals($expectedThothWork, $thothWork); } @@ -329,12 +349,13 @@ public function testRegisterBook() $thothImprintId = 'f02786d4-3bcc-473e-8d43-3da66c7e877c'; $expectedThothBook = new ThothWork(); - $expectedThothBook->setId('74fde3e2-ca4e-4597-bb0c-aee90648f5a5'); + $expectedThothBook->setWorkId('74fde3e2-ca4e-4597-bb0c-aee90648f5a5'); $expectedThothBook->setImprintId($thothImprintId); $expectedThothBook->setWorkType(ThothWork::WORK_TYPE_MONOGRAPH); $expectedThothBook->setWorkStatus(ThothWork::WORK_STATUS_ACTIVE); $expectedThothBook->setTitle('A Designer\'s Log'); $expectedThothBook->setSubtitle('Case Studies in Instructional Design'); + $expectedThothBook->setLongAbstract(''); $expectedThothBook->setFullTitle('A Designer\'s Log: Case Studies in Instructional Design'); $expectedThothBook->setLandingPage('https://omp.publicknowledgeproject.org/index.php/press/catalog/book/999'); $expectedThothBook->setCoverUrl('https://omp.publicknowledgeproject.org/templates/images/book-default.png'); @@ -352,8 +373,11 @@ public function testRegisterBook() $submission->setData('publications', [$publication]); $mockThothClient = $this->setUpMockEnvironment(); + ThothContainer::getInstance()->set('client', function () use ($mockThothClient) { + return $mockThothClient; + }); - $thothBook = $this->workService->registerBook($mockThothClient, $submission, $thothImprintId); + $thothBook = $this->workService->registerBook($submission, $thothImprintId); $this->assertEquals($expectedThothBook, $thothBook); } @@ -362,7 +386,7 @@ public function testRegisterChapter() $thothImprintId = 'f02786d4-3bcc-473e-8d43-3da66c7e877c'; $expectedThothChapter = new ThothWork(); - $expectedThothChapter->setId('74fde3e2-ca4e-4597-bb0c-aee90648f5a5'); + $expectedThothChapter->setWorkId('74fde3e2-ca4e-4597-bb0c-aee90648f5a5'); $expectedThothChapter->setImprintId($thothImprintId); $expectedThothChapter->setWorkType(ThothWork::WORK_TYPE_BOOK_CHAPTER); $expectedThothChapter->setWorkStatus(ThothWork::WORK_STATUS_ACTIVE); @@ -375,8 +399,11 @@ public function testRegisterChapter() $chapter->setData('publicationId', 9999); $mockThothClient = $this->setUpMockEnvironment(); + ThothContainer::getInstance()->set('client', function () use ($mockThothClient) { + return $mockThothClient; + }); - $thothChapter = $this->workService->registerChapter($mockThothClient, $chapter, $thothImprintId); + $thothChapter = $this->workService->registerChapter($chapter, $thothImprintId); $this->assertEquals($expectedThothChapter, $thothChapter); } @@ -386,7 +413,7 @@ public function testRegisterRelation() $relatedWorkId = '7d861db5-22f6-4ef8-abbb-b56ab8397624'; $expectedThothWorkRelation = new ThothWorkRelation(); - $expectedThothWorkRelation->setId('3e587b61-58f1-4064-bf80-e40e5c924d27'); + $expectedThothWorkRelation->setWorkRelationId('3e587b61-58f1-4064-bf80-e40e5c924d27'); $expectedThothWorkRelation->setRelatorWorkId('74fde3e2-ca4e-4597-bb0c-aee90648f5a5'); $expectedThothWorkRelation->setRelatedWorkId($relatedWorkId); $expectedThothWorkRelation->setRelationType(ThothWorkRelation::RELATION_TYPE_IS_CHILD_OF); @@ -398,9 +425,11 @@ public function testRegisterRelation() $chapter->setSequence(4); $mockThothClient = $this->setUpMockEnvironment(); + ThothContainer::getInstance()->set('client', function () use ($mockThothClient) { + return $mockThothClient; + }); $thothWorkRelation = $this->workService->registerWorkRelation( - $mockThothClient, $chapter, $thothImprintId, $relatedWorkId @@ -411,12 +440,13 @@ public function testRegisterRelation() public function testUpdateBook() { $thothWork = new ThothWork(); - $thothWork->setId('39e399fb-cd40-461d-97cf-cf7f3a14cc48'); + $thothWork->setWorkId('39e399fb-cd40-461d-97cf-cf7f3a14cc48'); $thothWork->setImprintId('145369a6-916a-4107-ba0f-ce28137659c2'); $thothWork->setWorkType(ThothWork::WORK_TYPE_EDITED_BOOK); $thothWork->setWorkStatus(ThothWork::WORK_STATUS_ACTIVE); $thothWork->setFullTitle('Cuba : Restructuring the Economy'); $thothWork->setTitle('Cuba : Restructuring the Economy'); + $thothWork->setLongAbstract(''); $thothWork->setLandingPage('https://omp.publicknowledgeproject.org/index.php/press/catalog/book'); $thothWork->setCoverUrl('https://omp.publicknowledgeproject.org/templates/images/book-default.png'); @@ -425,6 +455,9 @@ public function testUpdateBook() $expectedThothWork->setSubtitle('A Contribution to the Debate'); $mockThothClient = $this->setUpMockEnvironment(); + ThothContainer::getInstance()->set('client', function () use ($mockThothClient) { + return $mockThothClient; + }); $publication = new Publication(); $publication->setData('title', 'Cuba : Restructuring the Economy', 'en_US'); @@ -434,7 +467,6 @@ public function testUpdateBook() $thothWorkId = '49e58788-95d6-427f-8726-c24f5b15484c'; $updatedThothWork = $this->workService->updateBook( - $mockThothClient, $thothWorkId, $submission, $publication diff --git a/tests/classes/services/queryBuilders/ThothWorkQueryBuilderTest.php b/tests/classes/services/queryBuilders/ThothWorkQueryBuilderTest.php deleted file mode 100644 index 25a599d..0000000 --- a/tests/classes/services/queryBuilders/ThothWorkQueryBuilderTest.php +++ /dev/null @@ -1,209 +0,0 @@ -expectedFields = [ - 'workId', - 'workType', - 'workStatus', - 'fullTitle', - 'title', - 'subtitle', - 'edition', - 'imprintId', - 'doi', - 'publicationDate', - 'pageCount', - 'license', - 'copyrightHolder', - 'landingPage', - 'longAbstract', - 'coverUrl' - ]; - - $json = file_get_contents(__DIR__ . '/../../../fixtures/workWithContributions.json'); - $mockThothClient = $this->getMockBuilder(ThothClient::class) - ->setMethods([ - 'query', - ]) - ->getMock(); - $mockThothClient->expects($this->any()) - ->method('query') - ->will($this->returnValue(json_decode($json, true)['data']['work'])); - - $this->queryBuilder = new ThothWorkQueryBuilder($mockThothClient); - } - - protected function tearDown(): void - { - unset($this->queryBuilder); - parent::tearDown(); - } - - public function testIncludeContributionsToQuery() - { - $this->expectedFields['contributions'] = [ - 'contributionId', - 'workId', - 'contributorId', - 'contributionType', - 'mainContribution', - 'contributionOrdinal', - 'firstName', - 'lastName', - 'fullName', - 'biography' - ]; - $this->queryBuilder->includeContributions(); - $properties = $this->getProperties($this->queryBuilder); - $this->assertEquals($this->expectedFields, $properties['fields']); - - $this->expectedFields['contributions']['contributor'] = [ - 'contributorId', - 'firstName', - 'lastName', - 'fullName', - 'orcid', - 'website' - ]; - $this->queryBuilder->includeContributions(true); - $properties = $this->getProperties($this->queryBuilder); - $this->assertEquals($this->expectedFields, $properties['fields']); - - $this->expectedFields['contributions']['affiliations'] = [ - 'affiliationId', - 'contributionId', - 'institutionId', - 'affiliationOrdinal' - ]; - $this->queryBuilder->includeContributions(true, true); - $properties = $this->getProperties($this->queryBuilder); - $this->assertEquals($this->expectedFields, $properties['fields']); - - unset($this->expectedFields['contributions']['contributor']); - $this->queryBuilder->includeContributions(false, true); - $properties = $this->getProperties($this->queryBuilder); - $this->assertEquals($this->expectedFields, $properties['fields']); - } - - public function testIncludeRelationsToQuery() - { - $this->expectedFields['relations'] = [ - 'workRelationId', - 'relatorWorkId', - 'relatedWorkId', - 'relationType', - 'relationOrdinal' - ]; - $this->queryBuilder->includeRelations(); - $properties = $this->getProperties($this->queryBuilder); - $this->assertEquals($this->expectedFields, $properties['fields']); - - $this->expectedFields['relations']['relatedWork'] = [ - 'workId', - 'workType', - 'workStatus', - 'fullTitle', - 'title', - 'subtitle', - 'edition', - 'imprintId', - 'doi', - 'publicationDate', - 'pageCount', - 'license', - 'copyrightHolder', - 'landingPage', - 'longAbstract', - 'coverUrl' - ]; - $this->queryBuilder->includeRelations(true); - $properties = $this->getProperties($this->queryBuilder); - $this->assertEquals($this->expectedFields, $properties['fields']); - } - - public function testGetWorkWithQuery() - { - $expectedWorkData = [ - 'workId' => '84121955-b70f-47c2-ac02-f0171581680a', - 'workType' => 'MONOGRAPH', - 'workStatus' => 'ACTIVE', - 'fullTitle' => 'A ação mímica: princípios e poéticas da mímica corporal dramática de Étienne Decroux', - 'title' => 'A ação mímica', - 'subtitle' => 'princípios e poéticas da mímica corporal dramática de Étienne Decroux', - 'edition' => 1, - 'imprintId' => '5cf0b304-6ee5-45c7-a89d-53cd135d8d2b', - 'doi' => 'https://doi.org/10.7476/9786556303727', - 'publicationDate' => '2020-01-01', - 'pageCount' => 175, - 'license' => 'https://creativecommons.org/licenses/by/4.0/', - 'copyrightHolder' => null, - 'landingPage' => 'https://books.scielo.org/id/rzt8g', - 'longAbstract' => 'O que é mímica corporal dramática? Quais os seus princípios e fundamentos técnicos? ' . - 'Qual a sua aplicabilidade em projetos artísticos contemporâneos? ' . - 'Para discutir essas e outras questões, o livro apresenta alguns aspectos históricos, ' . - 'técnicos e poéticos dessa arte e aborda as controvertidas afirmações acerca das restrições de ' . - 'sua aplicação na contemporaneidade. A obra pretende fornecer um guia de estudos prático-teóricos ' . - 'para os interessados na Mímica Corporal Dramática de Étienne Decroux, como elemento complementar à ' . - 'prática nas salas de ensaio e no exercício cotidiano de artistas da cena.', - 'coverUrl' => 'https://books.scielo.org/id/rzt8g/cover/cover.jpeg', - 'contributions' => [ - [ - 'contributionId' => '5aa9d900-36fb-4ba8-83a5-ffd8db9a071a', - 'contributorId' => '2a3c6871-8ef9-433b-8ac7-5e4c5f976c1f', - 'workId' => '84121955-b70f-47c2-ac02-f0171581680a', - 'contributionType' => 'AUTHOR', - 'mainContribution' => true, - 'biography' => null, - 'firstName' => 'George', - 'lastName' => 'Mascarenhas', - 'fullName' => 'George Mascarenhas', - 'contributionOrdinal' => 1 - ] - ] - ]; - $workData = $this->queryBuilder->get('84121955-b70f-47c2-ac02-f0171581680a'); - - $this->assertEquals($expectedWorkData, $workData); - } - - private function getProperties($object) - { - $reflector = new ReflectionClass($object); - $properties = $reflector->getProperties(ReflectionProperty::IS_PRIVATE); - - $attributes = []; - foreach ($properties as $property) { - $property->setAccessible(true); - $value = $property->getValue($object); - $attributes[$property->getName()] = $value; - } - - return $attributes; - } -} diff --git a/tests/fixtures/accountDetails.json b/tests/fixtures/accountDetails.json deleted file mode 100644 index 2654993..0000000 --- a/tests/fixtures/accountDetails.json +++ /dev/null @@ -1 +0,0 @@ -{"accountId":"49e98000-8bd5-4959-8d4a-0b0754afe5d4","name":"Thoth","surname":"Publisher","email":"thoth_publisher@mailinator.com","token":"xxxxxyyyyyzzzzz","createdAt":"2024-07-15T19:37:23.215914Z","updatedAt":"2024-09-03T19:04:44.266144Z","resourceAccess":{"isSuperuser":true,"isBot":false,"linkedPublishers":[{"publisherId":"7e0435ab-a0a6-4dca-8503-ffc1dcaa9f9d","isAdmin":true}]}} \ No newline at end of file diff --git a/tests/fixtures/contribution.json b/tests/fixtures/contribution.json deleted file mode 100644 index 736876c..0000000 --- a/tests/fixtures/contribution.json +++ /dev/null @@ -1 +0,0 @@ -{"data":{"contribution":{"contributionId":"f6b4b1ba-6849-42f0-b43e-fff5c6693738","contributorId":"70a8a8c1-06f7-4adf-bfec-9421a6a70813","workId":"473fcddc-23ee-46a4-8ffa-afa5020ac540","contributionType":"AUTHOR","mainContribution":true,"biography":"Paula Bialski is junior professor of digital sociality at Leuphana University Lüneburg. She is an ethnographer of new media in everyday life and the author of Becoming Intimately Mobile.","firstName":"Paula","lastName":"Bialski","fullName":"Paula Bialski","contributionOrdinal":1}}} \ No newline at end of file diff --git a/tests/fixtures/contributions.json b/tests/fixtures/contributions.json deleted file mode 100644 index e5f387f..0000000 --- a/tests/fixtures/contributions.json +++ /dev/null @@ -1 +0,0 @@ -{"data":{"contributions":[{"contributionId":"6a132206-62f9-43ca-a05b-32e534eaf11a","contributorId":"c165d8d5-f8e1-43a3-ad46-9c999841ab12","workId":"2566ed3d-3df1-4e56-a7dc-455ecf7d3a4b","contributionType":"AUTHOR","mainContribution":true,"biography":"(7 December 1937 - 30 June 2021) was a British historian, senior research fellow at the Institute of English Studies, School of Advanced Study, University of London.","firstName":"William","lastName":"St Clair","fullName":"William St Clair","contributionOrdinal":1}]}} \ No newline at end of file diff --git a/tests/fixtures/contributor.json b/tests/fixtures/contributor.json deleted file mode 100644 index 15f2a1e..0000000 --- a/tests/fixtures/contributor.json +++ /dev/null @@ -1 +0,0 @@ -{"data": {"contributor": {"contributorId": "e8def8cf-0dfe-4da9-b7fa-f77e7aec7524","fullName": "Martin Paul Eve","lastName": "Eve","firstName": "Martin Paul","orcid": "https://orcid.org/0000-0002-5589-8511","website": "https://eve.gd/"}}} \ No newline at end of file diff --git a/tests/fixtures/contributors.json b/tests/fixtures/contributors.json deleted file mode 100644 index edb7156..0000000 --- a/tests/fixtures/contributors.json +++ /dev/null @@ -1 +0,0 @@ -{"data": {"contributors": [{"contributorId": "fd1ea3ac-bb47-4a19-a743-5c2c38a400bc","firstName": "Ádám","lastName": "Bethlenfalvy","fullName": "Ádám Bethlenfalvy","orcid": "https://orcid.org/0000-0002-4251-8161","website": "https://www.linkedin.com/in/adam-bethlenfalvy-31b18489/"}]}} \ No newline at end of file diff --git a/tests/fixtures/imprint.json b/tests/fixtures/imprint.json deleted file mode 100644 index 4cf6a26..0000000 --- a/tests/fixtures/imprint.json +++ /dev/null @@ -1 +0,0 @@ -{"data":{"imprint":{"imprintId":"5078b33c-5b3f-48bf-bf37-ced6b02beb7c","publisherId":"4ab3bec2-c491-46d4-8731-47a5d9b33cc5","imprintName":"mediastudies.press","imprintUrl":"https://www.mediastudies.press/","crossmarkDoi":"https://doi.org/10.33333/87654321"}}} \ No newline at end of file diff --git a/tests/fixtures/imprints.json b/tests/fixtures/imprints.json deleted file mode 100644 index d5760e8..0000000 --- a/tests/fixtures/imprints.json +++ /dev/null @@ -1 +0,0 @@ -{"data":{"imprints":[{"imprintId":"8bf133ee-e6d0-4a5f-981b-fda73bcc389c","publisherId":"7ec3811c-667b-419e-b96c-a726acac610c","imprintName":"Edinburgh Diamond","imprintUrl":"https://books.ed.ac.uk/edinburgh-diamond/","crossmarkDoi":"https://doi.org/10.12345/11122233"}]}} \ No newline at end of file diff --git a/tests/fixtures/institution.json b/tests/fixtures/institution.json deleted file mode 100644 index d1ff64c..0000000 --- a/tests/fixtures/institution.json +++ /dev/null @@ -1 +0,0 @@ -{"data":{"institution":{"institutionId":"6e451aef-e496-4730-ac86-9f60d8ef4c55","institutionName":"National Science Foundation","institutionDoi":"https://doi.org/10.13039/100000001","countryCode":"USA","ror":"https://ror.org/021nxhr62"}}} \ No newline at end of file diff --git a/tests/fixtures/institutions.json b/tests/fixtures/institutions.json deleted file mode 100644 index 50e89d5..0000000 --- a/tests/fixtures/institutions.json +++ /dev/null @@ -1 +0,0 @@ -{"data":{"institutions":[{"institutionId":"6302c2bb-8e89-4d9a-801a-16b2329fd493","institutionName":"Arctic Sciences","institutionDoi":"https://doi.org/10.13039/100000163","countryCode":"USA","ror":"https://ror.org/02trddg58"}]}} \ No newline at end of file diff --git a/tests/fixtures/publisher.json b/tests/fixtures/publisher.json deleted file mode 100644 index 511001a..0000000 --- a/tests/fixtures/publisher.json +++ /dev/null @@ -1 +0,0 @@ -{"data":{"publisher":{"publisherId":"d2459c17-ae6c-4179-a0ec-9aebd4c2d0be","publisherName":"Editorial Universidad del Rosario","publisherUrl":"https://editorial.urosario.edu.co/","publisherShortname":"Editorial UR"}}} \ No newline at end of file diff --git a/tests/fixtures/publishers.json b/tests/fixtures/publishers.json deleted file mode 100644 index db203d5..0000000 --- a/tests/fixtures/publishers.json +++ /dev/null @@ -1 +0,0 @@ -{"data":{"publishers":[{"publisherId":"f2229e70-e973-4e89-b60f-1055fa3d7505","publisherName":"University of Westminster Press","publisherShortname":"UWP","publisherUrl":"https://www.uwestminsterpress.co.uk/"}]}} \ No newline at end of file diff --git a/tests/fixtures/work.json b/tests/fixtures/work.json deleted file mode 100644 index 8c1de49..0000000 --- a/tests/fixtures/work.json +++ /dev/null @@ -1 +0,0 @@ -{"data":{"work":{"workId":"743ada7a-1d19-4968-b5e4-6a7656d48f02","workType":"MONOGRAPH","workStatus":"ACTIVE","fullTitle":"10necessárias falas: cidade, arquitetura e urbanismo","title":"10necessárias falas","subtitle":"cidade, arquitetura e urbanismo","edition":1,"imprintId":"5cf0b304-6ee5-45c7-a89d-53cd135d8d2b","doi":"https://doi.org/10.7476/9788523211516","publicationDate":"2010-01-01","pageCount":252,"license":"https://creativecommons.org/licenses/by/4.0/","copyrightHolder":null,"landingPage":"https://books.scielo.org/id/zhjcx","longAbstract":"10necessárias falas: Cidade, Arquitetura e Urbanismo consiste em uma coletânea de ensaios acerca de planejamento, arquitetura e urbanismo, estabelecendo relações de totalidade e fragmentos, expondo ideias e percepções do autor, algumas ainda provisórias e abertas ao diálogo com os leitores.","coverUrl":"https://books.scielo.org/id/zhjcx/cover/cover.jpeg"}}} \ No newline at end of file diff --git a/tests/fixtures/workWithContributions.json b/tests/fixtures/workWithContributions.json deleted file mode 100644 index d12d083..0000000 --- a/tests/fixtures/workWithContributions.json +++ /dev/null @@ -1 +0,0 @@ -{"data":{"work":{"workId":"84121955-b70f-47c2-ac02-f0171581680a","workType":"MONOGRAPH","workStatus":"ACTIVE","fullTitle":"A ação mímica: princípios e poéticas da mímica corporal dramática de Étienne Decroux","title":"A ação mímica","subtitle":"princípios e poéticas da mímica corporal dramática de Étienne Decroux","edition":1,"imprintId":"5cf0b304-6ee5-45c7-a89d-53cd135d8d2b","doi":"https://doi.org/10.7476/9786556303727","publicationDate":"2020-01-01","pageCount":175,"license":"https://creativecommons.org/licenses/by/4.0/","copyrightHolder":null,"landingPage":"https://books.scielo.org/id/rzt8g","longAbstract":"O que é mímica corporal dramática? Quais os seus princípios e fundamentos técnicos? Qual a sua aplicabilidade em projetos artísticos contemporâneos? Para discutir essas e outras questões, o livro apresenta alguns aspectos históricos, técnicos e poéticos dessa arte e aborda as controvertidas afirmações acerca das restrições de sua aplicação na contemporaneidade. A obra pretende fornecer um guia de estudos prático-teóricos para os interessados na Mímica Corporal Dramática de Étienne Decroux, como elemento complementar à prática nas salas de ensaio e no exercício cotidiano de artistas da cena.","coverUrl":"https://books.scielo.org/id/rzt8g/cover/cover.jpeg","contributions":[{"contributionId":"5aa9d900-36fb-4ba8-83a5-ffd8db9a071a","contributorId":"2a3c6871-8ef9-433b-8ac7-5e4c5f976c1f","workId":"84121955-b70f-47c2-ac02-f0171581680a","contributionType":"AUTHOR","mainContribution":true,"biography":null,"firstName":"George","lastName":"Mascarenhas","fullName":"George Mascarenhas","contributionOrdinal":1}]}}} \ No newline at end of file diff --git a/tests/thoth/ThothAccountTest.php b/tests/thoth/ThothAccountTest.php deleted file mode 100644 index ada32df..0000000 --- a/tests/thoth/ThothAccountTest.php +++ /dev/null @@ -1,101 +0,0 @@ - $mockHandler]); - - $account = new ThothAccount( - 'https://api.thoth.test.pub', - $guzzleClient, - ); - $token = $account->getToken('johndoe@mailinator.com', 'secret123'); - - $this->assertEquals('xxxxx.yyyyy.zzzzz', $token); - } - - public function testGetTokenWithInvalidCredentials() - { - $this->expectException(ThothException::class); - $this->expectExceptionCode(401); - $this->expectExceptionMessage('Failed to send the request to Thoth: Invalid credentials'); - - $mockHandler = new MockHandler([ - new RequestException( - 'Invalid credentials', - new Request('POST', 'https://api.thoth.test.pub/account/login'), - new Response(401, [], 'Invalid credentials') - ) - ]); - $guzzleClient = new Client(['handler' => $mockHandler]); - - $account = new ThothAccount( - 'https://api.thoth.test.pub', - $guzzleClient, - ); - $token = $account->getToken('botuser@mailinator.com', 'wrong_password'); - } - - public function testGetAccountDetails() - { - $expectedAccountDetails = [ - 'accountId' => '49e98000-8bd5-4959-8d4a-0b0754afe5d4', - 'name' => 'Thoth', - 'surname' => 'Publisher', - 'email' => 'thoth_publisher@mailinator.com', - 'token' => 'xxxxxyyyyyzzzzz', - 'createdAt' => '2024-07-15T19:37:23.215914Z', - 'updatedAt' => '2024-09-03T19:04:44.266144Z', - 'resourceAccess' => [ - 'isSuperuser' => true, - 'isBot' => false, - 'linkedPublishers' => [ - [ - 'publisherId' => '7e0435ab-a0a6-4dca-8503-ffc1dcaa9f9d', - 'isAdmin' => true - ] - ] - ] - ]; - - $mockHandler = new MockHandler([ - new Response(200, [], file_get_contents(__DIR__ . '/../fixtures/accountDetails.json')), - ]); - $guzzleClient = new Client(['handler' => $mockHandler]); - - $account = new ThothAccount( - 'https://api.thoth.test.pub', - $guzzleClient, - ); - $details = $account->getDetails('xxxxxyyyyyzzzzz'); - - $this->assertEquals($expectedAccountDetails, $details); - } -} diff --git a/tests/thoth/ThothClientTest.php b/tests/thoth/ThothClientTest.php deleted file mode 100644 index 82e496e..0000000 --- a/tests/thoth/ThothClientTest.php +++ /dev/null @@ -1,672 +0,0 @@ -fixturesPath = __DIR__ . '/../fixtures/'; - } - - protected function tearDown(): void - { - unset($this->fixturesPath); - parent::tearDown(); - } - - public function testLoginWithInvalidCredentials() - { - $mockHandler = new MockHandler([ - new RequestException( - 'Client error', - new Request('POST', 'https://api.thoth.test.pub/account/login'), - new Response( - 401, - [], - 'Invalid credentials.' - ) - ) - ]); - $guzzleClient = new Client(['handler' => $mockHandler]); - - $this->expectException(ThothException::class); - $this->expectExceptionCode(401); - $this->expectExceptionMessage('Failed to send the request to Thoth: Invalid credentials.'); - - $thothClient = new ThothClient(true, $guzzleClient); - $thothClient->login('user72581@mailinator.com', 'uys9ag9s'); - } - - public function testGetLinkedPublishers() - { - $expectedLinkedPublishers = [ - [ - 'publisherId' => '7e0435ab-a0a6-4dca-8503-ffc1dcaa9f9d', - 'isAdmin' => true - ] - ]; - - $mock = new MockHandler([ - new Response( - 200, - [], - file_get_contents($this->fixturesPath . 'accountDetails.json') - ) - ]); - $handlerStack = HandlerStack::create($mock); - $httpClient = new Client(['handler' => $handlerStack]); - - $client = new ThothClient(true, $httpClient); - $linkedPublishers = $client->linkedPublishers(); - - $this->assertEquals($expectedLinkedPublishers, $linkedPublishers); - } - - public function testCreateAffiliation() - { - $thothAffiliation = new ThothAffiliation(); - - $mock = new MockHandler([ - new Response( - 200, - [], - '{"data":{"createAffiliation":{"affiliationId":"1c6e252c-9fb3-404e-ac0a-1e03cd66aa70"}}}' - ) - ]); - $handlerStack = HandlerStack::create($mock); - $httpClient = new Client(['handler' => $handlerStack]); - - $client = new ThothClient(true, $httpClient); - $thothAffiliationId = $client->createAffiliation($thothAffiliation); - - $this->assertEquals('1c6e252c-9fb3-404e-ac0a-1e03cd66aa70', $thothAffiliationId); - } - - public function testWorkCreation() - { - $work = new ThothWork(); - - $mock = new MockHandler([ - new Response( - 200, - [], - '{"data":{"createWork":{"workId":"62933c17-7f40-46af-84ab-b563ac4ac448"}}}' - ) - ]); - $handlerStack = HandlerStack::create($mock); - $httpClient = new Client(['handler' => $handlerStack]); - - $client = new ThothClient(true, $httpClient); - $workId = $client->createWork($work); - - $this->assertEquals('62933c17-7f40-46af-84ab-b563ac4ac448', $workId); - } - - public function testContributorCreation() - { - $contributor = new ThothContributor(); - - $mock = new MockHandler([ - new Response( - 200, - [], - '{"data":{"createContributor":{"contributorId":"454d55ec-6c4c-42b9-bbf9-fa08b70d7f1d"}}}' - ) - ]); - $handlerStack = HandlerStack::create($mock); - $httpClient = new Client(['handler' => $handlerStack]); - - $client = new ThothClient(true, $httpClient); - $contributorId = $client->createContributor($contributor); - - $this->assertEquals('454d55ec-6c4c-42b9-bbf9-fa08b70d7f1d', $contributorId); - } - - public function testContributionCreation() - { - $contribution = new ThothContribution(); - - $mock = new MockHandler([ - new Response( - 200, - [], - '{"data":{"createContribution":{"contributionId":"bd59feee-53bd-403d-a1a9-db01c0edf10b"}}}' - ) - ]); - $handlerStack = HandlerStack::create($mock); - $httpClient = new Client(['handler' => $handlerStack]); - - $client = new ThothClient(true, $httpClient); - $contributionId = $client->createContribution($contribution); - - $this->assertEquals('bd59feee-53bd-403d-a1a9-db01c0edf10b', $contributionId); - } - - public function testRelationCreation() - { - $workRelation = new ThothWorkRelation(); - - $mock = new MockHandler([ - new Response( - 200, - [], - '{"data":{"createWorkRelation":{"workRelationId":"07253e79-e02f-4350-b4b5-e5fd27866ee2"}}}' - ) - ]); - $handlerStack = HandlerStack::create($mock); - $httpClient = new Client(['handler' => $handlerStack]); - - $client = new ThothClient(true, $httpClient); - $workRelationId = $client->createWorkRelation($workRelation); - - $this->assertEquals('07253e79-e02f-4350-b4b5-e5fd27866ee2', $workRelationId); - } - - public function testPublicationCreation() - { - $publication = new ThothPublication(); - - $mock = new MockHandler([ - new Response( - 200, - [], - '{"data":{"createPublication":{"publicationId":"4f51514b-5d45-42fc-a757-185cd5cee7b1"}}}' - ) - ]); - $handlerStack = HandlerStack::create($mock); - $httpClient = new Client(['handler' => $handlerStack]); - - $client = new ThothClient(true, $httpClient); - $publicationId = $client->createPublication($publication); - - $this->assertEquals('4f51514b-5d45-42fc-a757-185cd5cee7b1', $publicationId); - } - - public function testLocationCreation() - { - $location = new ThothLocation(); - - $mock = new MockHandler([ - new Response( - 200, - [], - '{"data":{"createLocation":{"locationId":"03b0367d-bba3-4e26-846a-4c36d3920db2"}}}' - ) - ]); - $handlerStack = HandlerStack::create($mock); - $httpClient = new Client(['handler' => $handlerStack]); - - $client = new ThothClient(true, $httpClient); - $locationId = $client->createLocation($location); - - $this->assertEquals('03b0367d-bba3-4e26-846a-4c36d3920db2', $locationId); - } - - public function testSubjectCreation() - { - $subject = new ThothSubject(); - - $mock = new MockHandler([ - new Response( - 200, - [], - '{"data":{"createSubject":{"subjectId":"279b9910-38bf-4742-a7ae-cfd9eeb10bf8"}}}' - ) - ]); - $handlerStack = HandlerStack::create($mock); - $httpClient = new Client(['handler' => $handlerStack]); - - $client = new ThothClient(true, $httpClient); - $subjectId = $client->createSubject($subject); - - $this->assertEquals('279b9910-38bf-4742-a7ae-cfd9eeb10bf8', $subjectId); - } - - public function testLanguageCreation() - { - $language = new ThothLanguage(); - - $mock = new MockHandler([ - new Response( - 200, - [], - '{"data":{"createLanguage":{"languageId":"4cfdf70d-cd8c-41a5-a5e2-356a2ff2f37f"}}}' - ) - ]); - $handlerStack = HandlerStack::create($mock); - $httpClient = new Client(['handler' => $handlerStack]); - - $client = new ThothClient(true, $httpClient); - $languageId = $client->createLanguage($language); - - $this->assertEquals('4cfdf70d-cd8c-41a5-a5e2-356a2ff2f37f', $languageId); - } - - public function testReferenceCreation() - { - $reference = new ThothReference(); - - $mock = new MockHandler([ - new Response( - 200, - [], - '{"data":{"createReference":{"referenceId":"56338ed3-d2a9-4ef4-9afc-303d63be719f"}}}' - ) - ]); - $handlerStack = HandlerStack::create($mock); - $httpClient = new Client(['handler' => $handlerStack]); - - $client = new ThothClient(true, $httpClient); - $referenceId = $client->createReference($reference); - - $this->assertEquals('56338ed3-d2a9-4ef4-9afc-303d63be719f', $referenceId); - } - - public function testGetContribution() - { - $contributionId = 'f6b4b1ba-6849-42f0-b43e-fff5c6693738'; - - $expectedContribution = [ - 'contributionId' => $contributionId, - 'contributorId' => '70a8a8c1-06f7-4adf-bfec-9421a6a70813', - 'workId' => '473fcddc-23ee-46a4-8ffa-afa5020ac540', - 'contributionType' => 'AUTHOR', - 'mainContribution' => true, - 'biography' => 'Paula Bialski is junior professor of digital sociality at Leuphana University Lüneburg. ' . - 'She is an ethnographer of new media in everyday life and the author of Becoming Intimately Mobile.', - 'firstName' => 'Paula', - 'lastName' => 'Bialski', - 'fullName' => 'Paula Bialski', - 'contributionOrdinal' => 1 - ]; - - $mock = new MockHandler([ - new Response( - 200, - [], - file_get_contents($this->fixturesPath . 'contribution.json') - ) - ]); - $handlerStack = HandlerStack::create($mock); - $httpClient = new Client(['handler' => $handlerStack]); - - $client = new ThothClient(true, $httpClient); - $contribution = $client->contribution($contributionId); - - $this->assertEquals($expectedContribution, $contribution); - } - - public function testGetContributions() - { - $contributionId = '6a132206-62f9-43ca-a05b-32e534eaf11a'; - - $expectedContributions = [ - [ - 'contributionId' => $contributionId, - 'contributorId' => 'c165d8d5-f8e1-43a3-ad46-9c999841ab12', - 'workId' => '2566ed3d-3df1-4e56-a7dc-455ecf7d3a4b', - 'contributionType' => 'AUTHOR', - 'mainContribution' => true, - 'biography' => '(7 December 1937 - 30 June 2021) was a British historian, senior research fellow at ' . - 'the Institute of English Studies, School of Advanced Study, University of London.', - 'firstName' => 'William', - 'lastName' => 'St Clair', - 'fullName' => 'William St Clair', - 'contributionOrdinal' => 1 - ] - ]; - - $mock = new MockHandler([ - new Response( - 200, - [], - file_get_contents($this->fixturesPath . 'contributions.json') - ) - ]); - $handlerStack = HandlerStack::create($mock); - $httpClient = new Client(['handler' => $handlerStack]); - - $client = new ThothClient(true, $httpClient); - $contributions = $client->contributions(); - - $this->assertEquals($expectedContributions, $contributions); - } - - public function testGetContributor() - { - $contributorId = 'e8def8cf-0dfe-4da9-b7fa-f77e7aec7524'; - - $expectedContributor = [ - 'contributorId' => $contributorId, - 'firstName' => 'Martin Paul', - 'lastName' => 'Eve', - 'fullName' => 'Martin Paul Eve', - 'orcid' => 'https://orcid.org/0000-0002-5589-8511', - 'website' => 'https://eve.gd/' - ]; - - $mock = new MockHandler([ - new Response( - 200, - [], - file_get_contents($this->fixturesPath . 'contributor.json') - ) - ]); - $handlerStack = HandlerStack::create($mock); - $httpClient = new Client(['handler' => $handlerStack]); - - $client = new ThothClient(true, $httpClient); - $contributor = $client->contributor($contributorId); - - $this->assertEquals($expectedContributor, $contributor); - } - - public function testGetContributors() - { - $expectedContributors = [ - [ - 'contributorId' => 'fd1ea3ac-bb47-4a19-a743-5c2c38a400bc', - 'firstName' => 'Ádám', - 'lastName' => 'Bethlenfalvy', - 'fullName' => 'Ádám Bethlenfalvy', - 'orcid' => 'https://orcid.org/0000-0002-4251-8161', - 'website' => 'https://www.linkedin.com/in/adam-bethlenfalvy-31b18489/' - ] - ]; - - $mock = new MockHandler([ - new Response( - 200, - [], - file_get_contents($this->fixturesPath . 'contributors.json') - ) - ]); - $handlerStack = HandlerStack::create($mock); - $httpClient = new Client(['handler' => $handlerStack]); - - $client = new ThothClient(true, $httpClient); - $contributors = $client->contributors(); - - $this->assertEquals($expectedContributors, $contributors); - } - - public function testGetInstitution() - { - $institutionId = '6e451aef-e496-4730-ac86-9f60d8ef4c55'; - - $expectedInstitution = [ - 'institutionId' => $institutionId, - 'institutionName' => 'National Science Foundation', - 'institutionDoi' => 'https://doi.org/10.13039/100000001', - 'countryCode' => 'USA', - 'ror' => 'https://ror.org/021nxhr62' - ]; - - $mock = new MockHandler([ - new Response( - 200, - [], - file_get_contents($this->fixturesPath . 'institution.json') - ) - ]); - $handlerStack = HandlerStack::create($mock); - $httpClient = new Client(['handler' => $handlerStack]); - - $client = new ThothClient(true, $httpClient); - $institution = $client->institution($institutionId); - - $this->assertEquals($expectedInstitution, $institution); - } - - public function testGetInstitutions() - { - $expectedInstitutions = [ - [ - 'institutionId' => '6302c2bb-8e89-4d9a-801a-16b2329fd493', - 'institutionName' => 'Arctic Sciences', - 'institutionDoi' => 'https://doi.org/10.13039/100000163', - 'countryCode' => 'USA', - 'ror' => 'https://ror.org/02trddg58' - ] - ]; - - $mock = new MockHandler([ - new Response( - 200, - [], - file_get_contents($this->fixturesPath . 'institutions.json') - ) - ]); - $handlerStack = HandlerStack::create($mock); - $httpClient = new Client(['handler' => $handlerStack]); - - $client = new ThothClient(true, $httpClient); - $institutions = $client->institutions(); - - $this->assertEquals($expectedInstitutions, $institutions); - } - - public function testGetImprint() - { - $imprintId = '5078b33c-5b3f-48bf-bf37-ced6b02beb7c'; - - $expectedImprint = [ - 'imprintId' => $imprintId, - 'publisherId' => '4ab3bec2-c491-46d4-8731-47a5d9b33cc5', - 'imprintName' => 'mediastudies.press', - 'imprintUrl' => 'https://www.mediastudies.press/', - 'crossmarkDoi' => 'https://doi.org/10.33333/87654321' - ]; - - $mock = new MockHandler([ - new Response( - 200, - [], - file_get_contents($this->fixturesPath . 'imprint.json') - ) - ]); - $handlerStack = HandlerStack::create($mock); - $httpClient = new Client(['handler' => $handlerStack]); - - $client = new ThothClient(true, $httpClient); - $imprint = $client->imprint($imprintId); - - $this->assertEquals($expectedImprint, $imprint); - } - - public function testGetImprints() - { - $expectedImprints = [ - [ - 'imprintId' => '8bf133ee-e6d0-4a5f-981b-fda73bcc389c', - 'publisherId' => '7ec3811c-667b-419e-b96c-a726acac610c', - 'imprintName' => 'Edinburgh Diamond', - 'imprintUrl' => 'https://books.ed.ac.uk/edinburgh-diamond/', - 'crossmarkDoi' => 'https://doi.org/10.12345/11122233' - ] - ]; - - $mock = new MockHandler([ - new Response( - 200, - [], - file_get_contents($this->fixturesPath . 'imprints.json') - ) - ]); - $handlerStack = HandlerStack::create($mock); - $httpClient = new Client(['handler' => $handlerStack]); - - $client = new ThothClient(true, $httpClient); - $imprints = $client->imprints(); - - $this->assertEquals($expectedImprints, $imprints); - } - - public function testGetPublisher() - { - $publisherId = 'd2459c17-ae6c-4179-a0ec-9aebd4c2d0be'; - - $expectedPublisher = [ - 'publisherId' => $publisherId, - 'publisherName' => 'Editorial Universidad del Rosario', - 'publisherShortname' => 'Editorial UR', - 'publisherUrl' => 'https://editorial.urosario.edu.co/' - ]; - - $mock = new MockHandler([ - new Response( - 200, - [], - file_get_contents($this->fixturesPath . 'publisher.json') - ) - ]); - $handlerStack = HandlerStack::create($mock); - $httpClient = new Client(['handler' => $handlerStack]); - - $client = new ThothClient(true, $httpClient); - $publisher = $client->publisher($publisherId); - - $this->assertEquals($expectedPublisher, $publisher); - } - - public function testGetPublishers() - { - $expectedPublishers = [ - [ - 'publisherId' => 'f2229e70-e973-4e89-b60f-1055fa3d7505', - 'publisherName' => 'University of Westminster Press', - 'publisherShortname' => 'UWP', - 'publisherUrl' => 'https://www.uwestminsterpress.co.uk/' - ] - ]; - - $mock = new MockHandler([ - new Response( - 200, - [], - file_get_contents($this->fixturesPath . 'publishers.json') - ) - ]); - $handlerStack = HandlerStack::create($mock); - $httpClient = new Client(['handler' => $handlerStack]); - - $client = new ThothClient(true, $httpClient); - $publishers = $client->publishers(); - - $this->assertEquals($expectedPublishers, $publishers); - } - - public function testGetWork() - { - $workId = 'e0f748b2-984f-45cc-8b9e-13989c31dda4'; - - $expectedWork = [ - 'workId' => '743ada7a-1d19-4968-b5e4-6a7656d48f02', - 'workType' => ThothWork::WORK_TYPE_MONOGRAPH, - 'workStatus' => ThothWork::WORK_STATUS_ACTIVE, - 'fullTitle' => '10necessárias falas: cidade, arquitetura e urbanismo', - 'title' => '10necessárias falas', - 'subtitle' => 'cidade, arquitetura e urbanismo', - 'edition' => 1, - 'imprintId' => '5cf0b304-6ee5-45c7-a89d-53cd135d8d2b', - 'doi' => 'https://doi.org/10.7476/9788523211516', - 'publicationDate' => '2010-01-01', - 'pageCount' => 252, - 'license' => 'https://creativecommons.org/licenses/by/4.0/', - 'copyrightHolder' => null, - 'landingPage' => 'https://books.scielo.org/id/zhjcx', - 'longAbstract' => '10necessárias falas: Cidade, Arquitetura e Urbanismo consiste em uma coletânea de ensaios acerca de planejamento, arquitetura e urbanismo, estabelecendo relações de totalidade e fragmentos, expondo ideias e percepções do autor, algumas ainda provisórias e abertas ao diálogo com os leitores.', - 'coverUrl' => 'https://books.scielo.org/id/zhjcx/cover/cover.jpeg' - ]; - - $mock = new MockHandler([ - new Response( - 200, - [], - file_get_contents($this->fixturesPath . 'work.json') - ) - ]); - $handlerStack = HandlerStack::create($mock); - $httpClient = new Client(['handler' => $handlerStack]); - - $client = new ThothClient(true, $httpClient); - $work = $client->work($workId); - - $this->assertEquals($expectedWork, $work); - } - - public function testUpdateWork() - { - $thothWork = new ThothWork(); - - $mock = new MockHandler([ - new Response( - 200, - [], - '{"data":{"updateWork":{"workId":"ad3b25d6-44f7-4419-9460-4e170c4ec64f"}}}' - ) - ]); - $handlerStack = HandlerStack::create($mock); - $httpClient = new Client(['handler' => $handlerStack]); - - $client = new ThothClient(true, $httpClient); - $thothWorkId = $client->updateWork($thothWork); - - $this->assertEquals('ad3b25d6-44f7-4419-9460-4e170c4ec64f', $thothWorkId); - } - - public function testDeleteContribution() - { - $mock = new MockHandler([ - new Response( - 200, - [], - '{"data":{"deleteContribution":{"contributionId":"819d8d49-6252-49d0-8f87-6b7487a0eecc"}}}' - ) - ]); - $handlerStack = HandlerStack::create($mock); - $httpClient = new Client(['handler' => $handlerStack]); - - $client = new ThothClient(true, $httpClient); - $thothContributionId = $client->deleteContribution('819d8d49-6252-49d0-8f87-6b7487a0eecc'); - - $this->assertEquals('819d8d49-6252-49d0-8f87-6b7487a0eecc', $thothContributionId); - } -} diff --git a/tests/thoth/ThothGraphQLTest.php b/tests/thoth/ThothGraphQLTest.php deleted file mode 100644 index 9fd8c8f..0000000 --- a/tests/thoth/ThothGraphQLTest.php +++ /dev/null @@ -1,144 +0,0 @@ - $handlerStack]); - - $query = ' - mutation { - createContributor( - data: { - firstName: "Abdullah", - lastName: "Mirzoev", - fullName: "Abdullah Mirzoev" - } - ) { - contributorId - } - } - '; - - $thothGraphQL = new ThothGraphQL('https://api.thoth.test.pub/', $httpClient, 'secret_token'); - $returnValue = $thothGraphQL->execute($query); - $this->assertEquals(json_decode($body, true)['data'], $returnValue); - } - - public function testRequestWithError() - { - $mockHandler = new MockHandler([ - new RequestException( - 'Client error', - new Request('POST', 'https://api.thoth.test.pub/graphql'), - new Response( - 400, - [], - '{"errors":[{ - "message":"Invalid value for argument \"data\", expected type \"NewContributor!\"", - "locations":[{"line":4,"column":21}] - }]}' - ) - ) - ]); - $guzzleClient = new Client(['handler' => $mockHandler]); - - $this->expectException(ThothException::class); - $this->expectExceptionCode(400); - $this->expectExceptionMessage( - 'Failed to send the request to Thoth: Invalid value for argument "data", expected type "NewContributor!"' - ); - - $query = ' - mutation { - createContributor( - data: { - givenName: "Abdullah", - "lastName": "Mirzoev", - "fullName": "Abdullah Mirzoev" - } - ) { - contributorId - } - } - '; - - $thothGraphQL = new ThothGraphQL('https://api.thoth.test.pub/', $guzzleClient, 'secret_token'); - $returnValue = $thothGraphQL->execute($query); - } - - public function testResponseWithError() - { - $mockHandler = new MockHandler([ - new RequestException( - 'Client error', - new Request('POST', 'https://api.thoth.test.pub/graphql'), - new Response( - 200, - [], - '{ - "data":null, - "errors":[ - {"message":"Invalid ORCID ID.", - "locations":[{"line":2,"column":17}], - "path":["createContributor"]} - ] - }' - ) - ) - ]); - $guzzleClient = new Client(['handler' => $mockHandler]); - - $this->expectException(ThothException::class); - $this->expectExceptionCode(200); - $this->expectExceptionMessage('Failed to send the request to Thoth: Invalid ORCID ID.'); - - $query = ' - mutation { - createContributor( - data: { - givenName: "Abdullah", - lastName: "Mirzoev", - fullName: "Abdullah Mirzoev", - orcid: "0000-0000-1245-5678" - } - ) { - contributorId - } - } - '; - - $thothGraphQL = new ThothGraphQL('https://api.thoth.test.pub/', $guzzleClient, 'secret_token'); - $returnValue = $thothGraphQL->execute($query); - } -} diff --git a/tests/thoth/ThothMutationTest.php b/tests/thoth/ThothMutationTest.php deleted file mode 100644 index c8c1930..0000000 --- a/tests/thoth/ThothMutationTest.php +++ /dev/null @@ -1,57 +0,0 @@ -setFirstName('Basem'); - $contributor->setLastName('Adi'); - $contributor->setFullName('Basem Adi'); - $contributor->setWebsite('https://sites.google.com/site/basemadi'); - - $thothMutation = new ThothMutation( - 'createContributor', - $contributor->getData(), - $contributor->getReturnValue() - ); - - $body = '{"data":{"createContributor":{"contributorId":"abcd1234-e5f6-g7h8-i9j0-a1b2c3d4e5f6"}}}'; - $mock = new MockHandler([ - new Response(200, [], $body) - ]); - - $handlerStack = HandlerStack::create($mock); - $httpClient = new Client(['handler' => $handlerStack]); - - $graphQl = new ThothGraphQl('https://api.thoth.test.pub/', $httpClient, 'secret_token'); - - $contributorId = $thothMutation->run($graphQl); - - $this->assertEquals(json_decode($body)->data->createContributor->contributorId, $contributorId); - } -} diff --git a/tests/thoth/ThothQueryTest.php b/tests/thoth/ThothQueryTest.php deleted file mode 100644 index 441ab6f..0000000 --- a/tests/thoth/ThothQueryTest.php +++ /dev/null @@ -1,100 +0,0 @@ -prepare(); - - $this->assertEquals($expectedQuery, $query); - } - - public function testExecuteQuery() - { - $expectedContributors = [ - [ - 'contributorId' => 'fd1ea3ac-bb47-4a19-a743-5c2c38a400bc', - 'firstName' => 'Ádám', - 'lastName' => 'Bethlenfalvy', - 'fullName' => 'Ádám Bethlenfalvy', - 'orcid' => 'https://orcid.org/0000-0002-4251-8161', - 'website' => 'https://www.linkedin.com/in/adam-bethlenfalvy-31b18489/' - ] - ]; - - $params = [ - 'limit:100', - 'offset:0' - ]; - - $contributor = new ThothContributor(); - $thothQuery = new ThothQuery('contributors', $params, ThothQueryFields::contributor()); - - $body = file_get_contents(__DIR__ . '/../fixtures/contributors.json'); - $mock = new MockHandler([ - new Response(200, [], $body) - ]); - - $handlerStack = HandlerStack::create($mock); - $httpClient = new Client(['handler' => $handlerStack]); - - $graphql = new ThothGraphQl('https://api.thoth.test.pub/', $httpClient); - $contributors = $thothQuery->run($graphql); - - $this->assertEquals($expectedContributors, $contributors); - } -} diff --git a/tests/thoth/models/ThothAffiliationTest.php b/tests/thoth/models/ThothAffiliationTest.php deleted file mode 100644 index e6fa427..0000000 --- a/tests/thoth/models/ThothAffiliationTest.php +++ /dev/null @@ -1,51 +0,0 @@ -setId('bb4d5b3c-592e-47ed-badc-dcc2d66d2cc1'); - $thothAffiliation->setContributionId('898bb18b-2725-4254-96b4-d3c5f5094ae7'); - $thothAffiliation->setInstitutionId('485e6488-b96e-4b76-aa5f-f6f717eed0b8'); - $thothAffiliation->setAffiliationOrdinal(1); - - $this->assertEquals('bb4d5b3c-592e-47ed-badc-dcc2d66d2cc1', $thothAffiliation->getId()); - $this->assertEquals('898bb18b-2725-4254-96b4-d3c5f5094ae7', $thothAffiliation->getContributionId()); - $this->assertEquals('485e6488-b96e-4b76-aa5f-f6f717eed0b8', $thothAffiliation->getInstitutionId()); - $this->assertEquals(1, $thothAffiliation->getAffiliationOrdinal()); - } - - public function testGetAffiliationData() - { - $thothAffiliation = new ThothAffiliation(); - $thothAffiliation->setId('3266c9b6-3f9a-4675-97dd-78c5f3b10ce9'); - $thothAffiliation->setContributionId('9ce4155d-bf71-4d71-8ac3-36e58161d901'); - $thothAffiliation->setInstitutionId('9674c5e2-6497-48ed-a93e-4c0a5b4f7874'); - $thothAffiliation->setAffiliationOrdinal(1); - - $this->assertEquals([ - 'affiliationId' => '3266c9b6-3f9a-4675-97dd-78c5f3b10ce9', - 'contributionId' => '9ce4155d-bf71-4d71-8ac3-36e58161d901', - 'institutionId' => '9674c5e2-6497-48ed-a93e-4c0a5b4f7874', - 'affiliationOrdinal' => 1 - ], $thothAffiliation->getData()); - } -} diff --git a/tests/thoth/models/ThothContributionTest.php b/tests/thoth/models/ThothContributionTest.php deleted file mode 100644 index 0fa0013..0000000 --- a/tests/thoth/models/ThothContributionTest.php +++ /dev/null @@ -1,87 +0,0 @@ -toString(); - $contribution = new ThothContribution(); - $contribution->setId($uuid); - $contribution->setWorkId('b5c810e1-c847-4553-a24e-9893164d9786'); - $contribution->setContributorId('454d55ec-6c4c-42b9-bbf9-fa08b70d7f1d'); - $contribution->setContributionType(ThothContribution::CONTRIBUTION_TYPE_AUTHOR); - $contribution->setMainContribution(true); - $contribution->setContributionOrdinal(1); - $contribution->setFirstName('Anthony'); - $contribution->setLastName('Williams'); - $contribution->setFullName('Anthony Williams'); - $contribution->setBiography( - 'Anthony Williams is Director of External Communications at the European Bank for ' . - 'Reconstruction and Development (EBRD).' - ); - - $this->assertEquals($uuid, $contribution->getId()); - $this->assertEquals('b5c810e1-c847-4553-a24e-9893164d9786', $contribution->getWorkId()); - $this->assertEquals('454d55ec-6c4c-42b9-bbf9-fa08b70d7f1d', $contribution->getContributorId()); - $this->assertEquals(ThothContribution::CONTRIBUTION_TYPE_AUTHOR, $contribution->getContributionType()); - $this->assertEquals(1, $contribution->getContributionOrdinal()); - $this->assertEquals('Anthony', $contribution->getFirstName()); - $this->assertEquals('Williams', $contribution->getLastName()); - $this->assertEquals('Anthony Williams', $contribution->getFullName()); - $this->assertEquals( - 'Anthony Williams is Director of External Communications at the European Bank for ' . - 'Reconstruction and Development (EBRD).', - $contribution->getBiography() - ); - } - - public function testGetContributionData() - { - $uuid = \Ramsey\Uuid\Uuid::uuid4()->toString(); - $contribution = new ThothContribution(); - $contribution->setId($uuid); - $contribution->setWorkId('e763a10c-1e2b-4b10-84c4-ac3f95236a97'); - $contribution->setContributorId('e1de541c-e84b-4092-941f-dab9b5dac865'); - $contribution->setContributionType(ThothContribution::CONTRIBUTION_TYPE_EDITOR); - $contribution->setMainContribution(false); - $contribution->setContributionOrdinal(1); - $contribution->setFirstName('Thomas'); - $contribution->setLastName('Pringle'); - $contribution->setFullName('Thomas Patrick Pringle'); - $contribution->setBiography( - 'Thomas Pringle is an SSHRC doctoral and presidential fellow at Brown University, ' . - 'where he is a PhD candidate in the Department of Modern Culture and Media.' - ); - - $this->assertEquals([ - 'contributionId' => $uuid, - 'workId' => 'e763a10c-1e2b-4b10-84c4-ac3f95236a97', - 'contributorId' => 'e1de541c-e84b-4092-941f-dab9b5dac865', - 'contributionType' => ThothContribution::CONTRIBUTION_TYPE_EDITOR, - 'mainContribution' => false, - 'contributionOrdinal' => 1, - 'firstName' => 'Thomas', - 'lastName' => 'Pringle', - 'fullName' => 'Thomas Patrick Pringle', - 'biography' => 'Thomas Pringle is an SSHRC doctoral and presidential fellow at Brown University, ' . - 'where he is a PhD candidate in the Department of Modern Culture and Media.' - ], $contribution->getData()); - } -} diff --git a/tests/thoth/models/ThothContributorTest.php b/tests/thoth/models/ThothContributorTest.php deleted file mode 100644 index 377dbba..0000000 --- a/tests/thoth/models/ThothContributorTest.php +++ /dev/null @@ -1,65 +0,0 @@ -toString(); - $contributor = new ThothContributor(); - $contributor->setId($uuid); - $contributor->setFirstName('John'); - $contributor->setLastName('Doe'); - $contributor->setFullName('John Doe'); - $contributor->setOrcid('https://orcid.org/0000-0001-2345-6789'); - $contributor->setWebsite('https://sites.google.com/site/johndoe'); - - $this->assertEquals($uuid, $contributor->getId()); - $this->assertEquals('John', $contributor->getFirstName()); - $this->assertEquals('Doe', $contributor->getLastName()); - $this->assertEquals('John Doe', $contributor->getFullName()); - $this->assertEquals('https://orcid.org/0000-0001-2345-6789', $contributor->getOrcid()); - $this->assertEquals('https://sites.google.com/site/johndoe', $contributor->getWebsite()); - $this->assertEquals('contributorId', $contributor->getReturnValue()); - } - - public function testGetContributorData() - { - $uuid = \Ramsey\Uuid\Uuid::uuid4()->toString(); - $contributor = new ThothContributor(); - $contributor->setId($uuid); - $contributor->setFirstName('Adriana Laura'); - $contributor->setLastName('Massidda'); - $contributor->setFullName('Adriana Laura Massidda'); - $contributor->setOrcid('https://orcid.org/0000-0001-8735-7990'); - $contributor->setWebsite('https://sites.google.com/site/adrianamassidda'); - - $this->assertEquals( - [ - 'contributorId' => $uuid, - 'firstName' => 'Adriana Laura', - 'lastName' => 'Massidda', - 'fullName' => 'Adriana Laura Massidda', - 'orcid' => 'https://orcid.org/0000-0001-8735-7990', - 'website' => 'https://sites.google.com/site/adrianamassidda', - ], - $contributor->getData() - ); - } -} diff --git a/tests/thoth/models/ThothImprintTest.php b/tests/thoth/models/ThothImprintTest.php deleted file mode 100644 index 63de3df..0000000 --- a/tests/thoth/models/ThothImprintTest.php +++ /dev/null @@ -1,55 +0,0 @@ -setId('be4c8448-93c8-4146-8d9c-84d121bc4bec'); - $imprint->setPublisherId('9c41b13c-cecc-4f6a-a151-be4682915ef5'); - $imprint->setImprintName('Tiny Collections'); - $imprint->setImprintUrl('https://punctumbooks.com/imprints/tiny-collections/'); - $imprint->setCrossmarkDoi('https://doi.org/10.55555/12345678'); - - $this->assertEquals('be4c8448-93c8-4146-8d9c-84d121bc4bec', $imprint->getId()); - $this->assertEquals('9c41b13c-cecc-4f6a-a151-be4682915ef5', $imprint->getPublisherId()); - $this->assertEquals('Tiny Collections', $imprint->getImprintName()); - $this->assertEquals('https://punctumbooks.com/imprints/tiny-collections/', $imprint->getImprintUrl()); - $this->assertEquals('https://doi.org/10.55555/12345678', $imprint->getCrossmarkDoi()); - } - - public function testGetImprintData() - { - $imprint = new ThothImprint(); - $imprint->setId('5078b33c-5b3f-48bf-bf37-ced6b02beb7c'); - $imprint->setPublisherId('4ab3bec2-c491-46d4-8731-47a5d9b33cc5'); - $imprint->setImprintName('mediastudies.press'); - $imprint->setImprintUrl('https://www.mediastudies.press/'); - $imprint->setCrossmarkDoi('https://doi.org/10.33333/87654321'); - - $this->assertEquals([ - 'imprintId' => '5078b33c-5b3f-48bf-bf37-ced6b02beb7c', - 'publisherId' => '4ab3bec2-c491-46d4-8731-47a5d9b33cc5', - 'imprintName' => 'mediastudies.press', - 'imprintUrl' => 'https://www.mediastudies.press/', - 'crossmarkDoi' => 'https://doi.org/10.33333/87654321' - ], $imprint->getData()); - } -} diff --git a/tests/thoth/models/ThothInstitutionTest.php b/tests/thoth/models/ThothInstitutionTest.php deleted file mode 100644 index e1c1a90..0000000 --- a/tests/thoth/models/ThothInstitutionTest.php +++ /dev/null @@ -1,53 +0,0 @@ -setId('92937abd-87c4-43eb-bb2d-cd17d3760b1d'); - $institution->setInstitutionName('1675 Foundation'); - $institution->setInstitutionDoi('https://doi.org/10.13039/100001436'); - $institution->setCountryCode('USA'); - $institution->setRor('https://ror.org/04n3dya31'); - - $this->assertEquals('92937abd-87c4-43eb-bb2d-cd17d3760b1d', $institution->getId()); - $this->assertEquals('1675 Foundation', $institution->getInstitutionName()); - $this->assertEquals('https://doi.org/10.13039/100001436', $institution->getInstitutionDoi()); - $this->assertEquals('USA', $institution->getCountryCode()); - $this->assertEquals('https://ror.org/04n3dya31', $institution->getRor()); - } - - public function testGetInstitutionData() - { - $institution = new ThothInstitution(); - $institution->setId('2f292272-21c4-4f97-bd28-e7ed642b1158'); - $institution->setInstitutionName('Zorggroep Meander'); - $institution->setCountryCode('NLD'); - $institution->setRor('https://ror.org/00vtp3850'); - - $this->assertEquals([ - 'institutionId' => '2f292272-21c4-4f97-bd28-e7ed642b1158', - 'institutionName' => 'Zorggroep Meander', - 'countryCode' => 'NLD', - 'ror' => 'https://ror.org/00vtp3850' - ], $institution->getData()); - } -} diff --git a/tests/thoth/models/ThothLanguageTest.php b/tests/thoth/models/ThothLanguageTest.php deleted file mode 100644 index 9241502..0000000 --- a/tests/thoth/models/ThothLanguageTest.php +++ /dev/null @@ -1,55 +0,0 @@ -setId('212aecd9-8b9e-4cc0-8ed7-9766c56b6de2'); - $language->setWorkId('f1963ed9-1b8d-43f7-af89-ee589b6e7116'); - $language->setLanguageCode('ENG'); - $language->setLanguageRelation(ThothLanguage::LANGUAGE_RELATION_ORIGINAL); - $language->setMainLanguage(true); - - $this->assertEquals('212aecd9-8b9e-4cc0-8ed7-9766c56b6de2', $language->getId()); - $this->assertEquals('f1963ed9-1b8d-43f7-af89-ee589b6e7116', $language->getWorkId()); - $this->assertEquals('ENG', $language->getLanguageCode()); - $this->assertEquals(ThothLanguage::LANGUAGE_RELATION_ORIGINAL, $language->getLanguageRelation()); - $this->assertEquals(true, $language->getMainLanguage()); - } - - public function testGetLanguageData() - { - $language = new ThothLanguage(); - $language->setId('1da01129-e259-4ba4-8630-17ca5193d350'); - $language->setWorkId('cc020008-4a84-42fd-af6b-8a3a99aecd4f'); - $language->setLanguageCode('BRA'); - $language->setLanguageRelation(ThothLanguage::LANGUAGE_RELATION_ORIGINAL); - $language->setMainLanguage(true); - - $this->assertEquals([ - 'languageId' => '1da01129-e259-4ba4-8630-17ca5193d350', - 'workId' => 'cc020008-4a84-42fd-af6b-8a3a99aecd4f', - 'languageCode' => 'BRA', - 'languageRelation' => ThothLanguage::LANGUAGE_RELATION_ORIGINAL, - 'mainLanguage' => true - ], $language->getData()); - } -} diff --git a/tests/thoth/models/ThothLocationTest.php b/tests/thoth/models/ThothLocationTest.php deleted file mode 100644 index 1ffba03..0000000 --- a/tests/thoth/models/ThothLocationTest.php +++ /dev/null @@ -1,77 +0,0 @@ -setId('03b0367d-bba3-4e26-846a-4c36d3920db2'); - $location->setPublicationId('8ac3e585-c32a-42d7-bd36-ef42ee397e6e'); - $location->setLandingPage('https://omp.publicknowledgeproject.org/press/catalog/book/23'); - $location->setFullTextUrl('https://omp.publicknowledgeproject.org/press/catalog/view/17'); - $location->setLocationPlatform(ThothLocation::LOCATION_PLATFORM_PUBLISHER_WEBSITE); - $location->setCanonical(true); - - $this->assertEquals( - '03b0367d-bba3-4e26-846a-4c36d3920db2', - $location->getId() - ); - $this->assertEquals( - '8ac3e585-c32a-42d7-bd36-ef42ee397e6e', - $location->getPublicationId() - ); - $this->assertEquals( - 'https://omp.publicknowledgeproject.org/press/catalog/book/23', - $location->getLandingPage() - ); - $this->assertEquals( - 'https://omp.publicknowledgeproject.org/press/catalog/view/17', - $location->getFullTextUrl() - ); - $this->assertEquals( - ThothLocation::LOCATION_PLATFORM_PUBLISHER_WEBSITE, - $location->getLocationPlatform() - ); - $this->assertEquals( - true, - $location->getCanonical() - ); - } - - public function testGetRelationData() - { - $location = new ThothLocation(); - $location->setId('0d9f4a87-8eab-40f1-a25c-6487a0cb9251'); - $location->setPublicationId('7d473e27-8b7a-4623-a853-55e1dffea2dc'); - $location->setLandingPage('https://omp.publicknowledgeproject.org/press/catalog/book/12'); - $location->setFullTextUrl('https://www.bookstore.com/site/books/book34/'); - $location->setLocationPlatform(ThothLocation::LOCATION_PLATFORM_OTHER); - $location->setCanonical(false); - - $this->assertEquals([ - 'locationId' => '0d9f4a87-8eab-40f1-a25c-6487a0cb9251', - 'publicationId' => '7d473e27-8b7a-4623-a853-55e1dffea2dc', - 'landingPage' => 'https://omp.publicknowledgeproject.org/press/catalog/book/12', - 'fullTextUrl' => 'https://www.bookstore.com/site/books/book34/', - 'locationPlatform' => ThothLocation::LOCATION_PLATFORM_OTHER, - 'canonical' => false - ], $location->getData()); - } -} diff --git a/tests/thoth/models/ThothPublicationTest.php b/tests/thoth/models/ThothPublicationTest.php deleted file mode 100644 index e8cc3b8..0000000 --- a/tests/thoth/models/ThothPublicationTest.php +++ /dev/null @@ -1,51 +0,0 @@ -setId('8ac3e585-c32a-42d7-bd36-ef42ee397e6e'); - $publication->setWorkId('003137ea-4fe6-470d-8bd3-f936ad065f3c'); - $publication->setPublicationType(ThothPublication::PUBLICATION_TYPE_PAPERBACK); - $publication->setIsbn('978-1-912656-00-4'); - - $this->assertEquals('8ac3e585-c32a-42d7-bd36-ef42ee397e6e', $publication->getId()); - $this->assertEquals('003137ea-4fe6-470d-8bd3-f936ad065f3c', $publication->getWorkId()); - $this->assertEquals(ThothPublication::PUBLICATION_TYPE_PAPERBACK, $publication->getPublicationType()); - $this->assertEquals('978-1-912656-00-4', $publication->getIsbn()); - } - - public function testGetPublicationData() - { - $publication = new ThothPublication(); - $publication->setId('30ff947b-1bd9-4eef-8b91-753e9b12b935'); - $publication->setWorkId('006571ae-ac0e-4cb0-8a3f-71280aa7f23b'); - $publication->setPublicationType(ThothPublication::PUBLICATION_TYPE_PDF); - $publication->setIsbn('978-0-615-94946-8'); - - $this->assertEquals([ - 'publicationId' => '30ff947b-1bd9-4eef-8b91-753e9b12b935', - 'workId' => '006571ae-ac0e-4cb0-8a3f-71280aa7f23b', - 'publicationType' => ThothPublication::PUBLICATION_TYPE_PDF, - 'isbn' => '978-0-615-94946-8', - ], $publication->getData()); - } -} diff --git a/tests/thoth/models/ThothPublisherTest.php b/tests/thoth/models/ThothPublisherTest.php deleted file mode 100644 index 111e665..0000000 --- a/tests/thoth/models/ThothPublisherTest.php +++ /dev/null @@ -1,51 +0,0 @@ -setId('ea0ad5ff-dd59-48f8-8da7-95dfd40c90d8'); - $publisher->setPublisherName('Ediciones Universidad de Camagüey'); - $publisher->setPublisherShortName('UCEdiciones'); - $publisher->setPublisherUrl('https://edicionesuc.reduc.edu.cu/'); - - $this->assertEquals('ea0ad5ff-dd59-48f8-8da7-95dfd40c90d8', $publisher->getId()); - $this->assertEquals('Ediciones Universidad de Camagüey', $publisher->getPublishername()); - $this->assertEquals('UCEdiciones', $publisher->getPublisherShortName()); - $this->assertEquals('https://edicionesuc.reduc.edu.cu/', $publisher->getPublisherUrl()); - } - - public function testGetPublisherData() - { - $publisher = new ThothPublisher(); - $publisher->setId('67d14e6c-8922-4cf9-9bc7-1c03a9357144'); - $publisher->setPublisherName('Editora da Universidade Federal da Bahia'); - $publisher->setPublisherShortname('EDUFBA'); - $publisher->setPublisherUrl('https://books.scielo.org/edufba/'); - - $this->assertEquals([ - 'publisherId' => '67d14e6c-8922-4cf9-9bc7-1c03a9357144', - 'publisherName' => 'Editora da Universidade Federal da Bahia', - 'publisherShortname' => 'EDUFBA', - 'publisherUrl' => 'https://books.scielo.org/edufba/' - ], $publisher->getData()); - } -} diff --git a/tests/thoth/models/ThothReferenceTest.php b/tests/thoth/models/ThothReferenceTest.php deleted file mode 100644 index a721b28..0000000 --- a/tests/thoth/models/ThothReferenceTest.php +++ /dev/null @@ -1,64 +0,0 @@ -setId('5aebdd10-1b0c-40c0-8b10-372651b1eced'); - $reference->setWorkId('a8e11061-b281-42de-8638-c14f452e658e'); - $reference->setReferenceOrdinal(1); - $reference->setUnstructuredCitation( - 'Stranack, K. (2018). Editorial: A New Path for Health Sciences. ' . - 'OJS3 Testdrive Journal, 1(3). https://doi.org/10.1234/td.v1i3.714' - ); - - $this->assertEquals('5aebdd10-1b0c-40c0-8b10-372651b1eced', $reference->getId()); - $this->assertEquals('a8e11061-b281-42de-8638-c14f452e658e', $reference->getWorkId()); - $this->assertEquals(1, $reference->getReferenceOrdinal()); - $this->assertEquals( - 'Stranack, K. (2018). Editorial: A New Path for Health Sciences. ' . - 'OJS3 Testdrive Journal, 1(3). https://doi.org/10.1234/td.v1i3.714', - $reference->getUnstructuredCitation() - ); - } - - public function testGetSubjectData() - { - $reference = new ThothReference(); - $reference->setId('62f3fb9b-2bce-4533-8862-da4c6a5b7b1c'); - $reference->setWorkId('9a6aab2b-8077-4cd3-9dd1-19c115f2a3ca'); - $reference->setReferenceOrdinal(4); - $reference->setUnstructuredCitation( - 'Bezsheiko, V. (2021). Effectiveness of influenza vaccination ' . - 'for healthy adults: Versioning Example. OJS3 Testdrive Journal, 1(3). ' . - 'https://doi.org/10.1234/td.v1i3.722 (Original work published March 15, 2021)' - ); - - $this->assertEquals([ - 'referenceId' => '62f3fb9b-2bce-4533-8862-da4c6a5b7b1c', - 'workId' => '9a6aab2b-8077-4cd3-9dd1-19c115f2a3ca', - 'referenceOrdinal' => 4, - 'unstructuredCitation' => 'Bezsheiko, V. (2021). Effectiveness of influenza vaccination ' . - 'for healthy adults: Versioning Example. OJS3 Testdrive Journal, 1(3). ' . - 'https://doi.org/10.1234/td.v1i3.722 (Original work published March 15, 2021)' - ], $reference->getData()); - } -} diff --git a/tests/thoth/models/ThothSubjectTest.php b/tests/thoth/models/ThothSubjectTest.php deleted file mode 100644 index ccb7e83..0000000 --- a/tests/thoth/models/ThothSubjectTest.php +++ /dev/null @@ -1,55 +0,0 @@ -setId('6a9cdd5a-5877-433e-8063-9af0617eaa17'); - $subject->setWorkId('62933c17-7f40-46af-84ab-b563ac4ac448'); - $subject->setSubjectType(ThothSubject::SUBJECT_TYPE_KEYWORD); - $subject->setSubjectCode('law'); - $subject->setSubjectOrdinal(1); - - $this->assertEquals('6a9cdd5a-5877-433e-8063-9af0617eaa17', $subject->getId()); - $this->assertEquals('62933c17-7f40-46af-84ab-b563ac4ac448', $subject->getWorkId()); - $this->assertEquals(ThothSubject::SUBJECT_TYPE_KEYWORD, $subject->getSubjectType()); - $this->assertEquals('law', $subject->getSubjectCode()); - $this->assertEquals(1, $subject->getSubjectOrdinal()); - } - - public function testGetSubjectData() - { - $subject = new ThothSubject(); - $subject->setId('fb3cdeec-a533-49f2-ac42-7f3860f966f3'); - $subject->setWorkId('7fbd3c3e-1e37-4352-9211-82665cc25ce1'); - $subject->setSubjectType(ThothSubject::SUBJECT_TYPE_KEYWORD); - $subject->setSubjectCode('conservation'); - $subject->setSubjectOrdinal(5); - - $this->assertEquals([ - 'subjectId' => 'fb3cdeec-a533-49f2-ac42-7f3860f966f3', - 'workId' => '7fbd3c3e-1e37-4352-9211-82665cc25ce1', - 'subjectType' => ThothSubject::SUBJECT_TYPE_KEYWORD, - 'subjectCode' => 'conservation', - 'subjectOrdinal' => 5, - ], $subject->getData()); - } -} diff --git a/tests/thoth/models/ThothWorkRelationTest.php b/tests/thoth/models/ThothWorkRelationTest.php deleted file mode 100644 index f2300d3..0000000 --- a/tests/thoth/models/ThothWorkRelationTest.php +++ /dev/null @@ -1,59 +0,0 @@ -toString(); - $relatorWorkId = \Ramsey\Uuid\Uuid::uuid4()->toString(); - $relatedWorkId = \Ramsey\Uuid\Uuid::uuid4()->toString(); - - $relation = new ThothWorkRelation(); - $relation->setId($workRelationId); - $relation->setRelatorWorkId($relatorWorkId); - $relation->setRelatedWorkId($relatedWorkId); - $relation->setRelationType(ThothWorkRelation::RELATION_TYPE_IS_CHILD_OF); - $relation->setRelationOrdinal(1); - - $this->assertEquals($workRelationId, $relation->getId()); - $this->assertEquals($relatorWorkId, $relation->getRelatorWorkId()); - $this->assertEquals($relatedWorkId, $relation->getRelatedWorkId()); - $this->assertEquals(ThothWorkRelation::RELATION_TYPE_IS_CHILD_OF, $relation->getRelationType()); - $this->assertEquals(1, $relation->getRelationOrdinal()); - } - - public function testGetRelationData() - { - $relation = new ThothWorkRelation(); - $relation->setId('3e587b61-58f1-4064-bf80-e40e5c924d27'); - $relation->setRelatorWorkId('991f1070-67fa-4e6e-8519-114006043492'); - $relation->setRelatedWorkId('7d861db5-22f6-4ef8-abbb-b56ab8397624'); - $relation->setRelationType(ThothWorkRelation::RELATION_TYPE_IS_CHILD_OF); - $relation->setRelationOrdinal(1); - - $this->assertEquals([ - 'workRelationId' => '3e587b61-58f1-4064-bf80-e40e5c924d27', - 'relatorWorkId' => '991f1070-67fa-4e6e-8519-114006043492', - 'relatedWorkId' => '7d861db5-22f6-4ef8-abbb-b56ab8397624', - 'relationType' => ThothWorkRelation::RELATION_TYPE_IS_CHILD_OF, - 'relationOrdinal' => 1, - ], $relation->getData()); - } -} diff --git a/tests/thoth/models/ThothWorkTest.php b/tests/thoth/models/ThothWorkTest.php deleted file mode 100644 index 9c5e35e..0000000 --- a/tests/thoth/models/ThothWorkTest.php +++ /dev/null @@ -1,109 +0,0 @@ -workData['uuid'] = \Ramsey\Uuid\Uuid::uuid4()->toString(); - $this->workData['workType'] = ThothWork::WORK_TYPE_MONOGRAPH; - $this->workData['workStatus'] = ThothWork::WORK_STATUS_ACTIVE; - $this->workData['fullTitle'] = 'Feliks Volkhovskii: A Revolutionary Life'; - $this->workData['title'] = 'Feliks Volkhovskii'; - $this->workData['subtitle'] = 'A Revolutionary Life'; - $this->workData['edition'] = 1; - $this->workData['imprintId'] = 'e3cb2206-c2b6-4835-9f35-24bfa1572643'; - $this->workData['doi'] = 'https://doi.org/10.11647/OBP.0385'; - $this->workData['publicationDate'] = '2024-06-28'; - $this->workData['pageCount'] = 354; - $this->workData['license'] = 'https://creativecommons.org/licenses/by-nc/4.0/'; - $this->workData['copyrightHolder'] = 'Michael Hughes'; - $this->workData['landingPage'] = 'https://www.openbookpublishers.com/books/10.11647/OBP.0385'; - $this->workData['longAbstract'] = 'Michael Hughes groundbreaking new biography provides a vivid history of ' . - 'this notable but hitherto neglected figure of both the political and literary worlds.'; - $this->workData['coverUrl'] = 'https://cdn.openbookpublishers.com/covers/10.11647/obp.0385.jpg'; - - $this->work = new ThothWork(); - $this->work->setId($this->workData['uuid']); - $this->work->setWorkType($this->workData['workType']); - $this->work->setWorkStatus($this->workData['workStatus']); - $this->work->setFullTitle($this->workData['fullTitle']); - $this->work->setTitle($this->workData['title']); - $this->work->setSubtitle($this->workData['subtitle']); - $this->work->setEdition($this->workData['edition']); - $this->work->setImprintId($this->workData['imprintId']); - $this->work->setDoi($this->workData['doi']); - $this->work->setPublicationDate($this->workData['publicationDate']); - $this->work->setPageCount($this->workData['pageCount']); - $this->work->setLicense($this->workData['license']); - $this->work->setCopyrightHolder($this->workData['copyrightHolder']); - $this->work->setLandingPage($this->workData['landingPage']); - $this->work->setLongAbstract($this->workData['longAbstract']); - $this->work->setCoverUrl($this->workData['coverUrl']); - } - - public function testGettersAndSetters() - { - $this->assertEquals($this->workData['uuid'], $this->work->getId()); - $this->assertEquals($this->workData['workType'], $this->work->getWorkType()); - $this->assertEquals($this->workData['workStatus'], $this->work->getWorkStatus()); - $this->assertEquals($this->workData['fullTitle'], $this->work->getFullTitle()); - $this->assertEquals($this->workData['title'], $this->work->getTitle()); - $this->assertEquals($this->workData['subtitle'], $this->work->getSubtitle()); - $this->assertEquals($this->workData['edition'], $this->work->getEdition()); - $this->assertEquals($this->workData['imprintId'], $this->work->getImprintId()); - $this->assertEquals($this->workData['doi'], $this->work->getDoi()); - $this->assertEquals($this->workData['publicationDate'], $this->work->getPublicationDate()); - $this->assertEquals($this->workData['pageCount'], $this->work->getPageCount()); - $this->assertEquals($this->workData['license'], $this->work->getLicense()); - $this->assertEquals($this->workData['copyrightHolder'], $this->work->getCopyrightHolder()); - $this->assertEquals($this->workData['landingPage'], $this->work->getLandingPage()); - $this->assertEquals($this->workData['longAbstract'], $this->work->getLongAbstract()); - $this->assertEquals($this->workData['coverUrl'], $this->work->getCoverUrl()); - } - - public function testGetWorkData() - { - $this->assertEquals( - [ - 'workId' => $this->workData['uuid'], - 'workType' => $this->workData['workType'], - 'workStatus' => $this->workData['workStatus'], - 'fullTitle' => $this->workData['fullTitle'], - 'title' => $this->workData['title'], - 'subtitle' => $this->workData['subtitle'], - 'edition' => $this->workData['edition'], - 'imprintId' => $this->workData['imprintId'], - 'doi' => $this->workData['doi'], - 'publicationDate' => $this->workData['publicationDate'], - 'pageCount' => $this->workData['pageCount'], - 'license' => $this->workData['license'], - 'copyrightHolder' => $this->workData['copyrightHolder'], - 'landingPage' => $this->workData['landingPage'], - 'longAbstract' => $this->workData['longAbstract'], - 'coverUrl' => $this->workData['coverUrl'] - ], - $this->work->getData() - ); - } -} From 237256d0224240f77998d379b7edba0c19944606 Mon Sep 17 00:00:00 2001 From: Thiago Matos Date: Tue, 28 Jan 2025 18:14:14 -0400 Subject: [PATCH 07/10] Added check if work with DOI already exists Issue: documentacao-e-tarefas/desenvolvimento_e_infra#929 Signed-off-by: Thiago Matos --- classes/ThothValidator.inc.php | 24 ++++++++++++++++ classes/services/ThothWorkService.inc.php | 6 ++++ locale/en/locale.po | 3 ++ locale/es/locale.po | 3 ++ locale/pt_BR/locale.po | 3 ++ tests/classes/ThothValidateTest.php | 27 ++++++++++++++++++ .../classes/services/ThothWorkServiceTest.php | 28 +++++++++++++++++++ 7 files changed, 94 insertions(+) diff --git a/classes/ThothValidator.inc.php b/classes/ThothValidator.inc.php index a178eac..c815174 100644 --- a/classes/ThothValidator.inc.php +++ b/classes/ThothValidator.inc.php @@ -17,6 +17,7 @@ require_once(__DIR__ . '/../vendor/autoload.php'); use Biblys\Isbn\Isbn; +use ThothApi\GraphQL\Models\Work as ThothWork; import('plugins.generic.thoth.classes.facades.ThothService'); @@ -26,6 +27,13 @@ public static function validate($submission) { $errors = []; + $publication = $submission->getCurrentPublication(); + $doi = $publication->getData('doiObject')?->getResolvingUrl(); + + if ($doi !== null) { + $errors = array_merge($errors, self::validateDoiExists($doi)); + } + $publicationFormats = Application::getRepresentationDao() ->getApprovedByPublicationId($submission->getData('currentPublicationId')) ->toArray(); @@ -58,4 +66,20 @@ public static function validateIsbn($publicationFormats) return $errors; } + + public static function validateDoiExists($doi) + { + $errors = []; + + try { + $work = ThothService::work()->getByDoi($doi); + if ($work instanceof ThothWork) { + $errors[] = __('plugins.generic.thoth.validation.doiExists', ['doi' => $doi]); + } + } catch (Exception $e) { + return $errors; + } + + return $errors; + } } diff --git a/classes/services/ThothWorkService.inc.php b/classes/services/ThothWorkService.inc.php index 4b2ce8a..b71d0ee 100644 --- a/classes/services/ThothWorkService.inc.php +++ b/classes/services/ThothWorkService.inc.php @@ -115,6 +115,12 @@ public function get($thothWorkId) return $thothClient->work($thothWorkId); } + public function getByDoi($doi) + { + $thothClient = ThothContainer::getInstance()->get('client'); + return $thothClient->workByDoi($doi); + } + public function registerBook($submission, $thothImprintId) { $thothBook = $this->newBySubmission($submission); diff --git a/locale/en/locale.po b/locale/en/locale.po index 7897aeb..a97fdf9 100644 --- a/locale/en/locale.po +++ b/locale/en/locale.po @@ -54,6 +54,9 @@ msgstr "The submission metadata can not be submitted to Thoth because of the fol msgid "plugins.generic.thoth.validation.isbn" msgstr "\"{$isbn}\" of \"{$formatName}\" publication format is not a valid ISBN-13. A valid ISBN-13 must be exactly 17 characters (numbers and hyphens)." +msgid "plugins.generic.thoth.validation.doiExists" +msgstr "A work with DOI \"{$doi}\" already exists." + msgid "plugins.generic.thoth.register.confirmation" msgstr "Do you want to register in Thoth the metadata related to this submission?" diff --git a/locale/es/locale.po b/locale/es/locale.po index 1632c05..aa97b5f 100644 --- a/locale/es/locale.po +++ b/locale/es/locale.po @@ -54,6 +54,9 @@ msgstr "Los metadatos de envio no pueden ser enviados a Thoth debido a los sigui msgid "plugins.generic.thoth.validation.isbn" msgstr "\"{$isbn}\" del formato de publicación \"{$formatName}\" no es un ISBN-13 válido. Un ISBN-13 válido debe tener exactamente 17 caracteres (números y guiones)." +msgid "plugins.generic.thoth.validation.doiExists" +msgstr "Un trabajo con el DOI \"{$doi}\" ya existe." + msgid "plugins.generic.thoth.register.confirmation" msgstr "¿Desea registrar en Thoth los metadatos relacionados con este envío?" diff --git a/locale/pt_BR/locale.po b/locale/pt_BR/locale.po index 4db8476..abbe67a 100644 --- a/locale/pt_BR/locale.po +++ b/locale/pt_BR/locale.po @@ -54,6 +54,9 @@ msgstr "Os metadados da submissão não podem ser enviados para Thoth devido aos msgid "plugins.generic.thoth.validation.isbn" msgstr "\"{$isbn}\" do formato de publicação \"{$formatName}\" não é um ISBN-13 válido. Um ISBN-13 válido deve ter exatamente 17 caracteres (números e hífens)." +msgid "plugins.generic.thoth.validation.doiExists" +msgstr "Um trabalho com o DOI \"{$doi}\" já existe." + msgid "plugins.generic.thoth.register.confirmation" msgstr "Deseja realmente registrar na Thoth os metadados relacionados a essa submissão?" diff --git a/tests/classes/ThothValidateTest.php b/tests/classes/ThothValidateTest.php index 597b847..adcead5 100644 --- a/tests/classes/ThothValidateTest.php +++ b/tests/classes/ThothValidateTest.php @@ -17,6 +17,7 @@ */ use PKP\tests\PKPTestCase; +use ThothApi\GraphQL\Models\Work as ThothWork; import('plugins.generic.thoth.classes.ThothValidator'); @@ -86,4 +87,30 @@ public function testISBNValidationFails() '##plugins.generic.thoth.validation.isbn##' ], $errors); } + + public function testDOIExistsValidationFails() + { + $doi = 'https://doi.org/10.12345/12345678'; + + $mockThothClient = $this->getMockBuilder(ThothClient::class) + ->setMethods([ + 'workByDoi', + ]) + ->getMock(); + $mockThothClient->expects($this->any()) + ->method('workByDoi') + ->will($this->returnValue(new ThothWork([ + 'doi' => $doi + ]))); + + ThothContainer::getInstance()->set('client', function () use ($mockThothClient) { + return $mockThothClient; + }); + + $errors = ThothValidator::validateDoiExists($doi); + + $this->assertEquals([ + '##plugins.generic.thoth.validation.doiExists##', + ], $errors); + } } diff --git a/tests/classes/services/ThothWorkServiceTest.php b/tests/classes/services/ThothWorkServiceTest.php index 29436e5..3f37cb7 100644 --- a/tests/classes/services/ThothWorkServiceTest.php +++ b/tests/classes/services/ThothWorkServiceTest.php @@ -344,6 +344,34 @@ public function testGetWork() $this->assertEquals($expectedThothWork, $thothWork); } + public function testGetWorkByDoi() + { + $doi = 'https://doi.org/10.12345/12345678'; + + $expectedThothWork = new ThothWork([ + 'doi' => $doi + ]); + + $mockThothClient = $this->getMockBuilder(ThothClient::class) + ->setMethods([ + 'workByDoi', + ]) + ->getMock(); + $mockThothClient->expects($this->any()) + ->method('workByDoi') + ->will($this->returnValue(new ThothWork([ + 'doi' => $doi + ]))); + + ThothContainer::getInstance()->set('client', function () use ($mockThothClient) { + return $mockThothClient; + }); + + $thothWork = $this->workService->getByDoi($doi); + + $this->assertEquals($expectedThothWork, $thothWork); + } + public function testRegisterBook() { $thothImprintId = 'f02786d4-3bcc-473e-8d43-3da66c7e877c'; From 84f660fa8b3d1ae2bbb86ed29830886dd3af0c0e Mon Sep 17 00:00:00 2001 From: Thiago Matos Date: Tue, 28 Jan 2025 18:20:15 -0400 Subject: [PATCH 08/10] Added check if a work with a landing page already exists Issue: documentacao-e-tarefas/desenvolvimento_e_infra#929 Signed-off-by: Thiago Matos --- classes/ThothValidator.inc.php | 28 ++++++++++++++++ classes/services/ThothWorkService.inc.php | 6 ++++ locale/en/locale.po | 3 ++ locale/es/locale.po | 3 ++ locale/pt_BR/locale.po | 3 ++ tests/classes/ThothValidateTest.php | 28 ++++++++++++++++ .../classes/services/ThothWorkServiceTest.php | 32 +++++++++++++++++++ 7 files changed, 103 insertions(+) diff --git a/classes/ThothValidator.inc.php b/classes/ThothValidator.inc.php index c815174..a3bf2ad 100644 --- a/classes/ThothValidator.inc.php +++ b/classes/ThothValidator.inc.php @@ -34,6 +34,21 @@ public static function validate($submission) $errors = array_merge($errors, self::validateDoiExists($doi)); } + $request = Application::get()->getRequest(); + $context = $request->getContext(); + $dispatcher = $request->getDispatcher(); + + $landingPage = $dispatcher->url( + $request, + ROUTE_PAGE, + $context->getPath(), + 'catalog', + 'book', + $submission->getBestId() + ); + + $errors = array_merge($errors, self::validateLandingPageExists($landingPage)); + $publicationFormats = Application::getRepresentationDao() ->getApprovedByPublicationId($submission->getData('currentPublicationId')) ->toArray(); @@ -82,4 +97,17 @@ public static function validateDoiExists($doi) return $errors; } + + public static function validateLandingPageExists($landingPage) + { + $errors = []; + + $works = ThothService::work()->search($landingPage); + + if (!empty($works)) { + $errors[] = __('plugins.generic.thoth.validation.landingPageExists', ['landingPage' => $landingPage]); + } + + return $errors; + } } diff --git a/classes/services/ThothWorkService.inc.php b/classes/services/ThothWorkService.inc.php index b71d0ee..a7ded50 100644 --- a/classes/services/ThothWorkService.inc.php +++ b/classes/services/ThothWorkService.inc.php @@ -121,6 +121,12 @@ public function getByDoi($doi) return $thothClient->workByDoi($doi); } + public function search($filter) + { + $thothClient = ThothContainer::getInstance()->get('client'); + return $thothClient->works(['filter' => $filter]); + } + public function registerBook($submission, $thothImprintId) { $thothBook = $this->newBySubmission($submission); diff --git a/locale/en/locale.po b/locale/en/locale.po index a97fdf9..6b4a75b 100644 --- a/locale/en/locale.po +++ b/locale/en/locale.po @@ -57,6 +57,9 @@ msgstr "\"{$isbn}\" of \"{$formatName}\" publication format is not a valid ISBN- msgid "plugins.generic.thoth.validation.doiExists" msgstr "A work with DOI \"{$doi}\" already exists." +msgid "plugins.generic.thoth.validation.landingPageExists" +msgstr "A work with the landing page \"{$landingPage}\" already exists." + msgid "plugins.generic.thoth.register.confirmation" msgstr "Do you want to register in Thoth the metadata related to this submission?" diff --git a/locale/es/locale.po b/locale/es/locale.po index aa97b5f..9558664 100644 --- a/locale/es/locale.po +++ b/locale/es/locale.po @@ -57,6 +57,9 @@ msgstr "\"{$isbn}\" del formato de publicación \"{$formatName}\" no es un ISBN- msgid "plugins.generic.thoth.validation.doiExists" msgstr "Un trabajo con el DOI \"{$doi}\" ya existe." +msgid "plugins.generic.thoth.validation.landingPageExists" +msgstr "Un trabajo con la página de destino \"{$landingPage}\" ya existe." + msgid "plugins.generic.thoth.register.confirmation" msgstr "¿Desea registrar en Thoth los metadatos relacionados con este envío?" diff --git a/locale/pt_BR/locale.po b/locale/pt_BR/locale.po index abbe67a..935187a 100644 --- a/locale/pt_BR/locale.po +++ b/locale/pt_BR/locale.po @@ -57,6 +57,9 @@ msgstr "\"{$isbn}\" do formato de publicação \"{$formatName}\" não é um ISBN msgid "plugins.generic.thoth.validation.doiExists" msgstr "Um trabalho com o DOI \"{$doi}\" já existe." +msgid "plugins.generic.thoth.validation.landingPageExists" +msgstr "Um trabalho com a página de destino \"{$landingPage}\" já existe." + msgid "plugins.generic.thoth.register.confirmation" msgstr "Deseja realmente registrar na Thoth os metadados relacionados a essa submissão?" diff --git a/tests/classes/ThothValidateTest.php b/tests/classes/ThothValidateTest.php index adcead5..e0ff02a 100644 --- a/tests/classes/ThothValidateTest.php +++ b/tests/classes/ThothValidateTest.php @@ -113,4 +113,32 @@ public function testDOIExistsValidationFails() '##plugins.generic.thoth.validation.doiExists##', ], $errors); } + + public function testLandingPageExistsValidationFails() + { + $landingPage = 'http://www.publicknowledge.omp/index.php/publicknowledge/catalog/book/14'; + + $mockThothClient = $this->getMockBuilder(ThothClient::class) + ->setMethods([ + 'works', + ]) + ->getMock(); + $mockThothClient->expects($this->any()) + ->method('works') + ->will($this->returnValue([ + new ThothWork([ + 'landingPage' => $landingPage + ]) + ])); + + ThothContainer::getInstance()->set('client', function () use ($mockThothClient) { + return $mockThothClient; + }); + + $errors = ThothValidator::validateLandingPageExists($landingPage); + + $this->assertEquals([ + '##plugins.generic.thoth.validation.landingPageExists##', + ], $errors); + } } diff --git a/tests/classes/services/ThothWorkServiceTest.php b/tests/classes/services/ThothWorkServiceTest.php index 3f37cb7..50f4532 100644 --- a/tests/classes/services/ThothWorkServiceTest.php +++ b/tests/classes/services/ThothWorkServiceTest.php @@ -372,6 +372,38 @@ public function testGetWorkByDoi() $this->assertEquals($expectedThothWork, $thothWork); } + public function testSearchWork() + { + $title = 'My book title'; + + $expectedThothWorks = [ + new ThothWork([ + 'title' => $title + ]) + ]; + + $mockThothClient = $this->getMockBuilder(ThothClient::class) + ->setMethods([ + 'works', + ]) + ->getMock(); + $mockThothClient->expects($this->any()) + ->method('works') + ->will($this->returnValue([ + new ThothWork([ + 'title' => $title + ]) + ])); + + ThothContainer::getInstance()->set('client', function () use ($mockThothClient) { + return $mockThothClient; + }); + + $thothWorks = $this->workService->search($title); + + $this->assertEquals($expectedThothWorks, $thothWorks); + } + public function testRegisterBook() { $thothImprintId = 'f02786d4-3bcc-473e-8d43-3da66c7e877c'; From 70d8992fcbddd9974d66f59e1dc6eb76c80f42d9 Mon Sep 17 00:00:00 2001 From: Thiago Matos Date: Tue, 28 Jan 2025 18:33:02 -0400 Subject: [PATCH 09/10] Added check if a publication with ISBN already exists Issue: documentacao-e-tarefas/desenvolvimento_e_infra#929 Signed-off-by: Thiago Matos --- classes/ThothValidator.inc.php | 14 ++++++++ .../services/ThothPublicationService.inc.php | 6 ++++ locale/en/locale.po | 3 ++ locale/es/locale.po | 3 ++ locale/pt_BR/locale.po | 3 ++ tests/classes/ThothValidateTest.php | 29 +++++++++++++++++ .../services/ThothPublicationServiceTest.php | 32 ++++++++++++++++++- 7 files changed, 89 insertions(+), 1 deletion(-) diff --git a/classes/ThothValidator.inc.php b/classes/ThothValidator.inc.php index a3bf2ad..8e0a5a3 100644 --- a/classes/ThothValidator.inc.php +++ b/classes/ThothValidator.inc.php @@ -71,6 +71,7 @@ public static function validateIsbn($publicationFormats) if ($isbn !== null) { Isbn::validateAsIsbn13($isbn); } + $errors = array_merge($errors, self::validateIsbnExists($isbn)); } catch (Exception $e) { $errors[] = __('plugins.generic.thoth.validation.isbn', [ 'isbn' => $isbn, @@ -110,4 +111,17 @@ public static function validateLandingPageExists($landingPage) return $errors; } + + public static function validateIsbnExists($isbn) + { + $errors = []; + + $publications = ThothService::publication()->search($isbn); + + if (!empty($publications)) { + $errors[] = __('plugins.generic.thoth.validation.isbnExists', ['isbn' => $isbn]); + } + + return $errors; + } } diff --git a/classes/services/ThothPublicationService.inc.php b/classes/services/ThothPublicationService.inc.php index 931c5f9..5910030 100644 --- a/classes/services/ThothPublicationService.inc.php +++ b/classes/services/ThothPublicationService.inc.php @@ -42,6 +42,12 @@ public function new($params) return $publication; } + public function search($filter) + { + $thothClient = ThothContainer::getInstance()->get('client'); + return $thothClient->publications(['filter' => $filter]); + } + public function register($publicationFormat, $workId, $chapterId = null) { $thothPublication = $this->newByPublicationFormat($publicationFormat); diff --git a/locale/en/locale.po b/locale/en/locale.po index 6b4a75b..2850a91 100644 --- a/locale/en/locale.po +++ b/locale/en/locale.po @@ -60,6 +60,9 @@ msgstr "A work with DOI \"{$doi}\" already exists." msgid "plugins.generic.thoth.validation.landingPageExists" msgstr "A work with the landing page \"{$landingPage}\" already exists." +msgid "plugins.generic.thoth.validation.isbnExists" +msgstr "A publication with the ISBN \"{$isbn}\" already exists." + msgid "plugins.generic.thoth.register.confirmation" msgstr "Do you want to register in Thoth the metadata related to this submission?" diff --git a/locale/es/locale.po b/locale/es/locale.po index 9558664..795dd91 100644 --- a/locale/es/locale.po +++ b/locale/es/locale.po @@ -60,6 +60,9 @@ msgstr "Un trabajo con el DOI \"{$doi}\" ya existe." msgid "plugins.generic.thoth.validation.landingPageExists" msgstr "Un trabajo con la página de destino \"{$landingPage}\" ya existe." +msgid "plugins.generic.thoth.validation.isbnExists" +msgstr "Una publicación con el ISBN \"{$isbn}\" ya existe." + msgid "plugins.generic.thoth.register.confirmation" msgstr "¿Desea registrar en Thoth los metadatos relacionados con este envío?" diff --git a/locale/pt_BR/locale.po b/locale/pt_BR/locale.po index 935187a..e31d0c6 100644 --- a/locale/pt_BR/locale.po +++ b/locale/pt_BR/locale.po @@ -60,6 +60,9 @@ msgstr "Um trabalho com o DOI \"{$doi}\" já existe." msgid "plugins.generic.thoth.validation.landingPageExists" msgstr "Um trabalho com a página de destino \"{$landingPage}\" já existe." +msgid "plugins.generic.thoth.validation.isbnExists" +msgstr "Uma publicação com o ISBN \"{$isbn}\" já existe." + msgid "plugins.generic.thoth.register.confirmation" msgstr "Deseja realmente registrar na Thoth os metadados relacionados a essa submissão?" diff --git a/tests/classes/ThothValidateTest.php b/tests/classes/ThothValidateTest.php index e0ff02a..97464a2 100644 --- a/tests/classes/ThothValidateTest.php +++ b/tests/classes/ThothValidateTest.php @@ -17,6 +17,7 @@ */ use PKP\tests\PKPTestCase; +use ThothApi\GraphQL\Models\Publication as ThothPublication; use ThothApi\GraphQL\Models\Work as ThothWork; import('plugins.generic.thoth.classes.ThothValidator'); @@ -141,4 +142,32 @@ public function testLandingPageExistsValidationFails() '##plugins.generic.thoth.validation.landingPageExists##', ], $errors); } + + public function testISBNExistsValidationFails() + { + $isbn = '978-65-89999-01-3'; + + $mockThothClient = $this->getMockBuilder(ThothClient::class) + ->setMethods([ + 'publications', + ]) + ->getMock(); + $mockThothClient->expects($this->any()) + ->method('publications') + ->will($this->returnValue([ + new ThothPublication([ + 'isbn' => $isbn + ]) + ])); + + ThothContainer::getInstance()->set('client', function () use ($mockThothClient) { + return $mockThothClient; + }); + + $errors = ThothValidator::validateIsbnExists($isbn); + + $this->assertEquals([ + '##plugins.generic.thoth.validation.isbnExists##', + ], $errors); + } } diff --git a/tests/classes/services/ThothPublicationServiceTest.php b/tests/classes/services/ThothPublicationServiceTest.php index 4f5866a..9df3784 100644 --- a/tests/classes/services/ThothPublicationServiceTest.php +++ b/tests/classes/services/ThothPublicationServiceTest.php @@ -166,7 +166,7 @@ public function testCreateNewPublicationByPublicationFormat() $this->assertEquals($expectedPublication, $publication); } - public function testCreateNewContributor() + public function testCreateNewPublication() { $expectedPublication = new ThothPublication(); $expectedPublication->setPublicationType(ThothPublication::PUBLICATION_TYPE_PDF); @@ -181,6 +181,36 @@ public function testCreateNewContributor() $this->assertEquals($expectedPublication, $publication); } + public function testSearchPublication() + { + $isbn = '978-65-89999-01-3'; + + $expectedThothPublications = [ + new ThothPublication([ + 'isbn' => $isbn + ]) + ]; + + $mockThothClient = $this->getMockBuilder(ThothClient::class) + ->setMethods(['publications']) + ->getMock(); + $mockThothClient->expects($this->any()) + ->method('publications') + ->will($this->returnValue([ + new ThothPublication([ + 'isbn' => $isbn + ]) + ])); + + ThothContainer::getInstance()->set('client', function () use ($mockThothClient) { + return $mockThothClient; + }); + + $thothPublications = $this->publicationService->search($isbn); + + $this->assertEquals($expectedThothPublications, $thothPublications); + } + public function testRegisterPublication() { $workId = '2a065323-76cd-4f54-b83b-19f2a925f426'; From 1d7f308f06609c367e66f87e6622c617d6bc54b1 Mon Sep 17 00:00:00 2001 From: Thiago Matos Date: Tue, 28 Jan 2025 18:33:49 -0400 Subject: [PATCH 10/10] Update version.xml Issue: documentacao-e-tarefas/desenvolvimento_e_infra#929 Signed-off-by: Thiago Matos --- version.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/version.xml b/version.xml index 4a4cacc..8518977 100644 --- a/version.xml +++ b/version.xml @@ -3,8 +3,8 @@ thoth plugins.generic - 0.2.2.0 - 2025-01-18 + 0.2.3.0 + 2025-01-28 1 ThothPlugin