aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/traccar')
-rw-r--r--src/main/java/org/traccar/Context.java14
-rw-r--r--src/main/java/org/traccar/MainModule.java6
-rw-r--r--src/main/java/org/traccar/database/CalendarManager.java27
-rw-r--r--src/main/java/org/traccar/database/NotificationManager.java8
-rw-r--r--src/main/java/org/traccar/database/PermissionsManager.java4
-rw-r--r--src/main/java/org/traccar/handler/events/GeofenceEventHandler.java12
6 files changed, 14 insertions, 57 deletions
diff --git a/src/main/java/org/traccar/Context.java b/src/main/java/org/traccar/Context.java
index dde98f505..e5a0c640f 100644
--- a/src/main/java/org/traccar/Context.java
+++ b/src/main/java/org/traccar/Context.java
@@ -24,7 +24,6 @@ import org.traccar.broadcast.BroadcastService;
import org.traccar.config.Config;
import org.traccar.config.Keys;
import org.traccar.database.BaseObjectManager;
-import org.traccar.database.CalendarManager;
import org.traccar.database.DataManager;
import org.traccar.database.DeviceManager;
import org.traccar.database.DriversManager;
@@ -39,7 +38,6 @@ import org.traccar.geocoder.Geocoder;
import org.traccar.helper.Log;
import org.traccar.helper.SanitizerModule;
import org.traccar.model.BaseModel;
-import org.traccar.model.Calendar;
import org.traccar.model.Device;
import org.traccar.model.Driver;
import org.traccar.model.Geofence;
@@ -50,6 +48,7 @@ import org.traccar.notification.EventForwarder;
import org.traccar.notification.NotificatorManager;
import org.traccar.reports.common.TripsConfig;
import org.traccar.session.ConnectionManager;
+import org.traccar.session.cache.CacheManager;
import org.traccar.sms.HttpSmsClient;
import org.traccar.sms.SmsManager;
import org.traccar.sms.SnsSmsClient;
@@ -149,12 +148,6 @@ public final class Context {
return geofenceManager;
}
- private static CalendarManager calendarManager;
-
- public static CalendarManager getCalendarManager() {
- return calendarManager;
- }
-
private static NotificationManager notificationManager;
public static NotificationManager getNotificationManager() {
@@ -291,8 +284,7 @@ public final class Context {
private static void initEventsModule() {
geofenceManager = new GeofenceManager(dataManager);
- calendarManager = new CalendarManager(dataManager);
- notificationManager = new NotificationManager(dataManager);
+ notificationManager = new NotificationManager(dataManager, Main.getInjector().getInstance(CacheManager.class));
notificatorManager = new NotificatorManager();
Properties velocityProperties = new Properties();
velocityProperties.setProperty("file.resource.loader.path",
@@ -330,8 +322,6 @@ public final class Context {
return (BaseObjectManager<T>) groupsManager;
} else if (clazz.equals(User.class)) {
return (BaseObjectManager<T>) usersManager;
- } else if (clazz.equals(Calendar.class)) {
- return (BaseObjectManager<T>) calendarManager;
} else if (clazz.equals(Geofence.class)) {
return (BaseObjectManager<T>) geofenceManager;
} else if (clazz.equals(Driver.class)) {
diff --git a/src/main/java/org/traccar/MainModule.java b/src/main/java/org/traccar/MainModule.java
index fb70a51c6..b757b99a7 100644
--- a/src/main/java/org/traccar/MainModule.java
+++ b/src/main/java/org/traccar/MainModule.java
@@ -23,7 +23,6 @@ import io.netty.util.HashedWheelTimer;
import io.netty.util.Timer;
import org.traccar.config.Config;
import org.traccar.config.Keys;
-import org.traccar.database.CalendarManager;
import org.traccar.database.LdapProvider;
import org.traccar.session.ConnectionManager;
import org.traccar.database.DataManager;
@@ -126,11 +125,6 @@ public class MainModule extends AbstractModule {
}
@Provides
- public static CalendarManager provideCalendarManager() {
- return Context.getCalendarManager();
- }
-
- @Provides
public static SmsManager provideSmsManager() {
return Context.getSmsManager();
}
diff --git a/src/main/java/org/traccar/database/CalendarManager.java b/src/main/java/org/traccar/database/CalendarManager.java
deleted file mode 100644
index 44ced1082..000000000
--- a/src/main/java/org/traccar/database/CalendarManager.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright 2016 - 2017 Anton Tananaev (anton@traccar.org)
- * Copyright 2016 - 2017 Andrey Kunitsyn (andrey@traccar.org)
- *
- * 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 org.traccar.model.Calendar;
-
-public class CalendarManager extends SimpleObjectManager<Calendar> {
-
- public CalendarManager(DataManager dataManager) {
- super(dataManager, Calendar.class);
- }
-
-}
diff --git a/src/main/java/org/traccar/database/NotificationManager.java b/src/main/java/org/traccar/database/NotificationManager.java
index 2f912fff1..fcefb54f0 100644
--- a/src/main/java/org/traccar/database/NotificationManager.java
+++ b/src/main/java/org/traccar/database/NotificationManager.java
@@ -37,16 +37,20 @@ import org.traccar.model.Position;
import org.traccar.model.Typed;
import org.traccar.model.User;
import org.traccar.notification.MessageException;
+import org.traccar.session.cache.CacheManager;
import org.traccar.storage.StorageException;
public class NotificationManager extends ExtendedObjectManager<Notification> {
private static final Logger LOGGER = LoggerFactory.getLogger(NotificationManager.class);
+ private final CacheManager cacheManager;
+
private final boolean geocodeOnRequest;
- public NotificationManager(DataManager dataManager) {
+ public NotificationManager(DataManager dataManager, CacheManager cacheManager) {
super(dataManager, Notification.class);
+ this.cacheManager = cacheManager;
geocodeOnRequest = Context.getConfig().getBoolean(Keys.GEOCODER_ON_REQUEST);
}
@@ -56,7 +60,7 @@ public class NotificationManager extends ExtendedObjectManager<Notification> {
for (long itemId : getUserItems(userId)) {
if (getById(itemId).getAlways() || deviceNotifications.contains(itemId)) {
long calendarId = getById(itemId).getCalendarId();
- Calendar calendar = calendarId != 0 ? Context.getCalendarManager().getById(calendarId) : null;
+ Calendar calendar = calendarId != 0 ? cacheManager.getObject(Calendar.class, calendarId) : null;
if (calendar == null || calendar.checkMoment(time)) {
result.add(itemId);
}
diff --git a/src/main/java/org/traccar/database/PermissionsManager.java b/src/main/java/org/traccar/database/PermissionsManager.java
index 61b35b380..544faf697 100644
--- a/src/main/java/org/traccar/database/PermissionsManager.java
+++ b/src/main/java/org/traccar/database/PermissionsManager.java
@@ -19,7 +19,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.traccar.Context;
import org.traccar.model.BaseModel;
-import org.traccar.model.Calendar;
import org.traccar.model.Device;
import org.traccar.model.Driver;
import org.traccar.model.Geofence;
@@ -361,7 +360,6 @@ public class PermissionsManager {
if (Context.getGeofenceManager() != null) {
Context.getGeofenceManager().refreshUserItems();
}
- Context.getCalendarManager().refreshUserItems();
Context.getDriversManager().refreshUserItems();
if (Context.getNotificationManager() != null) {
Context.getNotificationManager().refreshUserItems();
@@ -387,8 +385,6 @@ public class PermissionsManager {
Context.getGeofenceManager().refreshUserItems();
} else if (permission.getPropertyClass().equals(Driver.class)) {
Context.getDriversManager().refreshUserItems();
- } else if (permission.getPropertyClass().equals(Calendar.class)) {
- Context.getCalendarManager().refreshUserItems();
} else if (permission.getPropertyClass().equals(Notification.class)
&& Context.getNotificationManager() != null) {
Context.getNotificationManager().refreshUserItems();
diff --git a/src/main/java/org/traccar/handler/events/GeofenceEventHandler.java b/src/main/java/org/traccar/handler/events/GeofenceEventHandler.java
index c7dcf3f59..17e240f68 100644
--- a/src/main/java/org/traccar/handler/events/GeofenceEventHandler.java
+++ b/src/main/java/org/traccar/handler/events/GeofenceEventHandler.java
@@ -21,7 +21,6 @@ import java.util.List;
import java.util.Map;
import io.netty.channel.ChannelHandler;
-import org.traccar.database.CalendarManager;
import org.traccar.session.ConnectionManager;
import org.traccar.database.GeofenceManager;
import org.traccar.database.IdentityManager;
@@ -29,24 +28,25 @@ import org.traccar.model.Calendar;
import org.traccar.model.Device;
import org.traccar.model.Event;
import org.traccar.model.Position;
+import org.traccar.session.cache.CacheManager;
import javax.inject.Inject;
@ChannelHandler.Sharable
public class GeofenceEventHandler extends BaseEventHandler {
+ private final CacheManager cacheManager;
private final IdentityManager identityManager;
private final GeofenceManager geofenceManager;
- private final CalendarManager calendarManager;
private final ConnectionManager connectionManager;
@Inject
public GeofenceEventHandler(
- IdentityManager identityManager, GeofenceManager geofenceManager, CalendarManager calendarManager,
+ CacheManager cacheManager, IdentityManager identityManager, GeofenceManager geofenceManager,
ConnectionManager connectionManager) {
+ this.cacheManager = cacheManager;
this.identityManager = identityManager;
this.geofenceManager = geofenceManager;
- this.calendarManager = calendarManager;
this.connectionManager = connectionManager;
}
@@ -77,7 +77,7 @@ public class GeofenceEventHandler extends BaseEventHandler {
Map<Event, Position> events = new HashMap<>();
for (long geofenceId : oldGeofences) {
long calendarId = geofenceManager.getById(geofenceId).getCalendarId();
- Calendar calendar = calendarId != 0 ? calendarManager.getById(calendarId) : null;
+ Calendar calendar = calendarId != 0 ? cacheManager.getObject(Calendar.class, calendarId) : null;
if (calendar == null || calendar.checkMoment(position.getFixTime())) {
Event event = new Event(Event.TYPE_GEOFENCE_EXIT, position);
event.setGeofenceId(geofenceId);
@@ -86,7 +86,7 @@ public class GeofenceEventHandler extends BaseEventHandler {
}
for (long geofenceId : newGeofences) {
long calendarId = geofenceManager.getById(geofenceId).getCalendarId();
- Calendar calendar = calendarId != 0 ? calendarManager.getById(calendarId) : null;
+ Calendar calendar = calendarId != 0 ? cacheManager.getObject(Calendar.class, calendarId) : null;
if (calendar == null || calendar.checkMoment(position.getFixTime())) {
Event event = new Event(Event.TYPE_GEOFENCE_ENTER, position);
event.setGeofenceId(geofenceId);