FIX ISSUE#760 (#790)

* FIX ISSUE#760

* dozer强依赖, 改为provided

* 消除无用依赖

* 依赖删除

Co-authored-by: yanrongzhen <bruceyan@didiglobal.com>
pull/791/head
严荣振 2 years ago committed by GitHub
parent b41b3117b9
commit e5c144d148
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -29,6 +29,8 @@ public class StringUtil {
public static final char UNDERLINE = '_';
public static final String[] EMPTY_ARRAY = new String[0];
/**
* Returns the given string if it is nonempty; {@code null} otherwise.
*
@ -52,9 +54,11 @@ public class StringUtil {
/**
* Returns {@code true} if the given string is null or is the empty string.
*
* this method has been deprecated, use isEmpty() instead.
* @param str
* @return
*/
@Deprecated
public static boolean isNullOrEmpty(String str) {
return str == null || str.isEmpty();
}
@ -288,6 +292,33 @@ public class StringUtil {
.replaceAll(Matcher.quoteReplacement(replaceStr));
}
/**
* <p>Splits the provided text into an array, separators specified.
*
* <pre>
* StringUtils.split(null, *) = null
* StringUtils.split("", *) = []
* StringUtils.split("abc def", null) = ["abc", "def"]
* StringUtils.split("abc def", " ") = ["abc", "def"]
* StringUtils.split("ab:cd:ef", ":") = ["ab", "cd", "ef"]
* </pre>
* @param str the String to parse, may be null
* @param separatorChars the characters used as the delimiters,
* @return an array of parsed Strings
*/
public static String[] split(final String str, final String separatorChars) {
if (str == null) {
return null;
}
if (isBlank(str)) {
return EMPTY_ARRAY;
}
if (isBlank(separatorChars)) {
return str.split(" ");
}
return str.split(separatorChars);
}
/**
* Tests if this string starts with the specified prefix.
*

@ -20,8 +20,58 @@ package cn.hippo4j.common.toolkit;
import org.junit.Test;
import org.junit.Assert;
import java.util.Arrays;
import java.util.Optional;
public class StringUtilTest {
@Test
public void replace() {
String url = "http://localhost:8088/hippo4j_manager?";
String replace = StringUtil.replace(url, "/hippo4j_manager?", "?");
Assert.assertEquals(replace, "http://localhost:8088?");
}
/**
* <p>Splits the provided text into an array, separators specified.
*
* <pre>
* StringUtils.split(null, *) = null
* StringUtils.split("", *) = []
* StringUtils.split("abc def", null) = ["abc", "def"]
* StringUtils.split("abc def", " ") = ["abc", "def"]
* StringUtils.split("ab:cd:ef", ":") = ["ab", "cd", "ef"]
* </pre>
*/
@Test
public void split() {
String str1 = null;
String separator1 = "*";
String[] res1 = StringUtil.split(str1, separator1);
assert res1 == null;
String str2 = "";
String separator2 = "*";
String[] res2 = StringUtil.split(str2, separator2);
Assert.assertArrayEquals(res2, new String[0]);
String str3 = "abc def";
String separator3 = null;
String[] res3 = StringUtil.split(str3, separator3);
Assert.assertArrayEquals(res3, new String[]{"abc", "def"});
String str4 = "abc def";
String separator4 = " ";
String[] res4 = StringUtil.split(str4, separator4);
Assert.assertArrayEquals(res4, new String[]{"abc", "def"});
String str5 = "ab:cd:ef";
String separator5 = ":";
String[] res5 = StringUtil.split(str5, separator5);
Assert.assertArrayEquals(res5, new String[]{"ab", "cd", "ef"});
}
@Test
public void assertIsEmpty() {
String string = "";
@ -49,7 +99,7 @@ public class StringUtilTest {
@Test
public void isNullOrEmpty() {
String string = "null";
Assert.assertFalse(StringUtil.isNullOrEmpty(string));
Assert.assertFalse(StringUtil.isEmpty(string));
}
@Test

@ -19,6 +19,7 @@ package cn.hippo4j.config.service.biz.impl;
import cn.hippo4j.common.toolkit.Assert;
import cn.hippo4j.common.enums.DelEnum;
import cn.hippo4j.common.toolkit.StringUtil;
import cn.hippo4j.config.mapper.ItemInfoMapper;
import cn.hippo4j.config.model.ItemInfo;
import cn.hippo4j.config.model.biz.item.ItemQueryReqDTO;
@ -36,7 +37,6 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.util.List;
@ -55,10 +55,10 @@ public class ItemServiceImpl implements ItemService {
@Override
public IPage<ItemRespDTO> queryItemPage(ItemQueryReqDTO reqDTO) {
LambdaQueryWrapper<ItemInfo> wrapper = Wrappers.lambdaQuery(ItemInfo.class)
.eq(!StringUtils.isEmpty(reqDTO.getItemId()), ItemInfo::getItemId, reqDTO.getItemId())
.eq(!StringUtils.isEmpty(reqDTO.getItemName()), ItemInfo::getItemName, reqDTO.getItemName())
.eq(!StringUtils.isEmpty(reqDTO.getTenantId()), ItemInfo::getTenantId, reqDTO.getTenantId())
.eq(!StringUtils.isEmpty(reqDTO.getOwner()), ItemInfo::getOwner, reqDTO.getOwner())
.eq(StringUtil.isNotEmpty(reqDTO.getItemId()), ItemInfo::getItemId, reqDTO.getItemId())
.eq(StringUtil.isNotEmpty(reqDTO.getItemName()), ItemInfo::getItemName, reqDTO.getItemName())
.eq(StringUtil.isNotEmpty(reqDTO.getTenantId()), ItemInfo::getTenantId, reqDTO.getTenantId())
.eq(StringUtil.isNotEmpty(reqDTO.getOwner()), ItemInfo::getOwner, reqDTO.getOwner())
.orderByDesc(reqDTO.getDesc() != null, ItemInfo::getGmtCreate);
Page<ItemInfo> resultPage = itemInfoMapper.selectPage(reqDTO, wrapper);
return resultPage.convert(each -> BeanUtil.convert(each, ItemRespDTO.class));
@ -78,8 +78,8 @@ public class ItemServiceImpl implements ItemService {
@Override
public List<ItemRespDTO> queryItem(ItemQueryReqDTO reqDTO) {
LambdaQueryWrapper<ItemInfo> wrapper = Wrappers.lambdaQuery(ItemInfo.class)
.eq(!StringUtils.isEmpty(reqDTO.getItemId()), ItemInfo::getItemId, reqDTO.getItemId())
.eq(!StringUtils.isEmpty(reqDTO.getTenantId()), ItemInfo::getTenantId, reqDTO.getTenantId());
.eq(StringUtil.isNotEmpty(reqDTO.getItemId()), ItemInfo::getItemId, reqDTO.getItemId())
.eq(StringUtil.isNotEmpty(reqDTO.getTenantId()), ItemInfo::getTenantId, reqDTO.getTenantId());
List<ItemInfo> itemInfos = itemInfoMapper.selectList(wrapper);
return BeanUtil.convert(itemInfos, ItemRespDTO.class);
}

@ -19,6 +19,7 @@ package cn.hippo4j.config.service.biz.impl;
import cn.hippo4j.common.enums.DelEnum;
import cn.hippo4j.common.toolkit.Assert;
import cn.hippo4j.common.toolkit.StringUtil;
import cn.hippo4j.config.mapper.TenantInfoMapper;
import cn.hippo4j.config.model.TenantInfo;
import cn.hippo4j.config.model.biz.item.ItemQueryReqDTO;
@ -37,7 +38,6 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.util.List;
@ -70,9 +70,9 @@ public class TenantServiceImpl implements TenantService {
@Override
public IPage<TenantRespDTO> queryTenantPage(TenantQueryReqDTO reqDTO) {
LambdaQueryWrapper<TenantInfo> wrapper = Wrappers.lambdaQuery(TenantInfo.class)
.eq(!StringUtils.isEmpty(reqDTO.getTenantId()), TenantInfo::getTenantId, reqDTO.getTenantId())
.eq(!StringUtils.isEmpty(reqDTO.getTenantName()), TenantInfo::getTenantName, reqDTO.getTenantName())
.eq(!StringUtils.isEmpty(reqDTO.getOwner()), TenantInfo::getOwner, reqDTO.getOwner())
.eq(StringUtil.isNotEmpty(reqDTO.getTenantId()), TenantInfo::getTenantId, reqDTO.getTenantId())
.eq(StringUtil.isNotEmpty(reqDTO.getTenantName()), TenantInfo::getTenantName, reqDTO.getTenantName())
.eq(StringUtil.isNotEmpty(reqDTO.getOwner()), TenantInfo::getOwner, reqDTO.getOwner())
.orderByDesc(reqDTO.getDesc() != null, TenantInfo::getGmtCreate);
Page resultPage = tenantInfoMapper.selectPage(reqDTO, wrapper);
return resultPage.convert(each -> BeanUtil.convert(each, TenantRespDTO.class));

@ -17,7 +17,7 @@
package cn.hippo4j.config.toolkit;
import org.apache.commons.lang3.StringUtils;
import cn.hippo4j.common.toolkit.StringUtil;
import java.nio.file.Paths;
import java.util.Objects;
@ -41,9 +41,9 @@ public class EnvUtil {
* @return
*/
public static String getHippo4JHome() {
if (StringUtils.isBlank(HIPPO4J_HOME_PATH)) {
if (StringUtil.isBlank(HIPPO4J_HOME_PATH)) {
String hippo4jHome = System.getProperty(HIPPO4J_HOME_KEY);
if (StringUtils.isBlank(hippo4jHome)) {
if (StringUtil.isBlank(hippo4jHome)) {
hippo4jHome = Paths.get(System.getProperty("user.home"), "hippo4j").toString();
}
return hippo4jHome;

@ -19,6 +19,7 @@ package cn.hippo4j.config.toolkit;
import cn.hippo4j.common.toolkit.GroupKey;
import cn.hippo4j.common.toolkit.Md5Util;
import cn.hippo4j.common.toolkit.StringUtil;
import cn.hippo4j.config.service.ConfigCacheService;
import cn.hippo4j.config.model.ConfigAllInfo;
import org.springframework.util.StringUtils;
@ -140,7 +141,7 @@ public class Md5ConfigUtil {
sb.append(dataIdGroupId[1]);
// if have tenant, then set it
if (dataIdGroupId.length == 4) {
if (org.apache.commons.lang3.StringUtils.isNotBlank(dataIdGroupId[2])) {
if (StringUtil.isNotBlank(dataIdGroupId[2])) {
sb.append(WORD_SEPARATOR);
sb.append(dataIdGroupId[2]);
}

@ -57,7 +57,7 @@ public class EsClientHolder {
userName = environment.getProperty("es.thread-pool-state.userName");
password = environment.getProperty("es.thread-pool-state.password");
List<HttpHost> hosts = parseHosts();
if (StringUtil.isNullOrEmpty(userName) || StringUtil.isNullOrEmpty(password)) {
if (StringUtil.isEmpty(userName) || StringUtil.isEmpty(password)) {
client = new RestHighLevelClient(RestClient.builder(hosts.toArray(new HttpHost[]{})));
} else {
client = new RestHighLevelClient(RestClient.builder(hosts.toArray(new HttpHost[]{}))
@ -74,7 +74,7 @@ public class EsClientHolder {
}
private static BasicCredentialsProvider getCredentialsProvider() {
if (!StringUtil.isNullOrEmpty(userName) && !StringUtil.isNullOrEmpty(password)) {
if (StringUtil.isNotEmpty(userName) && StringUtil.isNotEmpty(password)) {
final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY,
new UsernamePasswordCredentials(userName, password));

@ -17,9 +17,9 @@
package cn.hippo4j.server.init;
import cn.hippo4j.common.toolkit.StringUtil;
import cn.hippo4j.server.config.DataBaseProperties;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.jdbc.ScriptRunner;
import org.springframework.beans.BeansException;
@ -68,7 +68,7 @@ public class LocalDataSourceLoader implements InstantiationAwareBeanPostProcesso
// because the hippo4j database does not need to be specified when executing the SQL file,
// otherwise the hippo4j database will be disconnected when the hippo4j database does not exist
if (Objects.equals(dataBaseProperties.getDialect(), "mysql")) {
jdbcUrl = StringUtils.replace(properties.getUrl(), "/hippo4j_manager?", "?");
jdbcUrl = StringUtil.replace(properties.getUrl(), "/hippo4j_manager?", "?");
}
Connection connection = DriverManager.getConnection(jdbcUrl, properties.getUsername(), properties.getPassword());
// TODO Compatible with h2 to execute `INSERT IGNORE INTO` statement error
@ -103,7 +103,7 @@ public class LocalDataSourceLoader implements InstantiationAwareBeanPostProcesso
runner.setLogWriter(null);
runner.setAutoCommit(true);
Resources.setCharset(StandardCharsets.UTF_8);
String[] initScripts = StringUtils.split(script, ";");
String[] initScripts = StringUtil.split(script, ";");
for (String sqlScript : initScripts) {
if (sqlScript.startsWith(PRE_FIX)) {
String sqlFile = sqlScript.substring(PRE_FIX.length());

@ -57,7 +57,6 @@
<dozer.version>6.5.0</dozer.version>
<caffeine.version>2.9.3</caffeine.version>
<okhttp3.version>3.12.0</okhttp3.version>
<commons-lang3.version>3.12.0</commons-lang3.version>
<hibernate-validator.version>6.1.5.Final</hibernate-validator.version>
<transmittable-thread-local.version>2.12.1</transmittable-thread-local.version>
<jjwt.version>0.9.0</jjwt.version>
@ -117,11 +116,6 @@
<artifactId>okhttp</artifactId>
<version>${okhttp3.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency>
<dependency>
<groupId>cn.hippo4j</groupId>
<artifactId>hippo4j-message</artifactId>

Loading…
Cancel
Save