use of org.traccar.model.Notification in project traccar by tananaev.
the class NotificationManager method updateEvent.
public void updateEvent(Event event, Position position) {
try {
getDataManager().addObject(event);
} catch (StorageException error) {
LOGGER.warn("Event save error", error);
}
long deviceId = event.getDeviceId();
Set<Long> users = Context.getPermissionsManager().getDeviceUsers(deviceId);
Set<Long> usersToForward = null;
if (Context.getEventForwarder() != null) {
usersToForward = new HashSet<>();
}
for (long userId : users) {
if ((event.getGeofenceId() == 0 || Context.getGeofenceManager().checkItemPermission(userId, event.getGeofenceId())) && (event.getMaintenanceId() == 0 || Context.getMaintenancesManager().checkItemPermission(userId, event.getMaintenanceId()))) {
if (usersToForward != null) {
usersToForward.add(userId);
}
final Set<String> notificators = new HashSet<>();
for (long notificationId : getEffectiveNotifications(userId, deviceId, event.getEventTime())) {
Notification notification = getById(notificationId);
if (getById(notificationId).getType().equals(event.getType())) {
boolean filter = false;
if (event.getType().equals(Event.TYPE_ALARM)) {
String alarmsAttribute = notification.getString("alarms");
if (alarmsAttribute == null) {
filter = true;
} else {
List<String> alarms = Arrays.asList(alarmsAttribute.split(","));
filter = !alarms.contains(event.getString(Position.KEY_ALARM));
}
}
if (!filter) {
notificators.addAll(notification.getNotificatorsTypes());
}
}
}
if (position != null && position.getAddress() == null && geocodeOnRequest && Context.getGeocoder() != null) {
position.setAddress(Context.getGeocoder().getAddress(position.getLatitude(), position.getLongitude(), null));
}
for (String notificator : notificators) {
Context.getNotificatorManager().getNotificator(notificator).sendAsync(userId, event, position);
}
}
}
if (Context.getEventForwarder() != null) {
Context.getEventForwarder().forwardEvent(event, position, usersToForward);
}
}
use of org.traccar.model.Notification in project traccar by traccar.
the class NotificationManager method updateEvent.
public void updateEvent(Event event, Position position) {
try {
getDataManager().addObject(event);
} catch (SQLException error) {
Log.warning(error);
}
if (position != null && geocodeOnRequest && Context.getGeocoder() != null && position.getAddress() == null) {
position.setAddress(Context.getGeocoder().getAddress(position.getLatitude(), position.getLongitude(), null));
}
long deviceId = event.getDeviceId();
Set<Long> users = Context.getPermissionsManager().getDeviceUsers(deviceId);
Set<Long> usersToForward = null;
if (Context.getEventForwarder() != null) {
usersToForward = new HashSet<>();
}
for (long userId : users) {
if (event.getGeofenceId() == 0 || Context.getGeofenceManager() != null && Context.getGeofenceManager().checkItemPermission(userId, event.getGeofenceId())) {
if (usersToForward != null) {
usersToForward.add(userId);
}
boolean sentWeb = false;
boolean sentMail = false;
boolean sentSms = Context.getSmppManager() == null;
for (long notificationId : getEffectiveNotifications(userId, deviceId, event.getServerTime())) {
Notification notification = getById(notificationId);
if (getById(notificationId).getType().equals(event.getType())) {
if (!sentWeb && notification.getWeb()) {
Context.getConnectionManager().updateEvent(userId, event);
sentWeb = true;
}
if (!sentMail && notification.getMail()) {
NotificationMail.sendMailAsync(userId, event, position);
sentMail = true;
}
if (!sentSms && notification.getSms()) {
NotificationSms.sendSmsAsync(userId, event, position);
sentSms = true;
}
}
if (sentWeb && sentMail && sentSms) {
break;
}
}
}
}
if (Context.getEventForwarder() != null) {
Context.getEventForwarder().forwardEvent(event, position, usersToForward);
}
}
Aggregations