Skip to content

Commit

Permalink
Improved handling of failing to load filter from v1 session files
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanielsherry committed Jan 22, 2024
1 parent 7629667 commit c9c4964
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public List<String> loadInto(PlotController plotController) {
this.data.loadInto(plotController.data());

//restore filtering settings
this.filtering.loadInto(plotController.filtering());
this.filtering.loadInto(plotController.filtering(), errors);

//restore fitting settings
errors.addAll(this.fitting.loadInto(plotController.fitting()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ public class SavedFilteringSessionV1 {


@Deprecated(since = "6", forRemoval = true)
public void loadInto(FilteringController controller) {
public void loadInto(FilteringController controller, List<String> errors) {
FilterSet filterset = controller.getFilteringModel().filters;
filterset.clear();
for (SerializedFilterV1 f : this.filters) {
try {
filterset.add(f.getFilter());
filterset.add(f.getFilter(errors).orElseThrow());
} catch (Exception e) {
PeakabooLog.get().log(Level.SEVERE, "Failed to restore filter", e);
errors.add("Failed to restore filter " + f.getClazz());
PeakabooLog.get().log(Level.WARNING, "Failed to restore filter " + f.getClazz(), e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.logging.Level;

import org.peakaboo.app.PeakabooLog;
import org.peakaboo.framework.bolt.plugin.core.BoltPlugin;
import org.peakaboo.framework.bolt.plugin.core.PluginDescriptor;

Expand Down Expand Up @@ -85,9 +88,9 @@ public void setSettingsMap(Map<String, Object> settings) {
}

@Deprecated(since = "6", forRemoval = true)
public Filter getFilter() {
public Optional<Filter> getFilter(List<String> errors) {
//If it already exists, just return it, otherwise build a filter
if (filter != null) { return filter; }
if (filter != null) { return Optional.of(filter); }

for (PluginDescriptor<? extends Filter> plugin : FilterRegistry.system().getPlugins()) {
if (
Expand All @@ -109,12 +112,17 @@ public Filter getFilter() {
filter.getParameterGroup().deserialize(this.settings);
}
} catch (IllegalArgumentException e) {
throw new RuntimeException("Cannot build plugin: " + plugin.getName(), e);
var msg = "Cannot restore settings for " + plugin.getName();
errors.add(msg);
PeakabooLog.get().log(Level.WARNING, msg, e);
}
return filter;
return Optional.of(filter);
}
}
throw new RuntimeException("Cannot find plugin " + uuidOrClazz);
var msg = "Cannot restore plugin " + uuidOrClazz;
errors.add(msg);
PeakabooLog.get().log(Level.WARNING, msg);
return Optional.empty();
}


Expand Down

0 comments on commit c9c4964

Please sign in to comment.