-
Notifications
You must be signed in to change notification settings - Fork 916
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pkp/pkp-lib#9771 Move ORCID functionality into core application
- Loading branch information
Showing
11 changed files
with
476 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
/** | ||
* @defgroup api_v1_orcid ORCID API requests | ||
*/ | ||
|
||
/** | ||
* @file api/v1/orcid/index.php | ||
* | ||
* Copyright (c) 2024 Simon Fraser University | ||
* Copyright (c) 2024 John Willinsky | ||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. | ||
* | ||
* @ingroup api_v1_orcid | ||
* | ||
* @brief Handle requests for ORCID API functions. | ||
* | ||
*/ | ||
|
||
return new \PKP\handler\APIHandler(new \PKP\API\v1\orcid\OrcidController()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
<?php | ||
|
||
/** | ||
* @file classes/orcid/OrcidReview.php | ||
* | ||
* Copyright (c) 2014-2024 Simon Fraser University | ||
* Copyright (c) 2000-2024 John Willinsky | ||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. | ||
* | ||
* @class OrcidReview | ||
* | ||
* @brief Builds ORCID review object for deposit | ||
*/ | ||
|
||
namespace APP\orcid; | ||
|
||
use APP\core\Application; | ||
use APP\submission\Submission; | ||
use Carbon\Carbon; | ||
use PKP\context\Context; | ||
use PKP\doi\Doi; | ||
use PKP\i18n\LocaleConversion; | ||
use PKP\orcid\OrcidManager; | ||
use PKP\submission\reviewAssignment\ReviewAssignment; | ||
|
||
class OrcidReview | ||
{ | ||
private array $data; | ||
|
||
public function __construct( | ||
private Submission $submission, | ||
private ReviewAssignment $review, | ||
private Context $context, | ||
) { | ||
$this->data = $this->build(); | ||
} | ||
|
||
/** | ||
* Returns ORCID review data as an associative array, ready for deposit. | ||
*/ | ||
public function toArray(): array | ||
{ | ||
return $this->data; | ||
} | ||
|
||
/** | ||
* Builds the internal structure for the ORCID review. | ||
*/ | ||
private function build(): array | ||
{ | ||
$publicationUrl = Application::get()->getDispatcher()->url( | ||
Application::get()->getRequest(), | ||
Application::ROUTE_PAGE, | ||
$this->context->getPath(), | ||
'article', | ||
'view', | ||
$this->submission->getId(), | ||
urlLocaleForPage: '', | ||
); | ||
|
||
$submissionLocale = $this->submission->getData('locale'); | ||
$currentPublication = $this->submission->getCurrentPublication(); | ||
|
||
if (empty($this->review->getData('dateCompleted')) || empty($this->context->getData('onlineIssn'))) { | ||
return []; | ||
} | ||
|
||
$reviewCompletionDate = Carbon::parse($this->review->getData('dateCompleted')); | ||
|
||
$orcidReview = [ | ||
'reviewer-role' => 'reviewer', | ||
'review-type' => 'review', | ||
'review-completion-date' => [ | ||
'year' => [ | ||
'value' => $reviewCompletionDate->format('Y') | ||
], | ||
'month' => [ | ||
'value' => $reviewCompletionDate->format('m') | ||
], | ||
'day' => [ | ||
'value' => $reviewCompletionDate->format('d') | ||
] | ||
], | ||
'review-group-id' => 'issn:' . $this->context->getData('onlineIssn'), | ||
|
||
'convening-organization' => [ | ||
'name' => $this->context->getData('publisherInstitution'), | ||
'address' => [ | ||
'city' => OrcidManager::getCity($this->context), | ||
'country' => OrcidManager::getCountry($this->context), | ||
|
||
] | ||
], | ||
'review-identifiers' => ['external-id' => [ | ||
[ | ||
'external-id-type' => 'source-work-id', | ||
'external-id-value' => $this->review->getData('reviewRoundId'), | ||
'external-id-relationship' => 'part-of'] | ||
]] | ||
]; | ||
if ($this->review->getReviewMethod() == ReviewAssignment::SUBMISSION_REVIEW_METHOD_OPEN) { | ||
$orcidReview['subject-url'] = ['value' => $publicationUrl]; | ||
$orcidReview['review-url'] = ['value' => $publicationUrl]; | ||
$orcidReview['subject-type'] = 'journal-article'; | ||
$orcidReview['subject-name'] = [ | ||
'title' => ['value' => $this->submission->getCurrentPublication()->getLocalizedData('title') ?? ''] | ||
]; | ||
|
||
if (!empty($currentPublication->getDoi())) { | ||
/** @var Doi $doiObject */ | ||
$doiObject = $currentPublication->getData('doiObject'); | ||
$externalIds = [ | ||
'external-id-type' => 'doi', | ||
'external-id-value' => $doiObject->getDoi(), | ||
'external-id-url' => [ | ||
'value' => $doiObject->getResolvingUrl(), | ||
], | ||
'external-id-relationship' => 'self' | ||
|
||
]; | ||
$orcidReview['subject-external-identifier'] = $externalIds; | ||
} | ||
} | ||
|
||
$allTitles = $currentPublication->getData('title'); | ||
foreach ($allTitles as $locale => $title) { | ||
if ($locale !== $submissionLocale) { | ||
$orcidReview['subject-name']['translated-title'] = ['value' => $title, 'language-code' => LocaleConversion::getIso1FromLocale($locale)]; | ||
} | ||
} | ||
|
||
return $orcidReview; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
<?php | ||
|
||
/** | ||
* @file classes/orcid/OrcidWork.php | ||
* | ||
* Copyright (c) 2014-2024 Simon Fraser University | ||
* Copyright (c) 2000-2024 John Willinsky | ||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. | ||
* | ||
* @class OrcidWork | ||
* | ||
* @brief Builds ORCID work object for deposit | ||
*/ | ||
|
||
namespace APP\orcid; | ||
|
||
use APP\core\Application; | ||
use APP\issue\Issue; | ||
use APP\plugins\generic\citationStyleLanguage\CitationStyleLanguagePlugin; | ||
use APP\plugins\PubIdPlugin; | ||
use APP\publication\Publication; | ||
use APP\submission\Submission; | ||
use PKP\context\Context; | ||
use PKP\orcid\PKPOrcidWork; | ||
use PKP\plugins\PluginRegistry; | ||
|
||
class OrcidWork extends PKPOrcidWork | ||
{ | ||
public function __construct( | ||
protected Publication $publication, | ||
protected Context $context, | ||
protected array $authors, | ||
protected ?Issue $issue = null | ||
) { | ||
parent::__construct($this->publication, $this->context, $this->authors); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function getAppPubIdExternalIds(PubIdPlugin $plugin): array | ||
{ | ||
$ids = []; | ||
|
||
$pubIdType = $plugin->getPubIdType(); | ||
$pubId = $this->issue?->getStoredPubId($pubIdType); | ||
if ($pubId) { | ||
$ids[] = [ | ||
'external-id-type' => self::PUBID_TO_ORCID_EXT_ID[$pubIdType], | ||
'external-id-value' => $pubId, | ||
'external-id-url' => [ | ||
'value' => $plugin->getResolvingURL($this->context->getId(), $pubId) | ||
], | ||
'external-id-relationship' => 'part-of' | ||
]; | ||
} | ||
|
||
return $ids; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function getAppDoiExternalIds(): array | ||
{ | ||
$ids = []; | ||
|
||
$issueDoiObject = $this->issue->getData('doiObject'); | ||
if ($issueDoiObject) { | ||
$ids[] = [ | ||
'external-id-type' => self::PUBID_TO_ORCID_EXT_ID['doi'], | ||
'external-id-value' => $issueDoiObject->getData('doi'), | ||
'external-id-url' => [ | ||
'value' => $issueDoiObject->getResolvingUrl() | ||
], | ||
'external-id-relationship' => 'part-of' | ||
]; | ||
} | ||
|
||
return $ids; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
protected function getOrcidPublicationType(): string | ||
{ | ||
return 'journal-article'; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function getBibtexCitation(Submission $submission): string | ||
{ | ||
$request = Application::get()->getRequest(); | ||
try { | ||
PluginRegistry::loadCategory('generic'); | ||
/** @var CitationStyleLanguagePlugin $citationPlugin */ | ||
$citationPlugin = PluginRegistry::getPlugin('generic', 'citationstylelanguageplugin'); | ||
return trim( | ||
strip_tags( | ||
$citationPlugin->getCitation( | ||
$request, | ||
$submission, | ||
'bibtex', | ||
$this->issue, | ||
$this->publication | ||
) | ||
) | ||
); | ||
} catch (\Exception $exception) { | ||
return ''; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
/** | ||
* @file classes/orcid/actions/SendReviewToOrcid.php | ||
* | ||
* Copyright (c) 2014-2024 Simon Fraser University | ||
* Copyright (c) 2000-2024 John Willinsky | ||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. | ||
* | ||
* @class SendReviewToOrcid | ||
* | ||
* @brief Trigger review deposit to ORCID if supported by the application (currently only OJS). | ||
*/ | ||
|
||
namespace APP\orcid\actions; | ||
|
||
use APP\jobs\orcid\DepositOrcidReview; | ||
use PKP\orcid\actions\PKPSendReviewToOrcid; | ||
|
||
class SendReviewToOrcid extends PKPSendReviewToOrcid | ||
{ | ||
/** @inheritDoc */ | ||
public function execute(): void | ||
{ | ||
dispatch(new DepositOrcidReview($this->submission, $this->context, $this->reviewAssignment)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
/** | ||
* @file classes/orcid/actions/SendSubmissionToOrcid.php | ||
* | ||
* Copyright (c) 2014-2024 Simon Fraser University | ||
* Copyright (c) 2000-2024 John Willinsky | ||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. | ||
* | ||
* @class SendSubmissionToOrcid | ||
* | ||
* @brief Compile and trigger deposits of submissions to ORCID. | ||
*/ | ||
|
||
namespace APP\orcid\actions; | ||
|
||
use APP\facades\Repo; | ||
use APP\orcid\OrcidWork; | ||
use PKP\orcid\actions\PKPSendSubmissionToOrcid; | ||
use PKP\orcid\PKPOrcidWork; | ||
|
||
class SendSubmissionToOrcid extends PKPSendSubmissionToOrcid | ||
{ | ||
/** | ||
* @inheritDoc | ||
*/ | ||
protected function getOrcidWork(array $authors): ?PKPOrcidWork | ||
{ | ||
$issueId = $this->publication->getData('issueId'); | ||
if (isset($issueId)) { | ||
$issue = Repo::issue()->get($issueId); | ||
} | ||
|
||
return new OrcidWork($this->publication, $this->context, $authors, $issue ?? null); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
protected function canDepositSubmission(): bool | ||
{ | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.