Skip to content

Commit

Permalink
Add submission file DOI.
Browse files Browse the repository at this point in the history
  • Loading branch information
nongenti committed Jun 17, 2024
1 parent 63ac8aa commit 6abc696
Show file tree
Hide file tree
Showing 10 changed files with 285 additions and 36 deletions.
18 changes: 17 additions & 1 deletion DataciteExportPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class DataciteExportPlugin extends DOIPubIdExportPlugin {

//DataCite API
public const DATACITE_API_URL = 'https://mds.datacite.org/';

public const DATACITE_API_URL_TEST = 'https://mds.test.datacite.org/';
#endregion

Expand Down Expand Up @@ -86,6 +87,14 @@ public function getRepresentationFilter(): string
return 'publicationFormat=>datacite-xml';
}

/**
* @copydoc PubObjectsExportPlugin::getRepresentationFilter()
*/
public function getSubmissionFileFilter(): string
{
return 'submissionFile=>datacite-xml';
}

public function getPluginSettingsPrefix(): string
{
return 'datacite';
Expand Down Expand Up @@ -201,7 +210,7 @@ public function exportAsDownload(Context $context, array $objects, ?bool $noVali
$this->getExportPath(),
$objectFileNamePart,
$context,
'.xml'
'.'. count($objects) .'.xml'
);
$fileManager->writeFile($exportFileName, $exportXml);
$exportedFiles[] = $exportFileName;
Expand Down Expand Up @@ -424,6 +433,9 @@ public function _getObjectUrl(Request$request, Context $context, DataObject $obj
$url = $dispatcher->url($request, PKPApplication::ROUTE_PAGE, $context->getPath(), 'catalog', 'book', [$publication->getData('submissionId')], null, null, true);
}
break;
case $object instanceof SubmissionFile:
$url = $dispatcher->url($request, PKPApplication::ROUTE_PAGE, $context->getPath(), 'catalog', 'view', [$object->getData('submissionId'), $object->getData('assocId'), $object->getId()], null, null, true);
break;
}

if ($this->isTestMode($context)) {
Expand All @@ -446,6 +458,8 @@ private function _getFilterFromObject(DataObject $object): string
return $this->getChapterFilter();
} elseif ($object instanceof PublicationFormat) {
return $this->getRepresentationFilter();
} elseif ($object instanceof SubmissionFile) {
return $this->getSubmissionFileFilter();
} else {
return '';
}
Expand All @@ -459,6 +473,8 @@ private function _getObjectFileNamePart(DataObject $object): string
return 'chapter-' . $object->getSourceChapterId();
} elseif ($object instanceof PublicationFormat) {
return 'publicationFormat-' . $object->getId();
} elseif ($object instanceof SubmissionFile) {
return 'submissionFile-' . $object->getId();
} else {
return '';
}
Expand Down
60 changes: 57 additions & 3 deletions DatacitePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use PKP\plugins\Hook;
use PKP\plugins\PluginRegistry;
use PKP\services\PKPSchemaService;
use PKP\submissionFile\SubmissionFile;

class DatacitePlugin extends GenericPlugin implements IDoiRegistrationAgency
{
Expand Down Expand Up @@ -115,27 +116,53 @@ public function exportSubmissions(array $submissions, Context $context): array
if (in_array(Repo::doi()::TYPE_CHAPTER, $context->getEnabledDoiTypes())) {
$chapterDAO = new ChapterDAO();
$chapters = $chapterDAO->getByPublicationId($currentPublicationId)->toAssociativeArray();
$onlyWithLandingPage = $this->getSetting($context->getId(), DataciteSettings::KEY_ONLY_WITH_LANDINGPAGE);
/** @var Chapter $chapter */
foreach ($chapters as $chapter) {
if ($chapter->getDoi()) {
if ($chapter->isPageEnabled() === 1) { //TODO: Remove this control structure, if omp core only assigns DOIs to chapters with own landing page.
if ($onlyWithLandingPage) { //TODO: Remove this control structure, if omp core only assigns DOIs to chapters with own landing page.
if ($chapter->isPageEnabled() === 1) {
$items[] = $chapter;
}
} else {
$items[] = $chapter;
}

}
}
}

//publication formats
if (in_array(Repo::doi()::TYPE_REPRESENTATION, $context->getEnabledDoiTypes())) {
$publicationFormatDAO = new PublicationFormatDAO();
$publicationFormats = $publicationFormatDAO->getByPublicationId($currentPublicationId)->toAssociativeArray();
$publicationFormats = $publicationFormatDAO->getByPublicationId($currentPublicationId);
/** @var PublicationFormat $publicationFormat */
foreach ($publicationFormats as $publicationFormat) {
if ($publicationFormat->getDoi()) {
$items[] = $publicationFormat;
}
}
}

//submission files
if (in_array(Repo::doi()::TYPE_SUBMISSION_FILE, $context->getEnabledDoiTypes())) {
$submissionFiles = Repo::submissionFile()
->getCollector()
->filterBySubmissionIds([$submission->getId()])
->filterByFileStages([SubmissionFile::SUBMISSION_FILE_PROOF])
->filterByAssoc(
Application::ASSOC_TYPE_PUBLICATION_FORMAT
)
->getMany()
->toArray();

/** @var SubmissionFile $submissionFile */
foreach ($submissionFiles as $submissionFile) {
if ($submissionFile->getDoi()) {
$items[] = $submissionFile;
}
}
}
}

$temporaryFileId = $exportPlugin->exportAsDownload($context, $items, null, $xmlErrors);
Expand Down Expand Up @@ -164,12 +191,18 @@ public function depositSubmissions(array $submissions, Context $context): array
if (in_array(Repo::doi()::TYPE_CHAPTER, $context->getEnabledDoiTypes())) {
$chapterDAO = new ChapterDAO();
$chapters = $chapterDAO->getByPublicationId($currentPublicationId)->toAssociativeArray();
$onlyWithLandingPage = $this->getSetting($context->getId(), DataciteSettings::KEY_ONLY_WITH_LANDINGPAGE);
/** @var Chapter $chapter */
foreach ($chapters as $chapter) {
if ($chapter->getDoi()) {
if ($chapter->isPageEnabled() === 1) { //TODO: Remove this control structure, if omp core only assigns DOIs to chapters with own landing page.
if ($onlyWithLandingPage) { //TODO: Remove this control structure, if omp core only assigns DOIs to chapters with own landing page.
if ($chapter->isPageEnabled() === 1) {
$items[] = $chapter;
}
} else {
$items[] = $chapter;
}

}
}
}
Expand All @@ -185,6 +218,26 @@ public function depositSubmissions(array $submissions, Context $context): array
}
}
}

//submission files
if (in_array(Repo::doi()::TYPE_SUBMISSION_FILE, $context->getEnabledDoiTypes())) {
$submissionFiles = Repo::submissionFile()
->getCollector()
->filterBySubmissionIds([$submission->getId()])
->filterByFileStages([SubmissionFile::SUBMISSION_FILE_PROOF])
->filterByAssoc(
Application::ASSOC_TYPE_PUBLICATION_FORMAT
)
->getMany()
->toArray();

/** @var SubmissionFile $submissionFile */
foreach ($submissionFiles as $submissionFile) {
if ($submissionFile->getDoi()) {
$items[] = $submissionFile;
}
}
}
}

$status = $exportPlugin->exportAndDeposit($context, $items, $responseMessage);
Expand Down Expand Up @@ -356,6 +409,7 @@ public function getAllowedDoiTypes(): array
Repo::doi()::TYPE_PUBLICATION, //book
Repo::doi()::TYPE_CHAPTER, //chapter
Repo::doi()::TYPE_REPRESENTATION, //publication format
Repo::doi()::TYPE_SUBMISSION_FILE, //submission file
];
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
### OMPDatacite Plugin

#### Introduction
This plugin registers DOIS for monographs, chapters and publication formats for DOI provider [Datacite.org](https://datacite.org).
This plugin registers DOIS for monographs, chapters, publication formats and files for DOI provider [Datacite.org](https://datacite.org).

Current Schema version is [4.4](https://support.datacite.org/docs/datacite-metadata-schema-44)

Expand Down
23 changes: 23 additions & 0 deletions classes/DOIPubIdExportPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use APP\template\TemplateManager;
use PKP\context\Context;
use PKP\core\PKPString;
use PKP\submissionFile\SubmissionFile;


abstract class DOIPubIdExportPlugin extends PubObjectsExportPlugin
Expand Down Expand Up @@ -187,6 +188,28 @@ public function getPublishedPublicationFormats(array $publicationFormatIds, Cont
return $validPublishedPublicationFormatsWithDoi;
}

/**
* Get publication formats from publication format IDs.
*
* @param array $submissionFileIds
* @param Context $context
*
* @return array
*/
public function getPublishedSubmissionFiles(array $submissionFileIds, Context $context): array
{
$validPublishedSubmissionFiles = parent::getPublishedSubmissionFiles($submissionFileIds, $context);
$validPublishedSubmissionFilesWithDoi = [];
/** @var SubmissionFile $submissionFile */
foreach ($validPublishedSubmissionFiles as $submissionFile) {
if ($submissionFile->getDoi() !== null) {
$validPublishedSubmissionFilesWithDoi[] = $submissionFile;
}
}

return $validPublishedSubmissionFilesWithDoi;
}


/**
* @copydoc ImportExportPlugin::executeCLI()
Expand Down
12 changes: 12 additions & 0 deletions classes/DataciteSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class DataciteSettings extends RegistrationAgencySettings
public const KEY_TEST_USERNAMER = 'testUsername';
public const KEY_TEST_PASSWORD = 'testPassword';
public const KEY_TEST_DOI_PREFIX = 'testDOIPrefix';
public const KEY_ONLY_WITH_LANDINGPAGE = 'onlyWithLandingPage';
public function getSchema(): stdClass
{
return (object) [
Expand Down Expand Up @@ -65,6 +66,10 @@ public function getSchema(): stdClass
'type' => 'string',
'validation' => ['nullable', 'max:50']
],
self::KEY_ONLY_WITH_LANDINGPAGE => (object) [
'type' => 'boolean',
'validation' => ['nullable']
],
],
];
}
Expand All @@ -89,6 +94,13 @@ public function getFields(Context $context): array
'inputType' => 'password',
'value' => $this->agencyPlugin->getSetting($context->getId(), self::KEY_PASSWORD),
]),
new FieldOptions(self::KEY_ONLY_WITH_LANDINGPAGE, [
'label' => __('plugins.importexport.datacite.settings.form.onlyWithLandingPage.label'),
'options' => [
['value' => true, 'label' => __('plugins.importexport.datacite.settings.form.onlyWithLandingPage.description')],
],
'value' => $this->agencyPlugin->getSetting($context->getId(), self::KEY_ONLY_WITH_LANDINGPAGE),
]),
new FieldOptions(self::KEY_TEST_MODE, [
'label' => __('plugins.importexport.common.settings.form.testMode.label'),
'options' => [
Expand Down
8 changes: 8 additions & 0 deletions classes/PubObjectCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use APP\publication\Publication;
use APP\publicationFormat\PublicationFormat;
use DataObject;
use PKP\submissionFile\SubmissionFile;

class PubObjectCache
{
Expand Down Expand Up @@ -55,6 +56,13 @@ public function add(DataObject $object, ?Publication $parent = null): void
$this->_insertInternally($object, 'publicationFormatsByPublication', $parent->getId(), $object->getId());
}
}
if ($object instanceof SubmissionFile) {
assert($parent instanceof Publication);
$this->_insertInternally($object, 'submissionFiles', $object->getId());
if ($parent) {
$this->_insertInternally($object, 'submissionFilesByPublication', $parent->getId(), $object->getId());
}
}
}

/**
Expand Down
Loading

0 comments on commit 6abc696

Please sign in to comment.