Skip to content

Commit fe5e6f7

Browse files
committed
Move units to attributes and add volume units
1 parent 3e51671 commit fe5e6f7

File tree

11 files changed

+26
-89
lines changed

11 files changed

+26
-89
lines changed

schema/changelog-3.15.xml

+8
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,13 @@
1313

1414
<dropTable tableName="attribute_aliases" />
1515

16+
<dropColumn tableName="servers" columnName="timezone" />
17+
<dropColumn tableName="servers" columnName="speedunit" />
18+
<dropColumn tableName="servers" columnName="distanceunit" />
19+
20+
<dropColumn tableName="users" columnName="timezone" />
21+
<dropColumn tableName="users" columnName="speedunit" />
22+
<dropColumn tableName="users" columnName="distanceunit" />
23+
1624
</changeSet>
1725
</databaseChangeLog>

src/org/traccar/database/PermissionsManager.java

+3-19
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import org.traccar.model.Server;
3030
import org.traccar.model.User;
3131

32-
import java.lang.reflect.Method;
3332
import java.sql.SQLException;
3433
import java.util.HashMap;
3534
import java.util.HashSet;
@@ -382,25 +381,10 @@ public User login(String email, String password) throws SQLException {
382381
return null;
383382
}
384383

385-
public Object lookupPreference(long userId, String key, Object defaultValue) {
386-
String methodName = "get" + key.substring(0, 1).toUpperCase() + key.substring(1);
384+
public Object lookupAttribute(long userId, String key, Object defaultValue) {
387385
Object preference;
388-
Object serverPreference = null;
389-
Object userPreference = null;
390-
try {
391-
Method method = null;
392-
method = User.class.getMethod(methodName, (Class<?>[]) null);
393-
if (method != null) {
394-
userPreference = method.invoke(getUser(userId), (Object[]) null);
395-
}
396-
method = null;
397-
method = Server.class.getMethod(methodName, (Class<?>[]) null);
398-
if (method != null) {
399-
serverPreference = method.invoke(server, (Object[]) null);
400-
}
401-
} catch (ReflectiveOperationException | SecurityException | IllegalArgumentException exception) {
402-
return defaultValue;
403-
}
386+
Object serverPreference = server.getAttributes().get(key);
387+
Object userPreference = getUser(userId).getAttributes().get(key);
404388
if (server.getForceSettings()) {
405389
preference = serverPreference != null ? serverPreference : userPreference;
406390
} else {

src/org/traccar/model/Server.java

-32
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
*/
1616
package org.traccar.model;
1717

18-
import java.util.TimeZone;
19-
2018
import org.traccar.database.QueryIgnore;
2119
import org.traccar.helper.Log;
2220

@@ -90,26 +88,6 @@ public void setMapUrl(String mapUrl) {
9088
this.mapUrl = mapUrl;
9189
}
9290

93-
private String distanceUnit;
94-
95-
public String getDistanceUnit() {
96-
return distanceUnit;
97-
}
98-
99-
public void setDistanceUnit(String distanceUnit) {
100-
this.distanceUnit = distanceUnit;
101-
}
102-
103-
private String speedUnit;
104-
105-
public String getSpeedUnit() {
106-
return speedUnit;
107-
}
108-
109-
public void setSpeedUnit(String speedUnit) {
110-
this.speedUnit = speedUnit;
111-
}
112-
11391
private double latitude;
11492

11593
public double getLatitude() {
@@ -169,14 +147,4 @@ public String getCoordinateFormat() {
169147
public void setCoordinateFormat(String coordinateFormat) {
170148
this.coordinateFormat = coordinateFormat;
171149
}
172-
173-
private String timezone;
174-
175-
public void setTimezone(String timezone) {
176-
this.timezone = timezone != null ? TimeZone.getTimeZone(timezone).getID() : null;
177-
}
178-
179-
public String getTimezone() {
180-
return timezone;
181-
}
182150
}

src/org/traccar/model/User.java

-30
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.traccar.helper.Hashing;
2323

2424
import java.util.Date;
25-
import java.util.TimeZone;
2625

2726
public class User extends ExtendedModel {
2827

@@ -86,26 +85,6 @@ public void setMap(String map) {
8685
this.map = map;
8786
}
8887

89-
private String distanceUnit;
90-
91-
public String getDistanceUnit() {
92-
return distanceUnit;
93-
}
94-
95-
public void setDistanceUnit(String distanceUnit) {
96-
this.distanceUnit = distanceUnit;
97-
}
98-
99-
private String speedUnit;
100-
101-
public String getSpeedUnit() {
102-
return speedUnit;
103-
}
104-
105-
public void setSpeedUnit(String speedUnit) {
106-
this.speedUnit = speedUnit;
107-
}
108-
10988
private double latitude;
11089

11190
public double getLatitude() {
@@ -272,13 +251,4 @@ public boolean isPasswordValid(String password) {
272251
return Hashing.validatePassword(password, hashedPassword, salt);
273252
}
274253

275-
private String timezone;
276-
277-
public void setTimezone(String timezone) {
278-
this.timezone = timezone != null ? TimeZone.getTimeZone(timezone).getID() : null;
279-
}
280-
281-
public String getTimezone() {
282-
return timezone;
283-
}
284254
}

src/org/traccar/notification/NotificationFormatter.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ public static VelocityContext prepareContext(long userId, Event event, Position
4848
velocityContext.put("event", event);
4949
if (position != null) {
5050
velocityContext.put("position", position);
51-
velocityContext.put("speedUnits", ReportUtils.getSpeedUnit(userId));
51+
velocityContext.put("speedUnit", ReportUtils.getSpeedUnit(userId));
52+
velocityContext.put("distanceUnit", ReportUtils.getDistanceUnit(userId));
53+
velocityContext.put("volumeUnit", ReportUtils.getVolumeUnit(userId));
5254
}
5355
if (event.getGeofenceId() != 0) {
5456
velocityContext.put("geofence", Context.getGeofenceManager().getById(event.getGeofenceId()));

src/org/traccar/reports/ReportUtils.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,19 @@ public static void checkPeriodLimit(Date from, Date to) {
6262
}
6363

6464
public static String getDistanceUnit(long userId) {
65-
return (String) Context.getPermissionsManager().lookupPreference(userId, "distanceUnit", "km");
65+
return (String) Context.getPermissionsManager().lookupAttribute(userId, "distanceUnit", "km");
6666
}
6767

6868
public static String getSpeedUnit(long userId) {
69-
return (String) Context.getPermissionsManager().lookupPreference(userId, "speedUnit", "kn");
69+
return (String) Context.getPermissionsManager().lookupAttribute(userId, "speedUnit", "kn");
70+
}
71+
72+
public static String getVolumeUnit(long userId) {
73+
return (String) Context.getPermissionsManager().lookupAttribute(userId, "volumeUnit", "ltr");
7074
}
7175

7276
public static TimeZone getTimezone(long userId) {
73-
String timezone = (String) Context.getPermissionsManager().lookupPreference(userId, "timezone", null);
77+
String timezone = (String) Context.getPermissionsManager().lookupAttribute(userId, "timezone", null);
7478
return timezone != null ? TimeZone.getTimeZone(timezone) : TimeZone.getDefault();
7579
}
7680

@@ -137,6 +141,7 @@ public static org.jxls.common.Context initializeContext(long userId) {
137141
org.jxls.common.Context jxlsContext = PoiTransformer.createInitialContext();
138142
jxlsContext.putVar("distanceUnit", getDistanceUnit(userId));
139143
jxlsContext.putVar("speedUnit", getSpeedUnit(userId));
144+
jxlsContext.putVar("volumeUnit", getVolumeUnit(userId));
140145
jxlsContext.putVar("webUrl", Context.getVelocityEngine().getProperty("web.url"));
141146
jxlsContext.putVar("dateTool", new DateTool());
142147
jxlsContext.putVar("numberTool", new NumberTool());

templates/export/stops.xlsx

15 Bytes
Binary file not shown.

templates/export/summary.xlsx

3.74 KB
Binary file not shown.

templates/export/trips.xlsx

-85 Bytes
Binary file not shown.

templates/mail/deviceOverspeed.vm

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#set($subject = "$device.name: exceeds the speed")
2-
#if($speedUnits == 'kmh')
2+
#if($speedUnit == 'kmh')
33
#set($speedValue = $position.speed * 1.852)
44
#set($speedString = $numberTool.format("0.0 km/h", $speedValue))
5-
#elseif($speedUnits == 'mph')
5+
#elseif($speedUnit == 'mph')
66
#set($speedValue = $position.speed * 1.15078)
77
#set($speedString = $numberTool.format("0.0 mph", $speedValue))
88
#else

templates/sms/deviceOverspeed.vm

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
#if($speedUnits == 'kmh')
1+
#if($speedUnit == 'kmh')
22
#set($speedValue = $position.speed * 1.852)
33
#set($speedString = $numberTool.format("0.0 km/h", $speedValue))
4-
#elseif($speedUnits == 'mph')
4+
#elseif($speedUnit == 'mph')
55
#set($speedValue = $position.speed * 1.15078)
66
#set($speedString = $numberTool.format("0.0 mph", $speedValue))
77
#else

0 commit comments

Comments
 (0)