|
|
@ -360,8 +360,13 @@ public class Criteria implements Predicate { |
|
|
|
boolean exists = ((Boolean) right); |
|
|
|
boolean exists = ((Boolean) right); |
|
|
|
try { |
|
|
|
try { |
|
|
|
Configuration c = Configuration.builder().jsonProvider(ctx.configuration().jsonProvider()).options(Option.REQUIRE_PROPERTIES).build(); |
|
|
|
Configuration c = Configuration.builder().jsonProvider(ctx.configuration().jsonProvider()).options(Option.REQUIRE_PROPERTIES).build(); |
|
|
|
((Path)left).evaluate(ctx.item(), ctx.root(), c).getValue(); |
|
|
|
Object value = ((Path) left).evaluate(ctx.item(), ctx.root(), c).getValue(); |
|
|
|
return exists; |
|
|
|
if(exists){ |
|
|
|
|
|
|
|
return (value != null); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return (value == null); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} catch (PathNotFoundException e) { |
|
|
|
} catch (PathNotFoundException e) { |
|
|
|
return !exists; |
|
|
|
return !exists; |
|
|
|
} |
|
|
|
} |
|
|
@ -654,7 +659,8 @@ public class Criteria implements Predicate { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static boolean isPath(String string){ |
|
|
|
private static boolean isPath(String string){ |
|
|
|
return (string != null && (string.startsWith("$") || string.startsWith("@"))); |
|
|
|
return (string != null |
|
|
|
|
|
|
|
&& (string.startsWith("$") || string.startsWith("@") || string.startsWith("!@"))); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static boolean isString(String string){ |
|
|
|
private static boolean isString(String string){ |
|
|
@ -717,8 +723,13 @@ public class Criteria implements Predicate { |
|
|
|
Object rightPrepared = right; |
|
|
|
Object rightPrepared = right; |
|
|
|
Path leftPath = null; |
|
|
|
Path leftPath = null; |
|
|
|
Path rightPath = null; |
|
|
|
Path rightPath = null; |
|
|
|
|
|
|
|
boolean existsCheck = true; |
|
|
|
|
|
|
|
|
|
|
|
if(isPath(left)){ |
|
|
|
if(isPath(left)){ |
|
|
|
|
|
|
|
if(left.charAt(0) == '!'){ |
|
|
|
|
|
|
|
existsCheck = false; |
|
|
|
|
|
|
|
left = left.substring(1); |
|
|
|
|
|
|
|
} |
|
|
|
leftPath = PathCompiler.compile(left); |
|
|
|
leftPath = PathCompiler.compile(left); |
|
|
|
if(!leftPath.isDefinite()){ |
|
|
|
if(!leftPath.isDefinite()){ |
|
|
|
throw new InvalidPathException("the predicate path: " + left + " is not definite"); |
|
|
|
throw new InvalidPathException("the predicate path: " + left + " is not definite"); |
|
|
@ -731,6 +742,9 @@ public class Criteria implements Predicate { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(isPath(right)){ |
|
|
|
if(isPath(right)){ |
|
|
|
|
|
|
|
if(right.charAt(0) == '!'){ |
|
|
|
|
|
|
|
throw new InvalidPathException("Invalid negation! Can only be used for existence check e.g [?(!@.foo)]"); |
|
|
|
|
|
|
|
} |
|
|
|
rightPath = PathCompiler.compile(right); |
|
|
|
rightPath = PathCompiler.compile(right); |
|
|
|
if(!rightPath.isDefinite()){ |
|
|
|
if(!rightPath.isDefinite()){ |
|
|
|
throw new InvalidPathException("the predicate path: " + right + " is not definite"); |
|
|
|
throw new InvalidPathException("the predicate path: " + right + " is not definite"); |
|
|
@ -743,7 +757,7 @@ public class Criteria implements Predicate { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(leftPath != null && operator.isEmpty()){ |
|
|
|
if(leftPath != null && operator.isEmpty()){ |
|
|
|
return Criteria.where(leftPath).exists(true); |
|
|
|
return Criteria.where(leftPath).exists(existsCheck); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
return new Criteria(leftPrepared, CriteriaType.parse(operator), rightPrepared); |
|
|
|
return new Criteria(leftPrepared, CriteriaType.parse(operator), rightPrepared); |
|
|
|
} |
|
|
|
} |
|
|
|