From 4e44d9d996f3855ca5ddd47e7b17a5fb60cd7dfc Mon Sep 17 00:00:00 2001 From: Arno Kaimbacher Date: Wed, 19 May 2021 15:10:46 +0200 Subject: [PATCH] - all editor cano now updates DOI's in backend - composer updates --- .../{ => Publish}/DoiController.php | 135 +++++++++++++++--- .../Controllers/Publish/EditorController.php | 9 +- app/Models/DatasetIdentifier.php | 4 + app/Tethys/Utils/DoiClient.php | 1 + composer.lock | 96 ++++++------- .../views/settings/layouts/app.blade.php | 3 + resources/views/workflow/doi/edit.blade.php | 79 ++++++++++ resources/views/workflow/doi/index.blade.php | 55 +++++++ routes/web.php | 16 ++- 9 files changed, 325 insertions(+), 73 deletions(-) rename app/Http/Controllers/{ => Publish}/DoiController.php (53%) create mode 100644 resources/views/workflow/doi/edit.blade.php create mode 100644 resources/views/workflow/doi/index.blade.php diff --git a/app/Http/Controllers/DoiController.php b/app/Http/Controllers/Publish/DoiController.php similarity index 53% rename from app/Http/Controllers/DoiController.php rename to app/Http/Controllers/Publish/DoiController.php index b6769be..b25858a 100644 --- a/app/Http/Controllers/DoiController.php +++ b/app/Http/Controllers/Publish/DoiController.php @@ -1,26 +1,29 @@ doiClient = $DoiClient; - + $this->xml = new \DomDocument(); $this->proc = new \XSLTProcessor(); } @@ -49,11 +52,21 @@ class DoiController extends Controller /** * Display a listing of the resource. * - * @return \Illuminate\Http\Response + * @return \Illuminate\Contracts\View\View */ - public function index() + // public function index() + // { + // // + // } + public function index(): \Illuminate\Contracts\View\View { - // + $datasets = Dataset::query() + ->has('identifier') + ->orderBy('server_date_modified', 'desc') + ->get(); + return View::make('workflow.doi.index', [ + 'datasets' => $datasets, + ]); } /** @@ -63,7 +76,7 @@ class DoiController extends Controller */ public function create(Request $request) { - // + // } /** @@ -75,11 +88,11 @@ class DoiController extends Controller public function store(Request $request) { $dataId = $request->input('publish_id'); - - // Setup stylesheet - $this->loadStyleSheet(public_path() .'/prefixes/doi_datacite.xslt'); - // set timestamp + // Setup stylesheet + $this->loadStyleSheet(public_path() . '/prefixes/doi_datacite.xslt'); + + // set timestamp $date = new \DateTime(); $unixTimestamp = $date->getTimestamp(); $this->proc->setParameter('', 'unixTimestamp', $unixTimestamp); @@ -108,7 +121,7 @@ class DoiController extends Controller $this->xml->documentElement->appendChild($node); $xmlMeta = $this->proc->transformToXML($this->xml); // Log::alert($xmlMeta); - //create doiValue and correspunfing landingpage of tehtys + //create doiValue and correspunfing landingpage of tehtys $doiValue = $prefix . '/tethys.' . $dataset->publish_id; $appUrl = config('app.url'); $landingPageUrl = $appUrl . "/dataset/" . $dataset->publish_id; @@ -141,9 +154,19 @@ class DoiController extends Controller * @param \App\Models\DatasetIdentifier $doi * @return \Illuminate\Http\Response */ - public function edit(DatasetIdentifier $doi) + public function edit($id) { - // + $dataset = Dataset::query() + ->with([ + 'titles', + 'persons' => function ($query) { + $query->wherePivot('role', 'author'); + }, + ])->findOrFail($id); + + return View::make('workflow.doi.edit', [ + 'dataset' => $dataset, + ]); } /** @@ -153,9 +176,81 @@ class DoiController extends Controller * @param \App\Models\DatasetIdentifier $doi * @return \Illuminate\Http\Response */ - public function update(Request $request, DatasetIdentifier $doi) + public function update(Request $request, $publish_id) { - // + $dataId = $publish_id; //$request->input('publish_id'); + // Setup stylesheet + $this->loadStyleSheet(public_path() . '/prefixes/doi_datacite.xslt'); + + // set timestamp + $date = new \DateTime(); + $unixTimestamp = $date->getTimestamp(); + $this->proc->setParameter('', 'unixTimestamp', $unixTimestamp); + + $prefix = ""; + $base_domain = ""; + $datacite_environment = config('tethys.datacite_environment'); + if ($datacite_environment == "debug") { + $prefix = config('tethys.datacite_test_prefix'); + $base_domain = config('tethys.test_base_domain'); + } elseif ($datacite_environment == "production") { + $prefix = config('tethys.datacite_prefix'); + $base_domain = config('tethys.base_domain'); + } + // $prefix = config('tethys.datacite_prefix'); + $this->proc->setParameter('', 'prefix', $prefix); + + $repIdentifier = "tethys"; + $this->proc->setParameter('', 'repIdentifier', $repIdentifier); + + $this->xml->appendChild($this->xml->createElement('Datasets')); + $dataset = Dataset::where('publish_id', '=', $dataId)->firstOrFail(); + if (is_null($dataset)) { + throw new OaiModelException('Dataset is not available for registering DOI!', OaiModelError::NORECORDSMATCH); + } + $dataset->fetchValues(); + $xmlModel = new \App\Library\Xml\XmlModel(); + $xmlModel->setModel($dataset); + $xmlModel->excludeEmptyFields(); + $cache = ($dataset->xmlCache) ? $dataset->xmlCache : new \App\Models\XmlCache(); + $xmlModel->setXmlCache($cache); + $domNode = $xmlModel->getDomDocument()->getElementsByTagName('Rdr_Dataset')->item(0); + $node = $this->xml->importNode($domNode, true); + $this->addSpecInformation($node, 'data-type:' . $dataset->type); + + $this->xml->documentElement->appendChild($node); + $newXmlMeta = $this->proc->transformToXML($this->xml); + // Log::alert($xmlMeta); + //create doiValue and correspunfing landingpage of tehtys + $doiValue = $prefix . '/tethys.' . $dataset->publish_id; + + $response = $this->doiClient->updateMetadataForDoi($doiValue, $newXmlMeta); + // if operation successful, store dataste identifier + if ($response->getStatusCode() == 201) { + $doi = $dataset->identifier(); + // $doi['value'] = $doiValue; + // $doi['type'] = "doi"; + // $doi['status'] = "findable"; + // $doi->save(); + $doi->touch(); + return redirect() + ->route('publish.workflow.doi.index') + ->with('flash_message', 'You have successfully updated a DOI for the dataset!'); + + // if ($doi->save()) { + // // update server_date_modified for triggering nex xml cache (doi interface) + // $time = new \Illuminate\Support\Carbon(); + // $dataset->server_date_modified = $time; + // $dataset->save(); + // return redirect() + // ->route('publish.workflow.editor.index') + // ->with('flash_message', 'You have successfully created a DOI for the dataset!'); + // } + } else { + $message = 'unexpected DataCite MDS response code ' . $response->getStatusCode(); + // $this->log($message, 'err'); + throw new GeneralException($message); + } } /** @@ -169,9 +264,9 @@ class DoiController extends Controller // } - - + + /** * Load an xslt stylesheet. * diff --git a/app/Http/Controllers/Publish/EditorController.php b/app/Http/Controllers/Publish/EditorController.php index e55271c..10e1e80 100644 --- a/app/Http/Controllers/Publish/EditorController.php +++ b/app/Http/Controllers/Publish/EditorController.php @@ -635,7 +635,7 @@ class EditorController extends Controller * @param int $id * @return \Illuminate\View\View */ - public function doi($id): \Illuminate\Contracts\View\View + public function doiCreate($id): \Illuminate\Contracts\View\View { $dataset = Dataset::query() ->with([ @@ -714,9 +714,10 @@ class EditorController extends Controller $doi['status'] = "findable"; if ($doi->save()) { // update server_date_modified for triggering nex xml cache (doi interface) - $time = new \Illuminate\Support\Carbon(); - $dataset->server_date_modified = $time; - $dataset->save(); + // $time = new \Illuminate\Support\Carbon(); + // $dataset->server_date_modified = $time; + // $dataset->save(); + // dataset gets automatically updated because of touches array return redirect() ->route('publish.workflow.editor.index') ->with('flash_message', 'You have successfully created a DOI for the dataset!'); diff --git a/app/Models/DatasetIdentifier.php b/app/Models/DatasetIdentifier.php index 9f0c079..1bbe91f 100644 --- a/app/Models/DatasetIdentifier.php +++ b/app/Models/DatasetIdentifier.php @@ -8,6 +8,10 @@ class DatasetIdentifier extends Model { protected $table = 'dataset_identifiers'; protected $guarded = array(); + public $timestamps = true; + + //See the array called $touches? This is where you put all the relationships you want to get updated_at as soon as this Model is updated + protected $touches = ['dataset']; /** * The dataset that belong to the DocumentIdentifier. diff --git a/app/Tethys/Utils/DoiClient.php b/app/Tethys/Utils/DoiClient.php index 933e2b9..4d09bba 100644 --- a/app/Tethys/Utils/DoiClient.php +++ b/app/Tethys/Utils/DoiClient.php @@ -235,6 +235,7 @@ class DoiClient implements DoiInterface // $this->log($message, 'err'); throw new DoiClientException($message); } + return $response; } /** diff --git a/composer.lock b/composer.lock index c5ffb87..99144c4 100755 --- a/composer.lock +++ b/composer.lock @@ -221,16 +221,16 @@ }, { "name": "doctrine/cache", - "version": "1.11.0", + "version": "1.11.1", "source": { "type": "git", "url": "https://github.com/doctrine/cache.git", - "reference": "a9c1b59eba5a08ca2770a76eddb88922f504e8e0" + "reference": "163074496dc7c3c7b8ccbf3d4376c0187424ed81" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/cache/zipball/a9c1b59eba5a08ca2770a76eddb88922f504e8e0", - "reference": "a9c1b59eba5a08ca2770a76eddb88922f504e8e0", + "url": "https://api.github.com/repos/doctrine/cache/zipball/163074496dc7c3c7b8ccbf3d4376c0187424ed81", + "reference": "163074496dc7c3c7b8ccbf3d4376c0187424ed81", "shasum": "" }, "require": { @@ -300,7 +300,7 @@ ], "support": { "issues": "https://github.com/doctrine/cache/issues", - "source": "https://github.com/doctrine/cache/tree/1.11.0" + "source": "https://github.com/doctrine/cache/tree/1.11.1" }, "funding": [ { @@ -316,7 +316,7 @@ "type": "tidelift" } ], - "time": "2021-04-13T14:46:17+00:00" + "time": "2021-05-18T16:45:32+00:00" }, { "name": "doctrine/dbal", @@ -3016,16 +3016,16 @@ }, { "name": "symfony/console", - "version": "v4.4.23", + "version": "v4.4.24", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "1ab187ac21d41d7d34a4f529091a1f5d0bb2924f" + "reference": "1b15ca1b1bedda86f98064da9ff5d800560d4c6d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/1ab187ac21d41d7d34a4f529091a1f5d0bb2924f", - "reference": "1ab187ac21d41d7d34a4f529091a1f5d0bb2924f", + "url": "https://api.github.com/repos/symfony/console/zipball/1b15ca1b1bedda86f98064da9ff5d800560d4c6d", + "reference": "1b15ca1b1bedda86f98064da9ff5d800560d4c6d", "shasum": "" }, "require": { @@ -3085,7 +3085,7 @@ "description": "Eases the creation of beautiful and testable command line interfaces", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/console/tree/v4.4.23" + "source": "https://github.com/symfony/console/tree/v4.4.24" }, "funding": [ { @@ -3101,20 +3101,20 @@ "type": "tidelift" } ], - "time": "2021-05-10T12:53:15+00:00" + "time": "2021-05-13T06:28:07+00:00" }, { "name": "symfony/css-selector", - "version": "v5.2.7", + "version": "v5.2.9", "source": { "type": "git", "url": "https://github.com/symfony/css-selector.git", - "reference": "59a684f5ac454f066ecbe6daecce6719aed283fb" + "reference": "5d5f97809015102116208b976eb2edb44b689560" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/css-selector/zipball/59a684f5ac454f066ecbe6daecce6719aed283fb", - "reference": "59a684f5ac454f066ecbe6daecce6719aed283fb", + "url": "https://api.github.com/repos/symfony/css-selector/zipball/5d5f97809015102116208b976eb2edb44b689560", + "reference": "5d5f97809015102116208b976eb2edb44b689560", "shasum": "" }, "require": { @@ -3150,7 +3150,7 @@ "description": "Converts CSS selectors to XPath expressions", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/css-selector/tree/v5.3.0-BETA1" + "source": "https://github.com/symfony/css-selector/tree/v5.2.9" }, "funding": [ { @@ -3166,7 +3166,7 @@ "type": "tidelift" } ], - "time": "2021-04-07T16:07:52+00:00" + "time": "2021-05-16T13:07:46+00:00" }, { "name": "symfony/debug", @@ -3537,16 +3537,16 @@ }, { "name": "symfony/finder", - "version": "v4.4.23", + "version": "v4.4.24", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "67b77716f517e3f864759232e1201e7aa2ab0e82" + "reference": "a96bc19ed87c88eec78e1a4c803bdc1446952983" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/67b77716f517e3f864759232e1201e7aa2ab0e82", - "reference": "67b77716f517e3f864759232e1201e7aa2ab0e82", + "url": "https://api.github.com/repos/symfony/finder/zipball/a96bc19ed87c88eec78e1a4c803bdc1446952983", + "reference": "a96bc19ed87c88eec78e1a4c803bdc1446952983", "shasum": "" }, "require": { @@ -3578,7 +3578,7 @@ "description": "Finds files and directories via an intuitive fluent interface", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/finder/tree/v4.4.23" + "source": "https://github.com/symfony/finder/tree/v4.4.24" }, "funding": [ { @@ -3594,7 +3594,7 @@ "type": "tidelift" } ], - "time": "2021-05-09T09:13:09+00:00" + "time": "2021-05-16T12:27:45+00:00" }, { "name": "symfony/http-client-contracts", @@ -3744,16 +3744,16 @@ }, { "name": "symfony/http-kernel", - "version": "v4.4.23", + "version": "v4.4.24", "source": { "type": "git", "url": "https://github.com/symfony/http-kernel.git", - "reference": "95bb42312503a212f4467529bac8735f01226ff9" + "reference": "59925ee79f2541b4c6e990843e1a42768e898254" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-kernel/zipball/95bb42312503a212f4467529bac8735f01226ff9", - "reference": "95bb42312503a212f4467529bac8735f01226ff9", + "url": "https://api.github.com/repos/symfony/http-kernel/zipball/59925ee79f2541b4c6e990843e1a42768e898254", + "reference": "59925ee79f2541b4c6e990843e1a42768e898254", "shasum": "" }, "require": { @@ -3828,7 +3828,7 @@ "description": "Provides a structured process for converting a Request into a Response", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/http-kernel/tree/v4.4.23" + "source": "https://github.com/symfony/http-kernel/tree/v4.4.24" }, "funding": [ { @@ -3844,20 +3844,20 @@ "type": "tidelift" } ], - "time": "2021-05-12T13:13:32+00:00" + "time": "2021-05-19T12:12:19+00:00" }, { "name": "symfony/mime", - "version": "v5.2.7", + "version": "v5.2.9", "source": { "type": "git", "url": "https://github.com/symfony/mime.git", - "reference": "7af452bf51c46f18da00feb32e1ad36db9426515" + "reference": "64258e870f8cc75c3dae986201ea2df58c210b52" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/mime/zipball/7af452bf51c46f18da00feb32e1ad36db9426515", - "reference": "7af452bf51c46f18da00feb32e1ad36db9426515", + "url": "https://api.github.com/repos/symfony/mime/zipball/64258e870f8cc75c3dae986201ea2df58c210b52", + "reference": "64258e870f8cc75c3dae986201ea2df58c210b52", "shasum": "" }, "require": { @@ -3911,7 +3911,7 @@ "mime-type" ], "support": { - "source": "https://github.com/symfony/mime/tree/v5.2.7" + "source": "https://github.com/symfony/mime/tree/v5.2.9" }, "funding": [ { @@ -3927,7 +3927,7 @@ "type": "tidelift" } ], - "time": "2021-04-29T20:47:09+00:00" + "time": "2021-05-16T13:07:46+00:00" }, { "name": "symfony/polyfill-ctype", @@ -4640,16 +4640,16 @@ }, { "name": "symfony/routing", - "version": "v4.4.22", + "version": "v4.4.24", "source": { "type": "git", "url": "https://github.com/symfony/routing.git", - "reference": "049e7c5c41f98511959668791b4adc0898a821b3" + "reference": "b42c3631fd9e3511610afb2ba081ea7e38d9fa38" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/routing/zipball/049e7c5c41f98511959668791b4adc0898a821b3", - "reference": "049e7c5c41f98511959668791b4adc0898a821b3", + "url": "https://api.github.com/repos/symfony/routing/zipball/b42c3631fd9e3511610afb2ba081ea7e38d9fa38", + "reference": "b42c3631fd9e3511610afb2ba081ea7e38d9fa38", "shasum": "" }, "require": { @@ -4708,7 +4708,7 @@ "url" ], "support": { - "source": "https://github.com/symfony/routing/tree/v4.4.22" + "source": "https://github.com/symfony/routing/tree/v4.4.24" }, "funding": [ { @@ -4724,7 +4724,7 @@ "type": "tidelift" } ], - "time": "2021-04-11T12:59:39+00:00" + "time": "2021-05-16T09:52:47+00:00" }, { "name": "symfony/service-contracts", @@ -4807,16 +4807,16 @@ }, { "name": "symfony/translation", - "version": "v4.4.23", + "version": "v4.4.24", "source": { "type": "git", "url": "https://github.com/symfony/translation.git", - "reference": "ff6e63c7b5de874464642969968f61f8dc649ac3" + "reference": "424d29dfcc15575af05196de0100d7b52f650602" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/translation/zipball/ff6e63c7b5de874464642969968f61f8dc649ac3", - "reference": "ff6e63c7b5de874464642969968f61f8dc649ac3", + "url": "https://api.github.com/repos/symfony/translation/zipball/424d29dfcc15575af05196de0100d7b52f650602", + "reference": "424d29dfcc15575af05196de0100d7b52f650602", "shasum": "" }, "require": { @@ -4875,7 +4875,7 @@ "description": "Provides tools to internationalize your application", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/translation/tree/v4.4.23" + "source": "https://github.com/symfony/translation/tree/v4.4.24" }, "funding": [ { @@ -4891,7 +4891,7 @@ "type": "tidelift" } ], - "time": "2021-04-28T06:59:52+00:00" + "time": "2021-05-16T09:52:47+00:00" }, { "name": "symfony/translation-contracts", diff --git a/resources/views/settings/layouts/app.blade.php b/resources/views/settings/layouts/app.blade.php index b7199ee..1f26189 100644 --- a/resources/views/settings/layouts/app.blade.php +++ b/resources/views/settings/layouts/app.blade.php @@ -107,6 +107,9 @@
  • EDITOR PAGE: Released datasets
  • +
  • + DOI UPDATE LIST +
  • @endpermission @permission('dataset-review-list')
  • diff --git a/resources/views/workflow/doi/edit.blade.php b/resources/views/workflow/doi/edit.blade.php new file mode 100644 index 0000000..e0ddced --- /dev/null +++ b/resources/views/workflow/doi/edit.blade.php @@ -0,0 +1,79 @@ +@extends('settings.layouts.app') +@section('content') +
    +

    + Publish reviewed dataset +

    +
    + +
    + +
    +
    + + + BACK + +
    +
    + + {!! Form::model($dataset, [ 'method' => 'POST', 'route' => ['publish.workflow.doi.update', + $dataset->publish_id], + 'id' => 'doiUpdateForm', 'class' => 'pure-form', 'enctype' => 'multipart/form-data', 'v-on:submit.prevent' => + 'checkForm']) + !!} +
    + + +

    Selected Dataset

    + + + + + + + +
    {{ $dataset->id }} + @foreach($dataset->titles as $title) +
    + {{ $title->value }} +
    + @endforeach +
    + @foreach($dataset->persons as $author) + {{ $author->full_name }} + @endforeach +
    + +
    + +
    + {!! Form::label('publisher_name', 'Publisher Name') !!} + {!! Form::text('publisher_name', 'Geologische Bundesanstalt (GBA)', ['readonly', 'class' => + 'pure-u-23-24', ]) !!} +
    +
    +

    + Are you sure you want to update the DOI for the selected dataset? +

    + +
    + +
    + +
    + + + {!! Form::close() !!} +
    +
    + +
    + + +@stop +@section('after-scripts') +@stop \ No newline at end of file diff --git a/resources/views/workflow/doi/index.blade.php b/resources/views/workflow/doi/index.blade.php new file mode 100644 index 0000000..fca537f --- /dev/null +++ b/resources/views/workflow/doi/index.blade.php @@ -0,0 +1,55 @@ +@extends('settings.layouts.app') +@section('content') +
    +

    + DOI LIST:update registerede DOI datasets +

    +
    + +
    +
    + + + + + + + + + + + + @foreach($datasets as $dataset) + + + + + + + @endforeach + + +
    Dataset TitleTethys IDServer StateDate of last modification
    + @if ($dataset->titles()->first()) + {{ $dataset->titles()->first()->value }} + @else + no title + @endif + + {{ $dataset->publish_id }} + + {{ $dataset->server_state }} + + {{ $dataset->server_date_modified }} + + @if ($dataset->server_state == "published") + + + Update DOI + + @endif +
    +
    +
    + +@stop \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index 76e7239..fd85abc 100644 --- a/routes/web.php +++ b/routes/web.php @@ -141,13 +141,27 @@ Route::group( ]); Route::get('workflow/editor/doi/{id}', [ 'middleware' => ['permission:dataset-publish'], - 'as' => 'workflow.editor.doi', 'uses' => 'EditorController@doi', + 'as' => 'workflow.editor.doi', 'uses' => 'EditorController@doiCreate', ]); Route::post('workflow/editor/doi/{publish_id}', [ 'middleware' => ['permission:dataset-publish'], 'as' => 'workflow.editor.doiStore', 'uses' => 'EditorController@doiStore', ]); + //doi + Route::get('workflow/doi/index', [ + 'middleware' => ['permission:dataset-editor-list'], + 'as' => 'workflow.doi.index', 'uses' => 'DoiController@index', + ]); + Route::get('workflow/doi/edit/{id}', [ + 'middleware' => ['permission:dataset-publish'], + 'as' => 'workflow.doi.edit', 'uses' => 'DoiController@edit', + ]); + Route::post('workflow/doi/update/{publish_id}', [ + 'middleware' => ['permission:dataset-publish'], + 'as' => 'workflow.doi.update', 'uses' => 'DoiController@update', + ]); + //reviewer Route::get('workflow/review/index', [ 'middleware' => ['permission:dataset-review-list'],