Skip to content

Commit

Permalink
WIP: ORCID integration into core
Browse files Browse the repository at this point in the history
  • Loading branch information
ewhanson committed May 7, 2024
1 parent 5b7bce6 commit 054ec0c
Show file tree
Hide file tree
Showing 10 changed files with 805 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 [];
}
}
}
Loading

0 comments on commit 054ec0c

Please sign in to comment.