Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
淡淡忧伤的程序员
DolphinScheduler
提交
c447bb48
DolphinScheduler
项目概览
淡淡忧伤的程序员
/
DolphinScheduler
与 Fork 源项目一致
Fork自
apache / DolphinScheduler
通知
48
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
DolphinScheduler
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c447bb48
编写于
2月 10, 2020
作者:
K
khadgarmage
提交者:
GitHub
2月 10, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add stringutils ut (#1921)
* add stringutils ut
上级
b77dddfe
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
89 addition
and
138 deletion
+89
-138
dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/utils/MailUtils.java
...va/org/apache/dolphinscheduler/alert/utils/MailUtils.java
+4
-4
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionController.java
...scheduler/api/controller/ProcessDefinitionController.java
+8
-8
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessInstanceController.java
...inscheduler/api/controller/ProcessInstanceController.java
+5
-5
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ResourcesService.java
...apache/dolphinscheduler/api/service/ResourcesService.java
+1
-1
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/StringUtils.java
...org/apache/dolphinscheduler/common/utils/StringUtils.java
+5
-120
dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/StringUtilsTest.java
...apache/dolphinscheduler/common/utils/StringUtilsTest.java
+66
-0
未找到文件。
dolphinscheduler-alert/src/main/java/org/apache/dolphinscheduler/alert/utils/MailUtils.java
浏览文件 @
c447bb48
...
...
@@ -90,14 +90,14 @@ public class MailUtils {
public
static
Map
<
String
,
Object
>
sendMails
(
Collection
<
String
>
receivers
,
Collection
<
String
>
receiversCc
,
String
title
,
String
content
,
ShowType
showType
)
{
Map
<
String
,
Object
>
retMap
=
new
HashMap
<>();
retMap
.
put
(
Constants
.
STATUS
,
false
);
// if there is no receivers && no receiversCc, no need to process
if
(
CollectionUtils
.
isEmpty
(
receivers
)
&&
CollectionUtils
.
isEmpty
(
receiversCc
))
{
return
retMap
;
}
receivers
.
removeIf
(
StringUtils:
:
isEmpty
);
if
(
showType
==
ShowType
.
TABLE
||
showType
==
ShowType
.
TEXT
){
// send email
HtmlEmail
email
=
new
HtmlEmail
();
...
...
@@ -335,7 +335,7 @@ public class MailUtils {
*/
private
static
void
handleException
(
Collection
<
String
>
receivers
,
Map
<
String
,
Object
>
retMap
,
Exception
e
)
{
logger
.
error
(
"Send email to {} failed {}"
,
receivers
,
e
);
retMap
.
put
(
Constants
.
MESSAGE
,
"Send email to {"
+
String
Utils
.
join
(
receivers
,
","
)
+
"} failed,"
+
e
.
toString
());
retMap
.
put
(
Constants
.
MESSAGE
,
"Send email to {"
+
String
.
join
(
","
,
receivers
)
+
"} failed,"
+
e
.
toString
());
}
}
\ No newline at end of file
}
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessDefinitionController.java
浏览文件 @
c447bb48
...
...
@@ -53,7 +53,7 @@ public class ProcessDefinitionController extends BaseController{
/**
* create process definition
*
*
* @param loginUser login user
* @param projectName project name
* @param name process definition name
...
...
@@ -96,7 +96,7 @@ public class ProcessDefinitionController extends BaseController{
/**
* verify process definition name unique
*
*
* @param loginUser login user
* @param projectName project name
* @param name name
...
...
@@ -328,9 +328,9 @@ public class ProcessDefinitionController extends BaseController{
/**
*
*
* get tasks list by process definition id
*
*
*
* @param loginUser login user
* @param projectName project name
...
...
@@ -442,7 +442,7 @@ public class ProcessDefinitionController extends BaseController{
loginUser
.
getUserName
(),
projectName
,
processDefinitionIds
);
Map
<
String
,
Object
>
result
=
new
HashMap
<>(
5
);
List
<
Integer
>
deleteFailedIdList
=
new
ArrayList
<
Integer
>();
List
<
String
>
deleteFailedIdList
=
new
ArrayList
<
>();
if
(
StringUtils
.
isNotEmpty
(
processDefinitionIds
)){
String
[]
processDefinitionIdArray
=
processDefinitionIds
.
split
(
","
);
...
...
@@ -451,17 +451,17 @@ public class ProcessDefinitionController extends BaseController{
try
{
Map
<
String
,
Object
>
deleteResult
=
processDefinitionService
.
deleteProcessDefinitionById
(
loginUser
,
projectName
,
processDefinitionId
);
if
(!
Status
.
SUCCESS
.
equals
(
deleteResult
.
get
(
Constants
.
STATUS
))){
deleteFailedIdList
.
add
(
p
rocessDefinitionId
);
deleteFailedIdList
.
add
(
strP
rocessDefinitionId
);
logger
.
error
((
String
)
deleteResult
.
get
(
Constants
.
MSG
));
}
}
catch
(
Exception
e
)
{
deleteFailedIdList
.
add
(
p
rocessDefinitionId
);
deleteFailedIdList
.
add
(
strP
rocessDefinitionId
);
}
}
}
if
(!
deleteFailedIdList
.
isEmpty
()){
putMsg
(
result
,
Status
.
BATCH_DELETE_PROCESS_DEFINE_BY_IDS_ERROR
,
StringUtils
.
join
(
deleteFailedIdList
,
","
));
putMsg
(
result
,
Status
.
BATCH_DELETE_PROCESS_DEFINE_BY_IDS_ERROR
,
String
.
join
(
","
,
deleteFailedIdList
));
}
else
{
putMsg
(
result
,
Status
.
SUCCESS
);
}
...
...
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/ProcessInstanceController.java
浏览文件 @
c447bb48
...
...
@@ -58,7 +58,7 @@ public class ProcessInstanceController extends BaseController{
/**
* query process instance list paging
*
*
* @param loginUser login user
* @param projectName project name
* @param pageNo page number
...
...
@@ -372,7 +372,7 @@ public class ProcessInstanceController extends BaseController{
// task queue
ITaskQueue
tasksQueue
=
TaskQueueFactory
.
getTaskQueueInstance
();
Map
<
String
,
Object
>
result
=
new
HashMap
<>(
5
);
List
<
Integer
>
deleteFailedIdList
=
new
ArrayList
<
Integer
>();
List
<
String
>
deleteFailedIdList
=
new
ArrayList
<
>();
if
(
StringUtils
.
isNotEmpty
(
processInstanceIds
)){
String
[]
processInstanceIdArray
=
processInstanceIds
.
split
(
","
);
...
...
@@ -381,16 +381,16 @@ public class ProcessInstanceController extends BaseController{
try
{
Map
<
String
,
Object
>
deleteResult
=
processInstanceService
.
deleteProcessInstanceById
(
loginUser
,
projectName
,
processInstanceId
,
tasksQueue
);
if
(!
Status
.
SUCCESS
.
equals
(
deleteResult
.
get
(
Constants
.
STATUS
))){
deleteFailedIdList
.
add
(
p
rocessInstanceId
);
deleteFailedIdList
.
add
(
strP
rocessInstanceId
);
logger
.
error
((
String
)
deleteResult
.
get
(
Constants
.
MSG
));
}
}
catch
(
Exception
e
)
{
deleteFailedIdList
.
add
(
p
rocessInstanceId
);
deleteFailedIdList
.
add
(
strP
rocessInstanceId
);
}
}
}
if
(
deleteFailedIdList
.
size
()
>
0
){
putMsg
(
result
,
Status
.
BATCH_DELETE_PROCESS_INSTANCE_BY_IDS_ERROR
,
StringUtils
.
join
(
deleteFailedIdList
,
","
));
putMsg
(
result
,
Status
.
BATCH_DELETE_PROCESS_INSTANCE_BY_IDS_ERROR
,
String
.
join
(
","
,
deleteFailedIdList
));
}
else
{
putMsg
(
result
,
Status
.
SUCCESS
);
}
...
...
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ResourcesService.java
浏览文件 @
c447bb48
...
...
@@ -539,7 +539,7 @@ public class ResourcesService extends BaseService {
putMsg
(
result
,
Status
.
SUCCESS
);
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
ALIAS
,
resource
.
getAlias
());
map
.
put
(
CONTENT
,
String
Utils
.
join
(
content
,
"\n"
));
map
.
put
(
CONTENT
,
String
.
join
(
"\n"
,
content
));
result
.
setData
(
map
);
}
else
{
logger
.
error
(
"read file {} not exist in hdfs"
,
hdfsFileName
);
...
...
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/StringUtils.java
浏览文件 @
c447bb48
...
...
@@ -16,17 +16,7 @@
*/
package
org.apache.dolphinscheduler.common.utils
;
import
java.nio.charset.StandardCharsets
;
import
java.util.Iterator
;
import
java.util.Objects
;
import
java.util.regex.Pattern
;
public
class
StringUtils
{
public
static
final
int
INDEX_NOT_FOUND
=
-
1
;
public
static
final
String
EMPTY
=
""
;
public
static
boolean
isEmpty
(
final
CharSequence
cs
)
{
...
...
@@ -37,119 +27,14 @@ public class StringUtils {
return
!
isEmpty
(
cs
);
}
public
static
boolean
isBlank
(
CharSequence
cs
){
int
strLen
;
if
(
cs
==
null
||
(
strLen
=
cs
.
length
())
==
0
)
{
public
static
boolean
isBlank
(
String
s
){
if
(
isEmpty
(
s
))
{
return
true
;
}
for
(
int
i
=
0
;
i
<
strLen
;
i
++)
{
if
(
Character
.
isWhitespace
(
cs
.
charAt
(
i
))
==
false
)
{
return
false
;
}
}
return
true
;
}
public
static
boolean
isNotBlank
(
CharSequence
str
){
return
!
isBlank
(
str
);
}
public
static
String
substringBefore
(
final
String
str
,
final
String
separator
)
{
if
(
isBlank
(
str
)
||
separator
==
null
)
{
return
str
;
}
if
(
separator
.
isEmpty
())
{
return
EMPTY
;
}
final
int
pos
=
str
.
indexOf
(
separator
);
if
(
pos
==
INDEX_NOT_FOUND
)
{
return
str
;
}
return
str
.
substring
(
0
,
pos
);
}
public
static
String
substringAfter
(
final
String
str
,
final
String
separator
)
{
if
(
isBlank
(
str
))
{
return
str
;
}
if
(
separator
==
null
)
{
return
EMPTY
;
}
final
int
pos
=
str
.
indexOf
(
separator
);
if
(
pos
==
INDEX_NOT_FOUND
)
{
return
EMPTY
;
}
return
str
.
substring
(
pos
+
separator
.
length
());
return
s
.
trim
().
length
()
==
0
;
}
public
static
String
substringAfterLast
(
final
String
str
,
final
String
separator
)
{
if
(
isEmpty
(
str
))
{
return
str
;
}
if
(
isEmpty
(
separator
))
{
return
EMPTY
;
}
final
int
pos
=
str
.
lastIndexOf
(
separator
);
if
(
pos
==
INDEX_NOT_FOUND
||
pos
==
str
.
length
()
-
separator
.
length
())
{
return
EMPTY
;
}
return
str
.
substring
(
pos
+
separator
.
length
());
}
public
static
String
getUtf8String
(
byte
[]
bytes
){
return
new
String
(
bytes
,
StandardCharsets
.
UTF_8
);
}
public
static
byte
[]
getUtf8Bytes
(
String
str
){
return
str
.
getBytes
(
StandardCharsets
.
UTF_8
);
}
public
static
boolean
hasChinese
(
String
str
)
{
if
(
str
==
null
)
{
return
false
;
}
Pattern
pattern
=
Pattern
.
compile
(
"[\\u4E00-\\u9FBF]+"
);
return
pattern
.
matcher
(
str
).
find
();
}
public
static
boolean
hasSpace
(
String
str
)
{
if
(
str
==
null
)
{
return
false
;
}
int
len
=
str
.
length
();
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
if
(
str
.
charAt
(
i
)
==
' '
)
{
return
true
;
}
}
return
false
;
}
public
static
String
join
(
final
Iterable
<?>
iterable
,
final
String
separator
){
Iterator
<?>
iterator
=
iterable
.
iterator
();
if
(
iterator
==
null
)
{
return
null
;
}
if
(!
iterator
.
hasNext
())
{
return
EMPTY
;
}
final
Object
first
=
iterator
.
next
();
if
(!
iterable
.
iterator
().
hasNext
())
{
return
Objects
.
toString
(
first
,
""
);
}
final
StringBuilder
buf
=
new
StringBuilder
(
64
);
if
(
first
!=
null
)
{
buf
.
append
(
first
);
}
while
(
iterator
.
hasNext
())
{
if
(
separator
!=
null
)
{
buf
.
append
(
separator
);
}
final
Object
obj
=
iterator
.
next
();
if
(
obj
!=
null
)
{
buf
.
append
(
obj
);
}
}
return
buf
.
toString
();
public
static
boolean
isNotBlank
(
String
s
){
return
!
isBlank
(
s
);
}
}
dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/StringUtilsTest.java
0 → 100644
浏览文件 @
c447bb48
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.dolphinscheduler.common.utils
;
import
org.junit.Assert
;
import
org.junit.Test
;
import
java.util.ArrayList
;
public
class
StringUtilsTest
{
@Test
public
void
testIsNotEmpty
()
{
//null string
boolean
b
=
StringUtils
.
isNotEmpty
(
null
);
Assert
.
assertFalse
(
b
);
//"" string
b
=
StringUtils
.
isNotEmpty
(
""
);
Assert
.
assertFalse
(
b
);
//" " string
b
=
StringUtils
.
isNotEmpty
(
" "
);
Assert
.
assertTrue
(
b
);
//"test" string
b
=
StringUtils
.
isNotEmpty
(
"test"
);
Assert
.
assertTrue
(
b
);
}
@Test
public
void
testIsNotBlank
()
{
//null string
boolean
b
=
StringUtils
.
isNotBlank
(
null
);
Assert
.
assertFalse
(
b
);
//"" string
b
=
StringUtils
.
isNotBlank
(
""
);
Assert
.
assertFalse
(
b
);
//" " string
b
=
StringUtils
.
isNotBlank
(
" "
);
Assert
.
assertFalse
(
b
);
//" test " string
b
=
StringUtils
.
isNotBlank
(
" test "
);
Assert
.
assertTrue
(
b
);
//"test" string
b
=
StringUtils
.
isNotBlank
(
"test"
);
Assert
.
assertTrue
(
b
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录