Skip to content

Commit

Permalink
Move units to attributes and add volume units
Browse files Browse the repository at this point in the history
  • Loading branch information
Abyss777 committed Sep 6, 2017
1 parent 3e51671 commit fe5e6f7
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 89 deletions.
8 changes: 8 additions & 0 deletions schema/changelog-3.15.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
22 changes: 3 additions & 19 deletions src/org/traccar/database/PermissionsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
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;
Expand Down Expand Up @@ -382,25 +381,10 @@ public User login(String email, String password) throws SQLException {
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 {
Expand Down
32 changes: 0 additions & 32 deletions src/org/traccar/model/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*/
package org.traccar.model;

import java.util.TimeZone;

import org.traccar.database.QueryIgnore;
import org.traccar.helper.Log;

Expand Down Expand Up @@ -90,26 +88,6 @@ public void setMapUrl(String mapUrl) {
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() {
Expand Down Expand Up @@ -169,14 +147,4 @@ public String getCoordinateFormat() {
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;
}
}
30 changes: 0 additions & 30 deletions src/org/traccar/model/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.traccar.helper.Hashing;

import java.util.Date;
import java.util.TimeZone;

public class User extends ExtendedModel {

Expand Down Expand Up @@ -86,26 +85,6 @@ public void setMap(String map) {
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() {
Expand Down Expand Up @@ -272,13 +251,4 @@ public boolean isPasswordValid(String password) {
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;
}
}
4 changes: 3 additions & 1 deletion src/org/traccar/notification/NotificationFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ public static VelocityContext prepareContext(long userId, Event event, Position
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()));
Expand Down
11 changes: 8 additions & 3 deletions src/org/traccar/reports/ReportUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,19 @@ public static void checkPeriodLimit(Date from, Date to) {
}

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();
}

Expand Down Expand Up @@ -137,6 +141,7 @@ public static org.jxls.common.Context initializeContext(long userId) {
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());
Expand Down
Binary file modified templates/export/stops.xlsx
Binary file not shown.
Binary file modified templates/export/summary.xlsx
Binary file not shown.
Binary file modified templates/export/trips.xlsx
Binary file not shown.
4 changes: 2 additions & 2 deletions templates/mail/deviceOverspeed.vm
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions templates/sms/deviceOverspeed.vm
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit fe5e6f7

Please sign in to comment.