FINERACT-964
bump json-path from 0.9.1 to 2.4.0
This commit is contained in:
committed by
Michael Vorburger ⛑️
parent
610375753c
commit
dc3af0c867
@@ -99,7 +99,7 @@ dependencyManagement {
|
|||||||
dependency 'com.amazonaws:aws-java-sdk-s3:1.11.779'
|
dependency 'com.amazonaws:aws-java-sdk-s3:1.11.779'
|
||||||
dependency 'net.sf.ehcache:ehcache:+'
|
dependency 'net.sf.ehcache:ehcache:+'
|
||||||
dependency 'com.github.spullara.mustache.java:compiler:0.8.12'
|
dependency 'com.github.spullara.mustache.java:compiler:0.8.12'
|
||||||
dependency 'com.jayway.jsonpath:json-path:0.9.1'
|
dependency 'com.jayway.jsonpath:json-path:2.4.0'
|
||||||
dependency 'org.apache.tika:tika-core:1.24.1'
|
dependency 'org.apache.tika:tika-core:1.24.1'
|
||||||
dependency 'org.apache.httpcomponents:httpclient:+'
|
dependency 'org.apache.httpcomponents:httpclient:+'
|
||||||
dependency 'io.swagger:swagger-jersey-jaxrs:1.6.1'
|
dependency 'io.swagger:swagger-jersey-jaxrs:1.6.1'
|
||||||
|
|||||||
+15
-14
@@ -21,7 +21,8 @@ package org.apache.fineract.batch.service;
|
|||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.jayway.jsonpath.JsonModel;
|
import com.jayway.jsonpath.JsonPath;
|
||||||
|
import com.jayway.jsonpath.ReadContext;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
@@ -134,7 +135,7 @@ public class ResolutionHelper {
|
|||||||
// Create a duplicate request
|
// Create a duplicate request
|
||||||
final BatchRequest br = request;
|
final BatchRequest br = request;
|
||||||
|
|
||||||
final JsonModel responseJsonModel = JsonModel.model(parentResponse.getBody());
|
final ReadContext responseCtx = JsonPath.parse(parentResponse.getBody());
|
||||||
|
|
||||||
// Gets the body from current Request as a JsonObject
|
// Gets the body from current Request as a JsonObject
|
||||||
final JsonObject jsonRequestBody = this.fromJsonHelper.parse(request.getBody()).getAsJsonObject();
|
final JsonObject jsonRequestBody = this.fromJsonHelper.parse(request.getBody()).getAsJsonObject();
|
||||||
@@ -145,7 +146,7 @@ public class ResolutionHelper {
|
|||||||
// parameter
|
// parameter
|
||||||
for (Entry<String, JsonElement> element : jsonRequestBody.entrySet()) {
|
for (Entry<String, JsonElement> element : jsonRequestBody.entrySet()) {
|
||||||
final String key = element.getKey();
|
final String key = element.getKey();
|
||||||
final JsonElement value = resolveDependentVariables(element, responseJsonModel);
|
final JsonElement value = resolveDependentVariables(element, responseCtx);
|
||||||
jsonResultBody.add(key, value);
|
jsonResultBody.add(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,7 +168,7 @@ public class ResolutionHelper {
|
|||||||
|
|
||||||
for (String parameter : parameters) {
|
for (String parameter : parameters) {
|
||||||
if (parameter.contains("$.")) {
|
if (parameter.contains("$.")) {
|
||||||
final String resParamValue = responseJsonModel.get(parameter).toString();
|
final String resParamValue = responseCtx.read(parameter).toString();
|
||||||
relativeUrl = relativeUrl.replace(parameter, resParamValue);
|
relativeUrl = relativeUrl.replace(parameter, resParamValue);
|
||||||
br.setRelativeUrl(relativeUrl+queryParams);
|
br.setRelativeUrl(relativeUrl+queryParams);
|
||||||
}
|
}
|
||||||
@@ -177,53 +178,53 @@ public class ResolutionHelper {
|
|||||||
return br;
|
return br;
|
||||||
}
|
}
|
||||||
|
|
||||||
private JsonElement resolveDependentVariables(final Entry<String, JsonElement> entryElement, final JsonModel responseJsonModel) {
|
private JsonElement resolveDependentVariables(final Entry<String, JsonElement> entryElement, final ReadContext responseCtx) {
|
||||||
JsonElement value = null;
|
JsonElement value = null;
|
||||||
|
|
||||||
final JsonElement element = entryElement.getValue();
|
final JsonElement element = entryElement.getValue();
|
||||||
|
|
||||||
if (element.isJsonObject()) {
|
if (element.isJsonObject()) {
|
||||||
final JsonObject jsObject = element.getAsJsonObject();
|
final JsonObject jsObject = element.getAsJsonObject();
|
||||||
value = processJsonObject(jsObject, responseJsonModel);
|
value = processJsonObject(jsObject, responseCtx);
|
||||||
} else if (element.isJsonArray()) {
|
} else if (element.isJsonArray()) {
|
||||||
final JsonArray jsElementArray = element.getAsJsonArray();
|
final JsonArray jsElementArray = element.getAsJsonArray();
|
||||||
value = processJsonArray(jsElementArray, responseJsonModel);
|
value = processJsonArray(jsElementArray, responseCtx);
|
||||||
} else {
|
} else {
|
||||||
value = resolveDependentVariable(element, responseJsonModel);
|
value = resolveDependentVariable(element, responseCtx);
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private JsonElement processJsonObject(final JsonObject jsObject, final JsonModel responseJsonModel) {
|
private JsonElement processJsonObject(final JsonObject jsObject, final ReadContext responseCtx) {
|
||||||
JsonObject valueObj = new JsonObject();
|
JsonObject valueObj = new JsonObject();
|
||||||
for (Entry<String, JsonElement> element : jsObject.entrySet()) {
|
for (Entry<String, JsonElement> element : jsObject.entrySet()) {
|
||||||
final String key = element.getKey();
|
final String key = element.getKey();
|
||||||
final JsonElement value = resolveDependentVariable(element.getValue(), responseJsonModel);
|
final JsonElement value = resolveDependentVariable(element.getValue(), responseCtx);
|
||||||
valueObj.add(key, value);
|
valueObj.add(key, value);
|
||||||
}
|
}
|
||||||
return valueObj;
|
return valueObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
private JsonArray processJsonArray(final JsonArray elementArray, final JsonModel responseJsonModel) {
|
private JsonArray processJsonArray(final JsonArray elementArray, final ReadContext responseCtx) {
|
||||||
|
|
||||||
JsonArray valueArr = new JsonArray();
|
JsonArray valueArr = new JsonArray();
|
||||||
|
|
||||||
for (JsonElement element : elementArray) {
|
for (JsonElement element : elementArray) {
|
||||||
if (element.isJsonObject()) {
|
if (element.isJsonObject()) {
|
||||||
final JsonObject jsObject = element.getAsJsonObject();
|
final JsonObject jsObject = element.getAsJsonObject();
|
||||||
valueArr.add(processJsonObject(jsObject, responseJsonModel));
|
valueArr.add(processJsonObject(jsObject, responseCtx));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return valueArr;
|
return valueArr;
|
||||||
}
|
}
|
||||||
|
|
||||||
private JsonElement resolveDependentVariable(final JsonElement element, final JsonModel responseJsonModel) {
|
private JsonElement resolveDependentVariable(final JsonElement element, final ReadContext responseCtx) {
|
||||||
JsonElement value = element;
|
JsonElement value = element;
|
||||||
String paramVal = element.getAsString();
|
String paramVal = element.getAsString();
|
||||||
if (paramVal.contains("$.")) {
|
if (paramVal.contains("$.")) {
|
||||||
// Get the value of the parameter from parent response
|
// Get the value of the parameter from parent response
|
||||||
final String resParamValue = responseJsonModel.get(paramVal).toString();
|
final String resParamValue = responseCtx.read(paramVal).toString();
|
||||||
value = this.fromJsonHelper.parse(resParamValue);
|
value = this.fromJsonHelper.parse(resParamValue);
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
|
|||||||
Reference in New Issue
Block a user