Skip to content

Commit

Permalink
Merge pull request #391 from NFDI4Chem/development
Browse files Browse the repository at this point in the history
v1.6.0-alpha - Development merge into production
  • Loading branch information
NishaSharma14 authored Aug 26, 2022
2 parents 11808b2 + 45ba82b commit c6b9cf8
Show file tree
Hide file tree
Showing 29 changed files with 1,995 additions and 47 deletions.
7 changes: 7 additions & 0 deletions app/Actions/Project/UpdateProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,11 @@ public function updateAuthors(Project $project, $authors)
$authors
);
}

public function updateCitation(Project $project, $citations, $user)
{
$project->citations()->syncWithPivotValues(
$citations,['user' => $user->id]
);
}
}
136 changes: 136 additions & 0 deletions app/Http/Controllers/API/Bioschema/BiochemaController.php
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;
}
}
}
36 changes: 36 additions & 0 deletions app/Http/Controllers/CitationController.php
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');
}
}
6 changes: 3 additions & 3 deletions app/Http/Controllers/ProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function publicProjectView(Request $request, $owner, $slug)

if ($tab == 'info') {
return Inertia::render('Public/Project/Show', [
'project' => (new ProjectResource($project))->lite(false, ['users', 'authors']),
'project' => (new ProjectResource($project))->lite(false, ['users', 'authors', 'citations']),
'tab' => $tab,
]);
} elseif ($tab == 'studies') {
Expand Down Expand Up @@ -69,7 +69,7 @@ public function publicProjectView(Request $request, $owner, $slug)
]);
} else {
return Inertia::render('Public/Project/Show', [
'project' => (new ProjectResource($project))->lite(false, ['users', 'authors']),
'project' => (new ProjectResource($project))->lite(false, ['users', 'authors', 'citations']),
'tab' => 'info',
]);
}
Expand Down Expand Up @@ -110,7 +110,7 @@ public function show(Request $request, Project $project, GetLicense $getLicense)
}

return Inertia::render('Project/Show', [
'project' => $project->load('projectInvitations', 'tags', 'authors'),
'project' => $project->load('projectInvitations', 'tags', 'authors', 'citations'),
'team' => $team ? $team->load(['users', 'owner']) : null,
'members' => $project->allUsers(),
'availableRoles' => array_values(Jetstream::$roles),
Expand Down
1 change: 1 addition & 0 deletions app/Http/Controllers/StudyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ public function moleculeDetach(Request $request, Study $study, Molecule $molecul
$sample = $study->sample;
$sample->molecules()->detach([$molecule->id]);
$sample = $sample->fresh();

return $sample->molecules;
}
}
Expand Down
1 change: 1 addition & 0 deletions app/Http/Middleware/HandleInertiaRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public function share(Request $request)
'MEILISEARCH_PUBLICKEY' => (env('MEILISEARCH_PUBLICKEY')),
'SCOUT_PREFIX' => (env('SCOUT_PREFIX')),
'getDetailsbyDOIApi' => (env('GET_DETAILS_BY_DOI_API')),
'getCitationbyDOIApi' => (env('GET_CITATION_BY_DOI_API')),
]);
}
}
25 changes: 25 additions & 0 deletions app/Http/Resources/CitationResource.php
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,
];
}
}
2 changes: 1 addition & 1 deletion app/Http/Resources/LicenseResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ public function toArray($request)
'body' => $this->body,
];
}
}
}
12 changes: 11 additions & 1 deletion app/Http/Resources/ProjectResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class ProjectResource extends JsonResource
{
private bool $lite = true;

private array $properties = ['users', 'studies', 'files', 'authors'];
private array $properties = ['users', 'studies', 'files', 'authors', 'citations'];

public function lite(bool $lite, array $properties): self
{
Expand Down Expand Up @@ -94,6 +94,16 @@ function () {
];
}
),
$this->mergeWhen(
in_array('citations', $this->properties),
function () {
return [
'citations' => CitationResource::collection(
$this->citations
),
];
}
),
];
}),
];
Expand Down
17 changes: 17 additions & 0 deletions app/Models/Bioschema/BioSchema.php
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();
}
}
Loading

0 comments on commit c6b9cf8

Please sign in to comment.