Skip to content

Commit

Permalink
Merge pull request #1139 from NFDI4Chem/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
CS76 authored Jun 19, 2024
2 parents 1289149 + 7ba5fe7 commit 8ef7bb2
Show file tree
Hide file tree
Showing 26 changed files with 1,251 additions and 26 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);
}
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,6 @@ public function prepareExperiment($dataset)
$experiment = 'c13';
}
}

if ($experiment == 'proton') {
$experimentSchema = BioschemasHelper::prepareDefinedTerm('1H nuclear magnetic resonance spectroscopy', ['1H-NMR spectrometry', 'proton nuclear magnetic resonance spectroscopy', '1H-NMR spectroscopy', '1H-NMR', '1H NMR', '1H NMR spectroscopy', '1H nuclear magnetic resonance spectrometry', 'proton NMR'], 'CHMO:0000593', 'http://purl.obolibrary.org/obo/CHMO_0000593', $chmo);
} elseif ($experiment == 'c13') {
Expand Down Expand Up @@ -379,12 +378,12 @@ public function prepareNMRiumInfo($dataset)
$dimensionProperty = BioschemasHelper::preparePropertyValue('NMR spectrum by dimensionality', 'NMR:1000117', $dimension, null);
$probeNameProperty = BioschemasHelper::preparePropertyValue('NMR probe', 'OBI:0000516', $probeName, null);
//$experimentProperty = BioschemasHelper::preparePropertyValue('pulsed nuclear magnetic resonance spectroscopy', 'CHMO:0000613', $experiment, null);
$temperatureProperty = BioschemasHelper::preparePropertyValue('Temperature', 'NCIT:C25206', $temperature, 'https://ontobee.org/ontology/UO?iri=http://purl.obolibrary.org/obo/UO_0000012');
$temperatureProperty = BioschemasHelper::preparePropertyValue('Temperature', 'NCIT:C25206', $temperature, 'http://purl.obolibrary.org/obo/UO_0000012');
$baseFrequencyProperty = BioschemasHelper::preparePropertyValue('irradiation frequency', 'NMR:1400026', $baseFrequency, 'http://purl.obolibrary.org/obo/UO_0000325');
$fieldStrengthProperty = BioschemasHelper::preparePropertyValue('magnetic field strength', 'MR:1400253', $fieldStrength, 'http://purl.obolibrary.org/obo/UO_0000228');
$numberOfScansProperty = BioschemasHelper::preparePropertyValue('number of scans', 'NMR:1400087', $numberOfScans, 'scans');
$pulseSequenceProperty = BioschemasHelper::preparePropertyValue('nuclear magnetic resonance pulse sequence', 'CHMO:0001841', $pulseSequence, null);
$spectralWidthProperty = BioschemasHelper::preparePropertyValue('Spectral Width', 'NCIT:C156496', $spectralWidth, null); //todo: add unit
$spectralWidthProperty = BioschemasHelper::preparePropertyValue('Spectral Width', 'NCIT:C156496', $spectralWidth, 'http://purl.obolibrary.org/obo/UO_0000169');
$numberOfPointsProperty = BioschemasHelper::preparePropertyValue('number of data points', 'NMR:1000176', $numberOfPoints, 'points');
$relaxationTimeProperty = BioschemasHelper::preparePropertyValue('relaxation time measurement', 'FIX:0000202', $relaxationTime, 'http://purl.obolibrary.org/obo/UO_0000010');

Expand Down
37 changes: 37 additions & 0 deletions app/Http/Controllers/API/Schemas/DataCite/DOIController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace App\Http\Controllers\API\Schemas\DataCite;

use App\Http\Controllers\Controller;
use App\Services\DOI\DOIService;
use Illuminate\Http\Request;

class DOIController extends Controller
{
/**
* Create a new class instance.
*
* @param App\Services\DOI\DOIService $doiService
* @return void
*/
public function __construct(DOIService $doiService)
{
$this->doiService = $doiService;
}

/**
* Update Model's DataCite metadata
*
* @param Illuminate\Http\Request $request
* @param string $identifier
* @return void
*/
public function update(Request $request, $identifier)
{
$resolvedModel = resolveIdentifier($identifier);
$model = $resolvedModel['model'];

// Call the updateDOI function
$model->updateDOIMetadata($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
80 changes: 79 additions & 1 deletion app/Models/HasDOI.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,25 @@ public function generateDOI($doiService)
}
}

public function updateDOI($doiService)
/**
* Update Model's DataCite metadata
*
* @param mixed $doiService
* @return void
*/
public function updateDOIMetadata($doiService)
{
$doi_host = env('DOI_HOST', null);

if (! is_null($doi_host)) {
$doi = $this->doi;
if ($doi !== null) {
$attributes = $this->getMetadata();
$doiResponse = $doiService->updateDOI($doi, $attributes);
$this->datacite_schema = $doiResponse;
$this->save();
}
}
}

public function getIdentifier($model, $key)
Expand Down Expand Up @@ -230,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();
}
}
}
2 changes: 1 addition & 1 deletion app/Services/DOI/DOIService.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public function createDOI($suffix, $attributes = []);

public function getDOI($doi);

public function updateDOI($doi);
public function updateDOI($doi, $attributes = []);

public function deleteDOI($doi);

Expand Down
30 changes: 28 additions & 2 deletions app/Services/DOI/DataCite.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,35 @@ public function createDOI($suffix, $metadata = [])
return json_decode($contents, true);
}

public function updateDOI($doi)
/**
* Update DataCite metadata based on DOI
*
* @param string $doi
* @param array $metadata
* @return array $contents
*/
public function updateDOI($doi, $metadata = [])
{
return 'Datacite';
foreach ($metadata as $key => $value) {
$attributes[$key] = $value;
}

$body = [
'data' => [
'type' => 'dois',
'attributes' => $attributes,
],
];

$response = $this->client->put('/dois/'.urlencode($doi),
[RequestOptions::JSON => $body]
);

$stream = $response->getBody();
$contents = $stream->getContents();
$contents = json_decode($contents, true);

return $contents;
}

public function deleteDOI($doi)
Expand Down
Binary file added public/img/about1.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/about2.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/about3.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/about4.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/about5.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/ct.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/gpauli.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/jl.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/journals.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/jw.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/lp.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/ph.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/uic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 8ef7bb2

Please sign in to comment.