From c7f6da3f8a6b9b6aeb64ec2526bd6929d4d67965 Mon Sep 17 00:00:00 2001 From: Kunal Shroff Date: Fri, 4 Oct 2024 15:31:27 -0400 Subject: [PATCH 01/12] refactor the sar epics parts into a utility module --- .../saveandrestore/util}/SnapshotUtil.java | 0 .../src/test/java/util}/SnapshotUtilTest.java | 3 -- .../epics/SnapshotUtilTestConfig.java | 44 ------------------- 3 files changed, 47 deletions(-) rename {services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/epics => app/save-and-restore/util/src/main/java/org/phoebus/saveandrestore/util}/SnapshotUtil.java (100%) rename {services/save-and-restore/src/test/java/org/phoebus/service/saveandrestore/epics => app/save-and-restore/util/src/test/java/util}/SnapshotUtilTest.java (95%) delete mode 100644 services/save-and-restore/src/test/java/org/phoebus/service/saveandrestore/epics/SnapshotUtilTestConfig.java diff --git a/services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/epics/SnapshotUtil.java b/app/save-and-restore/util/src/main/java/org/phoebus/saveandrestore/util/SnapshotUtil.java similarity index 100% rename from services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/epics/SnapshotUtil.java rename to app/save-and-restore/util/src/main/java/org/phoebus/saveandrestore/util/SnapshotUtil.java diff --git a/services/save-and-restore/src/test/java/org/phoebus/service/saveandrestore/epics/SnapshotUtilTest.java b/app/save-and-restore/util/src/test/java/util/SnapshotUtilTest.java similarity index 95% rename from services/save-and-restore/src/test/java/org/phoebus/service/saveandrestore/epics/SnapshotUtilTest.java rename to app/save-and-restore/util/src/test/java/util/SnapshotUtilTest.java index 55dbfb7d95..a369445630 100644 --- a/services/save-and-restore/src/test/java/org/phoebus/service/saveandrestore/epics/SnapshotUtilTest.java +++ b/app/save-and-restore/util/src/test/java/util/SnapshotUtilTest.java @@ -27,10 +27,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.phoebus.applications.saveandrestore.model.ConfigPv; -import org.phoebus.applications.saveandrestore.model.Configuration; import org.phoebus.applications.saveandrestore.model.ConfigurationData; -import org.phoebus.applications.saveandrestore.model.Node; -import org.phoebus.applications.saveandrestore.model.NodeType; import org.phoebus.applications.saveandrestore.model.SnapshotItem; import org.phoebus.core.vtypes.VTypeHelper; import org.phoebus.pv.PV; diff --git a/services/save-and-restore/src/test/java/org/phoebus/service/saveandrestore/epics/SnapshotUtilTestConfig.java b/services/save-and-restore/src/test/java/org/phoebus/service/saveandrestore/epics/SnapshotUtilTestConfig.java deleted file mode 100644 index 4b1bf43a61..0000000000 --- a/services/save-and-restore/src/test/java/org/phoebus/service/saveandrestore/epics/SnapshotUtilTestConfig.java +++ /dev/null @@ -1,44 +0,0 @@ -/** - * Copyright (C) 2018 European Spallation Source ERIC. - *

- * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - *

- * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - *

- * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -package org.phoebus.service.saveandrestore.epics; - -import org.springframework.boot.SpringBootConfiguration; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Profile; - -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -@SpringBootConfiguration -@ComponentScan(basePackages = "org.phoebus.service.saveandrestore.epics") -@SuppressWarnings("unused") -@Profile("!IT") -public class SnapshotUtilTestConfig { - - @Bean - public SnapshotUtil snapshotRestorer(){ - return new SnapshotUtil(); - } - - @Bean - public ExecutorService executorService(){ - return Executors.newCachedThreadPool(); - } -} From edc1ee508cda3136570a2e203fac1fb7487e860f Mon Sep 17 00:00:00 2001 From: Kunal Shroff Date: Fri, 4 Oct 2024 15:32:11 -0400 Subject: [PATCH 02/12] New Save and Restore utility module --- app/save-and-restore/pom.xml | 1 + app/save-and-restore/util/pom.xml | 60 +++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 app/save-and-restore/util/pom.xml diff --git a/app/save-and-restore/pom.xml b/app/save-and-restore/pom.xml index d2da448a85..c3e53e4b8a 100644 --- a/app/save-and-restore/pom.xml +++ b/app/save-and-restore/pom.xml @@ -11,5 +11,6 @@ model app logging + util diff --git a/app/save-and-restore/util/pom.xml b/app/save-and-restore/util/pom.xml new file mode 100644 index 0000000000..06eb34f870 --- /dev/null +++ b/app/save-and-restore/util/pom.xml @@ -0,0 +1,60 @@ + + + + org.phoebus + app-save-and-restore + 4.7.4-SNAPSHOT + + 4.0.0 + + save-and-restore-util + + + 17 + 17 + + + + + org.phoebus + save-and-restore-model + 4.7.4-SNAPSHOT + + + + org.phoebus + core-pva + 4.7.4-SNAPSHOT + + + org.phoebus + core-pv + 4.7.4-SNAPSHOT + + + org.phoebus + core-pv-pva + 4.7.4-SNAPSHOT + + + org.phoebus + core-pv-ca + 4.7.4-SNAPSHOT + + + org.phoebus + core-vtype + 4.7.4-SNAPSHOT + + + + org.junit.jupiter + junit-jupiter + ${junit.version} + test + + + + \ No newline at end of file From 3dadeb2031aa38d22dcec1af9f45a03d7f3aea0e Mon Sep 17 00:00:00 2001 From: Kunal Shroff Date: Fri, 4 Oct 2024 15:38:18 -0400 Subject: [PATCH 03/12] New preferences for configuring snaphost/restore timeouts --- .../saveandrestore/util/Preferences.java | 45 +++++++++++++++++++ ...ve_and_restore_util_preferences.properties | 9 ++++ 2 files changed, 54 insertions(+) create mode 100644 app/save-and-restore/util/src/main/java/org/phoebus/saveandrestore/util/Preferences.java create mode 100644 app/save-and-restore/util/src/main/resources/save_and_restore_util_preferences.properties diff --git a/app/save-and-restore/util/src/main/java/org/phoebus/saveandrestore/util/Preferences.java b/app/save-and-restore/util/src/main/java/org/phoebus/saveandrestore/util/Preferences.java new file mode 100644 index 0000000000..2e0e7e6bed --- /dev/null +++ b/app/save-and-restore/util/src/main/java/org/phoebus/saveandrestore/util/Preferences.java @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2024 European Spallation Source ERIC. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +package org.phoebus.saveandrestore.util; + +import org.phoebus.framework.preferences.AnnotatedPreferences; +import org.phoebus.framework.preferences.Preference; + +/** + * Preferences for save-and-restore. HTTP connection preferences managed in sub-package class + * {@link org.phoebus.saveandrestore.util.Preferences} + */ +public class Preferences { + + /** + * Timeout for PV read operations when taking snapshot. + */ + @Preference + public static int connectionTimeout; + + /** + * Page size used in search UI. + */ + @Preference + public static int writeTimeout; + + static { + AnnotatedPreferences.initialize(Preferences.class, "/save_and_restore_util_preferences.properties"); + } +} diff --git a/app/save-and-restore/util/src/main/resources/save_and_restore_util_preferences.properties b/app/save-and-restore/util/src/main/resources/save_and_restore_util_preferences.properties new file mode 100644 index 0000000000..40254d8408 --- /dev/null +++ b/app/save-and-restore/util/src/main/resources/save_and_restore_util_preferences.properties @@ -0,0 +1,9 @@ +# ----------------------------------------------- +# Package org.phoebus.applications.saveandrestore +# ----------------------------------------------- + +# connection timeout (in ms) when taking snapshot +connectionTimeout=5000 + +# write timeout (in ms) when restoring snapshot +writeTimeout=5000 \ No newline at end of file From e8a34ebd7555a6f6d8b21c24824b172cb0597802 Mon Sep 17 00:00:00 2001 From: Kunal Shroff Date: Fri, 4 Oct 2024 15:56:01 -0400 Subject: [PATCH 04/12] Cleanup the save and restore services dependencies --- services/save-and-restore/pom.xml | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/services/save-and-restore/pom.xml b/services/save-and-restore/pom.xml index af9ec06968..e8087d6e79 100644 --- a/services/save-and-restore/pom.xml +++ b/services/save-and-restore/pom.xml @@ -66,33 +66,13 @@ org.phoebus - core-util + save-and-restore-util 4.7.4-SNAPSHOT org.phoebus - core-pva - 4.7.4-SNAPSHOT - - - org.phoebus - core-pv - 4.7.4-SNAPSHOT - - - org.phoebus - core-pv-pva - 4.7.4-SNAPSHOT - - - org.phoebus - core-pv-ca - 4.7.4-SNAPSHOT - - - org.phoebus - core-vtype + core-util 4.7.4-SNAPSHOT From 02dd814c4e54248eced0dbd222abfe8d5294fca2 Mon Sep 17 00:00:00 2001 From: Kunal Shroff Date: Fri, 4 Oct 2024 16:28:29 -0400 Subject: [PATCH 05/12] Fix the Util initialization/preferences (not using spring annotations) --- .../saveandrestore/util/SnapshotUtil.java | 17 ++++++---------- .../src/test/java/util/SnapshotUtilTest.java | 20 +++++++++---------- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/app/save-and-restore/util/src/main/java/org/phoebus/saveandrestore/util/SnapshotUtil.java b/app/save-and-restore/util/src/main/java/org/phoebus/saveandrestore/util/SnapshotUtil.java index 000c251276..09fa07a073 100644 --- a/app/save-and-restore/util/src/main/java/org/phoebus/saveandrestore/util/SnapshotUtil.java +++ b/app/save-and-restore/util/src/main/java/org/phoebus/saveandrestore/util/SnapshotUtil.java @@ -1,4 +1,4 @@ -package org.phoebus.service.saveandrestore.epics; +package org.phoebus.saveandrestore.util; import org.epics.vtype.VType; import org.phoebus.applications.saveandrestore.model.ConfigPv; @@ -7,11 +7,10 @@ import org.phoebus.applications.saveandrestore.model.RestoreResult; import org.phoebus.applications.saveandrestore.model.SnapshotItem; import org.phoebus.core.vtypes.VTypeHelper; +import org.phoebus.framework.preferences.Preference; import org.phoebus.framework.preferences.PropertyPreferenceLoader; import org.phoebus.pv.PV; import org.phoebus.pv.PVPool; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import java.io.File; import java.io.FileInputStream; @@ -23,6 +22,7 @@ import java.util.concurrent.Callable; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import java.util.logging.Level; import java.util.logging.Logger; @@ -34,16 +34,11 @@ public class SnapshotUtil { private final Logger LOG = Logger.getLogger(SnapshotUtil.class.getName()); - @SuppressWarnings("unused") - @Value("${connection.timeout:5000}") - private int connectionTimeout; + private int connectionTimeout = Preferences.connectionTimeout; - @SuppressWarnings("unused") - @Value("${write.timeout:5000}") - private int writeTimeout; + private int writeTimeout = Preferences.writeTimeout; - @Autowired - private ExecutorService executorService; + private ExecutorService executorService = Executors.newCachedThreadPool(); public SnapshotUtil() { final File site_settings = new File("settings.ini"); diff --git a/app/save-and-restore/util/src/test/java/util/SnapshotUtilTest.java b/app/save-and-restore/util/src/test/java/util/SnapshotUtilTest.java index a369445630..1719094522 100644 --- a/app/save-and-restore/util/src/test/java/util/SnapshotUtilTest.java +++ b/app/save-and-restore/util/src/test/java/util/SnapshotUtilTest.java @@ -17,33 +17,33 @@ * */ -package org.phoebus.service.saveandrestore.epics; +package util; import org.epics.vtype.Alarm; import org.epics.vtype.Display; import org.epics.vtype.Time; import org.epics.vtype.VFloat; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; import org.phoebus.applications.saveandrestore.model.ConfigPv; import org.phoebus.applications.saveandrestore.model.ConfigurationData; import org.phoebus.applications.saveandrestore.model.SnapshotItem; import org.phoebus.core.vtypes.VTypeHelper; import org.phoebus.pv.PV; import org.phoebus.pv.PVPool; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit.jupiter.SpringExtension; +import org.phoebus.saveandrestore.util.SnapshotUtil; import java.util.List; -@ExtendWith(SpringExtension.class) -@ContextConfiguration(classes = SnapshotUtilTestConfig.class) public class SnapshotUtilTest { - @Autowired - private SnapshotUtil snapshotUtil; + private static SnapshotUtil snapshotUtil; + + @BeforeAll + public static void setup(){ + snapshotUtil = new SnapshotUtil(); + } @Test public void testRestorePVValues() throws Exception { @@ -74,7 +74,7 @@ public void testCannotConnectPV() { @Test public void testTakeSnapshot(){ - ConfigurationData configurationData = new ConfigurationData(); + ConfigurationData configurationData = new ConfigurationData(); ConfigPv configPv = new ConfigPv(); configPv.setPvName("loc://x(42.0)"); configPv.setReadbackPvName("loc://y(777.0)"); From 5258ec0cbc2b912058e95f6d90ef72761dd74bde Mon Sep 17 00:00:00 2001 From: Kunal Shroff Date: Mon, 7 Oct 2024 10:34:22 -0400 Subject: [PATCH 06/12] Fix imports in SAR service controllers and tests --- .../service/saveandrestore/web/config/WebConfiguration.java | 2 +- .../web/controllers/SnapshotRestoreController.java | 2 +- .../saveandrestore/web/controllers/TakeSnapshotController.java | 2 +- .../saveandrestore/web/config/ControllersTestConfig.java | 2 +- .../web/controllers/TakeSnapshotControllerTest.java | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/web/config/WebConfiguration.java b/services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/web/config/WebConfiguration.java index c6dcb4ca62..dc7b2eeab6 100644 --- a/services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/web/config/WebConfiguration.java +++ b/services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/web/config/WebConfiguration.java @@ -17,7 +17,7 @@ */ package org.phoebus.service.saveandrestore.web.config; -import org.phoebus.service.saveandrestore.epics.SnapshotUtil; +import org.phoebus.saveandrestore.util.SnapshotUtil; import org.phoebus.service.saveandrestore.persistence.dao.NodeDAO; import org.phoebus.service.saveandrestore.persistence.dao.impl.elasticsearch.ElasticsearchDAO; import org.springframework.context.annotation.Bean; diff --git a/services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/web/controllers/SnapshotRestoreController.java b/services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/web/controllers/SnapshotRestoreController.java index 52831baa19..55644a8fe7 100644 --- a/services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/web/controllers/SnapshotRestoreController.java +++ b/services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/web/controllers/SnapshotRestoreController.java @@ -20,7 +20,7 @@ import org.phoebus.applications.saveandrestore.model.Node; import org.phoebus.applications.saveandrestore.model.RestoreResult; import org.phoebus.applications.saveandrestore.model.SnapshotItem; -import org.phoebus.service.saveandrestore.epics.SnapshotUtil; +import org.phoebus.saveandrestore.util.SnapshotUtil; import org.phoebus.service.saveandrestore.persistence.dao.NodeDAO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PostMapping; diff --git a/services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/web/controllers/TakeSnapshotController.java b/services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/web/controllers/TakeSnapshotController.java index f04d7166bb..33ae7ffae6 100644 --- a/services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/web/controllers/TakeSnapshotController.java +++ b/services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/web/controllers/TakeSnapshotController.java @@ -10,7 +10,7 @@ import org.phoebus.applications.saveandrestore.model.Snapshot; import org.phoebus.applications.saveandrestore.model.SnapshotData; import org.phoebus.applications.saveandrestore.model.SnapshotItem; -import org.phoebus.service.saveandrestore.epics.SnapshotUtil; +import org.phoebus.saveandrestore.util.SnapshotUtil; import org.phoebus.service.saveandrestore.persistence.dao.NodeDAO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; diff --git a/services/save-and-restore/src/test/java/org/phoebus/service/saveandrestore/web/config/ControllersTestConfig.java b/services/save-and-restore/src/test/java/org/phoebus/service/saveandrestore/web/config/ControllersTestConfig.java index ff8a383ab7..27035af68c 100644 --- a/services/save-and-restore/src/test/java/org/phoebus/service/saveandrestore/web/config/ControllersTestConfig.java +++ b/services/save-and-restore/src/test/java/org/phoebus/service/saveandrestore/web/config/ControllersTestConfig.java @@ -20,7 +20,7 @@ import co.elastic.clients.elasticsearch.ElasticsearchClient; import org.mockito.Mockito; -import org.phoebus.service.saveandrestore.epics.SnapshotUtil; +import org.phoebus.saveandrestore.util.SnapshotUtil; import org.phoebus.service.saveandrestore.persistence.dao.NodeDAO; import org.phoebus.service.saveandrestore.persistence.dao.impl.elasticsearch.ConfigurationDataRepository; import org.phoebus.service.saveandrestore.persistence.dao.impl.elasticsearch.ElasticsearchTreeRepository; diff --git a/services/save-and-restore/src/test/java/org/phoebus/service/saveandrestore/web/controllers/TakeSnapshotControllerTest.java b/services/save-and-restore/src/test/java/org/phoebus/service/saveandrestore/web/controllers/TakeSnapshotControllerTest.java index 743e9c295b..37dfc128c1 100644 --- a/services/save-and-restore/src/test/java/org/phoebus/service/saveandrestore/web/controllers/TakeSnapshotControllerTest.java +++ b/services/save-and-restore/src/test/java/org/phoebus/service/saveandrestore/web/controllers/TakeSnapshotControllerTest.java @@ -7,8 +7,8 @@ import org.phoebus.applications.saveandrestore.model.ConfigurationData; import org.phoebus.applications.saveandrestore.model.Node; import org.phoebus.applications.saveandrestore.model.SnapshotItem; +import org.phoebus.saveandrestore.util.SnapshotUtil; import org.phoebus.service.saveandrestore.NodeNotFoundException; -import org.phoebus.service.saveandrestore.epics.SnapshotUtil; import org.phoebus.service.saveandrestore.persistence.dao.NodeDAO; import org.phoebus.service.saveandrestore.web.config.ControllersTestConfig; import org.springframework.beans.factory.annotation.Autowired; From 7edc5d16ddbc4a8affa95c84ffdc881de7601932 Mon Sep 17 00:00:00 2001 From: Kunal Shroff Date: Mon, 7 Oct 2024 13:08:35 -0400 Subject: [PATCH 07/12] add tags no longer allows comments (old tags displayed without comments) --- .../applications/saveandrestore/Messages.java | 4 ++++ .../ui/ContextMenuCompositeSnapshot.java | 22 +++++++++---------- .../ui/ContextMenuSnapshot.java | 20 ++++++++--------- .../saveandrestore/ui/ImageRepository.java | 2 +- .../ui/SaveAndRestoreController.java | 8 +++---- .../search/SearchAndFilterViewController.java | 12 +++++----- .../ui/snapshot/SnapshotNewTagDialog.java | 12 +++------- .../ui/snapshot/tag/TagUtil.java | 10 ++++----- .../ui/snapshot/tag/TagWidget.java | 16 ++++++-------- .../saveandrestore/messages.properties | 2 ++ .../saveandrestore/messages_fr.properties | 2 ++ 11 files changed, 54 insertions(+), 56 deletions(-) diff --git a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/Messages.java b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/Messages.java index 2199353ba3..e397f3b2aa 100644 --- a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/Messages.java +++ b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/Messages.java @@ -36,6 +36,8 @@ public class Messages { public static String closeCompositeSnapshotWarning; public static String closeTabPrompt; public static String compositeSnapshotConsistencyCheckFailed; + public static String contextMenuAddTag; + @Deprecated public static String contextMenuAddTagWithComment; public static String contextMenuCreateSnapshot; public static String contextMenuCompareSnapshots; @@ -52,6 +54,8 @@ public class Messages { public static String contextMenuRename; public static String contextMenuRemoveGoldenTag; public static String contextMenuTagAsGolden; + public static String contextMenuTags; + @Deprecated public static String contextMenuTagsWithComment; public static String contextMenuOpenCompositeSnapshotForRestore; diff --git a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/ContextMenuCompositeSnapshot.java b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/ContextMenuCompositeSnapshot.java index d824a948b7..5f0c73d511 100644 --- a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/ContextMenuCompositeSnapshot.java +++ b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/ContextMenuCompositeSnapshot.java @@ -38,7 +38,7 @@ public class ContextMenuCompositeSnapshot extends ContextMenuBase { public ContextMenuCompositeSnapshot(SaveAndRestoreController saveAndRestoreController) { super(saveAndRestoreController); - Image snapshotTagsWithCommentIcon = ImageCache.getImage(SaveAndRestoreController.class, "/icons/save-and-restore/snapshot-tags.png"); + Image snapshotTagsIcon = ImageCache.getImage(SaveAndRestoreController.class, "/icons/save-and-restore/snapshot-tags.png"); MenuItem editCompositeSnapshotMenuItem = new MenuItem(Messages.Edit, new ImageView(ImageRepository.EDIT_CONFIGURATION)); editCompositeSnapshotMenuItem.disableProperty().bind(multipleNodesSelectedProperty); @@ -48,20 +48,20 @@ public ContextMenuCompositeSnapshot(SaveAndRestoreController saveAndRestoreContr userIsAuthenticatedProperty.not().get() || multipleNodesSelectedProperty.get(), userIsAuthenticatedProperty, multipleNodesSelectedProperty)); - ImageView snapshotTagsWithCommentIconImage = new ImageView(snapshotTagsWithCommentIcon); - snapshotTagsWithCommentIconImage.setFitHeight(22); - snapshotTagsWithCommentIconImage.setFitWidth(22); + ImageView snapshotTagsIconImage = new ImageView(snapshotTagsIcon); + snapshotTagsIconImage.setFitHeight(22); + snapshotTagsIconImage.setFitWidth(22); - Menu tagWithComment = new Menu(Messages.contextMenuTagsWithComment, snapshotTagsWithCommentIconImage); - tagWithComment.setOnShowing(event -> saveAndRestoreController.tagWithComment(tagWithComment)); - tagWithComment.disableProperty().bind(Bindings.createBooleanBinding(() -> + Menu tags = new Menu(Messages.contextMenuTags, snapshotTagsIconImage); + tags.setOnShowing(event -> saveAndRestoreController.tag(tags)); + tags.disableProperty().bind(Bindings.createBooleanBinding(() -> multipleNodesSelectedProperty.get() || userIsAuthenticatedProperty.not().get(), multipleNodesSelectedProperty, userIsAuthenticatedProperty)); - CustomMenuItem addTagWithCommentMenuItem = TagWidget.AddTagWithCommentMenuItem(); - addTagWithCommentMenuItem.setOnAction(action -> saveAndRestoreController.addTagToSnapshots()); + CustomMenuItem addTagMenuItem = TagWidget.AddTagMenuItem(); + addTagMenuItem.setOnAction(action -> saveAndRestoreController.addTagToSnapshots()); - tagWithComment.getItems().addAll(addTagWithCommentMenuItem, new SeparatorMenuItem()); + tags.getItems().addAll(addTagMenuItem, new SeparatorMenuItem()); Image copyIcon = ImageCache.getImage(SaveAndRestoreController.class, "/icons/copy.png"); MenuItem copyMenuItem = new MenuItem(Messages.copy, new ImageView(copyIcon)); @@ -76,7 +76,7 @@ public ContextMenuCompositeSnapshot(SaveAndRestoreController saveAndRestoreContr copyMenuItem, deleteNodesMenuItem, copyUniqueIdToClipboardMenuItem, - tagWithComment); + tags); } /** diff --git a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/ContextMenuSnapshot.java b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/ContextMenuSnapshot.java index 324e05531d..3334fa3919 100644 --- a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/ContextMenuSnapshot.java +++ b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/ContextMenuSnapshot.java @@ -40,7 +40,7 @@ public class ContextMenuSnapshot extends ContextMenuBase { private final MenuItem tagGoldenMenuItem; - private final Menu tagWithComment; + private final Menu tags; private final SimpleBooleanProperty mayTagProperty = new SimpleBooleanProperty(); @@ -55,21 +55,21 @@ public ContextMenuSnapshot(SaveAndRestoreController saveAndRestoreController) { compareSnapshotsMenuItem.setOnAction(ae -> saveAndRestoreController.compareSnapshot()); compareSnapshotsMenuItem.disableProperty().bind(mayCompareSnapshotsProperty.not()); - ImageView snapshotTagsWithCommentIconImage = new ImageView(ImageRepository.SNAPSHOT_ADD_TAG_WITH_COMMENT); + ImageView snapshotTagsIconImage = new ImageView(ImageRepository.SNAPSHOT_ADD_TAG); - tagWithComment = new Menu(Messages.contextMenuTagsWithComment, snapshotTagsWithCommentIconImage); - tagWithComment.setOnShowing(event -> saveAndRestoreController.tagWithComment(tagWithComment)); - tagWithComment.disableProperty().bind(Bindings.createBooleanBinding(() -> + tags = new Menu(Messages.contextMenuTags, snapshotTagsIconImage); + tags.setOnShowing(event -> saveAndRestoreController.tag(tags)); + tags.disableProperty().bind(Bindings.createBooleanBinding(() -> multipleNodesSelectedProperty.get() || userIsAuthenticatedProperty.not().get(), multipleNodesSelectedProperty, userIsAuthenticatedProperty)); - MenuItem addTagWithCommentMenuItem = TagWidget.AddTagWithCommentMenuItem(); - addTagWithCommentMenuItem.setOnAction(action -> saveAndRestoreController.addTagToSnapshots()); - addTagWithCommentMenuItem.disableProperty().bind(Bindings.createBooleanBinding(() -> + MenuItem addTagMenuItem = TagWidget.AddTagMenuItem(); + addTagMenuItem.setOnAction(action -> saveAndRestoreController.addTagToSnapshots()); + addTagMenuItem.disableProperty().bind(Bindings.createBooleanBinding(() -> multipleNodesSelectedProperty.get() || mayTagProperty.not().get(), multipleNodesSelectedProperty, mayTagProperty)); - tagWithComment.getItems().addAll(addTagWithCommentMenuItem); + tags.getItems().addAll(addTagMenuItem); MenuItem findReferencesMenuItem = new MenuItem(Messages.findSnapshotReferences, new ImageView(ImageRepository.COMPOSITE_SNAPSHOT)); findReferencesMenuItem.setOnAction(ae -> saveAndRestoreController.findSnapshotReferences()); @@ -97,7 +97,7 @@ public ContextMenuSnapshot(SaveAndRestoreController saveAndRestoreController) { deleteNodesMenuItem, compareSnapshotsMenuItem, tagGoldenMenuItem, - tagWithComment, + tags, copyMenuItem, copyUniqueIdToClipboardMenuItem, exportSnapshotMenuItem); diff --git a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/ImageRepository.java b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/ImageRepository.java index ddaaeb2b25..6e2560590a 100644 --- a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/ImageRepository.java +++ b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/ImageRepository.java @@ -43,7 +43,7 @@ public class ImageRepository { public static final Image EDIT_CONFIGURATION = ImageCache.getImage(ImageRepository.class, "/icons/save-and-restore/edit-configuration.png"); - public static final Image SNAPSHOT_ADD_TAG_WITH_COMMENT = + public static final Image SNAPSHOT_ADD_TAG = ImageCache.getImage(ImageRepository.class, "/icons/save-and-restore/snapshot-add_tag.png"); public static final Image DELETE = ImageCache.getImage(SaveAndRestoreController.class, "/icons/delete.png"); diff --git a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/SaveAndRestoreController.java b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/SaveAndRestoreController.java index acb8d8ff3f..25901adfc6 100644 --- a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/SaveAndRestoreController.java +++ b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/SaveAndRestoreController.java @@ -1026,17 +1026,17 @@ protected void addTagToSnapshots() { } /** - * Configures the "tag with comment" sub-menu. Items are added based on existing {@link Tag}s on the + * Configures the "tag" sub-menu. Items are added based on existing {@link Tag}s on the * selected {@link Node}s * - * @param tagWithCommentMenu The {@link Menu} subject to configuration. + * @param tagMenu The {@link Menu} subject to configuration. */ - public void tagWithComment(final Menu tagWithCommentMenu) { + public void tag(final Menu tagMenu) { List selectedNodes = browserSelectionModel.getSelectedItems().stream().map(TreeItem::getValue).collect(Collectors.toList()); - TagUtil.tagWithComment(tagWithCommentMenu, selectedNodes, updatedNodes -> updatedNodes.forEach(this::nodeChanged)); + TagUtil.tag(tagMenu, selectedNodes, updatedNodes -> updatedNodes.forEach(this::nodeChanged)); } /** diff --git a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/search/SearchAndFilterViewController.java b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/search/SearchAndFilterViewController.java index cbdd101c9c..a2b8bb7249 100644 --- a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/search/SearchAndFilterViewController.java +++ b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/search/SearchAndFilterViewController.java @@ -417,12 +417,12 @@ protected void updateItem(Node node, boolean empty) { ContextMenu contextMenu = new ContextMenu(); MenuItem tagGoldenMenuItem = new MenuItem(Messages.contextMenuTagAsGolden, new ImageView(ImageRepository.SNAPSHOT)); - ImageView snapshotTagsWithCommentIconImage = new ImageView(ImageRepository.SNAPSHOT_ADD_TAG_WITH_COMMENT); - Menu tagMenuItem = new Menu(Messages.contextMenuTagsWithComment, snapshotTagsWithCommentIconImage); + ImageView snapshotTagsIconImage = new ImageView(ImageRepository.SNAPSHOT_ADD_TAG); + Menu tagMenuItem = new Menu(Messages.contextMenuTags, snapshotTagsIconImage); - MenuItem addTagWithCommentMenuItem = TagWidget.AddTagWithCommentMenuItem(); - addTagWithCommentMenuItem.setOnAction(event -> TagUtil.addTag(resultTableView.getSelectionModel().getSelectedItems())); - tagMenuItem.getItems().add(addTagWithCommentMenuItem); + MenuItem addTagMenuItem = TagWidget.AddTagMenuItem(); + addTagMenuItem.setOnAction(event -> TagUtil.addTag(resultTableView.getSelectionModel().getSelectedItems())); + tagMenuItem.getItems().add(addTagMenuItem); MenuItem restoreMenuItem = new MenuItem(Messages.restore); restoreMenuItem.setOnAction(e -> doRestore(resultTableView.getSelectionModel().getSelectedItem().getUniqueId())); @@ -430,7 +430,7 @@ protected void updateItem(Node node, boolean empty) { contextMenu.setOnShowing(event -> { NodeType selectedItemType = resultTableView.getSelectionModel().getSelectedItem().getNodeType(); if (selectedItemType.equals(NodeType.SNAPSHOT)) { - TagUtil.tagWithComment(tagMenuItem, + TagUtil.tag(tagMenuItem, resultTableView.getSelectionModel().getSelectedItems(), updatedNodes -> { // Callback, any extra handling added here }); diff --git a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotNewTagDialog.java b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotNewTagDialog.java index 99bdfbbe2b..7a0e11638d 100644 --- a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotNewTagDialog.java +++ b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotNewTagDialog.java @@ -50,7 +50,7 @@ * @author Genie Jhang */ -public class SnapshotNewTagDialog extends Dialog> { +public class SnapshotNewTagDialog extends Dialog { private final TextInputControl tagNameTextField; @@ -81,21 +81,15 @@ public SnapshotNewTagDialog(List nodes) { gridPane.setPadding(new Insets(12, 8, 3, 8)); Label tagNameLabel = new Label(Messages.tagNameLabel); - Label tagCommentLabel = new Label(Messages.tagCommentLabel); GridPane.setHalignment(tagNameLabel, HPos.RIGHT); - GridPane.setHalignment(tagCommentLabel, HPos.RIGHT); - tagNameTextField = new TextField(); - TextField tagCommentTextField = new TextField(); +// TextField tagCommentTextField = new TextField(); tagNameTextField.setMinWidth(400); - tagCommentTextField.setMinWidth(400); gridPane.add(tagNameLabel, 0, 0); - gridPane.add(tagCommentLabel, 0, 1); gridPane.add(tagNameTextField, 1, 0); - gridPane.add(tagCommentTextField, 1, 1); getDialogPane().setContent(gridPane); @@ -117,7 +111,7 @@ public SnapshotNewTagDialog(List nodes) { setResultConverter(dialogButton -> { if (dialogButton == saveTagButton) { - return new Pair<>(tagNameTextField.getText(), tagCommentTextField.getText()); + return tagNameTextField.getText(); } return null; diff --git a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/tag/TagUtil.java b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/tag/TagUtil.java index 75666e05cb..132ab559b1 100644 --- a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/tag/TagUtil.java +++ b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/tag/TagUtil.java @@ -46,7 +46,6 @@ import org.phoebus.ui.autocomplete.AutocompleteMenu; import org.phoebus.ui.dialog.ExceptionDetailsErrorDialog; -import java.text.MessageFormat; import java.util.ArrayList; import java.util.Collections; import java.util.Date; @@ -93,7 +92,7 @@ public static List getCommonTags(List selectedNodes, Consumer> callback) { AtomicInteger nonSnapshotCount = new AtomicInteger(0); @@ -119,7 +118,7 @@ public static void tagWithComment(Menu parentMenu, additionalItems.add(new SeparatorMenuItem()); commonTags.sort(new TagComparator()); commonTags.forEach(tag -> { - CustomMenuItem tagItem = TagWidget.TagWithCommentMenuItem(tag); + CustomMenuItem tagItem = TagWidget.TagMenuItem(tag); tagItem.setOnAction(actionEvent -> { Alert confirmation = new Alert(AlertType.CONFIRMATION); confirmation.setTitle(Messages.tagRemoveConfirmationTitle); @@ -159,11 +158,10 @@ public static List addTag(Li AutocompleteMenu autocompleteMenu = new AutocompleteMenu(proposalService); snapshotNewTagDialog.configureAutocompleteMenu(autocompleteMenu); List updatedNodes = new ArrayList<>(); - Optional> result = snapshotNewTagDialog.showAndWait(); + Optional result = snapshotNewTagDialog.showAndWait(); result.ifPresent(items -> { Tag aNewTag = Tag.builder() - .name(items.getKey()) - .comment(items.getValue()) + .name(items.trim()) .created(new Date()) .userName(System.getProperty("user.name")) .build(); diff --git a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/tag/TagWidget.java b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/tag/TagWidget.java index f468874f60..a82b641852 100644 --- a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/tag/TagWidget.java +++ b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/tag/TagWidget.java @@ -51,8 +51,8 @@ */ public class TagWidget { - public static final Image snapshotTagWithCommentIcon = ImageCache.getImage(SaveAndRestoreController.class, "/icons/save-and-restore/snapshot-tag.png"); - public static final Image snapshotAddTagWithCommentIcon = ImageCache.getImage(SaveAndRestoreController.class, "/icons/save-and-restore/snapshot-add_tag.png"); + public static final Image snapshotTagIcon = ImageCache.getImage(SaveAndRestoreController.class, "/icons/save-and-restore/snapshot-tag.png"); + public static final Image snapshotAddTagIcon = ImageCache.getImage(SaveAndRestoreController.class, "/icons/save-and-restore/snapshot-add_tag.png"); public static final Image snapshotTrashcanIcon = ImageCache.getImage(SaveAndRestoreController.class, "/icons/save-and-restore/snapshot-trashcan.png"); /** @@ -110,8 +110,8 @@ private static CustomMenuItem getBaseWidget(Image image, String text) { * * @return Add {@link Tag} {@link CustomMenuItem} */ - public static CustomMenuItem AddTagWithCommentMenuItem() { - return getBaseWidget(snapshotAddTagWithCommentIcon, Messages.contextMenuAddTagWithComment); + public static CustomMenuItem AddTagMenuItem() { + return getBaseWidget(snapshotAddTagIcon, Messages.contextMenuAddTag); } /** @@ -129,14 +129,12 @@ public static CustomMenuItem NoTagMenuItem() { * @param tag {@link Tag} to show * @return {@link CustomMenuItem} with a customized {@link Node} */ - public static CustomMenuItem TagWithCommentMenuItem(Tag tag) { - ImageView imageView = new ImageView(snapshotTagWithCommentIcon); + public static CustomMenuItem TagMenuItem(Tag tag) { + ImageView imageView = new ImageView(snapshotTagIcon); imageView.setFitWidth(22); imageView.setFitHeight(22); Label tagName = new Label(tag.getName()); - Label tagComment = new Label(tag.getComment()); - tagComment.setFont(Font.font(Font.getDefault().getSize()*0.9)); Label tagCreator = new Label(tag.getUserName()); Label tagCreated = new Label(tag.getCreated().toString()); @@ -144,7 +142,7 @@ public static CustomMenuItem TagWithCommentMenuItem(Tag tag) { VBox vBoxLeft = new VBox(); vBoxLeft.getStylesheets().add(SaveAndRestoreApplication.class.getResource("/save-and-restore-style.css").toExternalForm()); - vBoxLeft.getChildren().addAll(tagName, tagComment); + vBoxLeft.getChildren().addAll(tagName); VBox vBoxRight = new VBox(); vBoxRight.setAlignment(Pos.CENTER_RIGHT); diff --git a/app/save-and-restore/app/src/main/resources/org/phoebus/applications/saveandrestore/messages.properties b/app/save-and-restore/app/src/main/resources/org/phoebus/applications/saveandrestore/messages.properties index 4cd29329be..9ea5a9ae12 100644 --- a/app/save-and-restore/app/src/main/resources/org/phoebus/applications/saveandrestore/messages.properties +++ b/app/save-and-restore/app/src/main/resources/org/phoebus/applications/saveandrestore/messages.properties @@ -29,6 +29,7 @@ configurationLocation=Location configurationName=Configuration Name configurationNameHint=Select location before specifying name contextMenuAddToCompositeSnapshot=Add to composite snapshot +contextMenuAddTag=Add a tag contextMenuAddTagWithComment=Add a tag with comment contextMenuCreateSnapshot=Create Snapshot contextMenuCompareSnapshots=Compare Snapshots @@ -44,6 +45,7 @@ contextMenuOpenCompositeSnapshotForRestore=Open for restore contextMenuRename=Rename contextMenuRemoveGoldenTag=Remove Golden tag contextMenuTagAsGolden=Add Golden tag +contextMenuTags=Tags contextMenuTagsWithComment=Tags with comment copyOrMoveNotAllowedBody=Selection cannot be moved/copied to the specified target node. copyOrMoveNotAllowedHeader=Cannot move or copy selection. diff --git a/app/save-and-restore/app/src/main/resources/org/phoebus/applications/saveandrestore/messages_fr.properties b/app/save-and-restore/app/src/main/resources/org/phoebus/applications/saveandrestore/messages_fr.properties index f37eef6cc0..26541b16b3 100644 --- a/app/save-and-restore/app/src/main/resources/org/phoebus/applications/saveandrestore/messages_fr.properties +++ b/app/save-and-restore/app/src/main/resources/org/phoebus/applications/saveandrestore/messages_fr.properties @@ -21,6 +21,7 @@ configurationLocation=Emplacement configurationName=Nom de la configuration configurationNameHint=Séléctionner l'emplacement avant de spécifier le nom contextMenuAddToCompositeSnapshot=Ajouter à la capture instantanée composite +contextMenuAddTag=Ajouter une étiquette contextMenuAddTagWithComment=Ajouter une étiquette avec commentaire contextMenuCreateSnapshot=Créer une capture instantanée contextMenuCompareSnapshots=Comparer les captures instantanées @@ -35,6 +36,7 @@ contextMenuOpenCompositeSnapshotForRestore=Ouvrir pour restaurer contextMenuRename=Renommer contextMenuRemoveGoldenTag=Supprimer l'étiquette dorée contextMenuTagAsGolden=Ajouter l'étiquette dorée +contextMenuTags=Étiquettes contextMenuTagsWithComment=Étiquettes avec commentaire copyOrMoveNotAllowedBody=La sélection ne peut pas être déplacée/copier vers le n?ud cible spécifié. copyOrMoveNotAllowedHeader=Impossible de déplacer ou copier la sélection. From ba0ca7d344ec9b79735b2a8c48cdd60ba1d007bb Mon Sep 17 00:00:00 2001 From: Kunal Shroff Date: Tue, 8 Oct 2024 14:14:46 -0400 Subject: [PATCH 08/12] new messages for the 2 restore operation modes --- .../java/org/phoebus/applications/saveandrestore/Messages.java | 2 ++ .../org/phoebus/applications/saveandrestore/messages.properties | 2 ++ .../phoebus/applications/saveandrestore/messages_fr.properties | 2 ++ 3 files changed, 6 insertions(+) diff --git a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/Messages.java b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/Messages.java index e397f3b2aa..e9b669aa50 100644 --- a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/Messages.java +++ b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/Messages.java @@ -133,6 +133,8 @@ public class Messages { public static String restore; public static String restoreFailed; public static String restoreFailedPVs; + public static String restoreFromClient; + public static String restoreFromService; public static String saveFilter; public static String saveFilterConfirmOverwrite; diff --git a/app/save-and-restore/app/src/main/resources/org/phoebus/applications/saveandrestore/messages.properties b/app/save-and-restore/app/src/main/resources/org/phoebus/applications/saveandrestore/messages.properties index 9ea5a9ae12..0973024d49 100644 --- a/app/save-and-restore/app/src/main/resources/org/phoebus/applications/saveandrestore/messages.properties +++ b/app/save-and-restore/app/src/main/resources/org/phoebus/applications/saveandrestore/messages.properties @@ -165,6 +165,8 @@ restoreErrorTitle=Restore Error restoreErrorContent=Not all PVs were restored. restoreFailed=Restore operation failed restoreFailedPVs=Failed to write the following PVs: +restoreFromClient=Restore from client +restoreFromService=Restore from service save=Save saveAsFilter=Save As Filter saveFilter=Save Filter diff --git a/app/save-and-restore/app/src/main/resources/org/phoebus/applications/saveandrestore/messages_fr.properties b/app/save-and-restore/app/src/main/resources/org/phoebus/applications/saveandrestore/messages_fr.properties index 26541b16b3..a68ef8ca64 100644 --- a/app/save-and-restore/app/src/main/resources/org/phoebus/applications/saveandrestore/messages_fr.properties +++ b/app/save-and-restore/app/src/main/resources/org/phoebus/applications/saveandrestore/messages_fr.properties @@ -149,6 +149,8 @@ restoreErrorTitle=Erreur de restauration restoreErrorContent=Tous les PV n'ont pas été restaurés. restoreFailed=Échec de l'opération de restauration restoreFailedPVs=Échec de l'écriture des PV suivants : +restoreFromClient=Restaurer à partir du client +restoreFromService=Restauration à partir du service save=Enregistrer saveAsFilter=Enregistrer en tant que filtre saveFilter=Enregistrer le filtre From d12c8421aa13712a85ed0a29e68747767b638900 Mon Sep 17 00:00:00 2001 From: Kunal Shroff Date: Tue, 8 Oct 2024 14:15:19 -0400 Subject: [PATCH 09/12] A new enum representing client and service side restore --- .../saveandrestore/ui/RestoreMode.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/RestoreMode.java diff --git a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/RestoreMode.java b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/RestoreMode.java new file mode 100644 index 0000000000..6da89dafc6 --- /dev/null +++ b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/RestoreMode.java @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2024 European Spallation Source ERIC. + */ + +package org.phoebus.applications.saveandrestore.ui; + +import org.phoebus.applications.saveandrestore.Messages; + +public enum RestoreMode { + + /** + * Classic mode: read data from IOC + */ + CLIENT_RESTORE(Messages.restoreFromClient), + + /** + * Read PV data from archiver + */ + SERVICE_RESTORE(Messages.restoreFromService); + + private final String name; + + RestoreMode(final String name) { + this.name = name; + } + + @Override + public String toString(){ + return name; + } +} From a22821a089b007bbc2bff8385ddbd9ff4e4e856f Mon Sep 17 00:00:00 2001 From: Kunal Shroff Date: Tue, 8 Oct 2024 14:30:20 -0400 Subject: [PATCH 10/12] allow users to select client or services based restore --- .../saveandrestore/Preferences.java | 6 +++ .../ui/snapshot/SnapshotController.java | 2 +- .../SnapshotControlsViewController.java | 37 +++++++++++++++++++ .../snapshot/SnapshotTableViewController.java | 33 +++++++++++++++-- .../ui/snapshot/SnapshotControlsView.fxml | 35 ++++++++++++++++-- .../save_and_restore_preferences.properties | 7 +++- 6 files changed, 111 insertions(+), 9 deletions(-) diff --git a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/Preferences.java b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/Preferences.java index 803d019fad..9e7e8314df 100644 --- a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/Preferences.java +++ b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/Preferences.java @@ -57,6 +57,12 @@ public class Preferences { @Preference public static String default_snapshot_mode; + /** + * Default restore mode + */ + @Preference + public static String default_restore_mode; + static { AnnotatedPreferences.initialize(Preferences.class, "/save_and_restore_preferences.properties"); } diff --git a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotController.java b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotController.java index 325920f6c3..b552a95c9c 100644 --- a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotController.java +++ b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotController.java @@ -359,7 +359,7 @@ public void loadSnapshot(Node snapshotNode) { } public void restore(ActionEvent actionEvent) { - snapshotTableViewController.restore(snapshotProperty.get(), restoreResultList -> { + snapshotTableViewController.restoreSnapshot(snapshotControlsViewController.getRestoreMode(), snapshotProperty.get(), restoreResultList -> { if (snapshotControlsViewController.logAction()) { eventReceivers.forEach(r -> r.snapshotRestored(snapshotProperty.get().getSnapshotNode(), restoreResultList, this::showLoggingError)); } diff --git a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotControlsViewController.java b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotControlsViewController.java index 889c2f8b16..6e75603298 100644 --- a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotControlsViewController.java +++ b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotControlsViewController.java @@ -37,6 +37,7 @@ import org.phoebus.applications.saveandrestore.model.Node; import org.phoebus.applications.saveandrestore.model.NodeType; import org.phoebus.applications.saveandrestore.model.event.SaveAndRestoreEventReceiver; +import org.phoebus.applications.saveandrestore.ui.RestoreMode; import org.phoebus.applications.saveandrestore.ui.SaveAndRestoreBaseController; import org.phoebus.applications.saveandrestore.ui.SnapshotMode; import org.phoebus.ui.docking.DockPane; @@ -128,6 +129,14 @@ public class SnapshotControlsViewController extends SaveAndRestoreBaseController @FXML private RadioButton readFromArchiver; + @SuppressWarnings("unused") + @FXML + private RadioButton restoreFromClient; + + @SuppressWarnings("unused") + @FXML + private RadioButton restoreFromService; + private List> regexPatterns = new ArrayList<>(); protected final SimpleStringProperty snapshotNameProperty = new SimpleStringProperty(); @@ -155,6 +164,8 @@ public class SnapshotControlsViewController extends SaveAndRestoreBaseController private final SimpleObjectProperty snapshotModeProperty = new SimpleObjectProperty<>(SnapshotMode.READ_PVS); + private final SimpleObjectProperty restoreModeProperty = new SimpleObjectProperty<>(RestoreMode.CLIENT_RESTORE); + public void setSnapshotController(SnapshotController snapshotController) { this.snapshotController = snapshotController; } @@ -313,6 +324,29 @@ public void initialize() { toggleGroup.selectedToggleProperty().addListener((obs, o, n) -> { snapshotModeProperty.set((SnapshotMode) n.getUserData()); }); + + restoreFromClient.setUserData(RestoreMode.CLIENT_RESTORE); + restoreFromService.setUserData(RestoreMode.SERVICE_RESTORE); + + String restoreModeString = Preferences.default_restore_mode; + if (restoreModeString == null || restoreModeString.isEmpty()) { + restoreModeProperty.set(RestoreMode.CLIENT_RESTORE); + } else { + try { + restoreModeProperty.set(RestoreMode.valueOf(restoreModeString)); + } catch (IllegalArgumentException e) { + logger.log(Level.WARNING, "Unknown restore mode \"" + restoreModeString + "\", defaulting to " + RestoreMode.CLIENT_RESTORE); + restoreModeProperty.set(RestoreMode.CLIENT_RESTORE); + } + } + + ToggleGroup restoreToggleGroup = new ToggleGroup(); + restoreToggleGroup.getToggles().addAll(restoreFromClient, restoreFromService); + restoreToggleGroup.selectToggle(restoreToggleGroup.getToggles().stream() + .filter(t -> t.getUserData().equals(restoreModeProperty.get())).findFirst().get()); + restoreToggleGroup.selectedToggleProperty().addListener((obs, o, n) -> { + restoreModeProperty.set((RestoreMode) n.getUserData()); + }); } public SimpleStringProperty getSnapshotNameProperty() { @@ -379,6 +413,9 @@ public void setSnapshotRestorableProperty(boolean restorable) { public SnapshotMode getDefaultSnapshotMode() { return snapshotModeProperty.get(); } + public RestoreMode getRestoreMode() { + return restoreModeProperty.get(); + } public boolean logAction() { return logActionProperty.get(); diff --git a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotTableViewController.java b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotTableViewController.java index 9b3d683083..20e56776de 100644 --- a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotTableViewController.java +++ b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotTableViewController.java @@ -32,6 +32,7 @@ import org.phoebus.applications.saveandrestore.model.Snapshot; import org.phoebus.applications.saveandrestore.model.SnapshotData; import org.phoebus.applications.saveandrestore.model.SnapshotItem; +import org.phoebus.applications.saveandrestore.ui.RestoreMode; import org.phoebus.applications.saveandrestore.ui.SaveAndRestoreService; import org.phoebus.applications.saveandrestore.ui.SnapshotMode; import org.phoebus.applications.saveandrestore.ui.Threshold; @@ -363,13 +364,28 @@ public void hideEqualItems() { Platform.runLater(() -> updateTable(arrayList)); } + + /** + * Restore a snapshot either from the client or from the services + * @param restoreMode + * @param snapshot + * @param consumer + */ + public void restoreSnapshot(RestoreMode restoreMode, Snapshot snapshot, Consumer> consumer) { + switch (restoreMode) { + case CLIENT_RESTORE -> restoreFromClient(snapshot, consumer); + case SERVICE_RESTORE -> restoreFromService(snapshot, consumer); + default -> throw new IllegalArgumentException("RestoreMode mode " + restoreMode + " not supported"); + } + } + /** * Restores a snapshot through a call to the remote service. * * @param snapshot The {@link Snapshot} object subject to restore * @param completion A handler for the outcome of the restore operation */ - public void restore(Snapshot snapshot, Consumer> completion) { + public void restoreFromService(Snapshot snapshot, Consumer> completion) { JobManager.schedule("Restore snapshot " + snapshot.getSnapshotNode().getName(), monitor -> { List itemsToRestore = new ArrayList<>(); List restoreResultList = null; @@ -410,16 +426,23 @@ public void restore(Snapshot snapshot, Consumer> completion) * @param completion A handler for the outcome of the restore operation */ @SuppressWarnings("unused") - public void restoreFromClient(Snapshot snapshot, Consumer> completion) { + public void restoreFromClient(Snapshot snapshot, Consumer> completion) { new Thread(() -> { + // TODO merge this list with the restoreResultList List restoreFailedPVNames = new ArrayList<>(); CountDownLatch countDownLatch = new CountDownLatch(snapshot.getSnapshotData().getSnapshotItems().size()); + + List restoreResultList = new ArrayList<>(); + snapshot.getSnapshotData().getSnapshotItems() .forEach(e -> pvs.get(getPVKey(e.getConfigPv().getPvName(), e.getConfigPv().isReadOnly())).setCountDownLatch(countDownLatch)); for (SnapshotItem entry : snapshot.getSnapshotData().getSnapshotItems()) { TableEntry e = tableEntryItems.get(getPVKey(entry.getConfigPv().getPvName(), entry.getConfigPv().isReadOnly())); + RestoreResult restoreResult = new RestoreResult(); + restoreResult.setSnapshotItem(entry); + boolean restorable = e.selectedProperty().get() && !e.readOnlyProperty().get() && entry.getValue() != null && @@ -432,11 +455,15 @@ public void restoreFromClient(Snapshot snapshot, Consumer> completi pv.getPv().write(VTypeHelper.toObject(entry.getValue())); } catch (Exception writeException) { restoreFailedPVNames.add(entry.getConfigPv().getPvName()); + restoreResult.setErrorMsg(writeException.getMessage()); + restoreResultList.add(restoreResult); } finally { + restoreResultList.add(restoreResult); pv.countDown(); } } } else { + restoreResult.setErrorMsg(entry.getConfigPv().getPvName() + " is not restoreable"); countDownLatch.countDown(); } } @@ -457,7 +484,7 @@ public void restoreFromClient(Snapshot snapshot, Consumer> completi "Not all PVs could be restored for {0}: {1}. The following errors occurred:\n{2}", new Object[]{snapshot.getSnapshotNode().getName(), snapshot.getSnapshotNode(), sb.toString()}); } - completion.accept(restoreFailedPVNames); + completion.accept(restoreResultList); }).start(); } diff --git a/app/save-and-restore/app/src/main/resources/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotControlsView.fxml b/app/save-and-restore/app/src/main/resources/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotControlsView.fxml index 2ed2c5480b..436b6dd1ef 100644 --- a/app/save-and-restore/app/src/main/resources/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotControlsView.fxml +++ b/app/save-and-restore/app/src/main/resources/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotControlsView.fxml @@ -4,11 +4,25 @@ ~ Copyright (C) 2024 European Spallation Source ERIC. --> - - - + + + + + + + + + + + + + + + + + - + @@ -126,6 +140,19 @@ + + + + + + + + + + + + + diff --git a/app/save-and-restore/app/src/main/resources/save_and_restore_preferences.properties b/app/save-and-restore/app/src/main/resources/save_and_restore_preferences.properties index 90861c1254..958167c41c 100644 --- a/app/save-and-restore/app/src/main/resources/save_and_restore_preferences.properties +++ b/app/save-and-restore/app/src/main/resources/save_and_restore_preferences.properties @@ -20,4 +20,9 @@ default_search_query=tags=golden # Defines the default snapshot mode # READ_PVS: the classic mode where PV values are read from IOCs # FROM_ARCHIVER: PV values read from archiver at point in time selected by user -default_snapshot_mode=READ_PVS \ No newline at end of file +default_snapshot_mode=READ_PVS + +# Defines the default restore mode +# CLIENT_RESTORE: the restore operation is performed by the client +# SERVICE_RESTORE: the restore operation is performed by the server +default_restore_mode=CLIENT_RESTORE \ No newline at end of file From 41323f2b5f2620ca5fe6e54ffbdb0e152162c267 Mon Sep 17 00:00:00 2001 From: Kunal Shroff Date: Tue, 8 Oct 2024 14:54:55 -0400 Subject: [PATCH 11/12] The RestoreResult is only for errors, removing successful entries --- .../ui/snapshot/SnapshotTableViewController.java | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotTableViewController.java b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotTableViewController.java index 20e56776de..09992410f1 100644 --- a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotTableViewController.java +++ b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotTableViewController.java @@ -51,6 +51,7 @@ import java.time.Instant; import java.util.ArrayList; import java.util.Collections; +import java.util.Comparator; import java.util.Date; import java.util.List; import java.util.Optional; @@ -428,8 +429,6 @@ public void restoreFromService(Snapshot snapshot, Consumer> @SuppressWarnings("unused") public void restoreFromClient(Snapshot snapshot, Consumer> completion) { new Thread(() -> { - // TODO merge this list with the restoreResultList - List restoreFailedPVNames = new ArrayList<>(); CountDownLatch countDownLatch = new CountDownLatch(snapshot.getSnapshotData().getSnapshotItems().size()); List restoreResultList = new ArrayList<>(); @@ -454,11 +453,9 @@ public void restoreFromClient(Snapshot snapshot, Consumer> c try { pv.getPv().write(VTypeHelper.toObject(entry.getValue())); } catch (Exception writeException) { - restoreFailedPVNames.add(entry.getConfigPv().getPvName()); restoreResult.setErrorMsg(writeException.getMessage()); restoreResultList.add(restoreResult); } finally { - restoreResultList.add(restoreResult); pv.countDown(); } } @@ -474,15 +471,16 @@ public void restoreFromClient(Snapshot snapshot, Consumer> c LOGGER.log(Level.INFO, "Encountered InterruptedException", e); } - if (restoreFailedPVNames.isEmpty()) { + if (restoreResultList.isEmpty()) { LOGGER.log(Level.FINE, "Restored snapshot {0}", snapshot.getSnapshotNode().getName()); } else { - Collections.sort(restoreFailedPVNames); - StringBuilder sb = new StringBuilder(restoreFailedPVNames.size() * 200); - restoreFailedPVNames.forEach(e -> sb.append(e).append('\n')); + String msg = restoreResultList.stream() + .sorted(Comparator.comparing(o -> o.getSnapshotItem().getConfigPv().getPvName())) + .map(r -> r.getSnapshotItem().getConfigPv().getPvName()) + .collect(Collectors.joining(System.lineSeparator())); LOGGER.log(Level.WARNING, "Not all PVs could be restored for {0}: {1}. The following errors occurred:\n{2}", - new Object[]{snapshot.getSnapshotNode().getName(), snapshot.getSnapshotNode(), sb.toString()}); + new Object[]{snapshot.getSnapshotNode().getName(), snapshot.getSnapshotNode(), msg}); } completion.accept(restoreResultList); }).start(); From 8f7eace00f7cdcfbce3fd641415086429d0c8a7d Mon Sep 17 00:00:00 2001 From: Kunal Shroff Date: Mon, 14 Oct 2024 10:43:43 -0400 Subject: [PATCH 12/12] Use the save and restore utility to do both client and server restores --- app/save-and-restore/app/pom.xml | 7 +++ .../snapshot/SnapshotTableViewController.java | 46 +++++++------------ 2 files changed, 24 insertions(+), 29 deletions(-) diff --git a/app/save-and-restore/app/pom.xml b/app/save-and-restore/app/pom.xml index bc4243c848..af34067afc 100644 --- a/app/save-and-restore/app/pom.xml +++ b/app/save-and-restore/app/pom.xml @@ -21,6 +21,12 @@ save-and-restore-model 4.7.4-SNAPSHOT + + org.phoebus + save-and-restore-util + 4.7.4-SNAPSHOT + compile + org.phoebus app-display-model @@ -76,6 +82,7 @@ test + diff --git a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotTableViewController.java b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotTableViewController.java index 09992410f1..7695a60ba6 100644 --- a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotTableViewController.java +++ b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotTableViewController.java @@ -40,8 +40,8 @@ import org.phoebus.applications.saveandrestore.ui.VNoData; import org.phoebus.applications.saveandrestore.ui.VTypePair; import org.phoebus.core.vtypes.VDisconnectedData; -import org.phoebus.core.vtypes.VTypeHelper; import org.phoebus.framework.jobs.JobManager; +import org.phoebus.saveandrestore.util.SnapshotUtil; import org.phoebus.ui.dialog.DialogHelper; import org.phoebus.ui.dialog.ExceptionDetailsErrorDialog; import org.phoebus.ui.time.DateTimePane; @@ -50,13 +50,10 @@ import java.text.SimpleDateFormat; import java.time.Instant; import java.util.ArrayList; -import java.util.Collections; import java.util.Comparator; import java.util.Date; import java.util.List; import java.util.Optional; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; import java.util.function.Consumer; import java.util.logging.Level; import java.util.regex.Pattern; @@ -83,6 +80,7 @@ public class SnapshotTableViewController extends BaseSnapshotTableViewController private final SimpleBooleanProperty compareViewEnabled = new SimpleBooleanProperty(false); + private SnapshotUtil snapshotUtil; @FXML public void initialize() { @@ -147,6 +145,8 @@ public void initialize() { valueColumn.visibleProperty().bind(compareViewEnabled.not()); compareViewEnabled.addListener((ob, o, n) -> snapshotTableView.layout()); + + snapshotUtil = new SnapshotUtil(); } public void setSnapshotController(SnapshotController snapshotController) { @@ -429,48 +429,36 @@ public void restoreFromService(Snapshot snapshot, Consumer> @SuppressWarnings("unused") public void restoreFromClient(Snapshot snapshot, Consumer> completion) { new Thread(() -> { - CountDownLatch countDownLatch = new CountDownLatch(snapshot.getSnapshotData().getSnapshotItems().size()); + List itemsToRestore = new ArrayList<>(); List restoreResultList = new ArrayList<>(); - snapshot.getSnapshotData().getSnapshotItems() - .forEach(e -> pvs.get(getPVKey(e.getConfigPv().getPvName(), e.getConfigPv().isReadOnly())).setCountDownLatch(countDownLatch)); - for (SnapshotItem entry : snapshot.getSnapshotData().getSnapshotItems()) { TableEntry e = tableEntryItems.get(getPVKey(entry.getConfigPv().getPvName(), entry.getConfigPv().isReadOnly())); - RestoreResult restoreResult = new RestoreResult(); - restoreResult.setSnapshotItem(entry); - boolean restorable = e.selectedProperty().get() && !e.readOnlyProperty().get() && entry.getValue() != null && !entry.getValue().equals(VNoData.INSTANCE); if (restorable) { - final SaveAndRestorePV pv = pvs.get(getPVKey(e.pvNameProperty().get(), e.readOnlyProperty().get())); - if (entry.getValue() != null) { - try { - pv.getPv().write(VTypeHelper.toObject(entry.getValue())); - } catch (Exception writeException) { - restoreResult.setErrorMsg(writeException.getMessage()); - restoreResultList.add(restoreResult); - } finally { - pv.countDown(); - } - } - } else { - restoreResult.setErrorMsg(entry.getConfigPv().getPvName() + " is not restoreable"); - countDownLatch.countDown(); + itemsToRestore.add(entry); } } try { - countDownLatch.await(10, TimeUnit.MINUTES); - } catch (InterruptedException e) { - LOGGER.log(Level.INFO, "Encountered InterruptedException", e); + restoreResultList = snapshotUtil.restore(itemsToRestore); + } catch (Exception e) { + Platform.runLater(() -> { + Alert alert = new Alert(Alert.AlertType.ERROR); + alert.setTitle(Messages.errorActionFailed); + alert.setContentText(e.getMessage()); + alert.setHeaderText(Messages.restoreFailed); + DialogHelper.positionDialog(alert, snapshotTableView, -150, -150); + alert.showAndWait(); + }); } - + // Legacy if (restoreResultList.isEmpty()) { LOGGER.log(Level.FINE, "Restored snapshot {0}", snapshot.getSnapshotNode().getName()); } else {