Skip to content

Commit

Permalink
Issue #1086 - statistics IP filter
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-stastny committed Sep 11, 2024
1 parent 66ddf05 commit bb54bfc
Showing 1 changed file with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
Expand Down Expand Up @@ -169,7 +170,7 @@ public Response cleanData(@QueryParam("dateFrom") String dateFrom, @QueryParam("
}



@Deprecated
@GET
@Produces({ MediaType.APPLICATION_JSON + ";charset=utf-8" })
public Response reports() {
Expand All @@ -187,6 +188,7 @@ public Response reports() {
}
}

@Deprecated
@GET
@Path("{report}/options")
@Produces({ MediaType.APPLICATION_JSON + ";charset=utf-8" })
Expand Down Expand Up @@ -231,6 +233,7 @@ public Response filters(
}
}

@Deprecated
@GET
@Path("{report}")
@Produces({ MediaType.APPLICATION_JSON + ";charset=utf-8" })
Expand Down Expand Up @@ -559,6 +562,11 @@ public static void validateDateRange(String dateFrom, String dateTo) {
@Path("search")
public Response search(@Context UriInfo uriInfo, @Context HttpHeaders headers, @QueryParam("wt") String wt) {
try {
// default




if (permit(SecuredActions.A_STATISTICS)) {
MultivaluedMap<String, String> queryParameters = uriInfo.getQueryParameters();
StringBuilder builder = new StringBuilder();
Expand All @@ -571,6 +579,15 @@ public Response search(@Context UriInfo uriInfo, @Context HttpHeaders headers, @
}
}

List<Object> ipfiltersObject = KConfiguration.getInstance().getConfiguration().getList("statistics.ip.filter", new ArrayList<>());
List<String> ipFilters = ipfiltersObject.stream().map(Object::toString).collect(Collectors.toList());

for (String ipExpr : ipFilters) {
builder.append("fq").append("=").append("-ip_address:"+URLEncoder.encode(ipExpr, "UTF-8"));
builder.append("&");
}


if ("json".equals(wt)) {
return Response.ok().type(MediaType.APPLICATION_JSON + ";charset=utf-8").entity(buildSearchResponseJson(uriInfo, builder.toString() )).build();
} else if ("xml".equals(wt)) {
Expand Down

0 comments on commit bb54bfc

Please sign in to comment.