aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/database/PermissionsManager.java22
-rw-r--r--src/org/traccar/model/Server.java32
-rw-r--r--src/org/traccar/model/User.java30
-rw-r--r--src/org/traccar/notification/NotificationFormatter.java4
-rw-r--r--src/org/traccar/reports/ReportUtils.java11
5 files changed, 14 insertions, 85 deletions
diff --git a/src/org/traccar/database/PermissionsManager.java b/src/org/traccar/database/PermissionsManager.java
index 3b03c1900..0708cc5c9 100644
--- a/src/org/traccar/database/PermissionsManager.java
+++ b/src/org/traccar/database/PermissionsManager.java
@@ -29,7 +29,6 @@ import org.traccar.model.Permission;
import org.traccar.model.Server;
import org.traccar.model.User;
-import java.lang.reflect.Method;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.HashSet;
@@ -382,25 +381,10 @@ public class PermissionsManager {
return null;
}
- public Object lookupPreference(long userId, String key, Object defaultValue) {
- String methodName = "get" + key.substring(0, 1).toUpperCase() + key.substring(1);
+ public Object lookupAttribute(long userId, String key, Object defaultValue) {
Object preference;
- Object serverPreference = null;
- Object userPreference = null;
- try {
- Method method = null;
- method = User.class.getMethod(methodName, (Class<?>[]) null);
- if (method != null) {
- userPreference = method.invoke(getUser(userId), (Object[]) null);
- }
- method = null;
- method = Server.class.getMethod(methodName, (Class<?>[]) null);
- if (method != null) {
- serverPreference = method.invoke(server, (Object[]) null);
- }
- } catch (ReflectiveOperationException | SecurityException | IllegalArgumentException exception) {
- return defaultValue;
- }
+ Object serverPreference = server.getAttributes().get(key);
+ Object userPreference = getUser(userId).getAttributes().get(key);
if (server.getForceSettings()) {
preference = serverPreference != null ? serverPreference : userPreference;
} else {
diff --git a/src/org/traccar/model/Server.java b/src/org/traccar/model/Server.java
index 246be0b4f..bfe881479 100644
--- a/src/org/traccar/model/Server.java
+++ b/src/org/traccar/model/Server.java
@@ -15,8 +15,6 @@
*/
package org.traccar.model;
-import java.util.TimeZone;
-
import org.traccar.database.QueryIgnore;
import org.traccar.helper.Log;
@@ -90,26 +88,6 @@ public class Server extends ExtendedModel {
this.mapUrl = mapUrl;
}
- private String distanceUnit;
-
- public String getDistanceUnit() {
- return distanceUnit;
- }
-
- public void setDistanceUnit(String distanceUnit) {
- this.distanceUnit = distanceUnit;
- }
-
- private String speedUnit;
-
- public String getSpeedUnit() {
- return speedUnit;
- }
-
- public void setSpeedUnit(String speedUnit) {
- this.speedUnit = speedUnit;
- }
-
private double latitude;
public double getLatitude() {
@@ -169,14 +147,4 @@ public class Server extends ExtendedModel {
public void setCoordinateFormat(String coordinateFormat) {
this.coordinateFormat = coordinateFormat;
}
-
- private String timezone;
-
- public void setTimezone(String timezone) {
- this.timezone = timezone != null ? TimeZone.getTimeZone(timezone).getID() : null;
- }
-
- public String getTimezone() {
- return timezone;
- }
}
diff --git a/src/org/traccar/model/User.java b/src/org/traccar/model/User.java
index 3557521ab..043c23036 100644
--- a/src/org/traccar/model/User.java
+++ b/src/org/traccar/model/User.java
@@ -22,7 +22,6 @@ import org.traccar.database.QueryIgnore;
import org.traccar.helper.Hashing;
import java.util.Date;
-import java.util.TimeZone;
public class User extends ExtendedModel {
@@ -86,26 +85,6 @@ public class User extends ExtendedModel {
this.map = map;
}
- private String distanceUnit;
-
- public String getDistanceUnit() {
- return distanceUnit;
- }
-
- public void setDistanceUnit(String distanceUnit) {
- this.distanceUnit = distanceUnit;
- }
-
- private String speedUnit;
-
- public String getSpeedUnit() {
- return speedUnit;
- }
-
- public void setSpeedUnit(String speedUnit) {
- this.speedUnit = speedUnit;
- }
-
private double latitude;
public double getLatitude() {
@@ -272,13 +251,4 @@ public class User extends ExtendedModel {
return Hashing.validatePassword(password, hashedPassword, salt);
}
- private String timezone;
-
- public void setTimezone(String timezone) {
- this.timezone = timezone != null ? TimeZone.getTimeZone(timezone).getID() : null;
- }
-
- public String getTimezone() {
- return timezone;
- }
}
diff --git a/src/org/traccar/notification/NotificationFormatter.java b/src/org/traccar/notification/NotificationFormatter.java
index 33fd2cdc7..8da819430 100644
--- a/src/org/traccar/notification/NotificationFormatter.java
+++ b/src/org/traccar/notification/NotificationFormatter.java
@@ -48,7 +48,9 @@ public final class NotificationFormatter {
velocityContext.put("event", event);
if (position != null) {
velocityContext.put("position", position);
- velocityContext.put("speedUnits", ReportUtils.getSpeedUnit(userId));
+ velocityContext.put("speedUnit", ReportUtils.getSpeedUnit(userId));
+ velocityContext.put("distanceUnit", ReportUtils.getDistanceUnit(userId));
+ velocityContext.put("volumeUnit", ReportUtils.getVolumeUnit(userId));
}
if (event.getGeofenceId() != 0) {
velocityContext.put("geofence", Context.getGeofenceManager().getById(event.getGeofenceId()));
diff --git a/src/org/traccar/reports/ReportUtils.java b/src/org/traccar/reports/ReportUtils.java
index 74cdaf9b5..5f718feac 100644
--- a/src/org/traccar/reports/ReportUtils.java
+++ b/src/org/traccar/reports/ReportUtils.java
@@ -62,15 +62,19 @@ public final class ReportUtils {
}
public static String getDistanceUnit(long userId) {
- return (String) Context.getPermissionsManager().lookupPreference(userId, "distanceUnit", "km");
+ return (String) Context.getPermissionsManager().lookupAttribute(userId, "distanceUnit", "km");
}
public static String getSpeedUnit(long userId) {
- return (String) Context.getPermissionsManager().lookupPreference(userId, "speedUnit", "kn");
+ return (String) Context.getPermissionsManager().lookupAttribute(userId, "speedUnit", "kn");
+ }
+
+ public static String getVolumeUnit(long userId) {
+ return (String) Context.getPermissionsManager().lookupAttribute(userId, "volumeUnit", "ltr");
}
public static TimeZone getTimezone(long userId) {
- String timezone = (String) Context.getPermissionsManager().lookupPreference(userId, "timezone", null);
+ String timezone = (String) Context.getPermissionsManager().lookupAttribute(userId, "timezone", null);
return timezone != null ? TimeZone.getTimeZone(timezone) : TimeZone.getDefault();
}
@@ -137,6 +141,7 @@ public final class ReportUtils {
org.jxls.common.Context jxlsContext = PoiTransformer.createInitialContext();
jxlsContext.putVar("distanceUnit", getDistanceUnit(userId));
jxlsContext.putVar("speedUnit", getSpeedUnit(userId));
+ jxlsContext.putVar("volumeUnit", getVolumeUnit(userId));
jxlsContext.putVar("webUrl", Context.getVelocityEngine().getProperty("web.url"));
jxlsContext.putVar("dateTool", new DateTool());
jxlsContext.putVar("numberTool", new NumberTool());