Skip to content

Commit 03f3165

Browse files
authored
Merge pull request #90 from codingapi/dev
Dev
2 parents 23bac1c + 01009a1 commit 03f3165

38 files changed

Lines changed: 665 additions & 295 deletions

flow-engine-framework/src/main/java/com/codingapi/flow/error/ErrorThrow.java

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -24,38 +24,10 @@ public class ErrorThrow {
2424
*/
2525
private List<IFlowOperator> operators;
2626

27-
public static Builder builder() {
28-
return new Builder();
29-
}
30-
27+
/**
28+
* 是否为节点
29+
*/
3130
public boolean isNode() {
32-
return node != null;
33-
}
34-
35-
public static class Builder {
36-
private IFlowNode node;
37-
private List<IFlowOperator> operators;
38-
39-
public Builder node(IFlowNode node) {
40-
this.node = node;
41-
return this;
42-
}
43-
44-
public Builder operators(IFlowOperator... operators) {
45-
this.operators = List.of(operators);
46-
return this;
47-
}
48-
49-
public Builder operators(List<IFlowOperator> operators) {
50-
this.operators = operators;
51-
return this;
52-
}
53-
54-
public ErrorThrow build() {
55-
ErrorThrow errorThrow = new ErrorThrow();
56-
errorThrow.setNode(node);
57-
errorThrow.setOperators(operators);
58-
return errorThrow;
59-
}
31+
return node!=null;
6032
}
6133
}

flow-engine-framework/src/main/java/com/codingapi/flow/form/DataType.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
public enum DataType {
44
STRING,
5-
NUMBER,
5+
LONG,
6+
INTEGER,
7+
DOUBLE,
68
BOOLEAN
79
}

flow-engine-framework/src/main/java/com/codingapi/flow/form/FormData.java

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -114,34 +114,34 @@ private FlowForm getSubFormMeta(String formCode) {
114114
}
115115

116116
/**
117-
* 校验formData
117+
* 校验formData
118118
*/
119119
public void verify() {
120-
for (FormField formField:flowForm.getFields()){
120+
for (FormField formField : flowForm.getFields()) {
121121
Object value = this.dataBody.get(formField.getCode());
122122
Object defaultValue = formField.getDefaultValue();
123-
if(value==null && defaultValue!=null){
124-
this.dataBody.set(formField.getCode(),defaultValue);
123+
if (value == null && defaultValue != null) {
124+
this.dataBody.set(formField.getCode(), defaultValue);
125125
}
126-
if(formField.isRequired()){
127-
if(value==null && defaultValue==null){
126+
if (formField.isRequired()) {
127+
if (value == null && defaultValue == null) {
128128
throw FlowValidationException.fieldNotFound(formField.getName());
129129
}
130130
}
131131
}
132132

133-
if(flowForm.getSubForms()!=null) {
133+
if (flowForm.getSubForms() != null) {
134134
for (FlowForm subForm : flowForm.getSubForms()) {
135-
List<DataBody> subDataList = this.getSubDataBody(subForm.getCode());
136-
for (DataBody subData:subDataList) {
135+
List<DataBody> subDataList = this.getSubDataBody(subForm.getCode());
136+
for (DataBody subData : subDataList) {
137137
for (FormField formField : subForm.getFields()) {
138138
Object value = subData.get(formField.getCode());
139139
Object defaultValue = formField.getDefaultValue();
140-
if(value==null && defaultValue!=null){
141-
subData.set(formField.getCode(),defaultValue);
140+
if (value == null && defaultValue != null) {
141+
subData.set(formField.getCode(), defaultValue);
142142
}
143-
if(formField.isRequired()){
144-
if(value==null && defaultValue==null){
143+
if (formField.isRequired()) {
144+
if (value == null && defaultValue == null) {
145145
throw FlowValidationException.fieldNotFound(formField.getName());
146146
}
147147
}
@@ -199,7 +199,9 @@ public DataBody set(String key, Object value) {
199199
*/
200200
public Object get(String key) {
201201
String id = flowForm.getCode() + "." + key;
202-
return this.data.get(id);
202+
DataType dataType = this.fieldTypes.get(id);
203+
Object value = this.data.get(id);
204+
return ValueConvertorContext.getInstance().convert(dataType,value);
203205
}
204206

205207
/**
@@ -218,4 +220,5 @@ public Map<String, Object> toMapData() {
218220
}
219221
}
220222

223+
221224
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.codingapi.flow.form;
2+
3+
public interface IValueConvertor {
4+
5+
boolean support(DataType dataType);
6+
7+
Object getValue(Object value);
8+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.codingapi.flow.form;
2+
3+
import com.codingapi.flow.form.convertor.*;
4+
import lombok.Getter;
5+
6+
import java.util.ArrayList;
7+
import java.util.List;
8+
9+
public class ValueConvertorContext {
10+
11+
private final List<IValueConvertor> convertors;
12+
13+
@Getter
14+
private final static ValueConvertorContext instance = new ValueConvertorContext();
15+
16+
private ValueConvertorContext(){
17+
this.convertors = new ArrayList<>();
18+
this.init();
19+
}
20+
21+
public void addConvert(IValueConvertor valueConvertor){
22+
this.convertors.add(valueConvertor);
23+
}
24+
25+
public void clear(){
26+
this.convertors.clear();
27+
}
28+
29+
private void init(){
30+
this.convertors.add(new StringValueConvertor());
31+
this.convertors.add(new IntegerValueConvertor());
32+
this.convertors.add(new BooleanValueConvertor());
33+
this.convertors.add(new LongValueConvertor());
34+
this.convertors.add(new DoubleValueConvertor());
35+
}
36+
37+
public Object convert(DataType dataType,Object value){
38+
for (IValueConvertor convertor:this.convertors){
39+
if(convertor.support(dataType)){
40+
return convertor.getValue(value);
41+
}
42+
}
43+
return value;
44+
}
45+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.codingapi.flow.form.convertor;
2+
3+
import com.codingapi.flow.form.DataType;
4+
import com.codingapi.flow.form.IValueConvertor;
5+
6+
public class BooleanValueConvertor implements IValueConvertor {
7+
8+
@Override
9+
public boolean support(DataType dataType) {
10+
return dataType==DataType.BOOLEAN;
11+
}
12+
13+
@Override
14+
public Object getValue(Object value) {
15+
return String.valueOf(value).equals("true");
16+
}
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.codingapi.flow.form.convertor;
2+
3+
import com.codingapi.flow.form.DataType;
4+
import com.codingapi.flow.form.IValueConvertor;
5+
6+
public class DoubleValueConvertor implements IValueConvertor {
7+
8+
@Override
9+
public boolean support(DataType dataType) {
10+
return dataType==DataType.DOUBLE;
11+
}
12+
13+
@Override
14+
public Object getValue(Object value) {
15+
return Double.parseDouble(String.valueOf(value));
16+
}
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.codingapi.flow.form.convertor;
2+
3+
import com.codingapi.flow.form.DataType;
4+
import com.codingapi.flow.form.IValueConvertor;
5+
6+
public class IntegerValueConvertor implements IValueConvertor {
7+
8+
@Override
9+
public boolean support(DataType dataType) {
10+
return dataType==DataType.INTEGER;
11+
}
12+
13+
@Override
14+
public Object getValue(Object value) {
15+
return Integer.parseInt(String.valueOf(value));
16+
}
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.codingapi.flow.form.convertor;
2+
3+
import com.codingapi.flow.form.DataType;
4+
import com.codingapi.flow.form.IValueConvertor;
5+
6+
public class LongValueConvertor implements IValueConvertor {
7+
8+
@Override
9+
public boolean support(DataType dataType) {
10+
return dataType==DataType.LONG;
11+
}
12+
13+
@Override
14+
public Object getValue(Object value) {
15+
return Long.parseLong(String.valueOf(value));
16+
}
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.codingapi.flow.form.convertor;
2+
3+
import com.codingapi.flow.form.DataType;
4+
import com.codingapi.flow.form.IValueConvertor;
5+
6+
public class StringValueConvertor implements IValueConvertor {
7+
8+
@Override
9+
public boolean support(DataType dataType) {
10+
return dataType==DataType.STRING;
11+
}
12+
13+
@Override
14+
public Object getValue(Object value) {
15+
return String.valueOf(value);
16+
}
17+
}

0 commit comments

Comments
 (0)