-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Add functionality to disable forwarding per device #5351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Where's the old pull request? Provide a link. |
See closed pull request #4778 |
What is the use case for this? It looks like you originally has "allow forwarding". That actually makes more sense, but probably need another configuration parameters for it. We should also probably do the same thing for event forwarding. |
I created this version because of your comment "That's why I'm thinking that the attribute logic should be inversed. You add it to disable forwarding." in the previous pull request. |
I know what I said, but I said it because you only had one parameter, which would break existing logic. But if we add another configuration option, it would be fine. |
What do you mean by other configuration option? |
I mean a config parameter that will enable forwarding only for marked devices. |
I will make an updated version with a config parameter |
Do you want a new pull request or an update to this one? |
Please use the same pull request. That's always the preference, so we have full conversation here. |
Just to be clear:
|
Yes, correct. |
Changes pushed. Added config and attribute options for position and event forwarding. Hope you like it. |
@@ -80,6 +84,8 @@ public NotificationManager( | |||
blockedUsers.add(Long.parseLong(userIdString)); | |||
} | |||
} | |||
|
|||
this.perDevice = config.getBoolean(Keys.EVENT_FORWARD_ENABLE_PER_DEVICE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary this
.
LOGGER.warn("Event forwarding failed", throwable); | ||
Device device = cacheManager.getObject(Device.class, event.getDeviceId()); | ||
|
||
Object allowForwarding = device.getAttributes().get(ATTRIBUTE_DEVICE_ALLOW_FORWARDING); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this an object? Use getBoolean
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed it to
boolean allowForwarding = (boolean) device.getAttributes().get(ATTRIBUTE_DEVICE_ALLOW_FORWARDING);
src/main/java/org/traccar/handler/PositionForwardingHandler.java
Outdated
Show resolved
Hide resolved
src/main/java/org/traccar/handler/PositionForwardingHandler.java
Outdated
Show resolved
Hide resolved
src/main/java/org/traccar/handler/PositionForwardingHandler.java
Outdated
Show resolved
Hide resolved
LOGGER.warn("Event forwarding failed", throwable); | ||
Device device = cacheManager.getObject(Device.class, event.getDeviceId()); | ||
|
||
boolean allowForwarding = (boolean) device.getAttributes().get(ATTRIBUTE_DEVICE_ALLOW_FORWARDING); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be a getBoolean
you can use.
new AsyncRequestAndCallback(positionData).send(); | ||
Device device = cacheManager.getObject(Device.class, position.getDeviceId()); | ||
|
||
boolean allowForwarding = (boolean) device.getAttributes().get(ATTRIBUTE_DEVICE_ALLOW_FORWARDING); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
Device device = cacheManager.getObject(Device.class, event.getDeviceId()); | ||
|
||
boolean allowForwarding = (boolean) device.getAttributes().get(ATTRIBUTE_DEVICE_ALLOW_FORWARDING); | ||
if (!enablePerDevice || (enablePerDevice && allowForwarding)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check is redundant. You can do !enablePerDevice || allowForwarding
.
Device device = cacheManager.getObject(Device.class, position.getDeviceId()); | ||
|
||
boolean allowForwarding = (boolean) device.getAttributes().get(ATTRIBUTE_DEVICE_ALLOW_FORWARDING); | ||
if (!enablePerDevice || (enablePerDevice && allowForwarding)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
} | ||
}); | ||
} else { | ||
LOGGER.debug("Forwarding events not enabled for {}", event.getDeviceId()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be unique id, not device id.
positionData.setDevice(device); | ||
new AsyncRequestAndCallback(positionData).send(); | ||
} else { | ||
LOGGER.debug("Forwarding position not enabled for {}.", position.getDeviceId()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
This is the rewrite of and old pull request