Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -316,16 +316,10 @@ public boolean test(HMStacAsset asset) { // Assuming for now that "eo:bands" wou
return false;
}
};
}

if (resource.getParameters().get("jsonSelector", String.class) != null) {
// based on the JSON Expression on JSONSelector and JSONValue;
} else if (resource.getParameters().get("jsonSelector", String.class) != null) {
// based on the JSON Expression on JSONSelector and JSONValue
try {
if (assetPredicate != null) {
assetPredicate = assetPredicate.and(getAssetPredicateFromJSONSelector(resource)); // Predicate based on JSONPath AND the AssetID
} else {
assetPredicate = getAssetPredicateFromJSONSelector(resource);
}
assetPredicate = getAssetPredicate(resource);
} catch (Exception e) {
throw new KlabResourceAccessException("Couldn't form a predicate with the JSON Expressions");
}
Expand Down Expand Up @@ -386,7 +380,7 @@ public boolean test(HMStacAsset asset) { // Assuming for now that "eo:bands" wou
}
Predicate<HMStacAsset> predicate;
try {
predicate = getAssetPredicateFromJSONSelector(resource);
predicate = getAssetPredicate(resource);
} catch (KlabIllegalArgumentException e) {
manager.close();
throw e;
Expand Down Expand Up @@ -605,7 +599,11 @@ public boolean test(HMStacAsset asset) { // Assuming for now that "eo:bands" wou
}
}

private Predicate<HMStacAsset> getAssetPredicateFromJSONSelector(IResource resource) {
private Predicate<HMStacAsset> getAssetPredicate(IResource resource) {
String assetId = resource.getParameters().get("asset", String.class);
if (assetId != null) {
return STACPathExpression.STACAssetPredicate.fromHMStacAssetId(assetId);
}
String jsonSelector = resource.getParameters().get("jsonSelector", String.class);
String jsonValue = resource.getParameters().get("jsonValue", String.class);
if (jsonSelector != null && !jsonSelector.isBlank() && jsonValue != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,19 +282,10 @@ public static <T> Predicate<T> fromJsonPath(String jsonPath, String expectedValu
}

JsonNode node = jsonNodeExtractor.apply(object);

if (node == null || node.isNull() || node.isMissingNode()) {
return false;
}

/*
* Check if {"a.b": expectedValue} exists and also {"a": { "b": expectedValue }}
*/

JsonNode directValue = node.get(jsonPath);
if (directValue != null && !directValue.isNull()) {
return expectedValue.equals(directValue.asText());
}

return expression.matches(node, expectedValue);
};
Expand All @@ -309,7 +300,7 @@ public static Predicate<JsonNode> fromJsonNode(String jsonPath, String expectedV
}

public static Predicate<JSONObject> fromKongJsonObject(String jsonPath, String expectedValue) {
return fromJsonPath(jsonPath, expectedValue, STACAssetPredicate::toJsonNode);
return fromJsonPath(jsonPath, expectedValue, STACAssetPredicate::toJsonNode);
}

private static JsonNode toJsonNode(JSONObject jsonObject) {
Expand Down
Loading