-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Refactor parsed file field #2723
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
Conversation
Move `getFiles` from `TypedBibEntry` to `BibEntry` (the later already contained a `setFiles` method)
…leHelper` Reuse `ParsedFileField.findIn` methods
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Besides minor comments: LGTM
* @param fileName | ||
* @return The extension (without leading dot), trimmed and in lowercase. | ||
*/ | ||
public static Optional<String> getFileExtension(String fileName) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a JavaDoc comment why you implemented that method on your own instead of using Files.getFileExtension(fileName);? We have the Guava libraries and should use them 😇
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thik he just moved the method, we previously had it in FileUtils
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We nevertheless could use Guava 😇
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our code is slightly different (extensions are required to have at length > 1) and uses optional instead of empty strings. Thus I think it is not worth using Guava (maybe we can even remove the dependency on guava at some point).
* @param values The String array. | ||
* @return The encoded String. | ||
*/ | ||
public static String encodeStringArray(String[][] values) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a JavaDoc why this method is public? The other below is private, I miss the symmetry.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is public because it is used somewhere else. You are probably right and this method should be private, but I have no idea what "FileListTableModel" does....
//Extract the path | ||
Optional<String> oldValue = getField(FieldName.FILE); | ||
if (!oldValue.isPresent()) { | ||
return new ArrayList<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not Collections.emptyList()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
||
private static final ParsedFileField NULL_OBJECT = new ParsedFileField("", "", ""); | ||
public class LinkedFile { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a JavaDoc stating the intension and usage of this class? Also, why no TypedBibEntry is required anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course I can.
Optional<File> file = FileUtil.expandFilename(flEntry.getLink(), dirsS); | ||
if ((!file.isPresent()) || !file.get().exists()) { | ||
Optional<Path> file = field.findIn(panel.getBibDatabaseContext(), Globals.prefs.getFileDirectoryPreferences()); | ||
if ((file.isPresent()) && Files.exists(file.get())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you change the logic here?` Previously it was ! present
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch! Was probably a copy&paste error on my side. Fixed
// Include the standard "file" directory: | ||
List<String> fileDir = databaseContext.getFileDirectories(fileDirectoryPreferences); | ||
// Include the directory of the BIB file: | ||
List<String> al = new ArrayList<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A better variable name would be nice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor thing, especially the turned around logic
Inspired by a discussion with @lenhard in #2692. In detail, the following changes were performed:
FileField
intoFileFieldWriter
andFileFieldParser
getFiles
fromTypedBibEntry
toBibEntry
(the later already contained asetFiles
method)isOnlineLink
andfindIn
toParsedFileField
logic.util.io.FileUtil
tomodel.util.FileHelper
(idea for a better name?)ParsedFileField
toLinkedFile
gradle localizationUpdate
?