From 0e3d707576b1653fe761bcdeb9d54cca5b31e662 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sat, 4 Apr 2020 03:32:00 -0400 Subject: [PATCH] Remove a couple redundant lines in Extra on RDF import `publicationTitle`/`reporter` (and fields mapped to `publicationTitle`) and `meetingName`/`conferenceName` I assume these should just be base-field mappings, but since they're not, they're not automatically deduplicated in `fromJSON()` and need to be handled separately. https://groups.google.com/d/msgid/zotero-dev/806a22e3-3d6a-4d86-8747-10c787291a93%40googlegroups.com --- chrome/content/zotero/xpcom/data/item.js | 35 ++++++++++++++++++++---- test/tests/itemTest.js | 32 +++++++++++++++++++++- 2 files changed, 60 insertions(+), 7 deletions(-) diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js index 7ba6334cd7..8b1aab7d63 100644 --- a/chrome/content/zotero/xpcom/data/item.js +++ b/chrome/content/zotero/xpcom/data/item.js @@ -4425,12 +4425,35 @@ Zotero.Item.prototype.fromJSON = function (json, options = {}) { } } - // Remove "Version Number" if "Edition" is set, since as of 3/2020 the RDF translator - // assigns it - if (extraFields.has('versionNumber') && setFields.has('edition') - && extraFields.get('versionNumber') == this.getField('edition')) { - extraFields.delete('versionNumber'); - invalidFieldLogLines.delete('versionNumber'); + // Remove Extra lines created by double assignments in the RDF translator for fields that + // aren't base-field mappings (which are deduped above). These should probably just become + // base-field mappings, at which point this could be removed. + var temporaryRDFFixes = [ + ['versionNumber', 'edition'], + + ['conferenceName', 'meetingName'], + + ['publicationTitle', 'reporter'], + ['bookTitle', 'reporter'], + ['blogTitle', 'reporter'], + ['dictionaryTitle', 'reporter'], + ['encyclopediaTitle', 'reporter'], + ['forumTitle', 'reporter'], + ['proceedingsTitle', 'reporter'], + ['programTitle', 'reporter'], + ['websiteTitle', 'reporter'], + ]; + for (let x of temporaryRDFFixes) { + if (extraFields.has(x[0]) && setFields.has(x[1]) + && extraFields.get(x[0]) == this.getField(x[1])) { + extraFields.delete(x[0]); + invalidFieldLogLines.delete(x[0]); + } + if (extraFields.has(x[1]) && setFields.has(x[0]) + && extraFields.get(x[1]) == this.getField(x[0])) { + extraFields.delete(x[1]); + invalidFieldLogLines.delete(x[1]); + } } } diff --git a/test/tests/itemTest.js b/test/tests/itemTest.js index a19df08674..586a710471 100644 --- a/test/tests/itemTest.js +++ b/test/tests/itemTest.js @@ -1914,7 +1914,7 @@ describe("Zotero.Item", function () { assert.equal(item.getField('extra'), ''); }); - it("should ignore versionNumber for books", async function () { + it("should ignore some redundant fields from RDF translator (temporary)", function () { var json = { itemType: "book", edition: "1", @@ -1924,6 +1924,36 @@ describe("Zotero.Item", function () { item.fromJSON(json); assert.equal(item.getField('edition'), "1"); assert.equal(item.getField('extra'), ''); + + json = { + itemType: "presentation", + meetingName: "Foo", + conferenceName: "Foo" + }; + var item = new Zotero.Item; + item.fromJSON(json); + assert.equal(item.getField('meetingName'), "Foo"); + assert.equal(item.getField('extra'), ''); + + json = { + itemType: "journalArticle", + publicationTitle: "Foo", + reporter: "Foo" + }; + var item = new Zotero.Item; + item.fromJSON(json); + assert.equal(item.getField('publicationTitle'), "Foo"); + assert.equal(item.getField('extra'), ''); + + json = { + itemType: "conferencePaper", + proceedingsTitle: "Foo", + reporter: "Foo" + }; + var item = new Zotero.Item; + item.fromJSON(json); + assert.equal(item.getField('proceedingsTitle'), "Foo"); + assert.equal(item.getField('extra'), ''); }); });