diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-09-15 11:51:45 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-09-15 11:51:45 +1200 |
commit | 5cf1061cfcc5baf214bce145961512fd4f672621 (patch) | |
tree | 32efac22ba11abddec21656685c3e0ba730b1e47 | |
parent | 34a70e81ecb613c3216fcdd581a9724216137b41 (diff) | |
download | trackermap-server-5cf1061cfcc5baf214bce145961512fd4f672621.tar.gz trackermap-server-5cf1061cfcc5baf214bce145961512fd4f672621.tar.bz2 trackermap-server-5cf1061cfcc5baf214bce145961512fd4f672621.zip |
Rename other field to attributes
-rw-r--r-- | debug.xml | 8 | ||||
-rw-r--r-- | src/org/traccar/DistanceHandler.java | 4 | ||||
-rw-r--r-- | src/org/traccar/StringProtocolEncoder.java | 2 | ||||
-rw-r--r-- | src/org/traccar/WebDataHandler.java | 2 | ||||
-rw-r--r-- | src/org/traccar/database/DataManager.java | 6 | ||||
-rw-r--r-- | src/org/traccar/model/Command.java | 18 | ||||
-rw-r--r-- | src/org/traccar/model/Event.java | 16 | ||||
-rw-r--r-- | src/org/traccar/model/MiscFormatter.java | 26 | ||||
-rw-r--r-- | test/org/traccar/DistanceHandlerTest.java | 2 | ||||
-rw-r--r-- | test/org/traccar/helper/DecoderVerifier.java | 2 | ||||
-rw-r--r-- | test/org/traccar/model/MiscFormatterTest.java | 2 | ||||
-rw-r--r-- | web/app/model/Command.js | 2 | ||||
-rw-r--r-- | web/app/model/Position.js | 2 | ||||
-rw-r--r-- | web/app/view/command/CommandDialog.js | 2 | ||||
-rw-r--r-- | web/app/view/command/CommandDialogController.js | 10 | ||||
-rw-r--r-- | web/app/view/state/StateController.js | 14 |
16 files changed, 60 insertions, 58 deletions
@@ -100,7 +100,7 @@ speed FLOAT NOT NULL, course FLOAT NOT NULL, address VARCHAR(512), - other VARCHAR(4096) NOT NULL, + attributes VARCHAR(4096) NOT NULL, FOREIGN KEY (deviceId) REFERENCES device (id) ON DELETE CASCADE); CREATE INDEX position_deviceId_fixTime ON position (deviceId, fixTime); @@ -111,7 +111,7 @@ deviceId INT NOT NULL, serverTime TIMESTAMP NOT NULL, deviceTime TIMESTAMP NOT NULL, - other VARCHAR(4096) NOT NULL, + attributes VARCHAR(4096) NOT NULL, FOREIGN KEY (deviceId) REFERENCES device (id) ON DELETE CASCADE); CREATE TABLE server ( @@ -232,8 +232,8 @@ </entry> <entry key='database.insertPosition'> - INSERT INTO position (deviceId, protocol, serverTime, deviceTime, fixTime, valid, latitude, longitude, altitude, speed, course, address, other) - VALUES (:deviceId, :protocol, CURRENT_TIMESTAMP(), :time, :time, :valid, :latitude, :longitude, :altitude, :speed, :course, :address, :other); + INSERT INTO position (deviceId, protocol, serverTime, deviceTime, fixTime, valid, latitude, longitude, altitude, speed, course, address, attributes) + VALUES (:deviceId, :protocol, CURRENT_TIMESTAMP(), :time, :time, :valid, :latitude, :longitude, :altitude, :speed, :course, :address, :attributes); </entry> <entry key='database.selectLatestPositions'> diff --git a/src/org/traccar/DistanceHandler.java b/src/org/traccar/DistanceHandler.java index 6232c555f..1586d116b 100644 --- a/src/org/traccar/DistanceHandler.java +++ b/src/org/traccar/DistanceHandler.java @@ -36,8 +36,8 @@ public class DistanceHandler extends BaseDataHandler { Position last = getLastPosition(position.getDeviceId()); if (last != null) { - if (last.getOther().containsKey(Event.KEY_DISTANCE)) { - distance = ((Number) last.getOther().get(Event.KEY_DISTANCE)).doubleValue(); + if (last.getAttributes().containsKey(Event.KEY_DISTANCE)) { + distance = ((Number) last.getAttributes().get(Event.KEY_DISTANCE)).doubleValue(); } distance += DistanceCalculator.distance( diff --git a/src/org/traccar/StringProtocolEncoder.java b/src/org/traccar/StringProtocolEncoder.java index dcb9ccc0e..c64e1d03f 100644 --- a/src/org/traccar/StringProtocolEncoder.java +++ b/src/org/traccar/StringProtocolEncoder.java @@ -30,7 +30,7 @@ public abstract class StringProtocolEncoder extends BaseProtocolEncoder { String result = String.format(format, (Object[]) keys); result = result.replaceAll("\\{" + Command.KEY_UNIQUE_ID + "}", getUniqueId(command.getDeviceId())); - for (Map.Entry<String, Object> entry : command.getOther().entrySet()) { + for (Map.Entry<String, Object> entry : command.getAttributes().entrySet()) { String value = null; if (valueFormatter != null) { value = valueFormatter.formatValue(entry.getKey(), entry.getValue()); diff --git a/src/org/traccar/WebDataHandler.java b/src/org/traccar/WebDataHandler.java index 6a359ba0f..d694212e2 100644 --- a/src/org/traccar/WebDataHandler.java +++ b/src/org/traccar/WebDataHandler.java @@ -58,7 +58,7 @@ public class WebDataHandler extends BaseDataHandler { } private String calculateStatus(Position position) { - if (position.getOther().containsKey(Event.KEY_ALARM) && (Boolean) position.getOther().get(Event.KEY_ALARM)) { + if (position.getAttributes().containsKey(Event.KEY_ALARM) && (Boolean) position.getAttributes().get(Event.KEY_ALARM)) { return "0xF841"; // STATUS_PANIC_ON } else if (position.getSpeed() < 1.0) { return "0xF020"; // STATUS_LOCATION diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java index add355ea7..89df198fa 100644 --- a/src/org/traccar/database/DataManager.java +++ b/src/org/traccar/database/DataManager.java @@ -331,7 +331,8 @@ public class DataManager implements IdentityManager { .setDate("time", position.getFixTime()) // tmp .setLong("device_id", position.getDeviceId()) // tmp .setLong("power", 0) // tmp - .setString("extended_info", MiscFormatter.toXmlString(position.getOther())) // tmp + .setString("extended_info", MiscFormatter.toXmlString(position.getAttributes())) // tmp + .setString("other", MiscFormatter.toXmlString(position.getAttributes())) // tmp .executeUpdate()); } @@ -341,7 +342,8 @@ public class DataManager implements IdentityManager { .setDate("time", position.getFixTime()) // tmp .setLong("device_id", position.getDeviceId()) // tmp .setLong("power", 0) // tmp - .setString("extended_info", MiscFormatter.toXmlString(position.getOther())) // tmp + .setString("extended_info", MiscFormatter.toXmlString(position.getAttributes())) // tmp + .setString("other", MiscFormatter.toXmlString(position.getAttributes())) // tmp .executeUpdate(); } diff --git a/src/org/traccar/model/Command.java b/src/org/traccar/model/Command.java index cfebaa38e..16772e0cb 100644 --- a/src/org/traccar/model/Command.java +++ b/src/org/traccar/model/Command.java @@ -18,15 +18,15 @@ public class Command implements Factory { public String getType() { return type; } public void setType(String type) { this.type = type; } - private Map<String, Object> other = new LinkedHashMap<>(); - public Map<String, Object> getOther() { return other; } - public void setOther(Map<String, Object> other) { this.other = other; } - - public void set(String key, boolean value) { other.put(key, value); } - public void set(String key, int value) { other.put(key, value); } - public void set(String key, long value) { other.put(key, value); } - public void set(String key, double value) { other.put(key, value); } - public void set(String key, String value) { if (value != null && !value.isEmpty()) other.put(key, value); } + private Map<String, Object> attributes = new LinkedHashMap<>(); + public Map<String, Object> getAttributes() { return attributes; } + public void setAttributes(Map<String, Object> attributes) { this.attributes = attributes; } + + public void set(String key, boolean value) { attributes.put(key, value); } + public void set(String key, int value) { attributes.put(key, value); } + public void set(String key, long value) { attributes.put(key, value); } + public void set(String key, double value) { attributes.put(key, value); } + public void set(String key, String value) { if (value != null && !value.isEmpty()) attributes.put(key, value); } public static final String TYPE_POSITION_SINGLE = "positionSingle"; public static final String TYPE_POSITION_PERIODIC = "positionPeriodic"; diff --git a/src/org/traccar/model/Event.java b/src/org/traccar/model/Event.java index 40ea38e26..5ad6c38fe 100644 --- a/src/org/traccar/model/Event.java +++ b/src/org/traccar/model/Event.java @@ -41,15 +41,15 @@ public abstract class Event { public Date getDeviceTime() { return deviceTime; } public void setDeviceTime(Date deviceTime) { this.deviceTime = deviceTime; } - private Map<String, Object> other = new LinkedHashMap<>(); - public Map<String, Object> getOther() { return other; } - public void setOther(Map<String, Object> other) { this.other = other; } + private Map<String, Object> attributes = new LinkedHashMap<>(); + public Map<String, Object> getAttributes() { return attributes; } + public void setAttributes(Map<String, Object> attributes) { this.attributes = attributes; } - public void set(String key, boolean value) { other.put(key, value); } - public void set(String key, int value) { other.put(key, value); } - public void set(String key, long value) { other.put(key, value); } - public void set(String key, double value) { other.put(key, value); } - public void set(String key, String value) { if (value != null && !value.isEmpty()) other.put(key, value); } + public void set(String key, boolean value) { attributes.put(key, value); } + public void set(String key, int value) { attributes.put(key, value); } + public void set(String key, long value) { attributes.put(key, value); } + public void set(String key, double value) { attributes.put(key, value); } + public void set(String key, String value) { if (value != null && !value.isEmpty()) attributes.put(key, value); } // Words separated by dashes (word-second-third) public static final String KEY_INDEX = "index"; diff --git a/src/org/traccar/model/MiscFormatter.java b/src/org/traccar/model/MiscFormatter.java index 7a1e69082..38aa853d4 100644 --- a/src/org/traccar/model/MiscFormatter.java +++ b/src/org/traccar/model/MiscFormatter.java @@ -44,12 +44,12 @@ public class MiscFormatter { } } - public static String toXmlString(Map<String, Object> other) { + public static String toXmlString(Map<String, Object> attributes) { StringBuilder result = new StringBuilder(); result.append("<").append(xmlRootNode).append(">"); - for (Map.Entry<String, Object> entry : other.entrySet()) { + for (Map.Entry<String, Object> entry : attributes.entrySet()) { result.append("<").append(entry.getKey()).append(">"); result.append(format(entry.getValue())); @@ -61,10 +61,10 @@ public class MiscFormatter { return result.toString(); } - public static JsonObject toJson(Map<String, Object> other) { + public static JsonObject toJson(Map<String, Object> attributes) { JsonObjectBuilder json = Json.createObjectBuilder(); - for (Map.Entry<String, Object> entry : other.entrySet()) { + for (Map.Entry<String, Object> entry : attributes.entrySet()) { if (entry.getValue() instanceof String) { json.add(entry.getKey(), (String) entry.getValue()); } else if (entry.getValue() instanceof Integer) { @@ -87,35 +87,35 @@ public class MiscFormatter { public static Map<String, Object> fromJson(JsonObject json) { - Map<String, Object> other = new LinkedHashMap<>(); + Map<String, Object> attributes = new LinkedHashMap<>(); for (Map.Entry<String, JsonValue> entry : json.entrySet()) { switch (entry.getValue().getValueType()) { case STRING: - other.put(entry.getKey(), ((JsonString) entry.getValue()).getString()); + attributes.put(entry.getKey(), ((JsonString) entry.getValue()).getString()); break; case NUMBER: JsonNumber number = (JsonNumber) entry.getValue(); if (number.isIntegral()) { - other.put(entry.getKey(), number.longValue()); + attributes.put(entry.getKey(), number.longValue()); } else { - other.put(entry.getKey(), number.doubleValue()); + attributes.put(entry.getKey(), number.doubleValue()); } break; case TRUE: - other.put(entry.getKey(), true); + attributes.put(entry.getKey(), true); break; case FALSE: - other.put(entry.getKey(), false); + attributes.put(entry.getKey(), false); break; } } - return other; + return attributes; } - public static String toJsonString(Map<String, Object> other) { - return toJson(other).toString(); + public static String toJsonString(Map<String, Object> attributes) { + return toJson(attributes).toString(); } } diff --git a/test/org/traccar/DistanceHandlerTest.java b/test/org/traccar/DistanceHandlerTest.java index 8afeb83f0..e58d9c772 100644 --- a/test/org/traccar/DistanceHandlerTest.java +++ b/test/org/traccar/DistanceHandlerTest.java @@ -15,7 +15,7 @@ public class DistanceHandlerTest { Position position = distanceHandler.calculateDistance(new Position()); - assertEquals(0.0, position.getOther().get(Event.KEY_DISTANCE)); + assertEquals(0.0, position.getAttributes().get(Event.KEY_DISTANCE)); } diff --git a/test/org/traccar/helper/DecoderVerifier.java b/test/org/traccar/helper/DecoderVerifier.java index 63e42cf38..4b6272185 100644 --- a/test/org/traccar/helper/DecoderVerifier.java +++ b/test/org/traccar/helper/DecoderVerifier.java @@ -38,7 +38,7 @@ public class DecoderVerifier { assertTrue(position.getCourse() >= 0); assertTrue(position.getCourse() <= 360); - assertNotNull(position.getOther()); + assertNotNull(position.getAttributes()); } diff --git a/test/org/traccar/model/MiscFormatterTest.java b/test/org/traccar/model/MiscFormatterTest.java index 6a7a05d3b..eb93d5b38 100644 --- a/test/org/traccar/model/MiscFormatterTest.java +++ b/test/org/traccar/model/MiscFormatterTest.java @@ -13,7 +13,7 @@ public class MiscFormatterTest { position.set("b", "2"); position.set("a", "3"); - assertEquals("<info><a>3</a><b>2</b></info>", MiscFormatter.toXmlString(position.getOther())); + assertEquals("<info><a>3</a><b>2</b></info>", MiscFormatter.toXmlString(position.getAttributes())); } diff --git a/web/app/model/Command.js b/web/app/model/Command.js index 45e0a6b96..3e848b57d 100644 --- a/web/app/model/Command.js +++ b/web/app/model/Command.js @@ -25,6 +25,6 @@ Ext.define('Traccar.model.Command', { name: 'type', type: 'string' }, { - name: 'other' + name: 'attributes' }] }); diff --git a/web/app/model/Position.js b/web/app/model/Position.js index f070eb710..365b06115 100644 --- a/web/app/model/Position.js +++ b/web/app/model/Position.js @@ -58,6 +58,6 @@ Ext.define('Traccar.model.Position', { name: 'address', type: 'string' }, { - name: 'other' + name: 'attributes' }] }); diff --git a/web/app/view/command/CommandDialog.js b/web/app/view/command/CommandDialog.js index dbde458e3..e862b9076 100644 --- a/web/app/view/command/CommandDialog.js +++ b/web/app/view/command/CommandDialog.js @@ -43,7 +43,7 @@ Ext.define('Traccar.view.command.CommandDialog', { }, { xtype: 'fieldcontainer', reference: 'paramPositionPeriodic', - name: 'other', + name: 'attributes', hidden: true, items: [{ diff --git a/web/app/view/command/CommandDialogController.js b/web/app/view/command/CommandDialogController.js index 84ab8ede5..6dfb322f5 100644 --- a/web/app/view/command/CommandDialogController.js +++ b/web/app/view/command/CommandDialogController.js @@ -24,17 +24,17 @@ Ext.define('Traccar.view.command.CommandDialogController', { }, onSendClick: function(button) { - var other; + var attributes; var form = button.up('window').down('form'); form.updateRecord(); var record = form.getRecord(); if (record.get('type') === 'positionPeriodic') { - other = this.lookupReference('paramPositionPeriodic'); - var value = other.down('numberfield[name="frequency"]').getValue(); - value *= other.down('combobox[name="unit"]').getValue(); + attributes = this.lookupReference('paramPositionPeriodic'); + var value = attributes.down('numberfield[name="frequency"]').getValue(); + value *= attributes.down('combobox[name="unit"]').getValue(); - record.set('other', { + record.set('attributes', { frequency: value }); } diff --git a/web/app/view/state/StateController.js b/web/app/view/state/StateController.js index 8141b93a3..36978c3d0 100644 --- a/web/app/view/state/StateController.js +++ b/web/app/view/state/StateController.js @@ -83,7 +83,7 @@ Ext.define('Traccar.view.state.StateController', { updatePosition: function(position) { - var other; + var attributes; var value; var unit; var store = Ext.getStore('Attributes'); @@ -108,16 +108,16 @@ Ext.define('Traccar.view.state.StateController', { } } - var xml = position.get('other'); + var xml = position.get('attributes'); if (typeof xml === 'string' || xml instanceof String) { - other = this.parseXml(xml); + attributes = this.parseXml(xml); } else { - other = xml; + attributes = xml; } - for (var key in other) { - if (other.hasOwnProperty(key)) { + for (var key in attributes) { + if (attributes.hasOwnProperty(key)) { - value = other[key]; + value = attributes[key]; if (key === 'distance' || key === 'odometer') { var distanceUnits = Ext.getStore('DistanceUnits'); unit = Traccar.getApplication().getUser().get('distanceUnit') || Traccar.getApplication().getServer().get('distanceUnit') || ''; |