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

Fixed ZBMathTest and extracted keyWordSeparator #9485

Merged
merged 4 commits into from
Dec 20, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ private String computeIDForQuery(String query) {
* @param crawlResults The results that shall be persisted.
*/
private void persistResults(List<QueryResult> crawlResults) throws IOException, SaveException {
DatabaseMerger merger = new DatabaseMerger(importFormatPreferences.getKeywordSeparator());
DatabaseMerger merger = new DatabaseMerger(importFormatPreferences.bibEntryPreferences().getKeywordSeparator());
BibDatabase newStudyResultEntries = new BibDatabase();

for (QueryResult result : crawlResults) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,71 +1,17 @@
package org.jabref.logic.importer;

import javafx.beans.property.ReadOnlyObjectProperty;
import javafx.beans.property.SimpleObjectProperty;

import org.jabref.logic.bibtex.FieldContentFormatterPreferences;
import org.jabref.logic.citationkeypattern.CitationKeyPatternPreferences;
import org.jabref.logic.importer.fetcher.GrobidPreferences;
import org.jabref.logic.preferences.DOIPreferences;
import org.jabref.logic.xmp.XmpPreferences;
import org.jabref.preferences.BibEntryPreferences;

public class ImportFormatPreferences {

private final ReadOnlyObjectProperty<BibEntryPreferences> bibEntryPreferences;
private final CitationKeyPatternPreferences citationKeyPatternPreferences;
private final FieldContentFormatterPreferences fieldContentFormatterPreferences;
private final XmpPreferences xmpPreferences;
private final DOIPreferences doiPreferences;
private final GrobidPreferences grobidPreferences;

public ImportFormatPreferences(BibEntryPreferences bibEntryPreferences,
CitationKeyPatternPreferences citationKeyPatternPreferences,
FieldContentFormatterPreferences fieldContentFormatterPreferences,
XmpPreferences xmpPreferences,
DOIPreferences doiPreferences,
GrobidPreferences grobidPreferences) {
this.bibEntryPreferences = new SimpleObjectProperty<>(bibEntryPreferences);
this.citationKeyPatternPreferences = citationKeyPatternPreferences;
this.fieldContentFormatterPreferences = fieldContentFormatterPreferences;
this.xmpPreferences = xmpPreferences;
this.doiPreferences = doiPreferences;
this.grobidPreferences = grobidPreferences;
}

public DOIPreferences getDoiPreferences() {
return doiPreferences;
}

public ReadOnlyObjectProperty<BibEntryPreferences> bibEntryPreferencesProperty() {
return bibEntryPreferences;
}

public BibEntryPreferences getBibEntryPreferences() {
return bibEntryPreferences.getValue();
}

/**
* @deprecated use {@link BibEntryPreferences#getKeywordSeparator} instead.
*/
@Deprecated
public Character getKeywordSeparator() {
return bibEntryPreferencesProperty().getValue().getKeywordSeparator();
}

public CitationKeyPatternPreferences getCitationKeyPatternPreferences() {
return citationKeyPatternPreferences;
}

public FieldContentFormatterPreferences getFieldContentFormatterPreferences() {
return fieldContentFormatterPreferences;
}

public XmpPreferences getXmpPreferences() {
return xmpPreferences;
}

public GrobidPreferences getGrobidPreferences() {
return grobidPreferences;
}
public record ImportFormatPreferences(
BibEntryPreferences bibEntryPreferences,
CitationKeyPatternPreferences citationKeyPatternPreferences,
FieldContentFormatterPreferences fieldContentFormatterPreferences,
XmpPreferences xmpPreferences,
DOIPreferences doiPreferences,
GrobidPreferences grobidPreferences) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ public void resetImportFormats(ImporterPreferences importerPreferences,
formats.add(new PdfVerbatimBibTextImporter(importFormatPreferences));
formats.add(new PdfContentImporter(importFormatPreferences));
formats.add(new PdfEmbeddedBibFileImporter(importFormatPreferences));
if (importFormatPreferences.getGrobidPreferences().isGrobidEnabled()) {
if (importFormatPreferences.grobidPreferences().isGrobidEnabled()) {
formats.add(new PdfGrobidImporter(importFormatPreferences));
}
formats.add(new PdfXmpImporter(importFormatPreferences.getXmpPreferences()));
formats.add(new PdfXmpImporter(importFormatPreferences.xmpPreferences()));
formats.add(new RepecNepImporter(importFormatPreferences));
formats.add(new RisImporter());
formats.add(new SilverPlatterImporter());
Expand Down
7 changes: 1 addition & 6 deletions src/main/java/org/jabref/logic/importer/OpenDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,8 @@
import org.jabref.migrations.SpecialFieldsToSeparateFields;
import org.jabref.model.util.FileUpdateMonitor;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class OpenDatabase {

private static final Logger LOGGER = LoggerFactory.getLogger(OpenDatabase.class);

private OpenDatabase() {
}

Expand All @@ -32,7 +27,7 @@ public static ParserResult loadDatabase(Path fileToOpen, ImportFormatPreferences
throws IOException {
ParserResult result = new BibtexImporter(importFormatPreferences, fileMonitor).importDatabase(fileToOpen);

performLoadDatabaseMigrations(result, importFormatPreferences.getKeywordSeparator());
performLoadDatabaseMigrations(result, importFormatPreferences.bibEntryPreferences().getKeywordSeparator());

return result;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/logic/importer/WebFetchers.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public static Set<FulltextFetcher> getFullTextFetchers(ImportFormatPreferences i
Set<FulltextFetcher> fetchers = new HashSet<>();

// Original
fetchers.add(new DoiResolution(importFormatPreferences.getDoiPreferences()));
fetchers.add(new DoiResolution(importFormatPreferences.doiPreferences()));

// Publishers
fetchers.add(new ScienceDirect(importerPreferences));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,10 @@ private void adaptKeywordsFrom(BibEntry bibEntry) {
allKeywords = Optional.of(allKeywords.get().replaceAll(entry.getKey(), entry.getValue()));
}

String filteredKeywords = KeywordList.merge(allKeywords.get(), "", importFormatPreferences.getKeywordSeparator()).toString();
String filteredKeywords = KeywordList.merge(
allKeywords.get(),
"",
importFormatPreferences.bibEntryPreferences().getKeywordSeparator()).toString();
bibEntry.setField(StandardField.KEYWORDS, filteredKeywords);
}
}
Expand Down Expand Up @@ -596,9 +599,10 @@ public Optional<HelpFile> getHelpPage() {
public Page<BibEntry> performSearchPaged(QueryNode luceneQuery, int pageNumber) throws FetcherException {
ArXivQueryTransformer transformer = new ArXivQueryTransformer();
String transformedQuery = transformer.transformLuceneQuery(luceneQuery).orElse("");
List<BibEntry> searchResult = searchForEntries(transformedQuery, pageNumber).stream()
.map((arXivEntry) -> arXivEntry.toBibEntry(importFormatPreferences.getKeywordSeparator()))
.collect(Collectors.toList());
List<BibEntry> searchResult = searchForEntries(transformedQuery, pageNumber)
.stream()
.map((arXivEntry) -> arXivEntry.toBibEntry(importFormatPreferences.bibEntryPreferences().getKeywordSeparator()))
.collect(Collectors.toList());
return new Page<>(transformedQuery, pageNumber, filterYears(searchResult, transformer));
}

Expand All @@ -624,7 +628,7 @@ protected CompletableFuture<Optional<BibEntry>> asyncPerformSearchById(String id
@Override
public Optional<BibEntry> performSearchById(String identifier) throws FetcherException {
return searchForEntryById(identifier)
.map((arXivEntry) -> arXivEntry.toBibEntry(importFormatPreferences.getKeywordSeparator()));
.map((arXivEntry) -> arXivEntry.toBibEntry(importFormatPreferences.bibEntryPreferences().getKeywordSeparator()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public Parser getParser() {
JSONArray results = jsonObject.getJSONArray("results");
for (int i = 0; i < results.length(); i++) {
JSONObject bibJsonEntry = results.getJSONObject(i).getJSONObject("bibjson");
BibEntry entry = parseBibJSONtoBibtex(bibJsonEntry, preferences.getKeywordSeparator());
BibEntry entry = parseBibJSONtoBibtex(bibJsonEntry, preferences.bibEntryPreferences().getKeywordSeparator());
entries.add(entry);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/logic/importer/fetcher/IEEE.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public Parser getParser() {
JSONArray results = jsonObject.getJSONArray("articles");
for (int i = 0; i < results.length(); i++) {
JSONObject jsonEntry = results.getJSONObject(i);
BibEntry entry = parseJsonResponse(jsonEntry, importFormatPreferences.getKeywordSeparator());
BibEntry entry = parseJsonResponse(jsonEntry, importFormatPreferences.bibEntryPreferences().getKeywordSeparator());
boolean addEntry;
// In case entry has no year, add it
// In case an entry has a year, check if its in the year range
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public class BibtexParser implements Parser {

public BibtexParser(ImportFormatPreferences importFormatPreferences, FileUpdateMonitor fileMonitor) {
this.importFormatPreferences = Objects.requireNonNull(importFormatPreferences);
fieldContentFormatter = new FieldContentFormatter(importFormatPreferences.getFieldContentFormatterPreferences());
fieldContentFormatter = new FieldContentFormatter(importFormatPreferences.fieldContentFormatterPreferences());
metaDataParser = new MetaDataParser(fileMonitor);
}

Expand Down Expand Up @@ -228,7 +228,7 @@ private ParserResult parseFileContent() throws IOException {

// Instantiate meta data
try {
parserResult.setMetaData(metaDataParser.parse(meta, importFormatPreferences.getBibEntryPreferences().getKeywordSeparator()));
parserResult.setMetaData(metaDataParser.parse(meta, importFormatPreferences.bibEntryPreferences().getKeywordSeparator()));
} catch (ParseException exception) {
parserResult.addException(exception);
}
Expand Down Expand Up @@ -611,7 +611,7 @@ private void parseField(BibEntry entry) throws IOException {
entry.setField(field, entry.getField(field).get() + " and " + content);
} else if (StandardField.KEYWORDS.equals(field)) {
// multiple keywords fields should be combined to one
entry.addKeyword(content, importFormatPreferences.getBibEntryPreferences().getKeywordSeparator());
entry.addKeyword(content, importFormatPreferences.bibEntryPreferences().getKeywordSeparator());
}
} else {
entry.setField(field, content);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.jabref.logic.importer.fileformat.endnote.Dates;
import org.jabref.logic.importer.fileformat.endnote.ElectronicResourceNum;
import org.jabref.logic.importer.fileformat.endnote.Isbn;
import org.jabref.logic.importer.fileformat.endnote.Keyword;
import org.jabref.logic.importer.fileformat.endnote.Keywords;
import org.jabref.logic.importer.fileformat.endnote.Label;
import org.jabref.logic.importer.fileformat.endnote.Notes;
Expand Down Expand Up @@ -212,7 +213,7 @@ private BibEntry parseRecord(Record endNoteRecord) {
.ifPresent(value -> entry.setField(StandardField.NOTE, value.trim()));
getUrl(endNoteRecord)
.ifPresent(value -> entry.setField(StandardField.URL, value));
entry.putKeywords(getKeywords(endNoteRecord), preferences.getKeywordSeparator());
entry.putKeywords(getKeywords(endNoteRecord), preferences.bibEntryPreferences().getKeywordSeparator());
Optional.ofNullable(endNoteRecord.getAbstract())
.map(Abstract::getStyle)
.map(Style::getContent)
Expand Down Expand Up @@ -307,9 +308,9 @@ private List<String> getKeywords(Record endNoteRecord) {
if (keywords != null) {
return keywords.getKeyword()
.stream()
.map(keyword -> keyword.getStyle())
.map(Keyword::getStyle)
.filter(Objects::nonNull)
.map(style -> style.getContent())
.map(Style::getContent)
.collect(Collectors.toList());
} else {
return Collections.emptyList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public class ModsImporter extends Importer implements Parser {
private JAXBContext context;

public ModsImporter(ImportFormatPreferences importFormatPreferences) {
keywordSeparator = importFormatPreferences.getKeywordSeparator() + " ";
keywordSeparator = importFormatPreferences.bibEntryPreferences().getKeywordSeparator() + " ";
}

@Override
Expand Down Expand Up @@ -179,7 +179,7 @@ private void parseModsGroup(Map<Field, String> fields, List<Object> modsGroup, B
nameDefinition.ifPresent(name -> handleAuthorsInNamePart(name, authors, fields));

originInfoDefinition.ifPresent(originInfo -> originInfo
.getPlaceOrPublisherOrDateIssued().stream()
.getPlaceOrPublisherOrDateIssued()
.forEach(element -> putPlaceOrPublisherOrDate(fields, element.getName().getLocalPart(),
element.getValue())));

Expand Down Expand Up @@ -229,7 +229,7 @@ private void parseTitle(Map<Field, String> fields, List<Object> titleOrSubTitleO

private void parseIdentifier(Map<Field, String> fields, IdentifierDefinition identifier, BibEntry entry) {
String type = identifier.getType();
if ("citekey".equals(type) && !entry.getCitationKey().isPresent()) {
if ("citekey".equals(type) && entry.getCitationKey().isEmpty()) {
entry.setCitationKey(identifier.getValue());
} else if (!"local".equals(type) && !"citekey".equals(type)) {
// put all identifiers (doi, issn, isbn,...) except of local and citekey
Expand Down Expand Up @@ -381,8 +381,8 @@ private void putPlaceOrPublisherOrDate(Map<Field, String> fields, String element

List<String> places = new ArrayList<>();
placeDefinition
.ifPresent(place -> place.getPlaceTerm().stream().filter(placeTerm -> placeTerm.getValue() != null)
.map(PlaceTermDefinition::getValue).forEach(element -> places.add(element)));
.ifPresent(place -> place.getPlaceTerm().stream().map(PlaceTermDefinition::getValue)
.filter(Objects::nonNull).forEach(places::add));
putIfListIsNotEmpty(fields, places, StandardField.ADDRESS, ", ");

dateDefinition.ifPresent(date -> putDate(fields, elementName, date));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class PdfGrobidImporter extends Importer {
private final ImportFormatPreferences importFormatPreferences;

public PdfGrobidImporter(ImportFormatPreferences importFormatPreferences) {
this.grobidService = new GrobidService(importFormatPreferences.getGrobidPreferences());
this.grobidService = new GrobidService(importFormatPreferences.grobidPreferences());
this.importFormatPreferences = importFormatPreferences;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ public PdfMergeMetadataImporter(ImportFormatPreferences importFormatPreferences)
this.metadataImporters = new ArrayList<>();
this.metadataImporters.add(new PdfVerbatimBibTextImporter(importFormatPreferences));
this.metadataImporters.add(new PdfEmbeddedBibFileImporter(importFormatPreferences));
if (importFormatPreferences.getGrobidPreferences().isGrobidEnabled()) {
if (importFormatPreferences.grobidPreferences().isGrobidEnabled()) {
this.metadataImporters.add(new PdfGrobidImporter(importFormatPreferences));
}
this.metadataImporters.add(new PdfXmpImporter(importFormatPreferences.getXmpPreferences()));
this.metadataImporters.add(new PdfXmpImporter(importFormatPreferences.xmpPreferences()));
this.metadataImporters.add(new PdfContentImporter(importFormatPreferences));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ private void parseAdditionalFields(BibEntry be, boolean multilineUrlFieldAllowed
String content = readMultipleLines(in);
String[] keywords = content.split("[,;]");
be.addKeywords(Arrays.asList(keywords),
importFormatPreferences.getKeywordSeparator());
importFormatPreferences.bibEntryPreferences().getKeywordSeparator());
} else if ("JEL".equals(keyword)) {
// parse JEL field
be.setField(new UnknownField("jel"), readMultipleLines(in));
Expand Down
10 changes: 3 additions & 7 deletions src/test/java/org/jabref/gui/entryeditor/SourceTabTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
import org.jabref.model.entry.field.StandardField;
import org.jabref.model.entry.field.UnknownField;
import org.jabref.model.util.DummyFileUpdateMonitor;
import org.jabref.preferences.BibEntryPreferences;
import org.jabref.testutils.category.GUITest;

import org.fxmisc.richtext.CodeArea;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Answers;
import org.testfx.api.FxRobot;
import org.testfx.framework.junit5.ApplicationExtension;
import org.testfx.framework.junit5.Start;
Expand All @@ -52,12 +52,8 @@ public void onStart(Stage stage) {
StateManager stateManager = mock(StateManager.class);
when(stateManager.activeSearchQueryProperty()).thenReturn(OptionalObjectProperty.empty());
KeyBindingRepository keyBindingRepository = new KeyBindingRepository(Collections.emptyList(), Collections.emptyList());
BibEntryPreferences bibEntryPreferences = mock(BibEntryPreferences.class);
when(bibEntryPreferences.getKeywordSeparator()).thenReturn(',');
ImportFormatPreferences importFormatPreferences = mock(ImportFormatPreferences.class);
when(importFormatPreferences.getFieldContentFormatterPreferences())
.thenReturn(mock(FieldContentFormatterPreferences.class));
when(importFormatPreferences.getBibEntryPreferences()).thenReturn(bibEntryPreferences);
ImportFormatPreferences importFormatPreferences = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS);
when(importFormatPreferences.bibEntryPreferences().getKeywordSeparator()).thenReturn(',');
FieldWriterPreferences fieldWriterPreferences = new FieldWriterPreferences(true, List.of(StandardField.MONTH), new FieldContentFormatterPreferences());

sourceTab = new SourceTab(new BibDatabaseContext(), new CountingUndoManager(), fieldWriterPreferences, importFormatPreferences, new DummyFileUpdateMonitor(), mock(DialogService.class), stateManager, keyBindingRepository);
Expand Down
Loading