Hi @sarav_prakash :
You can add a filter with pattern below or if you want to implement for one query then add its complete path and filter the requests.
In the doFilter method, get the response of the query and then manipulate the response and add more fields to the response (size, lastModified, createdDate, cq:tags). Here is the sample code snippet.
@Override
public void doFilter(final ServletRequest request, final ServletResponse response,
final FilterChain filterChain) throws IOException, ServletException {
SlingHttpServletRequest slingHttpServletRequest = (SlingHttpServletRequest) request;
//isEnabledSuffix will check for the request suffix if it contains the specific query where imageRef schema needs to be modified.
if (isEnabledSuffix(slingHttpServletRequest.getRequestPathInfo().getSuffix())) {
CharResponseWrapper responseWrapper = new CharResponseWrapper((HttpServletResponse) response);
filterChain.doFilter(request, responseWrapper);
PrintWriter responseWriter = response.getWriter();
if (responseWriter == null) {
return;
}
JsonElement jsonElement = new Gson().fromJson(responseWrapper.toString(), JsonElement.class);
JsonObject jsonObject = jsonElement.getAsJsonObject();
searchJson(jsonObject);//search for imageRef object in the response json
responseWriter.write(jsonObject.toString()); //writing the modified response with more metadata back to the response
} else {
filterChain.doFilter(request, response);
}
}
private void searchJson(JsonObject jsonObject) {
String assetUrl = StringUtils.EMPTY;
for (Map.Entry<String, JsonElement> jsonEntry : jsonObject.entrySet()) {
if (TYPE_NAME.equals(jsonEntry.getKey()) && IMAGE_REF.equals(jsonEntry.getValue().getAsString())) {
assetUrl = jsonObject.get(URL).getAsString();
}
JsonElement jsonValue = jsonEntry.getValue();
if (jsonValue instanceof JsonObject) {
searchJson(jsonValue.getAsJsonObject());
} else if (jsonValue instanceof JsonArray) {
JsonArray jsonValues = jsonValue.getAsJsonArray();
for (JsonElement jsonArrayValue : jsonValues) {
if (jsonArrayValue instanceof JsonObject) {
searchJson(jsonArrayValue.getAsJsonObject());
}
}
}
}
if (StringUtils.isNotBlank(assetUrl)) {
setAssetMetadata(assetUrl, jsonObject); //this method gets the resource metadata and extract the properties and add those to the response json
}
}Hope this helps. Let me know if you face any issues implementing this.