Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Doi metadata versioning enhancement #1176

Open
wants to merge 3 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/Actions/Project/UpdateDOI.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ public function update($model)
}

if ($project) {
$project->addRelatedIdentifiers($this->doiService);
$project->updateDOIMetadata($this->doiService);
$studies = $project->studies;
}
if ($studies) {
foreach ($studies as $study) {
if ($study instanceof Study) {
$study->addRelatedIdentifiers($this->doiService);
$study->updateDOIMetadata($this->doiService);
$datasets = $study->datasets;
foreach ($datasets as $dataset) {
if ($dataset instanceof Dataset) {
$dataset->addRelatedIdentifiers($this->doiService);
$dataset->updateDOIMetadata($this->doiService);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion app/Actions/Project/UpdateProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public function update(Project $project, array $input)
Validator::make($input, [
'name' => ['required', 'string', 'max:255', Rule::unique('projects')
->where('owner_id', $project->owner_id)->ignore($project->id), ],
'description' => ['required_if:is_public,"true"', 'min:20'],
'license' => ['required_if:is_public,"true"'],
], $errorMessages)->validate();

Expand Down Expand Up @@ -107,7 +108,7 @@ public function update(Project $project, array $input)
$validation = $project->validation;

if (! $validation) {
$validation = new Validation();
$validation = new Validation;
$validation->save();
$project->validation()->associate($validation);
$project->save();
Expand Down
2 changes: 1 addition & 1 deletion app/Actions/Study/UpdateStudy.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function update(Study $study, array $input)
$license_id = $licenseExists ? $input['license_id'] : $study->license_id;

if ($is_public == true) {
$release_date = Carbon::now()->timestamp;
$release_date = $study->release_date;

$sample = $study->sample;
$sampleIdentifier = $sample->identifier ? $sample->identifier : null;
Expand Down
3 changes: 0 additions & 3 deletions app/Console/Commands/UpdateDOI.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,13 @@ public function handle()
foreach ($study->datasets as $dataset) {
echo $dataset->identifier."\r\n";
$dataset->updateDOIMetadata($this->doiService);
$dataset->addRelatedIdentifiers($this->doiService);
}
$study->updateDOIMetadata($this->doiService);
$study->addRelatedIdentifiers($this->doiService);
}

foreach ($projects as $project) {
echo $project->identifier."\r\n";
$project->updateDOIMetadata($this->doiService);
$project->addRelatedIdentifiers($this->doiService);
}
}
}
31 changes: 29 additions & 2 deletions app/Http/Controllers/ProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use App\Models\Study;
use App\Models\User;
use App\Models\Validation;
use App\Services\DOI\DOIService;
use Auth;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Contracts\Auth\StatefulGuard;
Expand All @@ -31,6 +32,29 @@

class ProjectController extends Controller
{
/**
* The DOI service instance.
*
* @var \App\Services\DOI\DOIService
*/
protected $doiService;

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

public function publicProjectView(Request $request, $owner, $slug)
{
$user = User::where('username', $owner)->firstOrFail();
Expand Down Expand Up @@ -274,7 +298,7 @@ public function validation(Request $request, Project $project)
$validation = $project->validation;

if (! $validation) {
$validation = new Validation();
$validation = new Validation;
$validation->save();
$project->validation()->associate($validation);
$project->save();
Expand Down Expand Up @@ -302,7 +326,7 @@ public function validationReport(Request $request, Project $project)
$validation = $project->validation;

if (! $validation) {
$validation = new Validation();
$validation = new Validation;
$validation->save();
$project->validation()->associate($validation);
$project->save();
Expand Down Expand Up @@ -414,6 +438,9 @@ public function update(Request $request, UpdateProject $updater, Project $projec
}

$updater->update($project, $request->all());
if ($project->is_public) {
$project->updateDOIMetadata($this->doiService);
}

return $request->wantsJson() ? new JsonResponse('', 200) : back()->with('success', 'Project updated successfully');
}
Expand Down
27 changes: 27 additions & 0 deletions app/Http/Controllers/StudyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use App\Models\Project;
use App\Models\Sample;
use App\Models\Study;
use App\Services\DOI\DOIService;
use Auth;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Contracts\Auth\StatefulGuard;
Expand All @@ -28,6 +29,29 @@

class StudyController extends Controller
{
/**
* The DOI service instance.
*
* @var \App\Services\DOI\DOIService
*/
protected $doiService;

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

public function publicStudiesView(Request $request)
{
$moleculeId = $request->get('compound');
Expand Down Expand Up @@ -68,6 +92,9 @@ public function update(Request $request, UpdateStudy $updater, Study $study)
$study = $study->fresh();

$study->load(['datasets', 'sample.molecules', 'tags']);
if ($study->is_public) {
$study->updateDOIMetadata($this->doiService);
}

return $request->wantsJson()
? new JsonResponse($study, 200)
Expand Down
123 changes: 57 additions & 66 deletions app/Models/HasDOI.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,59 @@ public function updateDOIMetadata($doiService)
$doi = $this->doi;
if ($doi !== null) {
$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);
}
}
} elseif ($this instanceof Study) {
if ($this->project) {
$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);
}
} elseif ($this instanceof Dataset) {
if ($this->project) {
$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($doi, $attributes);
$this->datacite_schema = $doiResponse;
$this->save();
Expand Down Expand Up @@ -134,6 +187,10 @@ public function getMetadata()
if ($this->project) {
$authors = $this->project->authors ? $this->project->authors : [];
$citations = $this->project->citations ? $this->project->citations : [];
foreach ($this->tags as &$tag) {
$keyword = $tag->name;
array_push($keywords, $keyword);
}
}

} elseif ($this instanceof Dataset) {
Expand Down Expand Up @@ -247,70 +304,4 @@ 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) {
if ($this->project) {
$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) {
if ($this->project) {
$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/Policies/ProjectPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function createProject(User $user)
*/
public function updateProject(User $user, Project $project)
{
if ($project->is_public || $project->is_archived || $project->is_deleted || $project->is_published) {
if ($project->is_archived || $project->is_deleted) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion app/Policies/StudyPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function createStudy(User $user)
*/
public function updateStudy(User $user, Study $study)
{
if ($study->is_public || $study->is_archived || $study->is_deleted || $study->is_published || (! $study->is_published && $study->doi)) {
if ($study->is_archived || $study->is_deleted) {
return false;
}

Expand Down
Loading