Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes Decode Event filtering #1367

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@ test {
dependencies {

// JUnit Tests
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.assertj:assertj-core:3.23.1'
testImplementation('org.junit.jupiter:junit-jupiter-api:5.9.0')
testImplementation 'org.mockito:mockito-core:4.8.0'
testImplementation 'junit:junit:4.12'
testImplementation "org.junit.jupiter:junit-jupiter-api:5.7.0"
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine:5.7.0'
testImplementation 'org.assertj:assertj-core:3.8.0'
testImplementation 'org.mockito:mockito-core:3.+'

testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'

Expand Down
31 changes: 13 additions & 18 deletions src/main/java/io/github/dsheirer/filter/FilterSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public FilterSet( String name )
{
mName = name;
}

public FilterSet()
{
mName = "Message Filter";
Expand All @@ -23,34 +23,32 @@ public FilterSet(IFilter<T> filter)
{
addFilter(filter);
}

public String getName()
{
return mName;
}

public void setName( String name )
{
mName = name;
}

public String toString()
{
return getName();
}

@Override
public boolean passes( T t )
{
if( mEnabled )
{
for( IFilter<T> filter: mFilters )
{
// Make sure to loop through all filters.
// Only return if true or all filters have been evaluated.
if( filter.canProcess( t ) && filter.passes( t ))
if( filter.canProcess( t ))
{
return true;
return filter.passes( t );
}
}
}
Expand All @@ -60,35 +58,32 @@ public boolean passes( T t )
@Override
public boolean canProcess( T t )
{
if( mEnabled )
{
for( IFilter<T> filter: mFilters )
{
if( filter.canProcess( t ) )
{
return true;
}
}
}

return false;

return false;
}

public List<IFilter<T>> getFilters()
{
return mFilters;
}

public void addFilters( List<IFilter<T>> filters )
{
mFilters.addAll( filters );
}

public void addFilter( IFilter<T> filter )
{
mFilters.add( filter );
}

public void removeFilter( IFilter<T> filter )
{
mFilters.remove( filter );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
package io.github.dsheirer.identifier;

import io.github.dsheirer.identifier.configuration.AliasListConfigurationIdentifier;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -79,6 +81,7 @@ public IdentifierCollection(Collection<Identifier> identifiers, int timeslot)
mAliasListConfigurationIdentifier = (AliasListConfigurationIdentifier)identifier;
}
}
mTimeslot = timeslot;
}

public int getTimeslot()
Expand All @@ -100,14 +103,6 @@ public AliasListConfigurationIdentifier getAliasListConfiguration()
return mAliasListConfigurationIdentifier;
}

/**
* Indicates if this collection has an alias list specified.
*/
public boolean hasAliasListConfiguration()
{
return mAliasListConfigurationIdentifier != null;
}

/**
* Immutable list of identifiers contained in this collection
*/
Expand Down Expand Up @@ -332,4 +327,26 @@ public String toString()
}
return sb.toString();
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

final var that = (IdentifierCollection) o;
return new EqualsBuilder()
.append(mTimeslot, that.mTimeslot)
.append(mIdentifiers, that.mIdentifiers)
.append(mAliasListConfigurationIdentifier, that.mAliasListConfigurationIdentifier)
.isEquals();
}

@Override
public int hashCode() {
return new HashCodeBuilder(17, 37)
.append(mIdentifiers)
.append(mAliasListConfigurationIdentifier)
.append(mTimeslot)
.toHashCode();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*/
public class DecodeEvent implements IDecodeEvent
{
private long mTimeStart;
private final long mTimeStart;
private long mTimeEnd;
private String mEventDescription;
private DecodeEventType mDecodeEventType;
Expand All @@ -40,7 +40,7 @@ public class DecodeEvent implements IDecodeEvent
private Protocol mProtocol;
private Integer mTimeslot;

public DecodeEvent(long start)
protected DecodeEvent(long start)
{
mTimeStart = start;
}
Expand Down Expand Up @@ -283,26 +283,6 @@ public DecodeEventBuilder(long timeStart)
mTimeStart = timeStart;
}

/**
* Sets the duration value
* @param duration in milliseconds
*/
public DecodeEventBuilder duration(long duration)
{
mDuration = duration;
return this;
}

/**
* Sets the duration value using the end - start timestamps
* @param timestamp for end of event
*/
public DecodeEventBuilder end(long timestamp)
{
mDuration = timestamp - mTimeStart;
return this;
}

/**
* Sets the channel descriptor for this event
* @param channelDescriptor
Expand Down Expand Up @@ -374,6 +354,7 @@ public DecodeEvent build()
decodeEvent.setChannelDescriptor(mChannelDescriptor);
decodeEvent.setDetails(mDetails);
decodeEvent.setDuration(mDuration);
decodeEvent.setEventType(mDecodeEventType);
decodeEvent.setEventDescription(mEventDescription);
decodeEvent.setIdentifierCollection(mIdentifierCollection);
decodeEvent.setProtocol(mProtocol);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
*/
package io.github.dsheirer.module.decode.event;

import com.google.common.collect.Collections2;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.eventbus.Subscribe;
import io.github.dsheirer.channel.IChannelDescriptor;
import io.github.dsheirer.eventbus.MyEventBus;
Expand All @@ -35,6 +38,7 @@

import javax.swing.table.AbstractTableModel;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

Expand Down Expand Up @@ -121,7 +125,7 @@ public void clear()
public void clearAndSet(List<IDecodeEvent> events)
{
mEvents.clear();
mEvents.addAll(events);
mEvents.addAll(Collections2.filter(Lists.reverse(events), mEventFilterSet::passes));
fireTableDataChanged();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public DecodeEventPanel(IconModel iconModel, UserPreferences userPreferences, Al
{
MyEventBus.getGlobalEventBus().register(this);

setLayout(new MigLayout("insets 0 0 0 0", "[grow,fill]", "[grow,fill]"));
setLayout(new MigLayout("insets 0 0 0 0", "[grow,fill]", "[]0[grow,fill]"));
mIconModel = iconModel;
mAliasModel = aliasModel;
mUserPreferences = userPreferences;
Expand All @@ -97,7 +97,7 @@ public DecodeEventPanel(IconModel iconModel, UserPreferences userPreferences, Al
add(mEventManagementPanel, "span,growx");

mEmptyScroller = new JScrollPane(mTable);
add(mEmptyScroller);
add(mEmptyScroller, "span,grow");
}

public void dispose()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import io.github.dsheirer.filter.FilterSet;
import io.github.dsheirer.module.decode.event.IDecodeEvent;

import java.util.List;

public class DecodeEventFilterSet extends FilterSet<IDecodeEvent> {
public DecodeEventFilterSet() {
super ("All Messages");
Expand All @@ -12,5 +14,20 @@ public DecodeEventFilterSet() {
addFilter(new DecodedDataEventFilter());
addFilter(new DecodedCommandEventFilter());
addFilter(new DecodedRegistrationEventFilter());

// This filter must be last. Its goal is to handle decode events that:
// - do not have type set, or
// - their type is not handled by filters above
addFilter(new EventFilter("Everything else", List.of()) {
@Override
public boolean canProcess(IDecodeEvent iDecodeEvent) {
return true;
}

@Override
public boolean passes(IDecodeEvent iDecodeEvent) {
return isEnabled();
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class DecodedCallEventFilter extends EventFilter
public DecodedCallEventFilter()
{
super("Voice Calls", Arrays.asList(
DecodeEventType.CALL,
DecodeEventType.CALL_GROUP,
DecodeEventType.CALL_PATCH_GROUP,
DecodeEventType.CALL_ALERT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
public class EventFilter extends Filter<IDecodeEvent>
{
private Map<DecodeEventType, FilterElement<DecodeEventType>> mElements = new EnumMap<>(DecodeEventType.class);
private final Map<DecodeEventType, FilterElement<DecodeEventType>> mElements = new EnumMap<>(DecodeEventType.class);

public EventFilter(String name, List<DecodeEventType> eventTypes)
{
Expand All @@ -29,25 +29,22 @@ public EventFilter(String name, List<DecodeEventType> eventTypes)
}
}

@Override
public boolean canProcess(IDecodeEvent iDecodeEvent)
{
return mElements.containsKey(iDecodeEvent.getEventType());
}

@Override
public boolean passes(IDecodeEvent iDecodeEvent)
{
if (mEnabled && canProcess(iDecodeEvent))
{
if (mElements.containsKey(iDecodeEvent.getEventType()))
{
return mElements.get(iDecodeEvent.getEventType()).isEnabled();
}
return mElements.get(iDecodeEvent.getEventType()).isEnabled();
}
return false;
}

@Override
public boolean canProcess(IDecodeEvent iDecodeEvent)
{
return true;
}

@Override
public List<FilterElement<?>> getFilterElements()
{
Expand Down
23 changes: 23 additions & 0 deletions src/test/java/io/github/dsheirer/CommonFixtures.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.github.dsheirer;

import io.github.dsheirer.channel.IChannelDescriptor;
import io.github.dsheirer.identifier.IdentifierCollection;
import io.github.dsheirer.identifier.Role;
import io.github.dsheirer.module.decode.dmr.channel.DMRLogicalChannel;
import io.github.dsheirer.module.decode.dmr.identifier.DMRTalkgroup;

import java.util.List;

public interface CommonFixtures {

default IChannelDescriptor someChannel() {
return new DMRLogicalChannel(1, 1);
}

default IdentifierCollection someIdentifiers() {
return new IdentifierCollection(List.of(
new DMRTalkgroup(1, Role.FROM),
new DMRTalkgroup(2, Role.TO)
));
}
}
Loading