You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by GitBox <gi...@apache.org> on 2020/01/04 14:24:34 UTC

[GitHub] [incubator-dolphinscheduler] clay4444 opened a new pull request #1713: Refactor alert template

clay4444 opened a new pull request #1713: Refactor alert template
URL: https://github.com/apache/incubator-dolphinscheduler/pull/1713
 
 
   ## What is the purpose of the pull request
   
   this pr is for refactor alert template, remove FreeMarker.  link issue  #1691 
   
   ## Brief change log
   
   1. remove freemarker
   2. define an abstract class and provide a default implementation. The implementation method is concat string. The reason for not using interfaces is to consider the problem of code reuse.
   3. provide a factory class to select a specific implementation class based on user configuration
   
   
   ## Verify this pull request
   
   This change added tests and can be verified as follows:
   
     - *Added AlertTemplateFactoryTest test  class for AlertTemplateFactory.*
     - *Added DefaultHTMLTemplateTest test  class for DefaultHTMLTemplateTest.*
     - *Manually verified the change by testing locally ( for MailUtilsTest ).*
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-dolphinscheduler] codecov-io edited a comment on issue #1713: Refactor alert template

Posted by GitBox <gi...@apache.org>.
codecov-io edited a comment on issue #1713: Refactor alert template
URL: https://github.com/apache/incubator-dolphinscheduler/pull/1713#issuecomment-570790461
 
 
   # [Codecov](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713?src=pr&el=h1) Report
   > Merging [#1713](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713?src=pr&el=desc) into [dev](https://codecov.io/gh/apache/incubator-dolphinscheduler/commit/1f7db8f7975d2d01048eaaeae98d4425417abbae?src=pr&el=desc) will **increase** coverage by `0.3%`.
   > The diff coverage is `70.68%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713/graphs/tree.svg?width=650&token=bv9iXXRLi9&height=150&src=pr)](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713?src=pr&el=tree)
   
   ```diff
   @@            Coverage Diff            @@
   ##              dev    #1713     +/-   ##
   =========================================
   + Coverage   17.48%   17.79%   +0.3%     
   =========================================
     Files         285      287      +2     
     Lines       13912    13905      -7     
     Branches     2274     2277      +3     
   =========================================
   + Hits         2433     2474     +41     
   + Misses      11206    11154     -52     
   - Partials      273      277      +4
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713?src=pr&el=tree) | Coverage Δ | |
   |---|---|---|
   | [...apache/dolphinscheduler/alert/utils/MailUtils.java](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713/diff?src=pr&el=tree#diff-ZG9scGhpbnNjaGVkdWxlci1hbGVydC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvZG9scGhpbnNjaGVkdWxlci9hbGVydC91dGlscy9NYWlsVXRpbHMuamF2YQ==) | `0% <0%> (ø)` | :arrow_up: |
   | [...scheduler/alert/template/AlertTemplateFactory.java](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713/diff?src=pr&el=tree#diff-ZG9scGhpbnNjaGVkdWxlci1hbGVydC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvZG9scGhpbnNjaGVkdWxlci9hbGVydC90ZW1wbGF0ZS9BbGVydFRlbXBsYXRlRmFjdG9yeS5qYXZh) | `42.85% <42.85%> (ø)` | |
   | [...duler/alert/template/impl/DefaultHTMLTemplate.java](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713/diff?src=pr&el=tree#diff-ZG9scGhpbnNjaGVkdWxlci1hbGVydC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvZG9scGhpbnNjaGVkdWxlci9hbGVydC90ZW1wbGF0ZS9pbXBsL0RlZmF1bHRIVE1MVGVtcGxhdGUuamF2YQ==) | `79.16% <79.16%> (ø)` | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713?src=pr&el=continue).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713?src=pr&el=footer). Last update [1f7db8f...5c313eb](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-dolphinscheduler] codecov-io commented on issue #1713: Refactor alert template

Posted by GitBox <gi...@apache.org>.
codecov-io commented on issue #1713: Refactor alert template
URL: https://github.com/apache/incubator-dolphinscheduler/pull/1713#issuecomment-570790461
 
 
   # [Codecov](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713?src=pr&el=h1) Report
   > Merging [#1713](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713?src=pr&el=desc) into [dev](https://codecov.io/gh/apache/incubator-dolphinscheduler/commit/4d1abb3fc7589b2cee846e806f59acc3a2375ecd?src=pr&el=desc) will **increase** coverage by `<.01%`.
   > The diff coverage is `0%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713/graphs/tree.svg?width=650&token=bv9iXXRLi9&height=150&src=pr)](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713?src=pr&el=tree)
   
   ```diff
   @@            Coverage Diff             @@
   ##              dev    #1713      +/-   ##
   ==========================================
   + Coverage   17.48%   17.49%   +<.01%     
   ==========================================
     Files         285      288       +3     
     Lines       13912    13908       -4     
     Branches     2274     2277       +3     
   ==========================================
     Hits         2433     2433              
   + Misses      11206    11202       -4     
     Partials      273      273
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713?src=pr&el=tree) | Coverage Δ | |
   |---|---|---|
   | [...duler/alert/template/impl/DefaultHTMLTemplate.java](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713/diff?src=pr&el=tree#diff-ZG9scGhpbnNjaGVkdWxlci1hbGVydC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvZG9scGhpbnNjaGVkdWxlci9hbGVydC90ZW1wbGF0ZS9pbXBsL0RlZmF1bHRIVE1MVGVtcGxhdGUuamF2YQ==) | `0% <0%> (ø)` | |
   | [...apache/dolphinscheduler/alert/utils/MailUtils.java](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713/diff?src=pr&el=tree#diff-ZG9scGhpbnNjaGVkdWxlci1hbGVydC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvZG9scGhpbnNjaGVkdWxlci9hbGVydC91dGlscy9NYWlsVXRpbHMuamF2YQ==) | `0% <0%> (ø)` | :arrow_up: |
   | [...dolphinscheduler/alert/template/AlertTemplate.java](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713/diff?src=pr&el=tree#diff-ZG9scGhpbnNjaGVkdWxlci1hbGVydC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvZG9scGhpbnNjaGVkdWxlci9hbGVydC90ZW1wbGF0ZS9BbGVydFRlbXBsYXRlLmphdmE=) | `0% <0%> (ø)` | |
   | [...scheduler/alert/template/AlertTemplateFactory.java](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713/diff?src=pr&el=tree#diff-ZG9scGhpbnNjaGVkdWxlci1hbGVydC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvZG9scGhpbnNjaGVkdWxlci9hbGVydC90ZW1wbGF0ZS9BbGVydFRlbXBsYXRlRmFjdG9yeS5qYXZh) | `0% <0%> (ø)` | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713?src=pr&el=continue).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713?src=pr&el=footer). Last update [4d1abb3...3ad4597](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-dolphinscheduler] Technoboy- commented on a change in pull request #1713: Refactor alert template

Posted by GitBox <gi...@apache.org>.
Technoboy- commented on a change in pull request #1713: Refactor alert template
URL: https://github.com/apache/incubator-dolphinscheduler/pull/1713#discussion_r363077219
 
 

 ##########
 File path: dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/template/AlertTemplateFactory.java
 ##########
 @@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dolphinscheduler.alert.template;
+
+import org.apache.dolphinscheduler.alert.exception.NotSupportOperatorException;
+import org.apache.dolphinscheduler.alert.template.impl.DefaultHTMLTemplate;
+import org.apache.dolphinscheduler.alert.utils.Constants;
+import org.apache.dolphinscheduler.alert.utils.PropertyUtils;
+import org.apache.dolphinscheduler.common.utils.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * the alert template factory
+ */
+public class AlertTemplateFactory {
+
+    private static final Logger logger = LoggerFactory.getLogger(AlertTemplateFactory.class);
+
+    private static final String alertTemplate = PropertyUtils.getString(Constants.ALERT_TEMPLATE);
+
+    private AlertTemplateFactory(){}
+
+    /**
+     * get a template from alert.properties conf file
+     * @return a template, default is DefaultHTMLTemplate
+     * @throws NotSupportOperatorException
+     */
+    public static AlertTemplate getMessageTemplate() throws NotSupportOperatorException {
 
 Review comment:
   No need to throw RuntimeException

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-dolphinscheduler] Technoboy- commented on a change in pull request #1713: Refactor alert template

Posted by GitBox <gi...@apache.org>.
Technoboy- commented on a change in pull request #1713: Refactor alert template
URL: https://github.com/apache/incubator-dolphinscheduler/pull/1713#discussion_r363077186
 
 

 ##########
 File path: dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/template/impl/DefaultHTMLTemplate.java
 ##########
 @@ -0,0 +1,163 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dolphinscheduler.alert.template.impl;
+
+import org.apache.dolphinscheduler.alert.exception.NotSupportOperatorException;
+import org.apache.dolphinscheduler.alert.template.AlertTemplate;
+import org.apache.dolphinscheduler.alert.utils.Constants;
+import org.apache.dolphinscheduler.alert.utils.JSONUtils;
+import org.apache.dolphinscheduler.alert.utils.MailUtils;
+import org.apache.dolphinscheduler.common.enums.ShowType;
+import org.apache.dolphinscheduler.common.utils.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.*;
+
+import static org.apache.dolphinscheduler.common.utils.Preconditions.*;
+
+/**
+ * the default html alert message template
+ */
+public class DefaultHTMLTemplate implements AlertTemplate {
+
+    public static final Logger logger = LoggerFactory.getLogger(DefaultHTMLTemplate.class);
+
+    @Override
+    public String getMessageFromTemplate(String content, ShowType showType,boolean showAll) {
+
+        switch (showType){
+            case TABLE:
+                return getTableTypeMessage(content,showAll);
+            case TEXT:
+                return getTextTypeMessage(content,showAll);
+            default:
+                logger.error("not support showType: {} in DefaultHTMLTemplate",showType);
+                throw new NotSupportOperatorException(String.format("not support showType: %s in DefaultHTMLTemplate",showType));
 
 Review comment:
   using IllegalArgumentException .
   No need to create a new exception

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-dolphinscheduler] Technoboy- commented on a change in pull request #1713: Refactor alert template

Posted by GitBox <gi...@apache.org>.
Technoboy- commented on a change in pull request #1713: Refactor alert template
URL: https://github.com/apache/incubator-dolphinscheduler/pull/1713#discussion_r363077393
 
 

 ##########
 File path: dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/template/impl/DefaultHTMLTemplate.java
 ##########
 @@ -0,0 +1,163 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dolphinscheduler.alert.template.impl;
+
+import org.apache.dolphinscheduler.alert.exception.NotSupportOperatorException;
+import org.apache.dolphinscheduler.alert.template.AlertTemplate;
+import org.apache.dolphinscheduler.alert.utils.Constants;
+import org.apache.dolphinscheduler.alert.utils.JSONUtils;
+import org.apache.dolphinscheduler.alert.utils.MailUtils;
+import org.apache.dolphinscheduler.common.enums.ShowType;
+import org.apache.dolphinscheduler.common.utils.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.*;
+
+import static org.apache.dolphinscheduler.common.utils.Preconditions.*;
+
+/**
+ * the default html alert message template
+ */
+public class DefaultHTMLTemplate implements AlertTemplate {
+
+    public static final Logger logger = LoggerFactory.getLogger(DefaultHTMLTemplate.class);
+
+    @Override
+    public String getMessageFromTemplate(String content, ShowType showType,boolean showAll) {
+
+        switch (showType){
+            case TABLE:
+                return getTableTypeMessage(content,showAll);
+            case TEXT:
+                return getTextTypeMessage(content,showAll);
+            default:
+                logger.error("not support showType: {} in DefaultHTMLTemplate",showType);
+                throw new NotSupportOperatorException(String.format("not support showType: %s in DefaultHTMLTemplate",showType));
+        }
+    }
+
+    /**
+     * get alert message which type is TABLE
+     * @param content message content
+     * @param showAll weather to show all
+     * @return alert message
+     */
+    private String getTableTypeMessage(String content,boolean showAll){
+
+        if (StringUtils.isNotEmpty(content)){
+            List<LinkedHashMap> mapItemsList = JSONUtils.toList(content, LinkedHashMap.class);
+
+            if(!showAll && mapItemsList.size() > Constants.NUMBER_1000){
+                mapItemsList = mapItemsList.subList(0,Constants.NUMBER_1000);
+            }
+
+            StringBuilder contents = new StringBuilder(200);
+
+            boolean flag = true;
+
+            String title = "";
+            for (LinkedHashMap mapItems : mapItemsList){
+
+                Set<Map.Entry<String, Object>> entries = mapItems.entrySet();
+
+                Iterator<Map.Entry<String, Object>> iterator = entries.iterator();
+
+                StringBuilder t = new StringBuilder(Constants.TR);
+                StringBuilder cs = new StringBuilder(Constants.TR);
+                while (iterator.hasNext()){
+
+                    Map.Entry<String, Object> entry = iterator.next();
+                    t.append(Constants.TH).append(entry.getKey()).append(Constants.TH_END);
+                    cs.append(Constants.TD).append(String.valueOf(entry.getValue())).append(Constants.TD_END);
+
+                }
+                t.append(Constants.TR_END);
+                cs.append(Constants.TR_END);
+                if (flag){
+                    title = t.toString();
+                }
+                flag = false;
+                contents.append(cs);
+            }
+
+            return getMessageFromHtmlTemplate(title,contents.toString());
+        }
+
+        return null;
+    }
+
+    /**
+     * get alert message which type is TEXT
+     * @param content message content
+     * @param showAll weather to show all
+     * @return alert message
+     */
+    private String getTextTypeMessage(String content,boolean showAll){
+
+        if (StringUtils.isNotEmpty(content)){
+            List<String> list;
+            try {
+                list = JSONUtils.toList(content,String.class);
+            }catch (Exception e){
+                logger.error("json format exception",e);
+                return null;
+            }
+
+            StringBuilder contents = new StringBuilder(100);
+            for (String str : list){
+                contents.append(Constants.TR);
+                contents.append(Constants.TD).append(str).append(Constants.TD_END);
+                contents.append(Constants.TR_END);
+            }
+
+            return getMessageFromHtmlTemplate(null,contents.toString());
+
+        }
+
+        return null;
 
 Review comment:
   "return content" is better here 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-dolphinscheduler] Technoboy- commented on a change in pull request #1713: Refactor alert template

Posted by GitBox <gi...@apache.org>.
Technoboy- commented on a change in pull request #1713: Refactor alert template
URL: https://github.com/apache/incubator-dolphinscheduler/pull/1713#discussion_r363077428
 
 

 ##########
 File path: dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/template/impl/DefaultHTMLTemplate.java
 ##########
 @@ -0,0 +1,163 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dolphinscheduler.alert.template.impl;
+
+import org.apache.dolphinscheduler.alert.exception.NotSupportOperatorException;
+import org.apache.dolphinscheduler.alert.template.AlertTemplate;
+import org.apache.dolphinscheduler.alert.utils.Constants;
+import org.apache.dolphinscheduler.alert.utils.JSONUtils;
+import org.apache.dolphinscheduler.alert.utils.MailUtils;
+import org.apache.dolphinscheduler.common.enums.ShowType;
+import org.apache.dolphinscheduler.common.utils.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.*;
+
+import static org.apache.dolphinscheduler.common.utils.Preconditions.*;
+
+/**
+ * the default html alert message template
+ */
+public class DefaultHTMLTemplate implements AlertTemplate {
+
+    public static final Logger logger = LoggerFactory.getLogger(DefaultHTMLTemplate.class);
+
+    @Override
+    public String getMessageFromTemplate(String content, ShowType showType,boolean showAll) {
+
+        switch (showType){
+            case TABLE:
+                return getTableTypeMessage(content,showAll);
+            case TEXT:
+                return getTextTypeMessage(content,showAll);
+            default:
+                logger.error("not support showType: {} in DefaultHTMLTemplate",showType);
+                throw new NotSupportOperatorException(String.format("not support showType: %s in DefaultHTMLTemplate",showType));
+        }
+    }
+
+    /**
+     * get alert message which type is TABLE
+     * @param content message content
+     * @param showAll weather to show all
+     * @return alert message
+     */
+    private String getTableTypeMessage(String content,boolean showAll){
+
+        if (StringUtils.isNotEmpty(content)){
+            List<LinkedHashMap> mapItemsList = JSONUtils.toList(content, LinkedHashMap.class);
+
+            if(!showAll && mapItemsList.size() > Constants.NUMBER_1000){
+                mapItemsList = mapItemsList.subList(0,Constants.NUMBER_1000);
+            }
+
+            StringBuilder contents = new StringBuilder(200);
+
+            boolean flag = true;
+
+            String title = "";
+            for (LinkedHashMap mapItems : mapItemsList){
+
+                Set<Map.Entry<String, Object>> entries = mapItems.entrySet();
+
+                Iterator<Map.Entry<String, Object>> iterator = entries.iterator();
+
+                StringBuilder t = new StringBuilder(Constants.TR);
+                StringBuilder cs = new StringBuilder(Constants.TR);
+                while (iterator.hasNext()){
+
+                    Map.Entry<String, Object> entry = iterator.next();
+                    t.append(Constants.TH).append(entry.getKey()).append(Constants.TH_END);
+                    cs.append(Constants.TD).append(String.valueOf(entry.getValue())).append(Constants.TD_END);
+
+                }
+                t.append(Constants.TR_END);
+                cs.append(Constants.TR_END);
+                if (flag){
+                    title = t.toString();
+                }
+                flag = false;
+                contents.append(cs);
+            }
+
+            return getMessageFromHtmlTemplate(title,contents.toString());
+        }
+
+        return null;
 
 Review comment:
   "return content" is better here . even though it's the same

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-dolphinscheduler] Technoboy- commented on a change in pull request #1713: Refactor alert template

Posted by GitBox <gi...@apache.org>.
Technoboy- commented on a change in pull request #1713: Refactor alert template
URL: https://github.com/apache/incubator-dolphinscheduler/pull/1713#discussion_r363077673
 
 

 ##########
 File path: dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/template/impl/DefaultHTMLTemplate.java
 ##########
 @@ -0,0 +1,163 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dolphinscheduler.alert.template.impl;
+
+import org.apache.dolphinscheduler.alert.exception.NotSupportOperatorException;
+import org.apache.dolphinscheduler.alert.template.AlertTemplate;
+import org.apache.dolphinscheduler.alert.utils.Constants;
+import org.apache.dolphinscheduler.alert.utils.JSONUtils;
+import org.apache.dolphinscheduler.alert.utils.MailUtils;
+import org.apache.dolphinscheduler.common.enums.ShowType;
+import org.apache.dolphinscheduler.common.utils.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.*;
+
+import static org.apache.dolphinscheduler.common.utils.Preconditions.*;
+
+/**
+ * the default html alert message template
+ */
+public class DefaultHTMLTemplate implements AlertTemplate {
+
+    public static final Logger logger = LoggerFactory.getLogger(DefaultHTMLTemplate.class);
+
+    @Override
+    public String getMessageFromTemplate(String content, ShowType showType,boolean showAll) {
+
+        switch (showType){
+            case TABLE:
+                return getTableTypeMessage(content,showAll);
+            case TEXT:
+                return getTextTypeMessage(content,showAll);
+            default:
+                logger.error("not support showType: {} in DefaultHTMLTemplate",showType);
 
 Review comment:
   no need to log, just throw exception is enough

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-dolphinscheduler] codecov-io edited a comment on issue #1713: Refactor alert template

Posted by GitBox <gi...@apache.org>.
codecov-io edited a comment on issue #1713: Refactor alert template
URL: https://github.com/apache/incubator-dolphinscheduler/pull/1713#issuecomment-570790461
 
 
   # [Codecov](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713?src=pr&el=h1) Report
   > Merging [#1713](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713?src=pr&el=desc) into [dev](https://codecov.io/gh/apache/incubator-dolphinscheduler/commit/1727a5357f7d56980d7676fddd7a93ac7a43018a?src=pr&el=desc) will **increase** coverage by `0.29%`.
   > The diff coverage is `1.66%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713/graphs/tree.svg?width=650&token=bv9iXXRLi9&height=150&src=pr)](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713?src=pr&el=tree)
   
   ```diff
   @@            Coverage Diff             @@
   ##              dev    #1713      +/-   ##
   ==========================================
   + Coverage   17.49%   17.78%   +0.29%     
   ==========================================
     Files         287      287              
     Lines       13907    13907              
     Branches     2277     2277              
   ==========================================
   + Hits         2433     2474      +41     
   + Misses      11201    11156      -45     
   - Partials      273      277       +4
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713?src=pr&el=tree) | Coverage Δ | |
   |---|---|---|
   | [.../dolphinscheduler/api/service/ExecutorService.java](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713/diff?src=pr&el=tree#diff-ZG9scGhpbnNjaGVkdWxlci1hcGkvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2RvbHBoaW5zY2hlZHVsZXIvYXBpL3NlcnZpY2UvRXhlY3V0b3JTZXJ2aWNlLmphdmE=) | `0% <ø> (ø)` | :arrow_up: |
   | [...phinscheduler/api/service/DataAnalysisService.java](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713/diff?src=pr&el=tree#diff-ZG9scGhpbnNjaGVkdWxlci1hcGkvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2RvbHBoaW5zY2hlZHVsZXIvYXBpL3NlcnZpY2UvRGF0YUFuYWx5c2lzU2VydmljZS5qYXZh) | `0% <ø> (ø)` | :arrow_up: |
   | [...che/dolphinscheduler/api/utils/ZooKeeperState.java](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713/diff?src=pr&el=tree#diff-ZG9scGhpbnNjaGVkdWxlci1hcGkvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2RvbHBoaW5zY2hlZHVsZXIvYXBpL3V0aWxzL1pvb0tlZXBlclN0YXRlLmphdmE=) | `0% <ø> (ø)` | :arrow_up: |
   | [...dolphinscheduler/api/service/SchedulerService.java](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713/diff?src=pr&el=tree#diff-ZG9scGhpbnNjaGVkdWxlci1hcGkvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2RvbHBoaW5zY2hlZHVsZXIvYXBpL3NlcnZpY2UvU2NoZWR1bGVyU2VydmljZS5qYXZh) | `0% <ø> (ø)` | :arrow_up: |
   | [...lphinscheduler/api/service/WorkerGroupService.java](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713/diff?src=pr&el=tree#diff-ZG9scGhpbnNjaGVkdWxlci1hcGkvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2RvbHBoaW5zY2hlZHVsZXIvYXBpL3NlcnZpY2UvV29ya2VyR3JvdXBTZXJ2aWNlLmphdmE=) | `78.33% <ø> (ø)` | :arrow_up: |
   | [...phinscheduler/api/service/TaskInstanceService.java](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713/diff?src=pr&el=tree#diff-ZG9scGhpbnNjaGVkdWxlci1hcGkvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2RvbHBoaW5zY2hlZHVsZXIvYXBpL3NlcnZpY2UvVGFza0luc3RhbmNlU2VydmljZS5qYXZh) | `0% <ø> (ø)` | :arrow_up: |
   | [...he/dolphinscheduler/api/service/TenantService.java](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713/diff?src=pr&el=tree#diff-ZG9scGhpbnNjaGVkdWxlci1hcGkvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2RvbHBoaW5zY2hlZHVsZXIvYXBpL3NlcnZpY2UvVGVuYW50U2VydmljZS5qYXZh) | `72.89% <ø> (ø)` | :arrow_up: |
   | [...he/dolphinscheduler/api/service/LoggerService.java](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713/diff?src=pr&el=tree#diff-ZG9scGhpbnNjaGVkdWxlci1hcGkvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2RvbHBoaW5zY2hlZHVsZXIvYXBpL3NlcnZpY2UvTG9nZ2VyU2VydmljZS5qYXZh) | `0% <ø> (ø)` | :arrow_up: |
   | [...pache/dolphinscheduler/common/utils/DateUtils.java](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713/diff?src=pr&el=tree#diff-ZG9scGhpbnNjaGVkdWxlci1jb21tb24vc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2RvbHBoaW5zY2hlZHVsZXIvY29tbW9uL3V0aWxzL0RhdGVVdGlscy5qYXZh) | `88.04% <ø> (ø)` | :arrow_up: |
   | [...che/dolphinscheduler/api/service/UsersService.java](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713/diff?src=pr&el=tree#diff-ZG9scGhpbnNjaGVkdWxlci1hcGkvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2RvbHBoaW5zY2hlZHVsZXIvYXBpL3NlcnZpY2UvVXNlcnNTZXJ2aWNlLmphdmE=) | `73.57% <ø> (ø)` | :arrow_up: |
   | ... and [30 more](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713/diff?src=pr&el=tree-more) | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713?src=pr&el=continue).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713?src=pr&el=footer). Last update [1727a53...0a6d8d3](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-dolphinscheduler] codecov-io edited a comment on issue #1713: Refactor alert template

Posted by GitBox <gi...@apache.org>.
codecov-io edited a comment on issue #1713: Refactor alert template
URL: https://github.com/apache/incubator-dolphinscheduler/pull/1713#issuecomment-570790461
 
 
   # [Codecov](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713?src=pr&el=h1) Report
   > Merging [#1713](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713?src=pr&el=desc) into [dev](https://codecov.io/gh/apache/incubator-dolphinscheduler/commit/4d1abb3fc7589b2cee846e806f59acc3a2375ecd?src=pr&el=desc) will **increase** coverage by `<.01%`.
   > The diff coverage is `0%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713/graphs/tree.svg?width=650&token=bv9iXXRLi9&height=150&src=pr)](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713?src=pr&el=tree)
   
   ```diff
   @@            Coverage Diff             @@
   ##              dev    #1713      +/-   ##
   ==========================================
   + Coverage   17.48%   17.49%   +<.01%     
   ==========================================
     Files         285      288       +3     
     Lines       13912    13908       -4     
     Branches     2274     2277       +3     
   ==========================================
     Hits         2433     2433              
   + Misses      11206    11202       -4     
     Partials      273      273
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713?src=pr&el=tree) | Coverage Δ | |
   |---|---|---|
   | [...duler/alert/template/impl/DefaultHTMLTemplate.java](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713/diff?src=pr&el=tree#diff-ZG9scGhpbnNjaGVkdWxlci1hbGVydC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvZG9scGhpbnNjaGVkdWxlci9hbGVydC90ZW1wbGF0ZS9pbXBsL0RlZmF1bHRIVE1MVGVtcGxhdGUuamF2YQ==) | `0% <0%> (ø)` | |
   | [...apache/dolphinscheduler/alert/utils/MailUtils.java](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713/diff?src=pr&el=tree#diff-ZG9scGhpbnNjaGVkdWxlci1hbGVydC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvZG9scGhpbnNjaGVkdWxlci9hbGVydC91dGlscy9NYWlsVXRpbHMuamF2YQ==) | `0% <0%> (ø)` | :arrow_up: |
   | [...dolphinscheduler/alert/template/AlertTemplate.java](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713/diff?src=pr&el=tree#diff-ZG9scGhpbnNjaGVkdWxlci1hbGVydC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvZG9scGhpbnNjaGVkdWxlci9hbGVydC90ZW1wbGF0ZS9BbGVydFRlbXBsYXRlLmphdmE=) | `0% <0%> (ø)` | |
   | [...scheduler/alert/template/AlertTemplateFactory.java](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713/diff?src=pr&el=tree#diff-ZG9scGhpbnNjaGVkdWxlci1hbGVydC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvZG9scGhpbnNjaGVkdWxlci9hbGVydC90ZW1wbGF0ZS9BbGVydFRlbXBsYXRlRmFjdG9yeS5qYXZh) | `0% <0%> (ø)` | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713?src=pr&el=continue).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713?src=pr&el=footer). Last update [4d1abb3...3ad4597](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-dolphinscheduler] qiaozhanwei merged pull request #1713: Refactor alert template

Posted by GitBox <gi...@apache.org>.
qiaozhanwei merged pull request #1713: Refactor alert template
URL: https://github.com/apache/incubator-dolphinscheduler/pull/1713
 
 
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-dolphinscheduler] codecov-io edited a comment on issue #1713: Refactor alert template

Posted by GitBox <gi...@apache.org>.
codecov-io edited a comment on issue #1713: Refactor alert template
URL: https://github.com/apache/incubator-dolphinscheduler/pull/1713#issuecomment-570790461
 
 
   # [Codecov](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713?src=pr&el=h1) Report
   > Merging [#1713](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713?src=pr&el=desc) into [dev](https://codecov.io/gh/apache/incubator-dolphinscheduler/commit/4d1abb3fc7589b2cee846e806f59acc3a2375ecd?src=pr&el=desc) will **increase** coverage by `<.01%`.
   > The diff coverage is `0%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713/graphs/tree.svg?width=650&token=bv9iXXRLi9&height=150&src=pr)](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713?src=pr&el=tree)
   
   ```diff
   @@            Coverage Diff             @@
   ##              dev    #1713      +/-   ##
   ==========================================
   + Coverage   17.48%   17.49%   +<.01%     
   ==========================================
     Files         285      287       +2     
     Lines       13912    13907       -5     
     Branches     2274     2277       +3     
   ==========================================
     Hits         2433     2433              
   + Misses      11206    11201       -5     
     Partials      273      273
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713?src=pr&el=tree) | Coverage Δ | |
   |---|---|---|
   | [...duler/alert/template/impl/DefaultHTMLTemplate.java](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713/diff?src=pr&el=tree#diff-ZG9scGhpbnNjaGVkdWxlci1hbGVydC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvZG9scGhpbnNjaGVkdWxlci9hbGVydC90ZW1wbGF0ZS9pbXBsL0RlZmF1bHRIVE1MVGVtcGxhdGUuamF2YQ==) | `0% <0%> (ø)` | |
   | [...apache/dolphinscheduler/alert/utils/MailUtils.java](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713/diff?src=pr&el=tree#diff-ZG9scGhpbnNjaGVkdWxlci1hbGVydC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvZG9scGhpbnNjaGVkdWxlci9hbGVydC91dGlscy9NYWlsVXRpbHMuamF2YQ==) | `0% <0%> (ø)` | :arrow_up: |
   | [...scheduler/alert/template/AlertTemplateFactory.java](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713/diff?src=pr&el=tree#diff-ZG9scGhpbnNjaGVkdWxlci1hbGVydC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvZG9scGhpbnNjaGVkdWxlci9hbGVydC90ZW1wbGF0ZS9BbGVydFRlbXBsYXRlRmFjdG9yeS5qYXZh) | `0% <0%> (ø)` | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713?src=pr&el=continue).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713?src=pr&el=footer). Last update [4d1abb3...1727a53](https://codecov.io/gh/apache/incubator-dolphinscheduler/pull/1713?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-dolphinscheduler] Technoboy- commented on a change in pull request #1713: Refactor alert template

Posted by GitBox <gi...@apache.org>.
Technoboy- commented on a change in pull request #1713: Refactor alert template
URL: https://github.com/apache/incubator-dolphinscheduler/pull/1713#discussion_r363077231
 
 

 ##########
 File path: dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/template/AlertTemplateFactory.java
 ##########
 @@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dolphinscheduler.alert.template;
+
+import org.apache.dolphinscheduler.alert.exception.NotSupportOperatorException;
+import org.apache.dolphinscheduler.alert.template.impl.DefaultHTMLTemplate;
+import org.apache.dolphinscheduler.alert.utils.Constants;
+import org.apache.dolphinscheduler.alert.utils.PropertyUtils;
+import org.apache.dolphinscheduler.common.utils.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * the alert template factory
+ */
+public class AlertTemplateFactory {
+
+    private static final Logger logger = LoggerFactory.getLogger(AlertTemplateFactory.class);
+
+    private static final String alertTemplate = PropertyUtils.getString(Constants.ALERT_TEMPLATE);
+
+    private AlertTemplateFactory(){}
+
+    /**
+     * get a template from alert.properties conf file
+     * @return a template, default is DefaultHTMLTemplate
+     * @throws NotSupportOperatorException
+     */
+    public static AlertTemplate getMessageTemplate() throws NotSupportOperatorException {
+
+        if(StringUtils.isEmpty(alertTemplate)){
+            return new DefaultHTMLTemplate();
+        }
+
+        switch (alertTemplate){
+            case "html":
+                return new DefaultHTMLTemplate();
+            default:
+                logger.error("not support alert template: {}",alertTemplate);
+                throw new NotSupportOperatorException(String.format("not support alert template: %s",alertTemplate));
 
 Review comment:
   using IllegalArgumentException

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-dolphinscheduler] Technoboy- commented on a change in pull request #1713: Refactor alert template

Posted by GitBox <gi...@apache.org>.
Technoboy- commented on a change in pull request #1713: Refactor alert template
URL: https://github.com/apache/incubator-dolphinscheduler/pull/1713#discussion_r363077428
 
 

 ##########
 File path: dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/template/impl/DefaultHTMLTemplate.java
 ##########
 @@ -0,0 +1,163 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dolphinscheduler.alert.template.impl;
+
+import org.apache.dolphinscheduler.alert.exception.NotSupportOperatorException;
+import org.apache.dolphinscheduler.alert.template.AlertTemplate;
+import org.apache.dolphinscheduler.alert.utils.Constants;
+import org.apache.dolphinscheduler.alert.utils.JSONUtils;
+import org.apache.dolphinscheduler.alert.utils.MailUtils;
+import org.apache.dolphinscheduler.common.enums.ShowType;
+import org.apache.dolphinscheduler.common.utils.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.*;
+
+import static org.apache.dolphinscheduler.common.utils.Preconditions.*;
+
+/**
+ * the default html alert message template
+ */
+public class DefaultHTMLTemplate implements AlertTemplate {
+
+    public static final Logger logger = LoggerFactory.getLogger(DefaultHTMLTemplate.class);
+
+    @Override
+    public String getMessageFromTemplate(String content, ShowType showType,boolean showAll) {
+
+        switch (showType){
+            case TABLE:
+                return getTableTypeMessage(content,showAll);
+            case TEXT:
+                return getTextTypeMessage(content,showAll);
+            default:
+                logger.error("not support showType: {} in DefaultHTMLTemplate",showType);
+                throw new NotSupportOperatorException(String.format("not support showType: %s in DefaultHTMLTemplate",showType));
+        }
+    }
+
+    /**
+     * get alert message which type is TABLE
+     * @param content message content
+     * @param showAll weather to show all
+     * @return alert message
+     */
+    private String getTableTypeMessage(String content,boolean showAll){
+
+        if (StringUtils.isNotEmpty(content)){
+            List<LinkedHashMap> mapItemsList = JSONUtils.toList(content, LinkedHashMap.class);
+
+            if(!showAll && mapItemsList.size() > Constants.NUMBER_1000){
+                mapItemsList = mapItemsList.subList(0,Constants.NUMBER_1000);
+            }
+
+            StringBuilder contents = new StringBuilder(200);
+
+            boolean flag = true;
+
+            String title = "";
+            for (LinkedHashMap mapItems : mapItemsList){
+
+                Set<Map.Entry<String, Object>> entries = mapItems.entrySet();
+
+                Iterator<Map.Entry<String, Object>> iterator = entries.iterator();
+
+                StringBuilder t = new StringBuilder(Constants.TR);
+                StringBuilder cs = new StringBuilder(Constants.TR);
+                while (iterator.hasNext()){
+
+                    Map.Entry<String, Object> entry = iterator.next();
+                    t.append(Constants.TH).append(entry.getKey()).append(Constants.TH_END);
+                    cs.append(Constants.TD).append(String.valueOf(entry.getValue())).append(Constants.TD_END);
+
+                }
+                t.append(Constants.TR_END);
+                cs.append(Constants.TR_END);
+                if (flag){
+                    title = t.toString();
+                }
+                flag = false;
+                contents.append(cs);
+            }
+
+            return getMessageFromHtmlTemplate(title,contents.toString());
+        }
+
+        return null;
 
 Review comment:
   "return content" is better here . even so it's the same

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services