From 16c73d45b0d901e243ca32b1cd17f159057d7a3a Mon Sep 17 00:00:00 2001 From: millmanorama Date: Thu, 1 Nov 2018 14:13:03 +0100 Subject: [PATCH] `fix RootFilterState intersection --- .../autopsy/timeline/FilteredEventsModel.java | 13 ++++---- .../ui/countsview/EventCountsChart.java | 3 +- .../datamodel/CompoundFilterState.java | 4 +-- .../datamodel/CompoundFilterStateImpl.java | 2 +- .../filtering/datamodel/RootFilterState.java | 31 ++++++++++++++++++- 5 files changed, 40 insertions(+), 13 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/timeline/FilteredEventsModel.java b/Core/src/org/sleuthkit/autopsy/timeline/FilteredEventsModel.java index cd3b4c8796..897f3d9560 100644 --- a/Core/src/org/sleuthkit/autopsy/timeline/FilteredEventsModel.java +++ b/Core/src/org/sleuthkit/autopsy/timeline/FilteredEventsModel.java @@ -23,6 +23,7 @@ import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableList; import com.google.common.eventbus.EventBus; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashSet; @@ -89,7 +90,6 @@ import org.sleuthkit.datamodel.timeline.TimelineFilter.TagsFilter; import org.sleuthkit.datamodel.timeline.TimelineFilter.TextFilter; import org.sleuthkit.datamodel.timeline.TimelineFilter.TypeFilter; - /** * This class acts as the model for a TimelineView * @@ -192,7 +192,7 @@ public final class FilteredEventsModel { * the EvenType of the level specified in the zoomState * * @param zoomState The params that control what events to count and how to - * organize the returned map + * organize the returned map * * @return a map from event type( of the requested level) to event counts * @@ -285,7 +285,6 @@ public final class FilteredEventsModel { filterState.setDisabled(tagNames.contains(filterState.getFilter().getTagName()) == false); } } - /** * Get a read only view of the time range currently in view. @@ -407,13 +406,13 @@ public final class FilteredEventsModel { public List getEventIDs(Interval timeRange, TimelineFilter filter) throws TskCoreException { final Interval overlap; - final RootFilterState intersect; + RootFilterState intersection; synchronized (this) { overlap = getSpanningInterval().overlap(timeRange); - intersect = getFilterState().copyOf(); + intersection = getFilterState().intersect(filter); } - intersect.getFilter().getSubFilters().add(filter); - return eventManager.getEventIDs(overlap, intersect.getActiveFilter()); + + return eventManager.getEventIDs(overlap, intersection.getActiveFilter()); } /** diff --git a/Core/src/org/sleuthkit/autopsy/timeline/ui/countsview/EventCountsChart.java b/Core/src/org/sleuthkit/autopsy/timeline/ui/countsview/EventCountsChart.java index a990b71a2d..7bf76a1d7d 100644 --- a/Core/src/org/sleuthkit/autopsy/timeline/ui/countsview/EventCountsChart.java +++ b/Core/src/org/sleuthkit/autopsy/timeline/ui/countsview/EventCountsChart.java @@ -286,8 +286,7 @@ final class EventCountsChart extends StackedBarChart implements * stacked bar chart. * * Concurrency Policy: This only accesses immutable state or javafx nodes - * (from the jfx thread) and the internally synchronized - * {@link TimeLineController} + * (from the jfx thread) and the internally synchronized TimeLineController * * TODO: review for thread safety -jm */ diff --git a/Core/src/org/sleuthkit/autopsy/timeline/ui/filtering/datamodel/CompoundFilterState.java b/Core/src/org/sleuthkit/autopsy/timeline/ui/filtering/datamodel/CompoundFilterState.java index 7c5745cb35..f6c60f58f0 100644 --- a/Core/src/org/sleuthkit/autopsy/timeline/ui/filtering/datamodel/CompoundFilterState.java +++ b/Core/src/org/sleuthkit/autopsy/timeline/ui/filtering/datamodel/CompoundFilterState.java @@ -33,9 +33,9 @@ import org.sleuthkit.datamodel.timeline.TimelineFilter.CompoundFilter; */ public interface CompoundFilterState> extends FilterState { - ObservableList> getSubFilterStates(); + ObservableList> getSubFilterStates(); @Override public CompoundFilterState copyOf(); -} + } diff --git a/Core/src/org/sleuthkit/autopsy/timeline/ui/filtering/datamodel/CompoundFilterStateImpl.java b/Core/src/org/sleuthkit/autopsy/timeline/ui/filtering/datamodel/CompoundFilterStateImpl.java index 2fb8cc9685..13f86afec2 100644 --- a/Core/src/org/sleuthkit/autopsy/timeline/ui/filtering/datamodel/CompoundFilterStateImpl.java +++ b/Core/src/org/sleuthkit/autopsy/timeline/ui/filtering/datamodel/CompoundFilterStateImpl.java @@ -108,7 +108,7 @@ class CompoundFilterStateImpl newFilterModel) { - subFilterStates.add(newFilterModel); + getSubFilterStates().add(newFilterModel); newFilterModel.selectedProperty().addListener(selectedProperty -> { //set this compound filter model selected af any of the subfilters are selected. setSelected(getSubFilterStates().stream().anyMatch(FilterState::isSelected)); diff --git a/Core/src/org/sleuthkit/autopsy/timeline/ui/filtering/datamodel/RootFilterState.java b/Core/src/org/sleuthkit/autopsy/timeline/ui/filtering/datamodel/RootFilterState.java index 7f936b41fa..170c59f5f9 100644 --- a/Core/src/org/sleuthkit/autopsy/timeline/ui/filtering/datamodel/RootFilterState.java +++ b/Core/src/org/sleuthkit/autopsy/timeline/ui/filtering/datamodel/RootFilterState.java @@ -22,7 +22,9 @@ import java.util.Collections; import javafx.beans.property.ReadOnlyBooleanProperty; import javafx.beans.property.ReadOnlyBooleanWrapper; import javafx.collections.FXCollections; +import javafx.collections.ListChangeListener; import javafx.collections.ObservableList; +import org.python.google.common.collect.Lists; import org.sleuthkit.datamodel.TimelineManager; import org.sleuthkit.datamodel.timeline.TimelineFilter; import org.sleuthkit.datamodel.timeline.TimelineFilter.DataSourceFilter; @@ -83,6 +85,33 @@ public class RootFilterState implements FilterState, CompoundFilterS dataSourcesFilterState, typeFilterState); } + /** + * Get a new root filter that intersects the given filter with this one. + * + * @param otherFilter + * + * @return A new RootFilter model that intersects the given filter with this + * one. + */ + public RootFilterState intersect(TimelineFilter otherFilter) { + RootFilterState copyOf = copyOf(); + copyOf.addSubFilterState(otherFilter); + return copyOf; + } + + private void addSubFilterState(TimelineFilter subFilter) { + + if (subFilter instanceof TimelineFilter.CompoundFilter) { + CompoundFilterStateImpl> compoundFilterStateImpl = new CompoundFilterStateImpl<>((TimelineFilter.CompoundFilter) subFilter); + getSubFilterStates().add(compoundFilterStateImpl); + compoundFilterStateImpl.setSelected(Boolean.TRUE); + } else { + DefaultFilterState defaultFilterState = new DefaultFilterState<>(subFilter); + getSubFilterStates().add(defaultFilterState); + defaultFilterState.setSelected(Boolean.TRUE); + } + } + @Override public RootFilterState copyOf() { return new RootFilterState(getFilter().copyOf(), @@ -126,7 +155,7 @@ public class RootFilterState implements FilterState, CompoundFilterS textFilterState.getActiveFilter(), typeFilterState.getActiveFilter(), dataSourcesFilterState.getActiveFilter(), - Collections.emptySet()); + Lists.transform(subFilterStates, FilterState::getActiveFilter)); } @SuppressWarnings("rawtypes")