Search in sources :

Example 11 with LinkedFile

use of org.jabref.model.entry.LinkedFile in project jabref by JabRef.

the class CleanupWorkerTest method cleanupRenamePdfRenamesRelativeFile.

@Test
public void cleanupRenamePdfRenamesRelativeFile() throws IOException {
    CleanupPreset preset = new CleanupPreset(CleanupPreset.CleanupStep.RENAME_PDF);
    File tempFile = bibFolder.newFile();
    BibEntry entry = new BibEntry();
    entry.setCiteKey("Toot");
    LinkedFile fileField = new LinkedFile("", tempFile.getAbsolutePath(), "");
    entry.setField("file", FileFieldWriter.getStringRepresentation(fileField));
    worker.cleanup(preset, entry);
    LinkedFile newFileField = new LinkedFile("", "Toot.tmp", "");
    Assert.assertEquals(Optional.of(FileFieldWriter.getStringRepresentation(newFileField)), entry.getField("file"));
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) LinkedFile(org.jabref.model.entry.LinkedFile) LinkedFile(org.jabref.model.entry.LinkedFile) File(java.io.File) Test(org.junit.Test)

Example 12 with LinkedFile

use of org.jabref.model.entry.LinkedFile in project jabref by JabRef.

the class CleanupWorkerTest method cleanupMoveFilesMovesFileFromSubfolder.

@Test
public void cleanupMoveFilesMovesFileFromSubfolder() throws IOException {
    CleanupPreset preset = new CleanupPreset(CleanupPreset.CleanupStep.MOVE_PDF);
    File subfolder = bibFolder.newFolder();
    File tempFile = new File(subfolder, "test.pdf");
    tempFile.createNewFile();
    BibEntry entry = new BibEntry();
    LinkedFile fileField = new LinkedFile("", tempFile.getAbsolutePath(), "");
    entry.setField("file", FileFieldWriter.getStringRepresentation(fileField));
    worker.cleanup(preset, entry);
    LinkedFile newFileField = new LinkedFile("", tempFile.getName(), "");
    Assert.assertEquals(Optional.of(FileFieldWriter.getStringRepresentation(newFileField)), entry.getField("file"));
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) LinkedFile(org.jabref.model.entry.LinkedFile) LinkedFile(org.jabref.model.entry.LinkedFile) File(java.io.File) Test(org.junit.Test)

Example 13 with LinkedFile

use of org.jabref.model.entry.LinkedFile in project jabref by JabRef.

the class RenamePdfCleanupTest method cleanupRenamePdfRenamesWithMultipleFiles.

@Test
public void cleanupRenamePdfRenamesWithMultipleFiles() throws IOException {
    String fileNamePattern = "\\bibtexkey - \\title";
    File tempFile = testFolder.newFile("Toot.tmp");
    entry.setField("title", "test title");
    entry.setField("file", FileFieldWriter.getStringRepresentation(Arrays.asList(new LinkedFile("", "", ""), new LinkedFile("", tempFile.getAbsolutePath(), ""), new LinkedFile("", "", ""))));
    RenamePdfCleanup cleanup = new RenamePdfCleanup(false, context, fileNamePattern, mock(LayoutFormatterPreferences.class), fileDirPrefs);
    cleanup.cleanup(entry);
    assertEquals(Optional.of(FileFieldWriter.getStringRepresentation(Arrays.asList(new LinkedFile("", "", ""), new LinkedFile("", "Toot - test title.tmp", ""), new LinkedFile("", "", "")))), entry.getField("file"));
}
Also used : LinkedFile(org.jabref.model.entry.LinkedFile) LayoutFormatterPreferences(org.jabref.logic.layout.LayoutFormatterPreferences) File(java.io.File) LinkedFile(org.jabref.model.entry.LinkedFile) Test(org.junit.Test)

Example 14 with LinkedFile

use of org.jabref.model.entry.LinkedFile in project jabref by JabRef.

the class RenamePdfCleanupTest method cleanupRenamePdfRenamesFileInSameFolder.

@Test
public void cleanupRenamePdfRenamesFileInSameFolder() throws IOException {
    String fileNamePattern = "\\bibtexkey\\begin{title} - \\format[RemoveBrackets]{\\title}\\end{title}";
    testFolder.newFile("Toot.pdf");
    LinkedFile fileField = new LinkedFile("", "Toot.pdf", "PDF");
    entry.setField("file", FileFieldWriter.getStringRepresentation(fileField));
    entry.setField("title", "test title");
    RenamePdfCleanup cleanup = new RenamePdfCleanup(false, context, fileNamePattern, layoutFormatterPreferences, fileDirPrefs);
    cleanup.cleanup(entry);
    LinkedFile newFileField = new LinkedFile("", "Toot - test title.pdf", "PDF");
    assertEquals(Optional.of(FileFieldWriter.getStringRepresentation(newFileField)), entry.getField("file"));
}
Also used : LinkedFile(org.jabref.model.entry.LinkedFile) Test(org.junit.Test)

Example 15 with LinkedFile

use of org.jabref.model.entry.LinkedFile in project jabref by JabRef.

the class MoveFilesCleanupTest method movesFileFromSubfolderMultiple.

@Test
public void movesFileFromSubfolderMultiple() throws IOException {
    File subfolder = bibFolder.newFolder();
    File fileBefore = new File(subfolder, "test.pdf");
    assertTrue(fileBefore.createNewFile());
    assertTrue(fileBefore.exists());
    LinkedFile fileField = new LinkedFile("", fileBefore.getAbsolutePath(), "");
    entry.setField("file", FileFieldWriter.getStringRepresentation(Arrays.asList(new LinkedFile("", "", ""), fileField, new LinkedFile("", "", ""))));
    cleanup = new MoveFilesCleanup(databaseContext, "", fileDirPrefs, mock(LayoutFormatterPreferences.class));
    cleanup.cleanup(entry);
    assertFalse(fileBefore.exists());
    File fileAfter = new File(pdfFolder, "test.pdf");
    assertTrue(fileAfter.exists());
    assertEquals(Optional.of(FileFieldWriter.getStringRepresentation(Arrays.asList(new LinkedFile("", "", ""), new LinkedFile("", fileAfter.getName(), ""), new LinkedFile("", "", "")))), entry.getField("file"));
}
Also used : LinkedFile(org.jabref.model.entry.LinkedFile) File(java.io.File) LinkedFile(org.jabref.model.entry.LinkedFile) Test(org.junit.Test)

Aggregations

LinkedFile (org.jabref.model.entry.LinkedFile)28 Test (org.junit.Test)13 File (java.io.File)11 Path (java.nio.file.Path)8 FieldChange (org.jabref.model.FieldChange)6 ArrayList (java.util.ArrayList)5 BibEntry (org.jabref.model.entry.BibEntry)5 HashMap (java.util.HashMap)3 List (java.util.List)3 ExternalFileType (org.jabref.gui.externalfiletype.ExternalFileType)3 UnknownExternalFileType (org.jabref.gui.externalfiletype.UnknownExternalFileType)3 FileListEntry (org.jabref.gui.filelist.FileListEntry)3 LayoutFormatterPreferences (org.jabref.logic.layout.LayoutFormatterPreferences)3 IOException (java.io.IOException)2 Paths (java.nio.file.Paths)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 Log (org.apache.commons.logging.Log)2 LogFactory (org.apache.commons.logging.LogFactory)2 FileFieldParser (org.jabref.model.entry.FileFieldParser)2