Skip to content

Commit

Permalink
BrowZine DOI Linking (#1219)
Browse files Browse the repository at this point in the history
- Add mechanism to load links by AJAX based on DOI.
- Implement data provider using BrowZine API.
  • Loading branch information
demiankatz committed Oct 10, 2018
1 parent affa44a commit a595b80
Show file tree
Hide file tree
Showing 23 changed files with 797 additions and 12 deletions.
14 changes: 14 additions & 0 deletions config/vufind/config.ini
Expand Up @@ -1012,6 +1012,20 @@ pw = "xxxxxx"
;[DPLA]
;apiKey = http://dp.la/info/developers/codex/policies/#get-a-key

; These settings affect dynamic DOI-based link inclusion; this can provide links
; to full text or contextual information.
[DOI]
; This setting controls whether or not DOI-based links are enabled, and which
; API is used to fetch the data. Currently supported options: BrowZine (requires
; credentials to be configured in BrowZine.ini) or false (to disable). Disabled
; by default.
;resolver = BrowZine

; The following settings control where DOI-based links are displayed:
show_in_results = true ; include in search results
show_in_record = false ; include in core record metadata
show_in_holdings = false ; include in holdings tab of record view

; These settings affect OpenURL generation and presentation; OpenURLs are used to
; help users find resources through your link resolver and to manage citations in
; Zotero.
Expand Down
1 change: 1 addition & 0 deletions languages/en.ini
Expand Up @@ -1083,6 +1083,7 @@ Video = "Video"
Video Clips = "Video Clips"
Videos = "Videos"
View Book Bag = "View Book Bag"
View Complete Issue = "View Complete Issue"
View Full Collection = "View Full Collection"
View Full Record = "View Full Record"
View in EDS = "View in EDS"
Expand Down
2 changes: 2 additions & 0 deletions module/VuFind/config/module.config.php
Expand Up @@ -342,6 +342,7 @@
'VuFind\Db\AdapterFactory' => 'VuFind\Service\ServiceWithConfigIniFactory',
'VuFind\Db\Row\PluginManager' => 'VuFind\ServiceManager\AbstractPluginManagerFactory',
'VuFind\Db\Table\PluginManager' => 'VuFind\ServiceManager\AbstractPluginManagerFactory',
'VuFind\DoiLinker\PluginManager' => 'VuFind\ServiceManager\AbstractPluginManagerFactory',
'VuFind\Export' => 'VuFind\ExportFactory',
'VuFind\Favorites\FavoritesService' => 'VuFind\Favorites\FavoritesServiceFactory',
'VuFind\GeoFeatures\BasemapConfig' => 'VuFind\GeoFeatures\AbstractConfigFactory',
Expand Down Expand Up @@ -515,6 +516,7 @@
'cover_layer' => [ /* see VuFind\Cover\Layer\PluginManager for defaults */ ],
'db_row' => [ /* see VuFind\Db\Row\PluginManager for defaults */ ],
'db_table' => [ /* see VuFind\Db\Table\PluginManager for defaults */ ],
'doilinker' => [ /* see VuFind\DoiLinker\PluginManager for defaults */ ],
'hierarchy_driver' => [ /* see VuFind\Hierarchy\Driver\PluginManager for defaults */ ],
'hierarchy_treedataformatter' => [ /* see VuFind\Hierarchy\TreeDataFormatter\PluginManager for defaults */ ],
'hierarchy_treedatasource' => [ /* see VuFind\Hierarchy\TreeDataSource\PluginManager for defaults */ ],
Expand Down
86 changes: 86 additions & 0 deletions module/VuFind/src/VuFind/AjaxHandler/DoiLookup.php
@@ -0,0 +1,86 @@
<?php
/**
* AJAX handler to look up DOI data.
*
* PHP version 7
*
* Copyright (C) Villanova University 2018.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category VuFind
* @package AJAX
* @author Demian Katz <demian.katz@villanova.edu>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development Wiki
*/
namespace VuFind\AjaxHandler;

use VuFind\DoiLinker\PluginManager;
use Zend\Mvc\Controller\Plugin\Params;

/**
* AJAX handler to look up DOI data.
*
* @category VuFind
* @package AJAX
* @author Demian Katz <demian.katz@villanova.edu>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development Wiki
*/
class DoiLookup extends AbstractBase
{
/**
* DOI Linker Plugin Manager
*
* @var PluginManager
*/
protected $pluginManager;

/**
* DOI resolver configuration value
*
* @var string
*/
protected $resolver;

/**
* Constructor
*
* @param PluginManager $pluginManager DOI Linker Plugin Manager
* @param string $resolver DOI resolver configuration value
*/
public function __construct(PluginManager $pluginManager, $resolver)
{
$this->pluginManager = $pluginManager;
$this->resolver = $resolver;
}

/**
* Handle a request.
*
* @param Params $params Parameter helper from controller
*
* @return array [response data, HTTP status code]
*/
public function handleRequest(Params $params)
{
$response = [];
if ($this->pluginManager->has($this->resolver)) {
$dois = (array)$params->fromQuery('doi', []);
$response = $this->pluginManager->get($this->resolver)->getLinks($dois);
}
return $this->formatResponse($response);
}
}
69 changes: 69 additions & 0 deletions module/VuFind/src/VuFind/AjaxHandler/DoiLookupFactory.php
@@ -0,0 +1,69 @@
<?php
/**
* Factory for DoiLookup AJAX handler.
*
* PHP version 7
*
* Copyright (C) Villanova University 2018.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category VuFind
* @package AJAX
* @author Demian Katz <demian.katz@villanova.edu>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development Wiki
*/
namespace VuFind\AjaxHandler;

use Interop\Container\ContainerInterface;

/**
* Factory for DoiLookup AJAX handler.
*
* @category VuFind
* @package AJAX
* @author Demian Katz <demian.katz@villanova.edu>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development Wiki
*/
class DoiLookupFactory implements \Zend\ServiceManager\Factory\FactoryInterface
{
/**
* Create an object
*
* @param ContainerInterface $container Service manager
* @param string $requestedName Service being created
* @param null|array $options Extra options (optional)
*
* @return object
*
* @throws ServiceNotFoundException if unable to resolve the service.
* @throws ServiceNotCreatedException if an exception is raised when
* creating a service.
* @throws ContainerException if any other error occurs
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function __invoke(ContainerInterface $container, $requestedName,
array $options = null
) {
if (!empty($options)) {
throw new \Exception('Unexpected options passed to factory.');
}
$config = $container->get('VuFind\Config\PluginManager')->get('config');
$pluginManager = $container->get('VuFind\DoiLinker\PluginManager');
return new $requestedName($pluginManager, $config->DOI->resolver ?? null);
}
}
2 changes: 2 additions & 0 deletions module/VuFind/src/VuFind/AjaxHandler/PluginManager.php
Expand Up @@ -47,6 +47,7 @@ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager
'checkRequestIsValid' => 'VuFind\AjaxHandler\CheckRequestIsValid',
'commentRecord' => 'VuFind\AjaxHandler\CommentRecord',
'deleteRecordComment' => 'VuFind\AjaxHandler\DeleteRecordComment',
'doiLookup' => 'VuFind\AjaxHandler\DoiLookup',
'getACSuggestions' => 'VuFind\AjaxHandler\GetACSuggestions',
'getFacetData' => 'VuFind\AjaxHandler\GetFacetData',
'getIlsStatus' => 'VuFind\AjaxHandler\GetIlsStatus',
Expand Down Expand Up @@ -82,6 +83,7 @@ class PluginManager extends \VuFind\ServiceManager\AbstractPluginManager
'VuFind\AjaxHandler\CommentRecordFactory',
'VuFind\AjaxHandler\DeleteRecordComment' =>
'VuFind\AjaxHandler\DeleteRecordCommentFactory',
'VuFind\AjaxHandler\DoiLookup' => 'VuFind\AjaxHandler\DoiLookupFactory',
'VuFind\AjaxHandler\GetACSuggestions' =>
'VuFind\AjaxHandler\GetACSuggestionsFactory',
'VuFind\AjaxHandler\GetFacetData' =>
Expand Down
94 changes: 94 additions & 0 deletions module/VuFind/src/VuFind/DoiLinker/BrowZine.php
@@ -0,0 +1,94 @@
<?php
/**
* BrowZine DOI linker
*
* PHP version 7
*
* Copyright (C) Villanova University 2018.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category VuFind
* @package DOI
* @author Demian Katz <demian.katz@villanova.edu>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development:plugins:record_drivers Wiki
*/
namespace VuFind\DoiLinker;

use VuFind\I18n\Translator\TranslatorAwareInterface;
use VuFindSearch\Backend\BrowZine\Connector;

/**
* BrowZine DOI linker
*
* @category VuFind
* @package DOI
* @author Demian Katz <demian.katz@villanova.edu>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development:plugins:record_drivers Wiki
*/
class BrowZine implements DoiLinkerInterface, TranslatorAwareInterface
{
use \VuFind\I18n\Translator\TranslatorAwareTrait;

/**
* BrowZine connector
*
* @var Connector
*/
protected $connector;

/**
* Constructor
*
* @param Connector $connector Connector
*/
public function __construct(Connector $connector)
{
$this->connector = $connector;
}

/**
* Given an array of DOIs, perform a lookup and return an associative array
* of arrays, keyed by DOI. Each array contains one or more associative arrays
* with 'link' and 'label' keys.
*
* @param array $doiArray DOIs to look up
*
* @return array
*/
public function getLinks(array $doiArray)
{
$response = [];
foreach ($doiArray as $doi) {
$data = $this->connector->lookupDoi($doi)['data'] ?? null;
if (!empty($data['browzineWebLink'])) {
$response[$doi][] = [
'link' => $data['browzineWebLink'],
'label' => $this->translate('View Complete Issue'),
'data' => $data,
];
}
if (!empty($data['fullTextFile'])) {
$response[$doi][] = [
'link' => $data['fullTextFile'],
'label' => $this->translate('PDF Full Text'),
'data' => $data,
];
}
}
return $response;
}
}
68 changes: 68 additions & 0 deletions module/VuFind/src/VuFind/DoiLinker/BrowZineFactory.php
@@ -0,0 +1,68 @@
<?php
/**
* BrowZine DOI linker factory
*
* PHP version 7
*
* Copyright (C) Villanova University 2018.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category VuFind
* @package DOI
* @author Demian Katz <demian.katz@villanova.edu>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development:plugins:record_drivers Wiki
*/
namespace VuFind\DoiLinker;

use Interop\Container\ContainerInterface;

/**
* BrowZine DOI linker factory
*
* @category VuFind
* @package DOI
* @author Demian Katz <demian.katz@villanova.edu>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development:plugins:record_drivers Wiki
*/
class BrowZineFactory implements \Zend\ServiceManager\Factory\FactoryInterface
{
/**
* Create an object
*
* @param ContainerInterface $container Service manager
* @param string $requestedName Service being created
* @param null|array $options Extra options (optional)
*
* @return object
*
* @throws ServiceNotFoundException if unable to resolve the service.
* @throws ServiceNotCreatedException if an exception is raised when
* creating a service.
* @throws ContainerException if any other error occurs
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function __invoke(ContainerInterface $container, $requestedName,
array $options = null
) {
if (!empty($options)) {
throw new \Exception('Unexpected options passed to factory.');
}
$backend = $container->get('VuFind\Search\BackendManager')->get('BrowZine');
return new $requestedName($backend->getConnector());
}
}

0 comments on commit a595b80

Please sign in to comment.