-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Refactored around the PDF Annotation Importer #2624
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
| } | ||
| private String prettyPrint(String date) { | ||
| // Sometimes this is null, not sure why. | ||
| if (date == null) { |
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.
This seems to be the case if the guava cache is loaded.
|
Current state: LGTM 👍 |
| private FileAnnotation linkedFileAnnotation; | ||
| private final static int ABBREVIATED_ANNOTATION_NAME_LENGTH = 45; | ||
| private final static String ANNOTATION_DATE_REGEX = "D:\\d+"; | ||
| public final String author; |
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 know that this is not a problem of mutability here, but is there a good reason for breaking with the Java conventions for this and the following attributes? If there is no added benefit, then I would much prefer to have public getters instead of public attributes for the simple reason that this is the convention. Otherwise it always looks fishy when such a variable is accessed in another class and I have to look up FileAnnotation to check that this is not a grave access bug.
|
Hm good point, @lenhard . I personally think that this mentioned convention ist quite obsolete nowadays unless you work with a framework that requires it.People blindly generate trivial setters and getters (see diff) for all attributes driving the principle of information hiding ad absurdum and bloating up the code with unnecessary methods.However, if this is the consensus that we stick with the getters convention I ofc can change it.
|
|
In this particular case, the point of the conventions is mainly to ease the understanding of the code and, thereby, consume less developer time. From my point of view, this is worthwhile and I would opt for adding getters. However, maybe someone from @JabRef/developers disagrees with this? In this case we should discuss our preferred solution and reach a consensus in the devcall that is to be followed for all of JabRef. |
|
I generally vote for getters and setters
Because of information hiding principle
Encapsulation, makes it easier to read and allows for future modifications
Am 07.03.2017 10:47 vorm. schrieb "Jörg Lenhard" <[email protected]>:
… In this particular case, the point of the conventions is mainly to ease
the understanding of the code and, thereby, consume less developer time.
From my point of view, this is worthwhile and I would opt for adding
getters.
However, maybe someone from @JabRef/developers
<https://github.com/orgs/JabRef/teams/developers> disagrees with this? In
this case we should discuss our preferred solution and reach a consensus in
the devcall that is to be followed for all of JabRef.
—
You are receiving this because you are on a team that was mentioned.
Reply to this email directly, view it on GitHub
<#2624 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AATi5DtBNbSsARrgwBjo1j6SnySe8xA1ks5rjSe1gaJpZM4MUsG->
.
|
tobiasdiez
left a comment
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.
Just a few minor remarks. I second @lenhard opinion and think that public getters + setters are the usual convention (as we use Java, it is almost by design that we have bloated code...auto-properties as in e.g. C# don't exists in the Java world.)
| * @param pageNumber The page of the pdf where the annotation occurs | ||
| */ | ||
| public FileAnnotation(final PDAnnotation annotation, final int pageNumber) { | ||
| COSDictionary dict = annotation.getDictionary(); |
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 please reuse the "dummy" construction, i.e. this(annotation.getModifiedDate(), pageNumber, ...). This comment also applies to the second constructor below.
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.
fixed in bd542d6
| private String prettyPrint(String date) { | ||
| // Sometimes this is null, not sure why. | ||
| if (date == null) { | ||
| return date; |
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.
Then better set date here to the empty string (otherwise the null-check has to propagate to every usage of the field FileAnnotation.date
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.
fixed in f977614
| this.author = author; | ||
| } | ||
| // normal case for an imported annotation | ||
| if (date.matches(ANNOTATION_DATE_REGEX)) { |
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.
Maybe even store the date as an instance of Date ? Then the gui can decide how to display it.
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 in bd542d6
| return PDDocument.load("/"+ path); | ||
| if (!Files.exists(path)) { | ||
| Optional<File> importedFile = FileUtil.expandFilename(context, path.toString(), | ||
| JabRefPreferences.getInstance().getFileDirectoryPreferences()); |
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 please pass the fileDirectoryPreferences as an argument to the constructor. Everything in logic and model should be independent of the JabRefPreferences class (we should add a architecture test for that too...)
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.
hmm I'm not sure how to do that. On the calling side of PdfAnnotationImporter (EntryAnnotationImporter) I only have the BibDatabaseContext available. Not sure how to obtain the correct path from there?
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.
Yes this change would propagate to EntryAnnotationImporter and FileAnnotationCache (and probably further places) until one ends up in gui. It's not that important, you can also leave it as it is right now.
|
I don't see a need for Getters if the Objects are immutable, just clutters the code. |
|
Well... I think adding the |
|
+1 for devcall. 🌞 Until then: https://projectlombok.org/features/GetterSetter.html (Only a pointer to some crazy stuff I personally don't like 😇 ) |
|
Thanks for the feedback, esp. @tobiasdiez. I fixed these issues and made the FileAnnotationTab better overall by removing invalid (i.e. unparsable annotations). |
| PDFTextStripperByArea stripperByArea = new PDFTextStripperByArea(); | ||
| COSArray quadsArray = (COSArray) annotation.getDictionary().getDictionaryObject(COSName.getPDFName("QuadPoints")); | ||
| String highlightedText = ""; | ||
| for (int j = 1, |
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 don't know if you changed it, but it would be nice to have a bit better speaking variable names, as I here don't get from a quick view what j and k stand for.
|
You are absolutely right. But to be honest in this particular case I just regard this method as a black box and hope nobody has to touch it again.
|
|
We decided that we want to stick with the good old Getters. |
* upstream/master: Donate to JabRef! Issuestats.com is down Add link to logo creator Improve perfomance of opening a database that still used the old groups format (#2636) Set POSIX filepermissions to 644 (#2637) Fix #2629: Removing entry from group updates view properly Remove empty tooltip in group panel Refactored around the PDF Annotation Importer (#2624) Fix last import issue Fix imports and some reformatting Fix wrong import order Add missing svg icon RIP old icon Add new logo files (#2164) # Conflicts: # src/main/java/org/jabref/gui/groups/GroupSelector.java
I mainly refactored the PdfAnnotationImporter. It now uses java.nio and has sane error handling.
Furthermore, I made the FileAnnotations immutable.
Deleted an unused (was renamed but not deleted) Interface
The only actual change for the user is that the dates from the FileAnnotations shown in the FileAnnotationsTab are nicely formatted now.
I am not so satisfied with the Optional field in FileAnnotation. However, I have not come up with a better solution to model that relationship from highlighted text to the sticky note attached to it.