From 02481faaa9be5eaf0cb00b39eba101f1a872232b Mon Sep 17 00:00:00 2001 From: zkl-ai <907668776@qq.com> Date: Sat, 30 Apr 2022 12:13:10 +0800 Subject: [PATCH 01/27] Rename cleanup actions: "Make LaTeX ready" and "Make BibTeX ready" --- src/main/resources/l10n/JabRef_en.properties | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index b573e1e9a70..2e8bc094a4b 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -1447,22 +1447,22 @@ Converts\ LaTeX\ encoding\ to\ Unicode\ characters.=Converts LaTeX encoding to U Converts\ Unicode\ characters\ to\ LaTeX\ encoding.=Converts Unicode characters to LaTeX encoding. Converts\ ordinals\ to\ LaTeX\ superscripts.=Converts ordinals to LaTeX superscripts. Converts\ units\ to\ LaTeX\ formatting.=Converts units to LaTeX formatting. -HTML\ to\ LaTeX=HTML to LaTeX -LaTeX\ cleanup=LaTeX cleanup +HTML\ to\ LaTeX=Prepare for LaTeX: HTML to LaTeX +LaTeX\ cleanup=Prepare for LaTeX: Cleanup LaTeX\ to\ Unicode=LaTeX to Unicode Lower\ case=Lower case Minify\ list\ of\ person\ names=Minify list of person names Normalize\ date=Normalize date Normalize\ en\ dashes=Normalize en dashes -Normalize\ month=Normalize month +Normalize\ month=Prepare for BibTeX: Normalize month Normalize\ month\ to\ BibTeX\ standard\ abbreviation.=Normalize month to BibTeX standard abbreviation. -Normalize\ names\ of\ persons=Normalize names of persons -Normalize\ page\ numbers=Normalize page numbers +Normalize\ names\ of\ persons=Prepare for BibTeX: Normalize names of persons +Normalize\ page\ numbers=Prepare for BibTex: Normalize page numbers Normalize\ pages\ to\ BibTeX\ standard.=Normalize pages to BibTeX standard. Normalizes\ lists\ of\ persons\ to\ the\ BibTeX\ standard.=Normalizes lists of persons to the BibTeX standard. Normalizes\ the\ date\ to\ ISO\ date\ format.=Normalizes the date to ISO date format. Normalizes\ the\ en\ dashes.=Normalizes the en dashes. -Ordinals\ to\ LaTeX\ superscript=Ordinals to LaTeX superscript +Ordinals\ to\ LaTeX\ superscript=Prepare for LaTeX: Ordinals to LaTeX superscript Protect\ terms=Protect terms Add\ enclosing\ braces=Add enclosing braces Add\ braces\ encapsulating\ the\ complete\ field\ content.=Add braces encapsulating the complete field content. @@ -1474,8 +1474,8 @@ Shortens\ DOI\ to\ more\ human\ readable\ form.=Shortens DOI to more human reada Sentence\ case=Sentence case Shortens\ lists\ of\ persons\ if\ there\ are\ more\ than\ 2\ persons\ to\ "et\ al.".=Shortens lists of persons if there are more than 2 persons to "et al.". Title\ case=Title case -Unicode\ to\ LaTeX=Unicode to LaTeX -Units\ to\ LaTeX=Units to LaTeX +Unicode\ to\ LaTeX=Prepare for LaTeX: Unicode to LaTeX +Units\ to\ LaTeX=Prepare for LaTeX: Units to LaTeX Upper\ case=Upper case Does\ nothing.=Does nothing. Identity=Identity From 07345ea003417d3fff8779edf4cc49602bfc70d7 Mon Sep 17 00:00:00 2001 From: zkl-ai <907668776@qq.com> Date: Sun, 22 May 2022 22:09:40 +0800 Subject: [PATCH 02/27] modify dio exception handler --- .../gui/mergeentries/FetchAndMergeEntry.java | 12 +++++++++- .../org/jabref/logic/net/URLDownload.java | 9 ++++++++ src/main/resources/l10n/JabRef_en.properties | 23 ++++++++++++------- .../org/jabref/logic/net/URLDownloadTest.java | 16 +++++++++++++ 4 files changed, 51 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java b/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java index 7c1a9e127ba..5916d1483cd 100644 --- a/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java +++ b/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java @@ -76,7 +76,17 @@ public void fetchAndMerge(BibEntry entry, List fields) { }) .onFailure(exception -> { LOGGER.error("Error while fetching bibliographic information", exception); - dialogService.showErrorDialogAndWait(exception); + String localMessage = exception.getCause().getLocalizedMessage(); + // client error + if (localMessage.startsWith("Client")) { + dialogService.showInformationDialogAndWait(Localization.lang("Lookup DOI"), Localization.lang("No DOI data exists")); + // server error + } else if (localMessage.startsWith("Server")) { + dialogService.showInformationDialogAndWait(Localization.lang("Lookup DOI"), Localization.lang("DOI server not available")); + // default error + } else { + dialogService.showErrorDialogAndWait(exception); + } }) .executeWith(Globals.TASK_EXECUTOR); } diff --git a/src/main/java/org/jabref/logic/net/URLDownload.java b/src/main/java/org/jabref/logic/net/URLDownload.java index 7646048d7ba..aef68369877 100644 --- a/src/main/java/org/jabref/logic/net/URLDownload.java +++ b/src/main/java/org/jabref/logic/net/URLDownload.java @@ -40,6 +40,7 @@ import javax.net.ssl.TrustManager; import javax.net.ssl.X509TrustManager; +import org.jabref.logic.l10n.Localization; import org.jabref.logic.util.io.FileUtil; import org.jabref.model.util.FileHelper; @@ -361,6 +362,14 @@ private URLConnection openConnection() throws IOException { connection = new URLDownload(newUrl).openConnection(); } } + // status code 4xx + if (status > HttpURLConnection.HTTP_BAD_REQUEST && status < HttpURLConnection.HTTP_INTERNAL_ERROR) { + throw new IOException(Localization.lang("Client Error " + status)); + + // status code 5xx + } else if (status >= HttpURLConnection.HTTP_INTERNAL_ERROR) { + throw new IOException(Localization.lang("Server Error " + status)); + } } // this does network i/o: GET + read returned headers diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index 2e8bc094a4b..e1aa756a5ae 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -1447,22 +1447,22 @@ Converts\ LaTeX\ encoding\ to\ Unicode\ characters.=Converts LaTeX encoding to U Converts\ Unicode\ characters\ to\ LaTeX\ encoding.=Converts Unicode characters to LaTeX encoding. Converts\ ordinals\ to\ LaTeX\ superscripts.=Converts ordinals to LaTeX superscripts. Converts\ units\ to\ LaTeX\ formatting.=Converts units to LaTeX formatting. -HTML\ to\ LaTeX=Prepare for LaTeX: HTML to LaTeX -LaTeX\ cleanup=Prepare for LaTeX: Cleanup +HTML\ to\ LaTeX=HTML to LaTeX +LaTeX\ cleanup=LaTeX cleanup LaTeX\ to\ Unicode=LaTeX to Unicode Lower\ case=Lower case Minify\ list\ of\ person\ names=Minify list of person names Normalize\ date=Normalize date Normalize\ en\ dashes=Normalize en dashes -Normalize\ month=Prepare for BibTeX: Normalize month +Normalize\ month=Normalize month Normalize\ month\ to\ BibTeX\ standard\ abbreviation.=Normalize month to BibTeX standard abbreviation. -Normalize\ names\ of\ persons=Prepare for BibTeX: Normalize names of persons -Normalize\ page\ numbers=Prepare for BibTex: Normalize page numbers +Normalize\ names\ of\ persons=Normalize names of persons +Normalize\ page\ numbers=Normalize page numbers Normalize\ pages\ to\ BibTeX\ standard.=Normalize pages to BibTeX standard. Normalizes\ lists\ of\ persons\ to\ the\ BibTeX\ standard.=Normalizes lists of persons to the BibTeX standard. Normalizes\ the\ date\ to\ ISO\ date\ format.=Normalizes the date to ISO date format. Normalizes\ the\ en\ dashes.=Normalizes the en dashes. -Ordinals\ to\ LaTeX\ superscript=Prepare for LaTeX: Ordinals to LaTeX superscript +Ordinals\ to\ LaTeX\ superscript=Ordinals to LaTeX superscript Protect\ terms=Protect terms Add\ enclosing\ braces=Add enclosing braces Add\ braces\ encapsulating\ the\ complete\ field\ content.=Add braces encapsulating the complete field content. @@ -1474,8 +1474,8 @@ Shortens\ DOI\ to\ more\ human\ readable\ form.=Shortens DOI to more human reada Sentence\ case=Sentence case Shortens\ lists\ of\ persons\ if\ there\ are\ more\ than\ 2\ persons\ to\ "et\ al.".=Shortens lists of persons if there are more than 2 persons to "et al.". Title\ case=Title case -Unicode\ to\ LaTeX=Prepare for LaTeX: Unicode to LaTeX -Units\ to\ LaTeX=Prepare for LaTeX: Units to LaTeX +Unicode\ to\ LaTeX=Unicode to LaTeX +Units\ to\ LaTeX=Units to LaTeX Upper\ case=Upper case Does\ nothing.=Does nothing. Identity=Identity @@ -2089,6 +2089,7 @@ Please\ provide\ a\ valid\ aux\ file.=Please provide a valid aux file. Keyword\ delimiter=Keyword delimiter Hierarchical\ keyword\ delimiter=Hierarchical keyword delimiter Escape\ ampersands=Escape ampersands +Escape\ dollar\ sign=Escape dollar sign Hint\:\n\nTo\ search\ all\ fields\ for\ Smith,\ enter\:\nsmith\n\nTo\ search\ the\ field\ author\ for\ Smith\ and\ the\ field\ title\ for\ electrical,\ enter\:\nauthor\=Smith\ and\ title\=electrical=Hint:\n\nTo search all fields for Smith, enter:\nsmith\n\nTo search the field author for Smith and the field title for electrical, enter:\nauthor=Smith and title=electrical @@ -2444,6 +2445,9 @@ Grobid\ URL=Grobid URL Remote\ services=Remote services Allow\ sending\ PDF\ files\ and\ raw\ citation\ strings\ to\ a\ JabRef\ online\ service\ (Grobid)\ to\ determine\ Metadata.\ This\ produces\ better\ results.=Allow sending PDF files and raw citation strings to a JabRef online service (Grobid) to determine Metadata. This produces better results. +Fetcher\ cannot\ be\ tested\!=Fetcher cannot be tested! +Fetcher\ unknown\!=Fetcher unknown! + Character\ by\ character=Character by character Embedded=Embedded Entry=Entry @@ -2476,3 +2480,6 @@ Error\ downloading=Error downloading Error\ while\ writing\ metadata.\ See\ the\ error\ log\ for\ details.=Error while writing metadata. See the error log for details. Failed\ to\ write\ metadata,\ file\ %1\ not\ found.=Failed to write metadata, file %1 not found. Success\!\ Finished\ writing\ metadata.=Success! Finished writing metadata. + +Custom\ API\ key=Custom API key +Check\ %0\ API\ Key\ Setting=Check %0 API Key Setting diff --git a/src/test/java/org/jabref/logic/net/URLDownloadTest.java b/src/test/java/org/jabref/logic/net/URLDownloadTest.java index 8891cb91579..0fff41a535c 100644 --- a/src/test/java/org/jabref/logic/net/URLDownloadTest.java +++ b/src/test/java/org/jabref/logic/net/URLDownloadTest.java @@ -25,6 +25,22 @@ public void testStringDownloadWithSetEncoding() throws IOException { assertTrue(dl.asString().contains("Google"), "google.com should contain google"); } + // test client error 404 + @Test + public void testStringDownloadThrowClientError() throws IOException { + URLDownload dl = new URLDownload(new URL("http://httpstat.us/404")); + IOException exception = assertThrows(IOException.class, dl::asString); + assertTrue(exception.getLocalizedMessage().contentEquals("Client Error 404"), "Should be Client Error."); + } + + // test server error 503 + @Test + public void testStringDownloadThrowServerError() throws IOException { + URLDownload dl = new URLDownload(new URL("http://httpstat.us/503")); + IOException exception = assertThrows(IOException.class, dl::asString); + assertTrue(exception.getLocalizedMessage().contentEquals("Server Error 503"), "Should be Server Error."); + } + @Test public void testStringDownload() throws IOException { URLDownload dl = new URLDownload(new URL("http://www.google.com")); From f06021a54330ebe65cef56fab0192ee103acd522 Mon Sep 17 00:00:00 2001 From: zkl-ai <907668776@qq.com> Date: Sun, 22 May 2022 23:28:58 +0800 Subject: [PATCH 03/27] modify dio exception handler change dialog from "No DOI data exits" to "No DOI data was found" --- .../java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java | 2 +- src/main/java/org/jabref/logic/net/URLDownload.java | 4 ++-- src/test/java/org/jabref/logic/net/URLDownloadTest.java | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java b/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java index 5916d1483cd..a1e9b238627 100644 --- a/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java +++ b/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java @@ -79,7 +79,7 @@ public void fetchAndMerge(BibEntry entry, List fields) { String localMessage = exception.getCause().getLocalizedMessage(); // client error if (localMessage.startsWith("Client")) { - dialogService.showInformationDialogAndWait(Localization.lang("Lookup DOI"), Localization.lang("No DOI data exists")); + dialogService.showInformationDialogAndWait(Localization.lang("Lookup DOI"), Localization.lang("No DOI data was found")); // server error } else if (localMessage.startsWith("Server")) { dialogService.showInformationDialogAndWait(Localization.lang("Lookup DOI"), Localization.lang("DOI server not available")); diff --git a/src/main/java/org/jabref/logic/net/URLDownload.java b/src/main/java/org/jabref/logic/net/URLDownload.java index aef68369877..21c33561727 100644 --- a/src/main/java/org/jabref/logic/net/URLDownload.java +++ b/src/main/java/org/jabref/logic/net/URLDownload.java @@ -364,11 +364,11 @@ private URLConnection openConnection() throws IOException { } // status code 4xx if (status > HttpURLConnection.HTTP_BAD_REQUEST && status < HttpURLConnection.HTTP_INTERNAL_ERROR) { - throw new IOException(Localization.lang("Client Error " + status)); + throw new IOException(Localization.lang(("Client Error:" + status))); // status code 5xx } else if (status >= HttpURLConnection.HTTP_INTERNAL_ERROR) { - throw new IOException(Localization.lang("Server Error " + status)); + throw new IOException(Localization.lang(("Server Error:" + status))); } } diff --git a/src/test/java/org/jabref/logic/net/URLDownloadTest.java b/src/test/java/org/jabref/logic/net/URLDownloadTest.java index 0fff41a535c..1e5beb7ca17 100644 --- a/src/test/java/org/jabref/logic/net/URLDownloadTest.java +++ b/src/test/java/org/jabref/logic/net/URLDownloadTest.java @@ -30,7 +30,7 @@ public void testStringDownloadWithSetEncoding() throws IOException { public void testStringDownloadThrowClientError() throws IOException { URLDownload dl = new URLDownload(new URL("http://httpstat.us/404")); IOException exception = assertThrows(IOException.class, dl::asString); - assertTrue(exception.getLocalizedMessage().contentEquals("Client Error 404"), "Should be Client Error."); + assertTrue(exception.getLocalizedMessage().contentEquals("Client Error:404"), "Should be Client Error."); } // test server error 503 @@ -38,7 +38,7 @@ public void testStringDownloadThrowClientError() throws IOException { public void testStringDownloadThrowServerError() throws IOException { URLDownload dl = new URLDownload(new URL("http://httpstat.us/503")); IOException exception = assertThrows(IOException.class, dl::asString); - assertTrue(exception.getLocalizedMessage().contentEquals("Server Error 503"), "Should be Server Error."); + assertTrue(exception.getLocalizedMessage().contentEquals("Server Error:503"), "Should be Server Error."); } @Test From d32eae2617b00861b01d8418255a7e3ca32635b0 Mon Sep 17 00:00:00 2001 From: zkl-ai <907668776@qq.com> Date: Mon, 23 May 2022 00:26:34 +0800 Subject: [PATCH 04/27] modify Localization.lang(message) --- src/main/java/org/jabref/logic/net/URLDownload.java | 6 ++++-- src/test/java/org/jabref/logic/net/URLDownloadTest.java | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/jabref/logic/net/URLDownload.java b/src/main/java/org/jabref/logic/net/URLDownload.java index eba4bf3b07d..00efafd1213 100644 --- a/src/main/java/org/jabref/logic/net/URLDownload.java +++ b/src/main/java/org/jabref/logic/net/URLDownload.java @@ -363,11 +363,13 @@ private URLConnection openConnection() throws IOException { } // status code 4xx if (status > HttpURLConnection.HTTP_BAD_REQUEST && status < HttpURLConnection.HTTP_INTERNAL_ERROR) { - throw new IOException(Localization.lang(("Client Error:" + status))); + String message = String.format("Client Error %d", status); + throw new IOException(Localization.lang(message)); // status code 5xx } else if (status >= HttpURLConnection.HTTP_INTERNAL_ERROR) { - throw new IOException(Localization.lang(("Server Error:" + status))); + String message = String.format("Server Error %d", status); + throw new IOException(Localization.lang(message)); } } diff --git a/src/test/java/org/jabref/logic/net/URLDownloadTest.java b/src/test/java/org/jabref/logic/net/URLDownloadTest.java index 27b157c7743..4b5e92cb924 100644 --- a/src/test/java/org/jabref/logic/net/URLDownloadTest.java +++ b/src/test/java/org/jabref/logic/net/URLDownloadTest.java @@ -33,7 +33,7 @@ public void testStringDownloadWithSetEncoding() throws IOException { public void testStringDownloadThrowClientError() throws IOException { URLDownload dl = new URLDownload(new URL("http://httpstat.us/404")); IOException exception = assertThrows(IOException.class, dl::asString); - assertTrue(exception.getLocalizedMessage().contentEquals("Client Error:404"), "Should be Client Error."); + assertTrue(exception.getLocalizedMessage().contentEquals("Client Error 404"), "Should be Client Error."); } // test server error 503 @@ -41,7 +41,7 @@ public void testStringDownloadThrowClientError() throws IOException { public void testStringDownloadThrowServerError() throws IOException { URLDownload dl = new URLDownload(new URL("http://httpstat.us/503")); IOException exception = assertThrows(IOException.class, dl::asString); - assertTrue(exception.getLocalizedMessage().contentEquals("Server Error:503"), "Should be Server Error."); + assertTrue(exception.getLocalizedMessage().contentEquals("Server Error 503"), "Should be Server Error."); } @Test From a6ec4699a0a75d42f0791f87f91225372b052436 Mon Sep 17 00:00:00 2001 From: zkl-ai <907668776@qq.com> Date: Mon, 23 May 2022 01:15:20 +0800 Subject: [PATCH 05/27] modify Localization.lang("Client Error") and Localization.lang("Server Error") --- src/main/java/org/jabref/logic/net/URLDownload.java | 6 ++---- src/test/java/org/jabref/logic/net/URLDownloadTest.java | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/jabref/logic/net/URLDownload.java b/src/main/java/org/jabref/logic/net/URLDownload.java index 00efafd1213..4719689bbc4 100644 --- a/src/main/java/org/jabref/logic/net/URLDownload.java +++ b/src/main/java/org/jabref/logic/net/URLDownload.java @@ -363,13 +363,11 @@ private URLConnection openConnection() throws IOException { } // status code 4xx if (status > HttpURLConnection.HTTP_BAD_REQUEST && status < HttpURLConnection.HTTP_INTERNAL_ERROR) { - String message = String.format("Client Error %d", status); - throw new IOException(Localization.lang(message)); + throw new IOException(Localization.lang("Client Error")); // status code 5xx } else if (status >= HttpURLConnection.HTTP_INTERNAL_ERROR) { - String message = String.format("Server Error %d", status); - throw new IOException(Localization.lang(message)); + throw new IOException(Localization.lang("Server Error")); } } diff --git a/src/test/java/org/jabref/logic/net/URLDownloadTest.java b/src/test/java/org/jabref/logic/net/URLDownloadTest.java index 4b5e92cb924..aeb4544dab1 100644 --- a/src/test/java/org/jabref/logic/net/URLDownloadTest.java +++ b/src/test/java/org/jabref/logic/net/URLDownloadTest.java @@ -33,7 +33,7 @@ public void testStringDownloadWithSetEncoding() throws IOException { public void testStringDownloadThrowClientError() throws IOException { URLDownload dl = new URLDownload(new URL("http://httpstat.us/404")); IOException exception = assertThrows(IOException.class, dl::asString); - assertTrue(exception.getLocalizedMessage().contentEquals("Client Error 404"), "Should be Client Error."); + assertTrue(exception.getLocalizedMessage().contentEquals("Client Error"), "Should be Client Error."); } // test server error 503 @@ -41,7 +41,7 @@ public void testStringDownloadThrowClientError() throws IOException { public void testStringDownloadThrowServerError() throws IOException { URLDownload dl = new URLDownload(new URL("http://httpstat.us/503")); IOException exception = assertThrows(IOException.class, dl::asString); - assertTrue(exception.getLocalizedMessage().contentEquals("Server Error 503"), "Should be Server Error."); + assertTrue(exception.getLocalizedMessage().contentEquals("Server Error"), "Should be Server Error."); } @Test From b3ac167446c87331962c535698fe6b6894a9fa68 Mon Sep 17 00:00:00 2001 From: zkl-ai <907668776@qq.com> Date: Mon, 23 May 2022 01:41:29 +0800 Subject: [PATCH 06/27] pass LocalizationConsistencyTest --- src/main/java/org/jabref/logic/net/URLDownload.java | 4 ++-- src/main/resources/l10n/JabRef_en.properties | 6 ++++++ src/test/java/org/jabref/logic/net/URLDownloadTest.java | 4 ++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/jabref/logic/net/URLDownload.java b/src/main/java/org/jabref/logic/net/URLDownload.java index 4719689bbc4..0749072cac2 100644 --- a/src/main/java/org/jabref/logic/net/URLDownload.java +++ b/src/main/java/org/jabref/logic/net/URLDownload.java @@ -363,11 +363,11 @@ private URLConnection openConnection() throws IOException { } // status code 4xx if (status > HttpURLConnection.HTTP_BAD_REQUEST && status < HttpURLConnection.HTTP_INTERNAL_ERROR) { - throw new IOException(Localization.lang("Client Error")); + throw new IOException(Localization.lang("Client Error %0", status)); // status code 5xx } else if (status >= HttpURLConnection.HTTP_INTERNAL_ERROR) { - throw new IOException(Localization.lang("Server Error")); + throw new IOException(Localization.lang("Server Error %0", status)); } } diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index a42cd243fae..37bc161d7e7 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -2487,3 +2487,9 @@ Success\!\ Finished\ writing\ metadata.=Success! Finished writing metadata. Custom\ API\ key=Custom API key Check\ %0\ API\ Key\ Setting=Check %0 API Key Setting + +Client\ Error\ %0=Client Error %0 +DOI\ server\ not\ available=DOI server not available +Lookup\ DOI=Lookup DOI +No\ DOI\ data\ was\ found=No DOI data was found +Server\ Error\ %0=Server Error %0 diff --git a/src/test/java/org/jabref/logic/net/URLDownloadTest.java b/src/test/java/org/jabref/logic/net/URLDownloadTest.java index aeb4544dab1..4b5e92cb924 100644 --- a/src/test/java/org/jabref/logic/net/URLDownloadTest.java +++ b/src/test/java/org/jabref/logic/net/URLDownloadTest.java @@ -33,7 +33,7 @@ public void testStringDownloadWithSetEncoding() throws IOException { public void testStringDownloadThrowClientError() throws IOException { URLDownload dl = new URLDownload(new URL("http://httpstat.us/404")); IOException exception = assertThrows(IOException.class, dl::asString); - assertTrue(exception.getLocalizedMessage().contentEquals("Client Error"), "Should be Client Error."); + assertTrue(exception.getLocalizedMessage().contentEquals("Client Error 404"), "Should be Client Error."); } // test server error 503 @@ -41,7 +41,7 @@ public void testStringDownloadThrowClientError() throws IOException { public void testStringDownloadThrowServerError() throws IOException { URLDownload dl = new URLDownload(new URL("http://httpstat.us/503")); IOException exception = assertThrows(IOException.class, dl::asString); - assertTrue(exception.getLocalizedMessage().contentEquals("Server Error"), "Should be Server Error."); + assertTrue(exception.getLocalizedMessage().contentEquals("Server Error 503"), "Should be Server Error."); } @Test From 6bf38c4269a47992358d096a7fe9c07a482aa873 Mon Sep 17 00:00:00 2001 From: zkl-ai <907668776@qq.com> Date: Mon, 23 May 2022 03:50:40 +0800 Subject: [PATCH 07/27] pass fetcher test --- .../gui/mergeentries/FetchAndMergeEntry.java | 2 +- .../logic/importer/fetcher/DoiFetcher.java | 20 +++++++++++++++++-- .../org/jabref/logic/net/URLDownload.java | 9 --------- src/main/resources/l10n/JabRef_en.properties | 6 ++---- .../importer/fetcher/DoiFetcherTest.java | 15 ++++++++++++++ .../org/jabref/logic/net/URLDownloadTest.java | 16 --------------- 6 files changed, 36 insertions(+), 32 deletions(-) diff --git a/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java b/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java index a1e9b238627..2fdf2bad130 100644 --- a/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java +++ b/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java @@ -76,7 +76,7 @@ public void fetchAndMerge(BibEntry entry, List fields) { }) .onFailure(exception -> { LOGGER.error("Error while fetching bibliographic information", exception); - String localMessage = exception.getCause().getLocalizedMessage(); + String localMessage = exception.getLocalizedMessage(); // client error if (localMessage.startsWith("Client")) { dialogService.showInformationDialogAndWait(Localization.lang("Lookup DOI"), Localization.lang("No DOI data was found")); diff --git a/src/main/java/org/jabref/logic/importer/fetcher/DoiFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/DoiFetcher.java index 41afea25707..c7d4b2c92ca 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/DoiFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/DoiFetcher.java @@ -1,5 +1,6 @@ package org.jabref.logic.importer.fetcher; +import java.io.FileNotFoundException; import java.io.IOException; import java.net.URL; import java.util.Collections; @@ -72,7 +73,6 @@ public Optional performSearchById(String identifier) throws FetcherExc return new Medra().performSearchById(identifier); } URL doiURL = new URL(doi.get().getURIAsASCIIString()); - // BibTeX data URLDownload download = getUrlDownload(doiURL); download.addHeader("Accept", MediaTypes.APPLICATION_BIBTEX); @@ -81,7 +81,12 @@ public Optional performSearchById(String identifier) throws FetcherExc bibtexString = download.asString(); } catch (IOException e) { // an IOException will be thrown if download is unable to download from the doiURL - throw new FetcherException(Localization.lang("No DOI data exists"), e); + // dispatch the IOException + if (e instanceof FileNotFoundException) { + throw new FetcherException(Localization.lang("Client Error"), e); + } else { + throw new FetcherException(Localization.lang("Server Error"), e); + } } // BibTeX entry @@ -109,6 +114,17 @@ public Optional performSearchById(String identifier) throws FetcherExc } } + /** + * Returns client error or server error according to the message + * + * @param exception the IOException + */ + private String dispatchIOException(IOException exception) { + String classification = "Client Error"; + + return classification; + } + private void doPostCleanup(BibEntry entry) { new FieldFormatterCleanup(StandardField.PAGES, new NormalizePagesFormatter()).cleanup(entry); new FieldFormatterCleanup(StandardField.URL, new ClearFormatter()).cleanup(entry); diff --git a/src/main/java/org/jabref/logic/net/URLDownload.java b/src/main/java/org/jabref/logic/net/URLDownload.java index 0749072cac2..77ac1ff3093 100644 --- a/src/main/java/org/jabref/logic/net/URLDownload.java +++ b/src/main/java/org/jabref/logic/net/URLDownload.java @@ -40,7 +40,6 @@ import javax.net.ssl.TrustManager; import javax.net.ssl.X509TrustManager; -import org.jabref.logic.l10n.Localization; import org.jabref.logic.util.io.FileUtil; import org.jabref.model.util.FileHelper; @@ -361,14 +360,6 @@ private URLConnection openConnection() throws IOException { connection = new URLDownload(newUrl).openConnection(); } } - // status code 4xx - if (status > HttpURLConnection.HTTP_BAD_REQUEST && status < HttpURLConnection.HTTP_INTERNAL_ERROR) { - throw new IOException(Localization.lang("Client Error %0", status)); - - // status code 5xx - } else if (status >= HttpURLConnection.HTTP_INTERNAL_ERROR) { - throw new IOException(Localization.lang("Server Error %0", status)); - } } // this does network i/o: GET + read returned headers diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index 37bc161d7e7..9deb0e71307 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -580,8 +580,6 @@ No\ journal\ names\ could\ be\ abbreviated.=No journal names could be abbreviate No\ journal\ names\ could\ be\ unabbreviated.=No journal names could be unabbreviated. -No\ DOI\ data\ exists=No DOI data exists - not=not not\ found=not found @@ -2488,8 +2486,8 @@ Success\!\ Finished\ writing\ metadata.=Success! Finished writing metadata. Custom\ API\ key=Custom API key Check\ %0\ API\ Key\ Setting=Check %0 API Key Setting -Client\ Error\ %0=Client Error %0 +Client\ Error=Client Error DOI\ server\ not\ available=DOI server not available Lookup\ DOI=Lookup DOI No\ DOI\ data\ was\ found=No DOI data was found -Server\ Error\ %0=Server Error %0 +Server\ Error=Server Error diff --git a/src/test/java/org/jabref/logic/importer/fetcher/DoiFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/DoiFetcherTest.java index 299ff91c8fa..0fcec9de7f7 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/DoiFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/DoiFetcherTest.java @@ -15,6 +15,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; @FetcherTest @@ -117,6 +118,20 @@ public void testPerformSearchInvalidDOI() { assertThrows(FetcherException.class, () -> fetcher.performSearchById("10.1002/9781118257517F")); } + // test invalid DOI client error message "Client Error" + @Test + public void testPerformSearchInvalidDOIClientErrorMessage1() { + FetcherException exception = assertThrows(FetcherException.class, () -> fetcher.performSearchById("10.1002/9781118257517F")); + assertTrue(exception.getLocalizedMessage().contentEquals("Client Error")); + } + + // test invalid DOI client error message "Client Error" + @Test + public void testPerformSearchInvalidDOIClientErrorMessage2() { + FetcherException exception = assertThrows(FetcherException.class, () -> fetcher.performSearchById("10.1002/9781517F")); + assertTrue(exception.getLocalizedMessage().contentEquals("Client Error")); + } + @Test public void testPerformSearchNonTrimmedDOI() throws FetcherException { Optional fetchedEntry = fetcher.performSearchById("http s://doi.org/ 10.1109 /ICWS .2007.59 "); diff --git a/src/test/java/org/jabref/logic/net/URLDownloadTest.java b/src/test/java/org/jabref/logic/net/URLDownloadTest.java index 4b5e92cb924..84c63c6b74d 100644 --- a/src/test/java/org/jabref/logic/net/URLDownloadTest.java +++ b/src/test/java/org/jabref/logic/net/URLDownloadTest.java @@ -28,22 +28,6 @@ public void testStringDownloadWithSetEncoding() throws IOException { assertTrue(dl.asString().contains("Google"), "google.com should contain google"); } - // test client error 404 - @Test - public void testStringDownloadThrowClientError() throws IOException { - URLDownload dl = new URLDownload(new URL("http://httpstat.us/404")); - IOException exception = assertThrows(IOException.class, dl::asString); - assertTrue(exception.getLocalizedMessage().contentEquals("Client Error 404"), "Should be Client Error."); - } - - // test server error 503 - @Test - public void testStringDownloadThrowServerError() throws IOException { - URLDownload dl = new URLDownload(new URL("http://httpstat.us/503")); - IOException exception = assertThrows(IOException.class, dl::asString); - assertTrue(exception.getLocalizedMessage().contentEquals("Server Error 503"), "Should be Server Error."); - } - @Test public void testStringDownload() throws IOException { URLDownload dl = new URLDownload(new URL("http://www.google.com")); From 8e5b82adc41a8f996cbeb45b81b888d897abb618 Mon Sep 17 00:00:00 2001 From: zkl-ai <907668776@qq.com> Date: Tue, 24 May 2022 11:22:12 +0800 Subject: [PATCH 08/27] improve the implementation with two add Exception DOIDataNotFoundException and DOIServerNotAvailableException --- .../gui/mergeentries/FetchAndMergeEntry.java | 7 ++++--- .../logic/importer/DOIDataNotFoundException.java | 16 ++++++++++++++++ .../importer/DOIServerNotAvailableException.java | 15 +++++++++++++++ .../logic/importer/fetcher/DoiFetcher.java | 6 ++++-- .../logic/importer/fetcher/DoiFetcherTest.java | 8 +++----- 5 files changed, 42 insertions(+), 10 deletions(-) create mode 100644 src/main/java/org/jabref/logic/importer/DOIDataNotFoundException.java create mode 100644 src/main/java/org/jabref/logic/importer/DOIServerNotAvailableException.java diff --git a/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java b/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java index 2fdf2bad130..89e623780e8 100644 --- a/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java +++ b/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java @@ -16,6 +16,8 @@ import org.jabref.gui.undo.UndoableFieldChange; import org.jabref.gui.util.BackgroundTask; import org.jabref.gui.util.TaskExecutor; +import org.jabref.logic.importer.DOIDataNotFoundException; +import org.jabref.logic.importer.DOIServerNotAvailableException; import org.jabref.logic.importer.EntryBasedFetcher; import org.jabref.logic.importer.IdBasedFetcher; import org.jabref.logic.importer.ImportCleanup; @@ -76,12 +78,11 @@ public void fetchAndMerge(BibEntry entry, List fields) { }) .onFailure(exception -> { LOGGER.error("Error while fetching bibliographic information", exception); - String localMessage = exception.getLocalizedMessage(); // client error - if (localMessage.startsWith("Client")) { + if (exception instanceof DOIDataNotFoundException) { dialogService.showInformationDialogAndWait(Localization.lang("Lookup DOI"), Localization.lang("No DOI data was found")); // server error - } else if (localMessage.startsWith("Server")) { + } else if (exception instanceof DOIServerNotAvailableException) { dialogService.showInformationDialogAndWait(Localization.lang("Lookup DOI"), Localization.lang("DOI server not available")); // default error } else { diff --git a/src/main/java/org/jabref/logic/importer/DOIDataNotFoundException.java b/src/main/java/org/jabref/logic/importer/DOIDataNotFoundException.java new file mode 100644 index 00000000000..594b3bb018d --- /dev/null +++ b/src/main/java/org/jabref/logic/importer/DOIDataNotFoundException.java @@ -0,0 +1,16 @@ +package org.jabref.logic.importer; + +public class DOIDataNotFoundException extends FetcherException { + + public DOIDataNotFoundException(String errorMessage, Throwable cause) { + super(errorMessage, cause); + } + + public DOIDataNotFoundException(String errorMessage) { + super(errorMessage); + } + + public DOIDataNotFoundException(String errorMessage, String localizedMessage, Throwable cause) { + super(errorMessage, localizedMessage, cause); + } +} diff --git a/src/main/java/org/jabref/logic/importer/DOIServerNotAvailableException.java b/src/main/java/org/jabref/logic/importer/DOIServerNotAvailableException.java new file mode 100644 index 00000000000..91c9a96787b --- /dev/null +++ b/src/main/java/org/jabref/logic/importer/DOIServerNotAvailableException.java @@ -0,0 +1,15 @@ +package org.jabref.logic.importer; + +public class DOIServerNotAvailableException extends FetcherException { + public DOIServerNotAvailableException(String errorMessage, Throwable cause) { + super(errorMessage, cause); + } + + public DOIServerNotAvailableException(String errorMessage) { + super(errorMessage); + } + + public DOIServerNotAvailableException(String errorMessage, String localizedMessage, Throwable cause) { + super(errorMessage, localizedMessage, cause); + } +} diff --git a/src/main/java/org/jabref/logic/importer/fetcher/DoiFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/DoiFetcher.java index c7d4b2c92ca..4013af912fb 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/DoiFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/DoiFetcher.java @@ -12,6 +12,8 @@ import org.jabref.logic.formatter.bibtexfields.ClearFormatter; import org.jabref.logic.formatter.bibtexfields.NormalizePagesFormatter; import org.jabref.logic.help.HelpFile; +import org.jabref.logic.importer.DOIDataNotFoundException; +import org.jabref.logic.importer.DOIServerNotAvailableException; import org.jabref.logic.importer.EntryBasedFetcher; import org.jabref.logic.importer.FetcherException; import org.jabref.logic.importer.IdBasedFetcher; @@ -83,9 +85,9 @@ public Optional performSearchById(String identifier) throws FetcherExc // an IOException will be thrown if download is unable to download from the doiURL // dispatch the IOException if (e instanceof FileNotFoundException) { - throw new FetcherException(Localization.lang("Client Error"), e); + throw new DOIDataNotFoundException(Localization.lang("Client Error"), e); } else { - throw new FetcherException(Localization.lang("Server Error"), e); + throw new DOIServerNotAvailableException(Localization.lang("Server Error"), e); } } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/DoiFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/DoiFetcherTest.java index 0fcec9de7f7..979f3f5238b 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/DoiFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/DoiFetcherTest.java @@ -2,6 +2,7 @@ import java.util.Optional; +import org.jabref.logic.importer.DOIDataNotFoundException; import org.jabref.logic.importer.FetcherException; import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.model.entry.BibEntry; @@ -15,7 +16,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; @FetcherTest @@ -121,15 +121,13 @@ public void testPerformSearchInvalidDOI() { // test invalid DOI client error message "Client Error" @Test public void testPerformSearchInvalidDOIClientErrorMessage1() { - FetcherException exception = assertThrows(FetcherException.class, () -> fetcher.performSearchById("10.1002/9781118257517F")); - assertTrue(exception.getLocalizedMessage().contentEquals("Client Error")); + assertThrows(DOIDataNotFoundException.class, () -> fetcher.performSearchById("10.1002/9781118257517F")); } // test invalid DOI client error message "Client Error" @Test public void testPerformSearchInvalidDOIClientErrorMessage2() { - FetcherException exception = assertThrows(FetcherException.class, () -> fetcher.performSearchById("10.1002/9781517F")); - assertTrue(exception.getLocalizedMessage().contentEquals("Client Error")); + assertThrows(DOIDataNotFoundException.class, () -> fetcher.performSearchById("10.1002/9781517F")); } @Test From 38f3e52ac8358c7ba7f0672c004ad8509647d2ce Mon Sep 17 00:00:00 2001 From: zkl-ai <907668776@qq.com> Date: Tue, 24 May 2022 12:06:28 +0800 Subject: [PATCH 09/27] improve the implementation with two add Exception DOIDataNotFoundException and DOIServerNotAvailableException and improved --- .../org/jabref/logic/importer/fetcher/DoiFetcher.java | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/main/java/org/jabref/logic/importer/fetcher/DoiFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/DoiFetcher.java index 4013af912fb..0d038b725a2 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/DoiFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/DoiFetcher.java @@ -116,17 +116,6 @@ public Optional performSearchById(String identifier) throws FetcherExc } } - /** - * Returns client error or server error according to the message - * - * @param exception the IOException - */ - private String dispatchIOException(IOException exception) { - String classification = "Client Error"; - - return classification; - } - private void doPostCleanup(BibEntry entry) { new FieldFormatterCleanup(StandardField.PAGES, new NormalizePagesFormatter()).cleanup(entry); new FieldFormatterCleanup(StandardField.URL, new ClearFormatter()).cleanup(entry); From 2561d32e8d93464d6a9bde73ccf2993707e83db4 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Thu, 14 Jul 2022 22:09:08 +0200 Subject: [PATCH 10/27] Add FetcherClientException and FetcherServerException --- .../gui/mergeentries/FetchAndMergeEntry.java | 12 ++++----- .../importer/DOIDataNotFoundException.java | 16 ------------ .../DOIServerNotAvailableException.java | 15 ----------- .../importer/FetcherClientException.java | 20 ++++++++++++++ .../importer/FetcherServerException.java | 19 ++++++++++++++ .../logic/importer/fetcher/DoiFetcher.java | 13 +++------- .../org/jabref/logic/net/URLDownload.java | 26 ++++++++++++------- src/main/resources/l10n/JabRef_en.properties | 11 +++----- .../importer/fetcher/DoiFetcherTest.java | 18 ++++++------- .../org/jabref/logic/net/URLDownloadTest.java | 19 ++++++++++++++ 10 files changed, 97 insertions(+), 72 deletions(-) delete mode 100644 src/main/java/org/jabref/logic/importer/DOIDataNotFoundException.java delete mode 100644 src/main/java/org/jabref/logic/importer/DOIServerNotAvailableException.java create mode 100644 src/main/java/org/jabref/logic/importer/FetcherClientException.java create mode 100644 src/main/java/org/jabref/logic/importer/FetcherServerException.java diff --git a/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java b/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java index 89e623780e8..58514e4fb61 100644 --- a/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java +++ b/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java @@ -16,9 +16,9 @@ import org.jabref.gui.undo.UndoableFieldChange; import org.jabref.gui.util.BackgroundTask; import org.jabref.gui.util.TaskExecutor; -import org.jabref.logic.importer.DOIDataNotFoundException; -import org.jabref.logic.importer.DOIServerNotAvailableException; import org.jabref.logic.importer.EntryBasedFetcher; +import org.jabref.logic.importer.FetcherClientException; +import org.jabref.logic.importer.FetcherServerException; import org.jabref.logic.importer.IdBasedFetcher; import org.jabref.logic.importer.ImportCleanup; import org.jabref.logic.importer.WebFetcher; @@ -79,11 +79,11 @@ public void fetchAndMerge(BibEntry entry, List fields) { .onFailure(exception -> { LOGGER.error("Error while fetching bibliographic information", exception); // client error - if (exception instanceof DOIDataNotFoundException) { - dialogService.showInformationDialogAndWait(Localization.lang("Lookup DOI"), Localization.lang("No DOI data was found")); + if (exception instanceof FetcherClientException) { + dialogService.showInformationDialogAndWait(Localization.lang("Lookup {0}", fetcher.get().getName()), Localization.lang("No data was found for the identifier")); // server error - } else if (exception instanceof DOIServerNotAvailableException) { - dialogService.showInformationDialogAndWait(Localization.lang("Lookup DOI"), Localization.lang("DOI server not available")); + } else if (exception instanceof FetcherServerException) { + dialogService.showInformationDialogAndWait(Localization.lang("Lookup {0}", fetcher.get().getName()), Localization.lang("Server not available")); // default error } else { dialogService.showErrorDialogAndWait(exception); diff --git a/src/main/java/org/jabref/logic/importer/DOIDataNotFoundException.java b/src/main/java/org/jabref/logic/importer/DOIDataNotFoundException.java deleted file mode 100644 index 594b3bb018d..00000000000 --- a/src/main/java/org/jabref/logic/importer/DOIDataNotFoundException.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.jabref.logic.importer; - -public class DOIDataNotFoundException extends FetcherException { - - public DOIDataNotFoundException(String errorMessage, Throwable cause) { - super(errorMessage, cause); - } - - public DOIDataNotFoundException(String errorMessage) { - super(errorMessage); - } - - public DOIDataNotFoundException(String errorMessage, String localizedMessage, Throwable cause) { - super(errorMessage, localizedMessage, cause); - } -} diff --git a/src/main/java/org/jabref/logic/importer/DOIServerNotAvailableException.java b/src/main/java/org/jabref/logic/importer/DOIServerNotAvailableException.java deleted file mode 100644 index 91c9a96787b..00000000000 --- a/src/main/java/org/jabref/logic/importer/DOIServerNotAvailableException.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.jabref.logic.importer; - -public class DOIServerNotAvailableException extends FetcherException { - public DOIServerNotAvailableException(String errorMessage, Throwable cause) { - super(errorMessage, cause); - } - - public DOIServerNotAvailableException(String errorMessage) { - super(errorMessage); - } - - public DOIServerNotAvailableException(String errorMessage, String localizedMessage, Throwable cause) { - super(errorMessage, localizedMessage, cause); - } -} diff --git a/src/main/java/org/jabref/logic/importer/FetcherClientException.java b/src/main/java/org/jabref/logic/importer/FetcherClientException.java new file mode 100644 index 00000000000..3d308e7d1b2 --- /dev/null +++ b/src/main/java/org/jabref/logic/importer/FetcherClientException.java @@ -0,0 +1,20 @@ +package org.jabref.logic.importer; + +/** + * Should be thrown when you encounter a http status code error >= 400 and < 500 + */ +public class FetcherClientException extends FetcherException { + + public FetcherClientException(String errorMessage, Throwable cause) { + super(errorMessage, cause); + } + + public FetcherClientException(String errorMessage) { + super(errorMessage); + } + + public FetcherClientException(String errorMessage, String localizedMessage, Throwable cause) { + super(errorMessage, localizedMessage, cause); + } + +} diff --git a/src/main/java/org/jabref/logic/importer/FetcherServerException.java b/src/main/java/org/jabref/logic/importer/FetcherServerException.java new file mode 100644 index 00000000000..6b3342e115f --- /dev/null +++ b/src/main/java/org/jabref/logic/importer/FetcherServerException.java @@ -0,0 +1,19 @@ +package org.jabref.logic.importer; +/** + * Should be thrown when you encounter a http status code error >= 500 + */ +public class FetcherServerException extends FetcherException { + + public FetcherServerException(String errorMessage, Throwable cause) { + super(errorMessage, cause); + } + + public FetcherServerException(String errorMessage) { + super(errorMessage); + } + + public FetcherServerException(String errorMessage, String localizedMessage, Throwable cause) { + super(errorMessage, localizedMessage, cause); + } + +} diff --git a/src/main/java/org/jabref/logic/importer/fetcher/DoiFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/DoiFetcher.java index 0d038b725a2..4f0927ef468 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/DoiFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/DoiFetcher.java @@ -1,6 +1,5 @@ package org.jabref.logic.importer.fetcher; -import java.io.FileNotFoundException; import java.io.IOException; import java.net.URL; import java.util.Collections; @@ -12,8 +11,6 @@ import org.jabref.logic.formatter.bibtexfields.ClearFormatter; import org.jabref.logic.formatter.bibtexfields.NormalizePagesFormatter; import org.jabref.logic.help.HelpFile; -import org.jabref.logic.importer.DOIDataNotFoundException; -import org.jabref.logic.importer.DOIServerNotAvailableException; import org.jabref.logic.importer.EntryBasedFetcher; import org.jabref.logic.importer.FetcherException; import org.jabref.logic.importer.IdBasedFetcher; @@ -82,13 +79,11 @@ public Optional performSearchById(String identifier) throws FetcherExc try { bibtexString = download.asString(); } catch (IOException e) { - // an IOException will be thrown if download is unable to download from the doiURL - // dispatch the IOException - if (e instanceof FileNotFoundException) { - throw new DOIDataNotFoundException(Localization.lang("Client Error"), e); - } else { - throw new DOIServerNotAvailableException(Localization.lang("Server Error"), e); + // an IOException with a nested FetcherException will be thrown when you encounter a 400x or 500x http status code + if (e.getCause() instanceof FetcherException fe) { + throw fe; } + throw e; } // BibTeX entry diff --git a/src/main/java/org/jabref/logic/net/URLDownload.java b/src/main/java/org/jabref/logic/net/URLDownload.java index 77ac1ff3093..686bb2dc0e9 100644 --- a/src/main/java/org/jabref/logic/net/URLDownload.java +++ b/src/main/java/org/jabref/logic/net/URLDownload.java @@ -40,6 +40,8 @@ import javax.net.ssl.TrustManager; import javax.net.ssl.X509TrustManager; +import org.jabref.logic.importer.FetcherClientException; +import org.jabref.logic.importer.FetcherServerException; import org.jabref.logic.util.io.FileUtil; import org.jabref.model.util.FileHelper; @@ -350,16 +352,22 @@ private URLConnection openConnection() throws IOException { if (connection instanceof HttpURLConnection) { // normally, 3xx is redirect int status = ((HttpURLConnection) connection).getResponseCode(); - if (status != HttpURLConnection.HTTP_OK) { - if ((status == HttpURLConnection.HTTP_MOVED_TEMP) - || (status == HttpURLConnection.HTTP_MOVED_PERM) - || (status == HttpURLConnection.HTTP_SEE_OTHER)) { - // get redirect url from "location" header field - String newUrl = connection.getHeaderField("location"); - // open the new connnection again - connection = new URLDownload(newUrl).openConnection(); - } + + if ((status == HttpURLConnection.HTTP_MOVED_TEMP) + || (status == HttpURLConnection.HTTP_MOVED_PERM) + || (status == HttpURLConnection.HTTP_SEE_OTHER)) { + // get redirect url from "location" header field + String newUrl = connection.getHeaderField("location"); + // open the new connnection again + connection = new URLDownload(newUrl).openConnection(); + } + if ((status >= 400) && (status < 500)) { + throw new IOException(new FetcherClientException("Client error. Status code " + status)); } + if (status >= 500) { + throw new IOException(new FetcherServerException("Server error. Status Code " + status)); + } + } // this does network i/o: GET + read returned headers diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index 57644006707..b7a618d751d 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -2487,6 +2487,10 @@ Version=Version Error\ downloading=Error downloading +Lookup\ {0}=Lookup {0} +No\ data\ was\ found\ for\ the\ identifier=No data was found for the identifier +Server\ not\ available=Server not available + Error\ while\ writing\ metadata.\ See\ the\ error\ log\ for\ details.=Error while writing metadata. See the error log for details. Failed\ to\ write\ metadata,\ file\ %1\ not\ found.=Failed to write metadata, file %1 not found. Success\!\ Finished\ writing\ metadata.=Success! Finished writing metadata. @@ -2494,13 +2498,6 @@ Success\!\ Finished\ writing\ metadata.=Success! Finished writing metadata. Custom\ API\ key=Custom API key Check\ %0\ API\ Key\ Setting=Check %0 API Key Setting -Client\ Error=Client Error -DOI\ server\ not\ available=DOI server not available -Lookup\ DOI=Lookup DOI -No\ DOI\ data\ was\ found=No DOI data was found -Server\ Error=Server Error - - Edit\ field\ value=Edit field value Two\ fields=Two fields Overwrite\ Non\ empty\ fields=Overwrite Non empty fields diff --git a/src/test/java/org/jabref/logic/importer/fetcher/DoiFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/DoiFetcherTest.java index d5109dfd279..43cee6714f5 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/DoiFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/DoiFetcherTest.java @@ -2,7 +2,7 @@ import java.util.Optional; -import org.jabref.logic.importer.DOIDataNotFoundException; +import org.jabref.logic.importer.FetcherClientException; import org.jabref.logic.importer.FetcherException; import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.model.entry.BibEntry; @@ -20,9 +20,9 @@ @FetcherTest public class DoiFetcherTest { - private DoiFetcher fetcher = new DoiFetcher(mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS)); + private final DoiFetcher fetcher = new DoiFetcher(mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS)); - private BibEntry bibEntryBurd2011 = new BibEntry(StandardEntryType.Book) + private final BibEntry bibEntryBurd2011 = new BibEntry(StandardEntryType.Book) .withCitationKey("Burd_2011") .withField(StandardField.TITLE, "Java{\\textregistered} For Dummies{\\textregistered}") .withField(StandardField.PUBLISHER, "Wiley") @@ -30,7 +30,7 @@ public class DoiFetcherTest { .withField(StandardField.AUTHOR, "Barry Burd") .withField(StandardField.MONTH, "jul") .withField(StandardField.DOI, "10.1002/9781118257517"); - private BibEntry bibEntryDecker2007 = new BibEntry(StandardEntryType.InProceedings) + private final BibEntry bibEntryDecker2007 = new BibEntry(StandardEntryType.InProceedings) .withCitationKey("Decker_2007") .withField(StandardField.AUTHOR, "Gero Decker and Oliver Kopp and Frank Leymann and Mathias Weske") .withField(StandardField.BOOKTITLE, "{IEEE} International Conference on Web Services ({ICWS} 2007)") @@ -39,7 +39,7 @@ public class DoiFetcherTest { .withField(StandardField.TITLE, "{BPEL}4Chor: Extending {BPEL} for Modeling Choreographies") .withField(StandardField.YEAR, "2007") .withField(StandardField.DOI, "10.1109/icws.2007.59"); - private BibEntry bibEntryIannarelli2019 = new BibEntry(StandardEntryType.Article) + private final BibEntry bibEntryIannarelli2019 = new BibEntry(StandardEntryType.Article) .withField(StandardField.AUTHOR, "" + "Iannarelli Riccardo and " @@ -56,7 +56,7 @@ public class DoiFetcherTest { .withField(StandardField.JOURNAL, "Chemical Engineering Transactions") .withField(StandardField.PAGES, "871-876") .withField(StandardField.VOLUME, "77"); - private BibEntry bibEntryStenzel2020 = new BibEntry(StandardEntryType.Article) + private final BibEntry bibEntryStenzel2020 = new BibEntry(StandardEntryType.Article) .withCitationKey("Stenzel_2020") .withField(StandardField.AUTHOR, "L. Stenzel and A. L. C. Hayward and U. Schollwöck and F. Heidrich-Meisner") .withField(StandardField.JOURNAL, "Physical Review A") @@ -102,16 +102,14 @@ public void testPerformSearchInvalidDOI() { assertThrows(FetcherException.class, () -> fetcher.performSearchById("10.1002/9781118257517F")); } - // test invalid DOI client error message "Client Error" @Test public void testPerformSearchInvalidDOIClientErrorMessage1() { - assertThrows(DOIDataNotFoundException.class, () -> fetcher.performSearchById("10.1002/9781118257517F")); + assertThrows(FetcherClientException.class, () -> fetcher.performSearchById("10.1002/9781118257517F")); } - // test invalid DOI client error message "Client Error" @Test public void testPerformSearchInvalidDOIClientErrorMessage2() { - assertThrows(DOIDataNotFoundException.class, () -> fetcher.performSearchById("10.1002/9781517F")); + assertThrows(FetcherClientException.class, () -> fetcher.performSearchById("10.1002/9781517F")); } @Test diff --git a/src/test/java/org/jabref/logic/net/URLDownloadTest.java b/src/test/java/org/jabref/logic/net/URLDownloadTest.java index 84c63c6b74d..b7788d961fb 100644 --- a/src/test/java/org/jabref/logic/net/URLDownloadTest.java +++ b/src/test/java/org/jabref/logic/net/URLDownloadTest.java @@ -7,6 +7,8 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Path; +import org.jabref.logic.importer.FetcherClientException; +import org.jabref.logic.importer.FetcherServerException; import org.jabref.support.DisabledOnCIServer; import kong.unirest.UnirestException; @@ -19,6 +21,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; public class URLDownloadTest { + private static final Logger LOGGER = LoggerFactory.getLogger(URLDownloadTest.class); @Test @@ -120,4 +123,20 @@ public void connectTimeoutIsNeverNull() throws MalformedURLException { urlDownload.setConnectTimeout(null); assertNotNull(urlDownload.getConnectTimeout(), "no null value can be set"); } + + @Test + public void test503ErrorThrowsNestedIOExceptionWithFetcherServerException() throws Exception { + URLDownload urlDownload = new URLDownload(new URL("http://httpstat.us/503")); + + Exception exception = assertThrows(IOException.class, () -> urlDownload.asString()); + assertTrue(exception.getCause() instanceof FetcherServerException); + } + + @Test + public void test429ErrorThrowsNestedIOExceptionWithFetcherServerException() throws Exception { + URLDownload urlDownload = new URLDownload(new URL("http://httpstat.us/429")); + + Exception exception = assertThrows(IOException.class, () -> urlDownload.asString()); + assertTrue(exception.getCause() instanceof FetcherClientException); + } } From a02f5d4eb2f45729ebeb1e5dfb69514dfb47a2d9 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Thu, 14 Jul 2022 22:12:47 +0200 Subject: [PATCH 11/27] rename test --- .../org/jabref/logic/importer/fetcher/DoiFetcherTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/jabref/logic/importer/fetcher/DoiFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/DoiFetcherTest.java index 43cee6714f5..134cdbc52d8 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/DoiFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/DoiFetcherTest.java @@ -103,12 +103,12 @@ public void testPerformSearchInvalidDOI() { } @Test - public void testPerformSearchInvalidDOIClientErrorMessage1() { + public void testPerformSearchInvalidDOIClientResultsinFetcherClientException() { assertThrows(FetcherClientException.class, () -> fetcher.performSearchById("10.1002/9781118257517F")); } @Test - public void testPerformSearchInvalidDOIClientErrorMessage2() { + public void testPerformSearchInvalidDOIClientResultsinFetcherClientException2() { assertThrows(FetcherClientException.class, () -> fetcher.performSearchById("10.1002/9781517F")); } From 5dfdc8e6af50c15408e2227c4a0f98f00b42be8d Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Thu, 14 Jul 2022 23:04:24 +0200 Subject: [PATCH 12/27] refactor impor format reader and clipboard manager move to import handler --- .../java/org/jabref/gui/ClipBoardManager.java | 91 +------------------ .../java/org/jabref/gui/DefaultInjector.java | 6 +- .../java/org/jabref/gui/EntryTypeView.java | 4 +- .../org/jabref/gui/EntryTypeViewModel.java | 10 +- src/main/java/org/jabref/gui/LibraryTab.java | 6 +- .../BibtexExtractorViewModel.java | 7 +- .../bibtexextractor/ExtractBibtexDialog.java | 4 +- .../gui/externalfiles/ImportHandler.java | 87 +++++++++++++++++- .../UnlinkedFilesDialogView.java | 4 +- .../UnlinkedFilesDialogViewModel.java | 7 +- .../IdentifierEditorViewModel.java | 18 +++- .../importer/GenerateEntryFromIdAction.java | 2 +- .../gui/importer/ImportEntriesViewModel.java | 4 +- .../org/jabref/gui/maintable/MainTable.java | 24 ++++- .../gui/mergeentries/FetchAndMergeEntry.java | 3 - .../logic/importer/IdParserFetcher.java | 2 + 16 files changed, 168 insertions(+), 111 deletions(-) diff --git a/src/main/java/org/jabref/gui/ClipBoardManager.java b/src/main/java/org/jabref/gui/ClipBoardManager.java index 290cb774c72..ac8e8042e9d 100644 --- a/src/main/java/org/jabref/gui/ClipBoardManager.java +++ b/src/main/java/org/jabref/gui/ClipBoardManager.java @@ -5,12 +5,8 @@ import java.awt.datatransfer.StringSelection; import java.awt.datatransfer.Transferable; import java.awt.datatransfer.UnsupportedFlavorException; -import java.io.ByteArrayInputStream; import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.Collections; import java.util.List; -import java.util.Optional; import javafx.application.Platform; import javafx.scene.control.TextInputControl; @@ -22,19 +18,8 @@ import org.jabref.architecture.AllowedToUseAwt; import org.jabref.logic.bibtex.BibEntryWriter; import org.jabref.logic.bibtex.FieldWriter; -import org.jabref.logic.importer.FetcherException; -import org.jabref.logic.importer.ImportException; -import org.jabref.logic.importer.ImportFormatReader; -import org.jabref.logic.importer.ImportFormatReader.UnknownFormatImport; -import org.jabref.logic.importer.ParseException; -import org.jabref.logic.importer.fetcher.ArXiv; -import org.jabref.logic.importer.fetcher.DoiFetcher; -import org.jabref.logic.importer.fileformat.BibtexParser; import org.jabref.model.database.BibDatabaseMode; import org.jabref.model.entry.BibEntry; -import org.jabref.model.entry.identifier.ArXivIdentifier; -import org.jabref.model.entry.identifier.DOI; -import org.jabref.model.util.OptionalUtil; import org.jabref.preferences.PreferencesService; import org.slf4j.Logger; @@ -49,18 +34,17 @@ public class ClipBoardManager { private static Clipboard clipboard; private static java.awt.datatransfer.Clipboard primary; - private static ImportFormatReader importFormatReader; + private final PreferencesService preferencesService; + public ClipBoardManager(PreferencesService preferencesService) { - this(Clipboard.getSystemClipboard(), Toolkit.getDefaultToolkit().getSystemSelection(), Globals.IMPORT_FORMAT_READER, preferencesService); + this(Clipboard.getSystemClipboard(), Toolkit.getDefaultToolkit().getSystemSelection(), preferencesService); } - public ClipBoardManager(Clipboard clipboard, java.awt.datatransfer.Clipboard primary, ImportFormatReader importFormatReader, PreferencesService preferencesService) { + public ClipBoardManager(Clipboard clipboard, java.awt.datatransfer.Clipboard primary, PreferencesService preferencesService) { ClipBoardManager.clipboard = clipboard; ClipBoardManager.primary = primary; - ClipBoardManager.importFormatReader = importFormatReader; - this.preferencesService = preferencesService; } @@ -167,71 +151,4 @@ public void setContent(List entries) throws IOException { clipboard.setContent(content); setPrimaryClipboardContent(content); } - - public List extractData() { - Object entries = clipboard.getContent(DragAndDropDataFormats.ENTRIES); - - if (entries == null) { - return handleStringData(clipboard.getString()); - } - return handleBibTeXData((String) entries); - } - - private List handleBibTeXData(String entries) { - BibtexParser parser = new BibtexParser(preferencesService.getImportFormatPreferences(), Globals.getFileUpdateMonitor()); - try { - return parser.parseEntries(new ByteArrayInputStream(entries.getBytes(StandardCharsets.UTF_8))); - } catch (ParseException ex) { - LOGGER.error("Could not paste", ex); - return Collections.emptyList(); - } - } - - private List handleStringData(String data) { - if ((data == null) || data.isEmpty()) { - return Collections.emptyList(); - } - - Optional doi = DOI.parse(data); - if (doi.isPresent()) { - return fetchByDOI(doi.get()); - } - Optional arXiv = ArXivIdentifier.parse(data); - if (arXiv.isPresent()) { - return fetchByArXiv(arXiv.get()); - } - - return tryImportFormats(data); - } - - private List tryImportFormats(String data) { - try { - UnknownFormatImport unknownFormatImport = importFormatReader.importUnknownFormat(data); - return unknownFormatImport.parserResult.getDatabase().getEntries(); - } catch (ImportException ignored) { - return Collections.emptyList(); - } - } - - private List fetchByDOI(DOI doi) { - LOGGER.info("Found DOI in clipboard"); - try { - Optional entry = new DoiFetcher(preferencesService.getImportFormatPreferences()).performSearchById(doi.getDOI()); - return OptionalUtil.toList(entry); - } catch (FetcherException ex) { - LOGGER.error("Error while fetching", ex); - return Collections.emptyList(); - } - } - - private List fetchByArXiv(ArXivIdentifier arXivIdentifier) { - LOGGER.info("Found arxiv identifier in clipboard"); - try { - Optional entry = new ArXiv(preferencesService.getImportFormatPreferences()).performSearchById(arXivIdentifier.getNormalizedWithoutVersion()); - return OptionalUtil.toList(entry); - } catch (FetcherException ex) { - LOGGER.error("Error while fetching", ex); - return Collections.emptyList(); - } - } } diff --git a/src/main/java/org/jabref/gui/DefaultInjector.java b/src/main/java/org/jabref/gui/DefaultInjector.java index d198dbe1136..c25162edfab 100644 --- a/src/main/java/org/jabref/gui/DefaultInjector.java +++ b/src/main/java/org/jabref/gui/DefaultInjector.java @@ -7,6 +7,7 @@ import org.jabref.gui.keyboard.KeyBindingRepository; import org.jabref.gui.theme.ThemeManager; import org.jabref.gui.util.TaskExecutor; +import org.jabref.logic.importer.ImportFormatReader; import org.jabref.logic.journals.JournalAbbreviationRepository; import org.jabref.logic.protectedterms.ProtectedTermsLoader; import org.jabref.model.entry.BibEntryTypesManager; @@ -52,7 +53,10 @@ private static Object createDependency(Class clazz) { return Globals.undoManager; } else if (clazz == BibEntryTypesManager.class) { return Globals.entryTypesManager; - } else { + } else if (clazz == ImportFormatReader.class) { + return Globals.IMPORT_FORMAT_READER; + } + else { try { return clazz.newInstance(); } catch (InstantiationException | IllegalAccessException ex) { diff --git a/src/main/java/org/jabref/gui/EntryTypeView.java b/src/main/java/org/jabref/gui/EntryTypeView.java index 10a95f3a5d0..d7c6d9933d5 100644 --- a/src/main/java/org/jabref/gui/EntryTypeView.java +++ b/src/main/java/org/jabref/gui/EntryTypeView.java @@ -24,6 +24,7 @@ import org.jabref.gui.util.IconValidationDecorator; import org.jabref.gui.util.ViewModelListCellFactory; import org.jabref.logic.importer.IdBasedFetcher; +import org.jabref.logic.importer.ImportFormatReader; import org.jabref.logic.importer.WebFetcher; import org.jabref.logic.l10n.Localization; import org.jabref.model.database.BibDatabaseMode; @@ -47,6 +48,7 @@ public class EntryTypeView extends BaseDialog { @Inject StateManager stateManager; + @Inject ImportFormatReader importFormatReader; @FXML private ButtonType generateButton; @FXML private TextField idTextField; @@ -118,7 +120,7 @@ private void addEntriesToPane(FlowPane pane, Collection @FXML public void initialize() { visualizer.setDecoration(new IconValidationDecorator()); - viewModel = new EntryTypeViewModel(preferencesService, libraryTab, dialogService, stateManager); + viewModel = new EntryTypeViewModel(preferencesService, libraryTab, dialogService, stateManager, importFormatReader); idBasedFetchers.itemsProperty().bind(viewModel.fetcherItemsProperty()); idTextField.textProperty().bindBidirectional(viewModel.idTextProperty()); diff --git a/src/main/java/org/jabref/gui/EntryTypeViewModel.java b/src/main/java/org/jabref/gui/EntryTypeViewModel.java index 16782b19c00..b887d0b28bb 100644 --- a/src/main/java/org/jabref/gui/EntryTypeViewModel.java +++ b/src/main/java/org/jabref/gui/EntryTypeViewModel.java @@ -19,6 +19,7 @@ import org.jabref.gui.importer.NewEntryAction; import org.jabref.logic.importer.FetcherException; import org.jabref.logic.importer.IdBasedFetcher; +import org.jabref.logic.importer.ImportFormatReader; import org.jabref.logic.importer.WebFetchers; import org.jabref.logic.importer.fetcher.DoiFetcher; import org.jabref.logic.l10n.Localization; @@ -50,15 +51,19 @@ public class EntryTypeViewModel { private final DialogService dialogService; private final Validator idFieldValidator; private final StateManager stateManager; + private final ImportFormatReader importFormatReader; public EntryTypeViewModel(PreferencesService preferences, LibraryTab libraryTab, DialogService dialogService, - StateManager stateManager) { + StateManager stateManager, + ImportFormatReader importFormatReader) { this.libraryTab = libraryTab; this.preferencesService = preferences; this.dialogService = dialogService; this.stateManager = stateManager; + this.importFormatReader = importFormatReader; + fetchers.addAll(WebFetchers.getIdBasedFetchers( preferences.getImportFormatPreferences(), preferences.getImporterPreferences())); @@ -164,7 +169,8 @@ public void runFetcherWorker() { Globals.getFileUpdateMonitor(), libraryTab.getUndoManager(), stateManager, - dialogService); + dialogService, + importFormatReader); handler.importEntryWithDuplicateCheck(libraryTab.getBibDatabaseContext(), entry); searchSuccesfulProperty.set(true); diff --git a/src/main/java/org/jabref/gui/LibraryTab.java b/src/main/java/org/jabref/gui/LibraryTab.java index 31e64458016..974e50b371f 100644 --- a/src/main/java/org/jabref/gui/LibraryTab.java +++ b/src/main/java/org/jabref/gui/LibraryTab.java @@ -480,7 +480,9 @@ private void createMainTable() { dialogService, stateManager, externalFileTypes, - Globals.getKeyPrefs()); + Globals.getKeyPrefs(), + Globals.getClipboardManager(), + Globals.IMPORT_FORMAT_READER); // Add the listener that binds selection to state manager (TODO: should be replaced by proper JavaFX binding as soon as table is implemented in JavaFX) mainTable.addSelectionListener(listEvent -> stateManager.setSelectedEntries(mainTable.getSelectedEntries())); @@ -929,7 +931,7 @@ public void notify(Node graphic, String text, List actions, Duration dur this.setText(text); this.getActions().setAll(actions); this.show(); - if (duration != null && !duration.equals(Duration.ZERO)) { + if ((duration != null) && !duration.equals(Duration.ZERO)) { PauseTransition delay = new PauseTransition(duration); delay.setOnFinished(e -> this.hide()); delay.play(); diff --git a/src/main/java/org/jabref/gui/bibtexextractor/BibtexExtractorViewModel.java b/src/main/java/org/jabref/gui/bibtexextractor/BibtexExtractorViewModel.java index 3472e69d466..8224873ad70 100644 --- a/src/main/java/org/jabref/gui/bibtexextractor/BibtexExtractorViewModel.java +++ b/src/main/java/org/jabref/gui/bibtexextractor/BibtexExtractorViewModel.java @@ -17,6 +17,7 @@ import org.jabref.gui.util.BackgroundTask; import org.jabref.gui.util.TaskExecutor; import org.jabref.logic.importer.FetcherException; +import org.jabref.logic.importer.ImportFormatReader; import org.jabref.logic.importer.fetcher.GrobidCitationFetcher; import org.jabref.logic.l10n.Localization; import org.jabref.model.database.BibDatabaseContext; @@ -43,7 +44,8 @@ public BibtexExtractorViewModel(BibDatabaseContext bibdatabaseContext, FileUpdateMonitor fileUpdateMonitor, TaskExecutor taskExecutor, UndoManager undoManager, - StateManager stateManager) { + StateManager stateManager, + ImportFormatReader importFormatReader) { this.dialogService = dialogService; this.preferencesService = preferencesService; @@ -55,7 +57,8 @@ public BibtexExtractorViewModel(BibDatabaseContext bibdatabaseContext, fileUpdateMonitor, undoManager, stateManager, - dialogService); + dialogService, + importFormatReader); } public StringProperty inputTextProperty() { diff --git a/src/main/java/org/jabref/gui/bibtexextractor/ExtractBibtexDialog.java b/src/main/java/org/jabref/gui/bibtexextractor/ExtractBibtexDialog.java index 04affccbf1a..3a5d0ec7a3f 100644 --- a/src/main/java/org/jabref/gui/bibtexextractor/ExtractBibtexDialog.java +++ b/src/main/java/org/jabref/gui/bibtexextractor/ExtractBibtexDialog.java @@ -13,6 +13,7 @@ import org.jabref.gui.StateManager; import org.jabref.gui.util.BaseDialog; import org.jabref.gui.util.TaskExecutor; +import org.jabref.logic.importer.ImportFormatReader; import org.jabref.logic.l10n.Localization; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.util.FileUpdateMonitor; @@ -35,6 +36,7 @@ public class ExtractBibtexDialog extends BaseDialog { @Inject private TaskExecutor taskExecutor; @Inject private UndoManager undoManager; @Inject private PreferencesService preferencesService; + @Inject private ImportFormatReader importFormatReader; public ExtractBibtexDialog() { ViewLoader.view(this) @@ -53,7 +55,7 @@ public ExtractBibtexDialog() { @FXML private void initialize() { BibDatabaseContext database = stateManager.getActiveDatabase().orElseThrow(() -> new NullPointerException("Database null")); - this.viewModel = new BibtexExtractorViewModel(database, dialogService, preferencesService, fileUpdateMonitor, taskExecutor, undoManager, stateManager); + this.viewModel = new BibtexExtractorViewModel(database, dialogService, preferencesService, fileUpdateMonitor, taskExecutor, undoManager, stateManager, importFormatReader); input.textProperty().bindBidirectional(viewModel.inputTextProperty()); } } diff --git a/src/main/java/org/jabref/gui/externalfiles/ImportHandler.java b/src/main/java/org/jabref/gui/externalfiles/ImportHandler.java index 7de10cf7b35..16a2460129e 100644 --- a/src/main/java/org/jabref/gui/externalfiles/ImportHandler.java +++ b/src/main/java/org/jabref/gui/externalfiles/ImportHandler.java @@ -1,6 +1,8 @@ package org.jabref.gui.externalfiles; +import java.io.ByteArrayInputStream; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.nio.file.Path; import java.util.ArrayList; import java.util.Collection; @@ -22,7 +24,15 @@ import org.jabref.logic.citationkeypattern.CitationKeyGenerator; import org.jabref.logic.database.DuplicateCheck; import org.jabref.logic.externalfiles.ExternalFilesContentImporter; +import org.jabref.logic.importer.FetcherException; import org.jabref.logic.importer.ImportCleanup; +import org.jabref.logic.importer.ImportException; +import org.jabref.logic.importer.ImportFormatReader; +import org.jabref.logic.importer.ParseException; +import org.jabref.logic.importer.ImportFormatReader.UnknownFormatImport; +import org.jabref.logic.importer.fetcher.ArXiv; +import org.jabref.logic.importer.fetcher.DoiFetcher; +import org.jabref.logic.importer.fileformat.BibtexParser; import org.jabref.logic.l10n.Localization; import org.jabref.logic.util.UpdateField; import org.jabref.logic.util.io.FileUtil; @@ -30,9 +40,12 @@ import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.StandardField; +import org.jabref.model.entry.identifier.ArXivIdentifier; +import org.jabref.model.entry.identifier.DOI; import org.jabref.model.groups.GroupEntryChanger; import org.jabref.model.groups.GroupTreeNode; import org.jabref.model.util.FileUpdateMonitor; +import org.jabref.model.util.OptionalUtil; import org.jabref.preferences.PreferencesService; import org.slf4j.Logger; @@ -49,6 +62,7 @@ public class ImportHandler { private final UndoManager undoManager; private final StateManager stateManager; private final DialogService dialogService; + private final ImportFormatReader importFormatReader; public ImportHandler(BibDatabaseContext database, ExternalFileTypes externalFileTypes, @@ -56,13 +70,15 @@ public ImportHandler(BibDatabaseContext database, FileUpdateMonitor fileupdateMonitor, UndoManager undoManager, StateManager stateManager, - DialogService dialogService) { + DialogService dialogService, + ImportFormatReader importFormatReader) { this.bibDatabaseContext = database; this.preferencesService = preferencesService; this.fileUpdateMonitor = fileupdateMonitor; this.stateManager = stateManager; this.dialogService = dialogService; + this.importFormatReader = importFormatReader; this.linker = new ExternalFilesEntryLinker(externalFileTypes, preferencesService.getFilePreferences(), database); this.contentImporter = new ExternalFilesContentImporter( @@ -245,4 +261,73 @@ private void generateKeys(List entries) { keyGenerator.generateAndSetKey(entry); } } + + public List extractData(String data) { + /* Object entries = clipboard.getContent(DragAndDropDataFormats.ENTRIES); + + if (entries == null) { + return handleStringData(clipboard.getString()); + } + return handleBibTeXData((String) entries); + */ + return null; + } + + private List handleBibTeXData(String entries) { + BibtexParser parser = new BibtexParser(preferencesService.getImportFormatPreferences(), Globals.getFileUpdateMonitor()); + try { + return parser.parseEntries(new ByteArrayInputStream(entries.getBytes(StandardCharsets.UTF_8))); + } catch (ParseException ex) { + LOGGER.error("Could not paste", ex); + return Collections.emptyList(); + } + } + + private List handleStringData(String data) { + if ((data == null) || data.isEmpty()) { + return Collections.emptyList(); + } + + Optional doi = DOI.parse(data); + if (doi.isPresent()) { + return fetchByDOI(doi.get()); + } + Optional arXiv = ArXivIdentifier.parse(data); + if (arXiv.isPresent()) { + return fetchByArXiv(arXiv.get()); + } + + return tryImportFormats(data); + } + + private List tryImportFormats(String data) { + try { + UnknownFormatImport unknownFormatImport = importFormatReader.importUnknownFormat(data); + return unknownFormatImport.parserResult.getDatabase().getEntries(); + } catch (ImportException ignored) { + return Collections.emptyList(); + } + } + + private List fetchByDOI(DOI doi) { + LOGGER.info("Found DOI in clipboard"); + try { + Optional entry = new DoiFetcher(preferencesService.getImportFormatPreferences()).performSearchById(doi.getDOI()); + return OptionalUtil.toList(entry); + } catch (FetcherException ex) { + LOGGER.error("Error while fetching", ex); + return Collections.emptyList(); + } + } + + private List fetchByArXiv(ArXivIdentifier arXivIdentifier) { + LOGGER.info("Found arxiv identifier in clipboard"); + try { + Optional entry = new ArXiv(preferencesService.getImportFormatPreferences()).performSearchById(arXivIdentifier.getNormalizedWithoutVersion()); + return OptionalUtil.toList(entry); + } catch (FetcherException ex) { + LOGGER.error("Error while fetching", ex); + return Collections.emptyList(); + } + } } diff --git a/src/main/java/org/jabref/gui/externalfiles/UnlinkedFilesDialogView.java b/src/main/java/org/jabref/gui/externalfiles/UnlinkedFilesDialogView.java index 2d1af899d12..0805c8a1f22 100644 --- a/src/main/java/org/jabref/gui/externalfiles/UnlinkedFilesDialogView.java +++ b/src/main/java/org/jabref/gui/externalfiles/UnlinkedFilesDialogView.java @@ -42,6 +42,7 @@ import org.jabref.gui.util.ValueTableCellFactory; import org.jabref.gui.util.ViewModelListCellFactory; import org.jabref.gui.util.ViewModelTreeCellFactory; +import org.jabref.logic.importer.ImportFormatReader; import org.jabref.logic.l10n.Localization; import org.jabref.model.util.FileUpdateMonitor; import org.jabref.preferences.PreferencesService; @@ -81,6 +82,7 @@ public class UnlinkedFilesDialogView extends BaseDialog { @Inject private TaskExecutor taskExecutor; @Inject private FileUpdateMonitor fileUpdateMonitor; @Inject private ThemeManager themeManager; + @Inject private ImportFormatReader importFormatReader; private final ControlsFxVisualizer validationVisualizer; private UnlinkedFilesDialogViewModel viewModel; @@ -106,7 +108,7 @@ public UnlinkedFilesDialogView() { @FXML private void initialize() { - viewModel = new UnlinkedFilesDialogViewModel(dialogService, ExternalFileTypes.getInstance(), undoManager, fileUpdateMonitor, preferencesService, stateManager, taskExecutor); + viewModel = new UnlinkedFilesDialogViewModel(dialogService, ExternalFileTypes.getInstance(), undoManager, fileUpdateMonitor, preferencesService, stateManager, taskExecutor, importFormatReader); progressDisplay.progressProperty().bind(viewModel.progressValueProperty()); progressText.textProperty().bind(viewModel.progressTextProperty()); diff --git a/src/main/java/org/jabref/gui/externalfiles/UnlinkedFilesDialogViewModel.java b/src/main/java/org/jabref/gui/externalfiles/UnlinkedFilesDialogViewModel.java index 7d19b2bdc98..fd942a61508 100644 --- a/src/main/java/org/jabref/gui/externalfiles/UnlinkedFilesDialogViewModel.java +++ b/src/main/java/org/jabref/gui/externalfiles/UnlinkedFilesDialogViewModel.java @@ -36,6 +36,7 @@ import org.jabref.gui.util.FileDialogConfiguration; import org.jabref.gui.util.FileNodeViewModel; import org.jabref.gui.util.TaskExecutor; +import org.jabref.logic.importer.ImportFormatReader; import org.jabref.logic.l10n.Localization; import org.jabref.logic.util.StandardFileType; import org.jabref.model.database.BibDatabaseContext; @@ -86,7 +87,8 @@ public UnlinkedFilesDialogViewModel(DialogService dialogService, FileUpdateMonitor fileUpdateMonitor, PreferencesService preferences, StateManager stateManager, - TaskExecutor taskExecutor) { + TaskExecutor taskExecutor, + ImportFormatReader importFormatReader) { this.preferences = preferences; this.dialogService = dialogService; this.taskExecutor = taskExecutor; @@ -98,7 +100,8 @@ public UnlinkedFilesDialogViewModel(DialogService dialogService, fileUpdateMonitor, undoManager, stateManager, - dialogService); + dialogService, + importFormatReader); this.fileFilterList = FXCollections.observableArrayList( new FileExtensionViewModel(StandardFileType.ANY_FILE, externalFileTypes), diff --git a/src/main/java/org/jabref/gui/fieldeditors/IdentifierEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/IdentifierEditorViewModel.java index 04025e60be7..84dbf1e9cc2 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/IdentifierEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/IdentifierEditorViewModel.java @@ -15,6 +15,8 @@ import org.jabref.gui.mergeentries.FetchAndMergeEntry; import org.jabref.gui.util.BackgroundTask; import org.jabref.gui.util.TaskExecutor; +import org.jabref.logic.importer.FetcherClientException; +import org.jabref.logic.importer.FetcherServerException; import org.jabref.logic.importer.WebFetchers; import org.jabref.logic.importer.util.IdentifierParser; import org.jabref.logic.integrity.FieldCheckers; @@ -27,8 +29,13 @@ import org.jabref.preferences.PreferencesService; import com.tobiasdiez.easybind.EasyBind; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class IdentifierEditorViewModel extends AbstractEditorViewModel { + + private static final Logger LOGGER = LoggerFactory.getLogger(IdentifierEditorViewModel.class); + private final BooleanProperty validIdentifierIsNotPresent = new SimpleBooleanProperty(true); private final BooleanProperty identifierLookupInProgress = new SimpleBooleanProperty(false); private final BooleanProperty idFetcherAvailable = new SimpleBooleanProperty(true); @@ -119,7 +126,16 @@ public void lookupIdentifier(BibEntry entry) { dialogService.notify(Localization.lang("No %0 found", field.getDisplayName())); } }) - .onFailure(dialogService::showErrorDialogAndWait) + .onFailure(exception -> { + LOGGER.error("Error while fetching bibliographic information", exception); + if (exception instanceof FetcherClientException) { + dialogService.showInformationDialogAndWait(Localization.lang("Lookup {0}", idFetcher.getName()), Localization.lang("No data was found for the identifier")); + } else if (exception instanceof FetcherServerException) { + dialogService.showInformationDialogAndWait(Localization.lang("Lookup {0}", idFetcher.getName()), Localization.lang("Server not available")); + } else { + dialogService.showErrorDialogAndWait(exception); + } + }) .executeWith(taskExecutor); }); } diff --git a/src/main/java/org/jabref/gui/importer/GenerateEntryFromIdAction.java b/src/main/java/org/jabref/gui/importer/GenerateEntryFromIdAction.java index 4c5c8a5747f..0e4012fe854 100644 --- a/src/main/java/org/jabref/gui/importer/GenerateEntryFromIdAction.java +++ b/src/main/java/org/jabref/gui/importer/GenerateEntryFromIdAction.java @@ -62,7 +62,7 @@ public void execute() { Optional result = bibEntry; if (result.isPresent()) { final BibEntry entry = result.get(); - ImportHandler handler = new ImportHandler(libraryTab.getBibDatabaseContext(), ExternalFileTypes.getInstance(), preferencesService, Globals.getFileUpdateMonitor(), libraryTab.getUndoManager(), stateManager, dialogService); + ImportHandler handler = new ImportHandler(libraryTab.getBibDatabaseContext(), ExternalFileTypes.getInstance(), preferencesService, Globals.getFileUpdateMonitor(), libraryTab.getUndoManager(), stateManager, dialogService, null); handler.importEntryWithDuplicateCheck(libraryTab.getBibDatabaseContext(), entry); } else { dialogService.notify("No entry found or import canceled"); diff --git a/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java b/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java index b139a4573c4..877a677234c 100644 --- a/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java +++ b/src/main/java/org/jabref/gui/importer/ImportEntriesViewModel.java @@ -12,6 +12,7 @@ import org.jabref.gui.AbstractViewModel; import org.jabref.gui.DialogService; +import org.jabref.gui.Globals; import org.jabref.gui.JabRefGUI; import org.jabref.gui.StateManager; import org.jabref.gui.duplicationFinder.DuplicateResolverDialog; @@ -170,7 +171,8 @@ private void buildImportHandlerThenImportEntries(List entriesToImport) fileUpdateMonitor, undoManager, stateManager, - dialogService); + dialogService, + Globals.IMPORT_FORMAT_READER); importHandler.importEntries(entriesToImport); dialogService.notify(Localization.lang("Number of entries successfully imported") + ": " + entriesToImport.size()); } diff --git a/src/main/java/org/jabref/gui/maintable/MainTable.java b/src/main/java/org/jabref/gui/maintable/MainTable.java index 91720b42823..4a297b708bb 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTable.java +++ b/src/main/java/org/jabref/gui/maintable/MainTable.java @@ -24,6 +24,7 @@ import javafx.scene.input.MouseEvent; import javafx.scene.input.TransferMode; +import org.jabref.gui.ClipBoardManager; import org.jabref.gui.DialogService; import org.jabref.gui.DragAndDropDataFormats; import org.jabref.gui.Globals; @@ -41,6 +42,7 @@ import org.jabref.gui.util.CustomLocalDragboard; import org.jabref.gui.util.DefaultTaskExecutor; import org.jabref.gui.util.ViewModelTableRowFactory; +import org.jabref.logic.importer.ImportFormatReader; import org.jabref.logic.l10n.Localization; import org.jabref.model.database.BibDatabaseContext; import org.jabref.model.database.event.EntriesAddedEvent; @@ -60,6 +62,8 @@ public class MainTable extends TableView { private final StateManager stateManager; private final BibDatabaseContext database; private final MainTableDataModel model; + private final ClipBoardManager clipBoardManager; + private final ImportFormatReader importFormatReader; private final ImportHandler importHandler; private final CustomLocalDragboard localDragboard; @@ -74,7 +78,9 @@ public MainTable(MainTableDataModel model, DialogService dialogService, StateManager stateManager, ExternalFileTypes externalFileTypes, - KeyBindingRepository keyBindingRepository) { + KeyBindingRepository keyBindingRepository, + ClipBoardManager clipBoardManager, + ImportFormatReader importFormatReader) { super(); this.libraryTab = libraryTab; @@ -82,6 +88,8 @@ public MainTable(MainTableDataModel model, this.stateManager = stateManager; this.database = Objects.requireNonNull(database); this.model = model; + this.clipBoardManager = clipBoardManager; + this.importFormatReader = importFormatReader; UndoManager undoManager = libraryTab.getUndoManager(); MainTablePreferences mainTablePreferences = preferencesService.getMainTablePreferences(); @@ -91,7 +99,8 @@ public MainTable(MainTableDataModel model, Globals.getFileUpdateMonitor(), undoManager, stateManager, - dialogService); + dialogService, + importFormatReader); localDragboard = stateManager.getLocalDragboard(); @@ -304,17 +313,20 @@ private void clearAndSelectLast() { } public void paste() { - // Find entries in clipboard - List entriesToAdd = Globals.getClipboardManager().extractData(); + + String data = this.clipBoardManager.getContents(); + //TODO call import handler + /*// Find entries in clipboard for (BibEntry entry : entriesToAdd) { importHandler.importEntryWithDuplicateCheck(database, entry); } if (!entriesToAdd.isEmpty()) { this.requestFocus(); - } + }*/ } + private void handleOnDragOver(TableRow row, BibEntryTableViewModel item, DragEvent event) { if (event.getDragboard().hasFiles()) { event.acceptTransferModes(TransferMode.ANY); @@ -441,4 +453,6 @@ private Optional findEntry(BibEntry entry) { .filter(viewModel -> viewModel.getEntry().equals(entry)) .findFirst(); } + + } diff --git a/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java b/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java index 58514e4fb61..3a86375aea3 100644 --- a/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java +++ b/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java @@ -78,13 +78,10 @@ public void fetchAndMerge(BibEntry entry, List fields) { }) .onFailure(exception -> { LOGGER.error("Error while fetching bibliographic information", exception); - // client error if (exception instanceof FetcherClientException) { dialogService.showInformationDialogAndWait(Localization.lang("Lookup {0}", fetcher.get().getName()), Localization.lang("No data was found for the identifier")); - // server error } else if (exception instanceof FetcherServerException) { dialogService.showInformationDialogAndWait(Localization.lang("Lookup {0}", fetcher.get().getName()), Localization.lang("Server not available")); - // default error } else { dialogService.showErrorDialogAndWait(exception); } diff --git a/src/main/java/org/jabref/logic/importer/IdParserFetcher.java b/src/main/java/org/jabref/logic/importer/IdParserFetcher.java index bf4b2bb32b9..f194f815ed8 100644 --- a/src/main/java/org/jabref/logic/importer/IdParserFetcher.java +++ b/src/main/java/org/jabref/logic/importer/IdParserFetcher.java @@ -88,6 +88,8 @@ default Optional findIdentifier(BibEntry entry) throws FetcherException { LOGGER.debug("Id not found"); return Optional.empty(); } catch (IOException e) { + + // TODO: Catch HTTP Response 401 errors and report that user has no rights to access resource // TODO catch 503 service unavailable and alert user throw new FetcherException("An I/O exception occurred", e); From 9ed8131ac5fee846800e244ddb354eebee5a5e1e Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Fri, 15 Jul 2022 19:47:52 +0200 Subject: [PATCH 13/27] Refactor clipboard manager Pass importFormatReader --- .../java/org/jabref/gui/ClipBoardManager.java | 5 +++ .../java/org/jabref/gui/DefaultInjector.java | 3 +- src/main/java/org/jabref/gui/JabRefFrame.java | 5 ++- src/main/java/org/jabref/gui/LibraryTab.java | 10 +++-- .../gui/externalfiles/ImportHandler.java | 38 +++++++------------ .../importer/actions/OpenDatabaseAction.java | 2 +- .../org/jabref/gui/maintable/MainTable.java | 13 ++++--- .../importer/FetcherClientException.java | 1 - .../importer/FetcherServerException.java | 1 - .../org/jabref/logic/net/URLDownload.java | 4 -- 10 files changed, 40 insertions(+), 42 deletions(-) diff --git a/src/main/java/org/jabref/gui/ClipBoardManager.java b/src/main/java/org/jabref/gui/ClipBoardManager.java index ac8e8042e9d..174072065c2 100644 --- a/src/main/java/org/jabref/gui/ClipBoardManager.java +++ b/src/main/java/org/jabref/gui/ClipBoardManager.java @@ -7,6 +7,7 @@ import java.awt.datatransfer.UnsupportedFlavorException; import java.io.IOException; import java.util.List; +import java.util.Optional; import javafx.application.Platform; import javafx.scene.control.TextInputControl; @@ -87,6 +88,10 @@ public static String getContents() { return result; } + public Optional getBibTeXEntriesFromClipbaord(){ + return Optional.ofNullable(clipboard.getContent(DragAndDropDataFormats.ENTRIES)).map(String.class::cast); + } + /** * Get the String residing on the primary clipboard (if it exists). * diff --git a/src/main/java/org/jabref/gui/DefaultInjector.java b/src/main/java/org/jabref/gui/DefaultInjector.java index c25162edfab..5318c3b95dc 100644 --- a/src/main/java/org/jabref/gui/DefaultInjector.java +++ b/src/main/java/org/jabref/gui/DefaultInjector.java @@ -55,8 +55,7 @@ private static Object createDependency(Class clazz) { return Globals.entryTypesManager; } else if (clazz == ImportFormatReader.class) { return Globals.IMPORT_FORMAT_READER; - } - else { + } else { try { return clazz.newInstance(); } catch (InstantiationException | IllegalAccessException ex) { diff --git a/src/main/java/org/jabref/gui/JabRefFrame.java b/src/main/java/org/jabref/gui/JabRefFrame.java index 91d074e7e7c..7c39965740c 100644 --- a/src/main/java/org/jabref/gui/JabRefFrame.java +++ b/src/main/java/org/jabref/gui/JabRefFrame.java @@ -127,6 +127,7 @@ import org.jabref.logic.help.HelpFile; import org.jabref.logic.importer.IdFetcher; import org.jabref.logic.importer.ImportCleanup; +import org.jabref.logic.importer.ImportFormatReader; import org.jabref.logic.importer.ParserResult; import org.jabref.logic.importer.WebFetchers; import org.jabref.logic.l10n.Localization; @@ -183,6 +184,7 @@ public class JabRefFrame extends BorderPane { private Subscription dividerSubscription; private final TaskExecutor taskExecutor; + private final ImportFormatReader importFormatReader; public JabRefFrame(Stage mainStage) { this.mainStage = mainStage; @@ -194,6 +196,7 @@ public JabRefFrame(Stage mainStage) { this.globalSearchBar = new GlobalSearchBar(this, stateManager, prefs, undoManager); this.fileHistory = new FileHistoryMenu(prefs, dialogService, getOpenDatabaseAction()); this.taskExecutor = Globals.TASK_EXECUTOR; + this.importFormatReader = Globals.IMPORT_FORMAT_READER; this.setOnKeyTyped(key -> { if (this.fileHistory.isShowing()) { if (this.fileHistory.openFileByKey(key)) { @@ -1092,7 +1095,7 @@ private void trackOpenNewDatabase(LibraryTab libraryTab) { public LibraryTab addTab(BibDatabaseContext databaseContext, boolean raisePanel) { Objects.requireNonNull(databaseContext); - LibraryTab libraryTab = new LibraryTab(this, prefs, stateManager, themeManager, databaseContext, ExternalFileTypes.getInstance()); + LibraryTab libraryTab = new LibraryTab(this, prefs, stateManager, themeManager, databaseContext, ExternalFileTypes.getInstance(), importFormatReader); addTab(libraryTab, raisePanel); return libraryTab; } diff --git a/src/main/java/org/jabref/gui/LibraryTab.java b/src/main/java/org/jabref/gui/LibraryTab.java index 974e50b371f..f2448a3bdbe 100644 --- a/src/main/java/org/jabref/gui/LibraryTab.java +++ b/src/main/java/org/jabref/gui/LibraryTab.java @@ -43,6 +43,7 @@ import org.jabref.logic.autosaveandbackup.AutosaveManager; import org.jabref.logic.autosaveandbackup.BackupManager; import org.jabref.logic.citationstyle.CitationStyleCache; +import org.jabref.logic.importer.ImportFormatReader; import org.jabref.logic.importer.ParserResult; import org.jabref.logic.importer.util.FileFieldParser; import org.jabref.logic.l10n.Localization; @@ -113,13 +114,15 @@ public class LibraryTab extends Tab { private BackgroundTask dataLoadingTask = BackgroundTask.wrap(() -> null); private final IndexingTaskManager indexingTaskManager = new IndexingTaskManager(Globals.TASK_EXECUTOR); + private final ImportFormatReader importFormatReader; public LibraryTab(JabRefFrame frame, PreferencesService preferencesService, StateManager stateManager, ThemeManager themeManager, BibDatabaseContext bibDatabaseContext, - ExternalFileTypes externalFileTypes) { + ExternalFileTypes externalFileTypes, + ImportFormatReader importFormatReader) { this.frame = Objects.requireNonNull(frame); this.bibDatabaseContext = Objects.requireNonNull(bibDatabaseContext); this.externalFileTypes = Objects.requireNonNull(externalFileTypes); @@ -128,6 +131,7 @@ public LibraryTab(JabRefFrame frame, this.preferencesService = Objects.requireNonNull(preferencesService); this.stateManager = Objects.requireNonNull(stateManager); this.themeManager = Objects.requireNonNull(themeManager); + this.importFormatReader = importFormatReader; bibDatabaseContext.getDatabase().registerListener(this); bibDatabaseContext.getMetaData().registerListener(this); @@ -791,11 +795,11 @@ public void resetChangedProperties() { } public static class Factory { - public LibraryTab createLibraryTab(JabRefFrame frame, PreferencesService preferencesService, StateManager stateManager, ThemeManager themeManager, Path file, BackgroundTask dataLoadingTask) { + public LibraryTab createLibraryTab(JabRefFrame frame, PreferencesService preferencesService, StateManager stateManager, ThemeManager themeManager, Path file, BackgroundTask dataLoadingTask, ImportFormatReader importFormatReader) { BibDatabaseContext context = new BibDatabaseContext(); context.setDatabasePath(file); - LibraryTab newTab = new LibraryTab(frame, preferencesService, stateManager, themeManager, context, ExternalFileTypes.getInstance()); + LibraryTab newTab = new LibraryTab(frame, preferencesService, stateManager, themeManager, context, ExternalFileTypes.getInstance(), importFormatReader); newTab.setDataLoadingTask(dataLoadingTask); dataLoadingTask.onRunning(newTab::onDatabaseLoadingStarted) diff --git a/src/main/java/org/jabref/gui/externalfiles/ImportHandler.java b/src/main/java/org/jabref/gui/externalfiles/ImportHandler.java index 16a2460129e..ea9d3848fdb 100644 --- a/src/main/java/org/jabref/gui/externalfiles/ImportHandler.java +++ b/src/main/java/org/jabref/gui/externalfiles/ImportHandler.java @@ -28,8 +28,8 @@ import org.jabref.logic.importer.ImportCleanup; import org.jabref.logic.importer.ImportException; import org.jabref.logic.importer.ImportFormatReader; -import org.jabref.logic.importer.ParseException; import org.jabref.logic.importer.ImportFormatReader.UnknownFormatImport; +import org.jabref.logic.importer.ParseException; import org.jabref.logic.importer.fetcher.ArXiv; import org.jabref.logic.importer.fetcher.DoiFetcher; import org.jabref.logic.importer.fileformat.BibtexParser; @@ -82,9 +82,9 @@ public ImportHandler(BibDatabaseContext database, this.linker = new ExternalFilesEntryLinker(externalFileTypes, preferencesService.getFilePreferences(), database); this.contentImporter = new ExternalFilesContentImporter( - preferencesService.getGeneralPreferences(), - preferencesService.getImporterPreferences(), - preferencesService.getImportFormatPreferences()); + preferencesService.getGeneralPreferences(), + preferencesService.getImporterPreferences(), + preferencesService.getImportFormatPreferences()); this.undoManager = undoManager; } @@ -94,6 +94,7 @@ public ExternalFilesEntryLinker getLinker() { public BackgroundTask> importFilesInBackground(final List files) { return new BackgroundTask<>() { + private int counter; private final List results = new ArrayList<>(); @@ -181,8 +182,8 @@ public void importEntries(List entries) { // Set owner/timestamp UpdateField.setAutomaticFields(entries, - preferencesService.getOwnerPreferences(), - preferencesService.getTimestampPreferences()); + preferencesService.getOwnerPreferences(), + preferencesService.getTimestampPreferences()); // Generate citation keys if (preferencesService.getImporterPreferences().isGenerateNewKeyOnImport()) { @@ -215,7 +216,7 @@ public void importEntryWithDuplicateCheck(BibDatabaseContext bibDatabaseContext, case AUTOREMOVE_EXACT: case BREAK: default: - return; + return; } } // Regenerate CiteKey of imported BibEntry @@ -252,28 +253,17 @@ private void addToGroups(List entries, Collection group */ private void generateKeys(List entries) { CitationKeyGenerator keyGenerator = new CitationKeyGenerator( - bibDatabaseContext.getMetaData().getCiteKeyPattern(preferencesService.getCitationKeyPatternPreferences() - .getKeyPattern()), - bibDatabaseContext.getDatabase(), - preferencesService.getCitationKeyPatternPreferences()); + bibDatabaseContext.getMetaData().getCiteKeyPattern(preferencesService.getCitationKeyPatternPreferences() + .getKeyPattern()), + bibDatabaseContext.getDatabase(), + preferencesService.getCitationKeyPatternPreferences()); for (BibEntry entry : entries) { keyGenerator.generateAndSetKey(entry); } } - public List extractData(String data) { - /* Object entries = clipboard.getContent(DragAndDropDataFormats.ENTRIES); - - if (entries == null) { - return handleStringData(clipboard.getString()); - } - return handleBibTeXData((String) entries); - */ - return null; - } - - private List handleBibTeXData(String entries) { + public List handleBibTeXData(String entries) { BibtexParser parser = new BibtexParser(preferencesService.getImportFormatPreferences(), Globals.getFileUpdateMonitor()); try { return parser.parseEntries(new ByteArrayInputStream(entries.getBytes(StandardCharsets.UTF_8))); @@ -283,7 +273,7 @@ private List handleBibTeXData(String entries) { } } - private List handleStringData(String data) { + public List handleStringData(String data) { if ((data == null) || data.isEmpty()) { return Collections.emptyList(); } diff --git a/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java b/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java index 02c38ad9a34..052dba2ccac 100644 --- a/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java +++ b/src/main/java/org/jabref/gui/importer/actions/OpenDatabaseAction.java @@ -180,7 +180,7 @@ private void openTheFile(Path file, boolean raisePanel) { BackgroundTask backgroundTask = BackgroundTask.wrap(() -> loadDatabase(file)); LibraryTab.Factory libraryTabFactory = new LibraryTab.Factory(); - LibraryTab newTab = libraryTabFactory.createLibraryTab(frame, preferencesService, stateManager, themeManager, file, backgroundTask); + LibraryTab newTab = libraryTabFactory.createLibraryTab(frame, preferencesService, stateManager, themeManager, file, backgroundTask, Globals.IMPORT_FORMAT_READER); backgroundTask.onFinished(() -> trackOpenNewDatabase(newTab)); } diff --git a/src/main/java/org/jabref/gui/maintable/MainTable.java b/src/main/java/org/jabref/gui/maintable/MainTable.java index 4a297b708bb..2bde31e1933 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTable.java +++ b/src/main/java/org/jabref/gui/maintable/MainTable.java @@ -313,19 +313,22 @@ private void clearAndSelectLast() { } public void paste() { - - String data = this.clipBoardManager.getContents(); - //TODO call import handler - /*// Find entries in clipboard + List entriesToAdd = this.clipBoardManager.getBibTeXEntriesFromClipbaord() + .map(importHandler::handleBibTeXData) + .orElseGet(this::handleNonBibteXStringData); for (BibEntry entry : entriesToAdd) { importHandler.importEntryWithDuplicateCheck(database, entry); } if (!entriesToAdd.isEmpty()) { this.requestFocus(); - }*/ + } } + private List handleNonBibteXStringData() { + String data = this.clipBoardManager.getContents(); + return this.importHandler.handleStringData(data); + } private void handleOnDragOver(TableRow row, BibEntryTableViewModel item, DragEvent event) { if (event.getDragboard().hasFiles()) { diff --git a/src/main/java/org/jabref/logic/importer/FetcherClientException.java b/src/main/java/org/jabref/logic/importer/FetcherClientException.java index 3d308e7d1b2..8de9d0d6114 100644 --- a/src/main/java/org/jabref/logic/importer/FetcherClientException.java +++ b/src/main/java/org/jabref/logic/importer/FetcherClientException.java @@ -16,5 +16,4 @@ public FetcherClientException(String errorMessage) { public FetcherClientException(String errorMessage, String localizedMessage, Throwable cause) { super(errorMessage, localizedMessage, cause); } - } diff --git a/src/main/java/org/jabref/logic/importer/FetcherServerException.java b/src/main/java/org/jabref/logic/importer/FetcherServerException.java index 6b3342e115f..537d71ff530 100644 --- a/src/main/java/org/jabref/logic/importer/FetcherServerException.java +++ b/src/main/java/org/jabref/logic/importer/FetcherServerException.java @@ -15,5 +15,4 @@ public FetcherServerException(String errorMessage) { public FetcherServerException(String errorMessage, String localizedMessage, Throwable cause) { super(errorMessage, localizedMessage, cause); } - } diff --git a/src/main/java/org/jabref/logic/net/URLDownload.java b/src/main/java/org/jabref/logic/net/URLDownload.java index 686bb2dc0e9..11456ca857f 100644 --- a/src/main/java/org/jabref/logic/net/URLDownload.java +++ b/src/main/java/org/jabref/logic/net/URLDownload.java @@ -367,12 +367,8 @@ private URLConnection openConnection() throws IOException { if (status >= 500) { throw new IOException(new FetcherServerException("Server error. Status Code " + status)); } - } - // this does network i/o: GET + read returned headers - connection.connect(); - return connection; } From 890e62355ae9a59fa6653cd042d4b367d27d1b57 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Fri, 15 Jul 2022 19:48:06 +0200 Subject: [PATCH 14/27] remove unused prefs --- src/main/java/org/jabref/gui/JabRefMain.java | 2 +- src/main/java/org/jabref/gui/importer/ImportAction.java | 6 +++--- .../customimporter/CustomImporterTabViewModel.java | 1 - .../java/org/jabref/logic/importer/ImportFormatReader.java | 5 +---- .../logic/importer/ImportFormatReaderIntegrationTest.java | 2 +- .../logic/importer/ImportFormatReaderTestParameterless.java | 2 +- 6 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/jabref/gui/JabRefMain.java b/src/main/java/org/jabref/gui/JabRefMain.java index 32de8b6f0d9..e26b1286c9b 100644 --- a/src/main/java/org/jabref/gui/JabRefMain.java +++ b/src/main/java/org/jabref/gui/JabRefMain.java @@ -163,7 +163,7 @@ private static void applyPreferences(PreferencesService preferences) { // Build list of Import and Export formats Globals.IMPORT_FORMAT_READER.resetImportFormats(preferences.getImporterPreferences(), - preferences.getGeneralPreferences(), preferences.getImportFormatPreferences(), + preferences.getImportFormatPreferences(), preferences.getXmpPreferences(), Globals.getFileUpdateMonitor()); Globals.entryTypesManager.addCustomOrModifiedTypes(preferences.getBibEntryTypes(BibDatabaseMode.BIBTEX), preferences.getBibEntryTypes(BibDatabaseMode.BIBLATEX)); diff --git a/src/main/java/org/jabref/gui/importer/ImportAction.java b/src/main/java/org/jabref/gui/importer/ImportAction.java index 37566e8dc83..3b08767886d 100644 --- a/src/main/java/org/jabref/gui/importer/ImportAction.java +++ b/src/main/java/org/jabref/gui/importer/ImportAction.java @@ -122,7 +122,7 @@ private List doImport(List files) // Unknown format: DefaultTaskExecutor.runAndWaitInJavaFXThread(() -> { if (fileIsPdf(filename) && GrobidOptInDialogHelper.showAndWaitIfUserIsUndecided(frame.getDialogService(), prefs.getImporterPreferences())) { - Globals.IMPORT_FORMAT_READER.resetImportFormats(prefs.getImporterPreferences(), prefs.getGeneralPreferences(), prefs.getImportFormatPreferences(), prefs.getXmpPreferences(), Globals.getFileUpdateMonitor()); + Globals.IMPORT_FORMAT_READER.resetImportFormats(prefs.getImporterPreferences(), prefs.getImportFormatPreferences(), prefs.getXmpPreferences(), Globals.getFileUpdateMonitor()); } frame.getDialogService().notify(Localization.lang("Importing in unknown format") + "..."); }); @@ -130,8 +130,8 @@ private List doImport(List files) imports.add(Globals.IMPORT_FORMAT_READER.importUnknownFormat(filename, Globals.getFileUpdateMonitor())); } else { DefaultTaskExecutor.runAndWaitInJavaFXThread(() -> { - if (importer.get() instanceof PdfGrobidImporter || importer.get() instanceof PdfMergeMetadataImporter && GrobidOptInDialogHelper.showAndWaitIfUserIsUndecided(frame.getDialogService(), prefs.getImporterPreferences())) { - Globals.IMPORT_FORMAT_READER.resetImportFormats(prefs.getImporterPreferences(), prefs.getGeneralPreferences(), prefs.getImportFormatPreferences(), prefs.getXmpPreferences(), Globals.getFileUpdateMonitor()); + if ((importer.get() instanceof PdfGrobidImporter) || ((importer.get() instanceof PdfMergeMetadataImporter) && GrobidOptInDialogHelper.showAndWaitIfUserIsUndecided(frame.getDialogService(), prefs.getImporterPreferences()))) { + Globals.IMPORT_FORMAT_READER.resetImportFormats(prefs.getImporterPreferences(), prefs.getImportFormatPreferences(), prefs.getXmpPreferences(), Globals.getFileUpdateMonitor()); } frame.getDialogService().notify(Localization.lang("Importing in %0 format", importer.get().getName()) + "..."); }); diff --git a/src/main/java/org/jabref/gui/preferences/customimporter/CustomImporterTabViewModel.java b/src/main/java/org/jabref/gui/preferences/customimporter/CustomImporterTabViewModel.java index 218c76d940a..08012693858 100644 --- a/src/main/java/org/jabref/gui/preferences/customimporter/CustomImporterTabViewModel.java +++ b/src/main/java/org/jabref/gui/preferences/customimporter/CustomImporterTabViewModel.java @@ -55,7 +55,6 @@ public void storeSettings() { .collect(Collectors.toSet())); Globals.IMPORT_FORMAT_READER.resetImportFormats( preferences.getImporterPreferences(), - preferences.getGeneralPreferences(), preferences.getImportFormatPreferences(), preferences.getXmpPreferences(), Globals.getFileUpdateMonitor()); diff --git a/src/main/java/org/jabref/logic/importer/ImportFormatReader.java b/src/main/java/org/jabref/logic/importer/ImportFormatReader.java index f3b8826171d..b9b6f4b850c 100644 --- a/src/main/java/org/jabref/logic/importer/ImportFormatReader.java +++ b/src/main/java/org/jabref/logic/importer/ImportFormatReader.java @@ -39,7 +39,6 @@ import org.jabref.model.entry.BibEntry; import org.jabref.model.strings.StringUtil; import org.jabref.model.util.FileUpdateMonitor; -import org.jabref.preferences.GeneralPreferences; public class ImportFormatReader { @@ -51,11 +50,9 @@ public class ImportFormatReader { */ private final List formats = new ArrayList<>(); - private GeneralPreferences generalPreferences; private ImportFormatPreferences importFormatPreferences; - public void resetImportFormats(ImporterPreferences importerPreferences, GeneralPreferences generalPreferences, ImportFormatPreferences newImportFormatPreferences, XmpPreferences xmpPreferences, FileUpdateMonitor fileMonitor) { - this.generalPreferences = generalPreferences; + public void resetImportFormats(ImporterPreferences importerPreferences, ImportFormatPreferences newImportFormatPreferences, XmpPreferences xmpPreferences, FileUpdateMonitor fileMonitor) { this.importFormatPreferences = newImportFormatPreferences; formats.clear(); diff --git a/src/test/java/org/jabref/logic/importer/ImportFormatReaderIntegrationTest.java b/src/test/java/org/jabref/logic/importer/ImportFormatReaderIntegrationTest.java index e7f45023830..ac6262322fb 100644 --- a/src/test/java/org/jabref/logic/importer/ImportFormatReaderIntegrationTest.java +++ b/src/test/java/org/jabref/logic/importer/ImportFormatReaderIntegrationTest.java @@ -30,7 +30,7 @@ void setUp() { ImportFormatPreferences importFormatPreferences = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS); when(importFormatPreferences.getCustomImportList()).thenReturn(Set.of()); GeneralPreferences generalPreferences = mock(GeneralPreferences.class, Answers.RETURNS_DEEP_STUBS); - reader.resetImportFormats(mock(ImporterPreferences.class), generalPreferences, importFormatPreferences, mock(XmpPreferences.class), new DummyFileUpdateMonitor()); + reader.resetImportFormats(mock(ImporterPreferences.class), importFormatPreferences, mock(XmpPreferences.class), new DummyFileUpdateMonitor()); } @ParameterizedTest diff --git a/src/test/java/org/jabref/logic/importer/ImportFormatReaderTestParameterless.java b/src/test/java/org/jabref/logic/importer/ImportFormatReaderTestParameterless.java index 4f867e05141..b0eadfda8dd 100644 --- a/src/test/java/org/jabref/logic/importer/ImportFormatReaderTestParameterless.java +++ b/src/test/java/org/jabref/logic/importer/ImportFormatReaderTestParameterless.java @@ -27,7 +27,7 @@ void setUp() { GeneralPreferences generalPreferences = mock(GeneralPreferences.class, Answers.RETURNS_DEEP_STUBS); ImportFormatPreferences importFormatPreferences = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS); when(importFormatPreferences.getCustomImportList()).thenReturn(Set.of()); - reader.resetImportFormats(mock(ImporterPreferences.class), generalPreferences, importFormatPreferences, mock(XmpPreferences.class), fileMonitor); + reader.resetImportFormats(mock(ImporterPreferences.class), importFormatPreferences, mock(XmpPreferences.class), fileMonitor); } @Test From c6deb0c3d34b498803a5262392862feb02298192 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Fri, 15 Jul 2022 19:49:46 +0200 Subject: [PATCH 15/27] revert style changes --- .../gui/externalfiles/ImportHandler.java | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/jabref/gui/externalfiles/ImportHandler.java b/src/main/java/org/jabref/gui/externalfiles/ImportHandler.java index ea9d3848fdb..7264296bf3b 100644 --- a/src/main/java/org/jabref/gui/externalfiles/ImportHandler.java +++ b/src/main/java/org/jabref/gui/externalfiles/ImportHandler.java @@ -82,9 +82,9 @@ public ImportHandler(BibDatabaseContext database, this.linker = new ExternalFilesEntryLinker(externalFileTypes, preferencesService.getFilePreferences(), database); this.contentImporter = new ExternalFilesContentImporter( - preferencesService.getGeneralPreferences(), - preferencesService.getImporterPreferences(), - preferencesService.getImportFormatPreferences()); + preferencesService.getGeneralPreferences(), + preferencesService.getImporterPreferences(), + preferencesService.getImportFormatPreferences()); this.undoManager = undoManager; } @@ -94,7 +94,6 @@ public ExternalFilesEntryLinker getLinker() { public BackgroundTask> importFilesInBackground(final List files) { return new BackgroundTask<>() { - private int counter; private final List results = new ArrayList<>(); @@ -182,8 +181,8 @@ public void importEntries(List entries) { // Set owner/timestamp UpdateField.setAutomaticFields(entries, - preferencesService.getOwnerPreferences(), - preferencesService.getTimestampPreferences()); + preferencesService.getOwnerPreferences(), + preferencesService.getTimestampPreferences()); // Generate citation keys if (preferencesService.getImporterPreferences().isGenerateNewKeyOnImport()) { @@ -216,7 +215,7 @@ public void importEntryWithDuplicateCheck(BibDatabaseContext bibDatabaseContext, case AUTOREMOVE_EXACT: case BREAK: default: - return; + return; } } // Regenerate CiteKey of imported BibEntry @@ -253,10 +252,10 @@ private void addToGroups(List entries, Collection group */ private void generateKeys(List entries) { CitationKeyGenerator keyGenerator = new CitationKeyGenerator( - bibDatabaseContext.getMetaData().getCiteKeyPattern(preferencesService.getCitationKeyPatternPreferences() - .getKeyPattern()), - bibDatabaseContext.getDatabase(), - preferencesService.getCitationKeyPatternPreferences()); + bibDatabaseContext.getMetaData().getCiteKeyPattern(preferencesService.getCitationKeyPatternPreferences() + .getKeyPattern()), + bibDatabaseContext.getDatabase(), + preferencesService.getCitationKeyPatternPreferences()); for (BibEntry entry : entries) { keyGenerator.generateAndSetKey(entry); From 4b0aeb2f9e9ea669759d3963517e98fe4cfe8842 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Fri, 15 Jul 2022 20:09:47 +0200 Subject: [PATCH 16/27] fix checkstlye fix l10n fix unused var --- src/main/java/org/jabref/gui/ClipBoardManager.java | 3 +-- .../jabref/gui/errorconsole/ErrorConsoleViewModel.java | 5 ----- .../gui/fieldeditors/IdentifierEditorViewModel.java | 4 ++-- src/main/java/org/jabref/gui/maintable/MainTable.java | 2 -- .../org/jabref/gui/mergeentries/FetchAndMergeEntry.java | 4 ++-- .../java/org/jabref/logic/importer/IdParserFetcher.java | 8 ++++---- src/main/resources/l10n/JabRef_en.properties | 2 +- 7 files changed, 10 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/jabref/gui/ClipBoardManager.java b/src/main/java/org/jabref/gui/ClipBoardManager.java index 174072065c2..a75dd1798d9 100644 --- a/src/main/java/org/jabref/gui/ClipBoardManager.java +++ b/src/main/java/org/jabref/gui/ClipBoardManager.java @@ -38,7 +38,6 @@ public class ClipBoardManager { private final PreferencesService preferencesService; - public ClipBoardManager(PreferencesService preferencesService) { this(Clipboard.getSystemClipboard(), Toolkit.getDefaultToolkit().getSystemSelection(), preferencesService); } @@ -88,7 +87,7 @@ public static String getContents() { return result; } - public Optional getBibTeXEntriesFromClipbaord(){ + public Optional getBibTeXEntriesFromClipbaord() { return Optional.ofNullable(clipboard.getContent(DragAndDropDataFormats.ENTRIES)).map(String.class::cast); } diff --git a/src/main/java/org/jabref/gui/errorconsole/ErrorConsoleViewModel.java b/src/main/java/org/jabref/gui/errorconsole/ErrorConsoleViewModel.java index 3d2752a42ef..bd3bb87da8c 100644 --- a/src/main/java/org/jabref/gui/errorconsole/ErrorConsoleViewModel.java +++ b/src/main/java/org/jabref/gui/errorconsole/ErrorConsoleViewModel.java @@ -2,9 +2,6 @@ import java.io.IOException; import java.net.URISyntaxException; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Date; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; @@ -30,8 +27,6 @@ public class ErrorConsoleViewModel extends AbstractViewModel { private static final Logger LOGGER = LoggerFactory.getLogger(ErrorConsoleViewModel.class); - private final DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); - private final Date date = new Date(); private final DialogService dialogService; private final ClipBoardManager clipBoardManager; private final BuildInfo buildInfo; diff --git a/src/main/java/org/jabref/gui/fieldeditors/IdentifierEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/IdentifierEditorViewModel.java index 84dbf1e9cc2..c70e9688575 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/IdentifierEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/IdentifierEditorViewModel.java @@ -129,9 +129,9 @@ public void lookupIdentifier(BibEntry entry) { .onFailure(exception -> { LOGGER.error("Error while fetching bibliographic information", exception); if (exception instanceof FetcherClientException) { - dialogService.showInformationDialogAndWait(Localization.lang("Lookup {0}", idFetcher.getName()), Localization.lang("No data was found for the identifier")); + dialogService.showInformationDialogAndWait(Localization.lang("Lookup %0", idFetcher.getName()), Localization.lang("No data was found for the identifier")); } else if (exception instanceof FetcherServerException) { - dialogService.showInformationDialogAndWait(Localization.lang("Lookup {0}", idFetcher.getName()), Localization.lang("Server not available")); + dialogService.showInformationDialogAndWait(Localization.lang("Lookup %0", idFetcher.getName()), Localization.lang("Server not available")); } else { dialogService.showErrorDialogAndWait(exception); } diff --git a/src/main/java/org/jabref/gui/maintable/MainTable.java b/src/main/java/org/jabref/gui/maintable/MainTable.java index 2bde31e1933..d2d46d73c70 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTable.java +++ b/src/main/java/org/jabref/gui/maintable/MainTable.java @@ -456,6 +456,4 @@ private Optional findEntry(BibEntry entry) { .filter(viewModel -> viewModel.getEntry().equals(entry)) .findFirst(); } - - } diff --git a/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java b/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java index 3a86375aea3..a3fc8a3a60b 100644 --- a/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java +++ b/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java @@ -79,9 +79,9 @@ public void fetchAndMerge(BibEntry entry, List fields) { .onFailure(exception -> { LOGGER.error("Error while fetching bibliographic information", exception); if (exception instanceof FetcherClientException) { - dialogService.showInformationDialogAndWait(Localization.lang("Lookup {0}", fetcher.get().getName()), Localization.lang("No data was found for the identifier")); + dialogService.showInformationDialogAndWait(Localization.lang("Lookup %0", fetcher.get().getName()), Localization.lang("No data was found for the identifier")); } else if (exception instanceof FetcherServerException) { - dialogService.showInformationDialogAndWait(Localization.lang("Lookup {0}", fetcher.get().getName()), Localization.lang("Server not available")); + dialogService.showInformationDialogAndWait(Localization.lang("Lookup %0", fetcher.get().getName()), Localization.lang("Server not available")); } else { dialogService.showErrorDialogAndWait(exception); } diff --git a/src/main/java/org/jabref/logic/importer/IdParserFetcher.java b/src/main/java/org/jabref/logic/importer/IdParserFetcher.java index f194f815ed8..b9b5ed92e44 100644 --- a/src/main/java/org/jabref/logic/importer/IdParserFetcher.java +++ b/src/main/java/org/jabref/logic/importer/IdParserFetcher.java @@ -88,10 +88,10 @@ default Optional findIdentifier(BibEntry entry) throws FetcherException { LOGGER.debug("Id not found"); return Optional.empty(); } catch (IOException e) { - - - // TODO: Catch HTTP Response 401 errors and report that user has no rights to access resource - // TODO catch 503 service unavailable and alert user + // check for the case where we already have a FetcherException from UrlDownload + if (e.getCause() instanceof FetcherException fe) { + throw fe; + } throw new FetcherException("An I/O exception occurred", e); } catch (ParseException e) { throw new FetcherException("An internal parser error occurred", e); diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index b7a618d751d..db92c390b6c 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -2487,7 +2487,7 @@ Version=Version Error\ downloading=Error downloading -Lookup\ {0}=Lookup {0} +Lookup\ %0=Lookup %0 No\ data\ was\ found\ for\ the\ identifier=No data was found for the identifier Server\ not\ available=Server not available From a03e25f3e58f723e5a424e4cc5b4e996ffca1fed Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sat, 16 Jul 2022 18:09:17 +0200 Subject: [PATCH 17/27] do not throw 404 errors from UrlDownload Fix some fetcher tests --- .../org/jabref/logic/importer/IdBasedParserFetcher.java | 5 ++++- .../org/jabref/logic/importer/PagedSearchBasedFetcher.java | 1 + src/main/java/org/jabref/logic/net/URLDownload.java | 6 +++++- .../org/jabref/logic/importer/fetcher/DoiFetcherTest.java | 5 ++--- .../org/jabref/logic/importer/fetcher/JstorFetcherTest.java | 5 +++-- .../org/jabref/logic/importer/fetcher/RfcFetcherTest.java | 2 +- 6 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/jabref/logic/importer/IdBasedParserFetcher.java b/src/main/java/org/jabref/logic/importer/IdBasedParserFetcher.java index 6be4a8dddfd..e348b69b8d8 100644 --- a/src/main/java/org/jabref/logic/importer/IdBasedParserFetcher.java +++ b/src/main/java/org/jabref/logic/importer/IdBasedParserFetcher.java @@ -81,7 +81,10 @@ default Optional performSearchById(String identifier) throws FetcherEx } catch (URISyntaxException e) { throw new FetcherException("Search URI is malformed", e); } catch (IOException e) { - // TODO: Catch HTTP Response 401 errors and report that user has no rights to access resource. It might be that there is an UnknownHostException (eutils.ncbi.nlm.nih.gov cannot be resolved). + // check for the case where we already have a FetcherException from UrlDownload + if (e.getCause() instanceof FetcherException fe) { + throw fe; + } throw new FetcherException("A network error occurred", e); } catch (ParseException e) { throw new FetcherException("An internal parser error occurred", e); diff --git a/src/main/java/org/jabref/logic/importer/PagedSearchBasedFetcher.java b/src/main/java/org/jabref/logic/importer/PagedSearchBasedFetcher.java index 1b8d31a064b..bafae176485 100644 --- a/src/main/java/org/jabref/logic/importer/PagedSearchBasedFetcher.java +++ b/src/main/java/org/jabref/logic/importer/PagedSearchBasedFetcher.java @@ -52,6 +52,7 @@ default int getPageSize() { * @param luceneQuery the root node of the lucene query * @return a list of {@link BibEntry}, which are matched by the query (may be empty) */ + @Override default List performSearch(QueryNode luceneQuery) throws FetcherException { return new ArrayList<>(performSearchPaged(luceneQuery, 0).getContent()); } diff --git a/src/main/java/org/jabref/logic/net/URLDownload.java b/src/main/java/org/jabref/logic/net/URLDownload.java index 11456ca857f..8cca3673e37 100644 --- a/src/main/java/org/jabref/logic/net/URLDownload.java +++ b/src/main/java/org/jabref/logic/net/URLDownload.java @@ -358,9 +358,13 @@ private URLConnection openConnection() throws IOException { || (status == HttpURLConnection.HTTP_SEE_OTHER)) { // get redirect url from "location" header field String newUrl = connection.getHeaderField("location"); - // open the new connnection again + // open the new connection again connection = new URLDownload(newUrl).openConnection(); } + if (status == HttpURLConnection.HTTP_NOT_FOUND) { + LOGGER.debug("Encountered 404 error for {}", connection.getURL()); + return connection; + } if ((status >= 400) && (status < 500)) { throw new IOException(new FetcherClientException("Client error. Status code " + status)); } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/DoiFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/DoiFetcherTest.java index 134cdbc52d8..da157b42347 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/DoiFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/DoiFetcherTest.java @@ -2,7 +2,6 @@ import java.util.Optional; -import org.jabref.logic.importer.FetcherClientException; import org.jabref.logic.importer.FetcherException; import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.model.entry.BibEntry; @@ -104,12 +103,12 @@ public void testPerformSearchInvalidDOI() { @Test public void testPerformSearchInvalidDOIClientResultsinFetcherClientException() { - assertThrows(FetcherClientException.class, () -> fetcher.performSearchById("10.1002/9781118257517F")); + assertThrows(FetcherException.class, () -> fetcher.performSearchById("10.1002/9781118257517F")); } @Test public void testPerformSearchInvalidDOIClientResultsinFetcherClientException2() { - assertThrows(FetcherClientException.class, () -> fetcher.performSearchById("10.1002/9781517F")); + assertThrows(FetcherException.class, () -> fetcher.performSearchById("10.1002/9781517F")); } @Test diff --git a/src/test/java/org/jabref/logic/importer/fetcher/JstorFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/JstorFetcherTest.java index 1bd77942c35..e9c3e0963d8 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/JstorFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/JstorFetcherTest.java @@ -40,7 +40,8 @@ public class JstorFetcherTest implements SearchBasedFetcherCapabilityTest { .withField(StandardField.PAGES, "63--73") .withField(StandardField.VOLUME, "20") .withField(StandardField.URL, "http://www.jstor.org/stable/90002164") - .withField(StandardField.YEAR, "2017"); + .withField(StandardField.YEAR, "2017") + .withField(StandardField.URLDATE, "2022-07-16"); private final BibEntry doiEntry = new BibEntry(StandardEntryType.Article) .withCitationKey("10.1086/501484") @@ -69,7 +70,7 @@ void searchById() throws FetcherException { } @Test - void fetchPDF() throws IOException, FetcherException { + void fetchPDF() throws IOException { Optional url = fetcher.findFullText(bibEntry); assertEquals(Optional.of(new URL("https://www.jstor.org/stable/pdf/90002164.pdf")), url); } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/RfcFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/RfcFetcherTest.java index 63db56f9a81..66f36912554 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/RfcFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/RfcFetcherTest.java @@ -63,7 +63,7 @@ public void performSearchByIdFindsEntryWithDraftIdentifier() throws Exception { bibDraftEntry.setField(StandardField.PUBLISHER, "Internet Engineering Task Force"); bibDraftEntry.setField(StandardField.TITLE, "{Hypertext Transfer Protocol -- HTTP/1.0}"); bibDraftEntry.setField(StandardField.TYPE, "Internet-Draft"); - bibDraftEntry.setField(StandardField.URL, "https://datatracker.ietf.org/doc/html/draft-fielding-http-spec-01"); + bibDraftEntry.setField(StandardField.URL, "https://datatracker.ietf.org/doc/draft-fielding-http-spec/01/"); bibDraftEntry.setField(StandardField.YEAR, "1994"); bibDraftEntry.setField(StandardField.ABSTRACT, "The Hypertext Transfer Protocol (HTTP) is an application-level protocol with the lightness and speed necessary for distributed, collaborative, hypermedia information systems. It is a generic, stateless, object-oriented protocol which can be used for many tasks, such as name servers and distributed object management systems, through extension of its request methods (commands). A feature of HTTP is the typing and negotiation of data representation, allowing systems to be built independently of the data being transferred. HTTP has been in use by the World-Wide Web global information initiative since 1990. This specification reflects preferred usage of the protocol referred to as 'HTTP/1.0', and is compatible with the most commonly used HTTP server and client programs implemented prior to November 1994."); bibDraftEntry.setCommentsBeforeEntry("%% You should probably cite draft-ietf-http-v10-spec instead of this I-D.\n"); From 32fd370e2b7879e4d4e1c0f1fbb533755d48d70c Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sat, 16 Jul 2022 21:16:55 +0200 Subject: [PATCH 18/27] better error messages throw exception on 404 todo fix tests --- .../org/jabref/gui/EntryTypeViewModel.java | 6 +++-- .../gui/externalfiles/ImportHandler.java | 25 ++++++------------- .../org/jabref/gui/maintable/MainTable.java | 21 ++++++++++++++-- .../org/jabref/logic/net/URLDownload.java | 4 --- 4 files changed, 31 insertions(+), 25 deletions(-) diff --git a/src/main/java/org/jabref/gui/EntryTypeViewModel.java b/src/main/java/org/jabref/gui/EntryTypeViewModel.java index b887d0b28bb..95c2eefadc6 100644 --- a/src/main/java/org/jabref/gui/EntryTypeViewModel.java +++ b/src/main/java/org/jabref/gui/EntryTypeViewModel.java @@ -146,9 +146,9 @@ public void runFetcherWorker() { String fetcher = selectedItemProperty().getValue().getName(); String searchId = idText.getValue(); if (exception instanceof FetcherException) { - dialogService.showErrorDialogAndWait(Localization.lang("Error"), Localization.lang("Error while fetching from %0", fetcher + "." + "\n" + fetcherExceptionMessage)); + dialogService.showInformationDialogAndWait(Localization.lang("Error"), Localization.lang("Error while fetching from %0", fetcher + "." + "\n" + fetcherExceptionMessage)); } else { - dialogService.showErrorDialogAndWait(Localization.lang("No files found.", Localization.lang("Fetcher '%0' did not find an entry for id '%1'.", fetcher, searchId) + "\n" + fetcherExceptionMessage)); + dialogService.showInformationDialogAndWait(Localization.lang("No files found."), Localization.lang("Fetcher '%0' did not find an entry for id '%1'.", fetcher, searchId) + "\n" + fetcherExceptionMessage); } LOGGER.error(String.format("Exception during fetching when using fetcher '%s' with entry id '%s'.", searchId, fetcher), exception); @@ -157,6 +157,8 @@ public void runFetcherWorker() { fetcherWorker = new FetcherWorker(); }); + + fetcherWorker.setOnSucceeded(evt -> { Optional result = fetcherWorker.getValue(); if (result.isPresent()) { diff --git a/src/main/java/org/jabref/gui/externalfiles/ImportHandler.java b/src/main/java/org/jabref/gui/externalfiles/ImportHandler.java index 7264296bf3b..9580a481344 100644 --- a/src/main/java/org/jabref/gui/externalfiles/ImportHandler.java +++ b/src/main/java/org/jabref/gui/externalfiles/ImportHandler.java @@ -272,7 +272,7 @@ public List handleBibTeXData(String entries) { } } - public List handleStringData(String data) { + public List handleStringData(String data) throws FetcherException { if ((data == null) || data.isEmpty()) { return Collections.emptyList(); } @@ -298,25 +298,16 @@ private List tryImportFormats(String data) { } } - private List fetchByDOI(DOI doi) { + private List fetchByDOI(DOI doi) throws FetcherException { LOGGER.info("Found DOI in clipboard"); - try { - Optional entry = new DoiFetcher(preferencesService.getImportFormatPreferences()).performSearchById(doi.getDOI()); - return OptionalUtil.toList(entry); - } catch (FetcherException ex) { - LOGGER.error("Error while fetching", ex); - return Collections.emptyList(); - } + Optional entry = new DoiFetcher(preferencesService.getImportFormatPreferences()).performSearchById(doi.getDOI()); + return OptionalUtil.toList(entry); } - private List fetchByArXiv(ArXivIdentifier arXivIdentifier) { + private List fetchByArXiv(ArXivIdentifier arXivIdentifier) throws FetcherException { LOGGER.info("Found arxiv identifier in clipboard"); - try { - Optional entry = new ArXiv(preferencesService.getImportFormatPreferences()).performSearchById(arXivIdentifier.getNormalizedWithoutVersion()); - return OptionalUtil.toList(entry); - } catch (FetcherException ex) { - LOGGER.error("Error while fetching", ex); - return Collections.emptyList(); - } + Optional entry = new ArXiv(preferencesService.getImportFormatPreferences()).performSearchById(arXivIdentifier.getNormalizedWithoutVersion()); + return OptionalUtil.toList(entry); + } } diff --git a/src/main/java/org/jabref/gui/maintable/MainTable.java b/src/main/java/org/jabref/gui/maintable/MainTable.java index d2d46d73c70..6d8fa056308 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTable.java +++ b/src/main/java/org/jabref/gui/maintable/MainTable.java @@ -3,6 +3,7 @@ import java.io.File; import java.io.IOException; import java.nio.file.Path; +import java.util.ArrayList; import java.util.List; import java.util.Objects; import java.util.Optional; @@ -42,6 +43,9 @@ import org.jabref.gui.util.CustomLocalDragboard; import org.jabref.gui.util.DefaultTaskExecutor; import org.jabref.gui.util.ViewModelTableRowFactory; +import org.jabref.logic.importer.FetcherClientException; +import org.jabref.logic.importer.FetcherException; +import org.jabref.logic.importer.FetcherServerException; import org.jabref.logic.importer.ImportFormatReader; import org.jabref.logic.l10n.Localization; import org.jabref.model.database.BibDatabaseContext; @@ -313,7 +317,8 @@ private void clearAndSelectLast() { } public void paste() { - List entriesToAdd = this.clipBoardManager.getBibTeXEntriesFromClipbaord() + List entriesToAdd = new ArrayList<>(); + entriesToAdd = this.clipBoardManager.getBibTeXEntriesFromClipbaord() .map(importHandler::handleBibTeXData) .orElseGet(this::handleNonBibteXStringData); @@ -327,7 +332,19 @@ public void paste() { private List handleNonBibteXStringData() { String data = this.clipBoardManager.getContents(); - return this.importHandler.handleStringData(data); + List entries = new ArrayList<>(); + try { + entries = this.importHandler.handleStringData(data); + } catch (FetcherException exception) { + if (exception instanceof FetcherClientException) { + dialogService.showInformationDialogAndWait(Localization.lang("Lookup identifier"), Localization.lang("No data was found for the identifier")); + } else if (exception instanceof FetcherServerException) { + dialogService.showInformationDialogAndWait(Localization.lang("Lookup identifier"), Localization.lang("Server not available")); + } else { + dialogService.showErrorDialogAndWait(exception); + } + } + return entries; } private void handleOnDragOver(TableRow row, BibEntryTableViewModel item, DragEvent event) { diff --git a/src/main/java/org/jabref/logic/net/URLDownload.java b/src/main/java/org/jabref/logic/net/URLDownload.java index 8cca3673e37..a47ae3055ac 100644 --- a/src/main/java/org/jabref/logic/net/URLDownload.java +++ b/src/main/java/org/jabref/logic/net/URLDownload.java @@ -361,10 +361,6 @@ private URLConnection openConnection() throws IOException { // open the new connection again connection = new URLDownload(newUrl).openConnection(); } - if (status == HttpURLConnection.HTTP_NOT_FOUND) { - LOGGER.debug("Encountered 404 error for {}", connection.getURL()); - return connection; - } if ((status >= 400) && (status < 500)) { throw new IOException(new FetcherClientException("Client error. Status code " + status)); } From a9c45894929b1d8fba4a750cfa535dc09503870c Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sat, 16 Jul 2022 21:22:57 +0200 Subject: [PATCH 19/27] checkstyle --- src/main/java/org/jabref/gui/EntryTypeViewModel.java | 3 --- src/main/java/org/jabref/gui/externalfiles/ImportHandler.java | 1 - 2 files changed, 4 deletions(-) diff --git a/src/main/java/org/jabref/gui/EntryTypeViewModel.java b/src/main/java/org/jabref/gui/EntryTypeViewModel.java index 95c2eefadc6..b6aa7b33d42 100644 --- a/src/main/java/org/jabref/gui/EntryTypeViewModel.java +++ b/src/main/java/org/jabref/gui/EntryTypeViewModel.java @@ -153,12 +153,9 @@ public void runFetcherWorker() { LOGGER.error(String.format("Exception during fetching when using fetcher '%s' with entry id '%s'.", searchId, fetcher), exception); searchingProperty.set(false); - fetcherWorker = new FetcherWorker(); }); - - fetcherWorker.setOnSucceeded(evt -> { Optional result = fetcherWorker.getValue(); if (result.isPresent()) { diff --git a/src/main/java/org/jabref/gui/externalfiles/ImportHandler.java b/src/main/java/org/jabref/gui/externalfiles/ImportHandler.java index 9580a481344..61cc7afd2e8 100644 --- a/src/main/java/org/jabref/gui/externalfiles/ImportHandler.java +++ b/src/main/java/org/jabref/gui/externalfiles/ImportHandler.java @@ -308,6 +308,5 @@ private List fetchByArXiv(ArXivIdentifier arXivIdentifier) throws Fetc LOGGER.info("Found arxiv identifier in clipboard"); Optional entry = new ArXiv(preferencesService.getImportFormatPreferences()).performSearchById(arXivIdentifier.getNormalizedWithoutVersion()); return OptionalUtil.toList(entry); - } } From 73a88b704daa4a71932025179e27044eeda3b2be Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Mon, 18 Jul 2022 20:57:43 +0200 Subject: [PATCH 20/27] improve dialog messages --- .../jabref/gui/fieldeditors/IdentifierEditorViewModel.java | 4 ++-- src/main/java/org/jabref/gui/maintable/MainTable.java | 4 ++-- .../java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java | 4 ++-- src/main/resources/l10n/JabRef_en.properties | 3 ++- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/jabref/gui/fieldeditors/IdentifierEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/IdentifierEditorViewModel.java index c70e9688575..8838eed70f4 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/IdentifierEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/IdentifierEditorViewModel.java @@ -129,9 +129,9 @@ public void lookupIdentifier(BibEntry entry) { .onFailure(exception -> { LOGGER.error("Error while fetching bibliographic information", exception); if (exception instanceof FetcherClientException) { - dialogService.showInformationDialogAndWait(Localization.lang("Lookup %0", idFetcher.getName()), Localization.lang("No data was found for the identifier")); + dialogService.showInformationDialogAndWait(Localization.lang("Look up %0", idFetcher.getName()), Localization.lang("No data was found for the identifier")); } else if (exception instanceof FetcherServerException) { - dialogService.showInformationDialogAndWait(Localization.lang("Lookup %0", idFetcher.getName()), Localization.lang("Server not available")); + dialogService.showInformationDialogAndWait(Localization.lang("Look up %0", idFetcher.getName()), Localization.lang("Server not available")); } else { dialogService.showErrorDialogAndWait(exception); } diff --git a/src/main/java/org/jabref/gui/maintable/MainTable.java b/src/main/java/org/jabref/gui/maintable/MainTable.java index 6d8fa056308..15964b0771e 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTable.java +++ b/src/main/java/org/jabref/gui/maintable/MainTable.java @@ -337,9 +337,9 @@ private List handleNonBibteXStringData() { entries = this.importHandler.handleStringData(data); } catch (FetcherException exception) { if (exception instanceof FetcherClientException) { - dialogService.showInformationDialogAndWait(Localization.lang("Lookup identifier"), Localization.lang("No data was found for the identifier")); + dialogService.showInformationDialogAndWait(Localization.lang("Look up identifier"), Localization.lang("No data was found for the identifier")); } else if (exception instanceof FetcherServerException) { - dialogService.showInformationDialogAndWait(Localization.lang("Lookup identifier"), Localization.lang("Server not available")); + dialogService.showInformationDialogAndWait(Localization.lang("Look up identifier"), Localization.lang("Server not available")); } else { dialogService.showErrorDialogAndWait(exception); } diff --git a/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java b/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java index a3fc8a3a60b..0fc561b0261 100644 --- a/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java +++ b/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java @@ -79,9 +79,9 @@ public void fetchAndMerge(BibEntry entry, List fields) { .onFailure(exception -> { LOGGER.error("Error while fetching bibliographic information", exception); if (exception instanceof FetcherClientException) { - dialogService.showInformationDialogAndWait(Localization.lang("Lookup %0", fetcher.get().getName()), Localization.lang("No data was found for the identifier")); + dialogService.showInformationDialogAndWait(Localization.lang("Fetching information using %0", fetcher.get().getName()), Localization.lang("No data was found for the identifier")); } else if (exception instanceof FetcherServerException) { - dialogService.showInformationDialogAndWait(Localization.lang("Lookup %0", fetcher.get().getName()), Localization.lang("Server not available")); + dialogService.showInformationDialogAndWait(Localization.lang("Fetching information using %0", fetcher.get().getName()), Localization.lang("Server not available")); } else { dialogService.showErrorDialogAndWait(exception); } diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index db92c390b6c..8f32390b60f 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -2487,9 +2487,10 @@ Version=Version Error\ downloading=Error downloading -Lookup\ %0=Lookup %0 No\ data\ was\ found\ for\ the\ identifier=No data was found for the identifier Server\ not\ available=Server not available +Fetching\ information\ using\ %0=Fetching information using %0 +Look\ up\ identifier=Look up identifier Error\ while\ writing\ metadata.\ See\ the\ error\ log\ for\ details.=Error while writing metadata. See the error log for details. Failed\ to\ write\ metadata,\ file\ %1\ not\ found.=Failed to write metadata, file %1 not found. From 5060e34f4b71e059a58d18b7d28f2350fabcc371 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Tue, 19 Jul 2022 19:55:07 +0200 Subject: [PATCH 21/27] change l10n --- .../org/jabref/gui/EntryTypeViewModel.java | 14 +++++++--- .../importer/GenerateEntryFromIdAction.java | 28 ++++++++++--------- .../gui/mergeentries/FetchAndMergeEntry.java | 2 +- .../org/jabref/logic/net/URLDownload.java | 4 +-- src/main/resources/l10n/JabRef_en.properties | 6 ++-- 5 files changed, 32 insertions(+), 22 deletions(-) diff --git a/src/main/java/org/jabref/gui/EntryTypeViewModel.java b/src/main/java/org/jabref/gui/EntryTypeViewModel.java index b6aa7b33d42..754eac11be2 100644 --- a/src/main/java/org/jabref/gui/EntryTypeViewModel.java +++ b/src/main/java/org/jabref/gui/EntryTypeViewModel.java @@ -17,7 +17,9 @@ import org.jabref.gui.externalfiles.ImportHandler; import org.jabref.gui.externalfiletype.ExternalFileTypes; import org.jabref.gui.importer.NewEntryAction; +import org.jabref.logic.importer.FetcherClientException; import org.jabref.logic.importer.FetcherException; +import org.jabref.logic.importer.FetcherServerException; import org.jabref.logic.importer.IdBasedFetcher; import org.jabref.logic.importer.ImportFormatReader; import org.jabref.logic.importer.WebFetchers; @@ -145,11 +147,15 @@ public void runFetcherWorker() { String fetcherExceptionMessage = exception.getMessage(); String fetcher = selectedItemProperty().getValue().getName(); String searchId = idText.getValue(); - if (exception instanceof FetcherException) { - dialogService.showInformationDialogAndWait(Localization.lang("Error"), Localization.lang("Error while fetching from %0", fetcher + "." + "\n" + fetcherExceptionMessage)); + + if (exception instanceof FetcherClientException) { + dialogService.showInformationDialogAndWait(Localization.lang("Failed to import by ID"), Localization.lang("Bibliographic data not found. Cause is likely the client side. Please check connection and identifier for correctness." + "\n" + fetcherExceptionMessage)); + } else if (exception instanceof FetcherServerException) { + dialogService.showInformationDialogAndWait(Localization.lang("Failed to import by ID"), Localization.lang("Bibliographic data not found. Cause is likely the server side. Please try agan later." + "\n" + fetcherExceptionMessage)); } else { - dialogService.showInformationDialogAndWait(Localization.lang("No files found."), Localization.lang("Fetcher '%0' did not find an entry for id '%1'.", fetcher, searchId) + "\n" + fetcherExceptionMessage); + dialogService.showInformationDialogAndWait(Localization.lang("Failed to import by ID"), Localization.lang("Error message %0", fetcherExceptionMessage)); } + LOGGER.error(String.format("Exception during fetching when using fetcher '%s' with entry id '%s'.", searchId, fetcher), exception); searchingProperty.set(false); @@ -182,7 +188,7 @@ public void runFetcherWorker() { String searchId = idText.getValue(); // When DOI ID is not found, allow the user to either return to the dialog or add entry manually - boolean addEntryFlag = dialogService.showConfirmationDialogAndWait(Localization.lang("DOI not found"), + boolean addEntryFlag = dialogService.showConfirmationDialogAndWait(Localization.lang("Identifier not found"), Localization.lang("Fetcher '%0' did not find an entry for id '%1'.", fetcher, searchId), Localization.lang("Add entry manually"), Localization.lang("Return to dialog")); diff --git a/src/main/java/org/jabref/gui/importer/GenerateEntryFromIdAction.java b/src/main/java/org/jabref/gui/importer/GenerateEntryFromIdAction.java index 0e4012fe854..727723c7f2c 100644 --- a/src/main/java/org/jabref/gui/importer/GenerateEntryFromIdAction.java +++ b/src/main/java/org/jabref/gui/importer/GenerateEntryFromIdAction.java @@ -11,9 +11,10 @@ import org.jabref.gui.externalfiletype.ExternalFileTypes; import org.jabref.gui.util.BackgroundTask; import org.jabref.gui.util.TaskExecutor; -import org.jabref.logic.JabRefException; import org.jabref.logic.importer.CompositeIdFetcher; +import org.jabref.logic.importer.FetcherClientException; import org.jabref.logic.importer.FetcherException; +import org.jabref.logic.importer.FetcherServerException; import org.jabref.logic.l10n.Localization; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.types.StandardEntryType; @@ -47,11 +48,17 @@ public void execute() { backgroundTask.titleProperty().set(Localization.lang("Import by ID")); backgroundTask.showToUser(true); backgroundTask.onRunning(() -> dialogService.notify("%s".formatted(backgroundTask.messageProperty().get()))); - backgroundTask.onFailure((e) -> { - // When unable to import by ID, present the user options to cancel or add entry manually - boolean addEntryFlag = dialogService.showConfirmationDialogAndWait(Localization.lang("Failed to import by ID"), - e.getMessage(), - Localization.lang("Add entry manually")); + backgroundTask.onFailure((exception) -> { + String fetcherExceptionMessage = exception.getMessage(); + + boolean addEntryFlag; + if (exception instanceof FetcherClientException) { + addEntryFlag = dialogService.showConfirmationDialogAndWait(Localization.lang("Failed to import by ID"), Localization.lang("Bibliographic data not found. Cause is likely the client side. Please check connection and identifier for correctness." + "\n" + fetcherExceptionMessage), Localization.lang("Add entry manually")); + } else if (exception instanceof FetcherServerException) { + addEntryFlag = dialogService.showConfirmationDialogAndWait(Localization.lang("Failed to import by ID"), Localization.lang("Bibliographic data not found. Cause is likely the server side. Please try agan later." + "\n" + fetcherExceptionMessage), Localization.lang("Add entry manually")); + } else { + addEntryFlag = dialogService.showConfirmationDialogAndWait(Localization.lang("Failed to import by ID"), Localization.lang("Error message %0", fetcherExceptionMessage), Localization.lang("Add entry manually")); + } if (addEntryFlag) { // add entry manually new NewEntryAction(libraryTab.frame(), StandardEntryType.Article, dialogService, @@ -76,17 +83,12 @@ public void execute() { private BackgroundTask> searchAndImportEntryInBackground() { return new BackgroundTask<>() { @Override - protected Optional call() throws JabRefException { + protected Optional call() throws FetcherException { if (isCanceled()) { return Optional.empty(); } - updateMessage(Localization.lang("Searching...")); - try { - return new CompositeIdFetcher(preferencesService.getImportFormatPreferences()).performSearchById(identifier); - } catch (FetcherException fetcherException) { - throw new JabRefException("Fetcher error: %s".formatted(fetcherException.getMessage())); - } + return new CompositeIdFetcher(preferencesService.getImportFormatPreferences()).performSearchById(identifier); } }; } diff --git a/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java b/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java index 0fc561b0261..e8f9359aa69 100644 --- a/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java +++ b/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java @@ -166,7 +166,7 @@ public void fetchAndMerge(BibEntry entry, EntryBasedFetcher fetcher) { } }) .onFailure(exception -> { - LOGGER.error("Error while fetching entry with " + fetcher.getName(), exception); + LOGGER.error("Error while fetching entry with {} ", fetcher.getName(), exception); dialogService.showErrorDialogAndWait(Localization.lang("Error while fetching from %0", fetcher.getName()), exception); }) .executeWith(taskExecutor); diff --git a/src/main/java/org/jabref/logic/net/URLDownload.java b/src/main/java/org/jabref/logic/net/URLDownload.java index a47ae3055ac..c499dcf3635 100644 --- a/src/main/java/org/jabref/logic/net/URLDownload.java +++ b/src/main/java/org/jabref/logic/net/URLDownload.java @@ -362,10 +362,10 @@ private URLConnection openConnection() throws IOException { connection = new URLDownload(newUrl).openConnection(); } if ((status >= 400) && (status < 500)) { - throw new IOException(new FetcherClientException("Client error. Status code " + status)); + throw new IOException(new FetcherClientException("Encountered HTTP Status code " + status)); } if (status >= 500) { - throw new IOException(new FetcherServerException("Server error. Status Code " + status)); + throw new IOException(new FetcherServerException("Encountered HTTP Status Code " + status)); } } // this does network i/o: GET + read returned headers diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index 8f32390b60f..a5bd14b40cd 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -224,8 +224,6 @@ cut\ entries=cut entries cut\ entry\ %0=cut entry %0 -DOI\ not\ found=DOI not found - Library\ encoding=Library encoding Library\ properties=Library properties @@ -2491,6 +2489,10 @@ No\ data\ was\ found\ for\ the\ identifier=No data was found for the identifier Server\ not\ available=Server not available Fetching\ information\ using\ %0=Fetching information using %0 Look\ up\ identifier=Look up identifier +Bibliographic\ data\ not\ found.\ Cause\ is\ likely\ the\ client\ side.\ Please\ check\ connection\ and\ identifier\ for\ correctness.\n=Bibliographic data not found. Cause is likely the client side. Please check connection and identifier for correctness.\n +Bibliographic\ data\ not\ found.\ Cause\ is\ likely\ the\ server\ side.\ Please\ try\ agan\ later.\n=Bibliographic data not found. Cause is likely the server side. Please try agan later.\n +Error\ message\ %0=Error message %0 +Identifier\ not\ found=Identifier not found Error\ while\ writing\ metadata.\ See\ the\ error\ log\ for\ details.=Error while writing metadata. See the error log for details. Failed\ to\ write\ metadata,\ file\ %1\ not\ found.=Failed to write metadata, file %1 not found. From 4c0ebd1df15acb075427bab7a3e8d28992a04fd9 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Tue, 19 Jul 2022 20:10:10 +0200 Subject: [PATCH 22/27] fix merge conflicts --- .../org/jabref/gui/maintable/MainTable.java | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/jabref/gui/maintable/MainTable.java b/src/main/java/org/jabref/gui/maintable/MainTable.java index dc2a8dd8077..57a6be61548 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTable.java +++ b/src/main/java/org/jabref/gui/maintable/MainTable.java @@ -11,8 +11,8 @@ import javax.swing.undo.UndoManager; -import javafx.collections.ListChangeListener; import javafx.scene.control.SelectionMode; +import javafx.collections.ListChangeListener; import javafx.scene.control.TableColumn; import javafx.scene.control.TableRow; import javafx.scene.control.TableView; @@ -35,17 +35,17 @@ import org.jabref.gui.edit.EditAction; import org.jabref.gui.externalfiles.ImportHandler; import org.jabref.gui.externalfiletype.ExternalFileTypes; -import org.jabref.gui.keyboard.KeyBinding; -import org.jabref.gui.keyboard.KeyBindingRepository; import org.jabref.gui.maintable.columns.LibraryColumn; import org.jabref.gui.maintable.columns.MainTableColumn; -import org.jabref.gui.util.ControlHelper; -import org.jabref.gui.util.CustomLocalDragboard; -import org.jabref.gui.util.DefaultTaskExecutor; import org.jabref.gui.util.ViewModelTableRowFactory; import org.jabref.logic.importer.FetcherClientException; import org.jabref.logic.importer.FetcherException; import org.jabref.logic.importer.FetcherServerException; +import org.jabref.gui.keyboard.KeyBinding; +import org.jabref.gui.keyboard.KeyBindingRepository; +import org.jabref.gui.util.ControlHelper; +import org.jabref.gui.util.CustomLocalDragboard; +import org.jabref.gui.util.DefaultTaskExecutor; import org.jabref.logic.importer.ImportFormatReader; import org.jabref.logic.l10n.Localization; import org.jabref.model.database.BibDatabaseContext; @@ -66,12 +66,10 @@ public class MainTable extends TableView { private final StateManager stateManager; private final BibDatabaseContext database; private final MainTableDataModel model; - private final ClipBoardManager clipBoardManager; - private final ImportFormatReader importFormatReader; private final ImportHandler importHandler; private final CustomLocalDragboard localDragboard; - + private final ClipBoardManager clipBoardManager; private long lastKeyPressTime; private String columnSearchTerm; @@ -93,7 +91,6 @@ public MainTable(MainTableDataModel model, this.database = Objects.requireNonNull(database); this.model = model; this.clipBoardManager = clipBoardManager; - this.importFormatReader = importFormatReader; UndoManager undoManager = libraryTab.getUndoManager(); MainTablePreferences mainTablePreferences = preferencesService.getMainTablePreferences(); @@ -345,6 +342,7 @@ private List handleNonBibteXStringData() { } } return entries; + } public void dropEntry(List entriesToAdd) { for (BibEntry entry : entriesToAdd) { From 0cc48263fe8ae4195fead4bcd78ad287e87a089b Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Tue, 19 Jul 2022 20:27:12 +0200 Subject: [PATCH 23/27] fix l10n messages --- src/main/java/org/jabref/gui/EntryTypeViewModel.java | 4 ++-- .../gui/importer/GenerateEntryFromIdAction.java | 4 ++-- .../java/org/jabref/gui/maintable/MainTable.java | 12 ++++++------ src/main/resources/l10n/JabRef_en.properties | 6 ++++-- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/jabref/gui/EntryTypeViewModel.java b/src/main/java/org/jabref/gui/EntryTypeViewModel.java index 754eac11be2..caa15357f18 100644 --- a/src/main/java/org/jabref/gui/EntryTypeViewModel.java +++ b/src/main/java/org/jabref/gui/EntryTypeViewModel.java @@ -149,9 +149,9 @@ public void runFetcherWorker() { String searchId = idText.getValue(); if (exception instanceof FetcherClientException) { - dialogService.showInformationDialogAndWait(Localization.lang("Failed to import by ID"), Localization.lang("Bibliographic data not found. Cause is likely the client side. Please check connection and identifier for correctness." + "\n" + fetcherExceptionMessage)); + dialogService.showInformationDialogAndWait(Localization.lang("Failed to import by ID"), Localization.lang("Bibliographic data not found. Cause is likely the client side. Please check connection and identifier for correctness.")+ "\n" + fetcherExceptionMessage); } else if (exception instanceof FetcherServerException) { - dialogService.showInformationDialogAndWait(Localization.lang("Failed to import by ID"), Localization.lang("Bibliographic data not found. Cause is likely the server side. Please try agan later." + "\n" + fetcherExceptionMessage)); + dialogService.showInformationDialogAndWait(Localization.lang("Failed to import by ID"), Localization.lang("Bibliographic data not found. Cause is likely the server side. Please try agan later.") + "\n" + fetcherExceptionMessage); } else { dialogService.showInformationDialogAndWait(Localization.lang("Failed to import by ID"), Localization.lang("Error message %0", fetcherExceptionMessage)); } diff --git a/src/main/java/org/jabref/gui/importer/GenerateEntryFromIdAction.java b/src/main/java/org/jabref/gui/importer/GenerateEntryFromIdAction.java index 727723c7f2c..619ec5a8e35 100644 --- a/src/main/java/org/jabref/gui/importer/GenerateEntryFromIdAction.java +++ b/src/main/java/org/jabref/gui/importer/GenerateEntryFromIdAction.java @@ -53,9 +53,9 @@ public void execute() { boolean addEntryFlag; if (exception instanceof FetcherClientException) { - addEntryFlag = dialogService.showConfirmationDialogAndWait(Localization.lang("Failed to import by ID"), Localization.lang("Bibliographic data not found. Cause is likely the client side. Please check connection and identifier for correctness." + "\n" + fetcherExceptionMessage), Localization.lang("Add entry manually")); + addEntryFlag = dialogService.showConfirmationDialogAndWait(Localization.lang("Failed to import by ID"), Localization.lang("Bibliographic data not found. Cause is likely the client side. Please check connection and identifier for correctness.") + "\n" + fetcherExceptionMessage, Localization.lang("Add entry manually")); } else if (exception instanceof FetcherServerException) { - addEntryFlag = dialogService.showConfirmationDialogAndWait(Localization.lang("Failed to import by ID"), Localization.lang("Bibliographic data not found. Cause is likely the server side. Please try agan later." + "\n" + fetcherExceptionMessage), Localization.lang("Add entry manually")); + addEntryFlag = dialogService.showConfirmationDialogAndWait(Localization.lang("Failed to import by ID"), Localization.lang("Bibliographic data not found. Cause is likely the server side. Please try agan later.") + "\n" + fetcherExceptionMessage, Localization.lang("Add entry manually")); } else { addEntryFlag = dialogService.showConfirmationDialogAndWait(Localization.lang("Failed to import by ID"), Localization.lang("Error message %0", fetcherExceptionMessage), Localization.lang("Add entry manually")); } diff --git a/src/main/java/org/jabref/gui/maintable/MainTable.java b/src/main/java/org/jabref/gui/maintable/MainTable.java index 57a6be61548..d37f3bb09c4 100644 --- a/src/main/java/org/jabref/gui/maintable/MainTable.java +++ b/src/main/java/org/jabref/gui/maintable/MainTable.java @@ -11,8 +11,8 @@ import javax.swing.undo.UndoManager; -import javafx.scene.control.SelectionMode; import javafx.collections.ListChangeListener; +import javafx.scene.control.SelectionMode; import javafx.scene.control.TableColumn; import javafx.scene.control.TableRow; import javafx.scene.control.TableView; @@ -35,17 +35,17 @@ import org.jabref.gui.edit.EditAction; import org.jabref.gui.externalfiles.ImportHandler; import org.jabref.gui.externalfiletype.ExternalFileTypes; +import org.jabref.gui.keyboard.KeyBinding; +import org.jabref.gui.keyboard.KeyBindingRepository; import org.jabref.gui.maintable.columns.LibraryColumn; import org.jabref.gui.maintable.columns.MainTableColumn; +import org.jabref.gui.util.ControlHelper; +import org.jabref.gui.util.CustomLocalDragboard; +import org.jabref.gui.util.DefaultTaskExecutor; import org.jabref.gui.util.ViewModelTableRowFactory; import org.jabref.logic.importer.FetcherClientException; import org.jabref.logic.importer.FetcherException; import org.jabref.logic.importer.FetcherServerException; -import org.jabref.gui.keyboard.KeyBinding; -import org.jabref.gui.keyboard.KeyBindingRepository; -import org.jabref.gui.util.ControlHelper; -import org.jabref.gui.util.CustomLocalDragboard; -import org.jabref.gui.util.DefaultTaskExecutor; import org.jabref.logic.importer.ImportFormatReader; import org.jabref.logic.l10n.Localization; import org.jabref.model.database.BibDatabaseContext; diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index a5bd14b40cd..08cfd4bf03c 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -2489,11 +2489,13 @@ No\ data\ was\ found\ for\ the\ identifier=No data was found for the identifier Server\ not\ available=Server not available Fetching\ information\ using\ %0=Fetching information using %0 Look\ up\ identifier=Look up identifier -Bibliographic\ data\ not\ found.\ Cause\ is\ likely\ the\ client\ side.\ Please\ check\ connection\ and\ identifier\ for\ correctness.\n=Bibliographic data not found. Cause is likely the client side. Please check connection and identifier for correctness.\n -Bibliographic\ data\ not\ found.\ Cause\ is\ likely\ the\ server\ side.\ Please\ try\ agan\ later.\n=Bibliographic data not found. Cause is likely the server side. Please try agan later.\n + +Bibliographic\ data\ not\ found.\ Cause\ is\ likely\ the\ client\ side.\ Please\ check\ connection\ and\ identifier\ for\ correctness.=Bibliographic data not found. Cause is likely the client side. Please check connection and identifier for correctness.\n +Bibliographic\ data\ not\ found.\ Cause\ is\ likely\ the\ server\ side.\ Please\ try\ agan\ later.=Bibliographic data not found. Cause is likely the server side. Please try agan later.\n Error\ message\ %0=Error message %0 Identifier\ not\ found=Identifier not found + Error\ while\ writing\ metadata.\ See\ the\ error\ log\ for\ details.=Error while writing metadata. See the error log for details. Failed\ to\ write\ metadata,\ file\ %1\ not\ found.=Failed to write metadata, file %1 not found. Success\!\ Finished\ writing\ metadata.=Success! Finished writing metadata. From 369310eddc18ca35a395bb343ea5e1c8f0eabc13 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Wed, 20 Jul 2022 20:35:12 +0200 Subject: [PATCH 24/27] fix checkstyle and fetcher --- src/main/java/org/jabref/gui/EntryTypeViewModel.java | 2 +- .../org/jabref/logic/importer/fetcher/CrossRefTest.java | 4 +++- .../jabref/logic/importer/fetcher/MedlineFetcherTest.java | 4 +++- .../org/jabref/logic/importer/fetcher/RfcFetcherTest.java | 8 +++++--- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/jabref/gui/EntryTypeViewModel.java b/src/main/java/org/jabref/gui/EntryTypeViewModel.java index caa15357f18..4e18e4d87c0 100644 --- a/src/main/java/org/jabref/gui/EntryTypeViewModel.java +++ b/src/main/java/org/jabref/gui/EntryTypeViewModel.java @@ -149,7 +149,7 @@ public void runFetcherWorker() { String searchId = idText.getValue(); if (exception instanceof FetcherClientException) { - dialogService.showInformationDialogAndWait(Localization.lang("Failed to import by ID"), Localization.lang("Bibliographic data not found. Cause is likely the client side. Please check connection and identifier for correctness.")+ "\n" + fetcherExceptionMessage); + dialogService.showInformationDialogAndWait(Localization.lang("Failed to import by ID"), Localization.lang("Bibliographic data not found. Cause is likely the client side. Please check connection and identifier for correctness.") + "\n" + fetcherExceptionMessage); } else if (exception instanceof FetcherServerException) { dialogService.showInformationDialogAndWait(Localization.lang("Failed to import by ID"), Localization.lang("Bibliographic data not found. Cause is likely the server side. Please try agan later.") + "\n" + fetcherExceptionMessage); } else { diff --git a/src/test/java/org/jabref/logic/importer/fetcher/CrossRefTest.java b/src/test/java/org/jabref/logic/importer/fetcher/CrossRefTest.java index 130206433ec..770290269ac 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/CrossRefTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/CrossRefTest.java @@ -4,6 +4,7 @@ import java.util.Locale; import java.util.Optional; +import org.jabref.logic.importer.FetcherClientException; import org.jabref.logic.importer.FetcherException; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.StandardField; @@ -14,6 +15,7 @@ import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; @FetcherTest public class CrossRefTest { @@ -145,6 +147,6 @@ public void performSearchByEmptyQuery() throws Exception { */ @Test public void testPerformSearchValidReturnNothingDOI() throws FetcherException { - assertEquals(Optional.empty(), fetcher.performSearchById("10.1392/BC1.0")); + assertThrows(FetcherClientException.class, () -> fetcher.performSearchById("10.1392/BC1.0")); } } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/MedlineFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/MedlineFetcherTest.java index c0e35312e49..e4d50f79fda 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/MedlineFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/MedlineFetcherTest.java @@ -4,6 +4,7 @@ import java.util.List; import java.util.Optional; +import org.jabref.logic.importer.FetcherClientException; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.StandardField; import org.jabref.model.entry.field.UnknownField; @@ -14,6 +15,7 @@ import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @FetcherTest @@ -188,7 +190,7 @@ public void testWithLuceneQueryAuthorDateRange() throws Exception { @Test public void testInvalidSearchTerm() throws Exception { - assertEquals(Optional.empty(), fetcher.performSearchById("this.is.a.invalid.search.term.for.the.medline.fetcher")); + assertThrows(FetcherClientException.class, () ->fetcher.performSearchById("this.is.a.invalid.search.term.for.the.medline.fetcher")); } @Test diff --git a/src/test/java/org/jabref/logic/importer/fetcher/RfcFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/RfcFetcherTest.java index 66f36912554..ea04ddca1f4 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/RfcFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/RfcFetcherTest.java @@ -2,6 +2,7 @@ import java.util.Optional; +import org.jabref.logic.importer.FetcherClientException; import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.InternalField; @@ -14,6 +15,7 @@ import org.mockito.Answers; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.mock; @FetcherTest @@ -88,16 +90,16 @@ public void performSearchByIdFindsNothingWithoutIdentifier() throws Exception { @Test public void performSearchByIdFindsNothingWithValidDraftIdentifier() throws Exception { - assertEquals(Optional.empty(), fetcher.performSearchById("draft-test-draft-spec")); + assertThrows(FetcherClientException.class, () -> fetcher.performSearchById("draft-test-draft-spec")); } @Test public void performSearchByIdFindsNothingWithValidIdentifier() throws Exception { - assertEquals(Optional.empty(), fetcher.performSearchById("RFC9999")); + assertThrows(FetcherClientException.class, () -> fetcher.performSearchById("RFC9999")); } @Test public void performSearchByIdFindsNothingWithInvalidIdentifier() throws Exception { - assertEquals(Optional.empty(), fetcher.performSearchById("banana")); + assertThrows(FetcherClientException.class, () -> fetcher.performSearchById("banana")); } } From c47ea2d0ed26b5128fc8657483029bfed1432cd7 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Fri, 5 Aug 2022 19:38:19 +0200 Subject: [PATCH 25/27] improve error messages --- .../IdentifierEditorViewModel.java | 25 +++++++++++-------- .../gui/mergeentries/FetchAndMergeEntry.java | 2 +- .../logic/importer/fetcher/IsbnFetcher.java | 18 ++++++++----- .../CompositeSearchBasedFetcherTest.java | 2 +- .../importer/fetcher/MedlineFetcherTest.java | 2 +- .../fetcher/OpenLibraryFetcherTest.java | 5 ++-- 6 files changed, 32 insertions(+), 22 deletions(-) diff --git a/src/main/java/org/jabref/gui/fieldeditors/IdentifierEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/IdentifierEditorViewModel.java index 8838eed70f4..93990c1a5c7 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/IdentifierEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/IdentifierEditorViewModel.java @@ -126,17 +126,20 @@ public void lookupIdentifier(BibEntry entry) { dialogService.notify(Localization.lang("No %0 found", field.getDisplayName())); } }) - .onFailure(exception -> { - LOGGER.error("Error while fetching bibliographic information", exception); - if (exception instanceof FetcherClientException) { - dialogService.showInformationDialogAndWait(Localization.lang("Look up %0", idFetcher.getName()), Localization.lang("No data was found for the identifier")); - } else if (exception instanceof FetcherServerException) { - dialogService.showInformationDialogAndWait(Localization.lang("Look up %0", idFetcher.getName()), Localization.lang("Server not available")); - } else { - dialogService.showErrorDialogAndWait(exception); - } - }) - .executeWith(taskExecutor); + .onFailure(exception -> { + LOGGER.error("Error while fetching bibliographic information", exception); + if (exception instanceof FetcherClientException) { + dialogService.showInformationDialogAndWait(Localization.lang("Look up %0", idFetcher.getName()), Localization.lang("No data was found for the identifier")); + } else if (exception instanceof FetcherServerException) { + dialogService.showInformationDialogAndWait(Localization.lang("Look up %0", idFetcher.getName()), Localization.lang("Server not available")); + } else if (exception.getCause() != null) { + dialogService.showWarningDialogAndWait(Localization.lang("Look up %0", idFetcher.getName()), Localization.lang("Error occured %0", exception.getCause().getMessage())); + + } else { + dialogService.showWarningDialogAndWait(Localization.lang("Look up %0", idFetcher.getName()), Localization.lang("Error occured %0", exception.getCause().getMessage())); + } + }) + .executeWith(taskExecutor); }); } } diff --git a/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java b/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java index e8f9359aa69..ed7220b532e 100644 --- a/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java +++ b/src/main/java/org/jabref/gui/mergeentries/FetchAndMergeEntry.java @@ -83,7 +83,7 @@ public void fetchAndMerge(BibEntry entry, List fields) { } else if (exception instanceof FetcherServerException) { dialogService.showInformationDialogAndWait(Localization.lang("Fetching information using %0", fetcher.get().getName()), Localization.lang("Server not available")); } else { - dialogService.showErrorDialogAndWait(exception); + dialogService.showInformationDialogAndWait(Localization.lang("Fetching information using %0", fetcher.get().getName()), Localization.lang("Error occured %0", exception.getMessage())); } }) .executeWith(Globals.TASK_EXECUTOR); diff --git a/src/main/java/org/jabref/logic/importer/fetcher/IsbnFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/IsbnFetcher.java index c97184bd36b..f4dedae3e7c 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/IsbnFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/IsbnFetcher.java @@ -50,13 +50,19 @@ public Optional performSearchById(String identifier) throws FetcherExc identifier = NEWLINE_SPACE_PATTERN.matcher(identifier).replaceAll(""); OpenLibraryFetcher openLibraryFetcher = new OpenLibraryFetcher(importFormatPreferences); - Optional bibEntry = openLibraryFetcher.performSearchById(identifier); - // nothing found at OpenLibrary: try ebook.de - if (!bibEntry.isPresent()) { - LOGGER.debug("No entry found at OpenLibrary; trying ebook.de"); - IsbnViaEbookDeFetcher isbnViaEbookDeFetcher = new IsbnViaEbookDeFetcher(importFormatPreferences); - bibEntry = isbnViaEbookDeFetcher.performSearchById(identifier); + Optional bibEntry = Optional.empty(); + try { + bibEntry = openLibraryFetcher.performSearchById(identifier); + } catch (FetcherException ex) { + LOGGER.debug("Got a fetcher exception for IBSN search", ex); + } finally { + // nothing found at OpenLibrary: try ebook.de + if (!bibEntry.isPresent()) { + LOGGER.debug("No entry found at OpenLibrary; trying ebook.de"); + IsbnViaEbookDeFetcher isbnViaEbookDeFetcher = new IsbnViaEbookDeFetcher(importFormatPreferences); + bibEntry = isbnViaEbookDeFetcher.performSearchById(identifier); + } } return bibEntry; diff --git a/src/test/java/org/jabref/logic/importer/fetcher/CompositeSearchBasedFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/CompositeSearchBasedFetcherTest.java index 8d50ea7192b..fe0db637765 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/CompositeSearchBasedFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/CompositeSearchBasedFetcherTest.java @@ -126,7 +126,7 @@ static Stream performSearchParameters() { // Only shift i at maximum to its MSB to the right for (int j = 0; Math.pow(2, j) <= i; j++) { // Add fetcher j to the list if the j-th bit of i is 1 - if ((i >> j) % 2 == 1) { + if (((i >> j) % 2) == 1) { fetchers.add(list.get(j)); } } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/MedlineFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/MedlineFetcherTest.java index e4d50f79fda..ed156ef4c04 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/MedlineFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/MedlineFetcherTest.java @@ -190,7 +190,7 @@ public void testWithLuceneQueryAuthorDateRange() throws Exception { @Test public void testInvalidSearchTerm() throws Exception { - assertThrows(FetcherClientException.class, () ->fetcher.performSearchById("this.is.a.invalid.search.term.for.the.medline.fetcher")); + assertThrows(FetcherClientException.class, () -> fetcher.performSearchById("this.is.a.invalid.search.term.for.the.medline.fetcher")); } @Test diff --git a/src/test/java/org/jabref/logic/importer/fetcher/OpenLibraryFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/OpenLibraryFetcherTest.java index 93b67e37c3c..6161b3b9879 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/OpenLibraryFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/OpenLibraryFetcherTest.java @@ -2,6 +2,7 @@ import java.util.Optional; +import org.jabref.logic.importer.FetcherClientException; import org.jabref.logic.importer.FetcherException; import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.model.entry.BibEntry; @@ -13,6 +14,7 @@ import org.mockito.Answers; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.mock; public class OpenLibraryFetcherTest extends AbstractIsbnFetcherTest { @@ -71,7 +73,6 @@ public void authorsAreCorrectlyFormatted() throws Exception { public void testIsbnNeitherAvailableOnEbookDeNorOrViaOpenLibrary() throws Exception { // In this test, the ISBN needs to be a valid (syntax+checksum) ISBN number // However, the ISBN number must not be assigned to a real book - Optional fetchedEntry = fetcher.performSearchById("9785646216541"); - assertEquals(Optional.empty(), fetchedEntry); + assertThrows(FetcherClientException.class, () -> fetcher.performSearchById("9785646216541")); } } From be9980198eaaa248f93ba36b8088eceef6c169fb Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Fri, 5 Aug 2022 20:25:33 +0200 Subject: [PATCH 26/27] further fixes --- .../gui/fieldeditors/IdentifierEditorViewModel.java | 1 - .../importer/fetcher/IsbnViaEbookDeFetcherTest.java | 7 ++++--- .../logic/importer/fetcher/LibraryOfCongressTest.java | 4 +++- .../org/jabref/logic/importer/fetcher/MedraTest.java | 10 +++++++--- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/jabref/gui/fieldeditors/IdentifierEditorViewModel.java b/src/main/java/org/jabref/gui/fieldeditors/IdentifierEditorViewModel.java index 93990c1a5c7..5d69547367d 100644 --- a/src/main/java/org/jabref/gui/fieldeditors/IdentifierEditorViewModel.java +++ b/src/main/java/org/jabref/gui/fieldeditors/IdentifierEditorViewModel.java @@ -134,7 +134,6 @@ public void lookupIdentifier(BibEntry entry) { dialogService.showInformationDialogAndWait(Localization.lang("Look up %0", idFetcher.getName()), Localization.lang("Server not available")); } else if (exception.getCause() != null) { dialogService.showWarningDialogAndWait(Localization.lang("Look up %0", idFetcher.getName()), Localization.lang("Error occured %0", exception.getCause().getMessage())); - } else { dialogService.showWarningDialogAndWait(Localization.lang("Look up %0", idFetcher.getName()), Localization.lang("Error occured %0", exception.getCause().getMessage())); } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/IsbnViaEbookDeFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/IsbnViaEbookDeFetcherTest.java index bbb2742d208..b00d3523d6d 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/IsbnViaEbookDeFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/IsbnViaEbookDeFetcherTest.java @@ -2,6 +2,7 @@ import java.util.Optional; +import org.jabref.logic.importer.FetcherClientException; import org.jabref.logic.importer.FetcherException; import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.model.entry.BibEntry; @@ -15,6 +16,7 @@ import org.mockito.Answers; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.mock; @FetcherTest @@ -77,11 +79,10 @@ public void authorsAreCorrectlyFormatted() throws Exception { /** * This test searches for a valid ISBN. See https://www.amazon.de/dp/3728128155/?tag=jabref-21 However, this ISBN is - * not available on ebook.de. The fetcher should return nothing rather than throwing an exception. + * not available on ebook.de. */ @Test public void searchForValidButNotFoundISBN() throws Exception { - Optional fetchedEntry = fetcher.performSearchById("3728128155"); - assertEquals(Optional.empty(), fetchedEntry); + assertThrows(FetcherClientException.class, ()-> fetcher.performSearchById("3728128155")); } } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/LibraryOfCongressTest.java b/src/test/java/org/jabref/logic/importer/fetcher/LibraryOfCongressTest.java index b18e2b88ba6..562ded1f3bd 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/LibraryOfCongressTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/LibraryOfCongressTest.java @@ -2,6 +2,7 @@ import java.util.Optional; +import org.jabref.logic.importer.FetcherClientException; import org.jabref.logic.importer.ImportFormatPreferences; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.StandardField; @@ -12,6 +13,7 @@ import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -54,6 +56,6 @@ public void performSearchByEmptyId() throws Exception { @Test public void performSearchByInvalidId() throws Exception { - assertEquals(Optional.empty(), fetcher.performSearchById("xxx")); + assertThrows(FetcherClientException.class, () -> fetcher.performSearchById("xxx")); } } diff --git a/src/test/java/org/jabref/logic/importer/fetcher/MedraTest.java b/src/test/java/org/jabref/logic/importer/fetcher/MedraTest.java index 4f0e2f9814b..3d940312fa1 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/MedraTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/MedraTest.java @@ -3,6 +3,7 @@ import java.util.Optional; import java.util.stream.Stream; +import org.jabref.logic.importer.FetcherClientException; import org.jabref.logic.importer.FetcherException; import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.StandardField; @@ -15,6 +16,7 @@ import org.junit.jupiter.params.provider.MethodSource; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; @FetcherTest public class MedraTest { @@ -23,9 +25,6 @@ public class MedraTest { private static Stream getDoiBibEntryPairs() { return Stream.of( - Arguments.of("10.1016/j.bjoms.2007.08.004", - Optional.empty()), - Arguments.of("10.2143/TVF.80.3.3285690", Optional.of( new BibEntry(StandardEntryType.Article) @@ -82,6 +81,11 @@ public void testPerformSearchEmptyDOI() throws FetcherException { assertEquals(Optional.empty(), fetcher.performSearchById("")); } + @Test + public void testPerformNonExistent() throws FetcherException { + assertThrows(FetcherClientException.class, () -> fetcher.performSearchById("10.1016/j.bjoms.2007.08.004")); + } + @ParameterizedTest @MethodSource("getDoiBibEntryPairs") public void testDoiBibEntryPairs(String identifier, Optional expected) throws FetcherException { From 7c609f3583a8d6a681e449232bad687fc847da13 Mon Sep 17 00:00:00 2001 From: Siedlerchr Date: Sat, 6 Aug 2022 19:48:54 +0200 Subject: [PATCH 27/27] fix l10n --- src/main/resources/l10n/JabRef_en.properties | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index eda1773eb73..4f355612618 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -2490,8 +2490,8 @@ Server\ not\ available=Server not available Fetching\ information\ using\ %0=Fetching information using %0 Look\ up\ identifier=Look up identifier -Bibliographic\ data\ not\ found.\ Cause\ is\ likely\ the\ client\ side.\ Please\ check\ connection\ and\ identifier\ for\ correctness.=Bibliographic data not found. Cause is likely the client side. Please check connection and identifier for correctness.\n -Bibliographic\ data\ not\ found.\ Cause\ is\ likely\ the\ server\ side.\ Please\ try\ agan\ later.=Bibliographic data not found. Cause is likely the server side. Please try agan later.\n +Bibliographic\ data\ not\ found.\ Cause\ is\ likely\ the\ client\ side.\ Please\ check\ connection\ and\ identifier\ for\ correctness.=Bibliographic data not found. Cause is likely the client side. Please check connection and identifier for correctness. +Bibliographic\ data\ not\ found.\ Cause\ is\ likely\ the\ server\ side.\ Please\ try\ agan\ later.=Bibliographic data not found. Cause is likely the server side. Please try agan later. Error\ message\ %0=Error message %0 Identifier\ not\ found=Identifier not found @@ -2526,3 +2526,4 @@ To=To Assign=Assign Do\ not\ assign=Do not assign +Error\ occured\ %0=Error occured %0