Skip to content
Merged
2 changes: 1 addition & 1 deletion providers/flagd/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
<dependency>
<groupId>io.github.jamsesso</groupId>
<artifactId>json-logic-java</artifactId>
<version>1.0.9</version>
<version>1.1.0</version>
</dependency>

<!-- Override gson usage of json-logic-java-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public String key() {
return "fractional";
}

public Object evaluate(List arguments, Object data) throws JsonLogicEvaluationException {
public Object evaluate(List arguments, Object data, String jsonPath) throws JsonLogicEvaluationException {
if (arguments.size() < 2) {
return null;
}
Expand Down Expand Up @@ -53,7 +53,7 @@ public Object evaluate(List arguments, Object data) throws JsonLogicEvaluationEx

try {
for (Object dist : distibutions) {
FractionProperty fractionProperty = new FractionProperty(dist);
FractionProperty fractionProperty = new FractionProperty(dist, jsonPath);
propertyList.add(fractionProperty);
totalWeight += fractionProperty.getWeight();
}
Expand All @@ -63,11 +63,11 @@ public Object evaluate(List arguments, Object data) throws JsonLogicEvaluationEx
}

// find distribution
return distributeValue(bucketBy, propertyList, totalWeight);
return distributeValue(bucketBy, propertyList, totalWeight, jsonPath);
}

private static String distributeValue(
final String hashKey, final List<FractionProperty> propertyList, int totalWeight)
final String hashKey, final List<FractionProperty> propertyList, int totalWeight, String jsonPath)
throws JsonLogicEvaluationException {
byte[] bytes = hashKey.getBytes(StandardCharsets.UTF_8);
int mmrHash = MurmurHash3.hash32x86(bytes, 0, bytes.length, 0);
Expand All @@ -83,7 +83,7 @@ private static String distributeValue(
}

// this shall not be reached
throw new JsonLogicEvaluationException("Unable to find a correct bucket");
throw new JsonLogicEvaluationException("Unable to find a correct bucket", jsonPath);
}

@Getter
Expand All @@ -96,27 +96,28 @@ protected final void finalize() {
// DO NOT REMOVE, spotbugs: CT_CONSTRUCTOR_THROW
}

FractionProperty(final Object from) throws JsonLogicException {
FractionProperty(final Object from, String jsonPath) throws JsonLogicException {
if (!(from instanceof List<?>)) {
throw new JsonLogicException("Property is not an array");
throw new JsonLogicException("Property is not an array", jsonPath);
}

final List<?> array = (List) from;

if (array.isEmpty()) {
throw new JsonLogicException("Fraction property needs at least one element");
throw new JsonLogicException("Fraction property needs at least one element", jsonPath);
}

// first must be a string
if (!(array.get(0) instanceof String)) {
throw new JsonLogicException("First element of the fraction property is not a string variant");
throw new JsonLogicException(
"First element of the fraction property is not a string variant", jsonPath);
}

variant = (String) array.get(0);
if (array.size() >= 2) {
// second element must be a number
if (!(array.get(1) instanceof Number)) {
throw new JsonLogicException("Second element of the fraction property is not a number");
throw new JsonLogicException("Second element of the fraction property is not a number", jsonPath);
}
weight = ((Number) array.get(1)).intValue();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public String key() {
return "sem_ver";
}

public Object evaluate(List arguments, Object data) throws JsonLogicEvaluationException {
public Object evaluate(List arguments, Object data, String jsonPath) throws JsonLogicEvaluationException {

if (arguments.size() != 3) {
log.debug("Incorrect number of arguments for sem_ver operator");
Expand Down Expand Up @@ -75,10 +75,10 @@ public Object evaluate(List arguments, Object data) throws JsonLogicEvaluationEx
return null;
}

return compare(arg2Parsed, arg1Parsed, arg3Parsed);
return compare(arg2Parsed, arg1Parsed, arg3Parsed, jsonPath);
}

private static boolean compare(final String operator, final Semver arg1, final Semver arg2)
private static boolean compare(final String operator, final Semver arg1, final Semver arg2, final String jsonPath)
throws JsonLogicEvaluationException {

int comp = arg1.compareTo(arg2);
Expand All @@ -102,7 +102,7 @@ private static boolean compare(final String operator, final Semver arg1, final S
return arg1.getMinor() == arg2.getMinor() && arg1.getMajor() == arg2.getMajor();
default:
throw new JsonLogicEvaluationException(
String.format("Unsupported operator received. Operator: %s", operator));
String.format("Unsupported operator received. Operator: %s", operator), jsonPath);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public String key() {
return type.key;
}

public Object evaluate(List arguments, Object data) throws JsonLogicEvaluationException {
public Object evaluate(List arguments, Object data, String jsonPath) throws JsonLogicEvaluationException {
if (arguments.size() != 2) {
log.debug("Incorrect number of arguments for String comparison operator");
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void validate_emptyJson_targetingReturned(@ConvertWith(FileContentConverter.clas
data.put(FLAGD_PROPS_KEY, flagdProperties);

// when
Object evaluate = fractional.evaluate(testData.rule, data);
Object evaluate = fractional.evaluate(testData.rule, data, "path");

// then
assertEquals(testData.result, evaluate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void testValidCases(List<String> args) throws JsonLogicEvaluationException {
final SemVer semVer = new SemVer();

// when
Object result = semVer.evaluate(args, new Object());
Object result = semVer.evaluate(args, new Object(), "jsonPath");

// then
if (!(result instanceof Boolean)) {
Expand All @@ -58,6 +58,6 @@ void testInvalidCases(List args) throws JsonLogicEvaluationException {
final SemVer semVer = new SemVer();

// then
assertNull(semVer.evaluate(args, new Object()));
assertNull(semVer.evaluate(args, new Object(), "jsonPath"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public void startsWithEvaluation() throws JsonLogicEvaluationException {
final StringComp startsWith = new StringComp(StringComp.Type.STARTS_WITH);

// when
Object result = startsWith.evaluate(Arrays.asList("abc@123.com", "abc"), new Object());
Object result = startsWith.evaluate(Arrays.asList("abc@123.com", "abc"), new Object(), "jsonPath");

// then
if (!(result instanceof Boolean)) {
Expand All @@ -31,7 +31,7 @@ public void endsWithEvaluation() throws JsonLogicEvaluationException {
final StringComp endsWith = new StringComp(StringComp.Type.ENDS_WITH);

// when
Object result = endsWith.evaluate(Arrays.asList("abc@123.com", "123.com"), new Object());
Object result = endsWith.evaluate(Arrays.asList("abc@123.com", "123.com"), new Object(), "jsonPath");

// then
if (!(result instanceof Boolean)) {
Expand All @@ -47,7 +47,7 @@ public void invalidTypeCheckArg1() throws JsonLogicEvaluationException {
final StringComp operator = new StringComp(StringComp.Type.STARTS_WITH);

// when
Object result = operator.evaluate(Arrays.asList(1230, "12"), new Object());
Object result = operator.evaluate(Arrays.asList(1230, "12"), new Object(), "jsonPath");

// then
assertThat(result).isNull();
Expand All @@ -59,7 +59,7 @@ public void invalidTypeCheckArg2() throws JsonLogicEvaluationException {
final StringComp operator = new StringComp(StringComp.Type.STARTS_WITH);

// when
Object result = operator.evaluate(Arrays.asList("abc@123.com", 123), new Object());
Object result = operator.evaluate(Arrays.asList("abc@123.com", 123), new Object(), "jsonPath");

// then
assertThat(result).isNull();
Expand All @@ -71,7 +71,7 @@ public void invalidNumberOfArgs() throws JsonLogicEvaluationException {
final StringComp operator = new StringComp(StringComp.Type.STARTS_WITH);

// when
Object result = operator.evaluate(Arrays.asList("123", "12", "1"), new Object());
Object result = operator.evaluate(Arrays.asList("123", "12", "1"), new Object(), "jsonPath");

// then
assertThat(result).isNull();
Expand Down
2 changes: 1 addition & 1 deletion providers/jsonlogic-eval-provider/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<dependency>
<groupId>io.github.jamsesso</groupId>
<artifactId>json-logic-java</artifactId>
<version>1.0.9</version>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
Expand Down