Skip to content

Commit

Permalink
Merge pull request #1130 from NFDI4Chem/related_indentifiers
Browse files Browse the repository at this point in the history
feat: add DataCite relatedIdentifier to link projects, studies, datasets.
  • Loading branch information
CS76 authored Jun 5, 2024
2 parents b5cd06d + e6a06c2 commit 0958388
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 3 deletions.
59 changes: 59 additions & 0 deletions app/Actions/Project/UpdateDOI.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

namespace App\Actions\Project;

use App\Models\Dataset;
use App\Models\Project;
use App\Models\Study;
use App\Services\DOI\DOIService;
use Illuminate\Support\Collection;

class UpdateDOI
{
private $doiService;

/**
* Create a new class instance.
*
* @return void
*/
public function __construct(DOIService $doiService)
{
$this->doiService = $doiService;
}

/**
* Update the given model DOI metadata.
*
* @param mixed $model
* @return void
*/
public function update($model)
{
$project = null;
$studies = null;
if ($model instanceof Project) {
$project = $model;
} elseif ($model instanceof Collection) {
$studies = $model;
}

if ($project) {
$project->addRelatedIdentifiers($this->doiService);
$studies = $project->studies;
}
if ($studies) {
foreach ($studies as $study) {
if ($study instanceof Study) {
$study->addRelatedIdentifiers($this->doiService);
$datasets = $study->datasets;
foreach ($datasets as $dataset) {
if ($dataset instanceof Dataset) {
$dataset->addRelatedIdentifiers($this->doiService);
}
}
}
}
}
}
}
4 changes: 3 additions & 1 deletion app/Jobs/ProcessProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Actions\Project\AssignIdentifier;
use App\Actions\Project\PublishProject;
use App\Actions\Project\UpdateDOI;
use App\Models\FileSystemObject;
use App\Models\Project;
use App\Notifications\DraftProcessedNotification;
Expand Down Expand Up @@ -45,7 +46,7 @@ public function __construct(Project $project)
*
* @return void
*/
public function handle(AssignIdentifier $assigner, PublishProject $publisher)
public function handle(AssignIdentifier $assigner, UpdateDOI $updater, PublishProject $publisher)
{
$project = $this->project;

Expand Down Expand Up @@ -109,6 +110,7 @@ public function handle(AssignIdentifier $assigner, PublishProject $publisher)
if ($release_date->isPast()) {
$publisher->publish($project);
}
$updater->update($project->fresh());

Notification::send($project->owner, new DraftProcessedNotification($project));
}
Expand Down
5 changes: 3 additions & 2 deletions app/Jobs/ProcessSubmission.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Actions\Project\AssignIdentifier;
use App\Actions\Project\PublishProject;
use App\Actions\Project\UpdateDOI;
use App\Actions\Study\PublishStudy;
use App\Events\StudyPublish;
use App\Models\FileSystemObject;
Expand Down Expand Up @@ -41,7 +42,7 @@ public function __construct(Project $project)
/**
* Execute the job.
*/
public function handle(AssignIdentifier $assigner, PublishProject $projectPublisher, PublishStudy $studyPublisher)
public function handle(AssignIdentifier $assigner, UpdateDOI $updater, PublishProject $projectPublisher, PublishStudy $studyPublisher)
{
$project = $this->project;

Expand Down Expand Up @@ -107,7 +108,7 @@ public function handle(AssignIdentifier $assigner, PublishProject $projectPublis
if ($release_date->isPast()) {
$projectPublisher->publish($project);
}

$updater->update($project->fresh());
ArchiveProject::dispatch($project);

$project->sendNotification('publish', $this->prepareSendList($project));
Expand Down
61 changes: 61 additions & 0 deletions app/Models/HasDOI.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,65 @@ public function getMetadata()

return $attributes;
}

public function addRelatedIdentifiers($doiService)
{
$attributes = $this->getMetadata();
if ($this instanceof Project) {
foreach ($this->studies as &$study) {
$relatedIdentifier = [
'relatedIdentifier' => $study->doi,
'relatedIdentifierType' => 'DOI',
'relationType' => 'HasPart',
];
array_push($attributes['relatedIdentifiers'], $relatedIdentifier);
foreach ($study->datasets as &$dataset) {
$relatedIdentifier = [
'relatedIdentifier' => $dataset->doi,
'relatedIdentifierType' => 'DOI',
'relationType' => 'HasPart',
];
array_push($attributes['relatedIdentifiers'], $relatedIdentifier);
}
}
$doiResponse = $doiService->updateDOI($this->doi, $attributes);
$this->datacite_schema = $doiResponse;
$this->save();

} elseif ($this instanceof Study) {
$relatedIdentifier = [
'relatedIdentifier' => $this->project->doi,
'relatedIdentifierType' => 'DOI',
'relationType' => 'IsPartOf',
];
array_push($attributes['relatedIdentifiers'], $relatedIdentifier);
foreach ($this->datasets as &$dataset) {
$relatedIdentifier = [
'relatedIdentifier' => $dataset->doi,
'relatedIdentifierType' => 'DOI',
'relationType' => 'HasPart',
];
array_push($attributes['relatedIdentifiers'], $relatedIdentifier);
}
$doiResponse = $doiService->updateDOI($this->doi, $attributes);
$this->datacite_schema = $doiResponse;
$this->save();
} elseif ($this instanceof Dataset) {
$relatedIdentifier = [
'relatedIdentifier' => $this->project->doi,
'relatedIdentifierType' => 'DOI',
'relationType' => 'IsPartOf',
];
array_push($attributes['relatedIdentifiers'], $relatedIdentifier);
$relatedIdentifier = [
'relatedIdentifier' => $this->study->doi,
'relatedIdentifierType' => 'DOI',
'relationType' => 'IsPartOf',
];
array_push($attributes['relatedIdentifiers'], $relatedIdentifier);
$doiResponse = $doiService->updateDOI($this->doi, $attributes);
$this->datacite_schema = $doiResponse;
$this->save();
}
}
}

0 comments on commit 0958388

Please sign in to comment.