diff options
author | Abyss777 <abyss@fox5.ru> | 2017-02-23 10:23:46 +0500 |
---|---|---|
committer | Abyss777 <abyss@fox5.ru> | 2017-02-23 10:23:46 +0500 |
commit | d0ae83ef94f1e4a89b27b70ebbc60150f1c83b31 (patch) | |
tree | e1d7e22aece6c0d308fd3a2a9b854bd713950a14 /src | |
parent | 53236979ca2298a4722512d49f5ebb07b550a914 (diff) | |
download | traccar-server-d0ae83ef94f1e4a89b27b70ebbc60150f1c83b31.tar.gz traccar-server-d0ae83ef94f1e4a89b27b70ebbc60150f1c83b31.tar.bz2 traccar-server-d0ae83ef94f1e4a89b27b70ebbc60150f1c83b31.zip |
- Combine template retrieving in one function
- Do not request delivery receipt
Diffstat (limited to 'src')
-rw-r--r-- | src/org/traccar/notification/NotificationFormatter.java | 37 | ||||
-rw-r--r-- | src/org/traccar/smpp/SmppClient.java | 1 |
2 files changed, 17 insertions, 21 deletions
diff --git a/src/org/traccar/notification/NotificationFormatter.java b/src/org/traccar/notification/NotificationFormatter.java index 1e3072d53..df7d73683 100644 --- a/src/org/traccar/notification/NotificationFormatter.java +++ b/src/org/traccar/notification/NotificationFormatter.java @@ -51,39 +51,36 @@ public final class NotificationFormatter { return velocityContext; } - public static MailMessage formatMailMessage(long userId, Event event, Position position) { - VelocityContext velocityContext = prepareContext(userId, event, position); - String mailTemplatesPath = Context.getConfig().getString("mail.templatesPath", "mail") + "/"; - Template template = null; + private static Template getTemplate(Event event, boolean mail) { + Template template; + String subPath = ""; + if (mail) { + subPath = Context.getConfig().getString("mail.templatesPath", "mail") + "/"; + } else { + subPath = Context.getConfig().getString("sms.templatesPath", "sms") + "/"; + } try { - template = Context.getVelocityEngine().getTemplate(mailTemplatesPath + event.getType() + ".vm", + template = Context.getVelocityEngine().getTemplate(subPath + event.getType() + ".vm", StandardCharsets.UTF_8.name()); } catch (ResourceNotFoundException error) { Log.warning(error); - template = Context.getVelocityEngine().getTemplate(mailTemplatesPath + "unknown.vm", + template = Context.getVelocityEngine().getTemplate(subPath + "unknown.vm", StandardCharsets.UTF_8.name()); } + return template; + } + public static MailMessage formatMailMessage(long userId, Event event, Position position) { + VelocityContext velocityContext = prepareContext(userId, event, position); StringWriter writer = new StringWriter(); - template.merge(velocityContext, writer); - String subject = (String) velocityContext.get("subject"); - return new MailMessage(subject, writer.toString()); + getTemplate(event, true).merge(velocityContext, writer); + return new MailMessage((String) velocityContext.get("subject"), writer.toString()); } public static String formatSmsMessage(long userId, Event event, Position position) { VelocityContext velocityContext = prepareContext(userId, event, position); - String smsTemplatesPath = Context.getConfig().getString("sms.templatesPath", "sms") + "/"; - Template template = null; - try { - template = Context.getVelocityEngine().getTemplate(smsTemplatesPath + event.getType() + ".vm", - StandardCharsets.UTF_8.name()); - } catch (ResourceNotFoundException error) { - Log.warning(error); - template = Context.getVelocityEngine().getTemplate(smsTemplatesPath + "unknown.vm", - StandardCharsets.UTF_8.name()); - } StringWriter writer = new StringWriter(); - template.merge(velocityContext, writer); + getTemplate(event, false).merge(velocityContext, writer); return writer.toString(); } } diff --git a/src/org/traccar/smpp/SmppClient.java b/src/org/traccar/smpp/SmppClient.java index b93253de4..3680d20e2 100644 --- a/src/org/traccar/smpp/SmppClient.java +++ b/src/org/traccar/smpp/SmppClient.java @@ -192,7 +192,6 @@ public class SmppClient { SubmitSm submit = new SubmitSm(); submit.setSourceAddress(new Address(sourceTon, sourceNpi, sourceAddress)); submit.setDestAddress(new Address(destTon, destNpi, destAddress)); - submit.setRegisteredDelivery(SmppConstants.REGISTERED_DELIVERY_SMSC_RECEIPT_REQUESTED); submit.setDataCoding(dataCoding); submit.setShortMessage(textBytes); SubmitSmResp submitResponce = getSession().submit(submit, submitTimeout); |