jenkins-bot has submitted this change and it was merged.

Change subject: Add OCLC to response for WorldCat requests
......................................................................


Add OCLC to response for WorldCat requests

Bug: T145467
Change-Id: I23620553cbe44a577acf14a41a66472acd7f9fc2
---
M lib/CitoidRequest.js
M lib/CitoidService.js
M lib/Exporter.js
M test/features/scraping/isbn.js
4 files changed, 15 insertions(+), 1 deletion(-)

Approvals:
  Mobrovac: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/lib/CitoidRequest.js b/lib/CitoidRequest.js
index 624e6af..83008c3 100644
--- a/lib/CitoidRequest.js
+++ b/lib/CitoidRequest.js
@@ -25,6 +25,7 @@
 
     this.url = null;
     this.doi = null;
+    this.oclc = null;
 
     this.jar = request.jar();
 
diff --git a/lib/CitoidService.js b/lib/CitoidService.js
index bfaae2a..c98d9bc 100644
--- a/lib/CitoidService.js
+++ b/lib/CitoidService.js
@@ -227,7 +227,13 @@
         function (res) {
             res.body = JSON.parse(res.body);
             if (res && res.status === 200 && res.body.stat === 'ok') {
-                cr.response.source.push('WorldCat'); // Add WorldCat as a 
source of the metadata
+                // Add oclc number to the request object
+                if (res.body.list && res.body.list[0] && 
res.body.list[0].oclcnum &&
+                    res.body.list[0].oclcnum[0] && typeof 
res.body.list[0].oclcnum[0] === 'string') {
+                    cr.oclc = res.body.list[0].oclcnum[0];
+                }
+                // Add WorldCat as a source of the metadata
+                cr.response.source.push('WorldCat');
                 return citoidService.scrapeJSON(cr, res.body);
             } else {
                 return reject(cr);
diff --git a/lib/Exporter.js b/lib/Exporter.js
index dab926f..3dc5899 100644
--- a/lib/Exporter.js
+++ b/lib/Exporter.js
@@ -493,6 +493,11 @@
         citation[cr.idType.toUpperCase()] = cr.idValue;
     }
 
+    // Add OCLC number if present
+    if (cr.oclc) {
+        citation.oclc = cr.oclc;
+    }
+
     // Try to get doi from cr.doi
     if (!citation.DOI && cr.doi){
         citation.DOI = cr.doi;
diff --git a/test/features/scraping/isbn.js b/test/features/scraping/isbn.js
index 2e3d6d3..7b8c501 100644
--- a/test/features/scraping/isbn.js
+++ b/test/features/scraping/isbn.js
@@ -20,6 +20,7 @@
         return server.query('978-0-596-51979-7').then(function(res) {
             assert.status(res, 200);
             assert.checkCitation(res, 'MediaWiki');
+            assert.deepEqual(!!res.body[0].oclc, true, 'Missing OCLC');
             assert.isInArray(res.body[0].source, 'WorldCat');
             assert.deepEqual(res.body[0].author, [['Daniel J.', 'Barrett']], 
'Unexpected value; expected [[\'Daniel J.\'], [\'Barrett.\']] ' + 
res.body[0].author);
             assert.deepEqual(res.body[0].publisher, 'O\'Reilly Media', 
'Unexpected value; expected O\'Reilly Media, got ' + res.body[0].publisher);
@@ -35,6 +36,7 @@
         return server.query('9780439784542').then(function(res) {
             assert.status(res, 200);
             assert.checkCitation(res, 'Harry Potter and the half-blood 
prince');
+            assert.deepEqual(!!res.body[0].oclc, true, 'Missing OCLC');
             assert.isInArray(res.body[0].source, 'WorldCat');
             assert.deepEqual(res.body[0].author, [['J.K.', 'Rowling']], 
'Unexpected value; expected [[\'J.K.\', \'Rowling\']] got ' + 
res.body[0].author);
             assert.deepEqual(res.body[0].place, 'New York, NY', 'Unexpected 
value; expected New York, NY, got ' + res.body[0].place);

-- 
To view, visit https://gerrit.wikimedia.org/r/313799
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I23620553cbe44a577acf14a41a66472acd7f9fc2
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/services/citoid
Gerrit-Branch: master
Gerrit-Owner: Mvolz <[email protected]>
Gerrit-Reviewer: Mobrovac <[email protected]>
Gerrit-Reviewer: Mvolz <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to