-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7d7a7f8
commit 77150ba
Showing
6 changed files
with
132 additions
and
86 deletions.
There are no files selected for viewing
46 changes: 7 additions & 39 deletions
46
src/main/java/org/jabref/gui/consistency/ConsistencyCheckAction.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 |
---|---|---|
@@ -1,67 +1,35 @@ | ||
package org.jabref.gui.consistency; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.jabref.gui.DialogService; | ||
import org.jabref.gui.StateManager; | ||
import org.jabref.gui.actions.SimpleCommand; | ||
import org.jabref.gui.preferences.GuiPreferences; | ||
import org.jabref.logic.quality.consistency.BibliographyConsistencyCheck; | ||
import org.jabref.model.database.BibDatabaseContext; | ||
import org.jabref.model.entry.BibEntry; | ||
import org.jabref.model.entry.field.Field; | ||
import org.jabref.model.entry.types.EntryType; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class ConsistencyCheckAction extends SimpleCommand { | ||
|
||
private final DialogService dialogService; | ||
private final StateManager stateManager; | ||
private final GuiPreferences preferences; | ||
|
||
private final Logger LOGGER = LoggerFactory.getLogger(ConsistencyCheckDialog.class); | ||
|
||
public ConsistencyCheckAction(DialogService dialogService, StateManager stateManager) { | ||
public ConsistencyCheckAction(DialogService dialogService, StateManager stateManager, GuiPreferences preferences) { | ||
this.dialogService = dialogService; | ||
this.stateManager = stateManager; | ||
this.preferences = preferences; | ||
} | ||
|
||
@Override | ||
public void execute() { | ||
BibDatabaseContext database = stateManager.getActiveDatabase().orElseThrow(() -> new NullPointerException("Database null")); | ||
List<BibEntry> entries = database.getDatabase().getEntries(); | ||
|
||
/* BibliographyConsistencyCheck.Result result = new BibliographyConsistencyCheck().check(entries); | ||
String homeDir = System.getProperty("user.home"); | ||
Path tempDir = Paths.get(homeDir, "downloads"); | ||
Path txtFile = tempDir.resolve("consistency-check.txt"); | ||
try (Writer writer = new OutputStreamWriter(Files.newOutputStream(txtFile))) { | ||
BibliographyConsistencyCheckResultTxtWriter bibliographyConsistencyCheckResultTxtWriter = new BibliographyConsistencyCheckResultTxtWriter(result, writer); | ||
bibliographyConsistencyCheckResultTxtWriter.writeFindings(); | ||
dialogService.notify("File created!"); | ||
} catch (IOException e) { | ||
dialogService.notify("Exception occured!"); | ||
}*/ | ||
BibDatabaseContext databaseContext = stateManager.getActiveDatabase().orElseThrow(() -> new NullPointerException("Database null")); | ||
List<BibEntry> entries = databaseContext.getDatabase().getEntries(); | ||
|
||
BibliographyConsistencyCheck consistencyCheck = new BibliographyConsistencyCheck(); | ||
BibliographyConsistencyCheck.Result result = consistencyCheck.check(entries); | ||
|
||
Map<EntryType, BibliographyConsistencyCheck.EntryTypeResult> entryTypeToResultMap = result.entryTypeToResultMap(); | ||
|
||
entryTypeToResultMap.forEach((entryType, entryTypeResult) -> { | ||
LOGGER.info("Entry Type: " + entryType); | ||
|
||
Collection<Field> uniqueFields = entryTypeResult.fields(); | ||
LOGGER.info("Unique Fields: " + uniqueFields); | ||
|
||
Collection<BibEntry> sortedEntries = entryTypeResult.sortedEntries(); | ||
LOGGER.info("Sorted Entries: " + sortedEntries); | ||
}); | ||
|
||
dialogService.showCustomDialogAndWait(new ConsistencyCheckDialog()); | ||
dialogService.showCustomDialogAndWait(new ConsistencyCheckDialog(result, dialogService, preferences)); | ||
} | ||
} |
24 changes: 18 additions & 6 deletions
24
src/main/java/org/jabref/gui/consistency/ConsistencyCheckDialog.fxml
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
60 changes: 60 additions & 0 deletions
60
src/main/java/org/jabref/gui/consistency/ConsistencyCheckDialogViewModel.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 |
---|---|---|
@@ -1,6 +1,66 @@ | ||
package org.jabref.gui.consistency; | ||
|
||
import java.io.IOException; | ||
import java.io.OutputStreamWriter; | ||
import java.io.Writer; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.Optional; | ||
|
||
import org.jabref.gui.AbstractViewModel; | ||
import org.jabref.gui.DialogService; | ||
import org.jabref.gui.preferences.GuiPreferences; | ||
import org.jabref.gui.util.FileDialogConfiguration; | ||
import org.jabref.logic.l10n.Localization; | ||
import org.jabref.logic.quality.consistency.BibliographyConsistencyCheck; | ||
import org.jabref.logic.quality.consistency.BibliographyConsistencyCheckResultCsvWriter; | ||
import org.jabref.logic.quality.consistency.BibliographyConsistencyCheckResultTxtWriter; | ||
import org.jabref.logic.util.StandardFileType; | ||
|
||
public class ConsistencyCheckDialogViewModel extends AbstractViewModel { | ||
private final DialogService dialogService; | ||
private final GuiPreferences preferences; | ||
private final BibliographyConsistencyCheck.Result result; | ||
|
||
public ConsistencyCheckDialogViewModel(BibliographyConsistencyCheck.Result result, DialogService dialogService, GuiPreferences preferences) { | ||
this.result = result; | ||
this.dialogService = dialogService; | ||
this.preferences = preferences; | ||
} | ||
|
||
public void startExportAsTxt() { | ||
FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder() | ||
.withInitialDirectory(preferences.getFilePreferences().getWorkingDirectory()) | ||
.addExtensionFilter(StandardFileType.TXT) | ||
.withDefaultExtension(StandardFileType.TXT) | ||
.build(); | ||
Optional<Path> exportPath = dialogService.showFileSaveDialog(fileDialogConfiguration); | ||
|
||
if (exportPath.isEmpty()) { | ||
return; | ||
} | ||
|
||
try (Writer writer = new OutputStreamWriter(Files.newOutputStream(exportPath.get()))) { | ||
BibliographyConsistencyCheckResultTxtWriter bibliographyConsistencyCheckResultTxtWriter = new BibliographyConsistencyCheckResultTxtWriter(result, writer); | ||
bibliographyConsistencyCheckResultTxtWriter.writeFindings(); | ||
} catch (IOException e) { | ||
dialogService.notify(Localization.lang("Failed to export file!")); | ||
} | ||
} | ||
|
||
public void startExportAsCsv() { | ||
FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder() | ||
.withInitialDirectory(preferences.getFilePreferences().getWorkingDirectory()) | ||
.addExtensionFilter(StandardFileType.TXT) | ||
.withDefaultExtension(StandardFileType.TXT) | ||
.build(); | ||
Optional<Path> exportPath = dialogService.showFileSaveDialog(fileDialogConfiguration); | ||
|
||
try (Writer writer = new OutputStreamWriter(Files.newOutputStream(exportPath.get()))) { | ||
BibliographyConsistencyCheckResultCsvWriter bibliographyConsistencyCheckResultTxtWriter = new BibliographyConsistencyCheckResultCsvWriter(result, writer); | ||
bibliographyConsistencyCheckResultTxtWriter.writeFindings(); | ||
} catch (IOException e) { | ||
dialogService.notify(Localization.lang("Failed to export file!")); | ||
} | ||
} | ||
} |
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