aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/handler/CopyAttributesHandler.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/traccar/handler/CopyAttributesHandler.java')
-rw-r--r--src/main/java/org/traccar/handler/CopyAttributesHandler.java30
1 files changed, 20 insertions, 10 deletions
diff --git a/src/main/java/org/traccar/handler/CopyAttributesHandler.java b/src/main/java/org/traccar/handler/CopyAttributesHandler.java
index f386116b0..8285dcc5d 100644
--- a/src/main/java/org/traccar/handler/CopyAttributesHandler.java
+++ b/src/main/java/org/traccar/handler/CopyAttributesHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 - 2019 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 - 2022 Anton Tananaev (anton@traccar.org)
* Copyright 2016 - 2017 Andrey Kunitsyn (andrey@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,27 +18,37 @@ package org.traccar.handler;
import io.netty.channel.ChannelHandler;
import org.traccar.BaseDataHandler;
+import org.traccar.config.Config;
+import org.traccar.config.Keys;
import org.traccar.database.IdentityManager;
import org.traccar.model.Position;
+import javax.inject.Inject;
+
@ChannelHandler.Sharable
public class CopyAttributesHandler extends BaseDataHandler {
- private IdentityManager identityManager;
+ private final boolean enabled;
+ private final IdentityManager identityManager;
- public CopyAttributesHandler(IdentityManager identityManager) {
+ @Inject
+ public CopyAttributesHandler(Config config, IdentityManager identityManager) {
+ enabled = config.getBoolean(Keys.PROCESSING_COPY_ATTRIBUTES_ENABLE);
this.identityManager = identityManager;
}
@Override
protected Position handlePosition(Position position) {
- String attributesString = identityManager.lookupAttributeString(
- position.getDeviceId(), "processing.copyAttributes", "", false, true);
- Position last = identityManager.getLastPosition(position.getDeviceId());
- if (last != null) {
- for (String attribute : attributesString.split("[ ,]")) {
- if (last.getAttributes().containsKey(attribute) && !position.getAttributes().containsKey(attribute)) {
- position.getAttributes().put(attribute, last.getAttributes().get(attribute));
+ if (enabled) {
+ String attributesString = identityManager.lookupAttributeString(
+ position.getDeviceId(), "processing.copyAttributes", "", false, true);
+ Position last = identityManager.getLastPosition(position.getDeviceId());
+ if (last != null) {
+ for (String attribute : attributesString.split("[ ,]")) {
+ if (last.getAttributes().containsKey(attribute)
+ && !position.getAttributes().containsKey(attribute)) {
+ position.getAttributes().put(attribute, last.getAttributes().get(attribute));
+ }
}
}
}