提交 8399ab47 编写于 作者: Y Yelli 提交者: dailidong

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

上级 289ae6ac
...@@ -32,7 +32,7 @@ import java.util.Map; ...@@ -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
......
...@@ -65,7 +65,7 @@ public class AlertSender{ ...@@ -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{ ...@@ -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
......
...@@ -34,6 +34,9 @@ public interface AlertTemplate { ...@@ -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);
......
...@@ -201,22 +201,22 @@ public class EnterpriseWeChatUtils { ...@@ -201,22 +201,22 @@ 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){
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)); Map.Entry<String, String> entry = iterator.next();
while (iterator.hasNext()){ t.append(Constants.MARKDOWN_QUOTE);
t.append(entry.getKey()).append(":").append(entry.getValue());
Map.Entry<String, String> entry = iterator.next(); t.append(Constants.MARKDOWN_ENTER);
t.append(Constants.MARKDOWN_QUOTE); }
t.append(entry.getKey()).append(":").append(entry.getValue()); contents.append(t);
t.append(Constants.MARKDOWN_ENTER);
} }
contents.append(t);
} }
return contents.toString(); return contents.toString();
} }
......
...@@ -96,7 +96,7 @@ public class MailUtils { ...@@ -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 { ...@@ -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 { ...@@ -229,8 +229,7 @@ public class MailUtils {
} }
}; };
Session session = Session.getInstance(props, auth); return Session.getInstance(props, auth);
return session;
} }
/** /**
......
...@@ -205,8 +205,7 @@ public class PropertyUtils { ...@@ -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);
} }
......
...@@ -57,7 +57,7 @@ public class FileUtils { ...@@ -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);
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册