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. 8
      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 * Enterprise WeChat Manager
*/ */
public class EnterpriseWeChatManager { 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 * Enterprise We Chat send
* @param alert the alert * @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()); users = alertDao.listUserByAlertgroupId(alert.getAlertGroupId());
// receiving group list // receiving group list
List<String> receviersList = new ArrayList<String>(); List<String> receviersList = new ArrayList<>();
for(User user:users){ for(User user:users){
receviersList.add(user.getEmail()); receviersList.add(user.getEmail());
} }
@ -77,7 +77,7 @@ public class AlertSender{
} }
// copy list // copy list
List<String> receviersCcList = new ArrayList<String>(); List<String> receviersCcList = new ArrayList<>();
// Custom Copier // 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 * 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){ default String getMessageFromTemplate(String content,ShowType showType){
return getMessageFromTemplate(content,showType,true); return getMessageFromTemplate(content,showType,true);

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

@ -201,13 +201,13 @@ public class EnterpriseWeChatUtils {
public static String markdownTable(String title,String content){ public static String markdownTable(String title,String content){
List<LinkedHashMap> mapItemsList = JSONUtils.toList(content, LinkedHashMap.class); List<LinkedHashMap> mapItemsList = JSONUtils.toList(content, LinkedHashMap.class);
StringBuilder contents = new StringBuilder(200); StringBuilder contents = new StringBuilder(200);
for (LinkedHashMap mapItems : mapItemsList){
if (null != mapItemsList) {
for (LinkedHashMap mapItems : mapItemsList){
Set<Map.Entry<String, String>> entries = mapItems.entrySet(); Set<Map.Entry<String, String>> entries = mapItems.entrySet();
Iterator<Map.Entry<String, String>> iterator = entries.iterator(); Iterator<Map.Entry<String, String>> iterator = entries.iterator();
StringBuilder t = new StringBuilder(String.format("`%s`%s",title,Constants.MARKDOWN_ENTER)); StringBuilder t = new StringBuilder(String.format("`%s`%s",title,Constants.MARKDOWN_ENTER));
while (iterator.hasNext()){ while (iterator.hasNext()){
Map.Entry<String, String> entry = iterator.next(); Map.Entry<String, String> entry = iterator.next();
@ -215,9 +215,9 @@ public class EnterpriseWeChatUtils {
t.append(entry.getKey()).append(":").append(entry.getValue()); t.append(entry.getKey()).append(":").append(entry.getValue());
t.append(Constants.MARKDOWN_ENTER); t.append(Constants.MARKDOWN_ENTER);
} }
contents.append(t); contents.append(t);
} }
}
return contents.toString(); 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; return retMap;
} }
receivers.removeIf((from) -> (StringUtils.isEmpty(from))); receivers.removeIf(StringUtils::isEmpty);
if (showType == ShowType.TABLE || showType == ShowType.TEXT){ if (showType == ShowType.TABLE || showType == ShowType.TEXT){
// send email // send email
@ -185,7 +185,7 @@ public class MailUtils {
/** /**
* get MimeMessage * get MimeMessage
* @param receivers * @param receivers receivers
* @return the MimeMessage * @return the MimeMessage
* @throws MessagingException * @throws MessagingException
*/ */
@ -229,8 +229,7 @@ public class MailUtils {
} }
}; };
Session session = Session.getInstance(props, auth); return Session.getInstance(props, auth);
return session;
} }
/** /**

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

@ -205,8 +205,7 @@ public class PropertyUtils {
return null; return null;
} }
try { try {
String[] propertyArray = value.split(splitStr); return value.split(splitStr);
return propertyArray;
} catch (PatternSyntaxException e) { } catch (PatternSyntaxException e) {
logger.info(e.getMessage(),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)); Files.copy(file.getInputStream(), Paths.get(destFilename));
} catch (IOException e) { } 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