The Gitlab instance will be restarted on Monday April 28th at 2AM. There will be a short interruption of service.

Skip to content
Snippets Groups Projects
Commit 5b05696c authored by Josef Moravec's avatar Josef Moravec Committed by Robert Lange
Browse files

Use url, if no pdf url found in Unpaywall DOI linker (#1547)

- Adds different labels for PDF and non-PDF full text in unpaywall doi linker
- Adjusts and enhances unpaywall tests
parent 3fcb31a7
No related merge requests found
......@@ -101,6 +101,11 @@ class Unpaywall implements DoiLinkerInterface, TranslatorAwareInterface,
'link' => $data['best_oa_location']['url_for_pdf'],
'label' => $this->translate('PDF Full Text'),
];
} elseif (!empty($data['best_oa_location']['url'])) {
$response[$doi][] = [
'link' => $data['best_oa_location']['url'],
'label' => $this->translate('online_resources'),
];
}
}
return $response;
......
HTTP/1.1 404 NOT FOUND
Connection: keep-alive
Server: gunicorn/19.9.0
Date: Tue, 11 Feb 2020 11:38:17 GMT
Content-Type: application/json
Content-Length: 157
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE, PATCH
Access-Control-Allow-Headers: origin, content-type, accept, x-requested-with
Via: 1.1 vegur
{
"HTTP_status_code": 404,
"error": true,
"message": "'10.1032228/nature12373' is an invalid doi. See https://doi.org/10.1032228/nature12373"
}
HTTP/1.1 200 OK
Connection: keep-alive
Server: gunicorn/19.9.0
Date: Wed, 06 Nov 2019 20:38:59 GMT
Content-Type: application/json
Content-Length: 2336
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE, PATCH
Access-Control-Allow-Headers: origin, content-type, accept, x-requested-with
Via: 1.1 vegur
{
"best_oa_location": {
"endpoint_id": null,
"evidence": "open (via page says license)",
"host_type": "publisher",
"is_best": true,
"license": "cc-by-sa",
"pmh_id": null,
"repository_institution": null,
"updated": "2018-07-24T23:01:04.482481",
"url": "https://doi.org/10.7553/66-4-1434",
"url_for_landing_page": "https://doi.org/10.7553/66-4-1434",
"url_for_pdf": null,
"version": "publishedVersion"
},
"data_standard": 2,
"doi": "10.7553/66-4-1434",
"doi_url": "https://doi.org/10.7553/66-4-1434",
"genre": "journal-article",
"has_repository_copy": false,
"is_oa": true,
"journal_is_in_doaj": true,
"journal_is_oa": true,
"journal_issn_l": "0256-8861",
"journal_issns": "2304-8263",
"journal_name": "South African Journal of Libraries and Information Science",
"oa_locations": [
{
"endpoint_id": null,
"evidence": "open (via page says license)",
"host_type": "publisher",
"is_best": true,
"license": "cc-by-sa",
"pmh_id": null,
"repository_institution": null,
"updated": "2018-07-24T23:01:04.482481",
"url": "http://sajlis.journals.ac.za/pub/article/download/1434/1332",
"url_for_landing_page": "https://doi.org/10.7553/66-4-1434",
"url_for_pdf": "http://sajlis.journals.ac.za/pub/article/download/1434/1332",
"version": "publishedVersion"
},
{
"endpoint_id": null,
"evidence": "oa journal (via doaj)",
"host_type": "publisher",
"is_best": false,
"license": "cc-by-sa",
"pmh_id": null,
"repository_institution": null,
"updated": "2019-11-06T20:38:59.834062",
"url": "https://doi.org/10.7553/66-4-1434",
"url_for_landing_page": "https://doi.org/10.7553/66-4-1434",
"url_for_pdf": null,
"version": "publishedVersion"
}
],
"oa_status": "gold",
"published_date": "2014-01-26",
"publisher": "Stellenbosch University",
"title": "Pioneers, passionate ladies, and private eyes : dime novels, series books, and paperbacks Sullivan, Larry E. & Cushman Schurman, Lydia eds.",
"updated": "2018-07-24T23:02:00.263680",
"year": 2014,
"z_authors": [
{
"family": "Sandham",
"given": "Tim"
}
]
}
......@@ -63,28 +63,57 @@ class UnpaywallTest extends \VuFindTest\Unit\TestCase
public function testApiSuccess()
{
$adapter = new TestAdapter();
$file = realpath(
__DIR__ . '/../../../../../tests/fixtures/unpaywall/goodresponse'
);
$response = file_get_contents($file);
$responseObj = HttpResponse::fromString($response);
$adapter->setResponse($responseObj);
$service = new \VuFindHttp\HttpService();
$service->setDefaultAdapter($adapter);
$testData = [
[
'filename' => realpath(__DIR__
. '/../../../../../tests/fixtures/unpaywall/goodresponsepdf'
),
'response' => [
'10.7553/66-4-1434' => [
[
'link' => 'http://sajlis.journals.ac.za/pub/article/download/1434/1332',
'label' => 'PDF Full Text',
]
]
]
],
[
'filename' => realpath(__DIR__
. '/../../../../../tests/fixtures/unpaywall/goodresponseonline'
),
'response' => [
'10.7553/66-4-1434' => [
[
'link' => 'https://doi.org/10.7553/66-4-1434',
'label' => 'online_resources',
]
]
]
],
[
'filename' => realpath(__DIR__
. '/../../../../../tests/fixtures/unpaywall/badresponse'
),
'response' => []
],
];
$config = [
'unpaywall_email' => 'foo@myuniversity.edu',
];
$unpaywall = new Unpaywall(new \Zend\Config\Config($config));
$unpaywall->setHttpService($service);
$this->assertEquals(
['10.7553/66-4-1434' => [
[
'link' => 'http://sajlis.journals.ac.za/pub/article/download/1434/1332',
'label' => 'PDF Full Text',
]
]
],
$unpaywall->getLinks(['10.7553/66-4-1434'])
);
foreach ($testData as $data) {
$response = file_get_contents($data['filename']);
$responseObj = HttpResponse::fromString($response);
$adapter->setResponse($responseObj);
$service = new \VuFindHttp\HttpService();
$service->setDefaultAdapter($adapter);
$unpaywall->setHttpService($service);
$this->assertEquals(
$data['response'],
$unpaywall->getLinks(['10.7553/66-4-1434'])
);
}
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment