Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor of DOI import failure dialog, import format reader and clipboard manager #8839

Merged
merged 37 commits into from
Aug 6, 2022
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
02481fa
Rename cleanup actions: "Make LaTeX ready" and "Make BibTeX ready"
zkl-ai Apr 30, 2022
07345ea
modify dio exception handler
zkl-ai May 22, 2022
f786412
Merge branch 'JabRef:main' into improve-DOI-import-failure-dialog
zkl-ai May 22, 2022
f06021a
modify dio exception handler change dialog from "No DOI data exits" t…
zkl-ai May 22, 2022
2348a34
Merge remote-tracking branch 'origin/improve-DOI-import-failure-dialo…
zkl-ai May 22, 2022
d32eae2
modify Localization.lang(message)
zkl-ai May 22, 2022
987d5df
Merge branch 'JabRef:main' into improve-DOI-import-failure-dialog
zkl-ai May 22, 2022
a6ec469
modify Localization.lang("Client Error") and
zkl-ai May 22, 2022
b3ac167
pass LocalizationConsistencyTest
zkl-ai May 22, 2022
6bf38c4
pass fetcher test
zkl-ai May 22, 2022
58361cb
Merge branch 'JabRef:main' into improve-DOI-import-failure-dialog
zkl-ai May 24, 2022
8e5b82a
improve the implementation with two add Exception DOIDataNotFoundExce…
zkl-ai May 24, 2022
d406d5a
Merge remote-tracking branch 'origin/improve-DOI-import-failure-dialo…
zkl-ai May 24, 2022
38f3e52
improve the implementation with two add Exception DOIDataNotFoundExce…
zkl-ai May 24, 2022
6b7dfa9
Merge remote-tracking branch 'upstream/main' into improve-DOI-import-…
Siedlerchr Jul 14, 2022
2561d32
Add FetcherClientException and FetcherServerException
Siedlerchr Jul 14, 2022
a02f5d4
rename test
Siedlerchr Jul 14, 2022
5dfdc8e
refactor impor format reader and clipboard manager
Siedlerchr Jul 14, 2022
3c0ee30
Merge remote-tracking branch 'upstream/main' into improve-DOI-import-…
Siedlerchr Jul 15, 2022
9ed8131
Refactor clipboard manager
Siedlerchr Jul 15, 2022
890e623
remove unused prefs
Siedlerchr Jul 15, 2022
c6deb0c
revert style changes
Siedlerchr Jul 15, 2022
4b0aeb2
fix checkstlye
Siedlerchr Jul 15, 2022
a03e25f
do not throw 404 errors from UrlDownload
Siedlerchr Jul 16, 2022
32fd370
better error messages
Siedlerchr Jul 16, 2022
a9c4589
checkstyle
Siedlerchr Jul 16, 2022
0165d14
Merge remote-tracking branch 'upstream/main' into improve-DOI-import-…
Siedlerchr Jul 18, 2022
73a88b7
improve dialog messages
Siedlerchr Jul 18, 2022
5060e34
change l10n
Siedlerchr Jul 19, 2022
b8a83ac
Merge remote-tracking branch 'upstream/main' into improve-DOI-import-…
Siedlerchr Jul 19, 2022
4c0ebd1
fix merge conflicts
Siedlerchr Jul 19, 2022
0cc4826
fix l10n messages
Siedlerchr Jul 19, 2022
369310e
fix checkstyle and fetcher
Siedlerchr Jul 20, 2022
d26e288
Merge remote-tracking branch 'upstream/main' into improve-DOI-import-…
Siedlerchr Aug 5, 2022
c47ea2d
improve error messages
Siedlerchr Aug 5, 2022
be99801
further fixes
Siedlerchr Aug 5, 2022
7c609f3
fix l10n
Siedlerchr Aug 6, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -76,7 +78,16 @@ public void fetchAndMerge(BibEntry entry, List<Field> fields) {
})
.onFailure(exception -> {
LOGGER.error("Error while fetching bibliographic information", exception);
dialogService.showErrorDialogAndWait(exception);
// client error
if (exception instanceof DOIDataNotFoundException) {
Siedlerchr marked this conversation as resolved.
Show resolved Hide resolved
dialogService.showInformationDialogAndWait(Localization.lang("Lookup DOI"), Localization.lang("No DOI data was found"));
// server error
} else if (exception instanceof DOIServerNotAvailableException) {
dialogService.showInformationDialogAndWait(Localization.lang("Lookup DOI"), Localization.lang("DOI server not available"));
// default error
} else {
dialogService.showErrorDialogAndWait(exception);
}
})
.executeWith(Globals.TASK_EXECUTOR);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
11 changes: 9 additions & 2 deletions src/main/java/org/jabref/logic/importer/fetcher/DoiFetcher.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -11,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;
Expand Down Expand Up @@ -72,7 +75,6 @@ public Optional<BibEntry> 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);
Expand All @@ -81,7 +83,12 @@ public Optional<BibEntry> 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 DOIDataNotFoundException(Localization.lang("Client Error"), e);
} else {
Siedlerchr marked this conversation as resolved.
Show resolved Hide resolved
throw new DOIServerNotAvailableException(Localization.lang("Server Error"), e);
}
}

// BibTeX entry
Expand Down
8 changes: 6 additions & 2 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
koppor marked this conversation as resolved.
Show resolved Hide resolved

not=not

not\ found=not found
Expand Down Expand Up @@ -2487,3 +2485,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=Client Error
Siedlerchr marked this conversation as resolved.
Show resolved Hide resolved
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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -117,6 +118,18 @@ public void testPerformSearchInvalidDOI() {
assertThrows(FetcherException.class, () -> fetcher.performSearchById("10.1002/9781118257517F"));
}

// test invalid DOI client error message "Client Error"
@Test
public void testPerformSearchInvalidDOIClientErrorMessage1() {
Siedlerchr marked this conversation as resolved.
Show resolved Hide resolved
assertThrows(DOIDataNotFoundException.class, () -> fetcher.performSearchById("10.1002/9781118257517F"));
}

// test invalid DOI client error message "Client Error"
Siedlerchr marked this conversation as resolved.
Show resolved Hide resolved
@Test
public void testPerformSearchInvalidDOIClientErrorMessage2() {
Siedlerchr marked this conversation as resolved.
Show resolved Hide resolved
assertThrows(DOIDataNotFoundException.class, () -> fetcher.performSearchById("10.1002/9781517F"));
}

@Test
public void testPerformSearchNonTrimmedDOI() throws FetcherException {
Optional<BibEntry> fetchedEntry = fetcher.performSearchById("http s://doi.org/ 10.1109 /ICWS .2007.59 ");
Expand Down