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

Check if value is already a Short DOI #10612

Merged
merged 3 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv
- We moved the location of the 'Open only one instance of JabRef' preference option from "Network" to "General". [#9306](https://github.com/JabRef/jabref/issues/9306)
- The two previews in the change resolver dialog now have their scrollbars synchronized. [#9576](https://github.com/JabRef/jabref/issues/9576).
- We changed the setting of the keyword separator to accept a single character only. [#177](https://github.com/koppor/jabref/issues/177)
- Short DOI formatter now checks, if the value is already formatted. If so, it returns the value instead of calling the ShortDOIService again. [#10589](https://github.com/JabRef/jabref/issues/10589)

### Fixed

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.jabref.logic.formatter.bibtexfields;

import java.util.Objects;
import java.util.function.Predicate;
import java.util.regex.Pattern;

import org.jabref.logic.cleanup.Formatter;
import org.jabref.logic.importer.util.ShortDOIService;
Expand All @@ -14,6 +16,7 @@
public class ShortenDOIFormatter extends Formatter {

private static final Logger LOGGER = LoggerFactory.getLogger(ShortenDOIFormatter.class);
private static final Predicate<String> SHORT_DOI_FORMAT = Pattern.compile("^10/[a-zA-Z0-9]+$").asPredicate();

@Override
public String getName() {
Expand All @@ -28,7 +31,7 @@ public String getKey() {
@Override
public String format(String value) {
Objects.requireNonNull(value);
return DOI.parse(value)
return SHORT_DOI_FORMAT.test(value) ? value : DOI.parse(value)
.map(doi -> {
try {
return new ShortDOIService().getShortDOI(doi).getDOI();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,9 @@ public void formatDoi() {
public void invalidDoiIsKept() {
assertEquals("invalid-doi", formatter.format("invalid-doi"));
}

@Test
public void shortDoi() {
assertEquals("10/adc", formatter.format("10/adc"));
}
}
Loading