Sync develop
This commit is contained in:
@@ -20,13 +20,15 @@ import lombok.Data;
|
|||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
import we.context.config.annotation.FizzRefreshScope;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link AggregateFilter} properties
|
* {@link AggregateFilter} properties
|
||||||
*
|
*
|
||||||
* @author zhongjie
|
* @author zhongjie
|
||||||
*/
|
*/
|
||||||
@RefreshScope
|
//@RefreshScope
|
||||||
|
@FizzRefreshScope
|
||||||
@Component
|
@Component
|
||||||
@Data
|
@Data
|
||||||
public class AggregateFilterProperties {
|
public class AggregateFilterProperties {
|
||||||
|
|||||||
@@ -212,19 +212,43 @@ public class FuncExecutor {
|
|||||||
// int pos2 = funcExpression.lastIndexOf(")");
|
// int pos2 = funcExpression.lastIndexOf(")");
|
||||||
String argsStr = funcExpression.substring(pos1 + 1);
|
String argsStr = funcExpression.substring(pos1 + 1);
|
||||||
argsStr = StringUtils.trim(argsStr);
|
argsStr = StringUtils.trim(argsStr);
|
||||||
|
|
||||||
|
Object[] args = new Object[paramTypes.length];
|
||||||
|
if (paramTypes.length == 0) {
|
||||||
|
// no argument method
|
||||||
|
if (hasCloseParenthesis(argsStr, 0)) {
|
||||||
|
ctx.funcExpression = argsStr.substring(1);
|
||||||
|
} else {
|
||||||
|
ctx.funcExpression = argsStr;
|
||||||
|
}
|
||||||
|
return args;
|
||||||
|
}
|
||||||
// check if there is any argument
|
// check if there is any argument
|
||||||
if (StringUtils.isBlank(argsStr)) {
|
if (StringUtils.isBlank(argsStr)) {
|
||||||
if (paramTypes == null || paramTypes.length == 0) {
|
if (paramTypes == null || paramTypes.length == 0) {
|
||||||
return null;
|
ctx.funcExpression = argsStr;
|
||||||
|
return args;
|
||||||
} else if (paramTypes.length == 1 && isVarArgs) {
|
} else if (paramTypes.length == 1 && isVarArgs) {
|
||||||
// check if variable arguments
|
// check if variable arguments
|
||||||
return null;
|
ctx.funcExpression = argsStr;
|
||||||
|
return args;
|
||||||
|
} else {
|
||||||
|
throw new FizzRuntimeException(
|
||||||
|
String.format("missing argument, Function Expression: %s", funcExpression));
|
||||||
|
}
|
||||||
|
} else if (hasCloseParenthesis(argsStr, 0)) {
|
||||||
|
if (paramTypes == null || paramTypes.length == 0) {
|
||||||
|
ctx.funcExpression = argsStr.substring(1);
|
||||||
|
return args;
|
||||||
|
} else if (paramTypes.length == 1 && isVarArgs) {
|
||||||
|
ctx.funcExpression = argsStr.substring(1);
|
||||||
|
return args;
|
||||||
} else {
|
} else {
|
||||||
throw new FizzRuntimeException(
|
throw new FizzRuntimeException(
|
||||||
String.format("missing argument, Function Expression: %s", funcExpression));
|
String.format("missing argument, Function Expression: %s", funcExpression));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Object[] args = new Object[paramTypes.length];
|
|
||||||
List<Object> varArgs = new ArrayList<>();
|
List<Object> varArgs = new ArrayList<>();
|
||||||
for (int i = 0; i < paramTypes.length; i++) {
|
for (int i = 0; i < paramTypes.length; i++) {
|
||||||
Class clazz = paramTypes[i];
|
Class clazz = paramTypes[i];
|
||||||
@@ -439,9 +463,9 @@ public class FuncExecutor {
|
|||||||
if (!Character.isWhitespace(argsStr.charAt(i))) {
|
if (!Character.isWhitespace(argsStr.charAt(i))) {
|
||||||
if (")".equals(String.valueOf(argsStr.charAt(i)))) {
|
if (")".equals(String.valueOf(argsStr.charAt(i)))) {
|
||||||
return true;
|
return true;
|
||||||
} /*else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}*/
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2021 the original author or authors.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package we.fizz.function;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Francis Dong
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class FuncExecutorTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void contextLoads() {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testNest() {
|
||||||
|
String funcExpression = "fn.codec.md5(fn.date.add( fn.date.add(\"2021-07-09 22:44:55\", \"yyyy-MM-dd HH:mm:ss\", 1, fn.math.addExact(999,1 ) ), \"yyyy-MM-dd HH:mm:ss\", fn.math.addExact(0,1), 1000 ))";
|
||||||
|
Object result = FuncExecutor.getInstance().exec(null, funcExpression);
|
||||||
|
assertEquals(CodecFunc.getInstance().md5("2021-07-09 22:44:57"), result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testNest2() {
|
||||||
|
String funcExpression = "fn.string.toUpperCase(fn.codec.sha256(fn.string.concat(\"a\",\"b\",fn.string.toString(fn.date.timestamp()))))";
|
||||||
|
Object result = FuncExecutor.getInstance().exec(null, funcExpression);
|
||||||
|
System.out.println(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testNest3() {
|
||||||
|
String funcExpression = "fn.string.toUpperCase(fn.string.concat(\"a\",\"b\", fn.string.concat())))";
|
||||||
|
Object result = FuncExecutor.getInstance().exec(null, funcExpression);
|
||||||
|
assertEquals("AB", result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testNest4() {
|
||||||
|
String funcExpression = "fn.string.toUpperCase(fn.codec.sha256(fn.string.concat(\"a\",fn.string.concat(),\"b\")))";
|
||||||
|
Object result = FuncExecutor.getInstance().exec(null, funcExpression);
|
||||||
|
System.out.println(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testNest5() {
|
||||||
|
String funcExpression = "fn.string.toUpperCase(fn.codec.sha256(fn.string.concat(\"a\",fn.string.toString(fn.date.timestamp()),fn.string.concat(fn.string.concat(fn.string.concat(fn.string.concat())), \"c\"),\"b\")))";
|
||||||
|
Object result = FuncExecutor.getInstance().exec(null, funcExpression);
|
||||||
|
System.out.println(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -97,7 +97,7 @@ class StringFuncTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testConcatws() {
|
void testConcatws() {
|
||||||
String funcExpression = "fn.string.concatws(\",\" , \"2021-07-09 22:44:55\", \"yyyy-MM-dd HH:mm:ss\")";
|
String funcExpression = "fn.string.concatws(\",\" , \"2021-07-09 22:44:55\", \"yyyy-MM-dd HH:mm:ss\" )";
|
||||||
Object result = FuncExecutor.getInstance().exec(null, funcExpression);
|
Object result = FuncExecutor.getInstance().exec(null, funcExpression);
|
||||||
assertEquals("2021-07-09 22:44:55,yyyy-MM-dd HH:mm:ss", result.toString());
|
assertEquals("2021-07-09 22:44:55,yyyy-MM-dd HH:mm:ss", result.toString());
|
||||||
}
|
}
|
||||||
@@ -124,6 +124,7 @@ class StringFuncTests {
|
|||||||
String funcExpression = "fn.string.substring({data.dateStr}, {data.startIndex})";
|
String funcExpression = "fn.string.substring({data.dateStr}, {data.startIndex})";
|
||||||
// String funcExpression = "fn.string.substring(\"2021-07-09 22:44:55\", 1)";
|
// String funcExpression = "fn.string.substring(\"2021-07-09 22:44:55\", 1)";
|
||||||
Object result = FuncExecutor.getInstance().exec(ctxNode, funcExpression);
|
Object result = FuncExecutor.getInstance().exec(ctxNode, funcExpression);
|
||||||
|
System.out.println(result);
|
||||||
assertEquals("2021-07-09 22:44:55".substring(1), result.toString());
|
assertEquals("2021-07-09 22:44:55".substring(1), result.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,6 +184,14 @@ class StringFuncTests {
|
|||||||
assertEquals("234", result);
|
assertEquals("234", result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testToString4() {
|
||||||
|
String funcExpression = "fn.string.toString(fn.date.timestamp())";
|
||||||
|
String result = (String)FuncExecutor.getInstance().exec(null, funcExpression);
|
||||||
|
System.out.println(result);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testReplace() {
|
void testReplace() {
|
||||||
String funcExpression = "fn.string.replace(\"2021-07-09 22:44:55\", \"44:55\", \"00:00\")";
|
String funcExpression = "fn.string.replace(\"2021-07-09 22:44:55\", \"44:55\", \"00:00\")";
|
||||||
@@ -197,6 +206,13 @@ class StringFuncTests {
|
|||||||
assertEquals("2021-07-09 22:44:55 44:55".replaceAll("44:55", "00:00"), result);
|
assertEquals("2021-07-09 22:44:55 44:55".replaceAll("44:55", "00:00"), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testReplaceAll2() {
|
||||||
|
String funcExpression = "fn.string.replaceAll(\"1.2.3\", \"\\.\", \"\")";
|
||||||
|
String result = (String)FuncExecutor.getInstance().exec(null, funcExpression);
|
||||||
|
assertEquals("1.2.3".replaceAll("\\.", ""), result);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testReplaceFirst() {
|
void testReplaceFirst() {
|
||||||
String funcExpression = "fn.string.replaceFirst(\"2021-07-09 22:44:55 44:55\", \"44:55\", \"00:00\")";
|
String funcExpression = "fn.string.replaceFirst(\"2021-07-09 22:44:55 44:55\", \"44:55\", \"00:00\")";
|
||||||
|
|||||||
Reference in New Issue
Block a user