From 725d738de64bd7df7ec05786baf6590c15a105b9 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 13 Apr 2024 07:25:54 -0700 Subject: Option to block notifications for users --- src/main/java/org/traccar/database/NotificationManager.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/main/java/org/traccar/database') diff --git a/src/main/java/org/traccar/database/NotificationManager.java b/src/main/java/org/traccar/database/NotificationManager.java index 65437f0a1..60b4f246b 100644 --- a/src/main/java/org/traccar/database/NotificationManager.java +++ b/src/main/java/org/traccar/database/NotificationManager.java @@ -42,8 +42,10 @@ import jakarta.annotation.Nullable; import jakarta.inject.Inject; import jakarta.inject.Singleton; import java.util.Arrays; +import java.util.HashSet; import java.util.Map; import java.util.Map.Entry; +import java.util.Set; import java.util.stream.Collectors; @Singleton @@ -59,6 +61,7 @@ public class NotificationManager { private final boolean geocodeOnRequest; private final long timeThreshold; + private final Set blockedUsers = new HashSet<>(); @Inject public NotificationManager( @@ -71,6 +74,12 @@ public class NotificationManager { this.geocoder = geocoder; geocodeOnRequest = config.getBoolean(Keys.GEOCODER_ON_REQUEST); timeThreshold = config.getLong(Keys.NOTIFICATOR_TIME_THRESHOLD); + String blockedUsersString = config.getString(Keys.NOTIFICATION_BLOCK_USERS); + if (blockedUsersString != null) { + for (String userIdString : blockedUsersString.split(",")) { + blockedUsers.add(Long.parseLong(userIdString)); + } + } } private void updateEvent(Event event, Position position) { @@ -122,6 +131,10 @@ public class NotificationManager { notifications.forEach(notification -> { cacheManager.getNotificationUsers(notification.getId(), event.getDeviceId()).forEach(user -> { + if (blockedUsers.contains(user.getId())) { + LOGGER.info("User {} notification blocked", user.getId()); + return; + } for (String notificator : notification.getNotificatorsTypes()) { try { notificatorManager.getNotificator(notificator).send(notification, user, event, position); -- cgit v1.2.3 From ef67a4c1577b2fbabb04c4de9b08b6d778c78952 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 17 Apr 2024 07:47:01 -0700 Subject: Move some defaults to the code --- setup/default.xml | 33 ------------ src/main/java/org/traccar/MainModule.java | 4 +- src/main/java/org/traccar/config/Keys.java | 59 ++++++++++++++-------- .../org/traccar/database/StatisticsManager.java | 2 +- .../java/org/traccar/storage/DatabaseModule.java | 5 +- 5 files changed, 43 insertions(+), 60 deletions(-) (limited to 'src/main/java/org/traccar/database') diff --git a/setup/default.xml b/setup/default.xml index 7422bdf05..02c0650c3 100644 --- a/setup/default.xml +++ b/setup/default.xml @@ -10,39 +10,6 @@ --> - 8082 - ./web - ./override - false - false - true - - true - locationiq - pk.689d849289c8c63708068b2ff1f63b2d - true - true - - info - ./logs/tracker-server.log - true - - true - 86400 - - true - - ./media - - web,mail,command - - https://www.traccar.org/analytics/ - - true - - true - ./schema/changelog-master.xml - 5001 5002 5003 diff --git a/src/main/java/org/traccar/MainModule.java b/src/main/java/org/traccar/MainModule.java index d1d3d4663..89d3d2fe0 100644 --- a/src/main/java/org/traccar/MainModule.java +++ b/src/main/java/org/traccar/MainModule.java @@ -191,7 +191,7 @@ public class MainModule extends AbstractModule { @Provides public static WebServer provideWebServer(Injector injector, Config config) { - if (config.hasKey(Keys.WEB_PORT)) { + if (config.getInteger(Keys.WEB_PORT) > 0) { return new WebServer(injector, config); } return null; @@ -201,7 +201,7 @@ public class MainModule extends AbstractModule { @Provides public static Geocoder provideGeocoder(Config config, Client client, StatisticsManager statisticsManager) { if (config.getBoolean(Keys.GEOCODER_ENABLE)) { - String type = config.getString(Keys.GEOCODER_TYPE, "google"); + String type = config.getString(Keys.GEOCODER_TYPE); String url = config.getString(Keys.GEOCODER_URL); String key = config.getString(Keys.GEOCODER_KEY); String language = config.getString(Keys.GEOCODER_LANGUAGE); diff --git a/src/main/java/org/traccar/config/Keys.java b/src/main/java/org/traccar/config/Keys.java index db3c5c9ed..0d34c75dc 100644 --- a/src/main/java/org/traccar/config/Keys.java +++ b/src/main/java/org/traccar/config/Keys.java @@ -320,7 +320,8 @@ public final class Keys { */ public static final ConfigKey SERVER_STATISTICS = new StringConfigKey( "server.statistics", - List.of(KeyType.CONFIG)); + List.of(KeyType.CONFIG), + "https://www.traccar.org/analytics/"); /** * Fuel drop threshold value. When fuel level drops from one position to another for more the value, an event is @@ -397,7 +398,8 @@ public final class Keys { */ public static final ConfigKey EVENT_IGNORE_DUPLICATE_ALERTS = new BooleanConfigKey( "event.ignoreDuplicateAlerts", - List.of(KeyType.CONFIG)); + List.of(KeyType.CONFIG), + true); /** * If set to true, invalid positions will be considered for motion logic. @@ -472,7 +474,8 @@ public final class Keys { */ public static final ConfigKey DATABASE_CHANGELOG = new StringConfigKey( "database.changelog", - List.of(KeyType.CONFIG)); + List.of(KeyType.CONFIG), + "./schema/changelog-master.xml"); /** * Database connection pool size. Default value is defined by the HikariCP library. @@ -736,7 +739,8 @@ public final class Keys { */ public static final ConfigKey MEDIA_PATH = new StringConfigKey( "media.path", - List.of(KeyType.CONFIG)); + List.of(KeyType.CONFIG), + "./media"); /** * Optional parameter to specify network interface for web interface to bind to. By default server will bind to all @@ -747,12 +751,13 @@ public final class Keys { List.of(KeyType.CONFIG)); /** - * Web interface TCP port number. By default Traccar uses port 8082. To avoid specifying port in the browser you + * Web interface TCP port number. By default, Traccar uses port 8082. To avoid specifying port in the browser you * can set it to 80 (default HTTP port). */ public static final ConfigKey WEB_PORT = new IntegerConfigKey( "web.port", - List.of(KeyType.CONFIG)); + List.of(KeyType.CONFIG), + 8082); /** * Maximum API requests per second. Above this limit requests and delayed and throttled. @@ -782,14 +787,16 @@ public final class Keys { */ public static final ConfigKey WEB_PATH = new StringConfigKey( "web.path", - List.of(KeyType.CONFIG)); + List.of(KeyType.CONFIG), + "./web"); /** * Path to a folder with overrides. It can be used for branding to keep custom logos in a separate place. */ public static final ConfigKey WEB_OVERRIDE = new StringConfigKey( "web.override", - List.of(KeyType.CONFIG)); + List.of(KeyType.CONFIG), + "./override"); /** * WebSocket connection timeout in milliseconds. Default timeout is 5 minutes. @@ -1172,7 +1179,8 @@ public final class Keys { */ public static final ConfigKey NOTIFICATOR_TYPES = new StringConfigKey( "notificator.types", - List.of(KeyType.CONFIG)); + List.of(KeyType.CONFIG), + "web,mail,command"); /** * If the event time is too old, we should not send notifications. This parameter is the threshold value in @@ -1338,7 +1346,8 @@ public final class Keys { */ public static final ConfigKey FILTER_ENABLE = new BooleanConfigKey( "filter.enable", - List.of(KeyType.CONFIG)); + List.of(KeyType.CONFIG), + true); /** * Filter invalid (valid field is set to false) positions. @@ -1376,7 +1385,8 @@ public final class Keys { */ public static final ConfigKey FILTER_FUTURE = new LongConfigKey( "filter.future", - List.of(KeyType.CONFIG)); + List.of(KeyType.CONFIG), + 86400L); /** * Filter records with fix time in the past. The value is specified in seconds. Records that have fix time more @@ -1587,15 +1597,16 @@ public final class Keys { */ public static final ConfigKey GEOCODER_ENABLE = new BooleanConfigKey( "geocoder.enable", - List.of(KeyType.CONFIG)); + List.of(KeyType.CONFIG), + true); /** - * Reverse geocoder type. Check reverse geocoding documentation for more info. By default (if the value is not - * specified) server uses Google API. + * Reverse geocoder type. Check reverse geocoding documentation for more info. */ public static final ConfigKey GEOCODER_TYPE = new StringConfigKey( "geocoder.type", - List.of(KeyType.CONFIG)); + List.of(KeyType.CONFIG), + "locationiq"); /** * Geocoder server URL. Applicable only to Nominatim and Gisgraphy providers. @@ -1609,7 +1620,8 @@ public final class Keys { */ public static final ConfigKey GEOCODER_KEY = new StringConfigKey( "geocoder.key", - List.of(KeyType.CONFIG)); + List.of(KeyType.CONFIG), + "pk.689d849289c8c63708068b2ff1f63b2d"); /** * Language parameter for providers that support localization (e.g. Google and Nominatim). @@ -1637,7 +1649,8 @@ public final class Keys { */ public static final ConfigKey GEOCODER_IGNORE_POSITIONS = new BooleanConfigKey( "geocoder.ignorePositions", - List.of(KeyType.CONFIG)); + List.of(KeyType.CONFIG), + true); /** * Boolean flag to apply reverse geocoding to invalid positions. @@ -1659,7 +1672,8 @@ public final class Keys { */ public static final ConfigKey GEOCODER_ON_REQUEST = new BooleanConfigKey( "geocoder.onRequest", - List.of(KeyType.CONFIG)); + List.of(KeyType.CONFIG), + true); /** * Boolean flag to enable LBS location resolution. Some devices send cell towers information and WiFi point when GPS @@ -1860,7 +1874,8 @@ public final class Keys { */ public static final ConfigKey LOGGER_FILE = new StringConfigKey( "logger.file", - List.of(KeyType.CONFIG)); + List.of(KeyType.CONFIG), + "./logs/tracker-server.log"); /** * Logging level. Default value is 'info'. @@ -1868,7 +1883,8 @@ public final class Keys { */ public static final ConfigKey LOGGER_LEVEL = new StringConfigKey( "logger.level", - List.of(KeyType.CONFIG)); + List.of(KeyType.CONFIG), + "info"); /** * Print full exception traces. Useful for debugging. By default shortened traces are logged. @@ -1883,7 +1899,8 @@ public final class Keys { */ public static final ConfigKey LOGGER_ROTATE = new BooleanConfigKey( "logger.rotate", - List.of(KeyType.CONFIG)); + List.of(KeyType.CONFIG), + true); /** * Log file rotation interval, the default rotation interval is once a day. diff --git a/src/main/java/org/traccar/database/StatisticsManager.java b/src/main/java/org/traccar/database/StatisticsManager.java index 445e53e7c..8711289a0 100644 --- a/src/main/java/org/traccar/database/StatisticsManager.java +++ b/src/main/java/org/traccar/database/StatisticsManager.java @@ -121,7 +121,7 @@ public class StatisticsManager { } String url = config.getString(Keys.SERVER_STATISTICS); - if (url != null) { + if (url != null && !url.isEmpty()) { String time = DateUtil.formatDate(statistics.getCaptureTime()); Form form = new Form(); diff --git a/src/main/java/org/traccar/storage/DatabaseModule.java b/src/main/java/org/traccar/storage/DatabaseModule.java index 9d9e5bd5e..9898a2fca 100644 --- a/src/main/java/org/traccar/storage/DatabaseModule.java +++ b/src/main/java/org/traccar/storage/DatabaseModule.java @@ -78,7 +78,8 @@ public class DatabaseModule extends AbstractModule { DataSource dataSource = new HikariDataSource(hikariConfig); - if (config.hasKey(Keys.DATABASE_CHANGELOG)) { + String changelog = config.getString(Keys.DATABASE_CHANGELOG); + if (changelog != null && !changelog.isEmpty()) { ResourceAccessor resourceAccessor = new DirectoryResourceAccessor(new File(".")); @@ -89,8 +90,6 @@ public class DatabaseModule extends AbstractModule { config.getString(Keys.DATABASE_DRIVER), null, null, null, resourceAccessor); - String changelog = config.getString(Keys.DATABASE_CHANGELOG); - try (Liquibase liquibase = new Liquibase(changelog, resourceAccessor, database)) { liquibase.clearCheckSums(); liquibase.update(new Contexts()); -- cgit v1.2.3