-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'development' into feat-api-search-expansion
- Loading branch information
Showing
12 changed files
with
422 additions
and
4 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
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,50 @@ | ||
<?php | ||
|
||
namespace App\Actions\Coconut; | ||
|
||
use App\Models\Collection; | ||
use App\Models\Ticker; | ||
use App\Services\DOI\DOIService; | ||
|
||
class AssignDOI | ||
{ | ||
private $doiService; | ||
|
||
/** | ||
* Create a new class instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct(DOIService $doiService) | ||
{ | ||
$this->doiService = $doiService; | ||
} | ||
|
||
/** | ||
* Archive the given model. | ||
* | ||
* @param mixed $model | ||
* @return void | ||
*/ | ||
public function assign($model) | ||
{ | ||
$collection = null; | ||
if ($model instanceof Collection) { | ||
$collection = $model; | ||
} | ||
if ($collection) { | ||
$collectionIdentifier = $collection->identifier ? $collection->identifier : null; | ||
if ($collectionIdentifier == null) { | ||
$collectionTicker = Ticker::whereType('collection')->first(); | ||
$collectionIdentifier = $collectionTicker->index + 1; | ||
$collectionTicker->index = $collectionIdentifier; | ||
$collectionTicker->save(); | ||
|
||
$collection->identifier = $collectionIdentifier; | ||
$collection->save(); | ||
} | ||
$collection->fresh()->generateDOI($this->doiService); | ||
echo $collection->identifier."\r\n"; | ||
} | ||
} | ||
} |
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,45 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Actions\Coconut\AssignDOI; | ||
use App\Models\Collection; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Facades\DB; | ||
|
||
class AssignDOIs extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'coconut:collection-assign-doi'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Assigns dois to all unassigned public collections'; | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return int | ||
*/ | ||
public function handle(AssignDOI $assigner) | ||
{ | ||
return DB::transaction(function () use ($assigner) { | ||
$collections = Collection::where([ | ||
['is_public', true], | ||
['doi', null], | ||
])->get(); | ||
|
||
foreach ($collections as $collection) { | ||
$collectionDOI = $collection->doi ? $collection->doi : null; | ||
$assigner->assign($collection); | ||
} | ||
}); | ||
} | ||
} |
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,114 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
trait HasDOI | ||
{ | ||
public function generateDOI($doiService) | ||
{ | ||
$doi_host = env('DOI_HOST', null); | ||
if (! is_null($doi_host)) { | ||
$identifier = $this->getIdentifier($this, 'identifier'); | ||
if ($this->doi == null) { | ||
$url = 'https://coconut.naturalproducts.net/collections/'.$identifier; | ||
$attributes = $this->getMetadata(); | ||
$attributes['url'] = $url; | ||
$doiResponse = $doiService->createDOI($identifier, $attributes); | ||
$this->doi = $doiResponse['data']['id']; | ||
$this->datacite_schema = $doiResponse; | ||
$this->save(); | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
public function getIdentifier($model, $key) | ||
{ | ||
return $model->getAttributes()[$key]; | ||
} | ||
|
||
public function getMetadata() | ||
{ | ||
$title = $this->title; | ||
$creators = [ | ||
['name' => 'COCONUT', | ||
'nameType' => 'Organizational', ], | ||
]; | ||
$description = [ | ||
'description' => $this->description, | ||
'descriptionType' => 'Other', | ||
]; | ||
$relatedIdentifiers = [ | ||
[ | ||
'relatedIdentifier' => $this->url, | ||
'relatedIdentifierType' => 'URL', | ||
'relationType' => 'References', | ||
], | ||
]; | ||
$dates = [ | ||
[ | ||
'date' => $this->created_at, | ||
'dateType' => 'Available', | ||
], | ||
[ | ||
'date' => $this->created_at, | ||
'dateType' => 'Submitted', | ||
], | ||
[ | ||
'date' => $this->updated_at, | ||
'dateType' => 'Updated', | ||
], | ||
]; | ||
|
||
$rights = [ | ||
[ | ||
'rights' => 'Creative Commons Attribution 4.0 International', | ||
'rightsUri' => 'https://creativecommons.org/licenses/by/4.0/legalcode', | ||
'rightsIdentifier' => 'CC-BY-4.0', | ||
'rightsIdentifierScheme' => 'SPDX', | ||
'schemeUri' => 'https://spdx.org/licenses/', | ||
], | ||
]; | ||
$publicationYear = explode('-', $this->created_at)[0]; | ||
$subjects = [ | ||
['subject' => 'Natural Product', | ||
'subjectScheme' => 'NCI Thesaurus OBO Edition', | ||
'schemeURI' => 'http://purl.obolibrary.org/obo/ncit/releases/2022-08-19/ncit.owl', | ||
'valueURI' => 'http://purl.obolibrary.org/obo/NCIT_C66892', | ||
'classificationCode' => 'NCIT:C66892', | ||
], | ||
]; | ||
$attributes = [ | ||
'creators' => $creators, | ||
'titles' => [ | ||
[ | ||
'title' => $title, | ||
], | ||
], | ||
'dates' => $dates, | ||
'language' => 'en', | ||
'rightsList' => $rights, | ||
'descriptions' => [$description], | ||
'relatedIdentifiers' => $relatedIdentifiers, | ||
'resourceType' => 'Collection', | ||
'resourceTypeGeneral' => 'Collection', | ||
'publicationYear' => $publicationYear, | ||
'subjects' => $subjects, | ||
'types' => [ | ||
'ris' => 'DATA', | ||
'bibtex' => 'misc', | ||
'schemaOrg' => 'Collection', | ||
'resourceType' => 'Collection', | ||
'resourceTypeGeneral' => 'Collection', | ||
], | ||
'isActive' => true, | ||
'event' => 'publish', | ||
'state' => 'findable', | ||
'schemaVersion' => 'http://datacite.org/schema/kernel-4', | ||
|
||
]; | ||
|
||
return $attributes; | ||
} | ||
} |
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,24 @@ | ||
<?php | ||
|
||
namespace App\Providers; | ||
|
||
use App\Services\DOI\DataCite; | ||
use App\Services\DOI\DOIService; | ||
use Illuminate\Support\ServiceProvider; | ||
|
||
class DOIServiceProvider extends ServiceProvider | ||
{ | ||
/** | ||
* Register any application services. | ||
* | ||
* @return void | ||
*/ | ||
public function register() | ||
{ | ||
$this->app->bind(DOIService::class, function ($app) { | ||
return match (config('doi.default')) { | ||
'datacite' => new DataCite | ||
}; | ||
}); | ||
} | ||
} |
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,18 @@ | ||
<?php | ||
|
||
namespace App\Services\DOI; | ||
|
||
interface DOIService | ||
{ | ||
public function getDOIs(); | ||
|
||
public function createDOI($identifier, $attributes = []); | ||
|
||
public function getDOI($doi); | ||
|
||
public function updateDOI($doi); | ||
|
||
public function deleteDOI($doi); | ||
|
||
public function getDOIActivity($doi); | ||
} |
Oops, something went wrong.