From d0f6c2b881fe9b35a1924f83f5590c0c745404ea Mon Sep 17 00:00:00 2001 From: lolodomo Date: Sat, 4 Feb 2023 09:30:58 +0100 Subject: [PATCH] [mail] Make actions names for DSL rules consistent with documentation (#14151) * [mail] Make actions names for DSL rules consistent with documentation Keep old names for backward compatibility. Actions names are now consistent over all rule engines. * Review comment: use htmlContent as parameter name * Review comment: make consistent url and urlList parameters Signed-off-by: Laurent Garnier --- bundles/org.openhab.binding.mail/README.md | 8 +- .../mail/internal/action/SendMailActions.java | 90 ++++++++++++------- 2 files changed, 60 insertions(+), 38 deletions(-) diff --git a/bundles/org.openhab.binding.mail/README.md b/bundles/org.openhab.binding.mail/README.md index a196c53a7..888328440 100644 --- a/bundles/org.openhab.binding.mail/README.md +++ b/bundles/org.openhab.binding.mail/README.md @@ -89,11 +89,11 @@ This binding includes rule actions for sending email. Six different actions available: - `boolean success = sendMail(String recipient, String subject, String text)` -- `boolean success = sendMailWithAttachment(String recipient, String subject, String text, String URL)` -- `boolean success = sendMailWithAttachments(String recipient, String subject, String text, List URL)` +- `boolean success = sendMailWithAttachment(String recipient, String subject, String text, String url)` +- `boolean success = sendMailWithAttachments(String recipient, String subject, String text, List urlList)` - `boolean success = sendHtmlMail(String recipient, String subject, String htmlContent)` -- `boolean success = sendHtmlMailWithAttachment(String recipient, String subject, String htmlContent, String URL)` -- `boolean success = sendHtmlMailWithAttachments(String recipient, String subject, String htmlContent, List URL)` +- `boolean success = sendHtmlMailWithAttachment(String recipient, String subject, String htmlContent, String url)` +- `boolean success = sendHtmlMailWithAttachments(String recipient, String subject, String htmlContent, List urlList)` The `sendMail(...)` send a plain text mail (with attachments if supplied). The `sendHtmlMail(...)` send a HTML mail (with attachments if supplied). diff --git a/bundles/org.openhab.binding.mail/src/main/java/org/openhab/binding/mail/internal/action/SendMailActions.java b/bundles/org.openhab.binding.mail/src/main/java/org/openhab/binding/mail/internal/action/SendMailActions.java index d08cf0728..0894ebe6e 100644 --- a/bundles/org.openhab.binding.mail/src/main/java/org/openhab/binding/mail/internal/action/SendMailActions.java +++ b/bundles/org.openhab.binding.mail/src/main/java/org/openhab/binding/mail/internal/action/SendMailActions.java @@ -60,10 +60,10 @@ public class SendMailActions implements ThingActions { public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean sendMailWithAttachment( @ActionInput(name = "recipient") @Nullable String recipient, @ActionInput(name = "subject") @Nullable String subject, @ActionInput(name = "text") @Nullable String text, - @ActionInput(name = "url") @Nullable String urlString) { + @ActionInput(name = "url") @Nullable String url) { List urlList = new ArrayList<>(); - if (urlString != null) { - urlList.add(urlString); + if (url != null) { + urlList.add(url); } return sendMailWithAttachments(recipient, subject, text, urlList); } @@ -72,7 +72,7 @@ public class SendMailActions implements ThingActions { public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean sendMailWithAttachments( @ActionInput(name = "recipient") @Nullable String recipient, @ActionInput(name = "subject") @Nullable String subject, @ActionInput(name = "text") @Nullable String text, - @ActionInput(name = "urlList") @Nullable List urlStringList) { + @ActionInput(name = "urlList") @Nullable List urlList) { if (recipient == null) { logger.warn("Cannot send mail as recipient is missing."); return false; @@ -87,8 +87,8 @@ public class SendMailActions implements ThingActions { if (text != null && !text.isEmpty()) { builder.withText(text); } - if (urlStringList != null) { - for (String urlString : urlStringList) { + if (urlList != null) { + for (String urlString : urlList) { builder.withURLAttachment(urlString); } } @@ -110,48 +110,60 @@ public class SendMailActions implements ThingActions { public static boolean sendMail(ThingActions actions, @Nullable String recipient, @Nullable String subject, @Nullable String text) { - return SendMailActions.sendMail(actions, recipient, subject, text, List.of()); + return SendMailActions.sendMailWithAttachments(actions, recipient, subject, text, List.of()); } public static boolean sendMail(ThingActions actions, @Nullable String recipient, @Nullable String subject, - @Nullable String text, @Nullable String urlString) { + @Nullable String text, @Nullable String url) { + return SendMailActions.sendMailWithAttachment(actions, recipient, subject, text, url); + } + + public static boolean sendMailWithAttachment(ThingActions actions, @Nullable String recipient, + @Nullable String subject, @Nullable String text, @Nullable String url) { List urlList = new ArrayList<>(); - if (urlString != null) { - urlList.add(urlString); + if (url != null) { + urlList.add(url); } - return SendMailActions.sendMail(actions, recipient, subject, text, urlList); + return SendMailActions.sendMailWithAttachments(actions, recipient, subject, text, urlList); } public static boolean sendMail(ThingActions actions, @Nullable String recipient, @Nullable String subject, - @Nullable String text, @Nullable List urlStringList) { - return ((SendMailActions) actions).sendMailWithAttachments(recipient, subject, text, urlStringList); + @Nullable String text, @Nullable List urlList) { + return SendMailActions.sendMailWithAttachments(actions, recipient, subject, text, urlList); + } + + public static boolean sendMailWithAttachments(ThingActions actions, @Nullable String recipient, + @Nullable String subject, @Nullable String text, @Nullable List urlList) { + return ((SendMailActions) actions).sendMailWithAttachments(recipient, subject, text, urlList); } @RuleAction(label = "@text/sendHTMLMessageActionLabel", description = "@text/sendHTMLMessageActionDescription") public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean sendHtmlMail( @ActionInput(name = "recipient") @Nullable String recipient, @ActionInput(name = "subject") @Nullable String subject, - @ActionInput(name = "html") @Nullable String html) { - return sendHtmlMailWithAttachments(recipient, subject, html, List.of()); + @ActionInput(name = "htmlContent") @Nullable String htmlContent) { + return sendHtmlMailWithAttachments(recipient, subject, htmlContent, List.of()); } @RuleAction(label = "@text/sendHTMLAttachmentMessageActionLabel", description = "@text/sendHTMLAttachmentMessageActionDescription") public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean sendHtmlMailWithAttachment( @ActionInput(name = "recipient") @Nullable String recipient, - @ActionInput(name = "subject") @Nullable String subject, @ActionInput(name = "html") @Nullable String html, - @ActionInput(name = "url") @Nullable String urlString) { + @ActionInput(name = "subject") @Nullable String subject, + @ActionInput(name = "htmlContent") @Nullable String htmlContent, + @ActionInput(name = "url") @Nullable String url) { List urlList = new ArrayList<>(); - if (urlString != null) { - urlList.add(urlString); + if (url != null) { + urlList.add(url); } - return sendHtmlMailWithAttachments(recipient, subject, html, urlList); + return sendHtmlMailWithAttachments(recipient, subject, htmlContent, urlList); } @RuleAction(label = "@text/sendHTMLAttachmentsMessageActionLabel", description = "@text/sendHTMLAttachmentsMessageActionDescription") public @ActionOutput(name = "success", type = "java.lang.Boolean") Boolean sendHtmlMailWithAttachments( @ActionInput(name = "recipient") @Nullable String recipient, - @ActionInput(name = "subject") @Nullable String subject, @ActionInput(name = "html") @Nullable String html, - @ActionInput(name = "urlList") @Nullable List urlStringList) { + @ActionInput(name = "subject") @Nullable String subject, + @ActionInput(name = "htmlContent") @Nullable String htmlContent, + @ActionInput(name = "urlList") @Nullable List urlList) { if (recipient == null) { logger.warn("Cannot send mail as recipient is missing."); return false; @@ -163,11 +175,11 @@ public class SendMailActions implements ThingActions { if (subject != null && !subject.isEmpty()) { builder.withSubject(subject); } - if (html != null && !html.isEmpty()) { - builder.withHtml(html); + if (htmlContent != null && !htmlContent.isEmpty()) { + builder.withHtml(htmlContent); } - if (urlStringList != null) { - for (String urlString : urlStringList) { + if (urlList != null) { + for (String urlString : urlList) { builder.withURLAttachment(urlString); } } @@ -188,22 +200,32 @@ public class SendMailActions implements ThingActions { } public static boolean sendHtmlMail(ThingActions actions, @Nullable String recipient, @Nullable String subject, - @Nullable String html) { - return SendMailActions.sendHtmlMail(actions, recipient, subject, html, List.of()); + @Nullable String htmlContent) { + return SendMailActions.sendHtmlMailWithAttachments(actions, recipient, subject, htmlContent, List.of()); } public static boolean sendHtmlMail(ThingActions actions, @Nullable String recipient, @Nullable String subject, - @Nullable String html, @Nullable String urlString) { + @Nullable String htmlContent, @Nullable String url) { + return SendMailActions.sendHtmlMailWithAttachment(actions, recipient, subject, htmlContent, url); + } + + public static boolean sendHtmlMailWithAttachment(ThingActions actions, @Nullable String recipient, + @Nullable String subject, @Nullable String htmlContent, @Nullable String url) { List urlList = new ArrayList<>(); - if (urlString != null) { - urlList.add(urlString); + if (url != null) { + urlList.add(url); } - return SendMailActions.sendHtmlMail(actions, recipient, subject, html, urlList); + return SendMailActions.sendHtmlMailWithAttachments(actions, recipient, subject, htmlContent, urlList); } public static boolean sendHtmlMail(ThingActions actions, @Nullable String recipient, @Nullable String subject, - @Nullable String html, @Nullable List urlStringList) { - return ((SendMailActions) actions).sendHtmlMailWithAttachments(recipient, subject, html, urlStringList); + @Nullable String htmlContent, @Nullable List urlList) { + return SendMailActions.sendHtmlMailWithAttachments(actions, recipient, subject, htmlContent, urlList); + } + + public static boolean sendHtmlMailWithAttachments(ThingActions actions, @Nullable String recipient, + @Nullable String subject, @Nullable String htmlContent, @Nullable List urlList) { + return ((SendMailActions) actions).sendHtmlMailWithAttachments(recipient, subject, htmlContent, urlList); } @Override