Skip to content

Commit

Permalink
Merge pull request #26 from OPUS4/4.6.3
Browse files Browse the repository at this point in the history
OPUSVIER-3894 OPUS 4 Framework 4.6.3 Release
  • Loading branch information
j3nsch authored Jun 11, 2018
2 parents b38fb11 + 93056bb commit 48ed01d
Show file tree
Hide file tree
Showing 44 changed files with 5,203 additions and 52 deletions.
2 changes: 2 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,12 @@
</target>

<target name="phpunit-fast" depends="create-database">
<tstamp />
<exec executable="${bindir}/phpunit" dir="${basedir}/tests" failonerror="on">
<arg line="--log-junit ${basedir}/build/logs/phpunit.xml" />
<arg line="--configuration phpunit.xml" />
<arg value="${testpath}" />
<redirector output="build/testresult-${DSTAMP}-${TSTAMP}.txt" alwayslog="true" />
</exec>
</target>

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"homepage": "http://opus4.kobv.de",
"require": {
"zendframework/zendframework1": "1.12.*",
"solarium/solarium": "3.4.*"
"solarium/solarium": "3.4.*",
"opus4-repo/opus4-doi": "4.6.2"
},
"autoload": {
"psr-0": {
Expand All @@ -28,7 +29,6 @@
"phpunit/phpunit-selenium": "1.4.2",
"doctrine/instantiator": "1.0.5",
"phploc/phploc": "*",
"phpdocumentor/phpdocumentor": "2.*",
"phpmd/phpmd" : "2.4.3",
"sebastian/phpcpd": "*",
"mayflower/php-codebrowser": "~1.1",
Expand Down
14 changes: 14 additions & 0 deletions db/schema/009-doi_support.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
START TRANSACTION;

-- Add two columns to document_identifiers for DOI support

ALTER TABLE `document_identifiers`
ADD `status` ENUM('registered', 'verified') NULL COMMENT 'DOI registration status',
ADD `registration_ts` TIMESTAMP NULL COMMENT 'timestamp of DOI registration';

-- Update database version

TRUNCATE TABLE `schema_version`;
INSERT INTO `schema_version` (`version`) VALUES (9);

COMMIT;
4 changes: 3 additions & 1 deletion db/schema/opus4schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ CREATE TABLE IF NOT EXISTS `opus_version` (
-- The values are generated through svn checkin.
-- Do not edit here.
-- -----------------------------------------------------
INSERT INTO `schema_version` (`version`) VALUES (8);
INSERT INTO `schema_version` (`version`) VALUES (9);

-- -----------------------------------------------------
-- Table `documents`
Expand Down Expand Up @@ -74,6 +74,8 @@ CREATE TABLE IF NOT EXISTS `document_identifiers` (
`document_id` INT UNSIGNED NOT NULL COMMENT 'Foreign key to: documents.documents_id.' ,
`type` ENUM('doi', 'handle', 'urn', 'std-doi', 'url', 'cris-link', 'splash-url', 'isbn', 'issn', 'opus3-id', 'opac-id', 'uuid', 'serial', 'old', 'pmid', 'arxiv') NOT NULL COMMENT 'Type of the identifier.' ,
`value` TEXT NOT NULL COMMENT 'Value of the identifier.' ,
`status` ENUM('registered', 'verified') NULL COMMENT 'DOI registration status' ,
`registration_ts` TIMESTAMP NULL COMMENT 'timestamp of DOI registration' ,
PRIMARY KEY (`id`) ,
INDEX `fk_document_identifiers_documents` (`document_id` ASC) ,
INDEX `fk_document_identifiers_documents_type` (`document_id` ASC, `type` ASC) ,
Expand Down
3 changes: 2 additions & 1 deletion library/Opus/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ class Opus_Document extends Opus_Model_AbstractDb {
protected $_plugins = array(
'Opus_Document_Plugin_Index' => null,
'Opus_Document_Plugin_XmlCache' => null,
'Opus_Document_Plugin_IdentifierUrn' => null
'Opus_Document_Plugin_IdentifierUrn' => null,
'Opus_Document_Plugin_IdentifierDoi' => null
);

/**
Expand Down
186 changes: 186 additions & 0 deletions library/Opus/Document/Plugin/IdentifierDoi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
<?php
/**
* This file is part of OPUS. The software OPUS has been originally developed
* at the University of Stuttgart with funding from the German Research Net,
* the Federal Department of Higher Education and Research and the Ministry
* of Science, Research and the Arts of the State of Baden-Wuerttemberg.
*
* OPUS 4 is a complete rewrite of the original OPUS software and was developed
* by the Stuttgart University Library, the Library Service Center
* Baden-Wuerttemberg, the Cooperative Library Network Berlin-Brandenburg,
* the Saarland University and State Library, the Saxon State Library -
* Dresden State and University Library, the Bielefeld University Library and
* the University Library of Hamburg University of Technology with funding from
* the German Research Foundation and the European Regional Development Fund.
*
* LICENCE
* OPUS is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the Licence, or any later version.
* OPUS is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details. You should have received a copy of the GNU General Public License
* along with OPUS; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @category Framework
* @package Opus_Document_Plugin
* @author Sascha Szott <[email protected]>
* @copyright Copyright (c) 2018, OPUS 4 development team
* @license http://www.gnu.org/licenses/gpl.html General Public License
*/

/**
* Plugin for generating identifiers of type DOI.
*
*/
class Opus_Document_Plugin_IdentifierDoi extends Opus_Model_Plugin_Abstract {

// was muss hier alles ausgewertet werden:
// automatische Generierung einer DOI für das vorliegende Dokument, wenn
// 1. noch keine DOI vorhanden
// 2. Enrichment opus.doi.autoCreate wurde gesetzt

// außerdem automatische Registrierung der DOI (Aufruf MDS-Webservice von DataCite)
// wenn DOI vorhanden und die Konfigurationseinstellung doi.registerAtPublish ist auf true/1 gesetzt


// laut Spezifikation: jedes OPUS-Dokument kann maximal eine zugeordnete DOI haben
// diese DOI ist entweder lokal oder extern
// im Rahmen der automatischen DOI-Registrierung werden nur lokale DOIs betrachtet
public function postStoreInternal(Opus_Model_AbstractDb $model) {

$log = Zend_Registry::get('Zend_Log');

if (!($model instanceof Opus_Document)) {
$log->err('found unexpected model class ' . get_class($model));
return;
}

$serverState = $model->getServerState();
$log->debug(__CLASS__ . ' postStoreInternal for ' . $model->getDisplayName() . ' and target state ' . $serverState);

if ($serverState == 'published') {
$this->handlePublishEvent($model, $log);
return;
}

if ($serverState == 'deleted') {
$this->handleDeleteEvent($model);
return;
}

$log->err('plugin ' . __CLASS__ . ' is not applicable for documents with server state ' . $serverState);
return;
}

private function handleDeleteEvent($document) {
// Metadatensatz für DOI auf den Status "inactive" setzen
$doiManager = new Opus_Doi_DoiManager();
$doiManager->deleteMetadataForDoi($document);
}

private function handlePublishEvent($document, $log) {
// prüfe zuerst, ob das Dokument das Enrichment opus.doi.autoCreate besitzt
// in diesem Fall wird nun eine DOI gemäß der Konfigurationseinstellungen generiert
$generateDoi = null;
$enrichment = $document->getEnrichment('opus.doi.autoCreate');
if (!is_null($enrichment)) {
$enrichmentValue = $enrichment->getValue();
$generateDoi = ($enrichmentValue == 'true');
$log->debug('found enrichment opus.doi.autoCreate with value ' . $enrichmentValue);
}

$config = Zend_Registry::get('Zend_Config');

if (is_null($generateDoi)) {
// Enrichment opus.doi.autoCreate wurde nicht gefunden - verwende Standardwert für die DOI-Erzeugung aus Konfiguration
$generateDoi = (isset($config->doi->autoCreate) && ($config->doi->autoCreate || $config->doi->autoCreate == '1'));
}

// prüfe, ob bereits eine DOI mit dem Dokument verknüpft ist
if (!empty($document->getIdentifierDoi())) {
$log->debug('could not assign more than one DOI to document ' . $document->getId());
}
else {
// $generateDoi kann hier nicht mehr null sein: aktueller Wert entscheidet, ob neue DOI generiert wird
if ($generateDoi) {
try {
$this->addDoi($document, $log);
}
catch (Exception $e) {
$log->err('could not generate local DOI for document ' . $document->getId() . ' - abort DOI registration procedure');
return;
}
}
}

// prüfe, ob DOI bei DataCite registriert werden soll -> wenn ja, dann Versuch der synchronen Registrierung
$this->registerDoi($document, $log, $config);
}

/**
* Fügt zum Dokument $model eine DOI hinzu, sofern noch keine existiert und die Konfiguration
* entsprechend gesetzt ist.
*
* @param $model Opus_Document zu dem die DOI hinzugefügt werden soll
*/
private function addDoi($model, $log) {

try {
$doiManager = new Opus_Doi_DoiManager();
$doiValue = $doiManager->generateNewDoi($model);
}
catch (Opus_Doi_DoiException $e) {
$message = 'could not generate DOI value for document ' . $model->getId() . ': ' . $e->getMessage();
$log->err($message);
throw new Exception($message);
}

$doi = new Opus_Identifier();
$doi->setType('doi');
$doi->setValue($doiValue);

$identifiers = $model->getIdentifier();
if (is_null($identifiers)) {
$identifiers = array();
}
$identifiers[] = $doi;
$model->setIdentifier($identifiers);

$log->debug('DOI ' . $doiValue . ' was generated for document ' . $model->getId());
}

/**
* Registriert die mit dem Dokument verknüpfte DOI bei DataCite unter Verwendung des DoiManagers
*
* @param $model
*/
private function registerDoi($model, $log, $config) {

// prüfe ob Konfigurationseinstellung eine Registrierung vorgibt
if (!isset($config->doi->registerAtPublish) || !($config->doi->registerAtPublish || $config->doi->registerAtPublish == '1')) {
$log->debug('registration of DOIs at publish time is disabled in configuration');
return;
}

// führe die Registrierung durch
$log->info('start registration of DOI for document ' . $model->getId());

try {
$doiManager = new Opus_Doi_DoiManager();
$registeredDoi = $doiManager->register($model);
if (is_null($registeredDoi)) {
$log->err('could not apply DOI registration on document ' . $model->getId());
}
}
catch (Opus_Doi_RegistrationException $e) {
$log->err('unexpected error in registration of DOI ' . $e->getDoi() . ' of document ' . $model->getId() . ': ' . $e->getMessage());
}
catch (Opus_Doi_DoiException $e) {
$log->err('unexpected error in DOI-registration of document ' . $model->getId() . ': ' . $e->getMessage());
}

}
}
55 changes: 45 additions & 10 deletions library/Opus/Document/Plugin/IdentifierUrn.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@
* @author Thoralf Klein <[email protected]>
* @copyright Copyright (c) 2009-2010
* Saechsische Landesbibliothek - Staats- und Universitaetsbibliothek Dresden (SLUB)
* @copyright Copyright (c) 2010-2012, OPUS 4 development team
* @copyright Copyright (c) 2010-2018, OPUS 4 development team
* @license http://www.gnu.org/licenses/gpl.html General Public License
* @version $Id$
*/

/**
Expand All @@ -41,14 +40,15 @@
* @package Opus_Document_Plugin
* @uses Opus_Model_Plugin_Abstract
*/
class Opus_Document_Plugin_IdentifierUrn extends Opus_Model_Plugin_Abstract {
class Opus_Document_Plugin_IdentifierUrn extends Opus_Model_Plugin_Abstract
{

/**
* Generates a new URN for any document that has no URN assigned yet.
* URN's are generated for Opus_Document instances only.
*/
public function postStoreInternal(Opus_Model_AbstractDb $model) {

public function postStoreInternal(Opus_Model_AbstractDb $model)
{
if(!($model instanceof Opus_Document))
return;

Expand All @@ -61,18 +61,40 @@ public function postStoreInternal(Opus_Model_AbstractDb $model) {

$log->debug('IdentifierUrn postStoreInternal for ' . $model->getDisplayName());

if(!isset($config->urn->autoCreate) or $config->urn->autoCreate != '1') {
// prüfe zuerst, ob das Dokument das Enrichment opus.urn.autoCreate besitzt
// in diesem Fall bestimmt der Wert des Enrichments, ob eine URN beim Publish generiert wird
$generateUrn = null;
$enrichment = $model->getEnrichment('opus.urn.autoCreate');
if (!is_null($enrichment)) {
$enrichmentValue = $enrichment->getValue();
$generateUrn = ($enrichmentValue == 'true');
$log->debug('found enrichment opus.urn.autoCreate with value ' . $enrichmentValue);
}

if (is_null($generateUrn)) {
// Enrichment opus.urn.autoCreate wurde nicht gefunden - verwende Standardwert für die URN-Erzeugung aus Konfiguration
$generateUrn = (isset($config->urn->autoCreate) && ($config->urn->autoCreate || $config->urn->autoCreate == '1'));
}

if (!$generateUrn) {
$log->debug('URN auto creation is not configured. skipping...');
return;
}

if(!isset($config->urn->nid) || !isset($config->urn->nss)) {
if (!isset($config->urn->nid) || !isset($config->urn->nss)) {
throw new Opus_Document_Exception('URN data is not present in config. Aborting...');
// FIXME hier sollte keine Exception geworfen werden, weil sonst
// die Ausführung aller nachfolgenden Plugins im Plugin-Array abgebrochen wird
// Plugins werden nämlich in Schleife nacheinander aufgerufen (ohne Exception Handling zwischen
// den einzelnen Aufrufen)

// FIXME außerdem ist der Exception Type schlecht gewählt, weil es sich in diesem
// Fall ja um einen Konfigurationsfehler handelt und nicht um einen Fehler im Dokument
}

$log->debug('config.ini is set to support urn auto generation');

if($this->urnAlreadyPresent($model)) {
if ($this->urnAlreadyPresent($model)) {
$log->debug('Model ' . $model->getDisplayName() . ' already has a URN. Skipping automatic generation.');
return;
}
Expand All @@ -96,6 +118,12 @@ public function postStoreInternal(Opus_Model_AbstractDb $model) {
$model->addIdentifierUrn($urn_model);
}

/**
* Liefert true, wenn das vorliegende Dokument bereits einen Identifier vom Typ URN besitzt; andernfalls false.
*
* @param $document
* @return bool
*/
public function urnAlreadyPresent($document) {
$identifierUrns = $document->getIdentifierUrn();
if(count($identifierUrns) > 0) {
Expand All @@ -112,10 +140,17 @@ public function urnAlreadyPresent($document) {
return false;
}

public function allowUrnOnThisDocument($document) {
/**
* Liefert true, wenn das vorliegende Dokumente mindestens eine Datei mit OAI-Sichtbarkeit besitzt (nur für solche
* Dokumente kann bei der DNB eine URN registriert werden)
*
* @param $document
* @return bool
*/
public function allowUrnOnThisDocument($document)
{
$files = array_filter($document->getFile(),
function ($f) { return $f->getVisibleInOai() == 1; });
return count($files) > 0;
}
}

Loading

0 comments on commit 48ed01d

Please sign in to comment.