减少不必要的依赖项

This commit is contained in:
椰子 2022-08-21 21:36:44 +08:00
parent 605fee50dd
commit 3e0ac9fc2e
7 changed files with 63 additions and 44 deletions

View File

@ -0,0 +1,33 @@
package com.cicdi.notify.util;
/**
* @author Yaser Hsueh
*/
public abstract class StringUtils {
public static boolean isEmpty(Object str) {
return (str == null || "".equals(str));
}
public static boolean hasLength(CharSequence str) {
return (str != null && str.length() > 0);
}
public static boolean hasLength(String str) {
return (str != null && !str.isEmpty());
}
public static boolean isBlank(String str) {
int strLen;
if (str == null || (strLen = str.length()) == 0) {
return true;
}
for (int i = 0; i < strLen; i++) {
if ((!Character.isWhitespace(str.charAt(i)))) {
return false;
}
}
return true;
}
}

View File

@ -29,12 +29,6 @@
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<scope>provided</scope>
</dependency>
<dependency> <dependency>
<groupId>com.alibaba</groupId> <groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId> <artifactId>fastjson</artifactId>

View File

@ -6,6 +6,7 @@ import com.cicdi.notify.email.EmailProvider;
import com.cicdi.notify.email.EmailTemplate; import com.cicdi.notify.email.EmailTemplate;
import com.cicdi.notify.email.EmailTemplateParsed; import com.cicdi.notify.email.EmailTemplateParsed;
import com.cicdi.notify.util.ExpressionUtils; import com.cicdi.notify.util.ExpressionUtils;
import com.cicdi.notify.util.StringUtils;
import org.apache.http.HttpHeaders; import org.apache.http.HttpHeaders;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient; import org.apache.http.client.HttpClient;
@ -19,7 +20,6 @@ import org.springframework.core.io.InputStreamSource;
import org.springframework.mail.javamail.JavaMailSender; import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl; import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper; import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.util.StringUtils;
import javax.mail.MessagingException; import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage; import javax.mail.internet.MimeMessage;

View File

@ -23,31 +23,28 @@ public class DefaultEmailTest {
@Test @Test
public void testSend() { public void testSend() {
// 通知器配置管理器 // 通知器配置管理器
NotifyConfigManager notifyConfigManager = new NotifyConfigManager() { NotifyConfigManager notifyConfigManager = (notifyType, configId) -> {
@Override NotifierProperties notifierProperties = new NotifierProperties();
public NotifierProperties getNotifyConfig(NotifyType notifyType, String configId) { notifierProperties.setType(DefaultNotifyType.email.getId());
NotifierProperties notifierProperties = new NotifierProperties(); notifierProperties.setProvider(EmailProvider.embedded.getId());
notifierProperties.setType(DefaultNotifyType.email.getId()); notifierProperties.setId("12");
notifierProperties.setProvider(EmailProvider.embedded.getId());
notifierProperties.setId("12");
Map<String, Object> config = new HashMap<>(); Map<String, Object> config = new HashMap<>();
config.put("host", "nas.xueye.io"); config.put("host", "nas.xueye.io");
config.put("port", 587); config.put("port", 587);
config.put("username", "xueye"); config.put("username", "xueye");
config.put("password", "snow@PX1314"); config.put("password", "snow@PX1314");
config.put("sender", "master@simaek.com"); config.put("sender", "master@simaek.com");
Map<String, Object> p1 = new HashMap<>(); Map<String, Object> p1 = new HashMap<>();
p1.put("name", "mail.smtp.starttls.enable"); p1.put("name", "mail.smtp.starttls.enable");
p1.put("value", "true"); p1.put("value", "true");
Map<String, Object> p2 = new HashMap<>(); Map<String, Object> p2 = new HashMap<>();
p2.put("name", "mail.smtp.auth"); p2.put("name", "mail.smtp.auth");
p2.put("value", "true"); p2.put("value", "true");
config.put("properties", Arrays.asList(p1, p2)); config.put("properties", Arrays.asList(p1, p2));
notifierProperties.setConfiguration(config); notifierProperties.setConfiguration(config);
return notifierProperties; return notifierProperties;
}
}; };
// 模板管理器 // 模板管理器

View File

@ -33,11 +33,6 @@
<artifactId>httpclient</artifactId> <artifactId>httpclient</artifactId>
</dependency> </dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -2,7 +2,7 @@ package com.cicdi.notify.wechat.corp;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.cicdi.notify.template.Template; import com.cicdi.notify.template.Template;
import org.apache.commons.lang.StringUtils; import com.cicdi.notify.util.StringUtils;
import java.util.Collections; import java.util.Collections;
import java.util.Map; import java.util.Map;
@ -68,10 +68,10 @@ public class WechatCorpTemplate implements Template {
json.put("msgtype", "text"); json.put("msgtype", "text");
json.put("text", Collections.singletonMap("content", message)); json.put("text", Collections.singletonMap("content", message));
if (StringUtils.isNotBlank(toUser)) { if (!StringUtils.isBlank(toUser)) {
json.put("touser", this.createUserIdList(context)); json.put("touser", this.createUserIdList(context));
} }
if (StringUtils.isNotBlank(toParty)) { if (!StringUtils.isBlank(toParty)) {
json.put("toparty", this.createDepartmentIdList(context)); json.put("toparty", this.createDepartmentIdList(context));
} }

12
pom.xml
View File

@ -76,12 +76,6 @@
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency> <dependency>
<groupId>org.apache.httpcomponents</groupId> <groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId> <artifactId>httpclient</artifactId>
@ -118,6 +112,12 @@
<version>1.6.7</version> <version>1.6.7</version>
</dependency> </dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.9.3</version>
</dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>