use of org.jabref.model.entry.LinkedFile in project jabref by JabRef.
the class MoveFilesCleanupTest method movesFileFromSubfolderWithFileDirPattern.
@Test
public void movesFileFromSubfolderWithFileDirPattern() throws IOException {
File subfolder = bibFolder.newFolder();
File fileBefore = new File(subfolder, "test.pdf");
assertTrue(fileBefore.createNewFile());
assertTrue(new File(subfolder, "test.pdf").exists());
LinkedFile fileField = new LinkedFile("", fileBefore.getAbsolutePath(), "");
entry.setField("file", FileFieldWriter.getStringRepresentation(fileField));
cleanup = new MoveFilesCleanup(databaseContext, "\\EntryType", fileDirPrefs, mock(LayoutFormatterPreferences.class));
cleanup.cleanup(entry);
assertFalse(fileBefore.exists());
Path after = pdfFolder.toPath().resolve("Misc").resolve("test.pdf");
Path relativefileDir = pdfFolder.toPath().relativize(after);
assertTrue(Files.exists(after));
assertEquals(Optional.of(FileFieldWriter.getStringRepresentation(new LinkedFile("", relativefileDir.toString(), ""))), entry.getField("file"));
}
use of org.jabref.model.entry.LinkedFile in project jabref by JabRef.
the class RenamePdfCleanupTest method cleanupRenamePdfRenamesFileEvenIfOnlyDifferenceIsCase.
/**
* Test for #466
*/
@Test
public void cleanupRenamePdfRenamesFileEvenIfOnlyDifferenceIsCase() throws IOException {
String fileNamePattern = "\\bibtexkey";
File tempFile = testFolder.newFile("toot.tmp");
LinkedFile fileField = new LinkedFile("", tempFile.getAbsolutePath(), "");
entry.setField("file", FileFieldWriter.getStringRepresentation(fileField));
RenamePdfCleanup cleanup = new RenamePdfCleanup(false, context, fileNamePattern, mock(LayoutFormatterPreferences.class), fileDirPrefs);
cleanup.cleanup(entry);
LinkedFile newFileField = new LinkedFile("", "Toot.tmp", "");
assertEquals(Optional.of(FileFieldWriter.getStringRepresentation(newFileField)), entry.getField("file"));
}
use of org.jabref.model.entry.LinkedFile in project jabref by JabRef.
the class FileListTableModel method setContent.
private FileListEntry setContent(String val, boolean firstOnly, boolean deduceUnknownTypes) {
String value = val;
if (value == null) {
value = "";
}
List<LinkedFile> fields = FileFieldParser.parse(value);
List<FileListEntry> files = new ArrayList<>();
for (LinkedFile entry : fields) {
if (entry.isEmpty()) {
continue;
}
if (firstOnly) {
return decodeEntry(entry, deduceUnknownTypes);
} else {
files.add(decodeEntry(entry, deduceUnknownTypes));
}
}
synchronized (list) {
list.clear();
list.addAll(files);
}
fireTableChanged(new TableModelEvent(this));
return null;
}
use of org.jabref.model.entry.LinkedFile in project jabref by JabRef.
the class LinkedFilesEditorViewModel method addFromURL.
private void addFromURL(URL url) {
URLDownload urlDownload = new URLDownload(url);
Optional<ExternalFileType> suggestedType = inferFileType(urlDownload);
String suggestedTypeName = suggestedType.map(ExternalFileType::getName).orElse("");
List<Path> fileDirectories = databaseContext.getFileDirectoriesAsPaths(Globals.prefs.getFileDirectoryPreferences());
Path destination = constructSuggestedPath(suggestedType, fileDirectories);
LinkedFileViewModel temporaryDownloadFile = new LinkedFileViewModel(new LinkedFile("", url, suggestedTypeName));
files.add(temporaryDownloadFile);
FileDownloadTask downloadTask = new FileDownloadTask(url, destination);
temporaryDownloadFile.downloadProgressProperty().bind(downloadTask.progressProperty());
downloadTask.setOnSucceeded(event -> {
files.remove(temporaryDownloadFile);
LinkedFile newLinkedFile = fromFile(destination, fileDirectories);
files.add(new LinkedFileViewModel(newLinkedFile));
});
downloadTask.setOnFailed(event -> dialogService.showErrorDialogAndWait("", downloadTask.getException()));
taskExecutor.execute(downloadTask);
}
use of org.jabref.model.entry.LinkedFile in project jabref by JabRef.
the class LinkedFilesEditorViewModel method addNewFile.
public void addNewFile() {
Path workingDirectory = databaseContext.getFirstExistingFileDir(Globals.prefs.getFileDirectoryPreferences()).orElse(Paths.get(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)));
FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder().withInitialDirectory(workingDirectory).build();
List<Path> fileDirectories = databaseContext.getFileDirectoriesAsPaths(Globals.prefs.getFileDirectoryPreferences());
dialogService.showFileOpenDialog(fileDialogConfiguration).ifPresent(newFile -> {
LinkedFile newLinkedFile = fromFile(newFile, fileDirectories);
files.add(new LinkedFileViewModel(newLinkedFile));
});
}
Aggregations