diff options
author | Abyss777 <abyss@fox5.ru> | 2018-06-26 09:22:22 +0500 |
---|---|---|
committer | Abyss777 <abyss@fox5.ru> | 2018-06-26 09:22:22 +0500 |
commit | aba402226403f8b3eb58cc01e8f536eb4104d35a (patch) | |
tree | ec884994ad90365fa9b385465a80391606f6d970 /src/org/traccar/notification/NotificationSms.java | |
parent | c700bfdb66071ba224ddf01e9827e721562fed7a (diff) | |
parent | 575deac9e2df1cbd0601328f7ea7a9f22029fa43 (diff) | |
download | trackermap-server-aba402226403f8b3eb58cc01e8f536eb4104d35a.tar.gz trackermap-server-aba402226403f8b3eb58cc01e8f536eb4104d35a.tar.bz2 trackermap-server-aba402226403f8b3eb58cc01e8f536eb4104d35a.zip |
Merge remote-tracking branch 'ivanfmartinez/notifications'
# Conflicts:
# src/org/traccar/Context.java
Diffstat (limited to 'src/org/traccar/notification/NotificationSms.java')
-rw-r--r-- | src/org/traccar/notification/NotificationSms.java | 43 |
1 files changed, 26 insertions, 17 deletions
diff --git a/src/org/traccar/notification/NotificationSms.java b/src/org/traccar/notification/NotificationSms.java index 8c0265af4..63fd57895 100644 --- a/src/org/traccar/notification/NotificationSms.java +++ b/src/org/traccar/notification/NotificationSms.java @@ -20,33 +20,42 @@ import org.traccar.Context; import org.traccar.model.Event; import org.traccar.model.Position; import org.traccar.model.User; +import org.traccar.sms.SMSManager; +import org.traccar.sms.SMSException; -import com.cloudhopper.smpp.type.RecoverablePduException; -import com.cloudhopper.smpp.type.SmppChannelException; -import com.cloudhopper.smpp.type.SmppTimeoutException; -import com.cloudhopper.smpp.type.UnrecoverablePduException; +public final class NotificationSms extends Notificator { -public final class NotificationSms { + private final SMSManager sms; - private NotificationSms() { + public NotificationSms(String methodId) throws ClassNotFoundException, + InstantiationException, IllegalAccessException { + final String smsClass = Context.getConfig().getString("notificator." + methodId + ".sms.class", ""); + if (smsClass.length() > 0) { + sms = (SMSManager) Class.forName(smsClass).newInstance(); + } else { + sms = Context.getSmsManager(); + } } - public static void sendSmsAsync(long userId, Event event, Position position) { - User user = Context.getPermissionsManager().getUser(userId); - if (Context.getSmppManager() != null && user.getPhone() != null) { + + @Override + public void sendAsync(long userId, Event event, Position position) { + final User user = Context.getPermissionsManager().getUser(userId); + if (user.getPhone() != null) { Context.getStatisticsManager().registerSms(); - Context.getSmppManager().sendMessageAsync(user.getPhone(), - NotificationFormatter.formatSmsMessage(userId, event, position), false); + sms.sendMessageAsync(user.getPhone(), + NotificationFormatter.formatShortMessage(userId, event, position), false); } } - public static void sendSmsSync(long userId, Event event, Position position) throws RecoverablePduException, - UnrecoverablePduException, SmppTimeoutException, SmppChannelException, InterruptedException { - User user = Context.getPermissionsManager().getUser(userId); - if (Context.getSmppManager() != null && user.getPhone() != null) { + @Override + public void sendSync(long userId, Event event, Position position) throws SMSException, + InterruptedException { + final User user = Context.getPermissionsManager().getUser(userId); + if (user.getPhone() != null) { Context.getStatisticsManager().registerSms(); - Context.getSmppManager().sendMessageSync(user.getPhone(), - NotificationFormatter.formatSmsMessage(userId, event, position), false); + sms.sendMessageSync(user.getPhone(), + NotificationFormatter.formatShortMessage(userId, event, position), false); } } } |