From f686847115097cf388a775fad6f13b8bf6893193 Mon Sep 17 00:00:00 2001 From: Khaksar Weqar Date: Fri, 22 Oct 2021 11:45:35 +0200 Subject: title-added --- src/main/java/org/traccar/config/Keys.java | 7 +++++++ .../traccar/notificators/NotificatorFirebase.java | 21 ++++++++++++--------- 2 files changed, 19 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/main/java/org/traccar/config/Keys.java b/src/main/java/org/traccar/config/Keys.java index 1411e8a13..f037c632f 100644 --- a/src/main/java/org/traccar/config/Keys.java +++ b/src/main/java/org/traccar/config/Keys.java @@ -744,6 +744,13 @@ public final class Keys { "notificator.firebase.key", Collections.singletonList(KeyType.GLOBAL)); + /** + * Firebase push notifications title. + */ + public static final ConfigKey NOTIFICATOR_FIREBASE_TITLE = new ConfigKey<>( + "notificator.firebase.title", + Collections.singletonList(KeyType.GLOBAL)); + /** * Pushover notification user name. */ diff --git a/src/main/java/org/traccar/notificators/NotificatorFirebase.java b/src/main/java/org/traccar/notificators/NotificatorFirebase.java index 78d5da1e2..cd084080e 100644 --- a/src/main/java/org/traccar/notificators/NotificatorFirebase.java +++ b/src/main/java/org/traccar/notificators/NotificatorFirebase.java @@ -37,6 +37,8 @@ public class NotificatorFirebase extends Notificator { private final String key; public static class Notification { + @JsonProperty("title") + private String title; @JsonProperty("body") private String body; @JsonProperty("sound") @@ -67,6 +69,7 @@ public class NotificatorFirebase extends Notificator { if (user.getAttributes().containsKey("notificationTokens")) { Notification notification = new Notification(); + notification.title=Context.getConfig().getString(Keys.NOTIFICATOR_FIREBASE_TITLE); notification.body = NotificationFormatter.formatShortMessage(userId, event, position).trim(); notification.sound = "default"; @@ -77,15 +80,15 @@ public class NotificatorFirebase extends Notificator { Context.getClient().target(url).request() .header("Authorization", "key=" + key) .async().post(Entity.json(message), new InvocationCallback() { - @Override - public void completed(Object o) { - } - - @Override - public void failed(Throwable throwable) { - LOGGER.warn("Firebase notification error", throwable); - } - }); + @Override + public void completed(Object o) { + } + + @Override + public void failed(Throwable throwable) { + LOGGER.warn("Firebase notification error", throwable); + } + }); } } -- cgit v1.2.3 From 12b26830b3eae6fac9e87c462fc09cfe6c962964 Mon Sep 17 00:00:00 2001 From: Khaksar Weqar Date: Tue, 2 Nov 2021 16:22:03 +0100 Subject: short-message-title-from-templates --- src/main/java/org/traccar/config/Keys.java | 7 ----- .../notification/NotificationFormatter.java | 2 +- .../org/traccar/notification/ShortMessage.java | 36 ++++++++++++++++++++++ .../notification/TextTemplateFormatter.java | 5 +-- .../traccar/notificators/NotificatorFirebase.java | 8 +++-- .../traccar/notificators/NotificatorPushover.java | 8 ++++- .../org/traccar/notificators/NotificatorSms.java | 7 +++-- .../traccar/notificators/NotificatorTelegram.java | 5 ++- templates/short/alarm.vm | 1 + templates/short/commandResult.vm | 1 + templates/short/deviceFuelDrop.vm | 1 + templates/short/deviceInactive.vm | 1 + templates/short/deviceMoving.vm | 1 + templates/short/deviceOffline.vm | 1 + templates/short/deviceOnline.vm | 1 + templates/short/deviceOverspeed.vm | 1 + templates/short/deviceStopped.vm | 1 + templates/short/deviceUnknown.vm | 1 + templates/short/driverChanged.vm | 1 + templates/short/geofenceEnter.vm | 1 + templates/short/geofenceExit.vm | 1 + templates/short/ignitionOff.vm | 1 + templates/short/ignitionOn.vm | 1 + templates/short/maintenance.vm | 1 + templates/short/test.vm | 1 + templates/short/textMessage.vm | 1 + templates/short/unknown.vm | 1 + 27 files changed, 81 insertions(+), 16 deletions(-) create mode 100644 src/main/java/org/traccar/notification/ShortMessage.java (limited to 'src') diff --git a/src/main/java/org/traccar/config/Keys.java b/src/main/java/org/traccar/config/Keys.java index f037c632f..1411e8a13 100644 --- a/src/main/java/org/traccar/config/Keys.java +++ b/src/main/java/org/traccar/config/Keys.java @@ -744,13 +744,6 @@ public final class Keys { "notificator.firebase.key", Collections.singletonList(KeyType.GLOBAL)); - /** - * Firebase push notifications title. - */ - public static final ConfigKey NOTIFICATOR_FIREBASE_TITLE = new ConfigKey<>( - "notificator.firebase.title", - Collections.singletonList(KeyType.GLOBAL)); - /** * Pushover notification user name. */ diff --git a/src/main/java/org/traccar/notification/NotificationFormatter.java b/src/main/java/org/traccar/notification/NotificationFormatter.java index dabc75b8b..f33961c8b 100644 --- a/src/main/java/org/traccar/notification/NotificationFormatter.java +++ b/src/main/java/org/traccar/notification/NotificationFormatter.java @@ -63,7 +63,7 @@ public final class NotificationFormatter { return TextTemplateFormatter.formatFullMessage(velocityContext, event.getType()); } - public static String formatShortMessage(long userId, Event event, Position position) { + public static ShortMessage formatShortMessage(long userId, Event event, Position position) { VelocityContext velocityContext = prepareContext(userId, event, position); return TextTemplateFormatter.formatShortMessage(velocityContext, event.getType()); } diff --git a/src/main/java/org/traccar/notification/ShortMessage.java b/src/main/java/org/traccar/notification/ShortMessage.java new file mode 100644 index 000000000..a0ee61def --- /dev/null +++ b/src/main/java/org/traccar/notification/ShortMessage.java @@ -0,0 +1,36 @@ +/* + * Copyright 2016 Anton Tananaev (anton@traccar.org) + * Copyright 2016 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.notification; + +public class ShortMessage { + + private String title; + private String body; + + public ShortMessage(String subject, String body) { + this.title = subject; + this.body = body; + } + + public String getTitle() { + return title; + } + + public String getBody() { + return body; + } +} diff --git a/src/main/java/org/traccar/notification/TextTemplateFormatter.java b/src/main/java/org/traccar/notification/TextTemplateFormatter.java index c7cac2d4d..8a4d35677 100644 --- a/src/main/java/org/traccar/notification/TextTemplateFormatter.java +++ b/src/main/java/org/traccar/notification/TextTemplateFormatter.java @@ -76,8 +76,9 @@ public final class TextTemplateFormatter { return new FullMessage((String) velocityContext.get("subject"), formattedMessage); } - public static String formatShortMessage(VelocityContext velocityContext, String name) { - return formatMessage(velocityContext, name, "short"); + public static ShortMessage formatShortMessage(VelocityContext velocityContext, String name) { + String formattedMessage = formatMessage(velocityContext, name, "short"); + return new ShortMessage((String) velocityContext.get("title"), formattedMessage); } private static String formatMessage( diff --git a/src/main/java/org/traccar/notificators/NotificatorFirebase.java b/src/main/java/org/traccar/notificators/NotificatorFirebase.java index cd084080e..9d1982f9c 100644 --- a/src/main/java/org/traccar/notificators/NotificatorFirebase.java +++ b/src/main/java/org/traccar/notificators/NotificatorFirebase.java @@ -24,7 +24,9 @@ import org.traccar.config.Keys; import org.traccar.model.Event; import org.traccar.model.Position; import org.traccar.model.User; +import org.traccar.notification.FullMessage; import org.traccar.notification.NotificationFormatter; +import org.traccar.notification.ShortMessage; import javax.ws.rs.client.Entity; import javax.ws.rs.client.InvocationCallback; @@ -68,9 +70,11 @@ public class NotificatorFirebase extends Notificator { final User user = Context.getPermissionsManager().getUser(userId); if (user.getAttributes().containsKey("notificationTokens")) { + ShortMessage shortMessage = NotificationFormatter.formatShortMessage(userId, event, position); + Notification notification = new Notification(); - notification.title=Context.getConfig().getString(Keys.NOTIFICATOR_FIREBASE_TITLE); - notification.body = NotificationFormatter.formatShortMessage(userId, event, position).trim(); + notification.title= shortMessage.getTitle(); + notification.body = shortMessage.getBody(); notification.sound = "default"; Message message = new Message(); diff --git a/src/main/java/org/traccar/notificators/NotificatorPushover.java b/src/main/java/org/traccar/notificators/NotificatorPushover.java index 189af7834..e541ea525 100644 --- a/src/main/java/org/traccar/notificators/NotificatorPushover.java +++ b/src/main/java/org/traccar/notificators/NotificatorPushover.java @@ -24,6 +24,7 @@ import org.traccar.model.Event; import org.traccar.model.Position; import org.traccar.model.User; import org.traccar.notification.NotificationFormatter; +import org.traccar.notification.ShortMessage; import javax.ws.rs.client.Entity; import javax.ws.rs.client.InvocationCallback; @@ -43,6 +44,8 @@ public class NotificatorPushover extends Notificator { private String user; @JsonProperty("device") private String device; + @JsonProperty("title") + private String title; @JsonProperty("message") private String message; } @@ -74,11 +77,14 @@ public class NotificatorPushover extends Notificator { return; } + ShortMessage shortMessage = NotificationFormatter.formatShortMessage(userId, event, position); + Message message = new Message(); message.token = token; message.user = this.user; message.device = device; - message.message = NotificationFormatter.formatShortMessage(userId, event, position); + message.title= shortMessage.getTitle(); + message.message = shortMessage.getBody(); Context.getClient().target(url).request() .async().post(Entity.json(message), new InvocationCallback() { diff --git a/src/main/java/org/traccar/notificators/NotificatorSms.java b/src/main/java/org/traccar/notificators/NotificatorSms.java index 8124e40b1..360eb44ff 100644 --- a/src/main/java/org/traccar/notificators/NotificatorSms.java +++ b/src/main/java/org/traccar/notificators/NotificatorSms.java @@ -24,6 +24,7 @@ import org.traccar.model.Position; import org.traccar.model.User; import org.traccar.notification.MessageException; import org.traccar.notification.NotificationFormatter; +import org.traccar.notification.ShortMessage; public final class NotificatorSms extends Notificator { @@ -31,9 +32,10 @@ public final class NotificatorSms extends Notificator { public void sendAsync(long userId, Event event, Position position) { final User user = Context.getPermissionsManager().getUser(userId); if (user.getPhone() != null) { + ShortMessage shortMessage = NotificationFormatter.formatShortMessage(userId, event, position); Main.getInjector().getInstance(StatisticsManager.class).registerSms(); Context.getSmsManager().sendMessageAsync(user.getPhone(), - NotificationFormatter.formatShortMessage(userId, event, position), false); + shortMessage.getBody(), false); } } @@ -41,9 +43,10 @@ public final class NotificatorSms extends Notificator { public void sendSync(long userId, Event event, Position position) throws MessageException, InterruptedException { final User user = Context.getPermissionsManager().getUser(userId); if (user.getPhone() != null) { + ShortMessage shortMessage = NotificationFormatter.formatShortMessage(userId, event, position); Main.getInjector().getInstance(StatisticsManager.class).registerSms(); Context.getSmsManager().sendMessageSync(user.getPhone(), - NotificationFormatter.formatShortMessage(userId, event, position), false); + shortMessage.getBody(), false); } } diff --git a/src/main/java/org/traccar/notificators/NotificatorTelegram.java b/src/main/java/org/traccar/notificators/NotificatorTelegram.java index dbba0d31d..a8cdacfbf 100644 --- a/src/main/java/org/traccar/notificators/NotificatorTelegram.java +++ b/src/main/java/org/traccar/notificators/NotificatorTelegram.java @@ -25,6 +25,7 @@ import org.traccar.config.Keys; import org.traccar.model.Event; import org.traccar.model.Position; import org.traccar.notification.NotificationFormatter; +import org.traccar.notification.ShortMessage; import javax.ws.rs.client.Entity; import javax.ws.rs.client.InvocationCallback; @@ -98,12 +99,14 @@ public class NotificatorTelegram extends Notificator { @Override public void sendSync(long userId, Event event, Position position) { User user = Context.getPermissionsManager().getUser(userId); + ShortMessage shortMessage = NotificationFormatter.formatShortMessage(userId, event, position); + TextMessage message = new TextMessage(); message.chatId = user.getString("telegramChatId"); if (message.chatId == null) { message.chatId = chatId; } - message.text = NotificationFormatter.formatShortMessage(userId, event, position); + message.text = shortMessage.getBody(); executeRequest(urlSendText, message); if (sendLocation && position != null) { executeRequest(urlSendLocation, createLocationMessage(message.chatId, position)); diff --git a/templates/short/alarm.vm b/templates/short/alarm.vm index ce641781b..faab92291 100644 --- a/templates/short/alarm.vm +++ b/templates/short/alarm.vm @@ -1 +1,2 @@ +#set($title = "Alarm") $device.name alarm: $position.getString("alarm") at $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone) diff --git a/templates/short/commandResult.vm b/templates/short/commandResult.vm index 27fd668be..7b3986573 100644 --- a/templates/short/commandResult.vm +++ b/templates/short/commandResult.vm @@ -1 +1,2 @@ +#set($title = "Command Result") $device.name command result received: $position.getString("result") at $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone) diff --git a/templates/short/deviceFuelDrop.vm b/templates/short/deviceFuelDrop.vm index 5eabe9cc0..2a4d2c608 100644 --- a/templates/short/deviceFuelDrop.vm +++ b/templates/short/deviceFuelDrop.vm @@ -1 +1,2 @@ +#set($title = "Fuel Drop") $device.name fuel drop at $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone) diff --git a/templates/short/deviceInactive.vm b/templates/short/deviceInactive.vm index d7431124c..f701ba408 100644 --- a/templates/short/deviceInactive.vm +++ b/templates/short/deviceInactive.vm @@ -1,3 +1,4 @@ +#set($title = "Inactive") #set($lastUpdate = $dateTool.getDate()) #set($ignore = $lastUpdate.setTime($event.getLong("lastUpdate"))) $device.name inactive from $dateTool.format("YYYY-MM-dd HH:mm:ss", $lastUpdate, $locale, $timezone) diff --git a/templates/short/deviceMoving.vm b/templates/short/deviceMoving.vm index a08becd2b..3307326d6 100644 --- a/templates/short/deviceMoving.vm +++ b/templates/short/deviceMoving.vm @@ -1 +1,2 @@ +#set($title = "Moving") $device.name moving at $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone) diff --git a/templates/short/deviceOffline.vm b/templates/short/deviceOffline.vm index 1dac43ac6..1967970b3 100644 --- a/templates/short/deviceOffline.vm +++ b/templates/short/deviceOffline.vm @@ -1 +1,2 @@ +#set($title = "Offline") $device.name offline at $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone) diff --git a/templates/short/deviceOnline.vm b/templates/short/deviceOnline.vm index 3c18097c1..65a59a8b3 100644 --- a/templates/short/deviceOnline.vm +++ b/templates/short/deviceOnline.vm @@ -1 +1,2 @@ +#set($title = "Online") $device.name online at $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone) diff --git a/templates/short/deviceOverspeed.vm b/templates/short/deviceOverspeed.vm index fe318fe08..fa4d7b189 100644 --- a/templates/short/deviceOverspeed.vm +++ b/templates/short/deviceOverspeed.vm @@ -7,4 +7,5 @@ #else #set($speedString = $numberTool.format("0.0 kn", $position.speed)) #end +#set($title = "Overspeed") $device.name exceeds the speed $speedString#{if}($geofence) in $geofence.name#{else}#{end} at $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone) diff --git a/templates/short/deviceStopped.vm b/templates/short/deviceStopped.vm index 1a63630ba..42147782b 100644 --- a/templates/short/deviceStopped.vm +++ b/templates/short/deviceStopped.vm @@ -1 +1,2 @@ +#set($title = "Stopped") $device.name stopped at $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone) diff --git a/templates/short/deviceUnknown.vm b/templates/short/deviceUnknown.vm index 37baa30a7..b0fd2c42d 100644 --- a/templates/short/deviceUnknown.vm +++ b/templates/short/deviceUnknown.vm @@ -1 +1,2 @@ +#set($title = "Status unknown") $device.name status is unknown at $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone) diff --git a/templates/short/driverChanged.vm b/templates/short/driverChanged.vm index 36ed8955e..fc9a6689e 100644 --- a/templates/short/driverChanged.vm +++ b/templates/short/driverChanged.vm @@ -3,4 +3,5 @@ #else #set($driverName = $event.getString("driverUniqueId")) #end +#set($title = "Driver changed") Driver $driverName has changed in $device.name at $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone) diff --git a/templates/short/geofenceEnter.vm b/templates/short/geofenceEnter.vm index 962eecc53..79736b096 100644 --- a/templates/short/geofenceEnter.vm +++ b/templates/short/geofenceEnter.vm @@ -1 +1,2 @@ +#set($title = "Geofence entered") $device.name has entered geofence $geofence.name at $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone) diff --git a/templates/short/geofenceExit.vm b/templates/short/geofenceExit.vm index 47999fa94..db5243600 100644 --- a/templates/short/geofenceExit.vm +++ b/templates/short/geofenceExit.vm @@ -1 +1,2 @@ +#set($title = "Geofence exited") $device.name has exited geofence $geofence.name at $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone) diff --git a/templates/short/ignitionOff.vm b/templates/short/ignitionOff.vm index 4d4b45ccc..953e8d0a5 100644 --- a/templates/short/ignitionOff.vm +++ b/templates/short/ignitionOff.vm @@ -1 +1,2 @@ +#set($title = "Ignition OFF") $device.name ignition OFF at $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone) diff --git a/templates/short/ignitionOn.vm b/templates/short/ignitionOn.vm index d8dd07966..610b8e272 100644 --- a/templates/short/ignitionOn.vm +++ b/templates/short/ignitionOn.vm @@ -1 +1,2 @@ +#set($title = "Ignition ON") $device.name ignition ON at $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone) diff --git a/templates/short/maintenance.vm b/templates/short/maintenance.vm index a931e5c20..917345599 100644 --- a/templates/short/maintenance.vm +++ b/templates/short/maintenance.vm @@ -1 +1,2 @@ +#set($title = "Maintenance") $device.name maintenance $maintenance.name is required at $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone) diff --git a/templates/short/test.vm b/templates/short/test.vm index d25f218ce..bd317d97b 100644 --- a/templates/short/test.vm +++ b/templates/short/test.vm @@ -1 +1,2 @@ +#set($title = "Test") Test message diff --git a/templates/short/textMessage.vm b/templates/short/textMessage.vm index 59fa7cbc6..456dcacd3 100644 --- a/templates/short/textMessage.vm +++ b/templates/short/textMessage.vm @@ -1 +1,2 @@ +#set($title = "Text message") Text message received from $device.name at $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone) diff --git a/templates/short/unknown.vm b/templates/short/unknown.vm index fd20b50cc..a7259f6e9 100644 --- a/templates/short/unknown.vm +++ b/templates/short/unknown.vm @@ -1 +1,2 @@ +#set($title = "Unknown") Unknown type -- cgit v1.2.3 From 64d38de4a3c8063ca8aabdc5583843e6db3c9446 Mon Sep 17 00:00:00 2001 From: Khaksar Weqar Date: Tue, 2 Nov 2021 16:46:57 +0100 Subject: argument-subject-changed-to-title --- src/main/java/org/traccar/notification/ShortMessage.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/main/java/org/traccar/notification/ShortMessage.java b/src/main/java/org/traccar/notification/ShortMessage.java index a0ee61def..28812a1f1 100644 --- a/src/main/java/org/traccar/notification/ShortMessage.java +++ b/src/main/java/org/traccar/notification/ShortMessage.java @@ -21,8 +21,8 @@ public class ShortMessage { private String title; private String body; - public ShortMessage(String subject, String body) { - this.title = subject; + public ShortMessage(String title, String body) { + this.title = title; this.body = body; } -- cgit v1.2.3 From 2c4b4cdd2e8c8c09bcbdc18dd9cbaeba5bd64ce7 Mon Sep 17 00:00:00 2001 From: Khaksar Weqar Date: Thu, 4 Nov 2021 09:56:42 +0100 Subject: formatting-reverted --- .../org/traccar/api/resource/PasswordResource.java | 6 ++-- .../java/org/traccar/notification/FullMessage.java | 36 ---------------------- .../notification/NotificationFormatter.java | 9 ++---- .../traccar/notification/NotificationMessage.java | 36 ++++++++++++++++++++++ .../org/traccar/notification/ShortMessage.java | 36 ---------------------- .../notification/TextTemplateFormatter.java | 17 ++-------- .../traccar/notificators/NotificatorFirebase.java | 7 ++--- .../org/traccar/notificators/NotificatorMail.java | 6 ++-- .../traccar/notificators/NotificatorPushover.java | 6 ++-- .../org/traccar/notificators/NotificatorSms.java | 6 ++-- .../traccar/notificators/NotificatorTelegram.java | 4 +-- templates/short/alarm.vm | 2 +- templates/short/commandResult.vm | 2 +- templates/short/deviceFuelDrop.vm | 2 +- templates/short/deviceInactive.vm | 2 +- templates/short/deviceMoving.vm | 2 +- templates/short/deviceOffline.vm | 2 +- templates/short/deviceOnline.vm | 2 +- templates/short/deviceOverspeed.vm | 2 +- templates/short/deviceStopped.vm | 2 +- templates/short/deviceUnknown.vm | 2 +- templates/short/driverChanged.vm | 2 +- templates/short/geofenceEnter.vm | 2 +- templates/short/geofenceExit.vm | 2 +- templates/short/ignitionOff.vm | 2 +- templates/short/ignitionOn.vm | 2 +- templates/short/maintenance.vm | 2 +- templates/short/test.vm | 2 +- templates/short/textMessage.vm | 2 +- templates/short/unknown.vm | 2 +- 30 files changed, 77 insertions(+), 130 deletions(-) delete mode 100644 src/main/java/org/traccar/notification/FullMessage.java create mode 100644 src/main/java/org/traccar/notification/NotificationMessage.java delete mode 100644 src/main/java/org/traccar/notification/ShortMessage.java (limited to 'src') diff --git a/src/main/java/org/traccar/api/resource/PasswordResource.java b/src/main/java/org/traccar/api/resource/PasswordResource.java index 20e8d768d..74cb7ca34 100644 --- a/src/main/java/org/traccar/api/resource/PasswordResource.java +++ b/src/main/java/org/traccar/api/resource/PasswordResource.java @@ -19,7 +19,7 @@ import org.apache.velocity.VelocityContext; import org.traccar.Context; import org.traccar.api.BaseResource; import org.traccar.model.User; -import org.traccar.notification.FullMessage; +import org.traccar.notification.NotificationMessage; import org.traccar.notification.TextTemplateFormatter; import javax.annotation.security.PermitAll; @@ -53,8 +53,8 @@ public class PasswordResource extends BaseResource { Context.getUsersManager().updateItem(user); VelocityContext velocityContext = TextTemplateFormatter.prepareContext(null); velocityContext.put("token", token); - FullMessage message = TextTemplateFormatter.formatFullMessage(velocityContext, "passwordReset"); - Context.getMailManager().sendMessage(userId, message.getSubject(), message.getBody()); + NotificationMessage fullMessage = TextTemplateFormatter.formatMessage(velocityContext, "passwordReset","full"); + Context.getMailManager().sendMessage(userId, fullMessage.getSubject(), fullMessage.getBody()); break; } } diff --git a/src/main/java/org/traccar/notification/FullMessage.java b/src/main/java/org/traccar/notification/FullMessage.java deleted file mode 100644 index f66537c6e..000000000 --- a/src/main/java/org/traccar/notification/FullMessage.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2016 Anton Tananaev (anton@traccar.org) - * Copyright 2016 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.notification; - -public class FullMessage { - - private String subject; - private String body; - - public FullMessage(String subject, String body) { - this.subject = subject; - this.body = body; - } - - public String getSubject() { - return subject; - } - - public String getBody() { - return body; - } -} diff --git a/src/main/java/org/traccar/notification/NotificationFormatter.java b/src/main/java/org/traccar/notification/NotificationFormatter.java index f33961c8b..9a6723a71 100644 --- a/src/main/java/org/traccar/notification/NotificationFormatter.java +++ b/src/main/java/org/traccar/notification/NotificationFormatter.java @@ -58,14 +58,9 @@ public final class NotificationFormatter { return velocityContext; } - public static FullMessage formatFullMessage(long userId, Event event, Position position) { + public static NotificationMessage formatMessage(long userId, Event event, Position position, String templatePath) { VelocityContext velocityContext = prepareContext(userId, event, position); - return TextTemplateFormatter.formatFullMessage(velocityContext, event.getType()); - } - - public static ShortMessage formatShortMessage(long userId, Event event, Position position) { - VelocityContext velocityContext = prepareContext(userId, event, position); - return TextTemplateFormatter.formatShortMessage(velocityContext, event.getType()); + return TextTemplateFormatter.formatMessage(velocityContext, event.getType(), templatePath); } } diff --git a/src/main/java/org/traccar/notification/NotificationMessage.java b/src/main/java/org/traccar/notification/NotificationMessage.java new file mode 100644 index 000000000..0fb8d7654 --- /dev/null +++ b/src/main/java/org/traccar/notification/NotificationMessage.java @@ -0,0 +1,36 @@ +/* + * Copyright 2016 Anton Tananaev (anton@traccar.org) + * Copyright 2016 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.notification; + +public class NotificationMessage { + + private String subject; + private String body; + + public NotificationMessage(String subject, String body) { + this.subject = subject; + this.body = body; + } + + public String getSubject() { + return subject; + } + + public String getBody() { + return body; + } +} diff --git a/src/main/java/org/traccar/notification/ShortMessage.java b/src/main/java/org/traccar/notification/ShortMessage.java deleted file mode 100644 index 28812a1f1..000000000 --- a/src/main/java/org/traccar/notification/ShortMessage.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2016 Anton Tananaev (anton@traccar.org) - * Copyright 2016 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.notification; - -public class ShortMessage { - - private String title; - private String body; - - public ShortMessage(String title, String body) { - this.title = title; - this.body = body; - } - - public String getTitle() { - return title; - } - - public String getBody() { - return body; - } -} diff --git a/src/main/java/org/traccar/notification/TextTemplateFormatter.java b/src/main/java/org/traccar/notification/TextTemplateFormatter.java index 8a4d35677..6a95628f0 100644 --- a/src/main/java/org/traccar/notification/TextTemplateFormatter.java +++ b/src/main/java/org/traccar/notification/TextTemplateFormatter.java @@ -71,22 +71,11 @@ public final class TextTemplateFormatter { return template; } - public static FullMessage formatFullMessage(VelocityContext velocityContext, String name) { - String formattedMessage = formatMessage(velocityContext, name, "full"); - return new FullMessage((String) velocityContext.get("subject"), formattedMessage); - } - - public static ShortMessage formatShortMessage(VelocityContext velocityContext, String name) { - String formattedMessage = formatMessage(velocityContext, name, "short"); - return new ShortMessage((String) velocityContext.get("title"), formattedMessage); - } - - private static String formatMessage( - VelocityContext velocityContext, String name, String templatePath) { - + public static NotificationMessage formatMessage(VelocityContext velocityContext, String name, String templatePath) { StringWriter writer = new StringWriter(); getTemplate(name, templatePath).merge(velocityContext, writer); - return writer.toString(); + String formattedMessage = writer.toString(); + return new NotificationMessage((String) velocityContext.get("subject"), formattedMessage); } } diff --git a/src/main/java/org/traccar/notificators/NotificatorFirebase.java b/src/main/java/org/traccar/notificators/NotificatorFirebase.java index 9d1982f9c..37d0cb25a 100644 --- a/src/main/java/org/traccar/notificators/NotificatorFirebase.java +++ b/src/main/java/org/traccar/notificators/NotificatorFirebase.java @@ -24,9 +24,8 @@ import org.traccar.config.Keys; import org.traccar.model.Event; import org.traccar.model.Position; import org.traccar.model.User; -import org.traccar.notification.FullMessage; +import org.traccar.notification.NotificationMessage; import org.traccar.notification.NotificationFormatter; -import org.traccar.notification.ShortMessage; import javax.ws.rs.client.Entity; import javax.ws.rs.client.InvocationCallback; @@ -70,10 +69,10 @@ public class NotificatorFirebase extends Notificator { final User user = Context.getPermissionsManager().getUser(userId); if (user.getAttributes().containsKey("notificationTokens")) { - ShortMessage shortMessage = NotificationFormatter.formatShortMessage(userId, event, position); + NotificationMessage shortMessage = NotificationFormatter.formatMessage(userId, event, position,"short"); Notification notification = new Notification(); - notification.title= shortMessage.getTitle(); + notification.title= shortMessage.getSubject(); notification.body = shortMessage.getBody(); notification.sound = "default"; diff --git a/src/main/java/org/traccar/notificators/NotificatorMail.java b/src/main/java/org/traccar/notificators/NotificatorMail.java index 6b9774c58..48e9d2311 100644 --- a/src/main/java/org/traccar/notificators/NotificatorMail.java +++ b/src/main/java/org/traccar/notificators/NotificatorMail.java @@ -19,7 +19,7 @@ package org.traccar.notificators; import org.traccar.Context; import org.traccar.model.Event; import org.traccar.model.Position; -import org.traccar.notification.FullMessage; +import org.traccar.notification.NotificationMessage; import org.traccar.notification.MessageException; import org.traccar.notification.NotificationFormatter; @@ -30,8 +30,8 @@ public final class NotificatorMail extends Notificator { @Override public void sendSync(long userId, Event event, Position position) throws MessageException { try { - FullMessage message = NotificationFormatter.formatFullMessage(userId, event, position); - Context.getMailManager().sendMessage(userId, message.getSubject(), message.getBody()); + NotificationMessage fullMessage = NotificationFormatter.formatMessage(userId, event, position,"full"); + Context.getMailManager().sendMessage(userId, fullMessage.getSubject(), fullMessage.getBody()); } catch (MessagingException e) { throw new MessageException(e); } diff --git a/src/main/java/org/traccar/notificators/NotificatorPushover.java b/src/main/java/org/traccar/notificators/NotificatorPushover.java index e541ea525..b62be7654 100644 --- a/src/main/java/org/traccar/notificators/NotificatorPushover.java +++ b/src/main/java/org/traccar/notificators/NotificatorPushover.java @@ -24,7 +24,7 @@ import org.traccar.model.Event; import org.traccar.model.Position; import org.traccar.model.User; import org.traccar.notification.NotificationFormatter; -import org.traccar.notification.ShortMessage; +import org.traccar.notification.NotificationMessage; import javax.ws.rs.client.Entity; import javax.ws.rs.client.InvocationCallback; @@ -77,13 +77,13 @@ public class NotificatorPushover extends Notificator { return; } - ShortMessage shortMessage = NotificationFormatter.formatShortMessage(userId, event, position); + NotificationMessage shortMessage = NotificationFormatter.formatMessage(userId, event, position,"short"); Message message = new Message(); message.token = token; message.user = this.user; message.device = device; - message.title= shortMessage.getTitle(); + message.title= shortMessage.getSubject(); message.message = shortMessage.getBody(); Context.getClient().target(url).request() diff --git a/src/main/java/org/traccar/notificators/NotificatorSms.java b/src/main/java/org/traccar/notificators/NotificatorSms.java index 360eb44ff..c99b555ce 100644 --- a/src/main/java/org/traccar/notificators/NotificatorSms.java +++ b/src/main/java/org/traccar/notificators/NotificatorSms.java @@ -24,7 +24,7 @@ import org.traccar.model.Position; import org.traccar.model.User; import org.traccar.notification.MessageException; import org.traccar.notification.NotificationFormatter; -import org.traccar.notification.ShortMessage; +import org.traccar.notification.NotificationMessage; public final class NotificatorSms extends Notificator { @@ -32,7 +32,7 @@ public final class NotificatorSms extends Notificator { public void sendAsync(long userId, Event event, Position position) { final User user = Context.getPermissionsManager().getUser(userId); if (user.getPhone() != null) { - ShortMessage shortMessage = NotificationFormatter.formatShortMessage(userId, event, position); + NotificationMessage shortMessage = NotificationFormatter.formatMessage(userId, event, position,"short"); Main.getInjector().getInstance(StatisticsManager.class).registerSms(); Context.getSmsManager().sendMessageAsync(user.getPhone(), shortMessage.getBody(), false); @@ -43,7 +43,7 @@ public final class NotificatorSms extends Notificator { public void sendSync(long userId, Event event, Position position) throws MessageException, InterruptedException { final User user = Context.getPermissionsManager().getUser(userId); if (user.getPhone() != null) { - ShortMessage shortMessage = NotificationFormatter.formatShortMessage(userId, event, position); + NotificationMessage shortMessage = NotificationFormatter.formatMessage(userId, event, position,"short"); Main.getInjector().getInstance(StatisticsManager.class).registerSms(); Context.getSmsManager().sendMessageSync(user.getPhone(), shortMessage.getBody(), false); diff --git a/src/main/java/org/traccar/notificators/NotificatorTelegram.java b/src/main/java/org/traccar/notificators/NotificatorTelegram.java index a8cdacfbf..62a5a14ff 100644 --- a/src/main/java/org/traccar/notificators/NotificatorTelegram.java +++ b/src/main/java/org/traccar/notificators/NotificatorTelegram.java @@ -25,7 +25,7 @@ import org.traccar.config.Keys; import org.traccar.model.Event; import org.traccar.model.Position; import org.traccar.notification.NotificationFormatter; -import org.traccar.notification.ShortMessage; +import org.traccar.notification.NotificationMessage; import javax.ws.rs.client.Entity; import javax.ws.rs.client.InvocationCallback; @@ -99,7 +99,7 @@ public class NotificatorTelegram extends Notificator { @Override public void sendSync(long userId, Event event, Position position) { User user = Context.getPermissionsManager().getUser(userId); - ShortMessage shortMessage = NotificationFormatter.formatShortMessage(userId, event, position); + NotificationMessage shortMessage = NotificationFormatter.formatMessage(userId, event, position,"short"); TextMessage message = new TextMessage(); message.chatId = user.getString("telegramChatId"); diff --git a/templates/short/alarm.vm b/templates/short/alarm.vm index faab92291..15970dab8 100644 --- a/templates/short/alarm.vm +++ b/templates/short/alarm.vm @@ -1,2 +1,2 @@ -#set($title = "Alarm") +#set($subject = "$device.name: alarm!") $device.name alarm: $position.getString("alarm") at $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone) diff --git a/templates/short/commandResult.vm b/templates/short/commandResult.vm index 7b3986573..6dc7a5dec 100644 --- a/templates/short/commandResult.vm +++ b/templates/short/commandResult.vm @@ -1,2 +1,2 @@ -#set($title = "Command Result") +#set($subject = "$device.name: command result received") $device.name command result received: $position.getString("result") at $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone) diff --git a/templates/short/deviceFuelDrop.vm b/templates/short/deviceFuelDrop.vm index 2a4d2c608..babe14351 100644 --- a/templates/short/deviceFuelDrop.vm +++ b/templates/short/deviceFuelDrop.vm @@ -1,2 +1,2 @@ -#set($title = "Fuel Drop") +#set($subject = "$device.name: fuel drop") $device.name fuel drop at $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone) diff --git a/templates/short/deviceInactive.vm b/templates/short/deviceInactive.vm index f701ba408..c293bf1b2 100644 --- a/templates/short/deviceInactive.vm +++ b/templates/short/deviceInactive.vm @@ -1,4 +1,4 @@ -#set($title = "Inactive") +#set($subject = "$device.name: inactive") #set($lastUpdate = $dateTool.getDate()) #set($ignore = $lastUpdate.setTime($event.getLong("lastUpdate"))) $device.name inactive from $dateTool.format("YYYY-MM-dd HH:mm:ss", $lastUpdate, $locale, $timezone) diff --git a/templates/short/deviceMoving.vm b/templates/short/deviceMoving.vm index 3307326d6..bf6aec340 100644 --- a/templates/short/deviceMoving.vm +++ b/templates/short/deviceMoving.vm @@ -1,2 +1,2 @@ -#set($title = "Moving") +#set($subject = "$device.name: moving") $device.name moving at $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone) diff --git a/templates/short/deviceOffline.vm b/templates/short/deviceOffline.vm index 1967970b3..e663812ab 100644 --- a/templates/short/deviceOffline.vm +++ b/templates/short/deviceOffline.vm @@ -1,2 +1,2 @@ -#set($title = "Offline") +#set($subject = "$device.name: offline") $device.name offline at $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone) diff --git a/templates/short/deviceOnline.vm b/templates/short/deviceOnline.vm index 65a59a8b3..bf3b40096 100644 --- a/templates/short/deviceOnline.vm +++ b/templates/short/deviceOnline.vm @@ -1,2 +1,2 @@ -#set($title = "Online") +#set($subject = "$device.name: online") $device.name online at $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone) diff --git a/templates/short/deviceOverspeed.vm b/templates/short/deviceOverspeed.vm index fa4d7b189..849c6ddb7 100644 --- a/templates/short/deviceOverspeed.vm +++ b/templates/short/deviceOverspeed.vm @@ -1,3 +1,4 @@ +#set($subject = "$device.name: exceeds the speed") #if($speedUnit == 'kmh') #set($speedValue = $position.speed * 1.852) #set($speedString = $numberTool.format("0.0 km/h", $speedValue)) @@ -7,5 +8,4 @@ #else #set($speedString = $numberTool.format("0.0 kn", $position.speed)) #end -#set($title = "Overspeed") $device.name exceeds the speed $speedString#{if}($geofence) in $geofence.name#{else}#{end} at $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone) diff --git a/templates/short/deviceStopped.vm b/templates/short/deviceStopped.vm index 42147782b..8fabf89f1 100644 --- a/templates/short/deviceStopped.vm +++ b/templates/short/deviceStopped.vm @@ -1,2 +1,2 @@ -#set($title = "Stopped") +#set($subject = "$device.name: stopped") $device.name stopped at $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone) diff --git a/templates/short/deviceUnknown.vm b/templates/short/deviceUnknown.vm index b0fd2c42d..b6a6e9c9f 100644 --- a/templates/short/deviceUnknown.vm +++ b/templates/short/deviceUnknown.vm @@ -1,2 +1,2 @@ -#set($title = "Status unknown") +#set($subject = "$device.name: status is unknown") $device.name status is unknown at $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone) diff --git a/templates/short/driverChanged.vm b/templates/short/driverChanged.vm index fc9a6689e..df96b00a1 100644 --- a/templates/short/driverChanged.vm +++ b/templates/short/driverChanged.vm @@ -1,7 +1,7 @@ +#set($subject = "$device.name: driver has changed") #if($driver) #set($driverName = $driver.name) #else #set($driverName = $event.getString("driverUniqueId")) #end -#set($title = "Driver changed") Driver $driverName has changed in $device.name at $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone) diff --git a/templates/short/geofenceEnter.vm b/templates/short/geofenceEnter.vm index 79736b096..8c250665e 100644 --- a/templates/short/geofenceEnter.vm +++ b/templates/short/geofenceEnter.vm @@ -1,2 +1,2 @@ -#set($title = "Geofence entered") +#set($subject = "$device.name: has entered geofence") $device.name has entered geofence $geofence.name at $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone) diff --git a/templates/short/geofenceExit.vm b/templates/short/geofenceExit.vm index db5243600..7d3ae6f6e 100644 --- a/templates/short/geofenceExit.vm +++ b/templates/short/geofenceExit.vm @@ -1,2 +1,2 @@ -#set($title = "Geofence exited") +#set($subject = "$device.name: has exited geofence") $device.name has exited geofence $geofence.name at $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone) diff --git a/templates/short/ignitionOff.vm b/templates/short/ignitionOff.vm index 953e8d0a5..db5a3f3e1 100644 --- a/templates/short/ignitionOff.vm +++ b/templates/short/ignitionOff.vm @@ -1,2 +1,2 @@ -#set($title = "Ignition OFF") +#set($subject = "$device.name: ignition OFF") $device.name ignition OFF at $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone) diff --git a/templates/short/ignitionOn.vm b/templates/short/ignitionOn.vm index 610b8e272..412ad4d84 100644 --- a/templates/short/ignitionOn.vm +++ b/templates/short/ignitionOn.vm @@ -1,2 +1,2 @@ -#set($title = "Ignition ON") +#set($subject = "$device.name: ignition ON") $device.name ignition ON at $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone) diff --git a/templates/short/maintenance.vm b/templates/short/maintenance.vm index 917345599..a58e274b8 100644 --- a/templates/short/maintenance.vm +++ b/templates/short/maintenance.vm @@ -1,2 +1,2 @@ -#set($title = "Maintenance") +#set($subject = "$device.name: maintenance is required") $device.name maintenance $maintenance.name is required at $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone) diff --git a/templates/short/test.vm b/templates/short/test.vm index bd317d97b..c9d93ce67 100644 --- a/templates/short/test.vm +++ b/templates/short/test.vm @@ -1,2 +1,2 @@ -#set($title = "Test") +#set($subject = "Test message") Test message diff --git a/templates/short/textMessage.vm b/templates/short/textMessage.vm index 456dcacd3..54c134df4 100644 --- a/templates/short/textMessage.vm +++ b/templates/short/textMessage.vm @@ -1,2 +1,2 @@ -#set($title = "Text message") +#set($subject = "$device.name: text message received") Text message received from $device.name at $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone) diff --git a/templates/short/unknown.vm b/templates/short/unknown.vm index a7259f6e9..2f9d5e3af 100644 --- a/templates/short/unknown.vm +++ b/templates/short/unknown.vm @@ -1,2 +1,2 @@ -#set($title = "Unknown") +#set($subject = "Unknown type") Unknown type -- cgit v1.2.3 From f3b8aa2e7355ca7bf7a8cf8c60e703300361cfe1 Mon Sep 17 00:00:00 2001 From: wkhaksar <31837615+wkhaksar@users.noreply.github.com> Date: Thu, 4 Nov 2021 17:31:21 +0100 Subject: Update src/main/java/org/traccar/notification/TextTemplateFormatter.java Co-authored-by: Anton Tananaev --- src/main/java/org/traccar/notification/TextTemplateFormatter.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src') diff --git a/src/main/java/org/traccar/notification/TextTemplateFormatter.java b/src/main/java/org/traccar/notification/TextTemplateFormatter.java index 6a95628f0..b7058c824 100644 --- a/src/main/java/org/traccar/notification/TextTemplateFormatter.java +++ b/src/main/java/org/traccar/notification/TextTemplateFormatter.java @@ -74,8 +74,7 @@ public final class TextTemplateFormatter { public static NotificationMessage formatMessage(VelocityContext velocityContext, String name, String templatePath) { StringWriter writer = new StringWriter(); getTemplate(name, templatePath).merge(velocityContext, writer); - String formattedMessage = writer.toString(); - return new NotificationMessage((String) velocityContext.get("subject"), formattedMessage); + return new NotificationMessage((String) velocityContext.get("subject"), writer.toString()); } } -- cgit v1.2.3 From 8465c59b8e63fa42fdf0d5966a266f3d1775bef1 Mon Sep 17 00:00:00 2001 From: wkhaksar <31837615+wkhaksar@users.noreply.github.com> Date: Thu, 4 Nov 2021 17:31:33 +0100 Subject: Update src/main/java/org/traccar/notificators/NotificatorFirebase.java Co-authored-by: Anton Tananaev --- src/main/java/org/traccar/notificators/NotificatorFirebase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/main/java/org/traccar/notificators/NotificatorFirebase.java b/src/main/java/org/traccar/notificators/NotificatorFirebase.java index 37d0cb25a..8951c8892 100644 --- a/src/main/java/org/traccar/notificators/NotificatorFirebase.java +++ b/src/main/java/org/traccar/notificators/NotificatorFirebase.java @@ -72,7 +72,7 @@ public class NotificatorFirebase extends Notificator { NotificationMessage shortMessage = NotificationFormatter.formatMessage(userId, event, position,"short"); Notification notification = new Notification(); - notification.title= shortMessage.getSubject(); + notification.title = shortMessage.getSubject(); notification.body = shortMessage.getBody(); notification.sound = "default"; -- cgit v1.2.3 From 0cb463258cf282036db6fdf3e08a50dc189a154b Mon Sep 17 00:00:00 2001 From: wkhaksar <31837615+wkhaksar@users.noreply.github.com> Date: Thu, 4 Nov 2021 17:31:41 +0100 Subject: Update src/main/java/org/traccar/notificators/NotificatorTelegram.java Co-authored-by: Anton Tananaev --- src/main/java/org/traccar/notificators/NotificatorTelegram.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/main/java/org/traccar/notificators/NotificatorTelegram.java b/src/main/java/org/traccar/notificators/NotificatorTelegram.java index 62a5a14ff..70148110c 100644 --- a/src/main/java/org/traccar/notificators/NotificatorTelegram.java +++ b/src/main/java/org/traccar/notificators/NotificatorTelegram.java @@ -99,7 +99,7 @@ public class NotificatorTelegram extends Notificator { @Override public void sendSync(long userId, Event event, Position position) { User user = Context.getPermissionsManager().getUser(userId); - NotificationMessage shortMessage = NotificationFormatter.formatMessage(userId, event, position,"short"); + NotificationMessage shortMessage = NotificationFormatter.formatMessage(userId, event, position, "short"); TextMessage message = new TextMessage(); message.chatId = user.getString("telegramChatId"); -- cgit v1.2.3 From 55f7d7ab29772267e49489993a978c4eb83f3fe4 Mon Sep 17 00:00:00 2001 From: wkhaksar <31837615+wkhaksar@users.noreply.github.com> Date: Thu, 4 Nov 2021 17:31:48 +0100 Subject: Update src/main/java/org/traccar/api/resource/PasswordResource.java Co-authored-by: Anton Tananaev --- src/main/java/org/traccar/api/resource/PasswordResource.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/main/java/org/traccar/api/resource/PasswordResource.java b/src/main/java/org/traccar/api/resource/PasswordResource.java index 74cb7ca34..79d675434 100644 --- a/src/main/java/org/traccar/api/resource/PasswordResource.java +++ b/src/main/java/org/traccar/api/resource/PasswordResource.java @@ -53,7 +53,7 @@ public class PasswordResource extends BaseResource { Context.getUsersManager().updateItem(user); VelocityContext velocityContext = TextTemplateFormatter.prepareContext(null); velocityContext.put("token", token); - NotificationMessage fullMessage = TextTemplateFormatter.formatMessage(velocityContext, "passwordReset","full"); + NotificationMessage fullMessage = TextTemplateFormatter.formatMessage(velocityContext, "passwordReset", "full"); Context.getMailManager().sendMessage(userId, fullMessage.getSubject(), fullMessage.getBody()); break; } -- cgit v1.2.3 From 7d5a18e6fd2b798873a719b361c9a7a61a236d6b Mon Sep 17 00:00:00 2001 From: wkhaksar <31837615+wkhaksar@users.noreply.github.com> Date: Thu, 4 Nov 2021 21:03:48 +0100 Subject: Update NotificatorFirebase.java formatting-reverted --- .../org/traccar/notificators/NotificatorFirebase.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/main/java/org/traccar/notificators/NotificatorFirebase.java b/src/main/java/org/traccar/notificators/NotificatorFirebase.java index 8951c8892..b452205f6 100644 --- a/src/main/java/org/traccar/notificators/NotificatorFirebase.java +++ b/src/main/java/org/traccar/notificators/NotificatorFirebase.java @@ -83,15 +83,15 @@ public class NotificatorFirebase extends Notificator { Context.getClient().target(url).request() .header("Authorization", "key=" + key) .async().post(Entity.json(message), new InvocationCallback() { - @Override - public void completed(Object o) { - } - - @Override - public void failed(Throwable throwable) { - LOGGER.warn("Firebase notification error", throwable); - } - }); + @Override + public void completed(Object o) { + } + + @Override + public void failed(Throwable throwable) { + LOGGER.warn("Firebase notification error", throwable); + } + }); } } -- cgit v1.2.3 From c370aa660d216980a0c8f52ca856b4116ff5ca23 Mon Sep 17 00:00:00 2001 From: Khaksar Weqar Date: Fri, 5 Nov 2021 09:04:44 +0100 Subject: resolved-gradle-check-errors --- src/main/java/org/traccar/api/resource/PasswordResource.java | 3 ++- src/main/java/org/traccar/notificators/NotificatorFirebase.java | 2 +- src/main/java/org/traccar/notificators/NotificatorMail.java | 2 +- src/main/java/org/traccar/notificators/NotificatorPushover.java | 4 ++-- src/main/java/org/traccar/notificators/NotificatorSms.java | 4 ++-- 5 files changed, 8 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/main/java/org/traccar/api/resource/PasswordResource.java b/src/main/java/org/traccar/api/resource/PasswordResource.java index 79d675434..1868a6191 100644 --- a/src/main/java/org/traccar/api/resource/PasswordResource.java +++ b/src/main/java/org/traccar/api/resource/PasswordResource.java @@ -53,7 +53,8 @@ public class PasswordResource extends BaseResource { Context.getUsersManager().updateItem(user); VelocityContext velocityContext = TextTemplateFormatter.prepareContext(null); velocityContext.put("token", token); - NotificationMessage fullMessage = TextTemplateFormatter.formatMessage(velocityContext, "passwordReset", "full"); + NotificationMessage fullMessage = + TextTemplateFormatter.formatMessage(velocityContext, "passwordReset", "full"); Context.getMailManager().sendMessage(userId, fullMessage.getSubject(), fullMessage.getBody()); break; } diff --git a/src/main/java/org/traccar/notificators/NotificatorFirebase.java b/src/main/java/org/traccar/notificators/NotificatorFirebase.java index b452205f6..f91ec25a0 100644 --- a/src/main/java/org/traccar/notificators/NotificatorFirebase.java +++ b/src/main/java/org/traccar/notificators/NotificatorFirebase.java @@ -69,7 +69,7 @@ public class NotificatorFirebase extends Notificator { final User user = Context.getPermissionsManager().getUser(userId); if (user.getAttributes().containsKey("notificationTokens")) { - NotificationMessage shortMessage = NotificationFormatter.formatMessage(userId, event, position,"short"); + NotificationMessage shortMessage = NotificationFormatter.formatMessage(userId, event, position, "short"); Notification notification = new Notification(); notification.title = shortMessage.getSubject(); diff --git a/src/main/java/org/traccar/notificators/NotificatorMail.java b/src/main/java/org/traccar/notificators/NotificatorMail.java index 48e9d2311..9b5637ed8 100644 --- a/src/main/java/org/traccar/notificators/NotificatorMail.java +++ b/src/main/java/org/traccar/notificators/NotificatorMail.java @@ -30,7 +30,7 @@ public final class NotificatorMail extends Notificator { @Override public void sendSync(long userId, Event event, Position position) throws MessageException { try { - NotificationMessage fullMessage = NotificationFormatter.formatMessage(userId, event, position,"full"); + NotificationMessage fullMessage = NotificationFormatter.formatMessage(userId, event, position, "full"); Context.getMailManager().sendMessage(userId, fullMessage.getSubject(), fullMessage.getBody()); } catch (MessagingException e) { throw new MessageException(e); diff --git a/src/main/java/org/traccar/notificators/NotificatorPushover.java b/src/main/java/org/traccar/notificators/NotificatorPushover.java index b62be7654..456c2fe4f 100644 --- a/src/main/java/org/traccar/notificators/NotificatorPushover.java +++ b/src/main/java/org/traccar/notificators/NotificatorPushover.java @@ -77,13 +77,13 @@ public class NotificatorPushover extends Notificator { return; } - NotificationMessage shortMessage = NotificationFormatter.formatMessage(userId, event, position,"short"); + NotificationMessage shortMessage = NotificationFormatter.formatMessage(userId, event, position, "short"); Message message = new Message(); message.token = token; message.user = this.user; message.device = device; - message.title= shortMessage.getSubject(); + message.title = shortMessage.getSubject(); message.message = shortMessage.getBody(); Context.getClient().target(url).request() diff --git a/src/main/java/org/traccar/notificators/NotificatorSms.java b/src/main/java/org/traccar/notificators/NotificatorSms.java index c99b555ce..fb817b112 100644 --- a/src/main/java/org/traccar/notificators/NotificatorSms.java +++ b/src/main/java/org/traccar/notificators/NotificatorSms.java @@ -32,7 +32,7 @@ public final class NotificatorSms extends Notificator { public void sendAsync(long userId, Event event, Position position) { final User user = Context.getPermissionsManager().getUser(userId); if (user.getPhone() != null) { - NotificationMessage shortMessage = NotificationFormatter.formatMessage(userId, event, position,"short"); + NotificationMessage shortMessage = NotificationFormatter.formatMessage(userId, event, position, "short"); Main.getInjector().getInstance(StatisticsManager.class).registerSms(); Context.getSmsManager().sendMessageAsync(user.getPhone(), shortMessage.getBody(), false); @@ -43,7 +43,7 @@ public final class NotificatorSms extends Notificator { public void sendSync(long userId, Event event, Position position) throws MessageException, InterruptedException { final User user = Context.getPermissionsManager().getUser(userId); if (user.getPhone() != null) { - NotificationMessage shortMessage = NotificationFormatter.formatMessage(userId, event, position,"short"); + NotificationMessage shortMessage = NotificationFormatter.formatMessage(userId, event, position, "short"); Main.getInjector().getInstance(StatisticsManager.class).registerSms(); Context.getSmsManager().sendMessageSync(user.getPhone(), shortMessage.getBody(), false); -- cgit v1.2.3