From 3c50618c8a32c4afc27263e52f421d9337d67452 Mon Sep 17 00:00:00 2001 From: Arno Kaimbacher Date: Mon, 10 Dec 2018 17:26:57 +0100 Subject: [PATCH] first test datacite schema --- .../Controllers/Oai/RequestController.php | 72 ++++----- app/Models/{ => Oai}/OaiModelError.php | 2 +- app/Models/Oai/ResumptionToken.php | 152 ++++++++++++++++++ app/Models/Person.php | 1 + composer.lock | 100 ++++++++++-- .../{oai-pmh.xslt => datasetxml2oai-pmh.xslt} | 141 +++++++++++----- public/xsl/{oai2.xslt => oai2_style.xslt} | 34 ++-- .../views/settings/person/_form.blade.php | 8 + 8 files changed, 411 insertions(+), 99 deletions(-) rename app/Models/{ => Oai}/OaiModelError.php (97%) create mode 100644 app/Models/Oai/ResumptionToken.php rename public/{oai-pmh.xslt => datasetxml2oai-pmh.xslt} (75%) rename public/xsl/{oai2.xslt => oai2_style.xslt} (96%) diff --git a/app/Http/Controllers/Oai/RequestController.php b/app/Http/Controllers/Oai/RequestController.php index 30f69d2..fc8ed6e 100644 --- a/app/Http/Controllers/Oai/RequestController.php +++ b/app/Http/Controllers/Oai/RequestController.php @@ -7,8 +7,9 @@ use App\Models\Dataset; use Illuminate\Support\Facades\Log; use App\Exceptions\OaiModelException; use Illuminate\Database\Eloquent\ModelNotFoundException; -use App\Models\OaiModelError; - +use App\Models\Oai\OaiModelError; +use App\Models\Oai\ResumptionToken; + class RequestController extends Controller { /** @@ -18,6 +19,7 @@ class RequestController extends Controller * @var array */ private $deliveringDocumentStates = array('published', 'deleted'); // maybe deleted documents too + private $xMetaDissRestriction = array('doctoralthesis', 'habilitation'); const SET_SPEC_PATTERN = '[A-Za-z0-9\-_\.!~\*\'\(\)]+'; @@ -102,7 +104,7 @@ class RequestController extends Controller private function __handleRequest(array $oaiRequest) { // Setup stylesheet - $this->loadStyleSheet('oai-pmh.xslt'); + $this->loadStyleSheet('datasetxml2oai-pmh.xslt'); // Set response time $this->_proc->setParameter('', 'responseDate', date("Y-m-d\TH:i:s\Z")); @@ -143,18 +145,18 @@ class RequestController extends Controller private function handleIdentify() { $email = "repository@geologie.ac.at"; - $repositoryName = "Data Research Repository"; + $repositoryName = "RDR - Data Research Repository"; $repIdentifier = "rdr.gba.ac.at"; - //$sampleIdentifier = $this->_configuration->getSampleIdentifier(); + $sampleIdentifier = "oai:" . $repIdentifier . ":27";//$this->_configuration->getSampleIdentifier(); $earliestDateFromDb = Dataset::earliestPublicationDate(); // set parameters for oai-pmh.xslt $this->_proc->setParameter('', 'email', $email); $this->_proc->setParameter('', 'repositoryName', $repositoryName); $this->_proc->setParameter('', 'repIdentifier', $repIdentifier); - //$this->_proc->setParameter('', 'sampleIdentifier', $sampleIdentifier); + $this->_proc->setParameter('', 'sampleIdentifier', $sampleIdentifier); $this->_proc->setParameter('', 'earliestDatestamp', $earliestDateFromDb); - $this->_xml->appendChild($this->_xml->createElement('Documents')); + $this->_xml->appendChild($this->_xml->createElement('Datasets')); } /** @@ -186,13 +188,11 @@ class RequestController extends Controller if (is_null($dataset) //or (false === in_array($dataset->getServerState(), $this->_deliveringDocumentStates)) or (false === $dataset->whereIn('server_state', $this->deliveringDocumentStates)) - - or (false === $dataset->hasEmbargoPassed())) { throw new OaiModelException('Document is not available for OAI export!', OaiModelError::NORECORDSMATCH); } - $this->_xml->appendChild($this->_xml->createElement('Documents')); + $this->_xml->appendChild($this->_xml->createElement('Datasets')); $this->createXmlRecord($dataset); } @@ -208,15 +208,6 @@ class RequestController extends Controller $dataId = null; switch ($identifierParts[0]) { - // case 'urn': - // //$finder = new Opus_DocumentFinder(); - // $finder = Dataset::query(); - // // $finder->setIdentifierTypeValue('urn', $oaiIdentifier); - // // $finder->setServerStateInList($this->_deliveringDocumentStates); - // $finder->whereIn('server_state', $this->deliveringDocumentStates); - // $docIds = $finder->ids(); - // $docId = $docIds[0]; - // break; case 'oai': if (isset($identifierParts[2])) { $dataId = $identifierParts[2]; @@ -251,7 +242,7 @@ class RequestController extends Controller */ private function handleListMetadataFormats() { - $this->_xml->appendChild($this->_xml->createElement('Documents')); + $this->_xml->appendChild($this->_xml->createElement('Datasets')); } /** @@ -274,7 +265,7 @@ class RequestController extends Controller */ private function handleListIdentifiers(array &$oaiRequest) { - $maxIdentifier = 20;//$this->_configuration->getMaxListIdentifiers(); + $maxIdentifier = 5;//$this->_configuration->getMaxListIdentifiers(); $this->handlingOfLists($oaiRequest, $maxIdentifier); } @@ -288,7 +279,7 @@ class RequestController extends Controller { $repIdentifier = "rdr.gba.ac.at"; $this->_proc->setParameter('', 'repIdentifier', $repIdentifier); - $this->_xml->appendChild($this->_xml->createElement('Documents')); + $this->_xml->appendChild($this->_xml->createElement('Datasets')); //$oaiSets = new Oai_Model_Sets(); $sets = array( @@ -336,9 +327,12 @@ class RequestController extends Controller if (true === empty($maxRecords)) { $maxRecords = 100; } + $repIdentifier = "rdr.gba.ac.at"; + $tokenTempPath = storage_path('app/resumption'); //$this->_configuration->getResumptionTokenPath(); + $this->_proc->setParameter('', 'repIdentifier', $repIdentifier); - $this->_xml->appendChild($this->_xml->createElement('Documents')); + $this->_xml->appendChild($this->_xml->createElement('Datasets')); // do some initialisation $cursor = 0; @@ -352,21 +346,27 @@ class RequestController extends Controller } $this->_proc->setParameter('', 'oai_metadataPrefix', $metadataPrefix); - // no resumptionToken is given - $finder = Dataset::query(); - // add server state restrictions - $finder->whereIn('server_state', $this->deliveringDocumentStates); - if (array_key_exists('set', $oaiRequest)) { - $setarray = explode(':', $oaiRequest['set']); - if ($setarray[0] == 'doc-type') { - if (count($setarray) === 2 and !empty($setarray[1])) { - $finder->where('type', $setarray[1]); + // parameter resumptionToken is given + if (false === empty($oaiRequest['resumptionToken'])) { + $tokenWorker = new ResumptionToken(); + $resParam = $oaiRequest['resumptionToken']; + } else { + // no resumptionToken is given + $finder = Dataset::query(); + // add server state restrictions + $finder->whereIn('server_state', $this->deliveringDocumentStates); + if (array_key_exists('set', $oaiRequest)) { + $setarray = explode(':', $oaiRequest['set']); + if ($setarray[0] == 'data-type') { + if (count($setarray) === 2 and !empty($setarray[1])) { + $finder->where('type', $setarray[1]); + } } } + $totalIds = $finder->count(); + $reldocIds = $finder->pluck('id')->toArray(); } - $totalIds = $finder->count(); - $reldocIds = $finder->pluck('id')->toArray(); // handling of document ids $restIds = $reldocIds; @@ -401,7 +401,7 @@ class RequestController extends Controller //$node->appendChild($child); //$type = $dataset->type; - $this->addSpecInformation($node, 'doc-type:' . $dataset->type); + $this->addSpecInformation($node, 'data-type:' . $dataset->type); //$this->addSpecInformation($node, 'bibliography:' . 'false'); $this->_xml->documentElement->appendChild($node); @@ -472,7 +472,7 @@ class RequestController extends Controller continue; } - $setSpec = 'doc-type:' . $doctype; + $setSpec = 'data-type:' . $doctype; // $count = $row['count']; $sets[$setSpec] = "Set for document type '$doctype'"; } diff --git a/app/Models/OaiModelError.php b/app/Models/Oai/OaiModelError.php similarity index 97% rename from app/Models/OaiModelError.php rename to app/Models/Oai/OaiModelError.php index 784d613..5dabd23 100644 --- a/app/Models/OaiModelError.php +++ b/app/Models/Oai/OaiModelError.php @@ -1,6 +1,6 @@ _documentIds; + } + + /** + * Returns metadata prefix information. + * + * @return string + */ + public function getMetadataPrefix() + { + return $this->_metadataPrefix; + } + + /** + * Return setted resumption id after successful storing of resumption token. + * + * @return string Returns resumption id + */ + public function getResumptionId() + { + return $this->_resumptionId; + } + + /** + * Returns start position. + * + * @return in + */ + public function getStartPosition() + { + return $this->_startPosition; + } + + /** + * Returns total number of document ids for this request + * + * @return int + */ + public function getTotalIds() + { + return $this->_totalIds; + } + + /** + * Set document ids for this token. + * + * @param $idsToStore Set of document ids to store. + * @return void + */ + public function setDocumentIds($idsToStore) + { + if (false === is_array($idsToStore)) { + $idsToStore = array($idsToStore); + } + + $this->_documentIds = $idsToStore; + } + + /** + * Set metadata prefix information. + * + * @param string $prefix + * @return void + */ + public function setMetadataPrefix($prefix) + { + $this->_metadataPrefix = $prefix; + } + + /** + * Set resumption id + * + * @return void + */ + public function setResumptionId($resumptionId) + { + $this->_resumptionId = $resumptionId; + } + + /** + * Set postion where to start on next request. + * + * @param $startPostion Positon where to start on next request + * @return void + */ + public function setStartPosition($startPosition) + { + $this->_startPosition = (int) $startPosition; + } + + /** + * Set count of document ids for this request. + * + * @return void + */ + public function setTotalIds($totalIds) + { + $this->_totalIds = (int) $totalIds; + } +} diff --git a/app/Models/Person.php b/app/Models/Person.php index e4d8a68..3e3833a 100644 --- a/app/Models/Person.php +++ b/app/Models/Person.php @@ -15,6 +15,7 @@ class Person extends Model 'email', 'identifier_orcid', 'status', + 'name_type' ]; protected $table = 'persons'; public $timestamps = false; diff --git a/composer.lock b/composer.lock index 73cb738..76f72d4 100755 --- a/composer.lock +++ b/composer.lock @@ -1815,17 +1815,85 @@ "time": "2018-11-26T12:48:07+00:00" }, { - "name": "symfony/css-selector", - "version": "v4.1.8", + "name": "symfony/contracts", + "version": "v1.0.1", "source": { "type": "git", - "url": "https://github.com/symfony/css-selector.git", - "reference": "9e4dc57949853315561f0cd5eb84d0707465502a" + "url": "https://github.com/symfony/contracts.git", + "reference": "3edf0ab943d1985a356721952cba36ff31bd6e5f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/css-selector/zipball/9e4dc57949853315561f0cd5eb84d0707465502a", - "reference": "9e4dc57949853315561f0cd5eb84d0707465502a", + "url": "https://api.github.com/repos/symfony/contracts/zipball/3edf0ab943d1985a356721952cba36ff31bd6e5f", + "reference": "3edf0ab943d1985a356721952cba36ff31bd6e5f", + "shasum": "" + }, + "require": { + "php": "^7.1.3" + }, + "require-dev": { + "psr/cache": "^1.0", + "psr/container": "^1.0" + }, + "suggest": { + "psr/cache": "When using the Cache contracts", + "psr/container": "When using the Service contracts", + "symfony/cache-contracts-implementation": "", + "symfony/service-contracts-implementation": "", + "symfony/translation-contracts-implementation": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Contracts\\": "" + }, + "exclude-from-classmap": [ + "**/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "A set of abstractions extracted out of the Symfony components", + "homepage": "https://symfony.com", + "keywords": [ + "abstractions", + "contracts", + "decoupling", + "interfaces", + "interoperability", + "standards" + ], + "time": "2018-11-24T09:35:08+00:00" + }, + { + "name": "symfony/css-selector", + "version": "v4.2.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/css-selector.git", + "reference": "aa9fa526ba1b2ec087ffdfb32753803d999fcfcd" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/css-selector/zipball/aa9fa526ba1b2ec087ffdfb32753803d999fcfcd", + "reference": "aa9fa526ba1b2ec087ffdfb32753803d999fcfcd", "shasum": "" }, "require": { @@ -1834,7 +1902,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.1-dev" + "dev-master": "4.2-dev" } }, "autoload": { @@ -1865,7 +1933,7 @@ ], "description": "Symfony CssSelector Component", "homepage": "https://symfony.com", - "time": "2018-11-11T19:51:29+00:00" + "time": "2018-11-11T19:52:12+00:00" }, { "name": "symfony/debug", @@ -2482,20 +2550,21 @@ }, { "name": "symfony/translation", - "version": "v4.1.8", + "version": "v4.2.0", "source": { "type": "git", "url": "https://github.com/symfony/translation.git", - "reference": "615e3cf75d00a7d6788316d9631957991ba9c26a" + "reference": "ff9a878c9b8f8bcd4d9138e2d32f508c942773d9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/translation/zipball/615e3cf75d00a7d6788316d9631957991ba9c26a", - "reference": "615e3cf75d00a7d6788316d9631957991ba9c26a", + "url": "https://api.github.com/repos/symfony/translation/zipball/ff9a878c9b8f8bcd4d9138e2d32f508c942773d9", + "reference": "ff9a878c9b8f8bcd4d9138e2d32f508c942773d9", "shasum": "" }, "require": { "php": "^7.1.3", + "symfony/contracts": "^1.0", "symfony/polyfill-mbstring": "~1.0" }, "conflict": { @@ -2503,6 +2572,9 @@ "symfony/dependency-injection": "<3.4", "symfony/yaml": "<3.4" }, + "provide": { + "symfony/translation-contracts-implementation": "1.0" + }, "require-dev": { "psr/log": "~1.0", "symfony/config": "~3.4|~4.0", @@ -2520,7 +2592,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.1-dev" + "dev-master": "4.2-dev" } }, "autoload": { @@ -2547,7 +2619,7 @@ ], "description": "Symfony Translation Component", "homepage": "https://symfony.com", - "time": "2018-11-26T10:26:29+00:00" + "time": "2018-11-27T07:20:32+00:00" }, { "name": "symfony/var-dumper", diff --git a/public/oai-pmh.xslt b/public/datasetxml2oai-pmh.xslt similarity index 75% rename from public/oai-pmh.xslt rename to public/datasetxml2oai-pmh.xslt index d096f38..9e9a3e2 100644 --- a/public/oai-pmh.xslt +++ b/public/datasetxml2oai-pmh.xslt @@ -43,7 +43,7 @@ - type="text/xsl" href="xsl/oai2.xslt" + type="text/xsl" href="xsl/oai2_style.xslt" - - - - @@ -80,22 +76,22 @@ - + - + - + - + - + - + @@ -103,7 +99,7 @@ - + @@ -148,7 +144,7 @@ - + @@ -161,22 +157,36 @@ http://www.openarchives.org/OAI/2.0/oai_dc/ + + + + oai_datacite + + + http://schema.datacite.org/meta/kernel-4.1/metadata.xsd + + + http://datacite.org/schema/kernel-4 + + + - + - - - - - - - + + + + + + + + @@ -198,27 +208,27 @@ - + - + + + + + + + + - - - - - + + + + + @@ -275,6 +285,9 @@ + + + @@ -282,14 +295,65 @@ - - + + + + + + oai: + + : + + + + + + + + + + + + + + + + + + + + + , + + + + ( + + ) + + + + + + + + + + GBA + + + @@ -389,12 +453,13 @@ + - doc-type: + data-type: diff --git a/public/xsl/oai2.xslt b/public/xsl/oai2_style.xslt similarity index 96% rename from public/xsl/oai2.xslt rename to public/xsl/oai2_style.xslt index ee31732..211632f 100644 --- a/public/xsl/oai2.xslt +++ b/public/xsl/oai2_style.xslt @@ -1,6 +1,7 @@ + + + + + + metadataNamespace + + + + schema + + diff --git a/resources/views/settings/person/_form.blade.php b/resources/views/settings/person/_form.blade.php index ac3e89d..e537cfb 100644 --- a/resources/views/settings/person/_form.blade.php +++ b/resources/views/settings/person/_form.blade.php @@ -37,6 +37,14 @@ orcid is optional. +
+ {!! Form::label('name_type', 'Name Type') !!} +
+ {!! Form::select('name_type', ['personal' => 'personal', 'organizational' => 'organizational'], null, ['id' => 'name_type', 'placeholder' => '-- no name type --']) !!} +
+ name type is optional +
+
Status of person