Browse Source

Improvements to the templates

pull/3760/head
Andrii Shvaika 6 years ago
committed by Andrew Shvayka
parent
commit
3feb32c0f6
  1. 2
      application/src/main/java/org/thingsboard/server/service/apiusage/DefaultTbApiUsageStateService.java
  2. 37
      application/src/main/java/org/thingsboard/server/service/mail/DefaultMailService.java
  3. 242
      application/src/main/resources/templates/state.disabled.ftl
  4. 13
      common/data/src/main/java/org/thingsboard/server/common/data/ApiFeature.java
  5. 2
      rule-engine/rule-engine-api/src/main/java/org/thingsboard/rule/engine/api/MailService.java

2
application/src/main/java/org/thingsboard/server/service/apiusage/DefaultTbApiUsageStateService.java

@ -305,7 +305,7 @@ public class DefaultTbApiUsageStateService implements TbApiUsageStateService {
} }
mailExecutor.submit(() -> { mailExecutor.submit(() -> {
try { try {
mailService.sendApiFeatureStateEmail(apiFeature, stateValue, email, msgs); mailService.sendApiFeatureStateEmail(apiFeature, stateValue, email, msgs[0]);
} catch (ThingsboardException e) { } catch (ThingsboardException e) {
log.warn("[{}] Can't send update of the API state to tenant with provided email [{}]", state.getTenantId(), email, e); log.warn("[{}] Can't send update of the API state to tenant with provided email [{}]", state.getTenantId(), email, e);
} }

37
application/src/main/java/org/thingsboard/server/service/mail/DefaultMailService.java

@ -250,13 +250,11 @@ public class DefaultMailService implements MailService {
} }
@Override @Override
public void sendApiFeatureStateEmail(ApiFeature apiFeature, ApiUsageStateValue stateValue, String email, ApiUsageStateMailMessage[] stateMailMessages) throws ThingsboardException { public void sendApiFeatureStateEmail(ApiFeature apiFeature, ApiUsageStateValue stateValue, String email, ApiUsageStateMailMessage msg) throws ThingsboardException {
String subject = messages.getMessage("api.usage.state", null, Locale.US); String subject = messages.getMessage("api.usage.state", null, Locale.US);
Map<String, Object> model = new HashMap<>(); Map<String, Object> model = new HashMap<>();
model.put("apiFeature", apiFeature.getApiStateKey()); model.put("apiFeature", apiFeature.getLabel());
model.put("apiUsageStateMailMessages", stateMailMessages);
model.put(TARGET_EMAIL, email); model.put(TARGET_EMAIL, email);
String message = null; String message = null;
@ -269,12 +267,43 @@ public class DefaultMailService implements MailService {
message = mergeTemplateIntoString("state.warning.ftl", model); message = mergeTemplateIntoString("state.warning.ftl", model);
break; break;
case DISABLED: case DISABLED:
model.put("apiLimitValueLabel", toDisabledValueLabel(apiFeature) + " " + toDisabledValueLabel(msg));
message = mergeTemplateIntoString("state.disabled.ftl", model); message = mergeTemplateIntoString("state.disabled.ftl", model);
break; break;
} }
sendMail(mailSender, mailFrom, email, subject, message); sendMail(mailSender, mailFrom, email, subject, message);
} }
private String toDisabledValueLabel(ApiFeature apiFeature) {
switch (apiFeature) {
case DB:
return "saved";
case TRANSPORT:
return "received";
case JS:
case RE:
return "invoked";
default:
throw new RuntimeException("Not implemented!");
}
}
private String toDisabledValueLabel(ApiUsageStateMailMessage msg) {
switch (msg.getKey()) {
case STORAGE_DP_COUNT:
case TRANSPORT_DP_COUNT:
return (msg.getThreshold() / 1000000) + "M data points";
case TRANSPORT_MSG_COUNT:
return (msg.getThreshold() / 1000000) + "M messages";
case JS_EXEC_COUNT:
return (msg.getThreshold() / 1000000) + "M JavaScript functions";
case RE_EXEC_COUNT:
return (msg.getThreshold() / 1000000) + "M Rule Engine nodes";
default:
throw new RuntimeException("Not implemented!");
}
}
private void sendMail(JavaMailSenderImpl mailSender, private void sendMail(JavaMailSenderImpl mailSender,
String mailFrom, String email, String mailFrom, String email,
String subject, String message) throws ThingsboardException { String subject, String message) throws ThingsboardException {

242
application/src/main/resources/templates/state.disabled.ftl

@ -15,112 +15,148 @@
limitations under the License. limitations under the License.
--> -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="http://www.w3.org/1999/xhtml" style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;"> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
<head> <head>
<meta name="viewport" content="width=device-width" /> <meta name="viewport" content="width=device-width"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Thingsboard - Api Usage State</title> <title>Thingsboard - Api Usage State</title>
<style type="text/css"> <style type="text/css">
img { img {
max-width: 100%; max-width: 100%;
} }
body {
-webkit-font-smoothing: antialiased; -webkit-text-size-adjust: none; width: 100% !important; height: 100%; line-height: 1.6em; body {
} -webkit-font-smoothing: antialiased;
body { -webkit-text-size-adjust: none;
background-color: #f6f6f6; width: 100% !important;
} height: 100%;
@media only screen and (max-width: 640px) { line-height: 1.6em;
body { }
padding: 0 !important;
} body {
h1 { background-color: #f6f6f6;
font-weight: 800 !important; margin: 20px 0 5px !important; }
}
h2 { @media only screen and (max-width: 640px) {
font-weight: 800 !important; margin: 20px 0 5px !important; body {
} padding: 0 !important;
h3 { }
font-weight: 800 !important; margin: 20px 0 5px !important;
} h1 {
h4 { font-weight: 800 !important;
font-weight: 800 !important; margin: 20px 0 5px !important; margin: 20px 0 5px !important;
} }
h1 {
font-size: 22px !important; h2 {
} font-weight: 800 !important;
h2 { margin: 20px 0 5px !important;
font-size: 18px !important; }
}
h3 { h3 {
font-size: 16px !important; font-weight: 800 !important;
} margin: 20px 0 5px !important;
.container { }
padding: 0 !important; width: 100% !important;
} h4 {
.content { font-weight: 800 !important;
padding: 0 !important; margin: 20px 0 5px !important;
} }
.content-wrap {
padding: 10px !important; h1 {
} font-size: 22px !important;
.invoice { }
width: 100% !important;
} h2 {
} font-size: 18px !important;
</style> }
h3 {
font-size: 16px !important;
}
.container {
padding: 0 !important;
width: 100% !important;
}
.content {
padding: 0 !important;
}
.content-wrap {
padding: 10px !important;
}
.invoice {
width: 100% !important;
}
}
</style>
</head> </head>
<body itemscope itemtype="http://schema.org/EmailMessage" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: none; width: 100% !important; height: 100%; line-height: 1.6em; background-color: #f6f6f6; margin: 0;" bgcolor="#f6f6f6"> <body itemscope itemtype="http://schema.org/EmailMessage"
style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: none; width: 100% !important; height: 100%; line-height: 1.6em; background-color: #f6f6f6; margin: 0;"
<table class="body-wrap" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; width: 100%; background-color: #f6f6f6; margin: 0;" bgcolor="#f6f6f6"><tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;"><td style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0;" valign="top"></td> bgcolor="#f6f6f6">
<td class="container" width="600" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; display: block !important; max-width: 600px !important; clear: both !important; margin: 0 auto;" valign="top">
<div class="content" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; max-width: 600px; display: block; margin: 0 auto; padding: 20px;"> <table class="main"
<table class="main" width="100%" cellpadding="0" cellspacing="0" itemprop="action" itemscope itemtype="http://schema.org/ConfirmAction" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; border-radius: 3px; background-color: #fff; margin: 0; border: 1px solid #e9e9e9;" bgcolor="#fff"><tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;"><td class="content-wrap" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0; padding: 20px;" valign="top"> style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; box-sizing: border-box; border-radius: 3px; width: 100%; background-color: #f6f6f6; margin: 0px auto;"
<meta itemprop="name" content="Confirm Email" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;" /><table width="100%" cellpadding="0" cellspacing="0" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;"> cellspacing="0" cellpadding="0" bgcolor="#f6f6f6">
<tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;"> <tbody>
<td class="content-block" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; color: #348eda; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0; padding: 0 0 20px;" valign="top"> <tr style="box-sizing: border-box; margin: 0px;">
<h2>Thingsboard Api Usage State for tenant has been updated</h2> <td class="content-wrap" style="box-sizing: border-box; vertical-align: top; margin: 0px; padding: 20px;"
</td> align="center" valign="top">
</tr> <table style="box-sizing: border-box; border: 1px solid #e9e9e9; border-radius: 3px; margin: 0px; height: 223px; padding: 20px; background-color: #ffffff; width: 600px; max-width: 600px !important;"
<tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;"> width="600" cellspacing="0" cellpadding="0">
<td class="content-block" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0; padding: 0 0 20px;" valign="top"> <tbody>
Thingsboard Usage state ${apiFeature} was updated to status DISABLED. <tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
</td> <td class="content-block"
</tr> style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; color: #348eda; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0px; padding: 0px 0px 20px; height: 84px;"
<#list apiUsageStateMailMessages as msg> valign="top">
<tr> <h2>Your ThingsBoard account feature was disabled</h2>
<td> </td>
${msg.key.apiLimitKey} = ${msg.threshold} </tr>
</td> <tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
</tr> <td class="content-block"
<tr> style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0px; padding: 0px 0px 20px; height: 40px;"
<td> valign="top">We have disabled the ${apiFeature} for your account because ThingsBoard has already&nbsp; ${apiLimitValueLabel}
${msg.key.apiCountKey} = ${msg.value} .
</td> </td>
</tr> </tr>
</#list> <tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
<tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;"> <td class="content-block"
<td class="content-block" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0; padding: 0 0 20px;" valign="top"> style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0px; padding: 0px 0px 20px; height: 59px;"
&mdash; The Thingsboard valign="top">Please contact your system administrator to resolve the issue.
</td> </td>
</tr></table></td> </tr>
</tr> <tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
</table> <td class="content-block"
<div class="footer" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; width: 100%; clear: both; color: #999; margin: 0; padding: 20px;"> style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0px; padding: 0px 0px 20px; height: 40px;"
<table width="100%" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;"> valign="top">&mdash; The ThingsBoard
<tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;"> </td>
<td class="aligncenter content-block" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 12px; vertical-align: top; color: #999; text-align: center; margin: 0; padding: 0 0 20px;" align="center" valign="top">This email was sent to <a href="mailto:${targetEmail}" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 12px; color: #999; text-decoration: underline; margin: 0;">${targetEmail}</a> by Thingsboard.</td> </tr>
</tr> </tbody>
</table> </table>
</div> </td>
</div> </tr>
</td> </tbody>
<td style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0;" valign="top"></td> </table>
</tr> <table style="color: #999999; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; box-sizing: border-box; margin: 0px auto; height: 64px; background-color: #f6f6f6; width: 100%;"
cellpadding="0px 0px 20px">
<tbody>
<tr style="box-sizing: border-box; margin: 0px;">
<td class="aligncenter content-block"
style="box-sizing: border-box; font-size: 12px; margin: 0px; padding: 0px 0px 20px; width: 600px; text-align: center; vertical-align: middle;"
align="center" valign="top">This email was sent to&nbsp;<a
style="box-sizing: border-box; color: #999999; margin: 0px;"
href="mailto:${targetEmail}">${targetEmail}</a>&nbsp;by ThingsBoard.
</td>
</tr>
</tbody>
</table> </table>
</body> </body>
</html> </html>

13
common/data/src/main/java/org/thingsboard/server/common/data/ApiFeature.java

@ -18,16 +18,19 @@ package org.thingsboard.server.common.data;
import lombok.Getter; import lombok.Getter;
public enum ApiFeature { public enum ApiFeature {
TRANSPORT("transportApiState"), TRANSPORT("transportApiState", "Device API"),
DB("dbApiState"), DB("dbApiState", "Telemetry persistence"),
RE("ruleEngineApiState"), RE("ruleEngineApiState", "Rule engine execution"),
JS("jsExecutionApiState"); JS("jsExecutionApiState", "JavaScript functions execution");
@Getter @Getter
private final String apiStateKey; private final String apiStateKey;
@Getter
private final String label;
ApiFeature(String apiStateKey) { ApiFeature(String apiStateKey, String label) {
this.apiStateKey = apiStateKey; this.apiStateKey = apiStateKey;
this.label = label;
} }
} }

2
rule-engine/rule-engine-api/src/main/java/org/thingsboard/rule/engine/api/MailService.java

@ -43,5 +43,5 @@ public interface MailService {
void sendAccountLockoutEmail( String lockoutEmail, String email, Integer maxFailedLoginAttempts) throws ThingsboardException; void sendAccountLockoutEmail( String lockoutEmail, String email, Integer maxFailedLoginAttempts) throws ThingsboardException;
void sendApiFeatureStateEmail(ApiFeature apiFeature, ApiUsageStateValue stateValue, String email, ApiUsageStateMailMessage[] stateMailMessages) throws ThingsboardException; void sendApiFeatureStateEmail(ApiFeature apiFeature, ApiUsageStateValue stateValue, String email, ApiUsageStateMailMessage msg) throws ThingsboardException;
} }

Loading…
Cancel
Save