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 May 22, 2024
1 parent 4b80a03 commit 216911f
Show file tree
Hide file tree
Showing 9 changed files with 437 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());
130 changes: 130 additions & 0 deletions classes/orcid/OrcidReview.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?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->buildOrcidReview();
}

public function toArray(): array
{
return $this->data;
}

private function buildOrcidReview(): 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')) && $this->context->getData('onlineIssn')) {
$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' => $currentPublication->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;
} else {
// TODO: Check how this should be handled.
// It seems like this should be blocked earlier rather than letting it get to this point.
return [];
}
}
}
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 '';
}
}
}
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 @@ -133,6 +133,7 @@
<migration class="PKP\migration\upgrade\v3_5_0\I9809_ReviewCancelDate"/>
<migration class="PKP\migration\upgrade\v3_5_0\I9860_EditorialMastheadNavMenuItem"/>
<migration class="PKP\migration\upgrade\v3_5_0\I8826_AddMissingForeignKeys" />
<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 216911f

Please sign in to comment.