Skip to content

Commit b45e3e8

Browse files
author
dujie
committed
restapi
1 parent 8761a66 commit b45e3e8

24 files changed

+1372
-35
lines changed
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package com.dtstack.flinkx.restapi.common;
19+
20+
import org.apache.commons.lang3.StringUtils;
21+
22+
import java.sql.Date;
23+
import java.time.LocalDateTime;
24+
import java.time.ZoneId;
25+
import java.time.format.DateTimeFormatter;
26+
import java.util.Objects;
27+
28+
/**
29+
* ConstantParan
30+
*
31+
* @author by [email protected]
32+
* @Date 2020/9/26
33+
*/
34+
public class ConstantParam<T> implements ParamDefinition {
35+
36+
private final String name;
37+
38+
private final ParamType paramType;
39+
40+
private final Class<T> valueClass;
41+
42+
protected Object value;
43+
44+
private final String description;
45+
46+
private String formatDescription;
47+
48+
private final DateTimeFormatter format;
49+
50+
public ConstantParam(String name, ParamType paramType, Class valueClass, Object value, String description, String format) {
51+
this.name = name;
52+
this.paramType = paramType;
53+
this.valueClass = valueClass;
54+
this.value = objectConvent(valueClass, value);
55+
this.description = description;
56+
this.formatDescription=format;
57+
if (StringUtils.isNotBlank(format)) {
58+
this.format = DateTimeFormatter.ofPattern(format);
59+
} else {
60+
this.format = null;
61+
}
62+
63+
}
64+
65+
@Override
66+
public String getName() {
67+
return name;
68+
}
69+
70+
@Override
71+
public ParamType getType() {
72+
return paramType;
73+
}
74+
75+
@Override
76+
public Object getValue() {
77+
return value;
78+
}
79+
80+
@Override
81+
public Class getValueType() {
82+
return valueClass;
83+
}
84+
85+
86+
@Override
87+
public String getDescription() {
88+
return description;
89+
}
90+
91+
@Override
92+
public String getFormat() {
93+
return formatDescription;
94+
}
95+
96+
@Override
97+
public Object format(Object data) {
98+
if (Objects.isNull(format) || Objects.isNull(data)) {
99+
return data;
100+
}
101+
if (getValueType().equals(Date.class)) {
102+
Date value1 = (Date) data;
103+
LocalDateTime ldt = value1.toInstant()
104+
.atZone(ZoneId.systemDefault())
105+
.toLocalDateTime();
106+
return format.format(ldt);
107+
}
108+
return null;
109+
}
110+
111+
@Override
112+
public <T> T objectConvent(Class<T> tClass, Object data) {
113+
return (T)data;
114+
}
115+
116+
117+
118+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.dtstack.flinkx.restapi.common;
2+
3+
public class ConstantVarible implements Paramitem {
4+
private final Object object;
5+
// private ParamDefinition paramDefinition;
6+
7+
public ConstantVarible(Object object ) {
8+
this.object = object;
9+
// this.paramDefinition = paramDefinition;
10+
}
11+
12+
@Override
13+
public Object getValue() {
14+
return object;
15+
}
16+
17+
// @Override
18+
// public ParamDefinition getParamDefinition() {
19+
// return paramDefinition;
20+
// }
21+
}

flinkx-restapi/flinkx-restapi-reader/src/main/java/com/dtstack/flinkx/restapi/inputformat/httpClient.java renamed to flinkx-restapi/flinkx-restapi-core/src/main/java/com/dtstack/flinkx/restapi/common/CurrentTimeVarible.java

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,18 @@
1515
* See the License for the specific language governing permissions and
1616
* limitations under the License.
1717
*/
18-
package com.dtstack.flinkx.restapi.inputformat;
18+
package com.dtstack.flinkx.restapi.common;
1919

2020
/**
21-
* httpClient
21+
* CurrentTimeVarible
2222
*
2323
* @author by [email protected]
24-
* @Date 2020/9/25
24+
* @Date 2020/9/28
2525
*/
26-
public class httpClient {
27-
28-
private Thread workThread;
29-
30-
public httpClient() {
26+
public class CurrentTimeVarible implements Paramitem {
3127

28+
@Override
29+
public Object getValue() {
30+
return System.currentTimeMillis();
3231
}
33-
34-
public void start(){
35-
this.workThread = new Thread(()->{
36-
});
37-
38-
workThread.start();
39-
}
40-
41-
4232
}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package com.dtstack.flinkx.restapi.common;
19+
20+
import java.util.List;
21+
import java.util.Objects;
22+
23+
/**
24+
* DymaticParam
25+
*
26+
* @author by [email protected]
27+
* @Date 2020/9/26
28+
*/
29+
public class DymaticParam extends ConstantParam implements ParamDefinitionNextAble ,lifecycle {
30+
31+
private RestContext restContext;
32+
private ParamItemContext valueDymaticParam;
33+
private ParamItemContext nextvalueDymaticParam;
34+
35+
public DymaticParam(String name, ParamType paramType, Class valueClass, String description, String format, RestContext context) {
36+
super(name, paramType, valueClass, null, description, format);
37+
this.restContext = context;
38+
}
39+
40+
@Override
41+
public Object getValue() {
42+
Object data;
43+
if (restContext.getTime() > 0 && Objects.nonNull(nextvalueDymaticParam)) {
44+
data = nextvalueDymaticParam.getValue();
45+
} else {
46+
data = nextvalueDymaticParam.getValue();
47+
}
48+
data = format(data);
49+
return objectConvent(getValueType(), data);
50+
}
51+
52+
/**
53+
* 字符串解析为后缀表达式
54+
* `如何判断是动态变量
55+
* 如何判断是符合后缀表达式的
56+
* 后缀表达式计算
57+
*
58+
* @return
59+
*/
60+
@Override
61+
public Object getNextValue() {
62+
// restContext.calcute();
63+
return getValue();
64+
}
65+
66+
//判断是否是运算符
67+
public boolean isOperator(String oper) {
68+
return oper.equals("+") || oper.equals("-") || oper.equals("*") || oper.equals("/");
69+
}
70+
71+
//计算 如何变量1 2 只要有一个是字符串 那么就直接拼接 或者为null 为null 2+2+
72+
public int calculation(int num1, int num2, String oper) {
73+
switch (oper) {
74+
case "+":
75+
return num2 + num1;
76+
case "-":
77+
return num2 - num1;
78+
case "*":
79+
return num2 * num1;
80+
case "/":
81+
return num2 / num1;
82+
default:
83+
return 0;
84+
}
85+
}
86+
87+
public int operationLv(char operation) {//给运算符设置优先级
88+
switch (operation) {
89+
case '+':
90+
case '-':
91+
return 1;
92+
case '*':
93+
case '/':
94+
return 2;
95+
case '(':
96+
case ')':
97+
return 3;
98+
default:
99+
return 0;
100+
}
101+
}
102+
103+
104+
@Override
105+
public void init() {
106+
if(Objects.nonNull(valueDymaticParam)){
107+
valueDymaticParam.init();
108+
}
109+
110+
if(Objects.nonNull(nextvalueDymaticParam)){
111+
nextvalueDymaticParam.init();
112+
}
113+
}
114+
115+
public void setValueDymaticParam(ParamItemContext valueDymaticParam) {
116+
this.valueDymaticParam = valueDymaticParam;
117+
}
118+
119+
public void setNextvalueDymaticParam(ParamItemContext nextvalueDymaticParam) {
120+
this.nextvalueDymaticParam = nextvalueDymaticParam;
121+
}
122+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package com.dtstack.flinkx.restapi.common;
19+
20+
import java.util.HashMap;
21+
import java.util.Map;
22+
23+
/**
24+
* InnerVaribleFactory
25+
*
26+
* @author by [email protected]
27+
* @Date 2020/9/26
28+
*/
29+
public class InnerVaribleFactory {
30+
31+
private static Map<String, Paramitem> InnerVaribles;
32+
33+
static {
34+
InnerVaribles = new HashMap<>(18);
35+
InnerVaribles.put("uuid", new UuidVarible());
36+
InnerVaribles.put("currentTime", new UuidVarible());
37+
InnerVaribles.put("currenttime", new CurrentTimeVarible());
38+
39+
}
40+
41+
public static Paramitem createInnerVarible(String name) {
42+
return InnerVaribles.get(name);
43+
}
44+
45+
public static boolean isInnerVariable(String name){
46+
return InnerVaribles.containsKey(name);
47+
}
48+
}

0 commit comments

Comments
 (0)