aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/database
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2017-09-07 11:33:22 +0500
committerAbyss777 <abyss@fox5.ru>2017-09-07 11:33:22 +0500
commit9ebd2a934a5ca3a61863f839733bff321ba30296 (patch)
tree265352fda7b704c240018f57e53c6626f166470d /src/org/traccar/database
parentf0578c7b5f8737e019a9cf05935d2caaa940f0ca (diff)
downloadtrackermap-server-9ebd2a934a5ca3a61863f839733bff321ba30296.tar.gz
trackermap-server-9ebd2a934a5ca3a61863f839733bff321ba30296.tar.bz2
trackermap-server-9ebd2a934a5ca3a61863f839733bff321ba30296.zip
Handle correct and incorrect attribute types
Diffstat (limited to 'src/org/traccar/database')
-rw-r--r--src/org/traccar/database/DeviceManager.java45
1 files changed, 15 insertions, 30 deletions
diff --git a/src/org/traccar/database/DeviceManager.java b/src/org/traccar/database/DeviceManager.java
index a485d6dc6..9bc221aa3 100644
--- a/src/org/traccar/database/DeviceManager.java
+++ b/src/org/traccar/database/DeviceManager.java
@@ -262,59 +262,44 @@ public class DeviceManager extends BaseObjectManager<Device> implements Identity
public boolean lookupAttributeBoolean(
long deviceId, String attributeName, boolean defaultValue, boolean lookupConfig) {
- String result = lookupAttribute(deviceId, attributeName, lookupConfig);
- if (result != null) {
- return Boolean.parseBoolean(result);
- }
- return defaultValue;
+ Object result = lookupAttribute(deviceId, attributeName, lookupConfig);
+ return result != null ? Boolean.parseBoolean(result.toString()) : defaultValue;
}
public String lookupAttributeString(
long deviceId, String attributeName, String defaultValue, boolean lookupConfig) {
- String result = lookupAttribute(deviceId, attributeName, lookupConfig);
- if (result != null) {
- return result;
- }
- return defaultValue;
+ Object result = lookupAttribute(deviceId, attributeName, lookupConfig);
+ return result != null ? result.toString() : defaultValue;
}
public int lookupAttributeInteger(long deviceId, String attributeName, int defaultValue, boolean lookupConfig) {
- String result = lookupAttribute(deviceId, attributeName, lookupConfig);
- if (result != null) {
- return Integer.parseInt(result);
- }
- return defaultValue;
+ Object result = lookupAttribute(deviceId, attributeName, lookupConfig);
+ return result != null ? Integer.parseInt(result.toString()) : defaultValue;
}
public long lookupAttributeLong(
long deviceId, String attributeName, long defaultValue, boolean lookupConfig) {
- String result = lookupAttribute(deviceId, attributeName, lookupConfig);
- if (result != null) {
- return Long.parseLong(result);
- }
- return defaultValue;
+ Object result = lookupAttribute(deviceId, attributeName, lookupConfig);
+ return result != null ? Long.parseLong(result.toString()) : defaultValue;
}
public double lookupAttributeDouble(
long deviceId, String attributeName, double defaultValue, boolean lookupConfig) {
- String result = lookupAttribute(deviceId, attributeName, lookupConfig);
- if (result != null) {
- return Double.parseDouble(result);
- }
- return defaultValue;
+ Object result = lookupAttribute(deviceId, attributeName, lookupConfig);
+ return result != null ? Double.parseDouble(result.toString()) : defaultValue;
}
- private String lookupAttribute(long deviceId, String attributeName, boolean lookupConfig) {
- String result = null;
+ private Object lookupAttribute(long deviceId, String attributeName, boolean lookupConfig) {
+ Object result = null;
Device device = getById(deviceId);
if (device != null) {
- result = device.getString(attributeName);
+ result = device.getAttributes().get(attributeName);
if (result == null && lookupGroupsAttribute) {
long groupId = device.getGroupId();
while (groupId != 0) {
Group group = Context.getGroupsManager().getById(groupId);
if (group != null) {
- result = group.getString(attributeName);
+ result = group.getAttributes().get(attributeName);
if (result != null) {
break;
}
@@ -329,7 +314,7 @@ public class DeviceManager extends BaseObjectManager<Device> implements Identity
result = Context.getConfig().getString(attributeName);
} else {
Server server = Context.getPermissionsManager().getServer();
- result = server.getString(attributeName);
+ result = server.getAttributes().get(attributeName);
}
}
}