Skip to content

Conversation

@LinusDietz
Copy link
Member

@LinusDietz LinusDietz commented Mar 6, 2017

  • 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.

}
private String prettyPrint(String date) {
// Sometimes this is null, not sure why.
if (date == null) {
Copy link
Member Author

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.

@koppor
Copy link
Member

koppor commented Mar 7, 2017

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

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.

@stefan-kolb stefan-kolb added the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Mar 7, 2017
@LinusDietz
Copy link
Member Author

LinusDietz commented Mar 7, 2017 via email

@lenhard
Copy link
Member

lenhard commented Mar 7, 2017

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.

@Siedlerchr
Copy link
Member

Siedlerchr commented Mar 7, 2017 via email

Copy link
Member

@tobiasdiez tobiasdiez left a 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();
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 please reuse the "dummy" construction, i.e. this(annotation.getModifiedDate(), pageNumber, ...). This comment also applies to the second constructor below.

Copy link
Member Author

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

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

Copy link
Member Author

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

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.

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 in bd542d6

return PDDocument.load("/"+ path);
if (!Files.exists(path)) {
Optional<File> importedFile = FileUtil.expandFilename(context, path.toString(),
JabRefPreferences.getInstance().getFileDirectoryPreferences());
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 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...)

Copy link
Member Author

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?

Copy link
Member

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.

@stefan-kolb
Copy link
Member

I don't see a need for Getters if the Objects are immutable, just clutters the code.

@matthiasgeiger
Copy link
Member

Well... I think adding the devcall label was a good idea of Jörg ;-)

@koppor
Copy link
Member

koppor commented Mar 7, 2017

+1 for devcall. 🌞

Until then: https://projectlombok.org/features/GetterSetter.html

(Only a pointer to some crazy stuff I personally don't like 😇 )

@LinusDietz
Copy link
Member Author

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

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.

@LinusDietz
Copy link
Member Author

LinusDietz commented Mar 8, 2017 via email

@matthiasgeiger
Copy link
Member

We decided that we want to stick with the good old Getters.

@LinusDietz LinusDietz added component: external-files status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers and removed status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers labels Mar 10, 2017
@tobiasdiez tobiasdiez merged commit e669157 into master Mar 11, 2017
@tobiasdiez tobiasdiez deleted the fileannotations branch March 11, 2017 20:18
Siedlerchr added a commit that referenced this pull request Mar 14, 2017
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: external-files 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.

8 participants