Skip to content

Commit 286eee1

Browse files
authored
Merge pull request #3389 from ControlSystemStudio/CSSTUDIO-1967
Web sockets for save&restore
2 parents c518085 + 503dd4c commit 286eee1

File tree

62 files changed

+2306
-1040
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+2306
-1040
lines changed

app/save-and-restore/app/doc/index.rst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,13 @@ A word of caution
5858
-----------------
5959

6060
Save-and-restore data is persisted in a central service and is therefore accessible by multiple
61-
clients. Users should keep in mind that changes (e.g. new or deleted nodes) are not pushed to all clients.
62-
Caution is therefore advocated when working on the nodes in the tree, in particular when changing the structure by
63-
copying, deleting or moving nodes.
61+
clients. Users should keep in mind that changes (e.g. new or deleted nodes) are pushed by the service to
62+
all connected clients. If any other user is working in the save-and-restore app, saved changes may update
63+
the current view. For instance, if a folder node is expanded and another user adds an object (folder
64+
or configuration) to that folder, the new object will automatically be added to the expanded folder.
65+
66+
In other words, changes in the current view are triggered not only by the current user, but may be triggered as a result of
67+
changes done by others.
6468

6569
Tree View Context Menu
6670
----------------------

app/save-and-restore/app/pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@
2525
<artifactId>core-logbook</artifactId>
2626
<version>5.0.1-SNAPSHOT</version>
2727
</dependency>
28+
<dependency>
29+
<groupId>org.phoebus</groupId>
30+
<artifactId>core-ui</artifactId>
31+
<version>5.0.1-SNAPSHOT</version>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.phoebus</groupId>
35+
<artifactId>core-websocket</artifactId>
36+
<version>5.0.1-SNAPSHOT</version>
37+
</dependency>
2838
<dependency>
2939
<groupId>org.phoebus</groupId>
3040
<artifactId>save-and-restore-model</artifactId>

app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/FilterViewInstance.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ public FilterViewInstance(AppDescriptor appDescriptor) {
5454
return CompletableFuture.completedFuture(true);
5555
});
5656

57+
dockItem.setOnCloseRequest(e -> searchResultTableViewController.handleTabClosed());
58+
5759
DockPane.getActiveDockPane().addTab(dockItem);
5860
}
5961

app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/Messages.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,18 @@ public class Messages {
178178
public static String toolTipConfigurationExists;
179179
public static String toolTipConfigurationExistsOption;
180180
public static String toolTipMultiplierSpinner;
181+
public static String unnamedConfiguration;
182+
public static String unnamedCompositeSnapshot;
181183
public static String unnamedSnapshot;
182184

183185
public static String updateCompositeSnapshotFailed;
184186
public static String updateConfigurationFailed;
185187

186188
public static String updateNodeFailed;
187189

190+
public static String webSocketConnected;
191+
public static String webSocketDisconnected;
192+
188193
static {
189194
NLS.initializeMessages(Messages.class);
190195
}

app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/SaveAndRestoreInstance.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public SaveAndRestoreInstance(AppDescriptor appDescriptor) {
5555
loader.setLocation(SaveAndRestoreApplication.class.getResource("ui/SaveAndRestoreUI.fxml"));
5656
dockItem = new DockItem(this, loader.load());
5757
} catch (Exception e) {
58-
Logger.getLogger(SaveAndRestoreApplication.class.getName()).log(Level.SEVERE, "Failed loading fxml", e);
58+
Logger.getLogger(SaveAndRestoreInstance.class.getName()).log(Level.SEVERE, "Failed loading fxml", e);
5959
}
6060

6161
saveAndRestoreController = loader.getController();
@@ -82,11 +82,11 @@ public void openResource(URI uri) {
8282
saveAndRestoreController.openResource(uri);
8383
}
8484

85-
public void secureStoreChanged(List<ScopedAuthenticationToken> validTokens){
85+
public void secureStoreChanged(List<ScopedAuthenticationToken> validTokens) {
8686
saveAndRestoreController.secureStoreChanged(validTokens);
8787
}
8888

89-
public void raise(){
89+
public void raise() {
9090
dockItem.select();
9191
}
9292
}

app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/client/SaveAndRestoreClientImpl.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,9 @@
3636
import java.net.CookieManager;
3737
import java.net.CookiePolicy;
3838
import java.net.URI;
39-
import java.net.URLEncoder;
4039
import java.net.http.HttpClient;
4140
import java.net.http.HttpRequest;
4241
import java.net.http.HttpResponse;
43-
import java.nio.charset.StandardCharsets;
4442
import java.time.Duration;
4543
import java.util.Base64;
4644
import java.util.List;
@@ -588,10 +586,10 @@ public UserData authenticate(String userName, String password) {
588586
String stringBuilder = Preferences.jmasarServiceUrl +
589587
"/login";
590588
HttpRequest request = HttpRequest.newBuilder()
591-
.uri(URI.create(stringBuilder))
592-
.header("Content-Type", CONTENT_TYPE_JSON)
593-
.POST(HttpRequest.BodyPublishers.ofString(OBJECT_MAPPER.writeValueAsString(new LoginCredentials(userName, password))))
594-
.build();
589+
.uri(URI.create(stringBuilder))
590+
.header("Content-Type", CONTENT_TYPE_JSON)
591+
.POST(HttpRequest.BodyPublishers.ofString(OBJECT_MAPPER.writeValueAsString(new LoginCredentials(userName, password))))
592+
.build();
595593
HttpResponse<String> response = CLIENT.send(request, HttpResponse.BodyHandlers.ofString());
596594
return OBJECT_MAPPER.readValue(response.body(), UserData.class);
597595
} catch (Exception e) {

app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/FilterChangeListener.java

Lines changed: 0 additions & 33 deletions
This file was deleted.

app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/NodeAddedListener.java

Lines changed: 0 additions & 34 deletions
This file was deleted.

app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/NodeChangedListener.java

Lines changed: 0 additions & 30 deletions
This file was deleted.

app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/SaveAndRestoreBaseController.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.phoebus.applications.saveandrestore.ui;
2121

2222
import javafx.beans.property.SimpleStringProperty;
23+
import org.phoebus.applications.saveandrestore.model.websocket.SaveAndRestoreWebSocketMessage;
2324
import org.phoebus.security.store.SecureStore;
2425
import org.phoebus.security.tokens.AuthenticationScope;
2526
import org.phoebus.security.tokens.ScopedAuthenticationToken;
@@ -32,8 +33,12 @@
3233
public abstract class SaveAndRestoreBaseController {
3334

3435
protected final SimpleStringProperty userIdentity = new SimpleStringProperty();
36+
protected final WebSocketClientService webSocketClientService;
37+
protected final SaveAndRestoreService saveAndRestoreService;
3538

3639
public SaveAndRestoreBaseController() {
40+
this.webSocketClientService = WebSocketClientService.getInstance();
41+
this.saveAndRestoreService = SaveAndRestoreService.getInstance();
3742
try {
3843
SecureStore secureStore = new SecureStore();
3944
ScopedAuthenticationToken token =
@@ -63,4 +68,16 @@ public void secureStoreChanged(List<ScopedAuthenticationToken> validTokens) {
6368
public SimpleStringProperty getUserIdentity() {
6469
return userIdentity;
6570
}
71+
72+
/**
73+
* Default no-op implementation of a handler for {@link SaveAndRestoreWebSocketMessage}s.
74+
* @param webSocketMessage See {@link SaveAndRestoreWebSocketMessage}
75+
*/
76+
protected void handleWebSocketMessage(SaveAndRestoreWebSocketMessage<?> webSocketMessage){
77+
}
78+
79+
80+
protected boolean handleTabClosed(){
81+
return true;
82+
}
6683
}

0 commit comments

Comments
 (0)