diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2017-09-06 21:08:31 +1200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-06 21:08:31 +1200 |
commit | f0578c7b5f8737e019a9cf05935d2caaa940f0ca (patch) | |
tree | 778b00dd1a6162007cb08239d475884843a678ba | |
parent | 3e5167131c758dd6e75e0f5d9b265a1514baac0c (diff) | |
parent | fe5e6f7e1aaa01dfe8d61af46c3b818f8c566a25 (diff) | |
download | traccar-server-f0578c7b5f8737e019a9cf05935d2caaa940f0ca.tar.gz traccar-server-f0578c7b5f8737e019a9cf05935d2caaa940f0ca.tar.bz2 traccar-server-f0578c7b5f8737e019a9cf05935d2caaa940f0ca.zip |
Merge pull request #3507 from Abyss777/units_attributes
Move units to attributes and add volume units
-rw-r--r-- | schema/changelog-3.15.xml | 8 | ||||
-rw-r--r-- | src/org/traccar/database/PermissionsManager.java | 22 | ||||
-rw-r--r-- | src/org/traccar/model/Server.java | 32 | ||||
-rw-r--r-- | src/org/traccar/model/User.java | 30 | ||||
-rw-r--r-- | src/org/traccar/notification/NotificationFormatter.java | 4 | ||||
-rw-r--r-- | src/org/traccar/reports/ReportUtils.java | 11 | ||||
-rw-r--r-- | templates/export/stops.xlsx | bin | 12855 -> 12870 bytes | |||
-rw-r--r-- | templates/export/summary.xlsx | bin | 8735 -> 12564 bytes | |||
-rw-r--r-- | templates/export/trips.xlsx | bin | 13239 -> 13154 bytes | |||
-rw-r--r-- | templates/mail/deviceOverspeed.vm | 4 | ||||
-rw-r--r-- | templates/sms/deviceOverspeed.vm | 4 |
11 files changed, 26 insertions, 89 deletions
diff --git a/schema/changelog-3.15.xml b/schema/changelog-3.15.xml index a2d944abb..37fd2e278 100644 --- a/schema/changelog-3.15.xml +++ b/schema/changelog-3.15.xml @@ -13,5 +13,13 @@ <dropTable tableName="attribute_aliases" /> + <dropColumn tableName="servers" columnName="timezone" /> + <dropColumn tableName="servers" columnName="speedunit" /> + <dropColumn tableName="servers" columnName="distanceunit" /> + + <dropColumn tableName="users" columnName="timezone" /> + <dropColumn tableName="users" columnName="speedunit" /> + <dropColumn tableName="users" columnName="distanceunit" /> + </changeSet> </databaseChangeLog> 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()); diff --git a/templates/export/stops.xlsx b/templates/export/stops.xlsx Binary files differindex d6bb4c3b9..0c00b7bff 100644 --- a/templates/export/stops.xlsx +++ b/templates/export/stops.xlsx diff --git a/templates/export/summary.xlsx b/templates/export/summary.xlsx Binary files differindex 73e702a70..a71f013a9 100644 --- a/templates/export/summary.xlsx +++ b/templates/export/summary.xlsx diff --git a/templates/export/trips.xlsx b/templates/export/trips.xlsx Binary files differindex 4a6734850..c5fa73342 100644 --- a/templates/export/trips.xlsx +++ b/templates/export/trips.xlsx diff --git a/templates/mail/deviceOverspeed.vm b/templates/mail/deviceOverspeed.vm index 0715a3d60..b1f0a6734 100644 --- a/templates/mail/deviceOverspeed.vm +++ b/templates/mail/deviceOverspeed.vm @@ -1,8 +1,8 @@ #set($subject = "$device.name: exceeds the speed") -#if($speedUnits == 'kmh') +#if($speedUnit == 'kmh') #set($speedValue = $position.speed * 1.852) #set($speedString = $numberTool.format("0.0 km/h", $speedValue)) -#elseif($speedUnits == 'mph') +#elseif($speedUnit == 'mph') #set($speedValue = $position.speed * 1.15078) #set($speedString = $numberTool.format("0.0 mph", $speedValue)) #else diff --git a/templates/sms/deviceOverspeed.vm b/templates/sms/deviceOverspeed.vm index ef0d9d955..f0b03c9e7 100644 --- a/templates/sms/deviceOverspeed.vm +++ b/templates/sms/deviceOverspeed.vm @@ -1,7 +1,7 @@ -#if($speedUnits == 'kmh') +#if($speedUnit == 'kmh') #set($speedValue = $position.speed * 1.852) #set($speedString = $numberTool.format("0.0 km/h", $speedValue)) -#elseif($speedUnits == 'mph') +#elseif($speedUnit == 'mph') #set($speedValue = $position.speed * 1.15078) #set($speedString = $numberTool.format("0.0 mph", $speedValue)) #else |