diff options
author | Anton Tananaev <anton@traccar.org> | 2022-05-30 13:12:37 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2022-05-30 13:12:37 -0700 |
commit | ce661ec77a957b70c15509c6801e6f34b32ad11d (patch) | |
tree | 1fd501abc09e1eeceb3bf411b5d2612b27cc35ad /src/main/java/org/traccar/handler/CopyAttributesHandler.java | |
parent | 154ff3b2175e67b3fac531cb9c5c5c68880f5e12 (diff) | |
download | trackermap-server-ce661ec77a957b70c15509c6801e6f34b32ad11d.tar.gz trackermap-server-ce661ec77a957b70c15509c6801e6f34b32ad11d.tar.bz2 trackermap-server-ce661ec77a957b70c15509c6801e6f34b32ad11d.zip |
Improve dependency injection
Diffstat (limited to 'src/main/java/org/traccar/handler/CopyAttributesHandler.java')
-rw-r--r-- | src/main/java/org/traccar/handler/CopyAttributesHandler.java | 30 |
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)); + } } } } |