aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-05-21 16:13:31 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2015-05-21 16:13:31 +1200
commitc6ce35720e315b0c28a52ef11ada67bf00642270 (patch)
tree53005ddfafa038ea8cad468a534428458a7476df
parentdc76207257da485eeb4887202335c24e46d90263 (diff)
downloadtrackermap-server-c6ce35720e315b0c28a52ef11ada67bf00642270.tar.gz
trackermap-server-c6ce35720e315b0c28a52ef11ada67bf00642270.tar.bz2
trackermap-server-c6ce35720e315b0c28a52ef11ada67bf00642270.zip
Add mock position data
-rw-r--r--default.cfg1
-rw-r--r--src/org/traccar/database/DataManager.java40
-rw-r--r--web/app/view/report/ReportController.js4
3 files changed, 33 insertions, 12 deletions
diff --git a/default.cfg b/default.cfg
index 6bbaf8ce3..bc552c9cb 100644
--- a/default.cfg
+++ b/default.cfg
@@ -10,6 +10,7 @@
<entry key='database.url'>jdbc:h2:./target/database</entry>
<entry key='database.user'>sa</entry>
<entry key='database.password'></entry>
+ <entry key='database.mock'>true</entry>
<!-->
id - Long
diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java
index 82e312c7e..4c65a3995 100644
--- a/src/org/traccar/database/DataManager.java
+++ b/src/org/traccar/database/DataManager.java
@@ -27,7 +27,10 @@ import java.sql.SQLException;
import java.sql.Statement;
import java.util.*;
import javax.sql.DataSource;
+
+import org.traccar.Context;
import org.traccar.helper.DriverDelegate;
+import org.traccar.helper.Log;
import org.traccar.model.Device;
import org.traccar.model.Permission;
import org.traccar.model.Position;
@@ -89,10 +92,6 @@ public class DataManager {
ds.setIdleConnectionTestPeriod(600);
ds.setTestConnectionOnCheckin(true);
dataSource = ds;
-
- if (useNewDatabase) {
- createDatabaseSchema();
- }
// Load statements from configuration
String query;
@@ -111,6 +110,10 @@ public class DataManager {
if (query != null) {
queryUpdateLatestPosition = new NamedParameterStatement(query, dataSource);
}
+
+ if (useNewDatabase) {
+ createDatabaseSchema();
+ }
}
private final NamedParameterStatement.ResultSetProcessor<Device> deviceResultSetProcessor = new NamedParameterStatement.ResultSetProcessor<Device>() {
@@ -302,12 +305,29 @@ public class DataManager {
admin.setPassword("admin");
admin.setAdmin(true);
addUser(admin);
-
- Device device = new Device();
- device.setName("test1");
- device.setUniqueId("123456789012345");
- addDevice(device);
- linkDevice(admin.getId(), device.getId());
+
+ mockData(admin.getId());
+ }
+
+ private void mockData(long userId) {
+ if (Boolean.valueOf(Context.getProps().getProperty("database.mock"))) {
+ try {
+
+ Device device = new Device();
+ device.setName("test1");
+ device.setUniqueId("123456789012345");
+ addDevice(device);
+ linkDevice(userId, device.getId());
+
+ Position position = new Position();
+ position.setDeviceId(device.getId());
+ position.setTime(new Date());
+ addPosition(position);
+
+ } catch (SQLException error) {
+ Log.warning(error);
+ }
+ }
}
public User login(String email, String password) throws SQLException {
diff --git a/web/app/view/report/ReportController.js b/web/app/view/report/ReportController.js
index df194c7f1..d62e87973 100644
--- a/web/app/view/report/ReportController.js
+++ b/web/app/view/report/ReportController.js
@@ -25,14 +25,14 @@ Ext.define('Traccar.view.report.ReportController', {
var fromTime = this.lookupReference('fromTimeField').getValue();
var from = new Date(
- fromDate.getFullYear(), fromDate.getMonth(), fromDate.getDay(),
+ fromDate.getFullYear(), fromDate.getMonth(), fromDate.getDate(),
fromTime.getHours(), fromTime.getMinutes(), fromTime.getSeconds(), fromTime.getMilliseconds());
var toDate = this.lookupReference('toDateField').getValue();
var toTime = this.lookupReference('toTimeField').getValue();
var to = new Date(
- toDate.getFullYear(), toDate.getMonth(), toDate.getDay(),
+ toDate.getFullYear(), toDate.getMonth(), toDate.getDate(),
toTime.getHours(), toTime.getMinutes(), toTime.getSeconds(), toTime.getMilliseconds());
var store = Ext.getStore('Positions');