Skip to content

Commit

Permalink
Merge pull request #189 from swisspost/cleanup-NumberFormatException-…
Browse files Browse the repository at this point in the history
…if-not-set-amount-in-context

Use configured cleanup amount if not present in context
  • Loading branch information
dominik-cnx authored Jun 6, 2024
2 parents 90ee2fc + 016b8dc commit 638ba6a
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/main/java/org/swisspush/reststorage/RestStorageHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import io.vertx.ext.web.Router;
import io.vertx.ext.web.RoutingContext;
import io.vertx.ext.web.handler.BasicAuthHandler;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.swisspush.reststorage.exception.RestStorageExceptionFactory;
import org.swisspush.reststorage.util.*;
Expand Down Expand Up @@ -45,6 +46,7 @@ public class RestStorageHandler implements Handler<HttpServerRequest> {
private final boolean return200onDeleteNonExisting;
private final DecimalFormat decimalFormat;
private final Integer maxStorageExpandSubresources;
private final long configuredCleanupAmount;

public RestStorageHandler(
Vertx vertx,
Expand All @@ -62,6 +64,7 @@ public RestStorageHandler(
this.rejectStorageWriteOnLowMemory = config.isRejectStorageWriteOnLowMemory();
this.return200onDeleteNonExisting = config.isReturn200onDeleteNonExisting();
this.maxStorageExpandSubresources = config.getMaxStorageExpandSubresources();
this.configuredCleanupAmount = config.getResourceCleanupAmount();

this.decimalFormat = new DecimalFormat();
this.decimalFormat.setMaximumFractionDigits(1);
Expand Down Expand Up @@ -127,7 +130,15 @@ private void cleanup(RoutingContext ctx) {
ctx.response().end();
});
pump.start();
}, ctx.request().params().get("cleanupResourcesAmount"));
}, getCleanupResourcesAmountContextOrConfig(ctx));
}

private String getCleanupResourcesAmountContextOrConfig(RoutingContext ctx) {
String routingContextCleanupAmount = ctx.request().getParam("cleanupResourcesAmount");
if (StringUtils.isNotEmpty(routingContextCleanupAmount)) {
return routingContextCleanupAmount;
}
return String.valueOf(this.configuredCleanupAmount);
}

private void getResourceNotFound(RoutingContext ctx) {
Expand Down

0 comments on commit 638ba6a

Please sign in to comment.