Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions app/save-and-restore/app/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,6 @@ tags is indicated with a symbol to the right of the node name:

.. image:: images/snapshot-with-tag.png

Similarly, snapshots and composite snapshots referenced in other composite snapshots are annotated with a symbol to the
right of the node name:

.. image:: images/snapshot-with-references.png



Node names and ordering
-----------------------
Expand Down Expand Up @@ -279,7 +273,7 @@ The composite snapshot can be saved when a case sensitive name and a description

* The combined list of PV names in the referenced snapshots must not contain duplicates. This is checked for each item dropped into the list when editing a composite snapshot. If duplicates are detected, an error dialog is shown.

* Snapshots and composite snapshots cannot be deleted if referenced in a composite snapshot.
* Snapshots and composite snapshots cannot be deleted if referenced in any composite snapshot. This is indicated by disabling the Delete context menu item.

Edit Composite Snapshot using drag-n-drop
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

package org.phoebus.applications.saveandrestore.ui;

import javafx.application.Platform;
import javafx.scene.control.Label;
import javafx.scene.control.Tooltip;
import javafx.scene.control.TreeCell;
Expand All @@ -39,13 +38,9 @@
import org.phoebus.applications.saveandrestore.model.Node;
import org.phoebus.applications.saveandrestore.model.NodeType;
import org.phoebus.applications.saveandrestore.model.Tag;
import org.phoebus.applications.saveandrestore.model.search.SearchResult;
import org.phoebus.framework.jobs.JobManager;
import org.phoebus.ui.javafx.ImageCache;
import org.phoebus.util.time.TimestampFormats;

import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -188,7 +183,6 @@ public void updateItem(Node node, boolean empty) {
tagImage.setPreserveRatio(true);
hBox.getChildren().add(tagImage);
}
annotateContainedInCompositeSnapshot(node, hBox);
break;
case COMPOSITE_SNAPSHOT:
hBox.getChildren().add(new ImageView(ImageRepository.COMPOSITE_SNAPSHOT));
Expand All @@ -199,7 +193,6 @@ public void updateItem(Node node, boolean empty) {
tagImage.setPreserveRatio(true);
getChildren().add(tagImage);
}
annotateContainedInCompositeSnapshot(node, hBox);
break;
case CONFIGURATION:
hBox.getChildren().add(new ImageView(ImageRepository.CONFIGURATION));
Expand All @@ -216,17 +209,4 @@ public void updateItem(Node node, boolean empty) {

setGraphic(hBox);
}

private void annotateContainedInCompositeSnapshot(Node node, HBox hbox) {
JobManager.schedule("Annotate contained in snapshot", monitor -> {
MultivaluedMap<String, String> multivaluedMap = new MultivaluedHashMap<>();
multivaluedMap.put("referenced", List.of(node.getUniqueId()));
SearchResult searchResult = saveAndRestoreController.saveAndRestoreService.search(multivaluedMap);
if (searchResult.getHitCount() > 0) {
Platform.runLater(() -> {
hbox.getChildren().add(new ImageView(ImageRepository.LINK));
});
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@
import java.util.ServiceLoader;
import java.util.Stack;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -1405,10 +1407,41 @@
compareSnapshotsMenuItem.disableProperty().set(!compareSnapshotsPossible());
deleteNodeMenuItem.disableProperty().set(getUserIdentity().isNull().get() ||
selectedItemsProperty.stream().anyMatch(n -> n.getUniqueId().equals(Node.ROOT_FOLDER_UNIQUE_ID)) ||
!hasSameParent());
!hasSameParent() ||
hasReferences(selectedItemsProperty.get(0)));
pasteMenuItem.disableProperty().set(!mayPaste());
}

/**
* Queries service if the specified {@link Node} is referenced in any composite snapshot.
*
* @param node The node to check.
* @return <code>true</code> if the {@link Node} is referenced.
*/
private boolean hasReferences(Node node) {
if (node.getNodeType().equals(NodeType.FOLDER) || node.getNodeType().equals(NodeType.CONFIGURATION)) {
return false;
}
AtomicBoolean hasReferences = new AtomicBoolean(false);
CountDownLatch countDownLatch = new CountDownLatch(1);
JobManager.schedule("Find references", monitor -> {
MultivaluedMap<String, String> multivaluedMap = new MultivaluedHashMap<>();
multivaluedMap.put("referenced", List.of(node.getUniqueId()));
try {
hasReferences.set(saveAndRestoreService.search(multivaluedMap).getHitCount() > 0);
} catch (Exception e) {
Comment thread
jacomago marked this conversation as resolved.
logger.log(Level.WARNING, "Failed to check for references for node " + node.getUniqueId(), e);

Check warning on line 1433 in app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/SaveAndRestoreController.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Lambda should be used to defer string concatenation.

See more on https://sonarcloud.io/project/issues?id=ControlSystemStudio_phoebus&issues=AZ4_g3KJTyMlENFnLAwh&open=AZ4_g3KJTyMlENFnLAwh&pullRequest=3805
}
countDownLatch.countDown();
});
try {
countDownLatch.await(10, TimeUnit.SECONDS);

Check warning on line 1438 in app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/SaveAndRestoreController.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Do something with the "boolean" value returned by "await".

See more on https://sonarcloud.io/project/issues?id=ControlSystemStudio_phoebus&issues=AZ4_fkKBpF59qXp12mXU&open=AZ4_fkKBpF59qXp12mXU&pullRequest=3805
} catch (InterruptedException e) {

Check warning on line 1439 in app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/SaveAndRestoreController.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Either re-interrupt this method or rethrow the "InterruptedException" that can be caught here.

See more on https://sonarcloud.io/project/issues?id=ControlSystemStudio_phoebus&issues=AZ4_fkKBpF59qXp12mXT&open=AZ4_fkKBpF59qXp12mXT&pullRequest=3805
logger.log(Level.WARNING, "Timeout when checking references for node " + node.getUniqueId(), e);

Check warning on line 1440 in app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/SaveAndRestoreController.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Lambda should be used to defer string concatenation.

See more on https://sonarcloud.io/project/issues?id=ControlSystemStudio_phoebus&issues=AZ4_fkKBpF59qXp12mXV&open=AZ4_fkKBpF59qXp12mXV&pullRequest=3805
}
return hasReferences.get();
}

/**
* Adds a create log menu item based on current selection and logbook client availability
*/
Expand Down
Loading