Fix validating params for single bucket requests (elastic/elasticsearch#622)

Original commit: elastic/x-pack-elasticsearch@42f8771bf8
This commit is contained in:
David Kyle 2017-01-03 14:59:01 +00:00 committed by GitHub
parent db3358166b
commit f8309a0706
1 changed files with 26 additions and 11 deletions

View File

@ -65,17 +65,31 @@ public class RestGetBucketsAction extends BaseRestHandler {
|| restRequest.hasParam(GetBucketsAction.Request.MAX_NORMALIZED_PROBABILITY.getPreferredName()) || restRequest.hasParam(GetBucketsAction.Request.MAX_NORMALIZED_PROBABILITY.getPreferredName())
|| timestamp == null) { || timestamp == null) {
// Multiple buckets // Multiple buckets, check if the param is set first so mutually exclusive
request.setStart(restRequest.param(GetBucketsAction.Request.START.getPreferredName())); // options will only cause an error if set
request.setEnd(restRequest.param(GetBucketsAction.Request.END.getPreferredName())); if (restRequest.hasParam(GetBucketsAction.Request.START.getPreferredName())) {
request.setPageParams(new PageParams(restRequest.paramAsInt(PageParams.FROM.getPreferredName(), PageParams.DEFAULT_FROM), request.setStart(restRequest.param(GetBucketsAction.Request.START.getPreferredName()));
restRequest.paramAsInt(PageParams.SIZE.getPreferredName(), PageParams.DEFAULT_SIZE))); }
request.setAnomalyScore( if (restRequest.hasParam(GetBucketsAction.Request.END.getPreferredName())) {
Double.parseDouble(restRequest.param(GetBucketsAction.Request.ANOMALY_SCORE.getPreferredName(), "0.0"))); request.setEnd(restRequest.param(GetBucketsAction.Request.END.getPreferredName()));
request.setMaxNormalizedProbability( }
Double.parseDouble(restRequest.param( if (restRequest.hasParam(PageParams.FROM.getPreferredName()) || restRequest.hasParam(PageParams.SIZE.getPreferredName())) {
GetBucketsAction.Request.MAX_NORMALIZED_PROBABILITY.getPreferredName(), "0.0"))); request.setPageParams(
request.setPartitionValue(restRequest.param(GetBucketsAction.Request.PARTITION_VALUE.getPreferredName())); new PageParams(restRequest.paramAsInt(PageParams.FROM.getPreferredName(), PageParams.DEFAULT_FROM),
restRequest.paramAsInt(PageParams.SIZE.getPreferredName(), PageParams.DEFAULT_SIZE)));
}
if (restRequest.hasParam(GetBucketsAction.Request.ANOMALY_SCORE.getPreferredName())) {
request.setAnomalyScore(
Double.parseDouble(restRequest.param(GetBucketsAction.Request.ANOMALY_SCORE.getPreferredName(), "0.0")));
}
if (restRequest.hasParam(GetBucketsAction.Request.MAX_NORMALIZED_PROBABILITY.getPreferredName())) {
request.setMaxNormalizedProbability(
Double.parseDouble(restRequest.param(
GetBucketsAction.Request.MAX_NORMALIZED_PROBABILITY.getPreferredName(), "0.0")));
}
if (restRequest.hasParam(GetBucketsAction.Request.PARTITION_VALUE.getPreferredName())) {
request.setPartitionValue(restRequest.param(GetBucketsAction.Request.PARTITION_VALUE.getPreferredName()));
}
} }
// Common options // Common options
@ -85,4 +99,5 @@ public class RestGetBucketsAction extends BaseRestHandler {
return channel -> transportAction.execute(request, new RestStatusToXContentListener<>(channel)); return channel -> transportAction.execute(request, new RestStatusToXContentListener<>(channel));
} }
} }