Skip to content

Commit

Permalink
[improve] replace 'StringUtils.hasText'.
Browse files Browse the repository at this point in the history
  • Loading branch information
MRgenial committed Aug 19, 2024
1 parent fd73164 commit 82ca308
Show file tree
Hide file tree
Showing 15 changed files with 48 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.hertzbeat.common.constants.CommonConstants;
import org.apache.hertzbeat.common.entity.manager.Monitor;
import org.apache.hertzbeat.common.entity.manager.StatusPageComponent;
Expand All @@ -51,7 +52,6 @@
import org.apache.hertzbeat.manager.dao.StatusPageOrgDao;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

/**
* calculate component status for status page
Expand Down Expand Up @@ -115,7 +115,7 @@ private void startCalculate() {
ListJoin<Monitor, Tag> tagJoin = root
.join(root.getModel()
.getList("tags", Tag.class), JoinType.LEFT);
if (StringUtils.hasText(tagItem.getValue())) {
if (StringUtils.isNotBlank(tagItem.getValue())) {
andList.add(criteriaBuilder.equal(tagJoin.get("name"), tagItem.getName()));
andList.add(criteriaBuilder.equal(tagJoin.get("tagValue"), tagItem.getValue()));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Locale;
import java.util.Random;
import java.util.TimeZone;
import org.apache.commons.lang3.StringUtils;
import org.apache.hertzbeat.common.constants.CommonConstants;
import org.apache.hertzbeat.common.entity.manager.GeneralConfig;
import org.apache.hertzbeat.common.util.TimeZoneUtil;
Expand All @@ -40,7 +41,6 @@
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

/**
* Common CommandLineRunner class
Expand Down Expand Up @@ -106,7 +106,7 @@ public void run(String... args) throws Exception {
if (DEFAULT_JWT_SECRET.equals(currentJwtSecret)) {
// use the random jwt secret
SystemSecret systemSecret = systemSecretService.getConfig();
if (systemSecret == null || !StringUtils.hasText(systemSecret.getJwtSecret())) {
if (systemSecret == null || StringUtils.isBlank(systemSecret.getJwtSecret())) {
char[] chars = DEFAULT_JWT_SECRET.toCharArray();
Random rand = new Random();
for (int i = 0; i < chars.length; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.Map;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.hertzbeat.common.constants.CommonConstants;
import org.apache.hertzbeat.common.entity.dto.CollectorInfo;
import org.apache.hertzbeat.common.entity.job.Configmap;
Expand All @@ -40,7 +41,6 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.util.StringUtils;

/**
* scheduler init
Expand Down Expand Up @@ -110,7 +110,7 @@ public void run(String... args) throws Exception {
.map(param -> new Configmap(param.getField(), param.getParamValue(),
param.getType())).collect(Collectors.toList());
List<ParamDefine> paramDefaultValue = appDefine.getParams().stream()
.filter(item -> StringUtils.hasText(item.getDefaultValue()))
.filter(item -> StringUtils.isNotBlank(item.getDefaultValue()))
.toList();
paramDefaultValue.forEach(defaultVar -> {
if (configmaps.stream().noneMatch(item -> item.getKey().equals(defaultVar.getField()))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
import io.netty.channel.ChannelHandlerContext;
import java.net.InetSocketAddress;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.hertzbeat.common.entity.dto.CollectorInfo;
import org.apache.hertzbeat.common.entity.message.ClusterMsg;
import org.apache.hertzbeat.common.util.JsonUtil;
import org.apache.hertzbeat.manager.scheduler.netty.ManageServer;
import org.apache.hertzbeat.remoting.netty.NettyRemotingProcessor;
import org.springframework.util.StringUtils;

/**
* handle collector online message
Expand All @@ -43,7 +43,7 @@ public ClusterMsg.Message handle(ChannelHandlerContext ctx, ClusterMsg.Message m
String collector = message.getIdentity();
log.info("the collector {} actively requests to go online.", collector);
CollectorInfo collectorInfo = JsonUtil.fromJson(message.getMsg(), CollectorInfo.class);
if (collectorInfo != null && !StringUtils.hasText(collectorInfo.getIp())) {
if (collectorInfo != null && StringUtils.isBlank(collectorInfo.getIp())) {
// fetch remote ip address
InetSocketAddress socketAddress = (InetSocketAddress) ctx.channel().remoteAddress();
String clientIP = socketAddress.getAddress().getHostAddress();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.hertzbeat.collector.dispatch.DispatchConstants;
import org.apache.hertzbeat.collector.util.CollectUtil;
import org.apache.hertzbeat.common.entity.job.Configmap;
Expand Down Expand Up @@ -70,7 +71,6 @@
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import org.springframework.util.StreamUtils;
import org.springframework.util.StringUtils;
import org.yaml.snakeyaml.Yaml;

/**
Expand Down Expand Up @@ -106,7 +106,7 @@ public class AppServiceImpl implements AppService, CommandLineRunner {

@Override
public List<ParamDefine> getAppParamDefines(String app) {
if (StringUtils.hasText(app)){
if (StringUtils.isNotBlank(app)){
var appDefine = appDefines.get(app.toLowerCase());
if (appDefine != null && appDefine.getParams() != null) {
return appDefine.getParams();
Expand Down Expand Up @@ -168,7 +168,7 @@ public Job getAutoGenerateDynamicDefine(Long monitorId) {

@Override
public Job getAppDefine(String app) throws IllegalArgumentException {
if (!StringUtils.hasText(app)) {
if (StringUtils.isBlank(app)) {
throw new IllegalArgumentException("The app can not null.");
}
var appDefine = appDefines.get(app.toLowerCase());
Expand All @@ -180,7 +180,7 @@ public Job getAppDefine(String app) throws IllegalArgumentException {

@Override
public Optional<Job> getAppDefineOption(String app) {
if (StringUtils.hasText(app)) {
if (StringUtils.isNotBlank(app)) {
Job appDefine = appDefines.get(app.toLowerCase());
return Optional.ofNullable(appDefine);
}
Expand All @@ -190,7 +190,7 @@ public Optional<Job> getAppDefineOption(String app) {
@Override
public List<String> getAppDefineMetricNames(String app) {
List<String> metricNames = new ArrayList<>(16);
if (StringUtils.hasLength(app)) {
if (StringUtils.isNotBlank(app)) {
var appDefine = appDefines.get(app.toLowerCase());
if (appDefine == null) {
throw new IllegalArgumentException("The app " + app + " not support.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
Expand All @@ -43,7 +44,6 @@
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.RegionUtil;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
* Configure the import and export EXCEL format
Expand Down Expand Up @@ -89,14 +89,14 @@ public List<ExportMonitorDTO> parseImport(InputStream is) {
continue;
}
String name = getCellValueAsString(row.getCell(0));
if (StringUtils.hasText(name)) {
if (StringUtils.isNotBlank(name)) {
startRowList.add(row.getRowNum());
MonitorDTO monitor = extractMonitorDataFromRow(row);
ExportMonitorDTO exportMonitor = new ExportMonitorDTO();
exportMonitor.setMonitor(monitor);
monitors.add(exportMonitor);
String metrics = getCellValueAsString(row.getCell(11));
if (StringUtils.hasText(metrics)) {
if (StringUtils.isNotBlank(metrics)) {
List<String> metricList = Arrays.stream(metrics.split(",")).collect(Collectors.toList());
exportMonitor.setMetrics(metricList);
}
Expand Down Expand Up @@ -145,7 +145,7 @@ private MonitorDTO extractMonitorDataFromRow(Row row) {
monitor.setDescription(getCellValueAsString(row.getCell(5)));

String tagsString = getCellValueAsString(row.getCell(6));
if (StringUtils.hasText(tagsString)) {
if (StringUtils.isNotBlank(tagsString)) {
List<Long> tags = Arrays.stream(tagsString.split(","))
.map(Long::parseLong)
.collect(Collectors.toList());
Expand All @@ -159,7 +159,7 @@ private MonitorDTO extractMonitorDataFromRow(Row row) {

private ParamDTO extractParamDataFromRow(Row row) {
String fieldName = getCellValueAsString(row.getCell(8));
if (StringUtils.hasText(fieldName)) {
if (StringUtils.isNotBlank(fieldName)) {
ParamDTO param = new ParamDTO();
param.setField(fieldName);
param.setType(getCellValueAsByte(row.getCell(9)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.util.Set;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.hertzbeat.alert.dao.AlertDefineBindDao;
import org.apache.hertzbeat.collector.dispatch.DispatchConstants;
import org.apache.hertzbeat.common.constants.CommonConstants;
Expand Down Expand Up @@ -87,7 +88,6 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;

/**
Expand Down Expand Up @@ -214,7 +214,7 @@ public void addMonitor(Monitor monitor, List<Param> params, String collector) th
}).collect(Collectors.toList());
appDefine.setConfigmap(configmaps);

long jobId = !StringUtils.hasText(collector) ? collectJobScheduling.addAsyncCollectJob(appDefine, null) :
long jobId = StringUtils.isBlank(collector) ? collectJobScheduling.addAsyncCollectJob(appDefine, null) :
collectJobScheduling.addAsyncCollectJob(appDefine, collector);

try {
Expand Down Expand Up @@ -361,7 +361,7 @@ public void validate(MonitorDto monitorDto, Boolean isModify) throws IllegalArgu
monitor.setTags(monitor.getTags().stream().distinct().collect(Collectors.toList()));
}
// the dispatch collector must exist if pin
if (StringUtils.hasText(monitorDto.getCollector())) {
if (StringUtils.isNotBlank(monitorDto.getCollector())) {
Optional<Collector> optionalCollector = collectorDao.findCollectorByName(monitorDto.getCollector());
if (optionalCollector.isEmpty()) {
throw new IllegalArgumentException("The pinned collector does not exist.");
Expand All @@ -378,7 +378,7 @@ public void validate(MonitorDto monitorDto, Boolean isModify) throws IllegalArgu
if (paramDefine.isRequired() && (param == null || param.getParamValue() == null)) {
throw new IllegalArgumentException("Params field " + field + " is required.");
}
if (param != null && param.getParamValue() != null && StringUtils.hasText(param.getParamValue())) {
if (param != null && param.getParamValue() != null && StringUtils.isNotBlank(param.getParamValue())) {
switch (paramDefine.getType()) {
case "number":
double doubleValue;
Expand Down Expand Up @@ -654,7 +654,7 @@ public Page<Monitor> getMonitors(List<Long> monitorIds, String app, String name,
}
andList.add(inPredicate);
}
if (StringUtils.hasText(app)) {
if (StringUtils.isNotBlank(app)) {
Predicate predicateApp = criteriaBuilder.equal(root.get("app"), app);
andList.add(predicateApp);
}
Expand All @@ -663,7 +663,7 @@ public Page<Monitor> getMonitors(List<Long> monitorIds, String app, String name,
andList.add(predicateStatus);
}

if (StringUtils.hasText(tag)) {
if (StringUtils.isNotBlank(tag)) {
String[] tagArr = tag.split(":");
String tagName = tagArr[0];
ListJoin<Monitor, Tag> tagJoin = root
Expand All @@ -681,11 +681,11 @@ public Page<Monitor> getMonitors(List<Long> monitorIds, String app, String name,
Predicate andPredicate = criteriaBuilder.and(andList.toArray(andPredicates));

List<Predicate> orList = new ArrayList<>();
if (StringUtils.hasText(host)) {
if (StringUtils.isNotBlank(host)) {
Predicate predicateHost = criteriaBuilder.like(root.get("host"), "%" + host + "%");
orList.add(predicateHost);
}
if (StringUtils.hasText(name)) {
if (StringUtils.isNotBlank(name)) {
Predicate predicateName = criteriaBuilder.like(root.get("name"), "%" + name + "%");
orList.add(predicateName);
}
Expand Down Expand Up @@ -748,7 +748,7 @@ public void enableManageMonitors(HashSet<Long> ids) {
List<Configmap> configmaps = params.stream().map(param ->
new Configmap(param.getField(), param.getParamValue(), param.getType())).collect(Collectors.toList());
List<ParamDefine> paramDefaultValue = appDefine.getParams().stream()
.filter(item -> StringUtils.hasText(item.getDefaultValue()))
.filter(item -> StringUtils.isNotBlank(item.getDefaultValue()))
.toList();
paramDefaultValue.forEach(defaultVar -> {
if (configmaps.stream().noneMatch(item -> item.getKey().equals(defaultVar.getField()))) {
Expand Down Expand Up @@ -854,7 +854,7 @@ public void updateAppCollectJob(Job job) {
List<Configmap> configmaps = params.stream().map(param -> new Configmap(param.getField(),
param.getParamValue(), param.getType())).collect(Collectors.toList());
List<ParamDefine> paramDefaultValue = appDefine.getParams().stream()
.filter(item -> StringUtils.hasText(item.getDefaultValue()))
.filter(item -> StringUtils.isNotBlank(item.getDefaultValue()))
.toList();
paramDefaultValue.forEach(defaultVar -> {
if (configmaps.stream().noneMatch(item -> item.getKey().equals(defaultVar.getField()))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
import java.util.HashMap;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.hertzbeat.common.constants.CommonConstants;
import org.apache.hertzbeat.common.entity.alerter.Alert;
import org.apache.hertzbeat.common.entity.manager.NoticeReceiver;
import org.apache.hertzbeat.common.entity.manager.NoticeTemplate;
import org.apache.hertzbeat.manager.AbstractSpringIntegrationTest;
import org.junit.jupiter.api.Test;
import org.springframework.util.StringUtils;

/**
* Test case for {@link DingTalkRobotAlertNotifyHandlerImpl}
Expand All @@ -41,7 +41,7 @@ class DingTalkRobotAlertNotifyHandlerImplTest extends AbstractSpringIntegrationT
@Test
void send() {
String ddAccessToken = System.getenv("DD_ACCESS_TOKEN");
if (!StringUtils.hasText(ddAccessToken)) {
if (StringUtils.isBlank(ddAccessToken)) {
log.warn("Please provide environment variables DD_ACCESS_TOKEN");
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
import jakarta.annotation.Resource;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.hertzbeat.common.constants.CommonConstants;
import org.apache.hertzbeat.common.entity.alerter.Alert;
import org.apache.hertzbeat.common.entity.manager.NoticeReceiver;
import org.apache.hertzbeat.common.entity.manager.NoticeTemplate;
import org.apache.hertzbeat.manager.AbstractSpringIntegrationTest;
import org.junit.jupiter.api.Test;
import org.springframework.util.StringUtils;

/**
* Test case for {@link DiscordBotAlertNotifyHandlerImpl}
Expand All @@ -41,7 +41,7 @@ class DiscordBotAlertNotifyHandlerImplTest extends AbstractSpringIntegrationTest
void send() {
var discordChannelId = System.getenv("DISCORD_CHANNEL_ID");
var discordBotToken = System.getenv("DISCORD_BOT_TOKEN");
if (!StringUtils.hasText(discordChannelId) || !StringUtils.hasText(discordBotToken)) {
if (StringUtils.isBlank(discordChannelId) || StringUtils.isBlank(discordBotToken)) {
log.warn("Please provide environment variables DISCORD_CHANNEL_ID, DISCORD_BOT_TOKEN");
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
import java.util.HashMap;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.hertzbeat.common.constants.CommonConstants;
import org.apache.hertzbeat.common.entity.alerter.Alert;
import org.apache.hertzbeat.common.entity.manager.NoticeReceiver;
import org.apache.hertzbeat.common.entity.manager.NoticeTemplate;
import org.apache.hertzbeat.manager.AbstractSpringIntegrationTest;
import org.junit.jupiter.api.Test;
import org.springframework.util.StringUtils;

/**
* Test case for {@link FlyBookAlertNotifyHandlerImpl}
Expand All @@ -41,7 +41,7 @@ class FlyBookAlertNotifyHandlerImplTest extends AbstractSpringIntegrationTest {
@Test
void send() {
String flyBookId = System.getenv("FLY_BOOK_ID");
if (!StringUtils.hasText(flyBookId)) {
if (StringUtils.isBlank(flyBookId)) {
log.warn("Please provide environment variables FLY_BOOK_ID");
return;
}
Expand Down
Loading

0 comments on commit 82ca308

Please sign in to comment.