From d710123ad553da1abc231f83eb3b0d46439ceb4d Mon Sep 17 00:00:00 2001 From: Allan Yip Date: Thu, 7 Sep 2023 10:53:21 +0100 Subject: [PATCH 1/5] check total number of export saving order before store the preferences --- CHANGELOG.md | 1 + .../jabref/preferences/JabRefPreferences.java | 44 ++++++++++++++----- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c9f52321f1..4f501311986 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -349,6 +349,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - We fixed the shared database opening dialog to remember autosave folder and tick. [#7516](https://github.com/JabRef/jabref/issues/7516) - We fixed an issue where name formatter could not be saved. [#9120](https://github.com/JabRef/jabref/issues/9120) - We fixed a bug where after the export of Preferences, custom exports were duplicated. [#10176](https://github.com/JabRef/jabref/issues/10176) +- we fixed a bug where exception was raised when saving less than 3 export save order in preference. [#10157](https://github.com/JabRef/jabref/issues/10157) ### Removed diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index 129beb48274..21302218fc3 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -2237,11 +2237,17 @@ public ExportPreferences getExportPreferences() { } private SaveOrder getExportSaveOrder() { - List sortCriteria = List.of( - new SaveOrder.SortCriterion(FieldFactory.parseField(get(EXPORT_PRIMARY_SORT_FIELD)), getBoolean(EXPORT_PRIMARY_SORT_DESCENDING)), - new SaveOrder.SortCriterion(FieldFactory.parseField(get(EXPORT_SECONDARY_SORT_FIELD)), getBoolean(EXPORT_SECONDARY_SORT_DESCENDING)), - new SaveOrder.SortCriterion(FieldFactory.parseField(get(EXPORT_TERTIARY_SORT_FIELD)), getBoolean(EXPORT_TERTIARY_SORT_DESCENDING)) - ); + List sortCriteria = new ArrayList<>(); + + if (!get(EXPORT_PRIMARY_SORT_FIELD).equals("")) { + sortCriteria.add(new SaveOrder.SortCriterion(FieldFactory.parseField(get(EXPORT_PRIMARY_SORT_FIELD)), getBoolean(EXPORT_PRIMARY_SORT_DESCENDING))); + } + if (!get(EXPORT_SECONDARY_SORT_FIELD).equals("")) { + sortCriteria.add(new SaveOrder.SortCriterion(FieldFactory.parseField(get(EXPORT_SECONDARY_SORT_FIELD)), getBoolean(EXPORT_SECONDARY_SORT_DESCENDING))); + } + if (!get(EXPORT_TERTIARY_SORT_FIELD).equals("")) { + sortCriteria.add(new SaveOrder.SortCriterion(FieldFactory.parseField(get(EXPORT_TERTIARY_SORT_FIELD)), getBoolean(EXPORT_TERTIARY_SORT_DESCENDING))); + } return new SaveOrder( SaveOrder.OrderType.fromBooleans(getBoolean(EXPORT_IN_SPECIFIED_ORDER), getBoolean(EXPORT_IN_ORIGINAL_ORDER)), @@ -2253,12 +2259,28 @@ private void storeExportSaveOrder(SaveOrder saveOrder) { putBoolean(EXPORT_IN_ORIGINAL_ORDER, saveOrder.getOrderType() == SaveOrder.OrderType.ORIGINAL); putBoolean(EXPORT_IN_SPECIFIED_ORDER, saveOrder.getOrderType() == SaveOrder.OrderType.SPECIFIED); - put(EXPORT_PRIMARY_SORT_FIELD, saveOrder.getSortCriteria().get(0).field.getName()); - put(EXPORT_SECONDARY_SORT_FIELD, saveOrder.getSortCriteria().get(1).field.getName()); - put(EXPORT_TERTIARY_SORT_FIELD, saveOrder.getSortCriteria().get(2).field.getName()); - putBoolean(EXPORT_PRIMARY_SORT_DESCENDING, saveOrder.getSortCriteria().get(0).descending); - putBoolean(EXPORT_SECONDARY_SORT_DESCENDING, saveOrder.getSortCriteria().get(1).descending); - putBoolean(EXPORT_TERTIARY_SORT_DESCENDING, saveOrder.getSortCriteria().get(2).descending); + long saveOrderCount = saveOrder.getSortCriteria().stream().count(); + if (saveOrderCount >= 1) { + put(EXPORT_PRIMARY_SORT_FIELD, saveOrder.getSortCriteria().get(0).field.getName()); + putBoolean(EXPORT_PRIMARY_SORT_DESCENDING, saveOrder.getSortCriteria().get(0).descending); + } else { + put(EXPORT_PRIMARY_SORT_FIELD, ""); + putBoolean(EXPORT_PRIMARY_SORT_DESCENDING, false); + } + if (saveOrderCount >= 2) { + put(EXPORT_SECONDARY_SORT_FIELD, saveOrder.getSortCriteria().get(1).field.getName()); + putBoolean(EXPORT_SECONDARY_SORT_DESCENDING, saveOrder.getSortCriteria().get(1).descending); + } else { + put(EXPORT_SECONDARY_SORT_FIELD, ""); + putBoolean(EXPORT_SECONDARY_SORT_DESCENDING, false); + } + if (saveOrderCount >= 3) { + put(EXPORT_TERTIARY_SORT_FIELD, saveOrder.getSortCriteria().get(2).field.getName()); + putBoolean(EXPORT_TERTIARY_SORT_DESCENDING, saveOrder.getSortCriteria().get(2).descending); + } else { + put(EXPORT_TERTIARY_SORT_FIELD, ""); + putBoolean(EXPORT_TERTIARY_SORT_DESCENDING, false); + } } /** From 26dd5a36819304b08b9282816a45d311e6e262d7 Mon Sep 17 00:00:00 2001 From: Allan Yip Date: Thu, 7 Sep 2023 12:29:11 +0100 Subject: [PATCH 2/5] refactor to comply with JabRef code style --- src/main/java/org/jabref/preferences/JabRefPreferences.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index 21302218fc3..fde4524c273 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -2239,13 +2239,13 @@ public ExportPreferences getExportPreferences() { private SaveOrder getExportSaveOrder() { List sortCriteria = new ArrayList<>(); - if (!get(EXPORT_PRIMARY_SORT_FIELD).equals("")) { + if (!"".equals(get(EXPORT_PRIMARY_SORT_FIELD))) { sortCriteria.add(new SaveOrder.SortCriterion(FieldFactory.parseField(get(EXPORT_PRIMARY_SORT_FIELD)), getBoolean(EXPORT_PRIMARY_SORT_DESCENDING))); } - if (!get(EXPORT_SECONDARY_SORT_FIELD).equals("")) { + if (!"".equals(get(EXPORT_SECONDARY_SORT_FIELD))) { sortCriteria.add(new SaveOrder.SortCriterion(FieldFactory.parseField(get(EXPORT_SECONDARY_SORT_FIELD)), getBoolean(EXPORT_SECONDARY_SORT_DESCENDING))); } - if (!get(EXPORT_TERTIARY_SORT_FIELD).equals("")) { + if (!"".equals(get(EXPORT_TERTIARY_SORT_FIELD))) { sortCriteria.add(new SaveOrder.SortCriterion(FieldFactory.parseField(get(EXPORT_TERTIARY_SORT_FIELD)), getBoolean(EXPORT_TERTIARY_SORT_DESCENDING))); } From 367eb9f74467088dfe11153ce8978e174ab98ae1 Mon Sep 17 00:00:00 2001 From: Allan Yip Date: Sat, 9 Sep 2023 17:18:05 +0100 Subject: [PATCH 3/5] move item to unreleased section in changelog.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f501311986..a798f998e11 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - It is possible again to use "current table sort order" for the order of entries when saving. [#9869](https://github.com/JabRef/jabref/issues/9869) - Passwords can be stored in GNOME key ring. [#10274](https://github.com/JabRef/jabref/issues/10274) +- we fixed a bug where exception was raised when saving less than 3 export save order in preference. [#10157](https://github.com/JabRef/jabref/issues/10157) ### Removed @@ -349,7 +350,6 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve - We fixed the shared database opening dialog to remember autosave folder and tick. [#7516](https://github.com/JabRef/jabref/issues/7516) - We fixed an issue where name formatter could not be saved. [#9120](https://github.com/JabRef/jabref/issues/9120) - We fixed a bug where after the export of Preferences, custom exports were duplicated. [#10176](https://github.com/JabRef/jabref/issues/10176) -- we fixed a bug where exception was raised when saving less than 3 export save order in preference. [#10157](https://github.com/JabRef/jabref/issues/10157) ### Removed From 1cb4e160af80bf7af9339c4cf8d90f388bfa3de3 Mon Sep 17 00:00:00 2001 From: Allan Yip Date: Sat, 9 Sep 2023 17:42:30 +0100 Subject: [PATCH 4/5] replace getSortCriteria().stream.count() to getSortCriteria().size() --- src/main/java/org/jabref/preferences/JabRefPreferences.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/jabref/preferences/JabRefPreferences.java b/src/main/java/org/jabref/preferences/JabRefPreferences.java index fde4524c273..ba88549b5b0 100644 --- a/src/main/java/org/jabref/preferences/JabRefPreferences.java +++ b/src/main/java/org/jabref/preferences/JabRefPreferences.java @@ -2259,7 +2259,7 @@ private void storeExportSaveOrder(SaveOrder saveOrder) { putBoolean(EXPORT_IN_ORIGINAL_ORDER, saveOrder.getOrderType() == SaveOrder.OrderType.ORIGINAL); putBoolean(EXPORT_IN_SPECIFIED_ORDER, saveOrder.getOrderType() == SaveOrder.OrderType.SPECIFIED); - long saveOrderCount = saveOrder.getSortCriteria().stream().count(); + long saveOrderCount = saveOrder.getSortCriteria().size(); if (saveOrderCount >= 1) { put(EXPORT_PRIMARY_SORT_FIELD, saveOrder.getSortCriteria().get(0).field.getName()); putBoolean(EXPORT_PRIMARY_SORT_DESCENDING, saveOrder.getSortCriteria().get(0).descending); From b37036b744bf050bd56b67195fa4439ff01af14e Mon Sep 17 00:00:00 2001 From: Christoph Date: Sat, 9 Sep 2023 19:27:35 +0200 Subject: [PATCH 5/5] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 46e2e455a4d..ca90aba82bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,7 +21,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv - It is possible again to use "current table sort order" for the order of entries when saving. [#9869](https://github.com/JabRef/jabref/issues/9869) - Passwords can be stored in GNOME key ring. [#10274](https://github.com/JabRef/jabref/issues/10274) - we fixed a bug where exception was raised when saving less than 3 export save order in preference. [#10157](https://github.com/JabRef/jabref/issues/10157) -- We fixed an issue were groups based on an aux file could not be created due to an exception [#10350](https://github.com/JabRef/jabref/issues/10352) +- We fixed an issue where groups based on an aux file could not be created due to an exception [#10350](https://github.com/JabRef/jabref/issues/10352) ### Removed