From 34a5823cb19d4b957da1c0bdda426eb8e76950d2 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Mon, 25 Feb 2019 23:50:42 -0800 Subject: Refactor copy attributes handler --- src/org/traccar/handler/CopyAttributesHandler.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'src/org/traccar/handler') diff --git a/src/org/traccar/handler/CopyAttributesHandler.java b/src/org/traccar/handler/CopyAttributesHandler.java index 73642d81b..6a0966d33 100644 --- a/src/org/traccar/handler/CopyAttributesHandler.java +++ b/src/org/traccar/handler/CopyAttributesHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 - 2017 Anton Tananaev (anton@traccar.org) + * Copyright 2016 - 2019 Anton Tananaev (anton@traccar.org) * Copyright 2016 - 2017 Andrey Kunitsyn (andrey@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,29 +18,28 @@ package org.traccar.handler; import io.netty.channel.ChannelHandler; import org.traccar.BaseDataHandler; -import org.traccar.Context; +import org.traccar.database.IdentityManager; import org.traccar.model.Position; @ChannelHandler.Sharable public class CopyAttributesHandler extends BaseDataHandler { - private Position getLastPosition(long deviceId) { - if (Context.getIdentityManager() != null) { - return Context.getIdentityManager().getLastPosition(deviceId); - } - return null; + private IdentityManager identityManager; + + public CopyAttributesHandler(IdentityManager identityManager) { + this.identityManager = identityManager; } @Override protected Position handlePosition(Position position) { - String attributesString = Context.getDeviceManager().lookupAttributeString( + String attributesString = identityManager.lookupAttributeString( position.getDeviceId(), "processing.copyAttributes", "", true); - Position last = getLastPosition(position.getDeviceId()); if (attributesString.isEmpty()) { attributesString = Position.KEY_DRIVER_UNIQUE_ID; } else { attributesString += "," + Position.KEY_DRIVER_UNIQUE_ID; } + Position last = identityManager.getLastPosition(position.getDeviceId()); if (last != null) { for (String attribute : attributesString.split("[ ,]")) { if (last.getAttributes().containsKey(attribute) && !position.getAttributes().containsKey(attribute)) { -- cgit v1.2.3