diff --git a/app/Actions/Project/UpdateDOI.php b/app/Actions/Project/UpdateDOI.php index e58d11bd..cf5e64a7 100644 --- a/app/Actions/Project/UpdateDOI.php +++ b/app/Actions/Project/UpdateDOI.php @@ -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); } } } diff --git a/app/Actions/Project/UpdateProject.php b/app/Actions/Project/UpdateProject.php index 712721c3..526e671b 100644 --- a/app/Actions/Project/UpdateProject.php +++ b/app/Actions/Project/UpdateProject.php @@ -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(); @@ -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(); diff --git a/app/Actions/Study/UpdateStudy.php b/app/Actions/Study/UpdateStudy.php index 5fc4ff16..c3a75822 100644 --- a/app/Actions/Study/UpdateStudy.php +++ b/app/Actions/Study/UpdateStudy.php @@ -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; diff --git a/app/Console/Commands/UpdateDOI.php b/app/Console/Commands/UpdateDOI.php index 807aedc8..1f292c73 100644 --- a/app/Console/Commands/UpdateDOI.php +++ b/app/Console/Commands/UpdateDOI.php @@ -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); } } } diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index b8267610..167689f5 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -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; @@ -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(); @@ -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(); @@ -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(); @@ -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'); } diff --git a/app/Http/Controllers/StudyController.php b/app/Http/Controllers/StudyController.php index a1532198..f7f30bbe 100644 --- a/app/Http/Controllers/StudyController.php +++ b/app/Http/Controllers/StudyController.php @@ -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; @@ -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'); @@ -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) diff --git a/app/Models/HasDOI.php b/app/Models/HasDOI.php index 626206ff..7943534c 100644 --- a/app/Models/HasDOI.php +++ b/app/Models/HasDOI.php @@ -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(); @@ -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) { @@ -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(); - } - } } diff --git a/app/Policies/ProjectPolicy.php b/app/Policies/ProjectPolicy.php index 54ad2b6b..dac51186 100644 --- a/app/Policies/ProjectPolicy.php +++ b/app/Policies/ProjectPolicy.php @@ -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; } diff --git a/app/Policies/StudyPolicy.php b/app/Policies/StudyPolicy.php index a3b3f309..26b10f5a 100644 --- a/app/Policies/StudyPolicy.php +++ b/app/Policies/StudyPolicy.php @@ -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; } diff --git a/resources/js/Pages/Project/Partials/Details.vue b/resources/js/Pages/Project/Partials/Details.vue index 1c6550db..585cbcc0 100644 --- a/resources/js/Pages/Project/Partials/Details.vue +++ b/resources/js/Pages/Project/Partials/Details.vue @@ -330,7 +330,7 @@ " /> -