From 835e7781784c98933c74d7a1ba6b1ccb543d32f3 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sat, 6 Jun 2020 13:41:12 +0200 Subject: [PATCH] Fix DOI import in RIS Importer Use DOI parse and only add valid DOIs Follow up from #6557 Fixes #6530 --- .../importer/fileformat/RisImporter.java | 13 ++--- .../logic/importer/RisImporterTest.java | 51 ------------------- .../importer/fileformat/RisImporterTest1.bib | 1 - .../importer/fileformat/RisImporterTest5a.bib | 1 + .../importer/fileformat/RisImporterTest6.bib | 1 + .../fileformat/RisImporterTestDOI.bib | 22 ++++++++ .../fileformat/RisImporterTestDOI.ris | 31 +++++++++++ .../fileformat/RisImporterTestScience.bib | 1 + .../fileformat/RisImporterTestScopus.bib | 1 + 9 files changed, 61 insertions(+), 61 deletions(-) delete mode 100644 src/test/java/org/jabref/logic/importer/RisImporterTest.java create mode 100644 src/test/resources/org/jabref/logic/importer/fileformat/RisImporterTestDOI.bib create mode 100644 src/test/resources/org/jabref/logic/importer/fileformat/RisImporterTestDOI.ris diff --git a/src/main/java/org/jabref/logic/importer/fileformat/RisImporter.java b/src/main/java/org/jabref/logic/importer/fileformat/RisImporter.java index 5bb9230d928..015dc378bfe 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/RisImporter.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/RisImporter.java @@ -9,7 +9,6 @@ import java.util.Arrays; import java.util.HashMap; import java.util.List; -import java.util.Locale; import java.util.Map; import java.util.Optional; import java.util.regex.Pattern; @@ -24,6 +23,7 @@ import org.jabref.model.entry.field.Field; import org.jabref.model.entry.field.StandardField; import org.jabref.model.entry.field.UnknownField; +import org.jabref.model.entry.identifier.DOI; import org.jabref.model.entry.types.EntryType; import org.jabref.model.entry.types.IEEETranEntryType; import org.jabref.model.entry.types.StandardEntryType; @@ -204,7 +204,7 @@ public ParserResult importDatabase(BufferedReader reader) throws IOException { } } else if ("UR".equals(tag) || "L2".equals(tag) || "LK".equals(tag)) { fields.put(StandardField.URL, value); - } else if ((tagPriority = dateTags.indexOf(tag)) != -1 && value.length() >= 4) { + } else if (((tagPriority = dateTags.indexOf(tag)) != -1) && (value.length() >= 4)) { if (tagPriority < datePriority) { String year = value.substring(0, 4); @@ -312,12 +312,7 @@ public ParserResult importDatabase(BufferedReader reader) throws IOException { } private void addDoi(Map hm, String val) { - String doi = val.toLowerCase(Locale.ENGLISH); - if (doi.startsWith("doi:")) { - doi = doi.replaceAll("(?i)doi:", "").trim(); - hm.put(StandardField.DOI, doi); - } else { - hm.put(StandardField.DOI, doi); - } + Optional parsedDoi = DOI.parse(val); + parsedDoi.ifPresent(doi -> hm.put(StandardField.DOI, doi.getDOI())); } } diff --git a/src/test/java/org/jabref/logic/importer/RisImporterTest.java b/src/test/java/org/jabref/logic/importer/RisImporterTest.java deleted file mode 100644 index 34f184ac149..00000000000 --- a/src/test/java/org/jabref/logic/importer/RisImporterTest.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.jabref.logic.importer; - -import java.lang.reflect.Method; -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; - -import org.jabref.logic.importer.fileformat.RisImporter; -import org.jabref.model.entry.field.Field; -import org.jabref.model.entry.field.StandardField; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -public class RisImporterTest { - RisImporter ri = null; - - @BeforeEach - public void setUp() throws Exception { - ri = new RisImporter(); - } - - @Test - public void testAddDoi1() throws Exception { - String testDoi = "10.1589/jpts.28.186"; - String doi = testDoi.toLowerCase(Locale.ENGLISH); - Map fields = new HashMap<>(); - Method testAddDoiMethod = ri.getClass().getDeclaredMethod("addDoi", Map.class, String.class); - testAddDoiMethod.setAccessible(true); - - testAddDoiMethod.invoke(ri, fields, doi); - assertNotNull(fields.get(StandardField.DOI)); - assertEquals("10.1589/jpts.28.186", fields.get(StandardField.DOI)); - } - - @Test - public void testAddDoi2() throws Exception { - String testDoi = "doi:10.1589/jpts.28.186"; - String doi = testDoi.toLowerCase(Locale.ENGLISH); - Map fields = new HashMap<>(); - Method testAddDoiMethod = ri.getClass().getDeclaredMethod("addDoi", Map.class, String.class); - testAddDoiMethod.setAccessible(true); - - testAddDoiMethod.invoke(ri, fields, doi); - assertNotNull(fields.get(StandardField.DOI)); - assertEquals("10.1589/jpts.28.186", fields.get(StandardField.DOI)); - } -} diff --git a/src/test/resources/org/jabref/logic/importer/fileformat/RisImporterTest1.bib b/src/test/resources/org/jabref/logic/importer/fileformat/RisImporterTest1.bib index 3ee23e1f165..5998fe27974 100644 --- a/src/test/resources/org/jabref/logic/importer/fileformat/RisImporterTest1.bib +++ b/src/test/resources/org/jabref/logic/importer/fileformat/RisImporterTest1.bib @@ -7,7 +7,6 @@ @phdthesis{ comment = {comment0 comment1 comment2}, - doi = {whatever}, issn = {kmptns}, journal = {kmptnd}, keywords = {keyword0, keyword1}, diff --git a/src/test/resources/org/jabref/logic/importer/fileformat/RisImporterTest5a.bib b/src/test/resources/org/jabref/logic/importer/fileformat/RisImporterTest5a.bib index 7c03a883a38..5313ba0cc34 100644 --- a/src/test/resources/org/jabref/logic/importer/fileformat/RisImporterTest5a.bib +++ b/src/test/resources/org/jabref/logic/importer/fileformat/RisImporterTest5a.bib @@ -2,6 +2,7 @@ @article{ abstract = {The objective of this work was to develop solid dosage forms using powders contg. inclusion complexes (ibuprofen with β-cyclodextrin) which were used to produce tablets (direct compression without addnl. excipients) and pellets (extrusion/spheronization) from wet mass contg. 40% (wt./wt.) of microcryst. cellulose. The pellets also demonstrated that during prepn. of the wet mass, the inclusion process occurred in a same yield that when pre-complexation was used. The particles characteristics were evaluated after being obtained through different complexation methods. The results showed that the tensile strength and profile dissoln. were as expected for both dosage forms. Tablets contg. inclusion complexes showed higher soly. when compared with a ref. formulation and with two com. formulations. The ibuprofen released from the two pellets formulations didn't show relevant differences between them. The drug released was analyzed considering different dissoln. parameters. The advantages of these new methodologies can be summarized as: (a) tablets were produced at a lower cost for the total process; and (b) in the pellet's prepn. there was no need of the previous complexation method resulting in a decrease in time and energy required. [on SciFinder(R)]}, author = {Salustio, P. J. and Feio, G. and Figueirinhas, J. L. and Cabral-Marques, H. M. and Costa, P. C. and Pinto, J. F.}, comment = {CAPLUS AN 2012:446586(Journal; Online Computer File)}, + doi = {10.1016/j.powtec.2012.01.008}, issn = {0032-5910}, journal = {Powder Technology}, keywords = {ibuprofen beta cyclodextrin inclusion complex tablet}, diff --git a/src/test/resources/org/jabref/logic/importer/fileformat/RisImporterTest6.bib b/src/test/resources/org/jabref/logic/importer/fileformat/RisImporterTest6.bib index 12a03af5704..bf1c384720e 100644 --- a/src/test/resources/org/jabref/logic/importer/fileformat/RisImporterTest6.bib +++ b/src/test/resources/org/jabref/logic/importer/fileformat/RisImporterTest6.bib @@ -1,6 +1,7 @@ @article{, author = {Sears, Margaret E.}, comment = {23690738[pmid]}, + doi = {10.1155/2013/219840}, database = {PMC}, issn = {1537-744X}, journal = {The Scientific World Journal}, diff --git a/src/test/resources/org/jabref/logic/importer/fileformat/RisImporterTestDOI.bib b/src/test/resources/org/jabref/logic/importer/fileformat/RisImporterTestDOI.bib new file mode 100644 index 00000000000..bc3b363d98e --- /dev/null +++ b/src/test/resources/org/jabref/logic/importer/fileformat/RisImporterTestDOI.bib @@ -0,0 +1,22 @@ +% Encoding: UTF-8 + +@Article{, + author = {Jung, Sang In and Lee, Na Kyung and Kang, Kyung Woo and Kim, Kyoung and Lee, Do Youn}, + title = {The effect of smartphone usage time on posture and respiratory function}, + doi = {10.1589/jpts.28.186}, + issn = {2187-5626}, + language = {eng}, + number = {26957754}, + pages = {186--189}, + url = {https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4756000/}, + volume = {28}, + comment = {26957754[pmid] +PMC4756000[pmcid]}, + database = {PubMed}, + edition = {2016/01/30}, + journal = {Journal of physical therapy science}, + keywords = {Posture, Respiratory function, Smartphone}, + month = jan, + publisher = {The Society of Physical Therapy Science}, + year = {2016}, +} diff --git a/src/test/resources/org/jabref/logic/importer/fileformat/RisImporterTestDOI.ris b/src/test/resources/org/jabref/logic/importer/fileformat/RisImporterTestDOI.ris new file mode 100644 index 00000000000..6357fe520bf --- /dev/null +++ b/src/test/resources/org/jabref/logic/importer/fileformat/RisImporterTestDOI.ris @@ -0,0 +1,31 @@ +TY - JOUR +DB - PubMed +AU - Jung, Sang In +AU - Lee, Na Kyung +AU - Kang, Kyung Woo +AU - Kim, Kyoung +AU - Lee, Do Youn +T1 - The effect of smartphone usage time on posture and respiratory function +LA - eng +SN - 0915-5287 +SN - 2187-5626 +Y1 - 2016/01/ +ET - 2016/01/30 +SP - 186 +EP - 189 +VL - 28 +IS - 1 +AN - 26957754 +UR - https://pubmed.ncbi.nlm.nih.gov/26957754 +DO - 10.1589/jpts.28.186 +L2 - https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4756000/ +U1 - 26957754[pmid] +U2 - PMC4756000[pmcid] +U4 - jpts-2015-817[PII] +J2 - J Phys Ther Sci +JF - Journal of physical therapy science +KW - Posture +KW - Respiratory function +KW - Smartphone +PB - The Society of Physical Therapy Science +ER - diff --git a/src/test/resources/org/jabref/logic/importer/fileformat/RisImporterTestScience.bib b/src/test/resources/org/jabref/logic/importer/fileformat/RisImporterTestScience.bib index faed9ca343d..eae43971a7b 100644 --- a/src/test/resources/org/jabref/logic/importer/fileformat/RisImporterTestScience.bib +++ b/src/test/resources/org/jabref/logic/importer/fileformat/RisImporterTestScience.bib @@ -1,5 +1,6 @@ @Article{, author = {Ghosh, Chanchal and Basu, Joysurya and Ramachandran, Divakar and Mohandas, E.}, + doi = {10.1016/j.actamat.2016.09.028}, title = {Phase separation and ω transformation in binary V-Ti and ternary V-Ti-Cr alloys}, journal = {Acta Materialia}, year = {2016}, diff --git a/src/test/resources/org/jabref/logic/importer/fileformat/RisImporterTestScopus.bib b/src/test/resources/org/jabref/logic/importer/fileformat/RisImporterTestScopus.bib index aea28784b06..e1d9527a1a6 100644 --- a/src/test/resources/org/jabref/logic/importer/fileformat/RisImporterTestScopus.bib +++ b/src/test/resources/org/jabref/logic/importer/fileformat/RisImporterTestScopus.bib @@ -10,6 +10,7 @@ @Article{ comment = {Cited By :44 Export Date: 1 April 2016}, database = {Scopus}, + doi = {10.1016/j.jmps.2004.03.010}, keywords = {Composite, Inclusions, Statistical distribution, Transverse isotropy}, url = {http://www.scopus.com/inward/record.url?eid=2-s2.0-4544289390&partnerID=40&md5=ad1a4baab95650b103a3467b787b83aa}, }