use of org.traccar.model.Event in project traccar by tananaev.
the class MotionEventHandler method updateMotionState.
public Map<Event, Position> updateMotionState(DeviceState deviceState) {
Map<Event, Position> result = null;
if (deviceState.getMotionState() != null && deviceState.getMotionPosition() != null) {
boolean newMotion = !deviceState.getMotionState();
Position motionPosition = deviceState.getMotionPosition();
long currentTime = System.currentTimeMillis();
long motionTime = motionPosition.getFixTime().getTime() + (newMotion ? tripsConfig.getMinimalTripDuration() : tripsConfig.getMinimalParkingDuration());
if (motionTime <= currentTime) {
result = newEvent(deviceState, newMotion);
}
}
return result;
}
use of org.traccar.model.Event in project traccar by tananaev.
the class TextMessageEventHandler method handleTextMessage.
public static void handleTextMessage(String phone, String message) {
Device device = Context.getDeviceManager().getDeviceByPhone(phone);
if (device != null && Context.getNotificationManager() != null) {
Event event = new Event(Event.TYPE_TEXT_MESSAGE, device.getId());
event.set("message", message);
Context.getNotificationManager().updateEvent(event, null);
}
}
use of org.traccar.model.Event in project traccar by tananaev.
the class EventResource method get.
@Path("{id}")
@GET
public Event get(@PathParam("id") long id) throws SQLException {
Event event = Context.getDataManager().getObject(Event.class, id);
Context.getPermissionsManager().checkDevice(getUserId(), event.getDeviceId());
if (event.getGeofenceId() != 0) {
Context.getPermissionsManager().checkPermission(Geofence.class, getUserId(), event.getGeofenceId());
}
return event;
}
use of org.traccar.model.Event in project traccar by tananaev.
the class GeofenceEventHandler method analyzePosition.
@Override
protected Map<Event, Position> analyzePosition(Position position) {
Device device = Context.getIdentityManager().getById(position.getDeviceId());
if (device == null) {
return null;
}
if (!Context.getIdentityManager().isLatestPosition(position) || !position.getValid()) {
return null;
}
List<Long> currentGeofences = geofenceManager.getCurrentDeviceGeofences(position);
List<Long> oldGeofences = new ArrayList<>();
if (device.getGeofenceIds() != null) {
oldGeofences.addAll(device.getGeofenceIds());
}
List<Long> newGeofences = new ArrayList<>(currentGeofences);
newGeofences.removeAll(oldGeofences);
oldGeofences.removeAll(currentGeofences);
device.setGeofenceIds(currentGeofences);
Map<Event, Position> events = new HashMap<>();
for (long geofenceId : newGeofences) {
long calendarId = geofenceManager.getById(geofenceId).getCalendarId();
Calendar calendar = calendarId != 0 ? Context.getCalendarManager().getById(calendarId) : null;
if (calendar == null || calendar.checkMoment(position.getFixTime())) {
Event event = new Event(Event.TYPE_GEOFENCE_ENTER, position.getDeviceId(), position.getId());
event.setGeofenceId(geofenceId);
events.put(event, position);
}
}
for (long geofenceId : oldGeofences) {
long calendarId = geofenceManager.getById(geofenceId).getCalendarId();
Calendar calendar = calendarId != 0 ? Context.getCalendarManager().getById(calendarId) : null;
if (calendar == null || calendar.checkMoment(position.getFixTime())) {
Event event = new Event(Event.TYPE_GEOFENCE_EXIT, position.getDeviceId(), position.getId());
event.setGeofenceId(geofenceId);
events.put(event, position);
}
}
return events;
}
use of org.traccar.model.Event in project traccar by tananaev.
the class OverspeedEventHandler method newEvent.
private Map<Event, Position> newEvent(DeviceState deviceState, double speedLimit) {
Position position = deviceState.getOverspeedPosition();
Event event = new Event(Event.TYPE_DEVICE_OVERSPEED, position.getDeviceId(), position.getId());
event.set("speed", deviceState.getOverspeedPosition().getSpeed());
event.set(ATTRIBUTE_SPEED_LIMIT, speedLimit);
deviceState.setOverspeedState(notRepeat);
deviceState.setOverspeedPosition(null);
return Collections.singletonMap(event, position);
}
Aggregations