REfactoring code to support logical and consitional operator
This commit is contained in:
parent
5b3db43248
commit
0d5e55472c
|
@ -97,53 +97,49 @@ public abstract class JsonQueryERElement {
|
|||
stringBuffer.append(queryLogicalOperator.getLogicalOperator());
|
||||
}
|
||||
|
||||
if(QueryLogicalOperator.getOperators().contains(fieldName)) {
|
||||
QueryLogicalOperator innnerQueryLogicalOperator = QueryLogicalOperator.getQueryLogicalOperator(fieldName);
|
||||
JsonNode node = objectNode.get(fieldName);
|
||||
stringBuffer.append(addConstraint(node, innnerQueryLogicalOperator, fieldNamePrefix));
|
||||
}else {
|
||||
stringBuffer.append(getNameValueToMatch(objectNode, fieldName, fieldNamePrefix));
|
||||
}
|
||||
JsonNode node = objectNode.get(fieldName);
|
||||
stringBuffer.append(evaluateNode(node, fieldName, fieldNamePrefix));
|
||||
}
|
||||
|
||||
return stringBuffer;
|
||||
}
|
||||
|
||||
private StringBuffer getNameValueToMatch(JsonNode jsonNode, String fieldName, String fieldNamePrefix) throws InvalidQueryException {
|
||||
|
||||
protected StringBuffer evaluateNode(JsonNode jsonNode, String fieldName, String fieldNamePrefix) throws InvalidQueryException {
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
|
||||
JsonNode gotJoJsonNode = jsonNode.get(fieldName);
|
||||
if(QueryLogicalOperator.getOperators().contains(fieldName)) {
|
||||
QueryLogicalOperator queryLogicalOperator = QueryLogicalOperator.getQueryLogicalOperator(fieldName);
|
||||
stringBuffer.append(addConstraint(jsonNode, queryLogicalOperator, fieldNamePrefix));
|
||||
return stringBuffer;
|
||||
}
|
||||
|
||||
if(gotJoJsonNode.isContainerNode()) {
|
||||
if(QueryConditionalOperator.getOperators().contains(fieldName)) {
|
||||
QueryConditionalOperator queryConditionalOperator = QueryConditionalOperator.getQueryComparisonOperator(fieldName);
|
||||
|
||||
if(gotJoJsonNode.isArray()) {
|
||||
throw new InvalidQueryException("Array not supported for " + fieldName);
|
||||
}
|
||||
|
||||
if(gotJoJsonNode.isObject()) {
|
||||
|
||||
for(QueryConditionalOperator queryComparisonOperator : QueryConditionalOperator.values()) {
|
||||
if(gotJoJsonNode.has(queryComparisonOperator.operator)) {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
|
||||
StringBuffer newPrefix = new StringBuffer();
|
||||
if(fieldNamePrefix!=null) {
|
||||
newPrefix.append(fieldNamePrefix);
|
||||
newPrefix.append(".");
|
||||
}
|
||||
newPrefix.append(fieldName);
|
||||
|
||||
stringBuffer.append(addConstraint(gotJoJsonNode, null, newPrefix.toString()));
|
||||
return stringBuffer;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
addNameToCompare(stringBuffer, fieldName, fieldNamePrefix);
|
||||
String value = jsonNode.get(fieldName).asText();
|
||||
addValueToMatch(stringBuffer, gotJoJsonNode, value);
|
||||
if(jsonNode.isArray()) {
|
||||
return stringBuffer;
|
||||
}
|
||||
|
||||
if(jsonNode.isObject()) {
|
||||
StringBuffer newPrefix = new StringBuffer();
|
||||
if(fieldNamePrefix!=null) {
|
||||
newPrefix.append(fieldNamePrefix);
|
||||
newPrefix.append(".");
|
||||
}
|
||||
newPrefix.append(fieldName);
|
||||
|
||||
stringBuffer.append(addConstraint(jsonNode, null, newPrefix.toString()));
|
||||
return stringBuffer;
|
||||
}
|
||||
|
||||
if(jsonNode.isTextual() || jsonNode.isNumber()) {
|
||||
addNameToCompare(stringBuffer, fieldName, fieldNamePrefix);
|
||||
String value = jsonNode.asText();
|
||||
addValueToMatch(stringBuffer, jsonNode, value);
|
||||
}
|
||||
|
||||
return stringBuffer;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue