Skip to content

Commit

Permalink
Merge branch 'development' into feat-api-search-expansion
Browse files Browse the repository at this point in the history
  • Loading branch information
sriramkanakam87 committed Dec 3, 2024
2 parents beadcb8 + a3b1b5f commit 8cb0379
Show file tree
Hide file tree
Showing 12 changed files with 422 additions and 4 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ COCONUT infrastructure code is licensed under the MIT license - see the [LICENSE

### COCONUT 2.0
- Venkata Chandrasekhar, Kohulan Rajan, Sri Ram Sagar Kanakam, Nisha Sharma, Viktor Weißenborn, Jonas Schaub, Christoph Steinbeck, COCONUT 2.0: a comprehensive overhaul and curation of the collection of open natural products database, Nucleic Acids Research, 2024;, gkae1063, https://doi.org/10.1093/nar/gkae1063

https://doi.org/10.1093/nar/gkae1063

### COCONUT (Legacy)
- Sorokina, M., Merseburger, P., Rajan, K. et al. (2021). COCONUT online: COlleCtion of Open Natural prodUcTs database. *Journal of Cheminformatics*, 13, 2.
Expand Down
50 changes: 50 additions & 0 deletions app/Actions/Coconut/AssignDOI.php
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";
}
}
}
4 changes: 3 additions & 1 deletion app/Console/Commands/AssignCollectionsIdentifiers.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ public function handle()

public function generateIdentifier($index)
{
return 'CNPC'.str_pad($index, 4, '0', STR_PAD_LEFT);
$prefix = (env('APP_ENV') === 'production') ? 'CNPC' : 'CNPC_DEV';

return $prefix.str_pad($index, 6, '0', STR_PAD_LEFT);
}

public function fetchLastIndex()
Expand Down
45 changes: 45 additions & 0 deletions app/Console/Commands/AssignDOIs.php
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);
}
});
}
}
2 changes: 2 additions & 0 deletions app/Models/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

class Collection extends Model implements Auditable, HasMedia
{
use HasDOI;
use HasFactory;
use HasTags;
use InteractsWithMedia;
Expand All @@ -41,6 +42,7 @@ protected static function booted()
'image',
'status',
'release_date',
'datacite_schema',
];

/**
Expand Down
114 changes: 114 additions & 0 deletions app/Models/HasDOI.php
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;
}
}
24 changes: 24 additions & 0 deletions app/Providers/DOIServiceProvider.php
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
};
});
}
}
18 changes: 18 additions & 0 deletions app/Services/DOI/DOIService.php
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);
}
Loading

0 comments on commit 8cb0379

Please sign in to comment.