diff --git a/xyz-hub-service/src/main/java/com/here/xyz/hub/rest/ChangesetApi.java b/xyz-hub-service/src/main/java/com/here/xyz/hub/rest/ChangesetApi.java index fb2845bbd..b08670e53 100644 --- a/xyz-hub-service/src/main/java/com/here/xyz/hub/rest/ChangesetApi.java +++ b/xyz-hub-service/src/main/java/com/here/xyz/hub/rest/ChangesetApi.java @@ -106,13 +106,17 @@ private IterateChangesetsEvent buildIterateChangesetsEvent(final RoutingContext if (useChangesetCollection) { startVersion = Query.getLong(context, Query.START_VERSION, 0L); endVersion = Query.getLong(context, Query.END_VERSION, null); + + validateVersion(startVersion, true); + validateVersion(endVersion, false); + validateVersions(startVersion, endVersion); } else { - final String version = context.pathParam(Path.VERSION); - startVersion = Long.parseLong(version); - endVersion = startVersion; - } + final Long version = Query.getLong(context, Query.VERSION, null); + validateVersion(version, true); - validateGetChangesetsQueryParams(startVersion, endVersion, useChangesetCollection); + startVersion = version; + endVersion = version; + } return new IterateChangesetsEvent() .withSpace(getSpaceId(context)) @@ -123,21 +127,17 @@ private IterateChangesetsEvent buildIterateChangesetsEvent(final RoutingContext .withLimit(limit); } - private void validateGetChangesetsQueryParams(Long startVersion, Long endVersion, boolean useChangesetCollection) - throws HttpException { - if (useChangesetCollection) { - if (startVersion != null && endVersion != null) { - if (startVersion < 0 || endVersion < 0) - throw new HttpException(HttpResponseStatus.BAD_REQUEST, "Invalid version specified."); - if (startVersion > endVersion) - throw new HttpException(HttpResponseStatus.BAD_REQUEST, "The parameter startVersion needs to be smaller as endVersion."); - } - } else { - if (startVersion == null) - throw new HttpException(HttpResponseStatus.BAD_REQUEST, "The parameter version is required."); - } + private void validateVersion(Long version, boolean required) throws HttpException { + if (required && version == null) + throw new HttpException(HttpResponseStatus.BAD_REQUEST, "The parameter version is required."); + if (version != null && version < 0) + throw new HttpException(HttpResponseStatus.BAD_REQUEST, "Invalid version specified."); } + private void validateVersions(Long startVersion, Long endVersion) throws HttpException { + if (endVersion != null && startVersion > endVersion) + throw new HttpException(HttpResponseStatus.BAD_REQUEST, "The parameter startVersion needs to be smaller as endVersion."); + } /** * Delete changesets by version number