From 2ede17fd67023a5b1112eace7919b8abc9e4a1fb Mon Sep 17 00:00:00 2001 From: Marten Date: Thu, 14 Dec 2023 14:29:48 +0100 Subject: [PATCH] refactor: marked obsolete exceptions as deprecated --- .../commons/exception/BadRequestException.java | 4 ++++ .../commons/exception/NotFoundException.java | 4 ++++ commons-rest-openapi/pom.xml | 6 ------ .../commons/openapi/DefaultOpenApiConverter.java | 6 ++++++ .../commons/openapi/GenerateClientTest.java | 15 +++++++++++++-- .../BadRequestExceptionHandler.java | 4 ++++ .../NotFoundExceptionHandler.java | 4 ++++ 7 files changed, 35 insertions(+), 8 deletions(-) diff --git a/commons-rest-api/src/main/java/io/rocketbase/commons/exception/BadRequestException.java b/commons-rest-api/src/main/java/io/rocketbase/commons/exception/BadRequestException.java index 45c9b06..0eb6173 100644 --- a/commons-rest-api/src/main/java/io/rocketbase/commons/exception/BadRequestException.java +++ b/commons-rest-api/src/main/java/io/rocketbase/commons/exception/BadRequestException.java @@ -3,6 +3,10 @@ import io.rocketbase.commons.dto.ErrorResponse; import lombok.Getter; +/** + * will get later replaced by javax.ws.rs.BadRequestException + */ +@Deprecated public class BadRequestException extends RuntimeException { @Getter diff --git a/commons-rest-api/src/main/java/io/rocketbase/commons/exception/NotFoundException.java b/commons-rest-api/src/main/java/io/rocketbase/commons/exception/NotFoundException.java index 95933a1..1bf9988 100644 --- a/commons-rest-api/src/main/java/io/rocketbase/commons/exception/NotFoundException.java +++ b/commons-rest-api/src/main/java/io/rocketbase/commons/exception/NotFoundException.java @@ -3,6 +3,10 @@ import io.rocketbase.commons.dto.ErrorResponse; import lombok.Getter; +/** + * will get later replaced by javax.ws.rs.NotFoundException + */ +@Deprecated public class NotFoundException extends RuntimeException { @Getter diff --git a/commons-rest-openapi/pom.xml b/commons-rest-openapi/pom.xml index 1fa797f..ce15f8f 100644 --- a/commons-rest-openapi/pom.xml +++ b/commons-rest-openapi/pom.xml @@ -56,11 +56,5 @@ spring-boot-starter-test test - - commons-io - commons-io - 2.13.0 - test - diff --git a/commons-rest-openapi/src/main/java/io/rocketbase/commons/openapi/DefaultOpenApiConverter.java b/commons-rest-openapi/src/main/java/io/rocketbase/commons/openapi/DefaultOpenApiConverter.java index d5bc25c..28b0a7b 100644 --- a/commons-rest-openapi/src/main/java/io/rocketbase/commons/openapi/DefaultOpenApiConverter.java +++ b/commons-rest-openapi/src/main/java/io/rocketbase/commons/openapi/DefaultOpenApiConverter.java @@ -99,6 +99,12 @@ protected String convertType(String type) { if ("Integer".equalsIgnoreCase(type) || "Long".equalsIgnoreCase(type) || "Double".equalsIgnoreCase(type) || "Float".equalsIgnoreCase(type) || "Short".equalsIgnoreCase(type) || "BigDecimal".equalsIgnoreCase(type)) { type = "number"; } + if (type != null && type.endsWith("TSID")) { + return "string"; + } + if (type != null && type.endsWith("JsonNode")) { + return "any"; + } for (String java : getJavaToUnknowns()) { if (java.equalsIgnoreCase(type)) { return "unknown"; diff --git a/commons-rest-openapi/src/test/java/io/rocketbase/commons/openapi/GenerateClientTest.java b/commons-rest-openapi/src/test/java/io/rocketbase/commons/openapi/GenerateClientTest.java index ef74557..2f0b10e 100644 --- a/commons-rest-openapi/src/test/java/io/rocketbase/commons/openapi/GenerateClientTest.java +++ b/commons-rest-openapi/src/test/java/io/rocketbase/commons/openapi/GenerateClientTest.java @@ -3,7 +3,6 @@ import io.rocketbase.commons.openapi.sample.SampleApplication; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.io.FileUtils; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Value; @@ -11,7 +10,11 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; import java.net.URL; +import java.nio.channels.Channels; +import java.nio.channels.ReadableByteChannel; @Slf4j @ExtendWith(SpringExtension.class) @@ -24,7 +27,15 @@ public class GenerateClientTest { @Test public void downloadZip() throws Exception { File destination = new File("target/test.zip"); - FileUtils.copyURLToFile(new URL(baseUrl + "/generator/client/v4/test.zip"), destination); + download(new URL(baseUrl + "/generator/client/v4/test.zip"), destination); log.info("downloaded: {}", destination.getAbsolutePath()); } + + private static void download(URL url, File file) throws IOException { + ReadableByteChannel rbc = Channels.newChannel(url.openStream()); + FileOutputStream fos = new FileOutputStream(file); + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + fos.close(); + rbc.close(); + } } diff --git a/commons-rest-server/src/main/java/io/rocketbase/commons/controller/exceptionhandler/BadRequestExceptionHandler.java b/commons-rest-server/src/main/java/io/rocketbase/commons/controller/exceptionhandler/BadRequestExceptionHandler.java index a48587d..20949b6 100644 --- a/commons-rest-server/src/main/java/io/rocketbase/commons/controller/exceptionhandler/BadRequestExceptionHandler.java +++ b/commons-rest-server/src/main/java/io/rocketbase/commons/controller/exceptionhandler/BadRequestExceptionHandler.java @@ -9,6 +9,10 @@ import static org.springframework.http.HttpStatus.BAD_REQUEST; +/** + * exception will get later replaced by javax.ws.rs.BadRequestException so that this handler is not needed anymore + */ +@Deprecated @ControllerAdvice public class BadRequestExceptionHandler extends BaseExceptionHandler { diff --git a/commons-rest-server/src/main/java/io/rocketbase/commons/controller/exceptionhandler/NotFoundExceptionHandler.java b/commons-rest-server/src/main/java/io/rocketbase/commons/controller/exceptionhandler/NotFoundExceptionHandler.java index 11f3713..8b83927 100644 --- a/commons-rest-server/src/main/java/io/rocketbase/commons/controller/exceptionhandler/NotFoundExceptionHandler.java +++ b/commons-rest-server/src/main/java/io/rocketbase/commons/controller/exceptionhandler/NotFoundExceptionHandler.java @@ -9,6 +9,10 @@ import static org.springframework.http.HttpStatus.NOT_FOUND; +/** + * exception will get later replaced by javax.ws.rs.NotFoundException so that this handler is not needed anymore + */ +@Deprecated @ControllerAdvice public class NotFoundExceptionHandler extends BaseExceptionHandler {