4242import org .springframework .util .LinkedMultiValueMap ;
4343import org .springframework .util .MultiValueMap ;
4444
45- import java .lang .annotation .Inherited ;
4645import java .util .ArrayList ;
4746import java .util .Collections ;
4847import java .util .Comparator ;
@@ -129,7 +128,7 @@ public List<Node> getNodes(List<String> uniqueNodeIds) {
129128 }
130129
131130 /**
132- * {@inheritDoc}
131+ * {@inheritDoc}
133132 */
134133 @ Override
135134 @ Deprecated
@@ -138,12 +137,12 @@ public void deleteNode(String nodeId) {
138137 }
139138
140139 /**
141- * {@inheritDoc}
140+ * {@inheritDoc}
142141 */
143142 @ Override
144- public void deleteNodes (List <String > nodeIds ){
143+ public void deleteNodes (List <String > nodeIds ) {
145144 List <Node > nodes = new ArrayList <>();
146- for (String nodeId : nodeIds ){
145+ for (String nodeId : nodeIds ) {
147146 Node nodeToDelete = getNode (nodeId );
148147 if (nodeToDelete == null ) {
149148 throw new NodeNotFoundException ("Cannot delete non-existing node" );
@@ -318,17 +317,17 @@ public Node moveNodes(List<String> nodeIds, String targetId, String userName) {
318317 throw new RuntimeException ("Parent node of source node " + sourceNodes .get (0 ).getUniqueId () + " not found. Should not happen." );
319318 }
320319
321- if (targetNode .getChildNodes () != null ){
320+ if (targetNode .getChildNodes () != null ) {
322321 List <Node > targetsChildNodes = new ArrayList <>();
323- for (String parentChildNode : targetNode .getChildNodes ()){
322+ for (String parentChildNode : targetNode .getChildNodes ()) {
324323 Optional <ESTreeNode > targetChildNodeOptional = elasticsearchTreeRepository .findById (parentChildNode );
325- if (targetChildNodeOptional .isEmpty ()){ // Should not happen, but ignore if it does.
324+ if (targetChildNodeOptional .isEmpty ()) { // Should not happen, but ignore if it does.
326325 continue ;
327326 }
328327 targetsChildNodes .add (targetChildNodeOptional .get ().getNode ());
329328 }
330- for (Node sourceNode : sourceNodes ){
331- for (Node targetChildNode : targetsChildNodes ) {
329+ for (Node sourceNode : sourceNodes ) {
330+ for (Node targetChildNode : targetsChildNodes ) {
332331 if (targetChildNode .getName ().equals (sourceNode .getName ()) && targetChildNode .getNodeType ().equals (sourceNode .getNodeType ())) {
333332 throw new IllegalArgumentException ("Cannot move, at least one source node has same name and type as a target child node" );
334333 }
@@ -758,15 +757,16 @@ public Snapshot updateSnapshot(Snapshot snapshot) {
758757
759758 snapshot .getSnapshotNode ().setNodeType (NodeType .SNAPSHOT ); // Force node type
760759 SnapshotData newSnapshotData ;
760+ Snapshot newSnapshot = new Snapshot ();
761761 try {
762762 newSnapshotData = snapshotDataRepository .save (snapshot .getSnapshotData ());
763+ Node updatedNode = updateNode (snapshot .getSnapshotNode (), false );
764+ newSnapshot .setSnapshotData (newSnapshotData );
765+ newSnapshot .setSnapshotNode (updatedNode );
763766 } catch (Exception e ) {
764767 throw new RuntimeException (e );
765768 }
766769
767- Snapshot newSnapshot = new Snapshot ();
768- newSnapshot .setSnapshotData (newSnapshotData );
769- newSnapshot .setSnapshotNode (snapshot .getSnapshotNode ());
770770
771771 return newSnapshot ;
772772 }
@@ -810,7 +810,8 @@ public Node findParentFromPathElements(Node parentNode, String[] splitPath, int
810810
811811 /**
812812 * Checks if a {@link Node} is present in a subtree. This is called recursively.
813- * @param startNode {@link Node} id from which the search will start.
813+ *
814+ * @param startNode {@link Node} id from which the search will start.
814815 * @param nodeToLookFor Self-explanatory.
815816 * @return <code>true</code> if the #nodeToLookFor is found in the subtree, otherwise <code>false</code>.
816817 */
@@ -1079,23 +1080,19 @@ private boolean checkCompositeSnapshotReferencedNodeType(String nodeId) {
10791080 }
10801081 }
10811082 return true ;
1082- } else if (node .getNodeType ().equals (NodeType .SNAPSHOT )) {
1083- return true ;
1084- } else {
1085- return false ;
1086- }
1083+ } else return node .getNodeType ().equals (NodeType .SNAPSHOT );
10871084 }
10881085
10891086 @ Override
10901087 public SearchResult search (MultiValueMap <String , String > searchParameters ) {
10911088 return searchInternal (searchParameters );
10921089 }
10931090
1094- private SearchResult searchInternal (MultiValueMap <String , String > searchParameters ){
1091+ private SearchResult searchInternal (MultiValueMap <String , String > searchParameters ) {
10951092 // Did client specify search on pv name(s)?
1096- if (searchParameters .keySet ().stream ().anyMatch (k -> k .strip ().toLowerCase ().contains ("pvs" ))){
1093+ if (searchParameters .keySet ().stream ().anyMatch (k -> k .strip ().toLowerCase ().contains ("pvs" ))) {
10971094 List <ConfigurationData > configurationDataList = configurationDataRepository .searchOnPvName (searchParameters );
1098- if (configurationDataList .isEmpty ()){
1095+ if (configurationDataList .isEmpty ()) {
10991096 // No matching configurations found, return empty SearchResult
11001097 return new SearchResult (0 , Collections .emptyList ());
11011098 }
@@ -1104,8 +1101,7 @@ private SearchResult searchInternal(MultiValueMap<String, String> searchParamete
11041101 augmented .putAll (searchParameters );
11051102 augmented .put ("uniqueid" , uniqueIds );
11061103 return elasticsearchTreeRepository .search (augmented );
1107- }
1108- else {
1104+ } else {
11091105 return elasticsearchTreeRepository .search (searchParameters );
11101106 }
11111107 }
@@ -1228,7 +1224,7 @@ protected String determineNewNodeName(Node sourceNode, List<Node> targetParentCh
12281224 // Filter to make sure only nodes of same type are considered.
12291225 targetParentChildNodes = targetParentChildNodes .stream ().filter (n -> n .getNodeType ().equals (sourceNode .getNodeType ())).collect (Collectors .toList ());
12301226 List <String > targetParentChildNodeNames = targetParentChildNodes .stream ().map (Node ::getName ).collect (Collectors .toList ());
1231- if (!targetParentChildNodeNames .contains (sourceNode .getName ())){
1227+ if (!targetParentChildNodeNames .contains (sourceNode .getName ())) {
12321228 return sourceNode .getName ();
12331229 }
12341230 String newNodeBaseName = sourceNode .getName ();
@@ -1240,7 +1236,7 @@ protected String determineNewNodeName(Node sourceNode, List<Node> targetParentCh
12401236 Pattern pattern = Pattern .compile (newNodeBaseName + "(\\ scopy(\\ s\\ d*)?$)" );
12411237 for (Node targetChildNode : targetParentChildNodes ) {
12421238 String targetChildNodeName = targetChildNode .getName ();
1243- if (pattern .matcher (targetChildNodeName ).matches ()){
1239+ if (pattern .matcher (targetChildNodeName ).matches ()) {
12441240 nodeNameCopies .add (targetChildNodeName );
12451241 }
12461242 }
@@ -1267,11 +1263,11 @@ protected String determineNewNodeName(Node sourceNode, List<Node> targetParentCh
12671263 /**
12681264 * Compares {@link Node} names for the purpose of ordering.
12691265 */
1270- public static class NodeNameComparator implements Comparator <String >{
1266+ public static class NodeNameComparator implements Comparator <String > {
12711267
12721268 @ Override
1273- public int compare (String s1 , String s2 ){
1274- if (s1 .endsWith ("copy" ) || s2 .endsWith ("copy" )){
1269+ public int compare (String s1 , String s2 ) {
1270+ if (s1 .endsWith ("copy" ) || s2 .endsWith ("copy" )) {
12751271 return s1 .compareTo (s2 );
12761272 }
12771273 int copyIndex1 = s1 .indexOf ("copy" );
0 commit comments