diff options
author | Anton Tananaev <anton@traccar.org> | 2022-07-18 18:25:49 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2022-07-18 18:25:49 -0700 |
commit | a61e08cb47b8294bf639ebdc0916ead031e92827 (patch) | |
tree | 35d06e71bec986c65ec79d245e349d2c9875a77e | |
parent | 9cccb2f86c5ecf4041772d28fbc78ddbd619885f (diff) | |
download | trackermap-server-a61e08cb47b8294bf639ebdc0916ead031e92827.tar.gz trackermap-server-a61e08cb47b8294bf639ebdc0916ead031e92827.tar.bz2 trackermap-server-a61e08cb47b8294bf639ebdc0916ead031e92827.zip |
Add media events (fix #3863)
-rw-r--r-- | src/main/java/org/traccar/BasePipelineFactory.java | 2 | ||||
-rw-r--r-- | src/main/java/org/traccar/handler/events/BaseEventHandler.java | 2 | ||||
-rw-r--r-- | src/main/java/org/traccar/handler/events/MediaEventHandler.java | 47 | ||||
-rw-r--r-- | src/main/java/org/traccar/model/Event.java | 3 | ||||
-rw-r--r-- | templates/full/media.vm | 11 | ||||
-rw-r--r-- | templates/short/media.vm | 2 |
6 files changed, 64 insertions, 3 deletions
diff --git a/src/main/java/org/traccar/BasePipelineFactory.java b/src/main/java/org/traccar/BasePipelineFactory.java index 915c3f7ea..fb48f81d1 100644 --- a/src/main/java/org/traccar/BasePipelineFactory.java +++ b/src/main/java/org/traccar/BasePipelineFactory.java @@ -49,6 +49,7 @@ import org.traccar.handler.events.FuelDropEventHandler; import org.traccar.handler.events.GeofenceEventHandler; import org.traccar.handler.events.IgnitionEventHandler; import org.traccar.handler.events.MaintenanceEventHandler; +import org.traccar.handler.events.MediaEventHandler; import org.traccar.handler.events.MotionEventHandler; import org.traccar.handler.events.OverspeedEventHandler; @@ -141,6 +142,7 @@ public abstract class BasePipelineFactory extends ChannelInitializer<Channel> { ComputedAttributesHandler.class, WebDataHandler.class, DefaultDataHandler.class, + MediaEventHandler.class, CommandResultEventHandler.class, OverspeedEventHandler.class, BehaviorEventHandler.class, diff --git a/src/main/java/org/traccar/handler/events/BaseEventHandler.java b/src/main/java/org/traccar/handler/events/BaseEventHandler.java index f7199f6dc..271aaa35d 100644 --- a/src/main/java/org/traccar/handler/events/BaseEventHandler.java +++ b/src/main/java/org/traccar/handler/events/BaseEventHandler.java @@ -36,7 +36,7 @@ public abstract class BaseEventHandler extends BaseDataHandler { @Override protected Position handlePosition(Position position) { Map<Event, Position> events = analyzePosition(position); - if (events != null) { + if (events != null && !events.isEmpty()) { notificationManager.updateEvents(events); } return position; diff --git a/src/main/java/org/traccar/handler/events/MediaEventHandler.java b/src/main/java/org/traccar/handler/events/MediaEventHandler.java new file mode 100644 index 000000000..5b9013fad --- /dev/null +++ b/src/main/java/org/traccar/handler/events/MediaEventHandler.java @@ -0,0 +1,47 @@ +/* + * Copyright 2022 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. + * 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.handler.events; + +import io.netty.channel.ChannelHandler; +import org.traccar.model.Event; +import org.traccar.model.Position; + +import javax.inject.Inject; +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +@ChannelHandler.Sharable +public class MediaEventHandler extends BaseEventHandler { + + @Inject + public MediaEventHandler() { + } + + @Override + protected Map<Event, Position> analyzePosition(Position position) { + return Stream.of(Position.KEY_IMAGE, Position.KEY_VIDEO, Position.KEY_AUDIO) + .filter(position::hasAttribute) + .map(type -> { + Event event = new Event(Event.TYPE_MEDIA, position); + event.set("media", type); + event.set("file", position.getString(type)); + return event; + }) + .collect(Collectors.toMap(event -> event, event -> position)); + } + +} diff --git a/src/main/java/org/traccar/model/Event.java b/src/main/java/org/traccar/model/Event.java index 6e3953fda..f00a0e5f1 100644 --- a/src/main/java/org/traccar/model/Event.java +++ b/src/main/java/org/traccar/model/Event.java @@ -62,10 +62,9 @@ public class Event extends Message { public static final String TYPE_IGNITION_OFF = "ignitionOff"; public static final String TYPE_MAINTENANCE = "maintenance"; - public static final String TYPE_TEXT_MESSAGE = "textMessage"; - public static final String TYPE_DRIVER_CHANGED = "driverChanged"; + public static final String TYPE_MEDIA = "media"; private Date eventTime; diff --git a/templates/full/media.vm b/templates/full/media.vm new file mode 100644 index 000000000..6651deffc --- /dev/null +++ b/templates/full/media.vm @@ -0,0 +1,11 @@ +#set($subject = "$device.name: media file received") +<!DOCTYPE html> +<html> +<body> +Device: $device.name<br> +Type: $event.getString("media")<br> +File: <a href="$webUrl/api/media/$device.uniqueId/$event.getString("file")">$event.getString("file")</a><br> +Time: $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone)<br> +Link: <a href="$webUrl?eventId=$event.id">$webUrl?eventId=$event.id</a> +</body> +</html> diff --git a/templates/short/media.vm b/templates/short/media.vm new file mode 100644 index 000000000..783636f3f --- /dev/null +++ b/templates/short/media.vm @@ -0,0 +1,2 @@ +#set($subject = "$device.name: media file received") +$device.name $event.getString("media") received: $event.getString("file") at $dateTool.format("YYYY-MM-dd HH:mm:ss", $event.eventTime, $locale, $timezone) |