aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2016-12-04 17:33:17 +0700
committerAbyss777 <abyss@fox5.ru>2016-12-04 17:33:17 +0700
commit6bfda86daaef7ce7b591f2fe1b33ab3b1d5ca2cd (patch)
tree1c11f3a9233a2a35ef921f6ab408984202da74b9
parentc9232000e595b0addd4bf7bbaf7a90e088c94624 (diff)
downloadtrackermap-server-6bfda86daaef7ce7b591f2fe1b33ab3b1d5ca2cd.tar.gz
trackermap-server-6bfda86daaef7ce7b591f2fe1b33ab3b1d5ca2cd.tar.bz2
trackermap-server-6bfda86daaef7ce7b591f2fe1b33ab3b1d5ca2cd.zip
Use model instead of attributes to store Notification options
-rw-r--r--schema/changelog-3.9.xml37
-rw-r--r--schema/changelog-master.xml1
-rw-r--r--setup/default.xml6
-rw-r--r--src/org/traccar/api/resource/NotificationResource.java2
-rw-r--r--src/org/traccar/database/NotificationManager.java27
-rw-r--r--src/org/traccar/model/Notification.java21
6 files changed, 86 insertions, 8 deletions
diff --git a/schema/changelog-3.9.xml b/schema/changelog-3.9.xml
new file mode 100644
index 000000000..93fa6123b
--- /dev/null
+++ b/schema/changelog-3.9.xml
@@ -0,0 +1,37 @@
+<?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-3.9">
+
+ <changeSet author="author" id="changelog-3.9">
+
+ <addColumn tableName="notifications">
+ <column name="web" type="BOOLEAN" defaultValueBoolean="false" />
+ <column name="mail" type="BOOLEAN" defaultValueBoolean="false" />
+ </addColumn>
+
+ <update tableName="notifications">
+ <column name="web" valueBoolean="true" />
+ <where>attributes = '{"web":"true"}'</where>
+ </update>
+
+ <update tableName="notifications">
+ <column name="mail" valueBoolean="true" />
+ <where>attributes = '{"mail":"true"}'</where>
+ </update>
+
+ <update tableName="notifications">
+ <column name="web" valueBoolean="true" />
+ <column name="mail" valueBoolean="true" />
+ <where>attributes = '{"web":"true","mail":"true"}'</where>
+ </update>
+
+ <update tableName="notifications">
+ <column name="attributes" value="{}" />
+ </update>
+
+ </changeSet>
+</databaseChangeLog>
diff --git a/schema/changelog-master.xml b/schema/changelog-master.xml
index 341714ca8..448015568 100644
--- a/schema/changelog-master.xml
+++ b/schema/changelog-master.xml
@@ -10,4 +10,5 @@
<include file="changelog-3.6.xml" relativeToChangelogFile="true" />
<include file="changelog-3.7.xml" relativeToChangelogFile="true" />
<include file="changelog-3.8.xml" relativeToChangelogFile="true" />
+ <include file="changelog-3.9.xml" relativeToChangelogFile="true" />
</databaseChangeLog>
diff --git a/setup/default.xml b/setup/default.xml
index 5c6f8fe90..ad23d7bd3 100644
--- a/setup/default.xml
+++ b/setup/default.xml
@@ -264,14 +264,16 @@
</entry>
<entry key='database.insertNotification'>
- INSERT INTO notifications (userId, type, attributes)
- VALUES (:userId, :type, :attributes)
+ INSERT INTO notifications (userId, type, web, mail, attributes)
+ VALUES (:userId, :type, :web, :mail, :attributes)
</entry>
<entry key='database.updateNotification'>
UPDATE notifications SET
userId = :userId,
type = :type,
+ web = :web,
+ mail = :mail,
attributes = :attributes
WHERE id = :id
</entry>
diff --git a/src/org/traccar/api/resource/NotificationResource.java b/src/org/traccar/api/resource/NotificationResource.java
index 6c9725f37..03f7e4ba0 100644
--- a/src/org/traccar/api/resource/NotificationResource.java
+++ b/src/org/traccar/api/resource/NotificationResource.java
@@ -49,7 +49,7 @@ public class NotificationResource extends BaseResource {
userId = getUserId();
}
Context.getPermissionsManager().checkUser(getUserId(), userId);
- return Context.getNotificationManager().getUserNotifications(userId);
+ return Context.getNotificationManager().getAllUserNotifications(userId);
}
@POST
diff --git a/src/org/traccar/database/NotificationManager.java b/src/org/traccar/database/NotificationManager.java
index 7e79e289f..caf1091cc 100644
--- a/src/org/traccar/database/NotificationManager.java
+++ b/src/org/traccar/database/NotificationManager.java
@@ -59,10 +59,10 @@ public class NotificationManager {
&& Context.getGeofenceManager().checkGeofence(userId, event.getGeofenceId())) {
Notification notification = getUserNotificationByType(userId, event.getType());
if (notification != null) {
- if (notification.getAttributes().containsKey("web")) {
+ if (notification.getWeb()) {
Context.getConnectionManager().updateEvent(userId, event, position);
}
- if (notification.getAttributes().containsKey("mail")) {
+ if (notification.getMail()) {
NotificationMail.sendMailAsync(userId, event, position);
}
}
@@ -130,8 +130,11 @@ public class NotificationManager {
public void updateNotification(Notification notification) {
Notification cachedNotification = getUserNotificationByType(notification.getUserId(), notification.getType());
if (cachedNotification != null) {
- if (!cachedNotification.getAttributes().equals(notification.getAttributes())) {
- if (notification.getAttributes().isEmpty()) {
+ if (cachedNotification.getWeb() != notification.getWeb()
+ || cachedNotification.getMail() != notification.getMail()
+ || !cachedNotification.getAttributes().equals(notification.getAttributes())) {
+ if (!notification.getWeb() && !notification.getMail()
+ && notification.getAttributes().isEmpty()) {
try {
dataManager.removeNotification(cachedNotification);
} catch (SQLException error) {
@@ -146,6 +149,8 @@ public class NotificationManager {
} else {
notificationsLock.writeLock().lock();
try {
+ cachedNotification.setWeb(notification.getWeb());
+ cachedNotification.setMail(notification.getMail());
cachedNotification.setAttributes(notification.getAttributes());
} finally {
notificationsLock.writeLock().unlock();
@@ -159,7 +164,7 @@ public class NotificationManager {
} else {
notification.setId(cachedNotification.getId());
}
- } else if (!notification.getAttributes().isEmpty()) {
+ } else if (notification.getWeb() || notification.getMail() || !notification.getAttributes().isEmpty()) {
try {
dataManager.addNotification(notification);
} catch (SQLException error) {
@@ -193,4 +198,16 @@ public class NotificationManager {
return notifications;
}
+ public Collection<Notification> getAllUserNotifications(long userId) {
+ Map<String, Notification> notifications = new HashMap<>();
+ for (Notification notification : getAllNotifications()) {
+ notification.setUserId(userId);
+ notifications.put(notification.getType(), notification);
+ }
+ for (Notification notification : getUserNotifications(userId)) {
+ notifications.put(notification.getType(), notification);
+ }
+ return notifications.values();
+ }
+
}
diff --git a/src/org/traccar/model/Notification.java b/src/org/traccar/model/Notification.java
index 64e1ac60c..3f08c0a39 100644
--- a/src/org/traccar/model/Notification.java
+++ b/src/org/traccar/model/Notification.java
@@ -37,4 +37,25 @@ public class Notification extends Extensible {
this.type = type;
}
+ private boolean web;
+
+ public boolean getWeb() {
+ return web;
+ }
+
+ public void setWeb(boolean web) {
+ this.web = web;
+ }
+
+ private boolean mail;
+
+ public boolean getMail() {
+ return mail;
+ }
+
+ public void setMail(boolean mail) {
+ this.mail = mail;
+ }
+
+
}