Skip to content

Commit 4073c97

Browse files
committed
refactor: parse view model
1 parent 3968935 commit 4073c97

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

server/src/main/java/datart/server/service/impl/DataProviderServiceImpl.java

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package datart.server.service.impl;
2020

2121
import com.alibaba.fastjson.JSON;
22+
import com.alibaba.fastjson.JSONArray;
2223
import com.alibaba.fastjson.JSONObject;
2324
import com.fasterxml.jackson.databind.DeserializationFeature;
2425
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -412,9 +413,33 @@ private Map<String, Column> parseSchema(String model) {
412413
}
413414

414415
JSONObject jsonObject = JSON.parseObject(model);
415-
for (String key : jsonObject.keySet()) {
416-
ValueType type = ValueType.valueOf(jsonObject.getJSONObject(key).getString("type"));
417-
schema.put(key, new Column(key, type));
416+
try {
417+
if (jsonObject.containsKey("hierarchy")) {
418+
jsonObject = jsonObject.getJSONObject("hierarchy");
419+
for (String key : jsonObject.keySet()) {
420+
JSONObject item = jsonObject.getJSONObject(key);
421+
if (item.containsKey("children")) {
422+
JSONArray children = item.getJSONArray("children");
423+
if (children != null && children.size() > 0) {
424+
for (int i = 0; i < children.size(); i++) {
425+
JSONObject child = children.getJSONObject(i);
426+
schema.put(child.getString("name"), new Column(child.getString("name"), ValueType.valueOf(child.getString("type"))));
427+
}
428+
}
429+
} else {
430+
schema.put(key, new Column(item.getString("name"), ValueType.valueOf(item.getString("type"))));
431+
}
432+
}
433+
} else {
434+
// 兼容1.0.0-beta.1以前的版本
435+
jsonObject = jsonObject.getJSONObject("columns");
436+
for (String key : jsonObject.keySet()) {
437+
ValueType type = ValueType.valueOf(jsonObject.getJSONObject(key).getString("type"));
438+
schema.put(key, new Column(key, type));
439+
}
440+
}
441+
} catch (Exception e) {
442+
log.error("view model parse error", e);
418443
}
419444
return schema;
420445
}

0 commit comments

Comments
 (0)