Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into test-for-citationstyle
Browse files Browse the repository at this point in the history
* upstream/main:
  Fix right clicking a group and choosing "remove selected entries from this group" leads to error when Bibtex source tab is selected (JabRef#8821)
  Fix single identifier cannot be opened on click (JabRef#8838)
  Add Pubmed/Medline Query Transformer (JabRef#8818)
  adjust and add testcases for FileAnnotationViewModel (JabRef#8830)
  Append config instead of replacing (JabRef#8834)
  Fix eclipse config (JabRef#8835)
  Add Nemo file manager (JabRef#8831)
  Fix missing clear action on pressing esc within the "Filter groups" field (JabRef#8829)
  • Loading branch information
Siedlerchr committed May 22, 2022
2 parents 4e81727 + 7257350 commit 2c2a521
Show file tree
Hide file tree
Showing 15 changed files with 241 additions and 44 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- Writing BibTeX data into a PDF (XMP) removes braces. [#8452](https://github.com/JabRef/jabref/issues/8452)
- Writing BibTeX data into a PDF (XMP) does not write the `file` field.
- Writing BibTeX data into a PDF (XMP) considers the configured keyword separator (and does not use "," as default any more)
- The Medline/Pubmed search now also supports the [default fields and operators for searching](https://docs.jabref.org/collect/import-using-online-bibliographic-database#search-syntax). [forum#3554](https://discourse.jabref.org/t/native-pubmed-search/3354)

### Fixed

Expand All @@ -29,6 +30,8 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We fixed an issue where the notification bar message, icon and actions appeared to be invisible. [#8761](https://github.com/JabRef/jabref/issues/8761)
- We fixed an issue where deprecated fields tab is shown when the fields don't contain any values. [#8396](https://github.com/JabRef/jabref/issues/8396)
- We fixed an issue which allow us to select and open identifiers from a popup list in the maintable [#8758](https://github.com/JabRef/jabref/issues/8758), [8802](https://github.com/JabRef/jabref/issues/8802)
- We fixed an issue where the escape button had no functionality within the "Filter groups" textfield. [koppor#562](https://github.com/koppor/jabref/issues/562)
- We fixed an issue where right clicking a group and choose "remove selected entries from this group" leads to error when Bibtex source tab is selected. [#8012](https://github.com/JabRef/jabref/issues/8012)

### Removed

Expand Down
8 changes: 7 additions & 1 deletion eclipse.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@ eclipse {
}

def javafxcontrols = entries.find { isJavafxControls(it) };
javafxcontrols.entryAttributes['add-exports'] = 'javafx.controls/com.sun.javafx.scene.control=org.jabref:javafx.controls/com.sun.javafx.scene.control.behavior=org.jabref:javafx.controls/javafx.scene.control=org.jabref';
javafxcontrols.entryAttributes['add-exports'] = 'javafx.controls/com.sun.javafx.scene.control=org.jabref:javafx.controls/com.sun.javafx.scene.control.behavior=org.jabref:javafx.controls/javafx.scene.control=org.jabref:javafx.controls/com.sun.javafx.scene.control.behavior=com.jfoenix';
javafxcontrols.entryAttributes['add-opens'] = 'javafx.controls/com.sun.javafx.scene.control=org.jabref:javafx.controls/com.sun.javafx.scene.control.behavior=org.jabref:javafx.controls/javafx.scene.control=org.jabref:javafx.controls/javafx.scene.control.skin=org.controlsfx.controls';

def javafxgraphics = entries.find { isJavafxGraphics(it) };
javafxgraphics.entryAttributes['add-opens'] = 'javafx.graphics/javafx.scene=org.controlsfx.controls';
javafxgraphics.entryAttributes['add-exports'] = 'javafx.graphics/com.sun.javafx.stage=com.jfoenix';

def javafxbase = entries.find { isJavafxBase(it) };
javafxbase.entryAttributes['add-exports'] = 'javafx.base/com.sun.javafx.event=org.controlsfx.controls:';

def javafxfxml = entries.find { isJavafxFXML(it) };
javafxfxml.entryAttributes['add-opens'] = 'javafx.fxml/javafx.fxml=org.jabref';
Expand Down Expand Up @@ -61,6 +65,8 @@ boolean isJavafxControls(entry) { return entry.properties.path.contains('javafx-

boolean isJavafxGraphics(entry) { return entry.properties.path.contains('javafx-graphics'); }

boolean isJavafxBase(entry) { return entry.properties.path.contains('javafx-base'); }

boolean isJavafxFXML(entry) { return entry.properties.path.contains('javafx-fxml'); }

// add formatter and cleanup settings to Eclipse settings
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/jabref/gui/JabRefMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ private static void addLogToDisk() {
"writerFile.level", "info",
"writerFile.file", directory.resolve("log.txt").toString(),
"writerFile.charset", "UTF-8");
Configuration.replace(configuration);

configuration.entrySet().forEach(config -> Configuration.set(config.getKey(), config.getValue()));
initializeLogger();
}

Expand Down
8 changes: 6 additions & 2 deletions src/main/java/org/jabref/gui/desktop/os/Linux.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,13 @@ public void openFolderAndSelectFile(Path filePath) throws IOException {
if (desktopSession != null) {
desktopSession = desktopSession.toLowerCase(Locale.ROOT);
if (desktopSession.contains("gnome")) {
cmd = "nautilus" + filePath.toString().replace(" ", "\\ ");
} else if (desktopSession.contains("kde")) {
cmd = "nautilus --select " + filePath.toString().replace(" ", "\\ ");
} else if (desktopSession.contains("kde") || desktopSession.contains("plasma")) {
cmd = "dolphin --select " + filePath.toString().replace(" ", "\\ ");
} else if (desktopSession.contains("mate")) {
cmd = "caja --select " + filePath.toString().replace(" ", "\\ ");
} else if (desktopSession.contains("cinnamon")) {
cmd = "nemo --select " + filePath.toString().replace(" ", "\\ ");
}
}
Runtime.getRuntime().exec(cmd);
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/jabref/gui/entryeditor/SourceTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,9 @@ private void storeSource(BibEntry outOfFocusEntry, String text) {
new FieldWriter(fieldWriterPreferences).write(fieldName, newValue);

compound.addEdit(new UndoableFieldChange(outOfFocusEntry, fieldName, oldValue, newValue));
outOfFocusEntry.setField(fieldName, newValue);
if (outOfFocusEntry.getField(fieldName).isPresent()) {
outOfFocusEntry.setField(fieldName, newValue);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import javafx.beans.property.StringProperty;

import org.jabref.logic.formatter.bibtexfields.RemoveHyphenatedNewlinesFormatter;
import org.jabref.logic.formatter.bibtexfields.RemoveNewlinesFormatter;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.pdf.FileAnnotation;
import org.jabref.model.pdf.FileAnnotationType;
Expand Down Expand Up @@ -33,22 +32,23 @@ private void setupContentProperties(FileAnnotation annotation) {
String annotationContent = annotation.getContent();
String illegibleTextMessage = Localization.lang("The marked area does not contain any legible text!");
String markingContent = (annotationContent.isEmpty() ? illegibleTextMessage : annotationContent);
// remove newlines && hyphens before linebreaks
markingContent = markingContent.replaceAll("-" + NEWLINE, "");
new RemoveHyphenatedNewlinesFormatter().format(markingContent);
// remove new lines not preceded by '.' or ':'
markingContent = markingContent.replaceAll("(?<![.|:])" + NEWLINE, " ");
this.marking.set(markingContent);
this.marking.set(removePunctuationMark(markingContent));
} else {
String content = annotation.getContent();
// remove newlines && hyphens before linebreaks
content = new RemoveHyphenatedNewlinesFormatter().format(content);
content = new RemoveNewlinesFormatter().format(content);
this.content.set(content);
this.content.set(removePunctuationMark(content));
this.marking.set("");
}
}

public String removePunctuationMark(String content) {
// remove newlines && hyphens before linebreaks
content = content.replaceAll("-" + NEWLINE, "");
content = new RemoveHyphenatedNewlinesFormatter().format(content);
// remove new lines not preceded by '.' or ':'
content = content.replaceAll("(?<![.|:])" + NEWLINE, " ");
return content;
}

public String getAuthor() {
return author.get();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ public static void call(Scene scene, KeyEvent event) {
focusedTextField.positionCaret(res.caretPosition);
event.consume();
}
case CLOSE -> {
focusedTextField.clear();
event.consume();
}
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ public LinkedIdentifierColumn(MainTableColumnModel model,
.withTooltip(this::createIdentifierTooltip)
.withMenu(this::createIdentifierMenu)
.withOnMouseClickedEvent((entry, linkedFiles) -> event -> {
if ((event.getButton() == MouseButton.SECONDARY)) {
new OpenUrlAction(dialogService, stateManager, preferences).execute();
// If we only have one identifer, open directly
if ((linkedFiles.size() == 1) && (event.getButton() == MouseButton.PRIMARY)) {
new OpenUrlAction(dialogService, stateManager, preferences).execute();
}
})
.install(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.jabref.logic.importer.Parser;
import org.jabref.logic.importer.ParserResult;
import org.jabref.logic.importer.SearchBasedFetcher;
import org.jabref.logic.importer.fetcher.transformers.DefaultQueryTransformer;
import org.jabref.logic.importer.fetcher.transformers.MedlineQueryTransformer;
import org.jabref.logic.importer.fileformat.MedlineImporter;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.entry.BibEntry;
Expand All @@ -54,16 +54,6 @@ public class MedlineFetcher implements IdBasedParserFetcher, SearchBasedFetcher

private int numberOfResultsFound;

/**
* Replaces all commas in a given string with " AND "
*
* @param query input to remove commas
* @return input without commas
*/
private static String replaceCommaWithAND(String query) {
return query.replaceAll(", ", " AND ").replaceAll(",", " AND ");
}

/**
* When using 'esearch.fcgi?db=&lt;database>&term=&lt;query>' we will get a list of IDs matching the query.
* Input: Any text query (&term)
Expand Down Expand Up @@ -164,7 +154,7 @@ private URL createSearchUrl(String query) throws URISyntaxException, MalformedUR
uriBuilder.addParameter("db", "pubmed");
uriBuilder.addParameter("sort", "relevance");
uriBuilder.addParameter("retmax", String.valueOf(NUMBER_TO_FETCH));
uriBuilder.addParameter("term", replaceCommaWithAND(query));
uriBuilder.addParameter("term", query); // already lucene query
return uriBuilder.build().toURL();
}

Expand Down Expand Up @@ -200,7 +190,7 @@ private List<BibEntry> fetchMedline(List<String> ids) throws FetcherException {
@Override
public List<BibEntry> performSearch(QueryNode luceneQuery) throws FetcherException {
List<BibEntry> entryList;
DefaultQueryTransformer transformer = new DefaultQueryTransformer();
MedlineQueryTransformer transformer = new MedlineQueryTransformer();
Optional<String> transformedQuery = transformer.transformLuceneQuery(luceneQuery);

if (transformedQuery.isEmpty() || transformedQuery.get().isBlank()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package org.jabref.logic.importer.fetcher.transformers;

/**
*
* Medline/Pubmed specific transformer which uses suffixes for searches
* see <a href="https://pubmed.ncbi.nlm.nih.gov/help/#search-tags">Pubmed help</a> for details
*
*/
public class MedlineQueryTransformer extends AbstractQueryTransformer {

@Override
protected String getLogicalAndOperator() {
return " AND ";
}

@Override
protected String getLogicalOrOperator() {
return " OR ";
}

@Override
protected String getLogicalNotOperator() {
return "NOT ";
}

@Override
protected String handleAuthor(String author) {
return author + "[au]";
}

@Override
protected String handleTitle(String title) {
return title + "[ti]";
}

@Override
protected String handleJournal(String journalTitle) {
return journalTitle + "[ta]";
}

@Override
protected String handleYear(String year) {
return year + "[dp]";
}

@Override
protected String handleYearRange(String yearRange) {
parseYearRange(yearRange);
if (endYear == Integer.MAX_VALUE) {
return yearRange;
}
return Integer.toString(startYear) + ":" + Integer.toString(endYear) + "[dp]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
public class FileAnnotationViewModelTest {

private FileAnnotationViewModel annotationViewModel;
private FileAnnotationViewModel annotationViewModelWithoutFileAnnotation;

@BeforeEach
void setup() {
Expand All @@ -24,8 +25,9 @@ void setup() {

FileAnnotation linkedFileAnnotation = new FileAnnotation("John", LocalDateTime.now(), 3, content, FileAnnotationType.FREETEXT, Optional.empty());
FileAnnotation annotation = new FileAnnotation("Jaroslav Kucha ˇr", LocalDateTime.parse("2017-07-20T10:11:30"), 1, marking, FileAnnotationType.HIGHLIGHT, Optional.of(linkedFileAnnotation));

FileAnnotation annotationWithoutFileAnnotation = new FileAnnotation("Jaroslav Kucha ˇr", LocalDateTime.parse("2017-07-20T10:11:30"), 1, marking, FileAnnotationType.HIGHLIGHT, Optional.empty());
annotationViewModel = new FileAnnotationViewModel(annotation);
annotationViewModelWithoutFileAnnotation = new FileAnnotationViewModel(annotationWithoutFileAnnotation);
}

@Test
Expand All @@ -48,6 +50,15 @@ public void retrieveCorrectContent() {
assertEquals("This is content", annotationViewModel.getContent());
}

@Test
public void retrieveCorrectContentWithoutLinkedFileAnnotation() {
String expectedMarking = String.format("This is paragraph 1.%n" +
"This is paragraph 2, and it crosses several lines, now you can see next paragraph:%n"
+ "This is paragraph 3.");

assertEquals(expectedMarking, annotationViewModelWithoutFileAnnotation.getContent());
}

@Test
public void removeOnlyLineBreaksNotPrecededByPeriodOrColon() {
String expectedMarking = String.format("This is paragraph 1.%n" +
Expand All @@ -56,4 +67,9 @@ public void removeOnlyLineBreaksNotPrecededByPeriodOrColon() {

assertEquals(expectedMarking, annotationViewModel.getMarking());
}

@Test
public void retrieveCorrectMarkingWithoutLinkedFileAnnotation() {
assertEquals("", annotationViewModelWithoutFileAnnotation.getMarking());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,20 @@ public void testMultipleEntries() throws Exception {
assertEquals(50, entryList.size());
}

@Test
public void testWithLuceneQueryAuthorDate() throws Exception {
List<BibEntry> entryList = fetcher.performSearch("author:vigmond AND year:2021");
entryList.forEach(entry -> entry.clearField(StandardField.ABSTRACT)); // Remove abstract due to copyright);
assertEquals(18, entryList.size());
}

@Test
public void testWithLuceneQueryAuthorDateRange() throws Exception {
List<BibEntry> entryList = fetcher.performSearch("author:vigmond AND year-range:2020-2021");
entryList.forEach(entry -> entry.clearField(StandardField.ABSTRACT)); // Remove abstract due to copyright);
assertEquals(28, entryList.size());
}

@Test
public void testInvalidSearchTerm() throws Exception {
assertEquals(Optional.empty(), fetcher.performSearchById("this.is.a.invalid.search.term.for.the.medline.fetcher"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public String getTitlePrefix() {
}

@Override
public void convertJournalField() throws Exception {
public void convertJournalFieldPrefix() throws Exception {
IEEEQueryTransformer transformer = getTransformer();

String queryString = "journal:Nature";
Expand Down
Loading

0 comments on commit 2c2a521

Please sign in to comment.