|
@@ -1,6 +1,7 @@
|
|
|
package org.hswebframework.web.workflow.dimension;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import io.vavr.Lazy;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
@@ -10,6 +11,7 @@ import org.springframework.stereotype.Component;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
import java.util.Collection;
|
|
|
+import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -19,32 +21,49 @@ public class DefaultCandidateDimensionParser implements CandidateDimensionParser
|
|
|
@Autowired(required = false)
|
|
|
private List<CandidateDimensionParserStrategy> strategies;
|
|
|
|
|
|
- @Override
|
|
|
- public CandidateDimension parse(DimensionContext context, String jsonConfig) {
|
|
|
- JSONObject jsonObject = JSON.parseObject(jsonConfig);
|
|
|
- String type = jsonObject.getString("dimension");
|
|
|
- CandidateDimensionParserStrategy.StrategyConfig config = jsonObject
|
|
|
- .toJavaObject(CandidateDimensionParserStrategy.StrategyConfig.class);
|
|
|
- if (config.getConfig() == null) {
|
|
|
- config.setConfig(jsonObject);
|
|
|
- }
|
|
|
+ private CandidateDimension parse(DimensionContext context, JSONArray jsonConfig) {
|
|
|
+ List<CandidateDimensionParserStrategy.StrategyConfig> configList = jsonConfig.stream()
|
|
|
+ .filter(json -> json instanceof JSONObject)
|
|
|
+ .map(JSONObject.class::cast)
|
|
|
+ .filter(json -> json.get("dimension") != null && CollectionUtils.isNotEmpty(json.getJSONArray("idList")))
|
|
|
+ .map(json -> {
|
|
|
+ CandidateDimensionParserStrategy.StrategyConfig config = json.toJavaObject(CandidateDimensionParserStrategy.StrategyConfig.class);
|
|
|
+ if (config.getConfig() == null) {
|
|
|
+ config.setConfig(json);
|
|
|
+ }
|
|
|
+ return config;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
|
|
- if (StringUtils.isEmpty(type)
|
|
|
- || CollectionUtils.isEmpty(strategies)
|
|
|
- || CollectionUtils.isEmpty(config.getIdList())) {
|
|
|
+ if (configList.isEmpty()) {
|
|
|
return CandidateDimension.empty;
|
|
|
}
|
|
|
-
|
|
|
return Lazy.val(() -> {
|
|
|
- List<String> list = strategies
|
|
|
- .stream()
|
|
|
- .filter(strategy -> strategy.support(type))
|
|
|
- .map(strategy -> strategy.parse(context, config))
|
|
|
- .filter(CollectionUtils::isNotEmpty)
|
|
|
- .flatMap(Collection::stream)
|
|
|
- .collect(Collectors.toList());
|
|
|
+ List<String> list = configList.stream()
|
|
|
+ .flatMap(config ->
|
|
|
+ strategies
|
|
|
+ .stream()
|
|
|
+ .filter(strategy -> strategy.support(config.getDimension()))
|
|
|
+ .map(strategy -> strategy.parse(context, config))
|
|
|
+ .filter(CollectionUtils::isNotEmpty)
|
|
|
+ .flatMap(Collection::stream)
|
|
|
+ ).collect(Collectors.toList());
|
|
|
+
|
|
|
return (CandidateDimension) () -> list;
|
|
|
}, CandidateDimension.class);
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CandidateDimension parse(DimensionContext context, String jsonConfig) {
|
|
|
+ JSONArray jsonArray;
|
|
|
+ if (jsonConfig.startsWith("[")) {
|
|
|
+ jsonArray = JSON.parseArray(jsonConfig);
|
|
|
+ } else {
|
|
|
+ JSONObject jsonObject = JSON.parseObject(jsonConfig);
|
|
|
+ jsonArray = new JSONArray();
|
|
|
+ jsonArray.add(jsonObject);
|
|
|
+ }
|
|
|
+ return parse(context, jsonArray);
|
|
|
+
|
|
|
+ }
|
|
|
}
|