aboutsummaryrefslogtreecommitdiff
path: root/src/org
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2017-03-16 09:49:34 +0500
committerAbyss777 <abyss@fox5.ru>2017-03-20 10:49:21 +0500
commit99e16edfd8b29d5ef1b751eefcf87a14df35cb9b (patch)
tree3427204a869a9ba568df7e71c5358104dc52ec09 /src/org
parent32cf37a4784418bc9be8d66add1b51af3aa91a4d (diff)
downloadtraccar-server-99e16edfd8b29d5ef1b751eefcf87a14df35cb9b.tar.gz
traccar-server-99e16edfd8b29d5ef1b751eefcf87a14df35cb9b.tar.bz2
traccar-server-99e16edfd8b29d5ef1b751eefcf87a14df35cb9b.zip
Implement phone to device comparison
Diffstat (limited to 'src/org')
-rw-r--r--src/org/traccar/database/DeviceManager.java48
-rw-r--r--src/org/traccar/model/Event.java2
-rw-r--r--src/org/traccar/smpp/ClientSmppSessionHandler.java11
3 files changed, 55 insertions, 6 deletions
diff --git a/src/org/traccar/database/DeviceManager.java b/src/org/traccar/database/DeviceManager.java
index f5fde9e1f..ca686b95c 100644
--- a/src/org/traccar/database/DeviceManager.java
+++ b/src/org/traccar/database/DeviceManager.java
@@ -34,6 +34,7 @@ import org.traccar.model.Command;
import org.traccar.model.CommandType;
import org.traccar.model.Device;
import org.traccar.model.DeviceTotalDistance;
+import org.traccar.model.Event;
import org.traccar.model.Group;
import org.traccar.model.Position;
import org.traccar.model.Server;
@@ -49,6 +50,7 @@ public class DeviceManager implements IdentityManager {
private Map<Long, Device> devicesById;
private Map<String, Device> devicesByUniqueId;
+ private Map<String, Device> devicesByPhone;
private AtomicLong devicesLastUpdate = new AtomicLong();
private Map<Long, Group> groupsById;
@@ -90,24 +92,39 @@ public class DeviceManager implements IdentityManager {
if (devicesByUniqueId == null) {
devicesByUniqueId = new ConcurrentHashMap<>(databaseDevices.size());
}
+ if (devicesByPhone == null) {
+ devicesByPhone = new ConcurrentHashMap<>(databaseDevices.size());
+ }
Set<Long> databaseDevicesIds = new HashSet<>();
Set<String> databaseDevicesUniqueIds = new HashSet<>();
+ Set<String> databaseDevicesPhones = new HashSet<>();
for (Device device : databaseDevices) {
databaseDevicesIds.add(device.getId());
databaseDevicesUniqueIds.add(device.getUniqueId());
+ databaseDevicesPhones.add(device.getPhone());
if (devicesById.containsKey(device.getId())) {
Device cachedDevice = devicesById.get(device.getId());
cachedDevice.setName(device.getName());
cachedDevice.setGroupId(device.getGroupId());
+ cachedDevice.setCategory(device.getCategory());
+ cachedDevice.setContact(device.getContact());
+ cachedDevice.setModel(device.getModel());
cachedDevice.setAttributes(device.getAttributes());
if (!device.getUniqueId().equals(cachedDevice.getUniqueId())) {
- devicesByUniqueId.remove(cachedDevice.getUniqueId());
devicesByUniqueId.put(device.getUniqueId(), cachedDevice);
}
cachedDevice.setUniqueId(device.getUniqueId());
+ if (device.getPhone() != null && !device.getPhone().isEmpty()
+ && !device.getPhone().equals(cachedDevice.getPhone())) {
+ devicesByPhone.put(device.getPhone(), cachedDevice);
+ }
+ cachedDevice.setPhone(device.getPhone());
} else {
devicesById.put(device.getId(), device);
devicesByUniqueId.put(device.getUniqueId(), device);
+ if (device.getPhone() != null && !device.getPhone().isEmpty()) {
+ devicesByPhone.put(device.getPhone(), device);
+ }
if (geofenceManager != null) {
Position lastPosition = getLastPosition(device.getId());
if (lastPosition != null) {
@@ -127,8 +144,14 @@ public class DeviceManager implements IdentityManager {
devicesByUniqueId.remove(cachedDeviceUniqId);
}
}
+ for (String cachedDevicePhone : devicesByPhone.keySet()) {
+ if (!databaseDevicesPhones.contains(cachedDevicePhone)) {
+ devicesByPhone.remove(cachedDevicePhone);
+ }
+ }
databaseDevicesIds.clear();
databaseDevicesUniqueIds.clear();
+ databaseDevicesPhones.clear();
}
}
@@ -146,6 +169,10 @@ public class DeviceManager implements IdentityManager {
return devicesByUniqueId.get(uniqueId);
}
+ public Device getDeviceByPhone(String phone) {
+ return devicesByPhone.get(phone);
+ }
+
public Collection<Device> getAllDevices() {
boolean forceUpdate = devicesById.isEmpty();
@@ -180,6 +207,9 @@ public class DeviceManager implements IdentityManager {
devicesById.put(device.getId(), device);
devicesByUniqueId.put(device.getUniqueId(), device);
+ if (device.getPhone() != null && !device.getPhone().isEmpty()) {
+ devicesByPhone.put(device.getPhone(), device);
+ }
}
public void updateDevice(Device device) throws SQLException {
@@ -187,6 +217,9 @@ public class DeviceManager implements IdentityManager {
devicesById.put(device.getId(), device);
devicesByUniqueId.put(device.getUniqueId(), device);
+ if (device.getPhone() != null && !device.getPhone().isEmpty()) {
+ devicesByPhone.put(device.getPhone(), device);
+ }
}
public void updateDeviceStatus(Device device) throws SQLException {
@@ -202,8 +235,12 @@ public class DeviceManager implements IdentityManager {
if (devicesById.containsKey(deviceId)) {
String deviceUniqueId = devicesById.get(deviceId).getUniqueId();
+ String phone = devicesById.get(deviceId).getPhone();
devicesById.remove(deviceId);
devicesByUniqueId.remove(deviceUniqueId);
+ if (phone != null && !phone.isEmpty()) {
+ devicesByPhone.remove(phone);
+ }
}
positions.remove(deviceId);
}
@@ -470,4 +507,13 @@ public class DeviceManager implements IdentityManager {
}
return result;
}
+
+ public void handleTextMessage(String phone, String message) {
+ Device device = devicesByPhone.get(phone);
+ if (device != null && Context.getNotificationManager() != null) {
+ Event event = new Event(Event.TYPE_TEXT_MESSAGE, device.getId());
+ event.set("message", message);
+ Context.getNotificationManager().updateEvent(event, null);
+ }
+ }
}
diff --git a/src/org/traccar/model/Event.java b/src/org/traccar/model/Event.java
index ee62f9776..96b371896 100644
--- a/src/org/traccar/model/Event.java
+++ b/src/org/traccar/model/Event.java
@@ -58,6 +58,8 @@ public class Event extends Message {
public static final String TYPE_MAINTENANCE = "maintenance";
+ public static final String TYPE_TEXT_MESSAGE = "textMessage";
+
private Date serverTime;
public Date getServerTime() {
diff --git a/src/org/traccar/smpp/ClientSmppSessionHandler.java b/src/org/traccar/smpp/ClientSmppSessionHandler.java
index 2a538a40f..f4d40c3eb 100644
--- a/src/org/traccar/smpp/ClientSmppSessionHandler.java
+++ b/src/org/traccar/smpp/ClientSmppSessionHandler.java
@@ -16,6 +16,7 @@
*/
package org.traccar.smpp;
+import org.traccar.Context;
import org.traccar.helper.Log;
import com.cloudhopper.commons.charset.CharsetUtil;
@@ -49,11 +50,11 @@ public class ClientSmppSessionHandler extends DefaultSmppSessionHandler {
+ ", State: "
+ request.getOptionalParameter(SmppConstants.TAG_MSG_STATE).getValueAsByte());
} else {
- Log.debug("SMS Message Received: "
- + CharsetUtil.decode(((DeliverSm) request).getShortMessage(),
- smppClient.mapDataCodingToCharset(((DeliverSm) request).getDataCoding())).trim()
- + ", Source Address: "
- + ((DeliverSm) request).getSourceAddress().getAddress());
+ String sourceAddress = ((DeliverSm) request).getSourceAddress().getAddress();
+ String message = CharsetUtil.decode(((DeliverSm) request).getShortMessage(),
+ smppClient.mapDataCodingToCharset(((DeliverSm) request).getDataCoding()));
+ Log.debug("SMS Message Received: " + message.trim() + ", Source Address: " + sourceAddress);
+ Context.getDeviceManager().handleTextMessage(sourceAddress, message);
}
}
response = request.createResponse();