forked from traccar/traccar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
21 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright 2016 Anton Tananaev ([email protected]) | ||
* Copyright 2016 - 2018 Anton Tananaev ([email protected]) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
|
@@ -19,18 +19,34 @@ | |
import java.util.Map; | ||
|
||
import org.traccar.BaseEventHandler; | ||
import org.traccar.Context; | ||
import org.traccar.model.Event; | ||
import org.traccar.model.Position; | ||
|
||
public class AlertEventHandler extends BaseEventHandler { | ||
|
||
private final boolean ignoreDuplicateAlerts; | ||
|
||
public AlertEventHandler() { | ||
ignoreDuplicateAlerts = Context.getConfig().getBoolean("event.ignoreDuplicateAlerts"); | ||
} | ||
|
||
@Override | ||
protected Map<Event, Position> analyzePosition(Position position) { | ||
Object alarm = position.getAttributes().get(Position.KEY_ALARM); | ||
if (alarm != null) { | ||
Event event = new Event(Event.TYPE_ALARM, position.getDeviceId(), position.getId()); | ||
event.set(Position.KEY_ALARM, (String) alarm); | ||
return Collections.singletonMap(event, position); | ||
boolean ignoreAlert = false; | ||
if (ignoreDuplicateAlerts) { | ||
Position lastPosition = Context.getIdentityManager().getLastPosition(position.getDeviceId()); | ||
if (lastPosition != null && alarm.equals(lastPosition.getAttributes().get(Position.KEY_ALARM))) { | ||
ignoreAlert = true; | ||
} | ||
} | ||
if (!ignoreAlert) { | ||
Event event = new Event(Event.TYPE_ALARM, position.getDeviceId(), position.getId()); | ||
event.set(Position.KEY_ALARM, (String) alarm); | ||
return Collections.singletonMap(event, position); | ||
} | ||
} | ||
return null; | ||
} | ||
|