aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--schema/changelog-5.9.xml27
-rw-r--r--schema/changelog-master.xml1
-rw-r--r--src/main/java/org/traccar/api/security/PermissionsService.java12
-rw-r--r--src/main/java/org/traccar/handler/FilterHandler.java12
-rw-r--r--src/main/java/org/traccar/model/Device.java16
-rw-r--r--src/main/java/org/traccar/model/Geofence.java16
-rw-r--r--src/main/java/org/traccar/model/Notification.java14
-rw-r--r--src/main/java/org/traccar/model/Report.java16
-rw-r--r--src/main/java/org/traccar/model/Schedulable.java (renamed from src/main/java/org/traccar/model/ScheduledModel.java)16
-rw-r--r--src/main/java/org/traccar/session/cache/CacheManager.java27
10 files changed, 118 insertions, 39 deletions
diff --git a/schema/changelog-5.9.xml b/schema/changelog-5.9.xml
new file mode 100644
index 000000000..50a3d3aaa
--- /dev/null
+++ b/schema/changelog-5.9.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<databaseChangeLog
+ xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
+ http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd"
+ logicalFilePath="changelog-5.9">
+
+ <changeSet author="author" id="changelog-5.9">
+
+ <addColumn tableName="tc_devices">
+ <column name="calendarid" type="INT" />
+ </addColumn>
+
+ <addForeignKeyConstraint
+ baseTableName="tc_devices"
+ baseColumnNames="calendarid"
+ constraintName="fk_devices_calendarid"
+ referencedTableName="tc_calendars"
+ referencedColumnNames="id"
+ onDelete="SET NULL"
+ onUpdate="RESTRICT"
+ />
+
+ </changeSet>
+
+</databaseChangeLog>
diff --git a/schema/changelog-master.xml b/schema/changelog-master.xml
index dd2bcc8a7..331d5ec78 100644
--- a/schema/changelog-master.xml
+++ b/schema/changelog-master.xml
@@ -39,5 +39,6 @@
<include file="changelog-5.6.xml" relativeToChangelogFile="true" />
<include file="changelog-5.7.xml" relativeToChangelogFile="true" />
<include file="changelog-5.8.xml" relativeToChangelogFile="true" />
+ <include file="changelog-5.9.xml" relativeToChangelogFile="true" />
</databaseChangeLog>
diff --git a/src/main/java/org/traccar/api/security/PermissionsService.java b/src/main/java/org/traccar/api/security/PermissionsService.java
index 18a376601..38bf48f30 100644
--- a/src/main/java/org/traccar/api/security/PermissionsService.java
+++ b/src/main/java/org/traccar/api/security/PermissionsService.java
@@ -24,7 +24,7 @@ import org.traccar.model.Group;
import org.traccar.model.GroupedModel;
import org.traccar.model.ManagedUser;
import org.traccar.model.Notification;
-import org.traccar.model.ScheduledModel;
+import org.traccar.model.Schedulable;
import org.traccar.model.Server;
import org.traccar.model.User;
import org.traccar.model.UserRestrictions;
@@ -137,13 +137,13 @@ public class PermissionsService {
}
}
}
- if (object instanceof ScheduledModel) {
- ScheduledModel after = ((ScheduledModel) object);
+ if (object instanceof Schedulable) {
+ Schedulable after = ((Schedulable) object);
if (after.getCalendarId() > 0) {
- ScheduledModel before = null;
+ Schedulable before = null;
if (!addition) {
before = storage.getObject(after.getClass(), new Request(
- new Columns.Include("calendarId"), new Condition.Equals("id", after.getId())));
+ new Columns.Include("calendarId"), new Condition.Equals("id", object.getId())));
}
if (before == null || before.getCalendarId() != after.getCalendarId()) {
checkPermission(Calendar.class, userId, after.getCalendarId());
@@ -156,7 +156,7 @@ public class PermissionsService {
Notification before = null;
if (!addition) {
before = storage.getObject(after.getClass(), new Request(
- new Columns.Include("commandId"), new Condition.Equals("id", after.getId())));
+ new Columns.Include("commandId"), new Condition.Equals("id", object.getId())));
}
if (before == null || before.getCommandId() != after.getCommandId()) {
checkPermission(Command.class, userId, after.getCommandId());
diff --git a/src/main/java/org/traccar/handler/FilterHandler.java b/src/main/java/org/traccar/handler/FilterHandler.java
index 2623c3486..028e4cd09 100644
--- a/src/main/java/org/traccar/handler/FilterHandler.java
+++ b/src/main/java/org/traccar/handler/FilterHandler.java
@@ -25,6 +25,7 @@ import org.traccar.config.Keys;
import org.traccar.database.StatisticsManager;
import org.traccar.helper.UnitsConverter;
import org.traccar.helper.model.AttributeUtil;
+import org.traccar.model.Calendar;
import org.traccar.model.Device;
import org.traccar.model.Position;
import org.traccar.session.cache.CacheManager;
@@ -259,9 +260,16 @@ public class FilterHandler extends ChannelInboundHandlerAdapter {
}
}
+ Device device = cacheManager.getObject(Device.class, deviceId);
+ if (device.getCalendarId() > 0) {
+ Calendar calendar = cacheManager.getObject(Calendar.class, device.getCalendarId());
+ if (!calendar.checkMoment(position.getFixTime())) {
+ filterType.append("Calendar ");
+ }
+ }
+
if (filterType.length() > 0) {
- String uniqueId = cacheManager.getObject(Device.class, deviceId).getUniqueId();
- LOGGER.info("Position filtered by {}filters from device: {}", filterType, uniqueId);
+ LOGGER.info("Position filtered by {}filters from device: {}", filterType, device.getUniqueId());
return true;
}
diff --git a/src/main/java/org/traccar/model/Device.java b/src/main/java/org/traccar/model/Device.java
index b7cffac49..2c582328e 100644
--- a/src/main/java/org/traccar/model/Device.java
+++ b/src/main/java/org/traccar/model/Device.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2022 Anton Tananaev (anton@traccar.org)
+ * Copyright 2012 - 2023 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,7 +22,19 @@ import org.traccar.storage.StorageName;
import java.util.Date;
@StorageName("tc_devices")
-public class Device extends GroupedModel implements Disableable {
+public class Device extends GroupedModel implements Disableable, Schedulable {
+
+ private long calendarId;
+
+ @Override
+ public long getCalendarId() {
+ return calendarId;
+ }
+
+ @Override
+ public void setCalendarId(long calendarId) {
+ this.calendarId = calendarId;
+ }
private String name;
diff --git a/src/main/java/org/traccar/model/Geofence.java b/src/main/java/org/traccar/model/Geofence.java
index 9259028fb..ca6293651 100644
--- a/src/main/java/org/traccar/model/Geofence.java
+++ b/src/main/java/org/traccar/model/Geofence.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 - 2022 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 - 2023 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,7 +26,19 @@ import org.traccar.storage.StorageName;
import java.text.ParseException;
@StorageName("tc_geofences")
-public class Geofence extends ScheduledModel {
+public class Geofence extends ExtendedModel implements Schedulable {
+
+ private long calendarId;
+
+ @Override
+ public long getCalendarId() {
+ return calendarId;
+ }
+
+ @Override
+ public void setCalendarId(long calendarId) {
+ this.calendarId = calendarId;
+ }
private String name;
diff --git a/src/main/java/org/traccar/model/Notification.java b/src/main/java/org/traccar/model/Notification.java
index b6a6e4cf5..6dcd9c9de 100644
--- a/src/main/java/org/traccar/model/Notification.java
+++ b/src/main/java/org/traccar/model/Notification.java
@@ -24,7 +24,19 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
import org.traccar.storage.StorageName;
@StorageName("tc_notifications")
-public class Notification extends ScheduledModel {
+public class Notification extends ExtendedModel implements Schedulable {
+
+ private long calendarId;
+
+ @Override
+ public long getCalendarId() {
+ return calendarId;
+ }
+
+ @Override
+ public void setCalendarId(long calendarId) {
+ this.calendarId = calendarId;
+ }
private boolean always;
diff --git a/src/main/java/org/traccar/model/Report.java b/src/main/java/org/traccar/model/Report.java
index 1556ecc9e..2ee7ae288 100644
--- a/src/main/java/org/traccar/model/Report.java
+++ b/src/main/java/org/traccar/model/Report.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2022 Anton Tananaev (anton@traccar.org)
+ * Copyright 2022 - 2023 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,7 +18,19 @@ package org.traccar.model;
import org.traccar.storage.StorageName;
@StorageName("tc_reports")
-public class Report extends ScheduledModel {
+public class Report extends ExtendedModel implements Schedulable {
+
+ private long calendarId;
+
+ @Override
+ public long getCalendarId() {
+ return calendarId;
+ }
+
+ @Override
+ public void setCalendarId(long calendarId) {
+ this.calendarId = calendarId;
+ }
private String type;
diff --git a/src/main/java/org/traccar/model/ScheduledModel.java b/src/main/java/org/traccar/model/Schedulable.java
index 9e6a4b9a6..331e77583 100644
--- a/src/main/java/org/traccar/model/ScheduledModel.java
+++ b/src/main/java/org/traccar/model/Schedulable.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2018 - 2023 Anton Tananaev (anton@traccar.org)
* Copyright 2018 Andrey Kunitsyn (andrey@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,15 +16,7 @@
*/
package org.traccar.model;
-public class ScheduledModel extends ExtendedModel {
-
- private long calendarId;
-
- public long getCalendarId() {
- return calendarId;
- }
-
- public void setCalendarId(long calendarId) {
- this.calendarId = calendarId;
- }
+public interface Schedulable {
+ long getCalendarId();
+ void setCalendarId(long calendarId);
}
diff --git a/src/main/java/org/traccar/session/cache/CacheManager.java b/src/main/java/org/traccar/session/cache/CacheManager.java
index 9d2350012..24abd7347 100644
--- a/src/main/java/org/traccar/session/cache/CacheManager.java
+++ b/src/main/java/org/traccar/session/cache/CacheManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2022 Anton Tananaev (anton@traccar.org)
+ * Copyright 2022 - 2023 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,7 +31,7 @@ import org.traccar.model.GroupedModel;
import org.traccar.model.Maintenance;
import org.traccar.model.Notification;
import org.traccar.model.Position;
-import org.traccar.model.ScheduledModel;
+import org.traccar.model.Schedulable;
import org.traccar.model.Server;
import org.traccar.model.User;
import org.traccar.storage.Storage;
@@ -244,8 +244,8 @@ public class CacheManager implements BroadcastInterface {
if (((GroupedModel) before).getGroupId() != ((GroupedModel) object).getGroupId()) {
invalidate = true;
}
- } else if (object instanceof ScheduledModel) {
- if (((ScheduledModel) before).getCalendarId() != ((ScheduledModel) object).getCalendarId()) {
+ } else if (object instanceof Schedulable) {
+ if (((Schedulable) before).getCalendarId() != ((Schedulable) object).getCalendarId()) {
invalidate = true;
}
}
@@ -308,6 +308,12 @@ public class CacheManager implements BroadcastInterface {
new Columns.All(), new Condition.Equals("id", deviceId)));
if (device != null) {
addObject(deviceId, device);
+ if (device.getCalendarId() > 0) {
+ var calendar = storage.getObject(Calendar.class, new Request(
+ new Columns.All(), new Condition.Equals("id", device.getCalendarId())));
+ links.computeIfAbsent(Calendar.class, k -> new LinkedHashSet<>()).add(calendar.getId());
+ addObject(deviceId, calendar);
+ }
int groupDepth = 0;
long groupId = device.getGroupId();
@@ -326,13 +332,12 @@ public class CacheManager implements BroadcastInterface {
links.put(clazz, objects.stream().map(BaseModel::getId).collect(Collectors.toSet()));
for (var object : objects) {
addObject(deviceId, object);
- if (object instanceof ScheduledModel) {
- var scheduled = (ScheduledModel) object;
+ if (object instanceof Schedulable) {
+ var scheduled = (Schedulable) object;
if (scheduled.getCalendarId() > 0) {
var calendar = storage.getObject(Calendar.class, new Request(
new Columns.All(), new Condition.Equals("id", scheduled.getCalendarId())));
- links.computeIfAbsent(Notification.class, k -> new LinkedHashSet<>())
- .add(calendar.getId());
+ links.computeIfAbsent(Calendar.class, k -> new LinkedHashSet<>()).add(calendar.getId());
addObject(deviceId, calendar);
}
}
@@ -350,14 +355,12 @@ public class CacheManager implements BroadcastInterface {
.filter(Notification::getAlways)
.collect(Collectors.toList());
for (var notification : notifications) {
- links.computeIfAbsent(Notification.class, k -> new LinkedHashSet<>())
- .add(notification.getId());
+ links.computeIfAbsent(Notification.class, k -> new LinkedHashSet<>()).add(notification.getId());
addObject(deviceId, notification);
if (notification.getCalendarId() > 0) {
var calendar = storage.getObject(Calendar.class, new Request(
new Columns.All(), new Condition.Equals("id", notification.getCalendarId())));
- links.computeIfAbsent(Notification.class, k -> new LinkedHashSet<>())
- .add(calendar.getId());
+ links.computeIfAbsent(Calendar.class, k -> new LinkedHashSet<>()).add(calendar.getId());
addObject(deviceId, calendar);
}
}