From 1bbce3b22dbb06099fe0c3537959582c07922d28 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9=20Lahmann?= <lahmann@ub.uni-leipzig.de>
Date: Tue, 23 Jun 2015 14:33:03 +0200
Subject: [PATCH] refs #5407: * removed Redi-ResolverDriver from module/finc *
 updated SolrMarc.php and SolrMarcRemote.php according to latest
 vufind-org/master commits

---
 module/finc/config/module.config.php          |   5 -
 .../finc/src/finc/RecordDriver/SolrMarc.php   | 138 ++++-----
 .../src/finc/RecordDriver/SolrMarcRemote.php  |   2 -
 .../finc/src/finc/Resolver/Driver/Factory.php |  58 ----
 module/finc/src/finc/Resolver/Driver/Redi.php | 268 ------------------
 5 files changed, 69 insertions(+), 402 deletions(-)
 delete mode 100644 module/finc/src/finc/Resolver/Driver/Factory.php
 delete mode 100644 module/finc/src/finc/Resolver/Driver/Redi.php

diff --git a/module/finc/config/module.config.php b/module/finc/config/module.config.php
index 6c4a97cd336..136f130a737 100644
--- a/module/finc/config/module.config.php
+++ b/module/finc/config/module.config.php
@@ -27,11 +27,6 @@ $config = [
                     'solrai' => 'finc\RecordDriver\Factory::getSolrAI',
                 ],
             ],
-            'resolver_driver' => [
-                'factories' => [
-                    'redi' => 'finc\Resolver\Driver\Factory::getRedi',
-                ],
-            ],
             'recordtab' => [
                 'invokables' => [
                     'additional' => 'finc\RecordTab\Additional',
diff --git a/module/finc/src/finc/RecordDriver/SolrMarc.php b/module/finc/src/finc/RecordDriver/SolrMarc.php
index 922fa599b29..247d8af7edd 100644
--- a/module/finc/src/finc/RecordDriver/SolrMarc.php
+++ b/module/finc/src/finc/RecordDriver/SolrMarc.php
@@ -155,20 +155,20 @@ class SolrMarc extends SolrDefault
         $biblioLevel = strtoupper($leader[7]);
 
         switch ($biblioLevel) {
-            case 'M': // Monograph
-                return "Monograph";
-            case 'S': // Serial
-                return "Serial";
-            case 'A': // Monograph Part
-                return "MonographPart";
-            case 'B': // Serial Part
-                return "SerialPart";
-            case 'C': // Collection
-                return "Collection";
-            case 'D': // Collection Part
-                return "CollectionPart";
-            default:
-                return "Unknown";
+        case 'M': // Monograph
+            return "Monograph";
+        case 'S': // Serial
+            return "Serial";
+        case 'A': // Monograph Part
+            return "MonographPart";
+        case 'B': // Serial Part
+            return "SerialPart";
+        case 'C': // Collection
+            return "Collection";
+        case 'D': // Collection Part
+            return "CollectionPart";
+        default:
+            return "Unknown";
         }
     }
 
@@ -323,12 +323,12 @@ class SolrMarc extends SolrDefault
                     ? $currentVal->getData() : null;
                 if (!empty($currentVal)) {
                     switch ($currentField->getIndicator('2')) {
-                        case '1':
-                            $pubResults[] = $currentVal;
-                            break;
-                        case '4':
-                            $copyResults[] = $currentVal;
-                            break;
+                    case '1':
+                        $pubResults[] = $currentVal;
+                        break;
+                    case '4':
+                        $copyResults[] = $currentVal;
+                        break;
                     }
                 }
             }
@@ -769,16 +769,16 @@ class SolrMarc extends SolrDefault
         // Assign notes based on the relationship type
         $value = $field->getTag();
         switch ($value) {
-            case '780':
-                if (in_array($relationshipIndicator, range('0', '7'))) {
-                    $value .= '_' . $relationshipIndicator;
-                }
-                break;
-            case '785':
-                if (in_array($relationshipIndicator, range('0', '8'))) {
-                    $value .= '_' . $relationshipIndicator;
-                }
-                break;
+        case '780':
+            if (in_array($relationshipIndicator, range('0', '7'))) {
+                $value .= '_' . $relationshipIndicator;
+            }
+            break;
+        case '785':
+            if (in_array($relationshipIndicator, range('0', '8'))) {
+                $value .= '_' . $relationshipIndicator;
+            }
+            break;
         }
 
         return 'note_' . $value;
@@ -813,46 +813,46 @@ class SolrMarc extends SolrDefault
         // If no reference found, check the next link type instead
         foreach ($linkTypes as $linkType) {
             switch (trim($linkType)){
-                case 'oclc':
-                    foreach ($linkFields as $current) {
-                        if ($oclc = $this->getIdFromLinkingField($current, 'OCoLC')) {
-                            $link = ['type' => 'oclc', 'value' => $oclc];
-                        }
-                    }
-                    break;
-                case 'dlc':
-                    foreach ($linkFields as $current) {
-                        if ($dlc = $this->getIdFromLinkingField($current, 'DLC', true)) {
-                            $link = ['type' => 'dlc', 'value' => $dlc];
-                        }
-                    }
-                    break;
-                case 'id':
-                    foreach ($linkFields as $current) {
-                        if ($bibLink = $this->getIdFromLinkingField($current)) {
-                            $link = ['type' => 'bib', 'value' => $bibLink];
-                        }
+            case 'oclc':
+                foreach ($linkFields as $current) {
+                    if ($oclc = $this->getIdFromLinkingField($current, 'OCoLC')) {
+                        $link = ['type' => 'oclc', 'value' => $oclc];
                     }
-                    break;
-                case 'isbn':
-                    if ($isbn = $field->getSubfield('z')) {
-                        $link = [
-                            'type' => 'isn', 'value' => trim($isbn->getData()),
-                            'exclude' => $this->getUniqueId()
-                        ];
+                }
+                break;
+            case 'dlc':
+                foreach ($linkFields as $current) {
+                    if ($dlc = $this->getIdFromLinkingField($current, 'DLC', true)) {
+                        $link = ['type' => 'dlc', 'value' => $dlc];
                     }
-                    break;
-                case 'issn':
-                    if ($issn = $field->getSubfield('x')) {
-                        $link = [
-                            'type' => 'isn', 'value' => trim($issn->getData()),
-                            'exclude' => $this->getUniqueId()
-                        ];
+                }
+                break;
+            case 'id':
+                foreach ($linkFields as $current) {
+                    if ($bibLink = $this->getIdFromLinkingField($current)) {
+                        $link = ['type' => 'bib', 'value' => $bibLink];
                     }
-                    break;
-                case 'title':
-                    $link = ['type' => 'title', 'value' => $title];
-                    break;
+                }
+                break;
+            case 'isbn':
+                if ($isbn = $field->getSubfield('z')) {
+                    $link = [
+                        'type' => 'isn', 'value' => trim($isbn->getData()),
+                        'exclude' => $this->getUniqueId()
+                    ];
+                }
+                break;
+            case 'issn':
+                if ($issn = $field->getSubfield('x')) {
+                    $link = [
+                        'type' => 'isn', 'value' => trim($issn->getData()),
+                        'exclude' => $this->getUniqueId()
+                    ];
+                }
+                break;
+            case 'title':
+                $link = ['type' => 'title', 'value' => $title];
+                break;
             }
             // Exit loop if we have a link
             if (isset($link)) {
@@ -1001,8 +1001,8 @@ class SolrMarc extends SolrDefault
      * @return void
      */
     public function attachILS(\VuFind\ILS\Connection $ils,
-                              \VuFind\ILS\Logic\Holds $holdLogic,
-                              \VuFind\ILS\Logic\TitleHolds $titleHoldLogic
+        \VuFind\ILS\Logic\Holds $holdLogic,
+        \VuFind\ILS\Logic\TitleHolds $titleHoldLogic
     ) {
         $this->ils = $ils;
         $this->holdLogic = $holdLogic;
diff --git a/module/finc/src/finc/RecordDriver/SolrMarcRemote.php b/module/finc/src/finc/RecordDriver/SolrMarcRemote.php
index a1197c1ca10..b32579cf77d 100644
--- a/module/finc/src/finc/RecordDriver/SolrMarcRemote.php
+++ b/module/finc/src/finc/RecordDriver/SolrMarcRemote.php
@@ -116,7 +116,6 @@ class SolrMarcRemote extends SolrMarc implements
      */
     protected function getRemoteFullrecord($id)
     {
-
         if (empty($id)) {
             throw new \Exception('empty id given');
         }
@@ -138,7 +137,6 @@ class SolrMarcRemote extends SolrMarc implements
                 'HTTP status ' . $response->getStatusCode() .
                 ' received, retrieving data for record: ' . $id
             );
-
             return false;
         }
 
diff --git a/module/finc/src/finc/Resolver/Driver/Factory.php b/module/finc/src/finc/Resolver/Driver/Factory.php
deleted file mode 100644
index f17535739c6..00000000000
--- a/module/finc/src/finc/Resolver/Driver/Factory.php
+++ /dev/null
@@ -1,58 +0,0 @@
-<?php
-/**
- * Resolver Driver Factory Class
- *
- * PHP version 5
- *
- * Copyright (C) Villanova University 2014.
- *
- * 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- * @category VuFind2
- * @package  Resolver_Drivers
- * @author   Demian Katz <demian.katz@villanova.edu>
- * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
- * @link     http://vufind.org/wiki/vufind2:hierarchy_components Wiki
- */
-namespace finc\Resolver\Driver;
-use Zend\ServiceManager\ServiceManager;
-
-/**
- * Resolver Driver Factory Class
- *
- * @category VuFind2
- * @package  Resolver_Drivers
- * @author   Demian Katz <demian.katz@villanova.edu>
- * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
- * @link     http://vufind.org/wiki/vufind2:hierarchy_components Wiki
- */
-class Factory
-{
-
-    /**
-     * Factory for Redi record driver.
-     *
-     * @param ServiceManager $sm Service manager.
-     *
-     * @return Redi
-     */
-    public static function getRedi(ServiceManager $sm)
-    {
-        $config = $sm->getServiceLocator()->get('VuFind\Config')->get('config');
-        return new Redi(
-            $config->OpenURL->url,
-            $sm->getServiceLocator()->get('VuFind\Http')->createClient()
-        );
-    }
-}
\ No newline at end of file
diff --git a/module/finc/src/finc/Resolver/Driver/Redi.php b/module/finc/src/finc/Resolver/Driver/Redi.php
deleted file mode 100644
index d8ab6e614ca..00000000000
--- a/module/finc/src/finc/Resolver/Driver/Redi.php
+++ /dev/null
@@ -1,268 +0,0 @@
-<?php
-/**
- * ReDi Link Resolver Driver
- *
- * PHP version 5
- *
- * Copyright (C) Leipzig University Library 2015
- *
- *
- * 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- * @category VuFind2
- * @package  Resolver_Drivers
- * @author   André Lahmann <lahmann@ub.uni-leipzig.de>
- * @author   Gregor Gawol <gawol@ub.uni-leipzig.de>
- * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
- * @link     http://vufind.org/wiki/vufind2:link_resolver_drivers Wiki
- */
-namespace finc\Resolver\Driver;
-use DOMDocument,
-    \VuFind\Resolver\Driver\DriverInterface as DriverInterface;
-use Zend\Dom\DOMXPath;
-
-/**
- * ReDi Link Resolver Driver
- *
- * @category VuFind2
- * @package  Resolver_Drivers
- * @author   André Lahmann <lahmann@ub.uni-leipzig.de>
- * @author   Gregor Gawol <gawol@ub.uni-leipzig.de>
- * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
- * @link     http://vufind.org/wiki/vufind2:link_resolver_drivers Wiki
- */
-class Redi implements DriverInterface
-{
-    /**
-     * HTTP client
-     *
-     * @var \Zend\Http\Client
-     */
-    protected $httpClient;
-
-    /**
-     * Base URL for link resolver
-     *
-     * @var string
-     */
-    protected $baseUrl;
-
-    /**
-     * Parsed resolver links
-     *
-     * @var array
-     */
-    protected $links;
-
-    /**
-     * Constructor
-     *
-     * @param string            $baseUrl    Base URL for link resolver
-     * @param \Zend\Http\Client $httpClient HTTP client
-     */
-    public function __construct($baseUrl, \Zend\Http\Client $httpClient)
-    {
-        $this->baseUrl = $baseUrl;
-        $this->httpClient = $httpClient;
-    }
-
-    /**
-     * Fetch Links
-     *
-     * Fetches a set of links corresponding to an OpenURL
-     *
-     * @param string $openURL openURL (url-encoded)
-     *
-     * @return string         raw XML returned by resolver
-     */
-    public function fetchLinks($openURL)
-    {
-        $url = $this->baseUrl.'?'.$openURL;
-        $feed = $this->httpClient->setUri($url)->send()->getBody();
-        return $feed;
-    }
-
-    /**
-     * Parse Links
-     *
-     * Parses an XML file returned by a link resolver
-     * and converts it to a standardised format for display
-     *
-     * @param string $xmlstr Raw XML returned by resolver
-     *
-     * @return array         Array of values
-     */
-    public function parseLinks($xmlstr)
-    {
-        $xml = new DOMDocument();
-        if (!@$xml->loadHTML($xmlstr)) {
-            return [];
-        }
-
-        // parse the raw resolver-data
-        $this->links = array_merge(
-            $this->parseDOI($xml),
-            $this->parseRediOpenURLs($xml)
-        );
-
-        // perform (individual) postprocessing on parsed resolver-data
-        $this->postProcessing();
-
-        return $this->links;
-    }
-
-    /**
-     * Parse the Redi XML response and return array with DOI information.
-     *
-     * @param DOMDocument $xml Loaded xml document
-     *
-     * @return array Get back a array with title, URL and service_type
-     */
-    protected function parseDOI($xml)
-    {
-        $retval = [];
-
-        $xpath = new DOMXPath($xml);
-
-        $doiTerm = $xpath
-            ->query("//dt[@class='doi_t']");
-        $doiDefinition = $xpath
-            ->query("//dd[@class='doi_d']");
-
-        if ($doiTerm->length == $doiDefinition->length) {
-            for ($i=0; $i<$doiTerm->length; $i++) {
-                $href = $xpath
-                    ->query(".//@href", $doiDefinition->item($i))
-                    ->item(0)->textContent;
-                $retval[] = [
-                    'title' => $doiTerm->item($i)->textContent
-                        . $doiDefinition->item($i)->textContent,
-                    'href' => $href,
-                    'service_type' => 'getFullTxt',
-                ];
-            }
-        }
-
-        return $retval;
-    }
-
-    /**
-     * Parse Redi additional information elements and return the one identified by
-     * the infoToken provided (e.g. "*")
-     *
-     * @param DOMDocument $xml       Loaded xml document
-     * @param string      $infoToken InfoToken to search for
-     *
-     * @return string
-     */
-    protected function parseRediInfo($xml, $infoToken)
-    {
-        $xpath = new DOMXPath($xml);
-
-        // additional info nodes - marked by "<sup>*</sup>"
-        $infoTokenNodes = $xpath->query("//div[@id='t_ezb']/div[@class='t']/p/sup");
-
-        if ($infoTokenNodes->length > 0) {
-            for ($i=0; $i<$infoTokenNodes->length; $i++) {
-                if ($infoToken == $infoTokenNodes->item($i)->textContent) {
-                    return $xpath
-                        ->query("//div[@id='t_ezb']/div[@class='t']/p/sup/..")
-                        ->item($i)->textContent;
-                }
-            }
-        }
-
-        return '';
-    }
-
-    /**
-     * Parse if the Redi xml snippet contains Redi urls.
-     *
-     * @param DOMDocument $xml Loaded xml document
-     *
-     * @return array Get back Redi direct link to sources containing title, URL and
-     *               service_type
-     */
-    protected function parseRediOpenURLs($xml)
-    {
-        $retval = [];
-
-        $xpath = new DOMXPath($xml);
-
-        $ezbResultsNodesText = $xpath
-            ->query("//div[@class='t_ezb_result']/p");
-        $ezbResultsNodesURL = $xpath
-            ->query("//div[@class='t_ezb_result']/p/span[@class='t_link']/a");
-
-        if ($ezbResultsNodesText->length == $ezbResultsNodesURL->length) {
-            for ($i=0; $i<$ezbResultsNodesText->length; $i++) {
-
-                $itemInfo = '';
-
-                $expression = "//div[@class='t_ezb_result']/p[{$i}]/sup";
-                if ($xpath->evaluate("count({$expression})") == 1) {
-                    $itemInfo = $this->parseRediInfo(
-                        $xml, $xpath->query($expression)->item(0)->textContent
-                    );
-                }
-
-                $retval[] = [
-                    'title' => $ezbResultsNodesText->item($i)->textContent,
-                    'href' => $ezbResultsNodesURL->item($i)
-                        ->attributes->getNamedItem("href")->textContent,
-                    'coverage'     => $itemInfo,
-                    'service_type' => 'getFullTxt',
-                ];
-            }
-        }
-
-        return $retval;
-    }
-
-    /**
-     * Hook for post processing of the parsed resolver response (e.g. by removing any
-     * double angle quotation mark from each link['title']).
-     *
-     * @return void
-     */
-    protected function postProcessing()
-    {
-        for ($i=0; $i < count($this->links); $i++) {
-            if (isset($this->links[$i]['title'])) {
-                $this->links[$i]['title'] = $this
-                    ->removeDoubleAngleQuotationMarks($this->links[$i]['title']);
-                $this->links[$i]['title'] = trim($this->links[$i]['title']);
-            }
-            if (isset($this->links[$i]['coverage'])) {
-                $this->links[$i]['coverage'] = trim($this->links[$i]['coverage']);
-            }
-        }
-    }
-
-    /**
-     * Helper function to remove hardcoded link-string "»" in Redi response
-     *
-     * @param string $string String to be manipulated
-     *
-     * @return string
-     */
-    protected function removeDoubleAngleQuotationMarks($string)
-    {
-        return str_replace(
-            ['»', chr(194).chr(160)],
-            ['', ''],
-            $string
-        ); // hack to replace \u00a0
-    }
-}
\ No newline at end of file
-- 
GitLab