Skip to content
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

Fixed duplicate fields assigned to entry types #8391

Merged
merged 8 commits into from
Jan 12, 2022

Conversation

dimitrisdimos00
Copy link
Contributor

@dimitrisdimos00 dimitrisdimos00 commented Jan 5, 2022

Changed the method addNewField of class CustomEntryTypeDialogViewModel in order to check if the field already exists. Added DialogService field to class CustomEntryTypeDialogViewModel in order to show warning notification to the user. Moreover, passed the existing dialogService field of the class CustomEntryDialogView as a parameter when calling the constructor of the CustomEntryTypeDialogViewModel inside it.
Fixes #8194

  • Change in CHANGELOG.md described in a way that is understandable for the average user (if applicable)
  • Tests created for changes (if applicable)
  • Manually tested changed features in running JabRef (always required)
  • Screenshots added in PR description (for UI changes)
  • Checked documentation: Is the information available and up to date? If not, I created an issue at https://github.com/JabRef/user-documentation/issues or, even better, I submitted a pull request to the documentation repository.

image

Changed the method addNewField of class CustomEntryTypeDialogViewModel in order to check if the field already exists. Added DialogService field to class CustomEntryTypeDialogViewModel in order to show warning notification to the user.
fixes JabRef#8194
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 small changes Can you also check what happens when you add a duplicate entry type (e.g. add a custom entry type article)? It could theoretically be possible, but would not make any sense...

import org.jabref.model.entry.field.FieldFactory;
import org.jabref.model.entry.field.FieldPriority;
import org.jabref.model.entry.field.OrFields;
import org.jabref.model.entry.field.*;
Copy link
Member

Choose a reason for hiding this comment

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

There seems to be something wrong with your codestyle here, no star imports allowed
See https://github.com/JabRef/jabref/tree/main/config

ObservableList<FieldViewModel> entryFields = this.selectedEntryType.getValue().fields();

// compare every entry field name with the user field name in order to find out if any of them has the same one. If so, show warning.
for (FieldViewModel fieldViewModel : entryFields) {
Copy link
Member

Choose a reason for hiding this comment

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

This can be simplified
entryFields.stream().anyMatch(fieldViewModel -> fieldViewModel.fieldName().getValue().equals(...)
See https://www.baeldung.com/java-8-streams-introduction#1-iterating

@Siedlerchr
Copy link
Member

Siedlerchr commented Jan 5, 2022

Thanks for your contribution (Congrats on your first 🥇 ) and the explanation of your changes! Very good start! Just some minor things.

@dimitrisdimos00
Copy link
Contributor Author

I am glad to help! Yeah, it is indeed my first contribution to an open source project. The truth is that I found it kind of hard to navigate among the countless project files. However I managed to make it work. Moreover, I tried adding a duplicate entry type and it works. I also implemented the requested changes. Hope it's ok this time!

@Siedlerchr
Copy link
Member

I am glad to help! Yeah, it is indeed my first contribution to an open source project. The truth is that I found it kind of hard to navigate among the countless project files. However I managed to make it work.

Cool :) And a solid first time contribution!
We have also a kind of high-level overview (e.g. the relationship between the different packages) and some other useful resources in our devdocs. https://devdocs.jabref.org/getting-into-the-code/high-level-documentation
May I ask how it came that you chose JabRef?

A little issue is still left:
Please have a look at the checkstyle/reviewdog (Files changed github) issues. Although these warnings are sometimes nasty, they help us to ensure a uniform code style and to prevent merge conflicts due to formatting changes.

@dimitrisdimos00
Copy link
Contributor Author

Thanks! Ok I will check this out. Well you have a very good guide on seting up everything for newcomers. The most difficult thing for me with projects like this on github is actually setting them up in order to start. In other projects, the instructions are kind of vague and if you encounter an issue in the process, it is very difficult to recover and get going again. In your project, the instructions for setting up Intellij for example were very clear and they had every possible error that might show up. Finally, I like java as a language and wanted to find a project that uses it, so I ended up choosing Jabref.

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.

codewise lgtm now. I will test your changes and wait for a second maintainer to review your code

edit// tested locally looks good

@Siedlerchr Siedlerchr added the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Jan 6, 2022
Copy link
Member

@calixtus calixtus left a comment

Choose a reason for hiding this comment

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

Two style issues.
Thanks for your contribution!

Comment on lines 133 to 144
// create list with all the entry's fields
ObservableList<FieldViewModel> entryFields = this.selectedEntryType.getValue().fields();

// compare every entry field name with the user field name in order to find out if any of them has the same one.
boolean fieldExists = entryFields.stream().anyMatch(fieldViewModel -> fieldViewModel.fieldName().getValue().equals(field.getDisplayName()));

// if the user field name isn't found inside the list, pass it to the entry as a new one. If that is not the case, show warning.
if (!fieldExists) {
this.selectedEntryType.getValue().addField(model);
} else {
dialogService.showWarningDialogAndWait(Localization.lang("Duplicate fields"), Localization.lang("Warning: You added field \"%0\" twice. Only one will be kept.", field.getDisplayName()));
}
Copy link
Member

Choose a reason for hiding this comment

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

No code-repeating comments. If the name of the variables are chosen well, then the code is self-explaining and you don't need them.

Copy link
Contributor Author

@dimitrisdimos00 dimitrisdimos00 Jan 11, 2022

Choose a reason for hiding this comment

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

Hello. I deleted the first and last comment and removed as many as lines possible. Shall I remove the second comment too? I think it is more helpful than the other ones.

Copy link
Member

Choose a reason for hiding this comment

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

No, no comment at all, if it's not really necessary and totally misunderstandable otherwise. The best comment is always the code itself, with meaningful variable names and clean code in 98% you don't need any comment at all.
Whoever works with java nowadays knows how to read streams.

@calixtus calixtus merged commit 9b8f17b into JabRef:main Jan 12, 2022
@calixtus
Copy link
Member

Thanks for your contribution!

@dimitrisdimos00
Copy link
Contributor Author

dimitrisdimos00 commented Jan 13, 2022

You're welcome!

@dimitrisdimos00 dimitrisdimos00 deleted the fix-for-issue-8194 branch January 13, 2022 14:47
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.

Duplicate fields assigned to entry types
3 participants