-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #391 from NFDI4Chem/development
v1.6.0-alpha - Development merge into production
- Loading branch information
Showing
29 changed files
with
1,995 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
app/Http/Controllers/API/Bioschema/BiochemaController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\API\Bioschema; | ||
|
||
use App\Http\Controllers\Controller; | ||
use Illuminate\Http\Request; | ||
use Spatie\SchemaOrg\Schema; | ||
use App\Models\Bioschema\BioSchema; | ||
use App\Models\Project; | ||
use App\Models\Study; | ||
use App\Models\Dataset; | ||
use App\Models\Bioschema\Study as StudySchema; | ||
use App\Models\User; | ||
use App\Models\Author; | ||
|
||
|
||
|
||
class BiochemaController extends Controller | ||
{ | ||
public function schema(Request $request, $username, $projectName, $studyName = null, $datasetName = null) | ||
{ | ||
$user = User::where('username', $username)->firstOrFail(); | ||
if($user){ | ||
$project = Project::where([['slug', $projectName], ['owner_id', $user->id]])->firstOrFail(); | ||
} | ||
if($project){ | ||
$creativeWork = Schema::creativeWork(); | ||
$creativeWork['@id'] = 'https://bioschemas.org/profiles/Study/0.2-DRAFT'; | ||
$confromsTo = []; | ||
$confromsTo['http://purl.org/dc/terms/conformsTo'] = $creativeWork; | ||
|
||
|
||
$projectSchema = Schema::Project(); | ||
$projectSchema['@id']= $project->uuid; | ||
$projectSchema['dct:conformsTo'] = $confromsTo; | ||
$authors = []; | ||
foreach ($project->authors as &$author) { | ||
$authorSchema = Schema::Person(); | ||
$authorSchema-> givenName($author->given_name); | ||
$authorSchema->familyName($author->family_name); | ||
$authorSchema->identifier($author->orcid_id); | ||
$authorSchema-> email($author->email_id); | ||
$authorSchema-> affiliation($author->affiliation); | ||
array_push($authors, $authorSchema); | ||
} | ||
$projectSchema['author'] = $authors; | ||
$projectSchema->datePublished($project->release_date); | ||
$projectSchema->description($project->description); | ||
$projectSchema->name($project->name); | ||
$projectSchema->dateCreated($project->created_at); | ||
$tags = []; | ||
foreach ($project->tags as &$tag) { | ||
$tag = $tag->name; | ||
array_push($tags, $tag); | ||
} | ||
$projectSchema->keywords($tags); | ||
$projectSchema->url($project->public_url); | ||
$projectSchema->license($project->license->url); | ||
|
||
$studies = []; | ||
foreach ($project->studies as &$study) { | ||
$studySchema = BioSchema::Study(); | ||
$studySchema->name($study->name); | ||
$studySchema->url($study->public_url); | ||
|
||
$datasets = []; | ||
foreach ($study->datasets as &$dataset) { | ||
$datasetSchema = Schema::Dataset(); | ||
$datasetSchema->name($dataset->name); | ||
$datasetSchema->url($dataset->public_url); | ||
array_push($datasets, $datasetSchema); | ||
} | ||
$studySchema->hasPart($datasets); | ||
array_push($studies, $studySchema); | ||
} | ||
$projectSchema->hasPart($studies); | ||
|
||
if($studyName){ | ||
// send study back with project info added to it\ | ||
$study = Study::where([['slug', $studyName], ['owner_id', $user->id], ['project_id', $project->id]])->firstOrFail(); | ||
if($study){ | ||
$studySchema = BioSchema::Study(); | ||
$studySchema['@id']= $study->uuid; | ||
$studySchema['dct:conformsTo'] = $confromsTo; | ||
$studySchema->name($study->name); | ||
$studySchema->description($study->description); | ||
$tags = []; | ||
foreach ($study->tags as &$tag) { | ||
$tag = $tag->name; | ||
array_push($tags, $tag); | ||
} | ||
$studySchema->keywords($tags); | ||
$studySchema->url($study->public_url); | ||
$studySchema->license($study->license->url); | ||
$datasets = []; | ||
foreach ($study->datasets as &$dataset) { | ||
$datasetSchema = Schema::Dataset(); | ||
$datasetSchema->name($dataset->name); | ||
$datasetSchema->url($dataset->public_url); | ||
array_push($datasets, $datasetSchema); | ||
} | ||
$studySchema->hasPart($datasets); | ||
$projectSchema->relatedStudy($studySchema); | ||
|
||
|
||
if($datasetName){ | ||
$dataset = Dataset::where([['slug', $datasetName], ['owner_id', $user->id], ['project_id', $project->id], ['study_id', $study->id]])->firstOrFail(); | ||
// send dataset with project and study details | ||
if($dataset){ | ||
$dataCatalog = Schema::dataCatalog(); | ||
$dataCatalog->name(env('APP_NAME')); | ||
$dataCatalog->url('https://nmrxiv.org'); | ||
|
||
$creativeWorkDataset = Schema::creativeWork(); | ||
$creativeWorkDataset['@id'] = 'https://bioschemas.org/profiles/Dataset/1.0-RELEASE'; | ||
$DatasetconfromsTo = []; | ||
$DatasetconfromsTo['http://purl.org/dc/terms/conformsTo'] = $creativeWorkDataset; | ||
$datasetSchema = Schema::Dataset(); | ||
$datasetSchema['@id']= $dataset->uuid; | ||
$datasetSchema['dct:conformsTo'] = $DatasetconfromsTo; | ||
$datasetSchema->description($dataset->description); | ||
$datasetSchema->name($dataset->name); | ||
$datasetSchema->url($dataset->public_url); | ||
$datasetSchema->license($study->license->url); | ||
$datasetSchema->includedInDataCatalog($dataCatalog); | ||
$datasetSchema->measurementTechnique("https://terminology.nfdi4chem.de/ts/ontologies/chmo/terms?iri=http%3A%2F%2Fpurl.obolibrary.org%2Fobo%2FCHMO_0000591"); | ||
$datasetSchema->isPartOf([$projectSchema]); | ||
return $datasetSchema; | ||
} | ||
} | ||
} | ||
} | ||
return $projectSchema; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
|
||
use App\Actions\Project\UpdateProject; | ||
use App\Models\Citation; | ||
use App\Models\Project; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\DB; | ||
|
||
class CitationController extends Controller | ||
{ | ||
public function updateCitation(Request $request, UpdateProject $updater, Project $project) | ||
{ | ||
$input = $request->citationList; | ||
$user = $request->user(); | ||
//dd($request->citationList); | ||
//DB transaction | ||
$citations = []; | ||
|
||
foreach ($input as $item) { | ||
$citation = Citation::create([ | ||
'doi' => array_key_exists('doi', $item) ? $item['doi'] : null, | ||
'title' => array_key_exists('title', $item) ? $item['title'] : null, | ||
'authors' => array_key_exists('authors', $item) ? $item['authors'] : null, | ||
'abstract' => array_key_exists('abstract', $item) ? $item['abstract'] : null, | ||
'citation_text' => array_key_exists('citation_text', $item) ? $item['citation_text'] : null, | ||
]); | ||
array_push($citations, $citation->id); | ||
} | ||
$updater->updateCitation($project, $citations, $user); | ||
|
||
return $request->wantsJson() ? new JsonResponse('', 200) : back()->with('success', 'Citation updated successfully'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace App\Http\Resources; | ||
|
||
use Illuminate\Http\Resources\Json\JsonResource; | ||
|
||
class CitationResource extends JsonResource | ||
{ | ||
/** | ||
* Transform the resource into an array. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable | ||
*/ | ||
public function toArray($request) | ||
{ | ||
return [ | ||
'doi' => $this->doi, | ||
'title' => $this->title, | ||
'authors' => $this->authors, | ||
'abstract' => $this->abstract, | ||
'citation_text' => $this->citation_text, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,4 +25,4 @@ public function toArray($request) | |
'body' => $this->body, | ||
]; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace App\Models\Bioschema; | ||
|
||
use App\Models\Bioschema\Study; | ||
use \Spatie\SchemaOrg\Schema; | ||
|
||
/** | ||
* Factory class for all Schema.org types. | ||
*/ | ||
class BioSchema extends Schema | ||
{ | ||
public static function study(): Study | ||
{ | ||
return new Study(); | ||
} | ||
} |
Oops, something went wrong.