Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed metadataApi class so it accepts multiple filters now #231

Merged
merged 7 commits into from
May 7, 2024
21 changes: 13 additions & 8 deletions src/main/java/nl/nn/testtool/web/api/MetadataApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ public class MetadataApi extends ApiBase {
* @param storageName Name of the storage to search.
* @param metadataNames The metadata names to return.
* @param limit Maximum number of results to return.
* @param filterHeader The header on which we filter.
* @param filterHeaders The headers on which we filter.
* @param uriInfo Query parameters for search.
* @param filterParam The regex on which the report names will be filtered
* @param filterParams The regex on which the report names will be filtered
* @return Response containing fields [List[String]] and values [List[List[Object]]].
* @throws ApiException If an exception occurs during metadata search in storage.
*/
Expand All @@ -64,15 +64,20 @@ public class MetadataApi extends ApiBase {
public Response getMetadataList(@PathParam("storage") String storageName,
@QueryParam("metadataNames") List<String> metadataNames,
@DefaultValue("-1") @QueryParam("limit") int limit,
@DefaultValue("") @QueryParam("filterHeader") String filterHeader,
@DefaultValue("(.*)") @QueryParam("filter") String filterParam ,
@DefaultValue("") @QueryParam("filterHeader") List<String> filterHeaders,
@DefaultValue("(.*)") @QueryParam("filter") List<String> filterParams ,
philipsens marked this conversation as resolved.
Show resolved Hide resolved
@Context UriInfo uriInfo) {

List<String> searchValues = new ArrayList<>();
for(String field : metadataNames) {
if (filterHeader.equals(field)) {
searchValues.add(filterParam);
} else {
boolean changed = false;
for (int filterHeaderIndex = 0; filterHeaderIndex < filterHeaders.size(); filterHeaderIndex++) {
philipsens marked this conversation as resolved.
Show resolved Hide resolved
if (filterHeaders.get(filterHeaderIndex).equals(field)) {
searchValues.add(filterParams.get(filterHeaderIndex));
changed = true;
}
}
if(!changed) {
searchValues.add(null);
}
}
Expand All @@ -97,7 +102,7 @@ public Response getMetadataList(@PathParam("storage") String storageName,

return Response.ok().entity(metadata).build();
} catch (Exception e) {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("Could not find metadata with limit [" + limit + "] and filter [" + filterParam + "] - detailed error message - " + e + Arrays.toString(e.getStackTrace())).build();
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("Could not find metadata with limit [" + limit + "] and filter [" + filterParams + "] - detailed error message - " + e + Arrays.toString(e.getStackTrace())).build();
philipsens marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
Loading