forked from JabRef/jabref
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into searchtestcases
- Loading branch information
Showing
20 changed files
with
455 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
[submodule "buildres/abbrv.jabref.org"] | ||
[submodule "abbrv.jabref.org"] | ||
path = buildres/abbrv.jabref.org | ||
url = https://github.com/JabRef/abbrv.jabref.org.git | ||
[submodule "buildres/csl-styles"] | ||
ignore = all | ||
shallow = true | ||
[submodule "csl-styles"] | ||
path = src/main/resources/csl-styles | ||
url = https://github.com/citation-style-language/styles.git | ||
[submodule "buildres/csl-locales"] | ||
ignore = all | ||
shallow = true | ||
[submodule "csl-locales"] | ||
path = src/main/resources/csl-locales | ||
url = https://github.com/citation-style-language/locales.git | ||
ignore = all | ||
shallow = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
...n/java/org/jabref/gui/entryeditor/citationrelationtab/CitationsRelationsTabViewModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package org.jabref.gui.entryeditor.citationrelationtab; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import javax.swing.undo.UndoManager; | ||
|
||
import org.jabref.gui.DialogService; | ||
import org.jabref.gui.StateManager; | ||
import org.jabref.gui.entryeditor.citationrelationtab.semanticscholar.CitationFetcher; | ||
import org.jabref.gui.externalfiles.ImportHandler; | ||
import org.jabref.gui.util.TaskExecutor; | ||
import org.jabref.logic.citationkeypattern.CitationKeyGenerator; | ||
import org.jabref.logic.citationkeypattern.CitationKeyPatternPreferences; | ||
import org.jabref.model.database.BibDatabaseContext; | ||
import org.jabref.model.entry.BibEntry; | ||
import org.jabref.model.entry.field.StandardField; | ||
import org.jabref.model.util.FileUpdateMonitor; | ||
import org.jabref.preferences.PreferencesService; | ||
|
||
public class CitationsRelationsTabViewModel { | ||
|
||
private final BibDatabaseContext databaseContext; | ||
private final PreferencesService preferencesService; | ||
private final UndoManager undoManager; | ||
private final StateManager stateManager; | ||
private final DialogService dialogService; | ||
private final FileUpdateMonitor fileUpdateMonitor; | ||
private final TaskExecutor taskExecutor; | ||
|
||
public CitationsRelationsTabViewModel(BibDatabaseContext databaseContext, PreferencesService preferencesService, UndoManager undoManager, StateManager stateManager, DialogService dialogService, FileUpdateMonitor fileUpdateMonitor, TaskExecutor taskExecutor) { | ||
this.databaseContext = databaseContext; | ||
this.preferencesService = preferencesService; | ||
this.undoManager = undoManager; | ||
this.stateManager = stateManager; | ||
this.dialogService = dialogService; | ||
this.fileUpdateMonitor = fileUpdateMonitor; | ||
this.taskExecutor = taskExecutor; | ||
} | ||
|
||
public void importEntries(List<CitationRelationItem> entriesToImport, CitationFetcher.SearchType searchType, BibEntry existingEntry) { | ||
List<BibEntry> entries = entriesToImport.stream().map(CitationRelationItem::entry).toList(); | ||
|
||
ImportHandler importHandler = new ImportHandler( | ||
databaseContext, | ||
preferencesService, | ||
fileUpdateMonitor, | ||
undoManager, | ||
stateManager, | ||
dialogService, | ||
taskExecutor); | ||
|
||
switch (searchType) { | ||
case CITES -> importCites(entries, existingEntry, importHandler); | ||
case CITED_BY -> importCitedBy(entries, existingEntry, importHandler); | ||
} | ||
} | ||
|
||
private void importCites(List<BibEntry> entries, BibEntry existingEntry, ImportHandler importHandler) { | ||
CitationKeyPatternPreferences citationKeyPatternPreferences = preferencesService.getCitationKeyPatternPreferences(); | ||
CitationKeyGenerator generator = new CitationKeyGenerator(databaseContext, citationKeyPatternPreferences); | ||
boolean generateNewKeyOnImport = preferencesService.getImporterPreferences().generateNewKeyOnImportProperty().get(); | ||
|
||
List<String> citeKeys = getExistingEntriesFromCiteField(existingEntry); | ||
citeKeys.removeIf(String::isEmpty); | ||
for (BibEntry entryToCite : entries) { | ||
if (generateNewKeyOnImport || entryToCite.getCitationKey().isEmpty()) { | ||
String key = generator.generateKey(entryToCite); | ||
entryToCite.setCitationKey(key); | ||
addToKeyToList(citeKeys, key); | ||
} else { | ||
addToKeyToList(citeKeys, entryToCite.getCitationKey().get()); | ||
} | ||
} | ||
existingEntry.setField(StandardField.CITES, toCommaSeparatedString(citeKeys)); | ||
importHandler.importEntries(entries); | ||
} | ||
|
||
private void importCitedBy(List<BibEntry> entries, BibEntry existingEntry, ImportHandler importHandler) { | ||
CitationKeyPatternPreferences citationKeyPatternPreferences = preferencesService.getCitationKeyPatternPreferences(); | ||
CitationKeyGenerator generator = new CitationKeyGenerator(databaseContext, citationKeyPatternPreferences); | ||
boolean generateNewKeyOnImport = preferencesService.getImporterPreferences().generateNewKeyOnImportProperty().get(); | ||
|
||
for (BibEntry entryThatCitesOurExistingEntry : entries) { | ||
List<String> existingCites = getExistingEntriesFromCiteField(entryThatCitesOurExistingEntry); | ||
existingCites.removeIf(String::isEmpty); | ||
String key; | ||
if (generateNewKeyOnImport || entryThatCitesOurExistingEntry.getCitationKey().isEmpty()) { | ||
key = generator.generateKey(entryThatCitesOurExistingEntry); | ||
entryThatCitesOurExistingEntry.setCitationKey(key); | ||
} else { | ||
key = existingEntry.getCitationKey().get(); | ||
} | ||
addToKeyToList(existingCites, key); | ||
entryThatCitesOurExistingEntry.setField(StandardField.CITES, toCommaSeparatedString(existingCites)); | ||
} | ||
|
||
importHandler.importEntries(entries); | ||
} | ||
|
||
private void addToKeyToList(List<String> list, String key) { | ||
if (!list.contains(key)) { | ||
list.add(key); | ||
} | ||
} | ||
|
||
private List<String> getExistingEntriesFromCiteField(BibEntry entry) { | ||
return Arrays.stream(entry.getField(StandardField.CITES).orElse("").split(",")).collect(Collectors.toList()); | ||
} | ||
|
||
private String toCommaSeparatedString(List<String> citeentries) { | ||
return String.join(",", citeentries); | ||
} | ||
} |
Oops, something went wrong.