Skip to content

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

Merged
merged 8 commits into from
Apr 18, 2017
Merged

Refactor parsed file field #2723

merged 8 commits into from
Apr 18, 2017

Conversation

tobiasdiez
Copy link
Member

@tobiasdiez tobiasdiez commented Apr 8, 2017

Inspired by a discussion with @lenhard in #2692. In detail, the following changes were performed:

  • Split FileField into FileFieldWriter and FileFieldParser
  • Move getFiles from TypedBibEntry to BibEntry (the later already contained a setFiles method)
  • Add isOnlineLink and findIn to ParsedFileField
  • Extract a few methods from logic.util.io.FileUtil to model.util.FileHelper (idea for a better name?)
  • Rename ParsedFileField to LinkedFile

  • Change in CHANGELOG.md described
  • Tests created for changes
  • Screenshots added (for bigger UI changes)
  • Manually tested changed features in running JabRef
  • Check documentation status (Issue created for outdated help page at help.jabref.org?)
  • If you changed the localization: Did you run gradle localizationUpdate?

Move `getFiles` from `TypedBibEntry` to `BibEntry` (the later already contained a `setFiles` method)
…leHelper`

Reuse `ParsedFileField.findIn` methods
@tobiasdiez tobiasdiez added the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Apr 8, 2017
@koppor koppor requested a review from lenhard April 16, 2017 16:04
Copy link
Member

@koppor koppor left a 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) {
Copy link
Member

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 😇

Copy link
Member

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

Copy link
Member

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 😇

Copy link
Member Author

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) {
Copy link
Member

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.

Copy link
Member Author

@tobiasdiez tobiasdiez Apr 17, 2017

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<>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not Collections.emptyList()?

Copy link
Member Author

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 {
Copy link
Member

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?

Copy link
Member Author

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())) {
Copy link
Member

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

Copy link
Member Author

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<>();
Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep

Copy link
Member

@Siedlerchr Siedlerchr left a 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

@tobiasdiez tobiasdiez merged commit c3104ac into master Apr 18, 2017
@tobiasdiez tobiasdiez deleted the refactorParsedFileField branch April 18, 2017 10:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants