Skip to content

Commit

Permalink
Merge branch 'development' of https://github.com/NFDI4Chem/nmrxiv int…
Browse files Browse the repository at this point in the history
…o issue-#601
  • Loading branch information
NishaSharma14 committed Nov 14, 2023
2 parents 76bbace + 40d147b commit ac1542b
Show file tree
Hide file tree
Showing 115 changed files with 8,742 additions and 1,862 deletions.
146 changes: 81 additions & 65 deletions app/Actions/Project/AssignIdentifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
namespace App\Actions\Project;

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

class AssignIdentifier
{
Expand All @@ -21,83 +23,97 @@ public function __construct(DOIService $doiService)
}

/**
* Archive the given project.
* Archive the given model.
*
* @param mixed $project
* @param mixed $model
* @return void
*/
public function assign($project)
public function assign($model)
{
$projectIdentifier = $project->identifier ? $project->identifier : null;

if ($projectIdentifier == null) {
$projectTicker = Ticker::whereType('project')->first();
$projectIdentifier = $projectTicker->index + 1;
$projectTicker->index = $projectIdentifier;
$projectTicker->save();

$project->identifier = $projectIdentifier;
$project->save();
$project->fresh()->generateDOI($this->doiService);
$project = null;
$studies = null;
if ($model instanceof Project) {
$project = $model;
} elseif ($model instanceof Collection) {
$studies = $model;
}

$studies = $project->studies;
foreach ($studies as $study) {
$studyIdentifier = $study->identifier ? $study->identifier : null;

if ($studyIdentifier == null) {
$studyTicker = Ticker::whereType('study')->first();
$studyIdentifier = $studyTicker->index + 1;
$study->identifier = $studyIdentifier;
$studyTicker->index = $studyIdentifier;
$studyTicker->save();
}
$study->save();
$study->generateDOI($this->doiService);
if ($project) {
$projectIdentifier = $project->identifier ? $project->identifier : null;

$sample = $study->sample;
$sampleIdentifier = $sample->identifier ? $sample->identifier : null;
if ($projectIdentifier == null) {
$projectTicker = Ticker::whereType('project')->first();
$projectIdentifier = $projectTicker->index + 1;
$projectTicker->index = $projectIdentifier;
$projectTicker->save();

if ($sampleIdentifier == null) {
$sampleTicker = Ticker::whereType('sample')->first();
$sampleIdentifier = $sampleTicker->index + 1;
$sample->identifier = $sampleIdentifier;
$sample->save();

$sampleTicker->index = $sampleIdentifier;
$sampleTicker->save();
$project->identifier = $projectIdentifier;
$project->save();
$project->fresh()->generateDOI($this->doiService);
}

$molecules = $sample->molecules;

foreach ($molecules as $molecule) {
$moleculeIdentifier = $molecule->identifier ? $molecule->identifier : null;
if ($moleculeIdentifier == null) {
$moleculeTicker = Ticker::whereType('molecule')->first();
$moleculeIdentifier = $moleculeTicker->index + 1;
$molecule->identifier = $moleculeIdentifier;
$molecule->save();

$moleculeTicker->index = $moleculeIdentifier;
$moleculeTicker->save();
}
}

$datasets = $study->datasets;
foreach ($datasets as $dataset) {
$dsIdentifier = $dataset->identifier ? $dataset->identifier : null;

if ($dsIdentifier == null) {
$dsTicker = Ticker::whereType('dataset')->first();
$dsIdentifier = $dsTicker->index + 1;
$dataset->identifier = $dsIdentifier;
$studies = $project->studies;
}

$dsTicker->index = $dsIdentifier;
$dsTicker->save();
if ($studies) {
foreach ($studies as $study) {
if ($study instanceof Study) {
$studyIdentifier = $study->identifier ? $study->identifier : null;
if ($studyIdentifier == null) {
$studyTicker = Ticker::whereType('study')->first();
$studyIdentifier = $studyTicker->index + 1;
$study->identifier = $studyIdentifier;
$studyTicker->index = $studyIdentifier;
$studyTicker->save();
}
$study->save();
$study->generateDOI($this->doiService);

$sample = $study->sample;
$sampleIdentifier = $sample->identifier ? $sample->identifier : null;

if ($sampleIdentifier == null) {
$sampleTicker = Ticker::whereType('sample')->first();
$sampleIdentifier = $sampleTicker->index + 1;
$sample->identifier = $sampleIdentifier;
$sample->save();

$sampleTicker->index = $sampleIdentifier;
$sampleTicker->save();
}

$molecules = $sample->molecules;

foreach ($molecules as $molecule) {
$moleculeIdentifier = $molecule->identifier ? $molecule->identifier : null;
if ($moleculeIdentifier == null) {
$moleculeTicker = Ticker::whereType('molecule')->first();
$moleculeIdentifier = $moleculeTicker->index + 1;
$molecule->identifier = $moleculeIdentifier;
$molecule->save();

$moleculeTicker->index = $moleculeIdentifier;
$moleculeTicker->save();
}
}

$datasets = $study->datasets;
foreach ($datasets as $dataset) {
$dsIdentifier = $dataset->identifier ? $dataset->identifier : null;

if ($dsIdentifier == null) {
$dsTicker = Ticker::whereType('dataset')->first();
$dsIdentifier = $dsTicker->index + 1;
$dataset->identifier = $dsIdentifier;

$dsTicker->index = $dsIdentifier;
$dsTicker->save();
}

$dataset->save();
$dataset->generateDOI($this->doiService);
}
}

$dataset->save();
$dataset->generateDOI($this->doiService);
}
}
}
Expand Down
12 changes: 7 additions & 5 deletions app/Actions/Project/UpdateProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function update(Project $project, array $input)
];
Validator::make($input, [
'name' => ['required', 'string', 'max:255', Rule::unique('projects')
->where('owner_id', $input['owner_id'])->ignore($project->id), ],
->where('owner_id', $project->owner_id)->ignore($project->id), ],
'description' => ['required', 'string', 'min:20'],
'license' => ['required_if:is_public,"true"'],
], $errorMessages)->validate();
Expand Down Expand Up @@ -69,9 +69,11 @@ public function update(Project $project, array $input)
'access_type' => array_key_exists('access_type', $input)
? $input['access_type']
: 'viewer',
'team_id' => $input['team_id'],
'owner_id' => $input['owner_id'],
'team_id' => array_key_exists('team_id', $input) ? $input['team_id'] : $project->team_id,
'owner_id' => array_key_exists('owner_id', $input) ? $input['owner_id'] : $project->owner_id,
'license_id' => $license_id,
'species' => array_key_exists('species', $input) ? $input['species'] : $project->species,
'release_date' => $release_date,
'project_photo_path' => $s3filePath ? $s3filePath : $project->project_photo_path,
])
->save();
Expand All @@ -87,7 +89,7 @@ public function update(Project $project, array $input)
$study->license_id = $license_id;
}
}

$study->release_date = $release_date;
$study->save();

$datasets = $study->datasets;
Expand All @@ -97,7 +99,7 @@ public function update(Project $project, array $input)
$dataset->license_id = $license_id;
}
}

$dataset->release_date = $release_date;
$dataset->save();
}
}
Expand Down
25 changes: 25 additions & 0 deletions app/Actions/Study/PublishStudy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace App\Actions\Study;

use App\Models\Study;

class PublishStudy
{
/**
* Publish the given study.
*
* @param mixed $study
* @return void
*/
public function publish($study)
{
$study->is_public = true;
$study->save();
$datasets = $study->datasets;
foreach ($datasets as $dataset) {
$dataset->is_public = true;
$dataset->save();
}
}
}
1 change: 1 addition & 0 deletions app/Actions/Study/UpdateStudy.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public function update(Study $study, array $input)
'location' => array_key_exists('location', $input) ? $input['location'] : $study->location,
'url' => array_key_exists('url', $input) ? $input['url'] : $study->url,
'type' => array_key_exists('type', $input) ? $input['type'] : $study->type,
'species' => array_key_exists('species', $input) ? $input['species'] : $study->species,
'access' => array_key_exists('access', $input) ? $input['access'] : 'restricted',
'access_type' => array_key_exists('access_type', $input) ? $input['access_type'] : 'viewer',
'is_public' => array_key_exists('is_public', $input) ? $input['is_public'] : $study->is_public,
Expand Down
46 changes: 46 additions & 0 deletions app/Console/Commands/ArchiveData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace App\Console\Commands;

use App\Jobs\ArchiveProject;
use App\Jobs\ArchiveStudy;
use App\Models\Project;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;

class ArchiveData extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'nmrxiv:archive-data';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';

/**
* Execute the console command.
*/
public function handle()
{
return DB::transaction(function () {
$projects = Project::where([
['is_public', true],
['download_url', null],
])->get();

foreach ($projects as $project) {
echo $project->identifier;
echo "\r\n";
ArchiveProject::dispatch($project);
ArchiveStudy::dispatch($project);
}
});
}
}
19 changes: 15 additions & 4 deletions app/Console/Commands/AssignDOIs.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

namespace App\Console\Commands;

use App\Actions\Project\AssignIdentifier;
use App\Models\Project;
use App\Services\DOI\DOIService;
use App\Models\Study;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;

Expand All @@ -28,17 +29,27 @@ class AssignDOIs extends Command
*
* @return int
*/
public function handle(DOIService $doiService)
public function handle(AssignIdentifier $assigner)
{
return DB::transaction(function () use ($doiService) {
return DB::transaction(function () use ($assigner) {
$projects = Project::where([
['is_public', true],
['doi', null],
])->get();

foreach ($projects as $project) {
$projectDOI = $project->doi ? $project->doi : null;
$project->generateDOI($doiService);
$assigner->assign($project);
}

$studies = Study::where([
['is_public', true],
['doi', null],
])->get();

foreach ($studies as $study) {
$studyDOI = $study->doi ? $study->doi : null;
$assigner->assign(collect([$study]));
}
});
}
Expand Down
Loading

0 comments on commit ac1542b

Please sign in to comment.