forked from WeBankFinTech/Exchangis
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request WeBankFinTech#179 from Davidhua1996/dev-1.0.0
LGTM
- Loading branch information
Showing
102 changed files
with
2,446 additions
and
1,299 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 35 additions & 6 deletions
41
...ce-core/src/main/java/com/webank/wedatasphere/exchangis/datasource/core/ui/ElementUI.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,51 @@ | ||
package com.webank.wedatasphere.exchangis.datasource.core.ui; | ||
|
||
public interface ElementUI<T> { | ||
String TEXTAREA = "TEXTAREA"; | ||
String INPUT = "INPUT"; | ||
String OPTION = "OPTION"; | ||
String MAP = "MAP"; | ||
import java.util.Map; | ||
|
||
public interface ElementUI<T> { | ||
/** | ||
* Type enum | ||
*/ | ||
enum Type { | ||
NONE, TEXTAREA, INPUT, OPTION, MAP | ||
} | ||
|
||
/** | ||
* Field name | ||
* @return string | ||
*/ | ||
String getField(); | ||
|
||
/** | ||
* Label | ||
* @return label string | ||
*/ | ||
String getLabel(); | ||
|
||
// 类型 | ||
/** | ||
* Type name | ||
* @return string | ||
*/ | ||
String getType(); | ||
|
||
Integer getSort(); | ||
|
||
/** | ||
* Value store | ||
* @return | ||
*/ | ||
T getValue(); | ||
|
||
/** | ||
* Default value | ||
* @return | ||
*/ | ||
T getDefaultValue(); | ||
|
||
/** | ||
* Get value from params | ||
* @param params | ||
* @return | ||
*/ | ||
void setValue(Map<String, Object> params); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
...com/webank/wedatasphere/exchangis/datasource/core/ui/builder/DefaultElementUIFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package com.webank.wedatasphere.exchangis.datasource.core.ui.builder; | ||
|
||
import com.webank.wedatasphere.exchangis.datasource.core.ui.ElementUI; | ||
import com.webank.wedatasphere.exchangis.datasource.core.ui.InputElementUI; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
import java.util.function.Function; | ||
|
||
/** | ||
* Default element factory | ||
*/ | ||
public class DefaultElementUIFactory implements ElementUIFactory{ | ||
/** | ||
* Element builders holder | ||
*/ | ||
private Map<Identify, Function<Object, ? extends ElementUI<?>>> builders = new HashMap<>(); | ||
|
||
|
||
@Override | ||
@SuppressWarnings("unchecked") | ||
public <T, R> void register(String type, Function<T, ? extends ElementUI<R>> builder, Class<?> inputType) { | ||
builders.putIfAbsent(new Identify(type, inputType), (Function<Object, ? extends ElementUI<?>>) builder); | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("unchecked") | ||
public <R> ElementUI<R> createElement(String type, Object input, Class<?> inputType) { | ||
Identify identify = new Identify(type, inputType); | ||
AtomicReference<ElementUI<R>> elementUI = new AtomicReference<>(); | ||
Optional.ofNullable(builders.get(identify)).ifPresent(builder -> { | ||
elementUI.set((ElementUI<R>) builder.apply(input)); | ||
}); | ||
return elementUI.get(); | ||
} | ||
|
||
/** | ||
* Identify for element builder | ||
*/ | ||
private static class Identify{ | ||
|
||
/** | ||
* Type | ||
*/ | ||
private final String type; | ||
|
||
/** | ||
* Input class | ||
*/ | ||
private final Class<?> inputClass; | ||
|
||
public Identify(String type, Class<?> inputClass){ | ||
this.type = type; | ||
this.inputClass = inputClass; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Identify identify = (Identify) o; | ||
return Objects.equals(type, identify.type) && Objects.equals(inputClass, identify.inputClass); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(type, inputClass); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Identify{" + | ||
"type='" + type + '\'' + | ||
", inputClass=" + inputClass.getCanonicalName() + | ||
'}'; | ||
} | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
...n/java/com/webank/wedatasphere/exchangis/datasource/core/ui/builder/ElementUIFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.webank.wedatasphere.exchangis.datasource.core.ui.builder; | ||
|
||
import com.webank.wedatasphere.exchangis.datasource.core.ui.ElementUI; | ||
|
||
import java.util.function.Function; | ||
|
||
/** | ||
* Element factory | ||
*/ | ||
public interface ElementUIFactory { | ||
|
||
/** | ||
* Register the element builder | ||
* @param type type | ||
* @param builder builder | ||
* @param inputType input type | ||
* @param <T> T | ||
* @param <R> R | ||
*/ | ||
<T, R> void register(String type, Function<T, ? extends ElementUI<R>> builder, Class<?> inputType); | ||
|
||
|
||
/** | ||
* Create element | ||
* @param type type | ||
* @param input input object | ||
* @param <R> element value type | ||
* @return element | ||
*/ | ||
<R>ElementUI<R> createElement(String type, Object input, Class<?> inputType); | ||
} |
49 changes: 49 additions & 0 deletions
49
.../com/webank/wedatasphere/exchangis/datasource/core/ui/builder/SpringElementUIFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.webank.wedatasphere.exchangis.datasource.core.ui.builder; | ||
|
||
import com.webank.wedatasphere.exchangis.datasource.core.ui.ElementUI; | ||
import com.webank.wedatasphere.exchangis.datasource.core.ui.InputElementUI; | ||
import com.webank.wedatasphere.exchangis.datasource.core.ui.MapElementUI; | ||
import com.webank.wedatasphere.exchangis.datasource.core.ui.OptionElementUI; | ||
import org.springframework.stereotype.Component; | ||
|
||
import javax.annotation.PostConstruct; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.function.Function; | ||
|
||
/** | ||
* Default element factory in spring | ||
*/ | ||
@Component | ||
public class SpringElementUIFactory extends DefaultElementUIFactory{ | ||
|
||
@PostConstruct | ||
public void init(){ | ||
super.register(ElementUI.Type.MAP.name(), (Function<Map<String, Object>, MapElementUI>) params -> | ||
setElementValue(new MapElementUI(), params), Map.class); | ||
super.register(ElementUI.Type.INPUT.name(), (Function<Map<String, Object>, InputElementUI>) params -> | ||
setElementValue(new InputElementUI(), params), Map.class); | ||
super.register(ElementUI.Type.OPTION.name(), (Function<Map<String, Object>, OptionElementUI>) params -> | ||
setElementValue(new OptionElementUI(), params), Map.class); | ||
} | ||
|
||
/** | ||
* Set the params into element and return | ||
* @param element element | ||
* @param params params Map | ||
* @param <R> R | ||
* @return | ||
*/ | ||
private <R extends ElementUI<?>>R setElementValue(R element, Map<String, Object> params){ | ||
element.setValue(params); | ||
return element; | ||
} | ||
|
||
public static void main(String[] args){ | ||
SpringElementUIFactory elementUIFactory = new SpringElementUIFactory(); | ||
elementUIFactory.init(); | ||
Map<String, Object> map = new HashMap<>(); | ||
map.putIfAbsent("hello", "world"); | ||
System.out.println(elementUIFactory.createElement(ElementUI.Type.MAP.name(), map, Map.class).getValue()); | ||
} | ||
} |
Oops, something went wrong.