Skip to content

Commit 41323f2

Browse files
committed
The RestoreResult is only for errors, removing successful entries
1 parent a22821a commit 41323f2

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import java.time.Instant;
5252
import java.util.ArrayList;
5353
import java.util.Collections;
54+
import java.util.Comparator;
5455
import java.util.Date;
5556
import java.util.List;
5657
import java.util.Optional;
@@ -428,8 +429,6 @@ public void restoreFromService(Snapshot snapshot, Consumer<List<RestoreResult>>
428429
@SuppressWarnings("unused")
429430
public void restoreFromClient(Snapshot snapshot, Consumer<List<RestoreResult>> completion) {
430431
new Thread(() -> {
431-
// TODO merge this list with the restoreResultList
432-
List<String> restoreFailedPVNames = new ArrayList<>();
433432
CountDownLatch countDownLatch = new CountDownLatch(snapshot.getSnapshotData().getSnapshotItems().size());
434433

435434
List<RestoreResult> restoreResultList = new ArrayList<>();
@@ -454,11 +453,9 @@ public void restoreFromClient(Snapshot snapshot, Consumer<List<RestoreResult>> c
454453
try {
455454
pv.getPv().write(VTypeHelper.toObject(entry.getValue()));
456455
} catch (Exception writeException) {
457-
restoreFailedPVNames.add(entry.getConfigPv().getPvName());
458456
restoreResult.setErrorMsg(writeException.getMessage());
459457
restoreResultList.add(restoreResult);
460458
} finally {
461-
restoreResultList.add(restoreResult);
462459
pv.countDown();
463460
}
464461
}
@@ -474,15 +471,16 @@ public void restoreFromClient(Snapshot snapshot, Consumer<List<RestoreResult>> c
474471
LOGGER.log(Level.INFO, "Encountered InterruptedException", e);
475472
}
476473

477-
if (restoreFailedPVNames.isEmpty()) {
474+
if (restoreResultList.isEmpty()) {
478475
LOGGER.log(Level.FINE, "Restored snapshot {0}", snapshot.getSnapshotNode().getName());
479476
} else {
480-
Collections.sort(restoreFailedPVNames);
481-
StringBuilder sb = new StringBuilder(restoreFailedPVNames.size() * 200);
482-
restoreFailedPVNames.forEach(e -> sb.append(e).append('\n'));
477+
String msg = restoreResultList.stream()
478+
.sorted(Comparator.comparing(o -> o.getSnapshotItem().getConfigPv().getPvName()))
479+
.map(r -> r.getSnapshotItem().getConfigPv().getPvName())
480+
.collect(Collectors.joining(System.lineSeparator()));
483481
LOGGER.log(Level.WARNING,
484482
"Not all PVs could be restored for {0}: {1}. The following errors occurred:\n{2}",
485-
new Object[]{snapshot.getSnapshotNode().getName(), snapshot.getSnapshotNode(), sb.toString()});
483+
new Object[]{snapshot.getSnapshotNode().getName(), snapshot.getSnapshotNode(), msg});
486484
}
487485
completion.accept(restoreResultList);
488486
}).start();

0 commit comments

Comments
 (0)