-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
minor refactor to JabRefDialogService #11767
Conversation
1. replace multiple if-else to switch case 2. remove unused generics `<V>` 3. replace `.collect(Collectors.toList())` to `.toList()` 4. remove unnecessary braces
switch (statusCode) { | ||
case 401 -> | ||
this.showInformationDialogAndWait(failedTitle, Localization.lang("Access denied. You are not authorized to access this resource. Please check your credentials and try again. If you believe you should have access, please contact the administrator for assistance.") + "\n\n" + localizedMessage); | ||
case 403 -> | ||
this.showInformationDialogAndWait(failedTitle, Localization.lang("Access denied. You do not have permission to access this resource. Please contact the administrator for assistance or try a different action.") + "\n\n" + localizedMessage); | ||
case 404 -> | ||
this.showInformationDialogAndWait(failedTitle, Localization.lang("The requested resource could not be found. It seems that the file you are trying to download is not available or has been moved. Please verify the URL and try again. If you believe this is an error, please contact the administrator for further assistance.") + "\n\n" + localizedMessage); | ||
default -> | ||
this.showErrorDialogAndWait(failedTitle, Localization.lang("Something is wrong on JabRef side. Please check the URL and try again.") + "\n\n" + localizedMessage); | ||
} |
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 can be refactored even more?
content = switch (statusCode) { 401 -> Localization.lang"..");
this.showInformationDialogAndWait(failedTitle, content);
I would just not care about info and error. I think "info" is OK even in the default
case.
@@ -472,7 +470,7 @@ public Optional<Path> showDirectorySelectionDialog(DirectoryDialogConfiguration | |||
public List<Path> showFileOpenDialogAndGetMultipleFiles(FileDialogConfiguration fileDialogConfiguration) { | |||
FileChooser chooser = getConfiguredFileChooser(fileDialogConfiguration); | |||
List<File> files = chooser.showOpenMultipleDialog(mainWindow); | |||
return files != null ? files.stream().map(File::toPath).collect(Collectors.toList()) : Collections.emptyList(); | |||
return files != null ? files.stream().map(File::toPath).toList() : 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.
return files != null ? files.stream().map(File::toPath).toList() : Collections.emptyList(); | |
return files != null ? files.stream().map(File::toPath).toList() : List.of(); |
.hideAfter(TOAST_MESSAGE_DISPLAY_TIME) | ||
.owner(mainWindow) | ||
.threshold(5, | ||
Notifications.create() |
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 new indent is a bit strange - maybe keep the old indent - on line 428 it also "felt" better, because it is indented 4 spaces, not 30 or so ^^
Thanks for your contribution, however due to our limited time for reviews (we are all working at JabRef in our spare time), we prefer such code quality only refactorings more in the context of bugs/feature implementations |
Thanks for your interest in JabRef. |
For me, it is currently OK, because the batch sizes are small enough to cope with it in some spare minutes 😅. |
OK, I'll try my best to solve some bigger issue from now on. Would you and @koppor mind review the comments in #10371 (comment), I'm not sure where to start solve this issue so I break down into small task, but I didn't get reply in two weeks, I think I may make a mistake, such as not @ anyone, so there wasn't any notification to others. |
1. remove `type` parameter in createDialogWithOptOut, since it always be `AlertType.CONFIRMATION` 2. remove `Math.min` in `shortenDialogMessage`, since it after a if compare, it means the dialogMessage.length() is always not less than JabRefDialogService.DIALOG_SIZE_LIMIT 3. refactor the switch case more. 4. fix the indent issue.
private String getContentByCode(int statusCode) { | ||
return switch (statusCode) { | ||
case 401 -> | ||
"Access denied. You are not authorized to access this resource. Please check your credentials and try again. If you believe you should have access, please contact the administrator for assistance."; |
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.
Please wrap in Localization.lang
. See https://devdocs.jabref.org/code-howtos/localization.html#localization-in-java-code for reasons.
fix missing Localization.lang
add missing newline character and localizedMessage
} else { | ||
this.showErrorDialogAndWait(failedTitle, Localization.lang("Something is wrong on JabRef side. Please check the URL and try again.") + "\n\n" + localizedMessage); | ||
} | ||
this.showInformationDialogAndWait(failedTitle, Localization.lang(getContentByCode(httpResponse.get().statusCode())) + "\n\n" + localizedMessage); |
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.
No, that does not work.
Localization.lang has to be parameterized with a literal (!) string. Otherwise, our tooling does nt work. Please see https://devdocs.jabref.org/code-howtos/localization.html
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 found this TODO in org.jabref.logic.l10n.LocalizationConsistencyTest
:
TODO: Localization.lang(var1 + "test" + var2) not covered
In my code is a var1 + "test" + var2
case, so it failed. maybe I should finish this TODO to pass the unit test?
sorry I made a mistake, my code is not var1 + "test" + var2
case, it just a var
case which is illegal in LocalizationConsistencyTest
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.
Finishing that ToDo would require several hours of work and design planning. Localization requires full sentences to be translated as in different languages word order and grammar changes d pending on what that var may be. So please just do as @koppor said, fix your strings.
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.
Finishing that ToDo would require several hours of work and design planning. Localization requires full sentences to be translated as in different languages word order and grammar changes d pending on what that var may be. So please just do as @koppor said, fix your strings.
I did as @koppor said, have fixed my strings before I commented. I just want to make this unit test better by finishing ToDo. And I think it may not require several hours work, such as this simple way:
- assert code in
LocalizationConsistencyTest
now:
assertTrue(e.getKey().startsWith("\"") || e.getKey().endsWith("\""), "Illegal localization parameter found. Must include a String with potential concatenation or replacement parameters. Illegal parameter: Localization.lang(" + e.getKey());
- a little fix, add
StringUtils.countMatches(e.getKey(), "\"") >= 2
to coverLocalization.lang(var1 + "test" + var2)
case:
assertTrue(e.getKey().startsWith("\"") || e.getKey().endsWith("\"") || StringUtils.countMatches(e.getKey(), "\"") >= 2, "Illegal localization parameter found. Must include a String with potential concatenation or replacement parameters. Illegal parameter: Localization.lang(" + e.getKey());
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.
Discussion follow-up at #11784
need to use plain string not a method result or a var to pass the unit test.
…xArxivHtmlImport * 'fixArxivHtmlImport' of github.com:JabRef/jabref: Fix focus for keywords and crossref fields (#11792) Fix ai chat not on fx thread (#11796) [AI] Add more uses statements (#11788) Update djl api dependency (#11787) Improve pdf content parser for DOIs (#11782) minor refactor to JabRefDialogService (#11767) Add more OS-dependent context to panel freeze dev documentation. (#11781)
<V>
.collect(Collectors.toList())
to.toList()
Mandatory checks
CHANGELOG.md
described in a way that is understandable for the average user (if applicable)