diff options
author | Iván Ávalos <avalos@disroot.org> | 2024-08-03 20:52:00 -0600 |
---|---|---|
committer | Iván Ávalos <avalos@disroot.org> | 2024-08-03 20:52:00 -0600 |
commit | 55f6d92c09a5b1d8566b53633d07be3d31010d3b (patch) | |
tree | b86bed801b0bbadb72c7e839296dae1d28b12bbb /src/main/java/org/traccar/handler/ComputedAttributesHandler.java | |
parent | c04ad7d48331253c095fc123ded1b00f6ff871d3 (diff) | |
parent | 2788174193def918a3a1a5be3bbed24c9613323f (diff) | |
download | trackermap-server-55f6d92c09a5b1d8566b53633d07be3d31010d3b.tar.gz trackermap-server-55f6d92c09a5b1d8566b53633d07be3d31010d3b.tar.bz2 trackermap-server-55f6d92c09a5b1d8566b53633d07be3d31010d3b.zip |
Merge tag 'tags/v6.3'
Diffstat (limited to 'src/main/java/org/traccar/handler/ComputedAttributesHandler.java')
-rw-r--r-- | src/main/java/org/traccar/handler/ComputedAttributesHandler.java | 64 |
1 files changed, 24 insertions, 40 deletions
diff --git a/src/main/java/org/traccar/handler/ComputedAttributesHandler.java b/src/main/java/org/traccar/handler/ComputedAttributesHandler.java index d286866a5..f4079f127 100644 --- a/src/main/java/org/traccar/handler/ComputedAttributesHandler.java +++ b/src/main/java/org/traccar/handler/ComputedAttributesHandler.java @@ -146,57 +146,41 @@ public class ComputedAttributesHandler extends BasePositionHandler { .collect(Collectors.toUnmodifiableList()); for (Attribute attribute : attributes) { if (attribute.getAttribute() != null) { - Object result = null; try { - result = computeAttribute(attribute, position); - } catch (JexlException error) { - LOGGER.warn("Attribute computation error", error); - } - if (result != null) { - try { + Object result = computeAttribute(attribute, position); + if (result != null) { switch (attribute.getAttribute()) { - case "valid": - position.setValid((Boolean) result); - break; - case "latitude": - position.setLatitude(((Number) result).doubleValue()); - break; - case "longitude": - position.setLongitude(((Number) result).doubleValue()); - break; - case "altitude": - position.setAltitude(((Number) result).doubleValue()); - break; - case "speed": - position.setSpeed(((Number) result).doubleValue()); - break; - case "course": - position.setCourse(((Number) result).doubleValue()); - break; - case "address": - position.setAddress((String) result); - break; - case "accuracy": - position.setAccuracy(((Number) result).doubleValue()); - break; - default: + case "valid" -> position.setValid((Boolean) result); + case "latitude" -> position.setLatitude(((Number) result).doubleValue()); + case "longitude" -> position.setLongitude(((Number) result).doubleValue()); + case "altitude" -> position.setAltitude(((Number) result).doubleValue()); + case "speed" -> position.setSpeed(((Number) result).doubleValue()); + case "course" -> position.setCourse(((Number) result).doubleValue()); + case "address" -> position.setAddress((String) result); + case "accuracy" -> position.setAccuracy(((Number) result).doubleValue()); + default -> { switch (attribute.getType()) { - case "number": + case "number" -> { Number numberValue = (Number) result; position.getAttributes().put(attribute.getAttribute(), numberValue); - break; - case "boolean": + } + case "boolean" -> { Boolean booleanValue = (Boolean) result; position.getAttributes().put(attribute.getAttribute(), booleanValue); - break; - default: + } + default -> { position.getAttributes().put(attribute.getAttribute(), result.toString()); + } } - break; + } } - } catch (ClassCastException error) { - LOGGER.warn("Attribute cast error", error); + } else { + position.getAttributes().remove(attribute.getAttribute()); } + } catch (JexlException error) { + LOGGER.warn("Attribute computation error", error); + } catch (ClassCastException error) { + LOGGER.warn("Attribute cast error", error); } } } |