Browse Source

add null check in markdownTable & modify EnterpriseWeChatManager logger class (#1809)

pull/2/head
Yelli 5 years ago committed by dailidong
parent
commit
8399ab4718
  1. 2
      dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/manager/EnterpriseWeChatManager.java
  2. 4
      dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/runner/AlertSender.java
  3. 3
      dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/template/AlertTemplate.java
  4. 24
      dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/utils/EnterpriseWeChatUtils.java
  5. 7
      dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/utils/MailUtils.java
  6. 3
      dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/utils/PropertyUtils.java
  7. 2
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/utils/FileUtils.java

2
dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/manager/EnterpriseWeChatManager.java

@ -32,7 +32,7 @@ import java.util.Map;
* Enterprise WeChat Manager
*/
public class EnterpriseWeChatManager {
private static final Logger logger = LoggerFactory.getLogger(MsgManager.class);
private static final Logger logger = LoggerFactory.getLogger(EnterpriseWeChatManager.class);
/**
* Enterprise We Chat send
* @param alert the alert

4
dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/runner/AlertSender.java

@ -65,7 +65,7 @@ public class AlertSender{
users = alertDao.listUserByAlertgroupId(alert.getAlertGroupId());
// receiving group list
List<String> receviersList = new ArrayList<String>();
List<String> receviersList = new ArrayList<>();
for(User user:users){
receviersList.add(user.getEmail());
}
@ -77,7 +77,7 @@ public class AlertSender{
}
// copy list
List<String> receviersCcList = new ArrayList<String>();
List<String> receviersCcList = new ArrayList<>();
// Custom Copier

3
dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/template/AlertTemplate.java

@ -34,6 +34,9 @@ public interface AlertTemplate {
/**
* default showAll is true
* @param content alert message content
* @param showType show type
* @return a message from a specified alert template
*/
default String getMessageFromTemplate(String content,ShowType showType){
return getMessageFromTemplate(content,showType,true);

24
dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/utils/EnterpriseWeChatUtils.java

@ -201,22 +201,22 @@ public class EnterpriseWeChatUtils {
public static String markdownTable(String title,String content){
List<LinkedHashMap> mapItemsList = JSONUtils.toList(content, LinkedHashMap.class);
StringBuilder contents = new StringBuilder(200);
for (LinkedHashMap mapItems : mapItemsList){
Set<Map.Entry<String, String>> entries = mapItems.entrySet();
if (null != mapItemsList) {
for (LinkedHashMap mapItems : mapItemsList){
Set<Map.Entry<String, String>> entries = mapItems.entrySet();
Iterator<Map.Entry<String, String>> iterator = entries.iterator();
StringBuilder t = new StringBuilder(String.format("`%s`%s",title,Constants.MARKDOWN_ENTER));
Iterator<Map.Entry<String, String>> iterator = entries.iterator();
while (iterator.hasNext()){
StringBuilder t = new StringBuilder(String.format("`%s`%s",title,Constants.MARKDOWN_ENTER));
while (iterator.hasNext()){
Map.Entry<String, String> entry = iterator.next();
t.append(Constants.MARKDOWN_QUOTE);
t.append(entry.getKey()).append(":").append(entry.getValue());
t.append(Constants.MARKDOWN_ENTER);
Map.Entry<String, String> entry = iterator.next();
t.append(Constants.MARKDOWN_QUOTE);
t.append(entry.getKey()).append(":").append(entry.getValue());
t.append(Constants.MARKDOWN_ENTER);
}
contents.append(t);
}
contents.append(t);
}
return contents.toString();
}

7
dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/utils/MailUtils.java

@ -96,7 +96,7 @@ public class MailUtils {
return retMap;
}
receivers.removeIf((from) -> (StringUtils.isEmpty(from)));
receivers.removeIf(StringUtils::isEmpty);
if (showType == ShowType.TABLE || showType == ShowType.TEXT){
// send email
@ -185,7 +185,7 @@ public class MailUtils {
/**
* get MimeMessage
* @param receivers
* @param receivers receivers
* @return the MimeMessage
* @throws MessagingException
*/
@ -229,8 +229,7 @@ public class MailUtils {
}
};
Session session = Session.getInstance(props, auth);
return session;
return Session.getInstance(props, auth);
}
/**

3
dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/utils/PropertyUtils.java

@ -205,8 +205,7 @@ public class PropertyUtils {
return null;
}
try {
String[] propertyArray = value.split(splitStr);
return propertyArray;
return value.split(splitStr);
} catch (PatternSyntaxException e) {
logger.info(e.getMessage(),e);
}

2
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/utils/FileUtils.java

@ -57,7 +57,7 @@ public class FileUtils {
Files.copy(file.getInputStream(), Paths.get(destFilename));
} catch (IOException e) {
logger.error(String.format("failed to copy file , {} is empty file", file.getOriginalFilename()), e);
logger.error("failed to copy file , {} is empty file", file.getOriginalFilename(), e);
}
}

Loading…
Cancel
Save