|
@@ -1,7 +1,9 @@
|
|
|
package com.persagy.ibms.data.sdk.util;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
@@ -71,8 +73,10 @@ public class CheckUtil {
|
|
|
|
|
|
public static void getPropertyBefore_query(Repository Repository, SceneProperty sceneProperty, List<SceneProperty> result) throws Exception {
|
|
|
JSONObject sql_json = JSON.parseObject(sceneProperty.query_sql);
|
|
|
- List<String> refList = query(sql_json);
|
|
|
- for (String refString : refList) {
|
|
|
+ Map<String, Boolean> refList = new HashMap<String, Boolean>();
|
|
|
+ query(sql_json, refList);
|
|
|
+ for (String refString : refList.keySet()) {
|
|
|
+ boolean refInTarget = refList.get(refString);
|
|
|
String[] splits = refString.split("'");
|
|
|
Object parentData;
|
|
|
if (splits[0].startsWith("ancestor_")) {
|
|
@@ -116,27 +120,35 @@ public class CheckUtil {
|
|
|
|
|
|
if (parentData instanceof SceneProperty) {
|
|
|
SceneProperty tmpProperty = (SceneProperty) parentData;
|
|
|
- addAll(result, getProperty(tmpProperty, splits, 1));
|
|
|
+ addAll(result, getProperty(tmpProperty, splits, 1, refInTarget));
|
|
|
} else {
|
|
|
SceneObject tmpObject = (SceneObject) parentData;
|
|
|
- addAll(result, getProperty(tmpObject, splits, 1));
|
|
|
+ addAll(result, getProperty(tmpObject, splits, 1, refInTarget));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private static List<SceneProperty> getProperty(SceneObject parentData, String[] splits, int splits_index) throws Exception {
|
|
|
+ private static List<SceneProperty> getProperty(SceneObject parentData, String[] splits, int splits_index, boolean refInTarget) throws Exception {
|
|
|
String name = splits[splits_index];
|
|
|
+ SceneProperty findSP = null;
|
|
|
for (SceneProperty spInner : parentData.propertyList) {
|
|
|
if (spInner.propertyName.equals(name)) {
|
|
|
- return getProperty(spInner, splits, splits_index + 1);
|
|
|
+ findSP = spInner;
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- throw new Exception();
|
|
|
+ if (findSP != null) {
|
|
|
+ return getProperty(findSP, splits, splits_index + 1, refInTarget);
|
|
|
+ } else {
|
|
|
+ throw new Exception();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- private static List<SceneProperty> getProperty(SceneProperty parentData, String[] splits, int splits_index) throws Exception {
|
|
|
+ private static List<SceneProperty> getProperty(SceneProperty parentData, String[] splits, int splits_index, boolean refInTarget)
|
|
|
+ throws Exception {
|
|
|
List<SceneProperty> result = new ArrayList<SceneProperty>();
|
|
|
+ boolean doit = true;
|
|
|
if (parentData.propertyValueType.equals("static") && parentData.propertyValueSchema.equals("JSONArray")) {
|
|
|
String split = splits[splits_index];
|
|
|
int index_ = split.indexOf('=');
|
|
@@ -155,84 +167,95 @@ public class CheckUtil {
|
|
|
}
|
|
|
}
|
|
|
if (matchInner) {
|
|
|
- List<SceneProperty> resultInner = getProperty(soInner, splits, splits_index + 1);
|
|
|
+ List<SceneProperty> resultInner = getProperty(soInner, splits, splits_index + 1, refInTarget);
|
|
|
result.addAll(resultInner);
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
for (SceneObject soInner : parentData.static_array) {
|
|
|
- List<SceneProperty> resultInner = getProperty(soInner, splits, splits_index);
|
|
|
+ List<SceneProperty> resultInner = getProperty(soInner, splits, splits_index, refInTarget);
|
|
|
result.addAll(resultInner);
|
|
|
}
|
|
|
}
|
|
|
- return result;
|
|
|
} else if (parentData.propertyValueType.equals("deamon")) {
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- if (splits_index == splits.length) {
|
|
|
result.add(parentData);
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- String name = splits[splits_index];
|
|
|
- if (parentData.query_attached != null) {
|
|
|
- for (SceneProperty spInner : parentData.query_attached) {
|
|
|
- if (spInner.propertyName.equals(name)) {
|
|
|
- return getProperty(spInner, splits, splits_index + 1);
|
|
|
+ } else if (splits_index == splits.length) {
|
|
|
+ result.add(parentData);
|
|
|
+ } else {
|
|
|
+ String name = splits[splits_index];
|
|
|
+ SceneProperty sp_attach = null;
|
|
|
+ if (parentData.query_attached != null) {
|
|
|
+ for (SceneProperty spInner : parentData.query_attached) {
|
|
|
+ if (spInner.propertyName.equals(name)) {
|
|
|
+ sp_attach = spInner;
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- if (parentData.custom_object != null) {
|
|
|
- for (SceneProperty spInner : parentData.custom_object.propertyList) {
|
|
|
- if (spInner.propertyName.equals(name)) {
|
|
|
- return getProperty(spInner, splits, splits_index + 1);
|
|
|
+ if (sp_attach != null) {
|
|
|
+ result = getProperty(sp_attach, splits, splits_index + 1, refInTarget);
|
|
|
+ } else {
|
|
|
+ SceneProperty sp_custom = null;
|
|
|
+ if (parentData.custom_object != null) {
|
|
|
+ for (SceneProperty spInner : parentData.custom_object.propertyList) {
|
|
|
+ if (spInner.propertyName.equals(name)) {
|
|
|
+ sp_custom = spInner;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (sp_custom != null) {
|
|
|
+ result = getProperty(sp_custom, splits, splits_index + 1, refInTarget);
|
|
|
+ } else if (parentData.propertyValueType.equals("query") && splits_index == splits.length - 1) {
|
|
|
+ doit = false;
|
|
|
+ result.add(parentData);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- if (parentData.propertyValueType.equals("query") && splits_index == splits.length - 1) {
|
|
|
- result.add(parentData);
|
|
|
- return result;
|
|
|
- }
|
|
|
|
|
|
// throw new Exception();
|
|
|
+ if (doit && refInTarget && splits_index + 1 == splits.length) {
|
|
|
+ List<SceneProperty> tmpList = new ArrayList<SceneProperty>();
|
|
|
+ for (SceneProperty spTmp : result) {
|
|
|
+ if (spTmp.query_attached != null) {
|
|
|
+ for (SceneProperty spTmp2 : spTmp.query_attached) {
|
|
|
+ if (spTmp2.propertyValueType.equals("query")
|
|
|
+ && (!spTmp2.propertyValueSchema.equals("JSONObject") && !spTmp2.propertyValueSchema.equals("JSONArray"))) {
|
|
|
+ tmpList.add(spTmp2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (SceneProperty spTmp : tmpList) {
|
|
|
+ result.add(spTmp);
|
|
|
+ }
|
|
|
+ }
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- public static List<String> query(JSONObject sql_json) {
|
|
|
+ public static void query(JSONObject sql_json, Map<String, Boolean> result) {
|
|
|
if (sql_json.get("QueryType") != null) {
|
|
|
- List<String> result = new ArrayList<String>();
|
|
|
// 扫描备选集合
|
|
|
if (sql_json.containsKey("Target")) {
|
|
|
- List<String> resultTmp = parseSet(sql_json.get("Target"));
|
|
|
- result.addAll(resultTmp);
|
|
|
+ parseSet(sql_json.get("Target"), result);
|
|
|
}
|
|
|
|
|
|
// 扫描查询条件
|
|
|
JSONObject CriteriaObject = (JSONObject) sql_json.get("Criteria");
|
|
|
{
|
|
|
- List<String> resultTmp = parseCriteria(CriteriaObject);
|
|
|
- result.addAll(resultTmp);
|
|
|
+ parseCriteria(CriteriaObject, result);
|
|
|
}
|
|
|
|
|
|
// 扫描返回列
|
|
|
if (sql_json.get("ReturnColumns") != null) {
|
|
|
- List<String> resultTmp = parseSet(sql_json.get("ReturnColumns"));
|
|
|
- result.addAll(resultTmp);
|
|
|
+ parseSet(sql_json.get("ReturnColumns"), result);
|
|
|
}
|
|
|
-
|
|
|
- return result;
|
|
|
} else if (sql_json.get("SetOperator") != null) {
|
|
|
- List<String> result = parseSet(sql_json);
|
|
|
- return result;
|
|
|
- } else {
|
|
|
- List<String> result = new ArrayList<String>();
|
|
|
- return result;
|
|
|
+ parseSet(sql_json, result);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private static List<String> parseCriteria(JSONObject CriteriaObject) {
|
|
|
- List<String> result = new ArrayList<String>();
|
|
|
+ private static void parseCriteria(JSONObject CriteriaObject, Map<String, Boolean> result) {
|
|
|
Object LogicOperator = CriteriaObject.get("LogicOperator");
|
|
|
if (LogicOperator != null) {
|
|
|
String LogicOperatorString = (LogicOperator).toString();
|
|
@@ -240,13 +263,11 @@ public class CheckUtil {
|
|
|
JSONArray Criterias = (JSONArray) CriteriaObject.get("Criterias");
|
|
|
for (int i = 0; i < Criterias.size(); i++) {
|
|
|
JSONObject CriteriaObjectInner = (JSONObject) Criterias.get(i);
|
|
|
- List<String> criteriaInner = parseCriteria(CriteriaObjectInner);
|
|
|
- result.addAll(criteriaInner);
|
|
|
+ parseCriteria(CriteriaObjectInner, result);
|
|
|
}
|
|
|
} else if (LogicOperatorString.equals("not")) {
|
|
|
JSONObject CriteriaObjectInner = (JSONObject) CriteriaObject.get("Criteria");
|
|
|
- List<String> criteriaInner = parseCriteria(CriteriaObjectInner);
|
|
|
- result.addAll(criteriaInner);
|
|
|
+ parseCriteria(CriteriaObjectInner, result);
|
|
|
}
|
|
|
} else {
|
|
|
for (String itemKey : CriteriaObject.keySet()) {
|
|
@@ -257,22 +278,19 @@ public class CheckUtil {
|
|
|
Object itemValueInner = valueInner.get(itemKeyInner);
|
|
|
if (itemKeyInner.equals("ref")) {
|
|
|
String refString = (itemValueInner).toString();
|
|
|
- result.add(refString);
|
|
|
+ result.put(refString, false);
|
|
|
} else if (itemKeyInner.equals("in") || itemKeyInner.equals("notin")) {
|
|
|
- List<String> criteriaInner = parseSet(itemValueInner);
|
|
|
- result.addAll(criteriaInner);
|
|
|
+ parseSet(itemValueInner, result);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- return result;
|
|
|
}
|
|
|
|
|
|
- private static List<String> parseSet(Object setDesc) {
|
|
|
- List<String> result = new ArrayList<String>();
|
|
|
+ private static void parseSet(Object setDesc, Map<String, Boolean> result) {
|
|
|
if (setDesc instanceof JSONArray) {
|
|
|
- return result;
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
JSONObject descSet = (JSONObject) setDesc;
|
|
@@ -280,28 +298,21 @@ public class CheckUtil {
|
|
|
String Source = (descSet.get("Source")).toString();
|
|
|
if (Source.equals("ref")) {
|
|
|
String refString = (descSet.get("ref")).toString();
|
|
|
- result.add(refString);
|
|
|
+ result.put(refString, true);
|
|
|
}
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- if (descSet.get("SetOperator") != null) {
|
|
|
+ } else if (descSet.get("SetOperator") != null) {
|
|
|
String SetOperator = (descSet.get("SetOperator")).toString();
|
|
|
if (SetOperator.equals("add") || SetOperator.equals("merge") || SetOperator.equals("unite")) {
|
|
|
JSONArray SetArray = (JSONArray) descSet.get("SetArray");
|
|
|
for (Object SetArrayItem : SetArray) {
|
|
|
- List<String> resultItem = parseSet(SetArrayItem);
|
|
|
- result.addAll(resultItem);
|
|
|
+ parseSet(SetArrayItem, result);
|
|
|
}
|
|
|
} else if (SetOperator.equals("sub")) {
|
|
|
- result.addAll(parseSet(descSet.get("Set1")));
|
|
|
- result.addAll(parseSet(descSet.get("Set2")));
|
|
|
+ parseSet(descSet.get("Set1"), result);
|
|
|
+ parseSet(descSet.get("Set2"), result);
|
|
|
}
|
|
|
- return result;
|
|
|
} else {
|
|
|
- List<String> resultItem = query(descSet);
|
|
|
- result.addAll(resultItem);
|
|
|
- return result;
|
|
|
+ query(descSet, result);
|
|
|
}
|
|
|
}
|
|
|
}
|