From 4edf41352251682b15818c37c9c92193f0601d46 Mon Sep 17 00:00:00 2001 From: Hamza Jugon Date: Wed, 23 Oct 2024 12:35:27 +0100 Subject: [PATCH 01/20] update controller to use ParameterObject As used in the metadata endpoint we want Swagger to be able to interpret and automatically generate pagination parameters like page, size, and sort. --- .../beekeeper/api/controller/BeekeeperController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/controller/BeekeeperController.java b/beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/controller/BeekeeperController.java index eda7fcbd..4d083f76 100644 --- a/beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/controller/BeekeeperController.java +++ b/beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/controller/BeekeeperController.java @@ -106,7 +106,7 @@ public ResponseEntity> getAllPaths( @Spec(path = "cleanupTimestamp", params = "deleted_after", spec = GreaterThan.class), @Spec(path = "creationTimestamp", params = "registered_before", spec = LessThan.class), @Spec(path = "creationTimestamp", params = "registered_after", spec = GreaterThan.class) }) Specification spec, - Pageable pageable) { + @ParameterObject Pageable pageable) { return ResponseEntity.ok(housekeepingEntityService.getAllPaths(spec, pageable)); } From 637b62286fd47b7cb93ada22c49be745ec0d2b0e Mon Sep 17 00:00:00 2001 From: Hamza Jugon Date: Wed, 23 Oct 2024 12:51:23 +0100 Subject: [PATCH 02/20] Add error handling for incorrect sort value --- .../api/BeekeeperApiApplication.java | 3 +- .../api/error/BeekeeperExceptionHandler.java | 54 +++++++++++++++++++ .../beekeeper/api/error/ErrorResponse.java | 30 +++++++++++ 3 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/error/BeekeeperExceptionHandler.java create mode 100644 beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/error/ErrorResponse.java diff --git a/beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/BeekeeperApiApplication.java b/beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/BeekeeperApiApplication.java index 42871a18..19f5ba46 100644 --- a/beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/BeekeeperApiApplication.java +++ b/beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/BeekeeperApiApplication.java @@ -29,7 +29,8 @@ @ComponentScan(basePackages = { "com.expediagroup.beekeeper.api.conf", "com.expediagroup.beekeeper.api.controller", - "com.expediagroup.beekeeper.api.service" }) + "com.expediagroup.beekeeper.api.service", + "com.expediagroup.beekeeper.api.error" }) public class BeekeeperApiApplication { public static void main(String[] args) { new SpringApplicationBuilder(BeekeeperApiApplication.class) diff --git a/beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/error/BeekeeperExceptionHandler.java b/beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/error/BeekeeperExceptionHandler.java new file mode 100644 index 00000000..794f79bc --- /dev/null +++ b/beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/error/BeekeeperExceptionHandler.java @@ -0,0 +1,54 @@ +/** + * Copyright (C) 2019-2024 Expedia, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.expediagroup.beekeeper.api.error; + +import javax.servlet.http.HttpServletRequest; + +import org.springframework.data.mapping.PropertyReferenceException; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +import java.time.LocalDateTime; + +@RestControllerAdvice +public class BeekeeperExceptionHandler { + + /** + * Handles invalid sort parameters. + * + * @param ex the exception thrown when an invalid property is referenced + * @param request the HTTP request + * @return a ResponseEntity containing the error response + */ + + @ExceptionHandler(PropertyReferenceException.class) + public ResponseEntity handlePropertyReferenceException( + PropertyReferenceException ex, HttpServletRequest request) { + + ErrorResponse errorResponse = new ErrorResponse(); + errorResponse.setTimestamp(LocalDateTime.now().toString()); + errorResponse.setStatus(HttpStatus.BAD_REQUEST.value()); + errorResponse.setError(HttpStatus.BAD_REQUEST.getReasonPhrase()); + errorResponse.setMessage("Invalid sort parameter: " + ex.getMessage()); + errorResponse.setPath(request.getRequestURI()); + + return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST); + } + +} \ No newline at end of file diff --git a/beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/error/ErrorResponse.java b/beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/error/ErrorResponse.java new file mode 100644 index 00000000..f9314feb --- /dev/null +++ b/beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/error/ErrorResponse.java @@ -0,0 +1,30 @@ +/** + * Copyright (C) 2019-2024 Expedia, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.expediagroup.beekeeper.api.error; + +import lombok.Getter; +import lombok.Setter; + +@Setter +@Getter +public class ErrorResponse { + private String timestamp; + private int status; + private String error; + private String message; + private String path; +} \ No newline at end of file From 2c11c8cf6264286ab04a956f721c50c479427f17 Mon Sep 17 00:00:00 2001 From: Hamza Jugon Date: Wed, 23 Oct 2024 12:52:12 +0100 Subject: [PATCH 03/20] Add test for error handling --- .../api/BeekeeperApiIntegrationTest.java | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/beekeeper-integration-tests/src/test/java/com/expediagroup/beekeeper/integration/api/BeekeeperApiIntegrationTest.java b/beekeeper-integration-tests/src/test/java/com/expediagroup/beekeeper/integration/api/BeekeeperApiIntegrationTest.java index c311dde0..f72f2bf8 100644 --- a/beekeeper-integration-tests/src/test/java/com/expediagroup/beekeeper/integration/api/BeekeeperApiIntegrationTest.java +++ b/beekeeper-integration-tests/src/test/java/com/expediagroup/beekeeper/integration/api/BeekeeperApiIntegrationTest.java @@ -43,6 +43,7 @@ import org.springframework.boot.SpringApplication; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.data.domain.Page; +import org.springframework.http.HttpStatus; import org.springframework.util.SocketUtils; import com.fasterxml.jackson.core.type.TypeReference; @@ -51,6 +52,7 @@ import com.fasterxml.jackson.module.paramnames.ParameterNamesModule; import com.expediagroup.beekeeper.api.BeekeeperApiApplication; +import com.expediagroup.beekeeper.api.error.ErrorResponse; import com.expediagroup.beekeeper.api.response.HousekeepingMetadataResponse; import com.expediagroup.beekeeper.api.response.HousekeepingPathResponse; import com.expediagroup.beekeeper.core.model.HousekeepingMetadata; @@ -111,7 +113,7 @@ public final void afterEach() { @Test public void testGetMetadataWhenTableNotFoundReturnsEmptyList() - throws SQLException, InterruptedException, IOException { + throws SQLException, InterruptedException, IOException { for (HousekeepingMetadata testMetadata : Arrays.asList(testMetadataB, testMetadataC)) { insertExpiredMetadata(testMetadata); @@ -302,4 +304,23 @@ private HousekeepingPath createHousekeepingPath( .build(); } -} + @Test + public void testInvalidSortParameter() throws SQLException, IOException, InterruptedException { + insertExpiredMetadata(testMetadataA); + + String filters = "?sort=nonExistentProperty,asc"; + HttpResponse response = testClient.getMetadata(someDatabase, someTable, filters); + + assertThat(response.statusCode()).isEqualTo(HttpStatus.BAD_REQUEST.value()); + + String body = response.body(); + ErrorResponse errorResponse = mapper.readValue(body, ErrorResponse.class); + + assertThat(errorResponse.getStatus()).isEqualTo(HttpStatus.BAD_REQUEST.value()); + assertThat(errorResponse.getMessage()).contains("Invalid sort parameter"); + assertThat(errorResponse.getError()).isEqualTo("Bad Request"); + assertThat(errorResponse.getPath()).contains("/api/v1/database/some_database/table/some_table/metadata"); + assertThat(errorResponse.getTimestamp()).isNotNull(); + } + +} \ No newline at end of file From 70ca05cd0d9515ab6680273a355e38b7f3078166 Mon Sep 17 00:00:00 2001 From: Hamza Jugon Date: Wed, 23 Oct 2024 13:00:35 +0100 Subject: [PATCH 04/20] Fix workflow to only release main branch to maven central --- .github/workflows/release.yml | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0f92c961..e8f9d272 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,11 +1,8 @@ name: Release to Maven Central + on: - workflow_dispatch: - inputs: - branch: - description: "The branch to use to release from." - required: true - default: "main" + workflow_dispatch: # Allows manual triggering of the workflow + jobs: release: name: Release to Maven Central @@ -16,8 +13,7 @@ jobs: uses: actions/checkout@v2 with: fetch-depth: 0 - ref: ${{ github.event.inputs.branch }} - # We need a personal access token to be able to push to a protected branch + ref: main # Hardcoded to main branch token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} - name: Set up JDK From 8118937712c43d98c1bb2e6361dbb6ffa4fb891b Mon Sep 17 00:00:00 2001 From: Hamza Jugon Date: Wed, 23 Oct 2024 13:23:55 +0100 Subject: [PATCH 05/20] Update CHANGELOG.md --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 61406d3b..8c4df781 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [3.5.7] - 2024-10-23 +### Changed +- Added error handling for bad requests with incorrect sort parameters +- Added automatic pagination handling in the `/unreferenced-paths` endpoint for improved Swagger documentation. +- Updated the Maven Central release workflow to run exclusively from the main branch. + ## [3.5.6] - 2024-06-14 ### Fixed - Added aws-sts-jdk dependency in `beekeeper-metadata-cleanup`, `beekeeper-path-cleanup`, `beekeeper-scheduler-apiary` to solve IRSA unable to assume role issue. From 903469a5fc2df8691448582d8bf80a3a3abf55f0 Mon Sep 17 00:00:00 2001 From: Hamza Jugon Date: Wed, 23 Oct 2024 13:41:25 +0100 Subject: [PATCH 06/20] tidy --- .github/workflows/release.yml | 2 +- CHANGELOG.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e8f9d272..a6e58675 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,7 +1,7 @@ name: Release to Maven Central on: - workflow_dispatch: # Allows manual triggering of the workflow + workflow_dispatch: jobs: release: diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c4df781..2da2d992 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [3.5.7] - 2024-10-23 ### Changed -- Added error handling for bad requests with incorrect sort parameters +- Added error handling for bad requests with incorrect sort parameters. - Added automatic pagination handling in the `/unreferenced-paths` endpoint for improved Swagger documentation. - Updated the Maven Central release workflow to run exclusively from the main branch. From 592e3701501c4707cd575ebb5bdec1062e7e8ede Mon Sep 17 00:00:00 2001 From: Hamza Jugon Date: Wed, 23 Oct 2024 15:44:29 +0100 Subject: [PATCH 07/20] Add unit test for BeeekeeperExceptionHandler Testing the request response and the errorResponses --- .../error/BeekeeperExceptionHandlerTest.java | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 beekeeper-api/src/test/java/com/expediagroup/beekeeper/api/error/BeekeeperExceptionHandlerTest.java diff --git a/beekeeper-api/src/test/java/com/expediagroup/beekeeper/api/error/BeekeeperExceptionHandlerTest.java b/beekeeper-api/src/test/java/com/expediagroup/beekeeper/api/error/BeekeeperExceptionHandlerTest.java new file mode 100644 index 00000000..c0c6302f --- /dev/null +++ b/beekeeper-api/src/test/java/com/expediagroup/beekeeper/api/error/BeekeeperExceptionHandlerTest.java @@ -0,0 +1,62 @@ +/** + * Copyright (C) 2019-2023 Expedia, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.expediagroup.beekeeper.api.test.error; + +import org.junit.jupiter.api.Test; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.mock.web.MockHttpServletRequest; +import org.springframework.data.mapping.PropertyReferenceException; +import org.springframework.data.mapping.PropertyPath; +import org.springframework.data.util.ClassTypeInformation; +import org.springframework.data.util.TypeInformation; + +import static org.assertj.core.api.Assertions.assertThat; + +import com.expediagroup.beekeeper.api.error.BeekeeperExceptionHandler; +import com.expediagroup.beekeeper.api.error.ErrorResponse; +import com.expediagroup.beekeeper.core.model.HousekeepingPath; // Import your entity class + +import java.util.Collections; +import java.util.List; + +public class BeekeeperExceptionHandlerTest { + + private final BeekeeperExceptionHandler exceptionHandler = new BeekeeperExceptionHandler(); + + @Test + public void handlePropertyReferenceException_ShouldReturnBadRequest() { + String propertyName = "string"; + TypeInformation typeInformation = ClassTypeInformation.from(HousekeepingPath.class); + List baseProperty = Collections.emptyList(); + PropertyReferenceException exception = new PropertyReferenceException(propertyName, typeInformation, baseProperty); + + MockHttpServletRequest request = new MockHttpServletRequest(); + request.setRequestURI("/api/v1/database/testDb/table/testTable/unreferenced-paths"); + + ResponseEntity response = exceptionHandler.handlePropertyReferenceException(exception, request); + + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST); + + ErrorResponse errorResponse = response.getBody(); + assertThat(errorResponse).isNotNull(); + assertThat(errorResponse.getStatus()).isEqualTo(HttpStatus.BAD_REQUEST.value()); + assertThat(errorResponse.getError()).isEqualTo("Bad Request"); + assertThat(errorResponse.getMessage()).contains("Invalid sort parameter"); + assertThat(errorResponse.getPath()).isEqualTo("/api/v1/database/testDb/table/testTable/unreferenced-paths"); + assertThat(errorResponse.getTimestamp()).isNotNull(); + } +} From d4570b79daf428b32953373ffdfd8d3e47d1f16d Mon Sep 17 00:00:00 2001 From: Hamza Jugon Date: Wed, 23 Oct 2024 16:04:20 +0100 Subject: [PATCH 08/20] Update BeekeeperExceptionHandlerTest.java --- .../beekeeper/api/error/BeekeeperExceptionHandlerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beekeeper-api/src/test/java/com/expediagroup/beekeeper/api/error/BeekeeperExceptionHandlerTest.java b/beekeeper-api/src/test/java/com/expediagroup/beekeeper/api/error/BeekeeperExceptionHandlerTest.java index c0c6302f..6e807f83 100644 --- a/beekeeper-api/src/test/java/com/expediagroup/beekeeper/api/error/BeekeeperExceptionHandlerTest.java +++ b/beekeeper-api/src/test/java/com/expediagroup/beekeeper/api/error/BeekeeperExceptionHandlerTest.java @@ -28,7 +28,7 @@ import com.expediagroup.beekeeper.api.error.BeekeeperExceptionHandler; import com.expediagroup.beekeeper.api.error.ErrorResponse; -import com.expediagroup.beekeeper.core.model.HousekeepingPath; // Import your entity class +import com.expediagroup.beekeeper.core.model.HousekeepingPath; import java.util.Collections; import java.util.List; From fb5c76e4d43b44e7bf94e504ea7ebd905ac71051 Mon Sep 17 00:00:00 2001 From: Hamza Jugon <104994559+HamzaJugon@users.noreply.github.com> Date: Wed, 23 Oct 2024 17:09:33 +0100 Subject: [PATCH 09/20] Update beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/error/ErrorResponse.java Co-authored-by: Jay Green-Stevens --- .../com/expediagroup/beekeeper/api/error/ErrorResponse.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/error/ErrorResponse.java b/beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/error/ErrorResponse.java index f9314feb..c4902427 100644 --- a/beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/error/ErrorResponse.java +++ b/beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/error/ErrorResponse.java @@ -27,4 +27,4 @@ public class ErrorResponse { private String error; private String message; private String path; -} \ No newline at end of file +} From 77c6a6255db560e9d9a2f8c623b1ed05f9623824 Mon Sep 17 00:00:00 2001 From: Hamza Jugon <104994559+HamzaJugon@users.noreply.github.com> Date: Wed, 23 Oct 2024 17:10:00 +0100 Subject: [PATCH 10/20] Update beekeeper-integration-tests/src/test/java/com/expediagroup/beekeeper/integration/api/BeekeeperApiIntegrationTest.java Co-authored-by: Jay Green-Stevens --- .../beekeeper/integration/api/BeekeeperApiIntegrationTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beekeeper-integration-tests/src/test/java/com/expediagroup/beekeeper/integration/api/BeekeeperApiIntegrationTest.java b/beekeeper-integration-tests/src/test/java/com/expediagroup/beekeeper/integration/api/BeekeeperApiIntegrationTest.java index f72f2bf8..55c1fce4 100644 --- a/beekeeper-integration-tests/src/test/java/com/expediagroup/beekeeper/integration/api/BeekeeperApiIntegrationTest.java +++ b/beekeeper-integration-tests/src/test/java/com/expediagroup/beekeeper/integration/api/BeekeeperApiIntegrationTest.java @@ -323,4 +323,4 @@ public void testInvalidSortParameter() throws SQLException, IOException, Interru assertThat(errorResponse.getTimestamp()).isNotNull(); } -} \ No newline at end of file +} From b840ae2f29612c200a45d939402006634172f6c3 Mon Sep 17 00:00:00 2001 From: Hamza Jugon <104994559+HamzaJugon@users.noreply.github.com> Date: Wed, 23 Oct 2024 17:10:09 +0100 Subject: [PATCH 11/20] Update beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/error/BeekeeperExceptionHandler.java Co-authored-by: Jay Green-Stevens --- .../beekeeper/api/error/BeekeeperExceptionHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/error/BeekeeperExceptionHandler.java b/beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/error/BeekeeperExceptionHandler.java index 794f79bc..bc923922 100644 --- a/beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/error/BeekeeperExceptionHandler.java +++ b/beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/error/BeekeeperExceptionHandler.java @@ -39,7 +39,7 @@ public class BeekeeperExceptionHandler { @ExceptionHandler(PropertyReferenceException.class) public ResponseEntity handlePropertyReferenceException( - PropertyReferenceException ex, HttpServletRequest request) { + PropertyReferenceException exception, HttpServletRequest request) { ErrorResponse errorResponse = new ErrorResponse(); errorResponse.setTimestamp(LocalDateTime.now().toString()); From 93853d06d846eba0a261b71e5ffab5521c61dd75 Mon Sep 17 00:00:00 2001 From: Hamza Jugon <104994559+HamzaJugon@users.noreply.github.com> Date: Wed, 23 Oct 2024 17:10:45 +0100 Subject: [PATCH 12/20] Update beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/error/BeekeeperExceptionHandler.java Co-authored-by: Jay Green-Stevens --- .../beekeeper/api/error/BeekeeperExceptionHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/error/BeekeeperExceptionHandler.java b/beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/error/BeekeeperExceptionHandler.java index bc923922..219ebd01 100644 --- a/beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/error/BeekeeperExceptionHandler.java +++ b/beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/error/BeekeeperExceptionHandler.java @@ -51,4 +51,4 @@ public ResponseEntity handlePropertyReferenceException( return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST); } -} \ No newline at end of file +} From 15ededd028f257173a897aa63cedc53782ce0675 Mon Sep 17 00:00:00 2001 From: Hamza Jugon <104994559+HamzaJugon@users.noreply.github.com> Date: Wed, 23 Oct 2024 17:10:51 +0100 Subject: [PATCH 13/20] Update beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/error/BeekeeperExceptionHandler.java Co-authored-by: Jay Green-Stevens --- .../beekeeper/api/error/BeekeeperExceptionHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/error/BeekeeperExceptionHandler.java b/beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/error/BeekeeperExceptionHandler.java index 219ebd01..fc02e34a 100644 --- a/beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/error/BeekeeperExceptionHandler.java +++ b/beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/error/BeekeeperExceptionHandler.java @@ -32,7 +32,7 @@ public class BeekeeperExceptionHandler { /** * Handles invalid sort parameters. * - * @param ex the exception thrown when an invalid property is referenced + * @param ex the exception is thrown when an invalid property is referenced * @param request the HTTP request * @return a ResponseEntity containing the error response */ From bce723a1b693c735bd87b731790d4ce7327900d0 Mon Sep 17 00:00:00 2001 From: Hamza Jugon Date: Wed, 23 Oct 2024 17:24:10 +0100 Subject: [PATCH 14/20] Update BeekeeperExceptionHandler.java --- .../beekeeper/api/error/BeekeeperExceptionHandler.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/error/BeekeeperExceptionHandler.java b/beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/error/BeekeeperExceptionHandler.java index fc02e34a..460ffb17 100644 --- a/beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/error/BeekeeperExceptionHandler.java +++ b/beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/error/BeekeeperExceptionHandler.java @@ -32,7 +32,7 @@ public class BeekeeperExceptionHandler { /** * Handles invalid sort parameters. * - * @param ex the exception is thrown when an invalid property is referenced + * @param exception the exception is thrown when an invalid property is referenced * @param request the HTTP request * @return a ResponseEntity containing the error response */ @@ -45,7 +45,7 @@ public ResponseEntity handlePropertyReferenceException( errorResponse.setTimestamp(LocalDateTime.now().toString()); errorResponse.setStatus(HttpStatus.BAD_REQUEST.value()); errorResponse.setError(HttpStatus.BAD_REQUEST.getReasonPhrase()); - errorResponse.setMessage("Invalid sort parameter: " + ex.getMessage()); + errorResponse.setMessage("Invalid sort parameter: " + exception.getMessage()); errorResponse.setPath(request.getRequestURI()); return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST); From 55fab02277a7643921d77e5d11f737499406a0aa Mon Sep 17 00:00:00 2001 From: Hamza Jugon Date: Thu, 24 Oct 2024 11:24:09 +0100 Subject: [PATCH 15/20] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2da2d992..4c191737 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [3.5.7] - 2024-10-23 +## [3.5.7] - 2024-10-24 ### Changed - Added error handling for bad requests with incorrect sort parameters. - Added automatic pagination handling in the `/unreferenced-paths` endpoint for improved Swagger documentation. From 5135664f4c6ceefb1de2aa79141419ff8739a94e Mon Sep 17 00:00:00 2001 From: Hamza Jugon Date: Thu, 24 Oct 2024 14:26:00 +0100 Subject: [PATCH 16/20] Implement builder pattern for ErrorResponse --- .../api/error/BeekeeperExceptionHandler.java | 13 +++++++------ .../beekeeper/api/error/ErrorResponse.java | 14 +++++++------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/error/BeekeeperExceptionHandler.java b/beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/error/BeekeeperExceptionHandler.java index 460ffb17..3930cab5 100644 --- a/beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/error/BeekeeperExceptionHandler.java +++ b/beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/error/BeekeeperExceptionHandler.java @@ -41,12 +41,13 @@ public class BeekeeperExceptionHandler { public ResponseEntity handlePropertyReferenceException( PropertyReferenceException exception, HttpServletRequest request) { - ErrorResponse errorResponse = new ErrorResponse(); - errorResponse.setTimestamp(LocalDateTime.now().toString()); - errorResponse.setStatus(HttpStatus.BAD_REQUEST.value()); - errorResponse.setError(HttpStatus.BAD_REQUEST.getReasonPhrase()); - errorResponse.setMessage("Invalid sort parameter: " + exception.getMessage()); - errorResponse.setPath(request.getRequestURI()); + ErrorResponse errorResponse = ErrorResponse.builder() + .timestamp(LocalDateTime.now().toString()) + .status(HttpStatus.BAD_REQUEST.value()) + .error(HttpStatus.BAD_REQUEST.getReasonPhrase()) + .message("Invalid sort parameter: " + exception.getMessage()) + .path(request.getRequestURI()) + .build(); return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST); } diff --git a/beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/error/ErrorResponse.java b/beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/error/ErrorResponse.java index c4902427..f4f4da24 100644 --- a/beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/error/ErrorResponse.java +++ b/beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/error/ErrorResponse.java @@ -16,15 +16,15 @@ package com.expediagroup.beekeeper.api.error; +import lombok.Builder; import lombok.Getter; -import lombok.Setter; -@Setter @Getter +@Builder public class ErrorResponse { - private String timestamp; - private int status; - private String error; - private String message; - private String path; + private final String timestamp; + private final int status; + private final String error; + private final String message; + private final String path; } From d1ee56787116beada87299a2501a1f3537edd1c3 Mon Sep 17 00:00:00 2001 From: Hamza Jugon Date: Thu, 24 Oct 2024 23:26:12 +0100 Subject: [PATCH 17/20] Make error message less specific in BeekeeperExceptionHandler --- .../beekeeper/api/error/BeekeeperExceptionHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/error/BeekeeperExceptionHandler.java b/beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/error/BeekeeperExceptionHandler.java index 3930cab5..b83a56ed 100644 --- a/beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/error/BeekeeperExceptionHandler.java +++ b/beekeeper-api/src/main/java/com/expediagroup/beekeeper/api/error/BeekeeperExceptionHandler.java @@ -45,7 +45,7 @@ public ResponseEntity handlePropertyReferenceException( .timestamp(LocalDateTime.now().toString()) .status(HttpStatus.BAD_REQUEST.value()) .error(HttpStatus.BAD_REQUEST.getReasonPhrase()) - .message("Invalid sort parameter: " + exception.getMessage()) + .message(exception.getMessage()) .path(request.getRequestURI()) .build(); From 0cda7d7f2c57697381404957201eee9fdcc2f797 Mon Sep 17 00:00:00 2001 From: Hamza Jugon Date: Thu, 24 Oct 2024 23:47:37 +0100 Subject: [PATCH 18/20] Update package name and fix test in BeekeeperExceptionHandler --- .../beekeeper/api/error/BeekeeperExceptionHandlerTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/beekeeper-api/src/test/java/com/expediagroup/beekeeper/api/error/BeekeeperExceptionHandlerTest.java b/beekeeper-api/src/test/java/com/expediagroup/beekeeper/api/error/BeekeeperExceptionHandlerTest.java index 6e807f83..11406e9d 100644 --- a/beekeeper-api/src/test/java/com/expediagroup/beekeeper/api/error/BeekeeperExceptionHandlerTest.java +++ b/beekeeper-api/src/test/java/com/expediagroup/beekeeper/api/error/BeekeeperExceptionHandlerTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.expediagroup.beekeeper.api.test.error; +package com.expediagroup.beekeeper.api.error; import org.junit.jupiter.api.Test; import org.springframework.http.HttpStatus; @@ -55,7 +55,7 @@ public void handlePropertyReferenceException_ShouldReturnBadRequest() { assertThat(errorResponse).isNotNull(); assertThat(errorResponse.getStatus()).isEqualTo(HttpStatus.BAD_REQUEST.value()); assertThat(errorResponse.getError()).isEqualTo("Bad Request"); - assertThat(errorResponse.getMessage()).contains("Invalid sort parameter"); + assertThat(errorResponse.getMessage()).isEqualTo(exception.getMessage()); assertThat(errorResponse.getPath()).isEqualTo("/api/v1/database/testDb/table/testTable/unreferenced-paths"); assertThat(errorResponse.getTimestamp()).isNotNull(); } From d7cb03e99c482cce4935f39c770959915c0c8d40 Mon Sep 17 00:00:00 2001 From: Hamza Jugon <104994559+HamzaJugon@users.noreply.github.com> Date: Fri, 25 Oct 2024 00:35:37 +0100 Subject: [PATCH 19/20] Updating integration test for newer generic error thrown --- .../beekeeper/integration/api/BeekeeperApiIntegrationTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beekeeper-integration-tests/src/test/java/com/expediagroup/beekeeper/integration/api/BeekeeperApiIntegrationTest.java b/beekeeper-integration-tests/src/test/java/com/expediagroup/beekeeper/integration/api/BeekeeperApiIntegrationTest.java index 55c1fce4..8af7159b 100644 --- a/beekeeper-integration-tests/src/test/java/com/expediagroup/beekeeper/integration/api/BeekeeperApiIntegrationTest.java +++ b/beekeeper-integration-tests/src/test/java/com/expediagroup/beekeeper/integration/api/BeekeeperApiIntegrationTest.java @@ -317,7 +317,7 @@ public void testInvalidSortParameter() throws SQLException, IOException, Interru ErrorResponse errorResponse = mapper.readValue(body, ErrorResponse.class); assertThat(errorResponse.getStatus()).isEqualTo(HttpStatus.BAD_REQUEST.value()); - assertThat(errorResponse.getMessage()).contains("Invalid sort parameter"); + assertThat(errorResponse.getMessage()).isEqualTo("No property 'nonExistentProperty' found for type 'HousekeepingMetadata'"); assertThat(errorResponse.getError()).isEqualTo("Bad Request"); assertThat(errorResponse.getPath()).contains("/api/v1/database/some_database/table/some_table/metadata"); assertThat(errorResponse.getTimestamp()).isNotNull(); From 23572a2e8d2b33d01b4c79d3235574c36ab86486 Mon Sep 17 00:00:00 2001 From: Hamza Jugon <104994559+HamzaJugon@users.noreply.github.com> Date: Fri, 25 Oct 2024 08:31:14 +0100 Subject: [PATCH 20/20] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c191737..72016af8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [3.5.7] - 2024-10-24 +## [3.5.7] - 2024-10-25 ### Changed - Added error handling for bad requests with incorrect sort parameters. - Added automatic pagination handling in the `/unreferenced-paths` endpoint for improved Swagger documentation.