Skip to content

Commit

Permalink
pkp/pkp-lib#9771 Move ORCID functionality into core application
Browse files Browse the repository at this point in the history
  • Loading branch information
ewhanson committed Jun 20, 2024
1 parent 2bdb112 commit afdfba3
Show file tree
Hide file tree
Showing 11 changed files with 476 additions and 0 deletions.
20 changes: 20 additions & 0 deletions api/v1/orcid/index.php
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());
134 changes: 134 additions & 0 deletions classes/orcid/OrcidReview.php
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;
}
}
116 changes: 116 additions & 0 deletions classes/orcid/OrcidWork.php
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 '';
}
}
}
27 changes: 27 additions & 0 deletions classes/orcid/actions/SendReviewToOrcid.php
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));
}
}
44 changes: 44 additions & 0 deletions classes/orcid/actions/SendSubmissionToOrcid.php
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;
}
}
1 change: 1 addition & 0 deletions dbscripts/xml/upgrade.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
<migration class="PKP\migration\upgrade\v3_5_0\I8826_AddMissingForeignKeys" />
<migration class="APP\migration\upgrade\v3_5_0\I9937_EditorialTeamToEditorialHistory"/>
<migration class="PKP\migration\upgrade\v3_5_0\I10041_UserGroupsAndUserUserGroupsMastheadValues"/>
<migration class="PKP\migration\upgrade\v3_5_0\I9771_OrcidMigration"/>
</upgrade>

<!-- update plugin configuration - should be done as the final upgrade task -->
Expand Down
Loading

0 comments on commit afdfba3

Please sign in to comment.