From b588b3c723cad4629dcecbce8983933f7ff2a255 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Tue, 14 Jun 2016 18:05:05 +0500 Subject: - Overlapping geofences - Simplified user-device link --- src/org/traccar/BaseEventHandler.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/org/traccar/BaseEventHandler.java') diff --git a/src/org/traccar/BaseEventHandler.java b/src/org/traccar/BaseEventHandler.java index 3e3317f0a..16d911dac 100644 --- a/src/org/traccar/BaseEventHandler.java +++ b/src/org/traccar/BaseEventHandler.java @@ -1,5 +1,7 @@ package org.traccar; +import java.util.Collection; + import org.traccar.model.Device; import org.traccar.model.Event; import org.traccar.model.Position; @@ -23,13 +25,15 @@ public abstract class BaseEventHandler extends BaseDataHandler { } } - Event event = analizePosition(position); - if (event != null) { - Context.getConnectionManager().updateEvent(event, position); + Collection events = analizePosition(position); + if (events != null) { + for (Event event : events) { + Context.getNotificationManager().updateEvent(event, position); + } } return position; } - protected abstract Event analizePosition(Position position); + protected abstract Collection analizePosition(Position position); } -- cgit v1.2.3 From f08bb5adf425269a00e760c669bdeeadc8c7e112 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Wed, 15 Jun 2016 14:22:23 +0500 Subject: - Work only with cached devices from everywhere - Some optimization --- src/org/traccar/BaseEventHandler.java | 8 +++++++- src/org/traccar/api/resource/DeviceResource.java | 2 +- src/org/traccar/database/DataManager.java | 25 +++++++++++++++++++++++- src/org/traccar/database/GeofenceManager.java | 2 +- src/org/traccar/database/PermissionsManager.java | 2 +- src/org/traccar/events/GeofenceEventHandler.java | 10 ++++------ src/org/traccar/events/MotionEventHandler.java | 5 ++--- 7 files changed, 40 insertions(+), 14 deletions(-) (limited to 'src/org/traccar/BaseEventHandler.java') diff --git a/src/org/traccar/BaseEventHandler.java b/src/org/traccar/BaseEventHandler.java index 16d911dac..78542b33a 100644 --- a/src/org/traccar/BaseEventHandler.java +++ b/src/org/traccar/BaseEventHandler.java @@ -14,10 +14,16 @@ public abstract class BaseEventHandler extends BaseDataHandler { return isLastPosition; } + private Device device; + + public Device getDevice() { + return device; + } + @Override protected Position handlePosition(Position position) { - Device device = Context.getDataManager().getDeviceById(position.getDeviceId()); + device = Context.getDataManager().getDeviceById(position.getDeviceId()); if (device != null) { long lastPositionId = device.getPositionId(); if (position.getId() == lastPositionId) { diff --git a/src/org/traccar/api/resource/DeviceResource.java b/src/org/traccar/api/resource/DeviceResource.java index 26880c1f8..fcbeed97b 100644 --- a/src/org/traccar/api/resource/DeviceResource.java +++ b/src/org/traccar/api/resource/DeviceResource.java @@ -44,7 +44,7 @@ public class DeviceResource extends BaseResource { @QueryParam("all") boolean all, @QueryParam("userId") long userId) throws SQLException { if (all) { Context.getPermissionsManager().checkAdmin(getUserId()); - return Context.getDataManager().getAllDevices(); + return Context.getDataManager().getAllDevicesCached(); } else { if (userId == 0) { userId = getUserId(); diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java index a32d31d68..f5df1b84b 100644 --- a/src/org/traccar/database/DataManager.java +++ b/src/org/traccar/database/DataManager.java @@ -342,11 +342,34 @@ public class DataManager implements IdentityManager { .executeQuery(GroupPermission.class); } - public Collection getAllDevices() throws SQLException { + private Collection getAllDevices() throws SQLException { return QueryBuilder.create(dataSource, getQuery("database.selectDevicesAll")) .executeQuery(Device.class); } + public Collection getAllDevicesCached() { + boolean forceUpdate; + devicesLock.readLock().lock(); + try { + forceUpdate = devicesById.values().isEmpty(); + } finally { + devicesLock.readLock().unlock(); + } + + try { + updateDeviceCache(forceUpdate); + } catch (SQLException e) { + Log.warning(e); + } + + devicesLock.readLock().lock(); + try { + return devicesById.values(); + } finally { + devicesLock.readLock().unlock(); + } + } + public Collection getDevices(long userId) throws SQLException { Collection devices = new ArrayList<>(); for (long id : Context.getPermissionsManager().getDevicePermissions(userId)) { diff --git a/src/org/traccar/database/GeofenceManager.java b/src/org/traccar/database/GeofenceManager.java index b551bc467..0119a62ca 100644 --- a/src/org/traccar/database/GeofenceManager.java +++ b/src/org/traccar/database/GeofenceManager.java @@ -113,7 +113,7 @@ public class GeofenceManager { .add(deviceGeofence.getGeofenceId()); } - for (Device device : dataManager.getAllDevices()) { + for (Device device : dataManager.getAllDevicesCached()) { long groupId = device.getGroupId(); while (groupId != 0) { getDeviceGeofences(deviceGeofencesWithGroups, diff --git a/src/org/traccar/database/PermissionsManager.java b/src/org/traccar/database/PermissionsManager.java index 96a6488ef..b6dd2e2a9 100644 --- a/src/org/traccar/database/PermissionsManager.java +++ b/src/org/traccar/database/PermissionsManager.java @@ -78,7 +78,7 @@ public class PermissionsManager { users.put(user.getId(), user); } - GroupTree groupTree = new GroupTree(dataManager.getAllGroups(), dataManager.getAllDevices()); + GroupTree groupTree = new GroupTree(dataManager.getAllGroups(), dataManager.getAllDevicesCached()); for (GroupPermission permission : dataManager.getGroupPermissions()) { Set userGroupPermissions = getGroupPermissions(permission.getUserId()); Set userDevicePermissions = getDevicePermissions(permission.getUserId()); diff --git a/src/org/traccar/events/GeofenceEventHandler.java b/src/org/traccar/events/GeofenceEventHandler.java index ed63b6f7d..56029fced 100644 --- a/src/org/traccar/events/GeofenceEventHandler.java +++ b/src/org/traccar/events/GeofenceEventHandler.java @@ -10,7 +10,6 @@ import org.traccar.Context; import org.traccar.database.DataManager; import org.traccar.database.GeofenceManager; import org.traccar.helper.Log; -import org.traccar.model.Device; import org.traccar.model.Event; import org.traccar.model.Position; @@ -32,21 +31,20 @@ public class GeofenceEventHandler extends BaseEventHandler { return null; } - Device device = dataManager.getDeviceById(position.getDeviceId()); - if (device == null) { + if (getDevice() == null) { return null; } List currentGeofences = geofenceManager.getCurrentDeviceGeofences(position); List oldGeofences = new ArrayList(); - if (device.getGeofenceIds() != null) { - oldGeofences.addAll(device.getGeofenceIds()); + if (getDevice().getGeofenceIds() != null) { + oldGeofences.addAll(getDevice().getGeofenceIds()); } List newGeofences = new ArrayList(currentGeofences); newGeofences.removeAll(oldGeofences); oldGeofences.removeAll(currentGeofences); - device.setGeofenceIds(currentGeofences); + getDevice().setGeofenceIds(currentGeofences); Collection events = new ArrayList<>(); try { diff --git a/src/org/traccar/events/MotionEventHandler.java b/src/org/traccar/events/MotionEventHandler.java index 54b6b922d..2ba5979e3 100644 --- a/src/org/traccar/events/MotionEventHandler.java +++ b/src/org/traccar/events/MotionEventHandler.java @@ -29,11 +29,10 @@ public class MotionEventHandler extends BaseEventHandler { double speed = position.getSpeed(); boolean valid = position.getValid(); - Device device = Context.getIdentityManager().getDeviceById(position.getDeviceId()); - if (device == null) { + if (getDevice() == null) { return null; } - String motion = device.getMotion(); + String motion = getDevice().getMotion(); if (motion == null) { motion = Device.STATUS_STOPPED; } -- cgit v1.2.3 From 5d56e9e452c8bebe93047497eb55f527fcc40ffc Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Thu, 16 Jun 2016 10:05:38 +0500 Subject: Fix typo and remove unnecessary super() --- src/org/traccar/BaseEventHandler.java | 4 ++-- src/org/traccar/events/CommandResultEventHandler.java | 2 +- src/org/traccar/events/GeofenceEventHandler.java | 2 +- src/org/traccar/events/MotionEventHandler.java | 2 +- src/org/traccar/events/OverspeedEventHandler.java | 2 +- src/org/traccar/geofence/GeofenceCircle.java | 2 -- src/org/traccar/geofence/GeofencePolygon.java | 2 -- 7 files changed, 6 insertions(+), 10 deletions(-) (limited to 'src/org/traccar/BaseEventHandler.java') diff --git a/src/org/traccar/BaseEventHandler.java b/src/org/traccar/BaseEventHandler.java index 78542b33a..d5755be89 100644 --- a/src/org/traccar/BaseEventHandler.java +++ b/src/org/traccar/BaseEventHandler.java @@ -31,7 +31,7 @@ public abstract class BaseEventHandler extends BaseDataHandler { } } - Collection events = analizePosition(position); + Collection events = analyzePosition(position); if (events != null) { for (Event event : events) { Context.getNotificationManager().updateEvent(event, position); @@ -40,6 +40,6 @@ public abstract class BaseEventHandler extends BaseDataHandler { return position; } - protected abstract Collection analizePosition(Position position); + protected abstract Collection analyzePosition(Position position); } diff --git a/src/org/traccar/events/CommandResultEventHandler.java b/src/org/traccar/events/CommandResultEventHandler.java index 9dbdb4b4c..8e19e9523 100644 --- a/src/org/traccar/events/CommandResultEventHandler.java +++ b/src/org/traccar/events/CommandResultEventHandler.java @@ -10,7 +10,7 @@ import org.traccar.model.Position; public class CommandResultEventHandler extends BaseEventHandler { @Override - protected Collection analizePosition(Position position) { + protected Collection analyzePosition(Position position) { Object commandResult = position.getAttributes().get(Position.KEY_RESULT); if (commandResult != null) { Collection events = new ArrayList<>(); diff --git a/src/org/traccar/events/GeofenceEventHandler.java b/src/org/traccar/events/GeofenceEventHandler.java index 56029fced..e3598bd16 100644 --- a/src/org/traccar/events/GeofenceEventHandler.java +++ b/src/org/traccar/events/GeofenceEventHandler.java @@ -26,7 +26,7 @@ public class GeofenceEventHandler extends BaseEventHandler { } @Override - protected Collection analizePosition(Position position) { + protected Collection analyzePosition(Position position) { if (!isLastPosition() || !position.getValid()) { return null; } diff --git a/src/org/traccar/events/MotionEventHandler.java b/src/org/traccar/events/MotionEventHandler.java index 2ba5979e3..5b1020aec 100644 --- a/src/org/traccar/events/MotionEventHandler.java +++ b/src/org/traccar/events/MotionEventHandler.java @@ -21,7 +21,7 @@ public class MotionEventHandler extends BaseEventHandler { } @Override - protected Collection analizePosition(Position position) { + protected Collection analyzePosition(Position position) { Collection result = null; if (!isLastPosition()) { return null; diff --git a/src/org/traccar/events/OverspeedEventHandler.java b/src/org/traccar/events/OverspeedEventHandler.java index 152fe6f22..61089274d 100644 --- a/src/org/traccar/events/OverspeedEventHandler.java +++ b/src/org/traccar/events/OverspeedEventHandler.java @@ -22,7 +22,7 @@ public class OverspeedEventHandler extends BaseEventHandler { } @Override - protected Collection analizePosition(Position position) { + protected Collection analyzePosition(Position position) { Collection events = new ArrayList<>(); if (!isLastPosition()) { return null; diff --git a/src/org/traccar/geofence/GeofenceCircle.java b/src/org/traccar/geofence/GeofenceCircle.java index e1c8f8a02..f71497475 100644 --- a/src/org/traccar/geofence/GeofenceCircle.java +++ b/src/org/traccar/geofence/GeofenceCircle.java @@ -12,11 +12,9 @@ public class GeofenceCircle extends GeofenceGeometry { private double radius; public GeofenceCircle() { - super(); } public GeofenceCircle(String wkt) throws ParseException { - super(); fromWkt(wkt); } diff --git a/src/org/traccar/geofence/GeofencePolygon.java b/src/org/traccar/geofence/GeofencePolygon.java index 52920b7b1..970734214 100644 --- a/src/org/traccar/geofence/GeofencePolygon.java +++ b/src/org/traccar/geofence/GeofencePolygon.java @@ -6,11 +6,9 @@ import java.util.ArrayList; public class GeofencePolygon extends GeofenceGeometry { public GeofencePolygon() { - super(); } public GeofencePolygon(String wkt) throws ParseException { - super(); fromWkt(wkt); } -- cgit v1.2.3 From 3f0f6c1f6ec4665783ec62a65f8f30a33f1d2152 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Thu, 16 Jun 2016 10:20:44 +0500 Subject: Added/updated license headers --- src/org/traccar/BaseEventHandler.java | 15 +++++++++++++++ src/org/traccar/Context.java | 2 +- src/org/traccar/api/resource/DeviceGeofenceResource.java | 2 +- src/org/traccar/api/resource/DeviceResource.java | 2 +- src/org/traccar/api/resource/GeofenceResource.java | 2 +- src/org/traccar/api/resource/UserResource.java | 2 +- src/org/traccar/database/ConnectionManager.java | 2 +- src/org/traccar/database/GeofenceManager.java | 15 +++++++++++++++ src/org/traccar/database/NotificationManager.java | 15 +++++++++++++++ src/org/traccar/events/CommandResultEventHandler.java | 15 +++++++++++++++ src/org/traccar/events/GeofenceEventHandler.java | 15 +++++++++++++++ src/org/traccar/events/MotionEventHandler.java | 15 +++++++++++++++ src/org/traccar/events/OverspeedEventHandler.java | 15 +++++++++++++++ src/org/traccar/geofence/GeofenceCircle.java | 15 +++++++++++++++ src/org/traccar/geofence/GeofenceGeometry.java | 15 +++++++++++++++ src/org/traccar/geofence/GeofencePolygon.java | 15 +++++++++++++++ src/org/traccar/model/DeviceGeofence.java | 15 +++++++++++++++ src/org/traccar/model/Event.java | 15 +++++++++++++++ src/org/traccar/model/Extensible.java | 15 +++++++++++++++ src/org/traccar/model/Geofence.java | 15 +++++++++++++++ src/org/traccar/model/GeofencePermission.java | 15 +++++++++++++++ src/org/traccar/model/GroupGeofence.java | 15 +++++++++++++++ src/org/traccar/model/Message.java | 2 +- src/org/traccar/model/Position.java | 2 +- 24 files changed, 248 insertions(+), 8 deletions(-) (limited to 'src/org/traccar/BaseEventHandler.java') diff --git a/src/org/traccar/BaseEventHandler.java b/src/org/traccar/BaseEventHandler.java index d5755be89..143c2dc2b 100644 --- a/src/org/traccar/BaseEventHandler.java +++ b/src/org/traccar/BaseEventHandler.java @@ -1,3 +1,18 @@ +/* + * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.traccar; import java.util.Collection; diff --git a/src/org/traccar/Context.java b/src/org/traccar/Context.java index 6f99ff97d..f40db72e5 100644 --- a/src/org/traccar/Context.java +++ b/src/org/traccar/Context.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/org/traccar/api/resource/DeviceGeofenceResource.java b/src/org/traccar/api/resource/DeviceGeofenceResource.java index 99d64292b..27535617d 100644 --- a/src/org/traccar/api/resource/DeviceGeofenceResource.java +++ b/src/org/traccar/api/resource/DeviceGeofenceResource.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/org/traccar/api/resource/DeviceResource.java b/src/org/traccar/api/resource/DeviceResource.java index fcbeed97b..d6032bb1e 100644 --- a/src/org/traccar/api/resource/DeviceResource.java +++ b/src/org/traccar/api/resource/DeviceResource.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/org/traccar/api/resource/GeofenceResource.java b/src/org/traccar/api/resource/GeofenceResource.java index b56e20e08..9c80e61a1 100644 --- a/src/org/traccar/api/resource/GeofenceResource.java +++ b/src/org/traccar/api/resource/GeofenceResource.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/org/traccar/api/resource/UserResource.java b/src/org/traccar/api/resource/UserResource.java index 7e503dcfb..7cc4ed09a 100644 --- a/src/org/traccar/api/resource/UserResource.java +++ b/src/org/traccar/api/resource/UserResource.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/org/traccar/database/ConnectionManager.java b/src/org/traccar/database/ConnectionManager.java index 4f12c44d4..8a1debdfa 100644 --- a/src/org/traccar/database/ConnectionManager.java +++ b/src/org/traccar/database/ConnectionManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/org/traccar/database/GeofenceManager.java b/src/org/traccar/database/GeofenceManager.java index 0119a62ca..0a07e2cf3 100644 --- a/src/org/traccar/database/GeofenceManager.java +++ b/src/org/traccar/database/GeofenceManager.java @@ -1,3 +1,18 @@ +/* + * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.traccar.database; import java.sql.SQLException; diff --git a/src/org/traccar/database/NotificationManager.java b/src/org/traccar/database/NotificationManager.java index 8c8e958c8..7593367a3 100644 --- a/src/org/traccar/database/NotificationManager.java +++ b/src/org/traccar/database/NotificationManager.java @@ -1,3 +1,18 @@ +/* + * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.traccar.database; import java.sql.SQLException; diff --git a/src/org/traccar/events/CommandResultEventHandler.java b/src/org/traccar/events/CommandResultEventHandler.java index 8e19e9523..3f4ff521b 100644 --- a/src/org/traccar/events/CommandResultEventHandler.java +++ b/src/org/traccar/events/CommandResultEventHandler.java @@ -1,3 +1,18 @@ +/* + * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.traccar.events; import java.util.ArrayList; diff --git a/src/org/traccar/events/GeofenceEventHandler.java b/src/org/traccar/events/GeofenceEventHandler.java index e3598bd16..7d24c4efe 100644 --- a/src/org/traccar/events/GeofenceEventHandler.java +++ b/src/org/traccar/events/GeofenceEventHandler.java @@ -1,3 +1,18 @@ +/* + * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.traccar.events; import java.sql.SQLException; diff --git a/src/org/traccar/events/MotionEventHandler.java b/src/org/traccar/events/MotionEventHandler.java index 5b1020aec..c05bd4843 100644 --- a/src/org/traccar/events/MotionEventHandler.java +++ b/src/org/traccar/events/MotionEventHandler.java @@ -1,3 +1,18 @@ +/* + * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.traccar.events; import java.sql.SQLException; diff --git a/src/org/traccar/events/OverspeedEventHandler.java b/src/org/traccar/events/OverspeedEventHandler.java index 61089274d..f4676b995 100644 --- a/src/org/traccar/events/OverspeedEventHandler.java +++ b/src/org/traccar/events/OverspeedEventHandler.java @@ -1,3 +1,18 @@ +/* + * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.traccar.events; import java.sql.SQLException; diff --git a/src/org/traccar/geofence/GeofenceCircle.java b/src/org/traccar/geofence/GeofenceCircle.java index f71497475..56230240b 100644 --- a/src/org/traccar/geofence/GeofenceCircle.java +++ b/src/org/traccar/geofence/GeofenceCircle.java @@ -1,3 +1,18 @@ +/* + * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.traccar.geofence; import java.text.DecimalFormat; diff --git a/src/org/traccar/geofence/GeofenceGeometry.java b/src/org/traccar/geofence/GeofenceGeometry.java index 83656a029..e717ede0b 100644 --- a/src/org/traccar/geofence/GeofenceGeometry.java +++ b/src/org/traccar/geofence/GeofenceGeometry.java @@ -1,3 +1,18 @@ +/* + * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.traccar.geofence; import java.text.ParseException; diff --git a/src/org/traccar/geofence/GeofencePolygon.java b/src/org/traccar/geofence/GeofencePolygon.java index 970734214..be5f971a5 100644 --- a/src/org/traccar/geofence/GeofencePolygon.java +++ b/src/org/traccar/geofence/GeofencePolygon.java @@ -1,3 +1,18 @@ +/* + * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.traccar.geofence; import java.text.ParseException; diff --git a/src/org/traccar/model/DeviceGeofence.java b/src/org/traccar/model/DeviceGeofence.java index f55c8ca69..05f06bb3d 100644 --- a/src/org/traccar/model/DeviceGeofence.java +++ b/src/org/traccar/model/DeviceGeofence.java @@ -1,3 +1,18 @@ +/* + * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.traccar.model; public class DeviceGeofence { diff --git a/src/org/traccar/model/Event.java b/src/org/traccar/model/Event.java index 863acd621..235a39f9a 100644 --- a/src/org/traccar/model/Event.java +++ b/src/org/traccar/model/Event.java @@ -1,3 +1,18 @@ +/* + * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.traccar.model; import java.util.Date; diff --git a/src/org/traccar/model/Extensible.java b/src/org/traccar/model/Extensible.java index b4052dbda..eceeccadf 100644 --- a/src/org/traccar/model/Extensible.java +++ b/src/org/traccar/model/Extensible.java @@ -1,3 +1,18 @@ +/* + * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.traccar.model; import java.util.LinkedHashMap; diff --git a/src/org/traccar/model/Geofence.java b/src/org/traccar/model/Geofence.java index 300d8fb74..9a60f784f 100644 --- a/src/org/traccar/model/Geofence.java +++ b/src/org/traccar/model/Geofence.java @@ -1,3 +1,18 @@ +/* + * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.traccar.model; import java.text.ParseException; diff --git a/src/org/traccar/model/GeofencePermission.java b/src/org/traccar/model/GeofencePermission.java index 38fe7b6c1..269918d66 100644 --- a/src/org/traccar/model/GeofencePermission.java +++ b/src/org/traccar/model/GeofencePermission.java @@ -1,3 +1,18 @@ +/* + * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.traccar.model; public class GeofencePermission { diff --git a/src/org/traccar/model/GroupGeofence.java b/src/org/traccar/model/GroupGeofence.java index a8f6bd475..0e261fd54 100644 --- a/src/org/traccar/model/GroupGeofence.java +++ b/src/org/traccar/model/GroupGeofence.java @@ -1,3 +1,18 @@ +/* + * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.traccar.model; public class GroupGeofence { diff --git a/src/org/traccar/model/Message.java b/src/org/traccar/model/Message.java index 5015b9339..55d9fd0c7 100644 --- a/src/org/traccar/model/Message.java +++ b/src/org/traccar/model/Message.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 - 2015 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2013 - 2016 Anton Tananaev (anton.tananaev@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/org/traccar/model/Position.java b/src/org/traccar/model/Position.java index b4079dae6..4e03b2097 100644 --- a/src/org/traccar/model/Position.java +++ b/src/org/traccar/model/Position.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 - 2015 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2012 - 2016 Anton Tananaev (anton.tananaev@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. -- cgit v1.2.3 From 1b8e05ce34ff7c576c29e383601f74cb8c01d728 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Thu, 16 Jun 2016 11:23:41 +0500 Subject: Moved variables from parent to inheritor --- src/org/traccar/BaseEventHandler.java | 21 --------------------- src/org/traccar/events/GeofenceEventHandler.java | 13 +++++++------ src/org/traccar/events/MotionEventHandler.java | 14 ++++++++------ src/org/traccar/events/OverspeedEventHandler.java | 11 +++++++++-- 4 files changed, 24 insertions(+), 35 deletions(-) (limited to 'src/org/traccar/BaseEventHandler.java') diff --git a/src/org/traccar/BaseEventHandler.java b/src/org/traccar/BaseEventHandler.java index 143c2dc2b..1ae9d2c6d 100644 --- a/src/org/traccar/BaseEventHandler.java +++ b/src/org/traccar/BaseEventHandler.java @@ -17,35 +17,14 @@ package org.traccar; import java.util.Collection; -import org.traccar.model.Device; import org.traccar.model.Event; import org.traccar.model.Position; public abstract class BaseEventHandler extends BaseDataHandler { - private boolean isLastPosition = false; - - public boolean isLastPosition() { - return isLastPosition; - } - - private Device device; - - public Device getDevice() { - return device; - } - @Override protected Position handlePosition(Position position) { - device = Context.getDataManager().getDeviceById(position.getDeviceId()); - if (device != null) { - long lastPositionId = device.getPositionId(); - if (position.getId() == lastPositionId) { - isLastPosition = true; - } - } - Collection events = analyzePosition(position); if (events != null) { for (Event event : events) { diff --git a/src/org/traccar/events/GeofenceEventHandler.java b/src/org/traccar/events/GeofenceEventHandler.java index 7d24c4efe..e9a4a640f 100644 --- a/src/org/traccar/events/GeofenceEventHandler.java +++ b/src/org/traccar/events/GeofenceEventHandler.java @@ -25,6 +25,7 @@ import org.traccar.Context; import org.traccar.database.DataManager; import org.traccar.database.GeofenceManager; import org.traccar.helper.Log; +import org.traccar.model.Device; import org.traccar.model.Event; import org.traccar.model.Position; @@ -42,24 +43,24 @@ public class GeofenceEventHandler extends BaseEventHandler { @Override protected Collection analyzePosition(Position position) { - if (!isLastPosition() || !position.getValid()) { + Device device = dataManager.getDeviceById(position.getDeviceId()); + if (device == null) { return null; } - - if (getDevice() == null) { + if (position.getId() != device.getPositionId() || !position.getValid()) { return null; } List currentGeofences = geofenceManager.getCurrentDeviceGeofences(position); List oldGeofences = new ArrayList(); - if (getDevice().getGeofenceIds() != null) { - oldGeofences.addAll(getDevice().getGeofenceIds()); + if (device.getGeofenceIds() != null) { + oldGeofences.addAll(device.getGeofenceIds()); } List newGeofences = new ArrayList(currentGeofences); newGeofences.removeAll(oldGeofences); oldGeofences.removeAll(currentGeofences); - getDevice().setGeofenceIds(currentGeofences); + device.setGeofenceIds(currentGeofences); Collection events = new ArrayList<>(); try { diff --git a/src/org/traccar/events/MotionEventHandler.java b/src/org/traccar/events/MotionEventHandler.java index c05bd4843..d10513d26 100644 --- a/src/org/traccar/events/MotionEventHandler.java +++ b/src/org/traccar/events/MotionEventHandler.java @@ -37,17 +37,19 @@ public class MotionEventHandler extends BaseEventHandler { @Override protected Collection analyzePosition(Position position) { - Collection result = null; - if (!isLastPosition()) { + + Device device = Context.getDataManager().getDeviceById(position.getDeviceId()); + if (device == null) { + return null; + } + if (position.getId() != device.getPositionId() || !position.getValid()) { return null; } + Collection result = null; double speed = position.getSpeed(); boolean valid = position.getValid(); - if (getDevice() == null) { - return null; - } - String motion = getDevice().getMotion(); + String motion = device.getMotion(); if (motion == null) { motion = Device.STATUS_STOPPED; } diff --git a/src/org/traccar/events/OverspeedEventHandler.java b/src/org/traccar/events/OverspeedEventHandler.java index f4676b995..e14d4bcea 100644 --- a/src/org/traccar/events/OverspeedEventHandler.java +++ b/src/org/traccar/events/OverspeedEventHandler.java @@ -21,6 +21,7 @@ import java.util.Collection; import org.traccar.BaseEventHandler; import org.traccar.Context; +import org.traccar.model.Device; import org.traccar.model.Event; import org.traccar.model.Position; import org.traccar.helper.Log; @@ -38,10 +39,16 @@ public class OverspeedEventHandler extends BaseEventHandler { @Override protected Collection analyzePosition(Position position) { - Collection events = new ArrayList<>(); - if (!isLastPosition()) { + + Device device = Context.getDataManager().getDeviceById(position.getDeviceId()); + if (device == null) { + return null; + } + if (position.getId() != device.getPositionId() || !position.getValid()) { return null; } + + Collection events = new ArrayList<>(); double speed = position.getSpeed(); boolean valid = position.getValid(); -- cgit v1.2.3