From 7d76c0896cf60c42b9d2f6dfa8739dac7172aa3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20R=C3=B6gner?= Date: Fri, 18 Oct 2024 17:24:06 +0200 Subject: [PATCH] Fix rebase-conflicts regarding ChangesetApi updates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Benjamin Rögner --- .../com/here/xyz/hub/rest/ChangesetApi.java | 77 ++++++++----------- .../xyz/events/IterateChangesetsEvent.java | 2 +- .../xyz/psql/query/IterateChangesets.java | 4 +- .../com/here/xyz/util/service/rest/Api.java | 6 +- 4 files changed, 39 insertions(+), 50 deletions(-) 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 978231ed5b..4116301ab6 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 @@ -49,64 +49,53 @@ public class ChangesetApi extends SpaceBasedApi { public ChangesetApi(RouterBuilder rb) { - rb.getRoute("getChangesets").setDoValidation(false).addHandler(this::getChangesets); - rb.getRoute("getChangeset").setDoValidation(false).addHandler(this::getChangeset); - rb.getRoute("deleteChangesets").setDoValidation(false).addHandler(this::deleteChangesets); - rb.getRoute("getChangesetStatistics").setDoValidation(false).addHandler(this::getChangesetStatistics); + rb.getRoute("getChangesets").setDoValidation(false).addHandler(handleErrors(this::getChangesets)); + rb.getRoute("getChangeset").setDoValidation(false).addHandler(handleErrors(this::getChangeset)); + rb.getRoute("deleteChangesets").setDoValidation(false).addHandler(handleErrors(this::deleteChangesets)); + rb.getRoute("getChangesetStatistics").setDoValidation(false).addHandler(handleErrors(this::getChangesetStatistics)); } /** * Get changesets by version */ private void getChangesets(final RoutingContext context) { - try { - long startVersion = getLongQueryParam(context, START_VERSION); - long endVersion = getLongQueryParam(context, END_VERSION); + long startVersion = getLongQueryParam(context, START_VERSION, 0); + long endVersion = getLongQueryParam(context, END_VERSION, -1); - if (startVersion > endVersion) - throw new IllegalArgumentException("The parameter \"" + START_VERSION + "\" needs to be smaller than \"" + END_VERSION + "\"."); + if (endVersion != -1 && startVersion > endVersion) + throw new IllegalArgumentException("The parameter \"" + START_VERSION + "\" needs to be smaller than or equal to \"" + END_VERSION + "\"."); - IterateChangesetsEvent event = buildIterateChangesetsEvent(context, startVersion, endVersion); - //TODO: Add static caching to this endpoint, once the execution pipelines have been refactored. - SpaceConnectorBasedHandler.execute(getMarker(context), - space -> Authorization.authorizeManageSpacesRights(context, space.getId(), space.getOwner()).map(space), event) - .onSuccess(result -> sendResponse(context, result)) - .onFailure(t -> sendErrorResponse(context, t)); - } - catch (Exception e) { - sendErrorResponse(context, e); - } + IterateChangesetsEvent event = buildIterateChangesetsEvent(context, startVersion, endVersion); + //TODO: Add static caching to this endpoint, once the execution pipelines have been refactored. + SpaceConnectorBasedHandler.execute(getMarker(context), + space -> Authorization.authorizeManageSpacesRights(context, space.getId(), space.getOwner()).map(space), event) + .onSuccess(result -> sendResponse(context, result)) + .onFailure(t -> sendErrorResponse(context, t)); } /** * Get changesets by version */ private void getChangeset(RoutingContext context) { - try { - long version = getVersionFromPathParam(context); - IterateChangesetsEvent event = buildIterateChangesetsEvent(context, version, version); - //TODO: Add static caching to this endpoint, once the execution pipelines have been refactored. - SpaceConnectorBasedHandler.execute(getMarker(context), - space -> Authorization.authorizeManageSpacesRights(context, space.getId(), space.getOwner()).map(space), event) - .onSuccess(result -> { - ChangesetCollection changesets = (ChangesetCollection) result; - if (changesets.getVersions().isEmpty()) - sendErrorResponse(context, new HttpException(NOT_FOUND, "No changeset was found for version " + version)); - else - sendResponse(context, changesets.getVersions().get(version).withNextPageToken(changesets.getNextPageToken())); - }) - .onFailure(t -> sendErrorResponse(context, t)); - - } - catch (Exception e) { - sendErrorResponse(context, e); - } + long version = getVersionFromPathParam(context); + IterateChangesetsEvent event = buildIterateChangesetsEvent(context, version, version); + //TODO: Add static caching to this endpoint, once the execution pipelines have been refactored. + SpaceConnectorBasedHandler.execute(getMarker(context), + space -> Authorization.authorizeManageSpacesRights(context, space.getId(), space.getOwner()).map(space), event) + .onSuccess(result -> { + ChangesetCollection changesets = (ChangesetCollection) result; + if (changesets.getVersions().isEmpty()) + sendErrorResponse(context, new HttpException(NOT_FOUND, "No changeset was found for version " + version)); + else + sendResponse(context, changesets.getVersions().get(version).withNextPageToken(changesets.getNextPageToken())); + }) + .onFailure(t -> sendErrorResponse(context, t)); } /** * Delete changesets by version number */ - private void deleteChangesets(final RoutingContext context) { + private void deleteChangesets(final RoutingContext context) throws HttpException { final String spaceId = getSpaceId(context); final PropertyQuery version = Query.getPropertyQuery(context.request().query(), "version", false); @@ -141,8 +130,7 @@ else if (version.getOperation() != LESS_THAN) { .onFailure(t -> sendErrorResponse(context, t)); } catch (NumberFormatException e) { - sendErrorResponse(context, - new HttpException(HttpResponseStatus.BAD_REQUEST, "Query parameter version must be a valid number larger than 0")); + throw new HttpException(HttpResponseStatus.BAD_REQUEST, "Query parameter version must be a valid number larger than 0"); } } @@ -155,8 +143,7 @@ private void getChangesetStatistics(final RoutingContext context) { .onFailure(t -> sendErrorResponse(context, t)); } - private IterateChangesetsEvent buildIterateChangesetsEvent(final RoutingContext context, long startVersion, long endVersion) - throws HttpException { + private IterateChangesetsEvent buildIterateChangesetsEvent(final RoutingContext context, long startVersion, long endVersion) { String pageToken = Query.getString(context, Query.PAGE_TOKEN, null); long limit = Query.getLong(context, Query.LIMIT, IterateChangesets.DEFAULT_LIMIT); @@ -168,7 +155,7 @@ private IterateChangesetsEvent buildIterateChangesetsEvent(final RoutingContext .withLimit(limit); } - private long getLongQueryParam(RoutingContext context, String paramName) { + private long getLongQueryParam(RoutingContext context, String paramName, long defaultValue) { try { long paramValue = Query.getLong(context, paramName); if (paramValue < 0) @@ -176,7 +163,7 @@ private long getLongQueryParam(RoutingContext context, String paramName) { return paramValue; } catch (NullPointerException e) { - throw new IllegalArgumentException("The parameter \"" + paramName + "\" is required.", e); + return defaultValue; } catch (NumberFormatException e) { throw new IllegalArgumentException("The parameter \"" + paramName + "\" is not a number.", e); diff --git a/xyz-models/src/main/java/com/here/xyz/events/IterateChangesetsEvent.java b/xyz-models/src/main/java/com/here/xyz/events/IterateChangesetsEvent.java index b757d4378e..f37c317830 100644 --- a/xyz-models/src/main/java/com/here/xyz/events/IterateChangesetsEvent.java +++ b/xyz-models/src/main/java/com/here/xyz/events/IterateChangesetsEvent.java @@ -30,7 +30,7 @@ public final class IterateChangesetsEvent extends SearchForFeaturesEvent handleErrors(ThrowingHandler h return context -> { try { handler.handle(context); - } catch (HttpException e) { + } + catch (HttpException | IllegalArgumentException | ValidationException | AccessDeniedException | RequestCancelledException e) { sendErrorResponse(context, e); - } catch (Exception e) { + } + catch (Exception e) { sendInternalServerError(context, e); } };