Code format hawkbit-rest-core (#1944)
Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -9,92 +9,92 @@
|
|||||||
SPDX-License-Identifier: EPL-2.0
|
SPDX-License-Identifier: EPL-2.0
|
||||||
|
|
||||||
-->
|
-->
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>org.eclipse.hawkbit</groupId>
|
<groupId>org.eclipse.hawkbit</groupId>
|
||||||
<artifactId>hawkbit-rest-parent</artifactId>
|
<artifactId>hawkbit-rest-parent</artifactId>
|
||||||
<version>${revision}</version>
|
<version>${revision}</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>hawkbit-rest-core</artifactId>
|
<artifactId>hawkbit-rest-core</artifactId>
|
||||||
<name>hawkBit :: REST :: Core</name>
|
<name>hawkBit :: REST :: Core</name>
|
||||||
|
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.eclipse.hawkbit</groupId>
|
<groupId>org.eclipse.hawkbit</groupId>
|
||||||
<artifactId>hawkbit-core</artifactId>
|
<artifactId>hawkbit-core</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.commons</groupId>
|
<groupId>org.apache.commons</groupId>
|
||||||
<artifactId>commons-lang3</artifactId>
|
<artifactId>commons-lang3</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.hateoas</groupId>
|
<groupId>org.springframework.hateoas</groupId>
|
||||||
<artifactId>spring-hateoas</artifactId>
|
<artifactId>spring-hateoas</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.data</groupId>
|
<groupId>org.springframework.data</groupId>
|
||||||
<artifactId>spring-data-commons</artifactId>
|
<artifactId>spring-data-commons</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-json</artifactId>
|
<artifactId>spring-boot-starter-json</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springdoc</groupId>
|
<groupId>org.springdoc</groupId>
|
||||||
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
|
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>jakarta.servlet</groupId>
|
<groupId>jakarta.servlet</groupId>
|
||||||
<artifactId>jakarta.servlet-api</artifactId>
|
<artifactId>jakarta.servlet-api</artifactId>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Test -->
|
<!-- Test -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.eclipse.hawkbit</groupId>
|
<groupId>org.eclipse.hawkbit</groupId>
|
||||||
<artifactId>hawkbit-repository-test</artifactId>
|
<artifactId>hawkbit-repository-test</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.eclipse.hawkbit</groupId>
|
<groupId>org.eclipse.hawkbit</groupId>
|
||||||
<artifactId>hawkbit-repository-jpa</artifactId>
|
<artifactId>hawkbit-repository-jpa</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.qameta.allure</groupId>
|
<groupId>io.qameta.allure</groupId>
|
||||||
<artifactId>allure-junit5</artifactId>
|
<artifactId>allure-junit5</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<goals>
|
<goals>
|
||||||
<goal>test-jar</goal>
|
<goal>test-jar</goal>
|
||||||
</goals>
|
</goals>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
</project>
|
</project>
|
||||||
@@ -20,83 +20,84 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@ConditionalOnProperty(
|
@ConditionalOnProperty(
|
||||||
value="hawkbit.server.swagger.enabled",
|
value = "hawkbit.server.swagger.enabled",
|
||||||
havingValue = "true",
|
havingValue = "true",
|
||||||
matchIfMissing = true)
|
matchIfMissing = true)
|
||||||
public class OpenApiConfiguration {
|
public class OpenApiConfiguration {
|
||||||
|
|
||||||
private static final String API_TITLE = "hawkBit REST APIs";
|
private static final String API_TITLE = "hawkBit REST APIs";
|
||||||
private static final String API_VERSION = "v1";
|
private static final String API_VERSION = "v1";
|
||||||
private static final String DESCRIPTION = """
|
private static final String DESCRIPTION = """
|
||||||
Eclipse hawkBit™ is a domain-independent back-end framework for rolling out software updates to constrained edge devices as well as more powerful controllers and gateways connected to IP based networking infrastructure.
|
Eclipse hawkBit™ is a domain-independent back-end framework for rolling out software updates to constrained edge devices as well as more powerful controllers and gateways connected to IP based networking infrastructure.
|
||||||
""";
|
""";
|
||||||
|
|
||||||
private static final String BASIC_AUTH_SEC_SCHEME_NAME = "Basic Authentication";
|
private static final String BASIC_AUTH_SEC_SCHEME_NAME = "Basic Authentication";
|
||||||
private static final String BEARER_AUTH_SEC_SCHEME_NAME = "Bearer Authentication";
|
private static final String BEARER_AUTH_SEC_SCHEME_NAME = "Bearer Authentication";
|
||||||
private static final String DDI_TOKEN_SEC_SCHEME_NAME = "DDI Target/GatewayToken Authentication";
|
private static final String DDI_TOKEN_SEC_SCHEME_NAME = "DDI Target/GatewayToken Authentication";
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public OpenAPI openApi() {
|
public OpenAPI openApi() {
|
||||||
return new OpenAPI().info(new Info().title(API_TITLE).version(API_VERSION).description(DESCRIPTION));
|
return new OpenAPI().info(new Info().title(API_TITLE).version(API_VERSION).description(DESCRIPTION));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnProperty(
|
@ConditionalOnProperty(
|
||||||
value="hawkbit.server.swagger.mgmt.api.group.enabled",
|
value = "hawkbit.server.swagger.mgmt.api.group.enabled",
|
||||||
havingValue = "true",
|
havingValue = "true",
|
||||||
matchIfMissing = true)
|
matchIfMissing = true)
|
||||||
public GroupedOpenApi mgmtApi() {
|
public GroupedOpenApi mgmtApi() {
|
||||||
return GroupedOpenApi
|
return GroupedOpenApi
|
||||||
.builder()
|
.builder()
|
||||||
.group("Management API")
|
.group("Management API")
|
||||||
.pathsToMatch("/rest/v1/**")
|
.pathsToMatch("/rest/v1/**")
|
||||||
.addOpenApiCustomizer(openApi -> {
|
.addOpenApiCustomizer(openApi -> {
|
||||||
openApi
|
|
||||||
.addSecurityItem(new SecurityRequirement()
|
|
||||||
.addList(BASIC_AUTH_SEC_SCHEME_NAME)
|
|
||||||
.addList(BEARER_AUTH_SEC_SCHEME_NAME))
|
|
||||||
.components(
|
|
||||||
openApi
|
openApi
|
||||||
.getComponents()
|
.addSecurityItem(new SecurityRequirement()
|
||||||
.addSecuritySchemes(BASIC_AUTH_SEC_SCHEME_NAME,
|
.addList(BASIC_AUTH_SEC_SCHEME_NAME)
|
||||||
new SecurityScheme()
|
.addList(BEARER_AUTH_SEC_SCHEME_NAME))
|
||||||
.name(BASIC_AUTH_SEC_SCHEME_NAME)
|
.components(
|
||||||
.type(SecurityScheme.Type.HTTP)
|
openApi
|
||||||
.in(SecurityScheme.In.HEADER)
|
.getComponents()
|
||||||
.scheme("basic"))
|
.addSecuritySchemes(BASIC_AUTH_SEC_SCHEME_NAME,
|
||||||
.addSecuritySchemes(BEARER_AUTH_SEC_SCHEME_NAME,
|
new SecurityScheme()
|
||||||
new SecurityScheme()
|
.name(BASIC_AUTH_SEC_SCHEME_NAME)
|
||||||
.name(BEARER_AUTH_SEC_SCHEME_NAME)
|
.type(SecurityScheme.Type.HTTP)
|
||||||
.type(SecurityScheme.Type.HTTP)
|
.in(SecurityScheme.In.HEADER)
|
||||||
.in(SecurityScheme.In.HEADER)
|
.scheme("basic"))
|
||||||
.bearerFormat("JWT")
|
.addSecuritySchemes(BEARER_AUTH_SEC_SCHEME_NAME,
|
||||||
.scheme("bearer")));
|
new SecurityScheme()
|
||||||
})
|
.name(BEARER_AUTH_SEC_SCHEME_NAME)
|
||||||
.build();
|
.type(SecurityScheme.Type.HTTP)
|
||||||
}
|
.in(SecurityScheme.In.HEADER)
|
||||||
@Bean
|
.bearerFormat("JWT")
|
||||||
@ConditionalOnProperty(
|
.scheme("bearer")));
|
||||||
value="hawkbit.server.swagger.ddi.api.group.enabled",
|
})
|
||||||
havingValue = "true",
|
.build();
|
||||||
matchIfMissing = true)
|
}
|
||||||
public GroupedOpenApi ddiApi() {
|
|
||||||
return GroupedOpenApi
|
@Bean
|
||||||
.builder()
|
@ConditionalOnProperty(
|
||||||
.group("Direct Device Integration API")
|
value = "hawkbit.server.swagger.ddi.api.group.enabled",
|
||||||
.pathsToMatch("/{tenant}/controller/**")
|
havingValue = "true",
|
||||||
.addOpenApiCustomizer(openApi -> {
|
matchIfMissing = true)
|
||||||
openApi
|
public GroupedOpenApi ddiApi() {
|
||||||
.addSecurityItem(new SecurityRequirement().addList(DDI_TOKEN_SEC_SCHEME_NAME))
|
return GroupedOpenApi
|
||||||
.components(
|
.builder()
|
||||||
|
.group("Direct Device Integration API")
|
||||||
|
.pathsToMatch("/{tenant}/controller/**")
|
||||||
|
.addOpenApiCustomizer(openApi -> {
|
||||||
openApi
|
openApi
|
||||||
.getComponents()
|
.addSecurityItem(new SecurityRequirement().addList(DDI_TOKEN_SEC_SCHEME_NAME))
|
||||||
.addSecuritySchemes(DDI_TOKEN_SEC_SCHEME_NAME,
|
.components(
|
||||||
new SecurityScheme()
|
openApi
|
||||||
.name("Authorization")
|
.getComponents()
|
||||||
.type(SecurityScheme.Type.APIKEY)
|
.addSecuritySchemes(DDI_TOKEN_SEC_SCHEME_NAME,
|
||||||
.in(SecurityScheme.In.HEADER)
|
new SecurityScheme()
|
||||||
.description("Format: (Target|Gateway)Token <token>")));
|
.name("Authorization")
|
||||||
})
|
.type(SecurityScheme.Type.APIKEY)
|
||||||
.build();
|
.in(SecurityScheme.In.HEADER)
|
||||||
}
|
.description("Format: (Target|Gateway)Token <token>")));
|
||||||
|
})
|
||||||
|
.build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,8 +9,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.eclipse.hawkbit.rest;
|
package org.eclipse.hawkbit.rest;
|
||||||
|
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
|
||||||
|
|
||||||
import org.eclipse.hawkbit.rest.exception.ResponseExceptionHandler;
|
import org.eclipse.hawkbit.rest.exception.ResponseExceptionHandler;
|
||||||
import org.eclipse.hawkbit.rest.filter.ExcludePathAwareShallowETagFilter;
|
import org.eclipse.hawkbit.rest.filter.ExcludePathAwareShallowETagFilter;
|
||||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||||
@@ -20,7 +18,6 @@ import org.springframework.hateoas.config.EnableHypermediaSupport;
|
|||||||
import org.springframework.hateoas.config.EnableHypermediaSupport.HypermediaType;
|
import org.springframework.hateoas.config.EnableHypermediaSupport.HypermediaType;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||||
import org.springframework.web.context.WebApplicationContext;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configuration for Rest api.
|
* Configuration for Rest api.
|
||||||
|
|||||||
@@ -26,8 +26,7 @@ public class ResponseList<T> extends RepresentationModel<ResponseList<T>> implem
|
|||||||
private final List<T> content;
|
private final List<T> content;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param content
|
* @param content to delegate
|
||||||
* to delegate
|
|
||||||
*/
|
*/
|
||||||
public ResponseList(final List<T> content) {
|
public ResponseList(final List<T> content) {
|
||||||
this.content = content;
|
this.content = content;
|
||||||
@@ -103,16 +102,6 @@ public class ResponseList<T> extends RepresentationModel<ResponseList<T>> implem
|
|||||||
content.clear();
|
content.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(final Object o) {
|
|
||||||
return content.equals(o);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return content.hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public T get(final int index) {
|
public T get(final int index) {
|
||||||
return content.get(index);
|
return content.get(index);
|
||||||
@@ -163,4 +152,14 @@ public class ResponseList<T> extends RepresentationModel<ResponseList<T>> implem
|
|||||||
return "ResponseList [content=" + content + "]";
|
return "ResponseList [content=" + content + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(final Object o) {
|
||||||
|
return content.equals(o);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return content.hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,11 +27,9 @@ public enum SortDirection {
|
|||||||
/**
|
/**
|
||||||
* Returns the sort direction for the given name.
|
* Returns the sort direction for the given name.
|
||||||
*
|
*
|
||||||
* @param name
|
* @param name the name of the enum
|
||||||
* the name of the enum
|
|
||||||
* @return the corresponding enum
|
* @return the corresponding enum
|
||||||
* @throws SortParameterUnsupportedDirectionException
|
* @throws SortParameterUnsupportedDirectionException if there is no matching enum for the specified name
|
||||||
* if there is no matching enum for the specified name
|
|
||||||
*/
|
*/
|
||||||
public static SortDirection getByName(final String name) {
|
public static SortDirection getByName(final String name) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -9,11 +9,11 @@
|
|||||||
*/
|
*/
|
||||||
package org.eclipse.hawkbit.rest.exception;
|
package org.eclipse.hawkbit.rest.exception;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
|
||||||
import org.eclipse.hawkbit.exception.AbstractServerRtException;
|
import org.eclipse.hawkbit.exception.AbstractServerRtException;
|
||||||
import org.eclipse.hawkbit.exception.SpServerError;
|
import org.eclipse.hawkbit.exception.SpServerError;
|
||||||
|
|
||||||
import java.io.Serial;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exception which is thrown in case an request body is not well formatted and
|
* Exception which is thrown in case an request body is not well formatted and
|
||||||
* cannot be parsed.
|
* cannot be parsed.
|
||||||
|
|||||||
@@ -14,15 +14,13 @@ import org.eclipse.hawkbit.exception.SpServerError;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Thrown if a multi part exception occurred.
|
* Thrown if a multi part exception occurred.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public final class MultiPartFileUploadException extends AbstractServerRtException {
|
public final class MultiPartFileUploadException extends AbstractServerRtException {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param cause
|
* @param cause for the exception
|
||||||
* for the exception
|
|
||||||
*/
|
*/
|
||||||
public MultiPartFileUploadException(final Throwable cause) {
|
public MultiPartFileUploadException(final Throwable cause) {
|
||||||
super(cause.getMessage(), SpServerError.SP_ARTIFACT_UPLOAD_FAILED, cause);
|
super(cause.getMessage(), SpServerError.SP_ARTIFACT_UPLOAD_FAILED, cause);
|
||||||
|
|||||||
@@ -99,19 +99,12 @@ public class ResponseExceptionHandler {
|
|||||||
ERROR_TO_HTTP_STATUS.put(SpServerError.SP_STOP_ROLLOUT_FAILED, HttpStatus.LOCKED);
|
ERROR_TO_HTTP_STATUS.put(SpServerError.SP_STOP_ROLLOUT_FAILED, HttpStatus.LOCKED);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static HttpStatus getStatusOrDefault(final SpServerError error) {
|
|
||||||
return ERROR_TO_HTTP_STATUS.getOrDefault(error, DEFAULT_RESPONSE_STATUS);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* method for handling exception of type AbstractServerRtException. Called
|
* method for handling exception of type AbstractServerRtException. Called
|
||||||
* by the Spring-Framework for exception handling.
|
* by the Spring-Framework for exception handling.
|
||||||
*
|
*
|
||||||
* @param request
|
* @param request the Http request
|
||||||
* the Http request
|
* @param ex the exception which occurred
|
||||||
* @param ex
|
|
||||||
* the exception which occurred
|
|
||||||
*
|
|
||||||
* @return the entity to be responded containing the exception information
|
* @return the entity to be responded containing the exception information
|
||||||
* as entity.
|
* as entity.
|
||||||
*/
|
*/
|
||||||
@@ -137,10 +130,8 @@ public class ResponseExceptionHandler {
|
|||||||
* ResponseStatus 500 is returned. Called by the Spring-Framework for
|
* ResponseStatus 500 is returned. Called by the Spring-Framework for
|
||||||
* exception handling.
|
* exception handling.
|
||||||
*
|
*
|
||||||
* @param request
|
* @param request the Http request
|
||||||
* the Http request
|
* @param ex the exception which occurred
|
||||||
* @param ex
|
|
||||||
* the exception which occurred
|
|
||||||
* @return the entity to be responded containing the response status 500
|
* @return the entity to be responded containing the response status 500
|
||||||
*/
|
*/
|
||||||
@ExceptionHandler(FileStreamingFailedException.class)
|
@ExceptionHandler(FileStreamingFailedException.class)
|
||||||
@@ -158,10 +149,8 @@ public class ResponseExceptionHandler {
|
|||||||
* cannot be deserialized. Called by the Spring-Framework for exception
|
* cannot be deserialized. Called by the Spring-Framework for exception
|
||||||
* handling.
|
* handling.
|
||||||
*
|
*
|
||||||
* @param request
|
* @param request the Http request
|
||||||
* the Http request
|
* @param ex the exception which occurred
|
||||||
* @param ex
|
|
||||||
* the exception which occurred
|
|
||||||
* @return the entity to be responded containing the exception information
|
* @return the entity to be responded containing the exception information
|
||||||
* as entity.
|
* as entity.
|
||||||
*/
|
*/
|
||||||
@@ -181,10 +170,8 @@ public class ResponseExceptionHandler {
|
|||||||
* is thrown in case the request is rejected due to a constraint violation.
|
* is thrown in case the request is rejected due to a constraint violation.
|
||||||
* Called by the Spring-Framework for exception handling.
|
* Called by the Spring-Framework for exception handling.
|
||||||
*
|
*
|
||||||
* @param request
|
* @param request the Http request
|
||||||
* the Http request
|
* @param ex the exception which occurred
|
||||||
* @param ex
|
|
||||||
* the exception which occurred
|
|
||||||
* @return the entity to be responded containing the exception information
|
* @return the entity to be responded containing the exception information
|
||||||
* as entity.
|
* as entity.
|
||||||
*/
|
*/
|
||||||
@@ -195,7 +182,7 @@ public class ResponseExceptionHandler {
|
|||||||
|
|
||||||
final ExceptionInfo response = new ExceptionInfo();
|
final ExceptionInfo response = new ExceptionInfo();
|
||||||
response.setMessage(ex.getConstraintViolations().stream().map(
|
response.setMessage(ex.getConstraintViolations().stream().map(
|
||||||
violation -> violation.getPropertyPath() + MESSAGE_FORMATTER_SEPARATOR + violation.getMessage() + ".")
|
violation -> violation.getPropertyPath() + MESSAGE_FORMATTER_SEPARATOR + violation.getMessage() + ".")
|
||||||
.collect(Collectors.joining(MESSAGE_FORMATTER_SEPARATOR)));
|
.collect(Collectors.joining(MESSAGE_FORMATTER_SEPARATOR)));
|
||||||
response.setExceptionClass(ex.getClass().getName());
|
response.setExceptionClass(ex.getClass().getName());
|
||||||
response.setErrorCode(SpServerError.SP_REPO_CONSTRAINT_VIOLATION.getKey());
|
response.setErrorCode(SpServerError.SP_REPO_CONSTRAINT_VIOLATION.getKey());
|
||||||
@@ -208,10 +195,8 @@ public class ResponseExceptionHandler {
|
|||||||
* in case the request is rejected due to invalid requests. Called by the
|
* in case the request is rejected due to invalid requests. Called by the
|
||||||
* Spring-Framework for exception handling.
|
* Spring-Framework for exception handling.
|
||||||
*
|
*
|
||||||
* @param request
|
* @param request the Http request
|
||||||
* the Http request
|
* @param ex the exception which occurred
|
||||||
* @param ex
|
|
||||||
* the exception which occurred
|
|
||||||
* @return the entity to be responded containing the exception information
|
* @return the entity to be responded containing the exception information
|
||||||
* as entity.
|
* as entity.
|
||||||
*/
|
*/
|
||||||
@@ -233,10 +218,8 @@ public class ResponseExceptionHandler {
|
|||||||
* thrown in case the request body is not well formed and cannot be
|
* thrown in case the request body is not well formed and cannot be
|
||||||
* deserialized. Called by the Spring-Framework for exception handling.
|
* deserialized. Called by the Spring-Framework for exception handling.
|
||||||
*
|
*
|
||||||
* @param request
|
* @param request the Http request
|
||||||
* the Http request
|
* @param ex the exception which occurred
|
||||||
* @param ex
|
|
||||||
* the exception which occurred
|
|
||||||
* @return the entity to be responded containing the exception information
|
* @return the entity to be responded containing the exception information
|
||||||
* as entity.
|
* as entity.
|
||||||
*/
|
*/
|
||||||
@@ -258,6 +241,10 @@ public class ResponseExceptionHandler {
|
|||||||
return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST);
|
return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static HttpStatus getStatusOrDefault(final SpServerError error) {
|
||||||
|
return ERROR_TO_HTTP_STATUS.getOrDefault(error, DEFAULT_RESPONSE_STATUS);
|
||||||
|
}
|
||||||
|
|
||||||
private void logRequest(final HttpServletRequest request, final Exception ex) {
|
private void logRequest(final HttpServletRequest request, final Exception ex) {
|
||||||
log.debug("Handling exception {} of request {}", ex.getClass().getName(), request.getRequestURL());
|
log.debug("Handling exception {} of request {}", ex.getClass().getName(), request.getRequestURL());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,16 +14,12 @@ import org.eclipse.hawkbit.exception.SpServerError;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Exception used by the REST API in case of invalid sort parameter syntax.
|
* Exception used by the REST API in case of invalid sort parameter syntax.
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class SortParameterSyntaxErrorException extends AbstractServerRtException {
|
public class SortParameterSyntaxErrorException extends AbstractServerRtException {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -15,16 +15,12 @@ import org.eclipse.hawkbit.exception.SpServerError;
|
|||||||
/**
|
/**
|
||||||
* Exception used by the REST API in case of invalid sort parameter direction
|
* Exception used by the REST API in case of invalid sort parameter direction
|
||||||
* name.
|
* name.
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class SortParameterUnsupportedDirectionException extends AbstractServerRtException {
|
public class SortParameterUnsupportedDirectionException extends AbstractServerRtException {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -38,10 +34,9 @@ public class SortParameterUnsupportedDirectionException extends AbstractServerRt
|
|||||||
* Creates a new SortParameterSyntaxErrorException with
|
* Creates a new SortParameterSyntaxErrorException with
|
||||||
* {@link SpServerError#SP_REST_SORT_PARAM_INVALID_DIRECTION} error.
|
* {@link SpServerError#SP_REST_SORT_PARAM_INVALID_DIRECTION} error.
|
||||||
*
|
*
|
||||||
* @param cause
|
* @param cause the cause (which is saved for later retrieval by the
|
||||||
* the cause (which is saved for later retrieval by the
|
* getCause() method). (A null value is permitted, and indicates
|
||||||
* getCause() method). (A null value is permitted, and indicates
|
* that the cause is nonexistent or unknown.)
|
||||||
* that the cause is nonexistent or unknown.)
|
|
||||||
*/
|
*/
|
||||||
public SortParameterUnsupportedDirectionException(final Throwable cause) {
|
public SortParameterUnsupportedDirectionException(final Throwable cause) {
|
||||||
super(SpServerError.SP_REST_SORT_PARAM_INVALID_DIRECTION, cause);
|
super(SpServerError.SP_REST_SORT_PARAM_INVALID_DIRECTION, cause);
|
||||||
|
|||||||
@@ -15,16 +15,12 @@ import org.eclipse.hawkbit.exception.SpServerError;
|
|||||||
/**
|
/**
|
||||||
* Exception used by the REST API in case of invalid field name in the sort
|
* Exception used by the REST API in case of invalid field name in the sort
|
||||||
* parameter.
|
* parameter.
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class SortParameterUnsupportedFieldException extends AbstractServerRtException {
|
public class SortParameterUnsupportedFieldException extends AbstractServerRtException {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -39,10 +35,9 @@ public class SortParameterUnsupportedFieldException extends AbstractServerRtExce
|
|||||||
* Creates a new SortParameterSyntaxErrorException with
|
* Creates a new SortParameterSyntaxErrorException with
|
||||||
* {@link SpServerError#SP_REST_SORT_PARAM_INVALID_FIELD} error.
|
* {@link SpServerError#SP_REST_SORT_PARAM_INVALID_FIELD} error.
|
||||||
*
|
*
|
||||||
* @param cause
|
* @param cause the cause (which is saved for later retrieval by the
|
||||||
* the cause (which is saved for later retrieval by the
|
* getCause() method). (A null value is permitted, and indicates
|
||||||
* getCause() method). (A null value is permitted, and indicates
|
* that the cause is nonexistent or unknown.)
|
||||||
* that the cause is nonexistent or unknown.)
|
|
||||||
*/
|
*/
|
||||||
public SortParameterUnsupportedFieldException(final Throwable cause) {
|
public SortParameterUnsupportedFieldException(final Throwable cause) {
|
||||||
super(SpServerError.SP_REST_SORT_PARAM_INVALID_FIELD, cause);
|
super(SpServerError.SP_REST_SORT_PARAM_INVALID_FIELD, cause);
|
||||||
|
|||||||
@@ -30,8 +30,7 @@ public final class FileStreamingFailedException extends AbstractServerRtExceptio
|
|||||||
/**
|
/**
|
||||||
* Constructor with Throwable.
|
* Constructor with Throwable.
|
||||||
*
|
*
|
||||||
* @param cause
|
* @param cause for the exception
|
||||||
* for the exception
|
|
||||||
*/
|
*/
|
||||||
public FileStreamingFailedException(final Throwable cause) {
|
public FileStreamingFailedException(final Throwable cause) {
|
||||||
super(SpServerError.SP_ARTIFACT_LOAD_FAILED, cause);
|
super(SpServerError.SP_ARTIFACT_LOAD_FAILED, cause);
|
||||||
@@ -40,8 +39,7 @@ public final class FileStreamingFailedException extends AbstractServerRtExceptio
|
|||||||
/**
|
/**
|
||||||
* Constructor with error string.
|
* Constructor with error string.
|
||||||
*
|
*
|
||||||
* @param message
|
* @param message of the error
|
||||||
* of the error
|
|
||||||
*/
|
*/
|
||||||
public FileStreamingFailedException(final String message) {
|
public FileStreamingFailedException(final String message) {
|
||||||
super(message, SpServerError.SP_ARTIFACT_LOAD_FAILED);
|
super(message, SpServerError.SP_ARTIFACT_LOAD_FAILED);
|
||||||
@@ -50,10 +48,8 @@ public final class FileStreamingFailedException extends AbstractServerRtExceptio
|
|||||||
/**
|
/**
|
||||||
* Constructor with error string and cause.
|
* Constructor with error string and cause.
|
||||||
*
|
*
|
||||||
* @param message
|
* @param message of the error
|
||||||
* of the error
|
* @param cause for the exception
|
||||||
* @param cause
|
|
||||||
* for the exception
|
|
||||||
*/
|
*/
|
||||||
public FileStreamingFailedException(final String message, final Throwable cause) {
|
public FileStreamingFailedException(final String message, final Throwable cause) {
|
||||||
super(message, SpServerError.SP_ARTIFACT_LOAD_FAILED, cause);
|
super(message, SpServerError.SP_ARTIFACT_LOAD_FAILED, cause);
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ package org.eclipse.hawkbit.rest.util;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Listener for progress on artifact file streaming.
|
* Listener for progress on artifact file streaming.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface FileStreamingProgressListener {
|
public interface FileStreamingProgressListener {
|
||||||
@@ -19,12 +18,9 @@ public interface FileStreamingProgressListener {
|
|||||||
/**
|
/**
|
||||||
* Called multiple times during streaming.
|
* Called multiple times during streaming.
|
||||||
*
|
*
|
||||||
* @param requestedBytes
|
* @param requestedBytes requested bytes of the request
|
||||||
* requested bytes of the request
|
* @param shippedBytesSinceLast since the last report
|
||||||
* @param shippedBytesSinceLast
|
* @param shippedBytesOverall during the request
|
||||||
* since the last report
|
|
||||||
* @param shippedBytesOverall
|
|
||||||
* during the request
|
|
||||||
*/
|
*/
|
||||||
void progress(long requestedBytes, long shippedBytesSinceLast, long shippedBytesOverall);
|
void progress(long requestedBytes, long shippedBytesSinceLast, long shippedBytesOverall);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ package org.eclipse.hawkbit.rest.util;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.math.RoundingMode;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -50,15 +49,11 @@ public final class FileStreamingUtil {
|
|||||||
/**
|
/**
|
||||||
* Write a md5 file response.
|
* Write a md5 file response.
|
||||||
*
|
*
|
||||||
* @param response
|
* @param response the response
|
||||||
* the response
|
* @param md5Hash of the artifact
|
||||||
* @param md5Hash
|
* @param filename as provided by the client
|
||||||
* of the artifact
|
|
||||||
* @param filename
|
|
||||||
* as provided by the client
|
|
||||||
* @return the response
|
* @return the response
|
||||||
* @throws IOException
|
* @throws IOException cannot write output stream
|
||||||
* cannot write output stream
|
|
||||||
*/
|
*/
|
||||||
public static ResponseEntity<Void> writeMD5FileResponse(final HttpServletResponse response, final String md5Hash,
|
public static ResponseEntity<Void> writeMD5FileResponse(final HttpServletResponse response, final String md5Hash,
|
||||||
final String filename) throws IOException {
|
final String filename) throws IOException {
|
||||||
@@ -94,26 +89,16 @@ public final class FileStreamingUtil {
|
|||||||
* The request supports RFC7233 range requests.
|
* The request supports RFC7233 range requests.
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param artifact
|
* @param artifact the artifact
|
||||||
* the artifact
|
* @param filename to be written to the client response
|
||||||
* @param filename
|
* @param lastModified unix timestamp of the artifact
|
||||||
* to be written to the client response
|
* @param response to be sent back to the requesting client
|
||||||
* @param lastModified
|
* @param request from the client
|
||||||
* unix timestamp of the artifact
|
* @param progressListener to write progress updates to
|
||||||
* @param response
|
|
||||||
* to be sent back to the requesting client
|
|
||||||
* @param request
|
|
||||||
* from the client
|
|
||||||
* @param progressListener
|
|
||||||
* to write progress updates to
|
|
||||||
*
|
|
||||||
* @return http response
|
* @return http response
|
||||||
*
|
* @throws FileStreamingFailedException if streaming fails
|
||||||
* @see <a href="https://tools.ietf.org/html/rfc7233">https://tools.ietf.org
|
* @see <a href="https://tools.ietf.org/html/rfc7233">https://tools.ietf.org
|
||||||
* /html/rfc7233</a>
|
* /html/rfc7233</a>
|
||||||
*
|
|
||||||
* @throws FileStreamingFailedException
|
|
||||||
* if streaming fails
|
|
||||||
*/
|
*/
|
||||||
public static ResponseEntity<InputStream> writeFileResponse(final DbArtifact artifact, final String filename,
|
public static ResponseEntity<InputStream> writeFileResponse(final DbArtifact artifact, final String filename,
|
||||||
final long lastModified, final HttpServletResponse response, final HttpServletRequest request,
|
final long lastModified, final HttpServletResponse response, final HttpServletRequest request,
|
||||||
@@ -187,7 +172,7 @@ public final class FileStreamingUtil {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void resetResponseExceptHeaders(final HttpServletResponse response){
|
private static void resetResponseExceptHeaders(final HttpServletResponse response) {
|
||||||
// do backup the current headers (like CORS related)
|
// do backup the current headers (like CORS related)
|
||||||
final Map<String, String> storedHeaders = new HashMap<>();
|
final Map<String, String> storedHeaders = new HashMap<>();
|
||||||
for (final String header : response.getHeaderNames()) {
|
for (final String header : response.getHeaderNames()) {
|
||||||
@@ -359,7 +344,7 @@ public final class FileStreamingUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (progressListener != null) {
|
if (progressListener != null) {
|
||||||
final int newPercent = (int)Math.floor(total * 100.0 / length);
|
final int newPercent = (int) Math.floor(total * 100.0 / length);
|
||||||
|
|
||||||
// every 10 percent an event
|
// every 10 percent an event
|
||||||
if (newPercent == 100 || newPercent > progressPercent + 10) {
|
if (newPercent == 100 || newPercent > progressPercent + 10) {
|
||||||
@@ -383,6 +368,7 @@ public final class FileStreamingUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static final class ByteRange {
|
private static final class ByteRange {
|
||||||
|
|
||||||
private static final String MULTIPART_BOUNDARY = "THIS_STRING_SEPARATES_MULTIPART";
|
private static final String MULTIPART_BOUNDARY = "THIS_STRING_SEPARATES_MULTIPART";
|
||||||
|
|
||||||
private final long start;
|
private final long start;
|
||||||
@@ -397,22 +383,6 @@ public final class FileStreamingUtil {
|
|||||||
this.total = total;
|
this.total = total;
|
||||||
}
|
}
|
||||||
|
|
||||||
private long getStart() {
|
|
||||||
return start;
|
|
||||||
}
|
|
||||||
|
|
||||||
private long getEnd() {
|
|
||||||
return end;
|
|
||||||
}
|
|
||||||
|
|
||||||
private long getLength() {
|
|
||||||
return length;
|
|
||||||
}
|
|
||||||
|
|
||||||
private long getTotal() {
|
|
||||||
return total;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
// Generated code
|
// Generated code
|
||||||
@SuppressWarnings("squid:S864")
|
@SuppressWarnings("squid:S864")
|
||||||
@@ -455,6 +425,22 @@ public final class FileStreamingUtil {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private long getStart() {
|
||||||
|
return start;
|
||||||
|
}
|
||||||
|
|
||||||
|
private long getEnd() {
|
||||||
|
return end;
|
||||||
|
}
|
||||||
|
|
||||||
|
private long getLength() {
|
||||||
|
return length;
|
||||||
|
}
|
||||||
|
|
||||||
|
private long getTotal() {
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,11 +23,8 @@ public final class HttpUtil {
|
|||||||
/**
|
/**
|
||||||
* Checks given CSV string for defined match value or wildcard.
|
* Checks given CSV string for defined match value or wildcard.
|
||||||
*
|
*
|
||||||
* @param matchHeader
|
* @param matchHeader to search through
|
||||||
* to search through
|
* @param toMatch to search for
|
||||||
* @param toMatch
|
|
||||||
* to search for
|
|
||||||
*
|
|
||||||
* @return <code>true</code> if string matches.
|
* @return <code>true</code> if string matches.
|
||||||
*/
|
*/
|
||||||
public static boolean matchesHttpHeader(final String matchHeader, final String toMatch) {
|
public static boolean matchesHttpHeader(final String matchHeader, final String toMatch) {
|
||||||
|
|||||||
@@ -9,6 +9,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.eclipse.hawkbit.rest.util;
|
package org.eclipse.hawkbit.rest.util;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
@@ -16,8 +18,6 @@ import lombok.NoArgsConstructor;
|
|||||||
import org.springframework.web.context.request.RequestContextHolder;
|
import org.springframework.web.context.request.RequestContextHolder;
|
||||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gives access to the request and response for the rest resources.
|
* Gives access to the request and response for the rest resources.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -23,9 +23,6 @@ import org.springframework.data.domain.Sort.Order;
|
|||||||
/**
|
/**
|
||||||
* A utility class for parsing query parameters which define the sorting of
|
* A utility class for parsing query parameters which define the sorting of
|
||||||
* elements.
|
* elements.
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public final class SortUtility {
|
public final class SortUtility {
|
||||||
|
|
||||||
@@ -48,24 +45,18 @@ public final class SortUtility {
|
|||||||
* will be split into the keys of the returned map. The direction of the
|
* will be split into the keys of the returned map. The direction of the
|
||||||
* sorting will be mapped into the {@link Direction} enum.
|
* sorting will be mapped into the {@link Direction} enum.
|
||||||
*
|
*
|
||||||
* @param enumType
|
* @param enumType the class of the enum which the fields in the sort string
|
||||||
* the class of the enum which the fields in the sort string
|
* should be related to.
|
||||||
* should be related to.
|
* @param <T> the type of the enumeration which must be derived from
|
||||||
* @param <T>
|
* {@link RsqlQueryField}
|
||||||
* the type of the enumeration which must be derived from
|
* @param sortString the string representation of the query parameters. Might be
|
||||||
* {@link RsqlQueryField}
|
* {@code null} or an empty string.
|
||||||
* @param sortString
|
|
||||||
* the string representation of the query parameters. Might be
|
|
||||||
* {@code null} or an empty string.
|
|
||||||
* @return a list which holds the {@link RsqlQueryField} and the specific
|
* @return a list which holds the {@link RsqlQueryField} and the specific
|
||||||
* {@link Direction} for them as a tuple. Never {@code null}. In
|
* {@link Direction} for them as a tuple. Never {@code null}. In
|
||||||
* case of no sorting parameters an empty map will be returned.
|
* case of no sorting parameters an empty map will be returned.
|
||||||
* @throws SortParameterSyntaxErrorException
|
* @throws SortParameterSyntaxErrorException if the sorting query parameter is not well-formed
|
||||||
* if the sorting query parameter is not well-formed
|
* @throws SortParameterUnsupportedFieldException if a field name cannot be mapped to the enum type
|
||||||
* @throws SortParameterUnsupportedFieldException
|
* @throws SortParameterUnsupportedDirectionException if the given direction is not "ASC" or "DESC"
|
||||||
* if a field name cannot be mapped to the enum type
|
|
||||||
* @throws SortParameterUnsupportedDirectionException
|
|
||||||
* if the given direction is not "ASC" or "DESC"
|
|
||||||
*/
|
*/
|
||||||
public static <T extends Enum<T> & RsqlQueryField> List<Order> parse(final Class<T> enumType,
|
public static <T extends Enum<T> & RsqlQueryField> List<Order> parse(final Class<T> enumType,
|
||||||
final String sortString) throws SortParameterSyntaxErrorException {
|
final String sortString) throws SortParameterSyntaxErrorException {
|
||||||
@@ -96,17 +87,13 @@ public final class SortUtility {
|
|||||||
/**
|
/**
|
||||||
* Returns the attribute identifier for the given name.
|
* Returns the attribute identifier for the given name.
|
||||||
*
|
*
|
||||||
* @param enumType
|
* @param enumType the class of the enum which the fields in the sort string
|
||||||
* the class of the enum which the fields in the sort string
|
* should be related to.
|
||||||
* should be related to.
|
* @param name the name of the enum
|
||||||
* @param name
|
* @param <T> the type of the enumeration which must be derived from
|
||||||
* the name of the enum
|
* {@link RsqlQueryField}
|
||||||
* @param <T>
|
|
||||||
* the type of the enumeration which must be derived from
|
|
||||||
* {@link RsqlQueryField}
|
|
||||||
* @return the corresponding enum
|
* @return the corresponding enum
|
||||||
* @throws SortParameterUnsupportedFieldException
|
* @throws SortParameterUnsupportedFieldException if there is no matching enum for the specified name
|
||||||
* if there is no matching enum for the specified name
|
|
||||||
*/
|
*/
|
||||||
private static <T extends Enum<T> & RsqlQueryField> T getAttributeIdentifierByName(final Class<T> enumType,
|
private static <T extends Enum<T> & RsqlQueryField> T getAttributeIdentifierByName(final Class<T> enumType,
|
||||||
final String name) {
|
final String name) {
|
||||||
|
|||||||
@@ -32,19 +32,17 @@ import org.springframework.web.filter.CharacterEncodingFilter;
|
|||||||
*/
|
*/
|
||||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK)
|
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK)
|
||||||
@ContextConfiguration(classes = {
|
@ContextConfiguration(classes = {
|
||||||
RestConfiguration.class, RepositoryApplicationConfiguration.class, TestConfiguration.class})
|
RestConfiguration.class, RepositoryApplicationConfiguration.class, TestConfiguration.class })
|
||||||
@Import(TestChannelBinderConfiguration.class)
|
@Import(TestChannelBinderConfiguration.class)
|
||||||
@WebAppConfiguration
|
@WebAppConfiguration
|
||||||
@AutoConfigureMockMvc
|
@AutoConfigureMockMvc
|
||||||
public abstract class AbstractRestIntegrationTest extends AbstractIntegrationTest {
|
public abstract class AbstractRestIntegrationTest extends AbstractIntegrationTest {
|
||||||
|
|
||||||
protected MockMvc mvc;
|
protected MockMvc mvc;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private CharacterEncodingFilter characterEncodingFilter;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
protected WebApplicationContext webApplicationContext;
|
protected WebApplicationContext webApplicationContext;
|
||||||
|
@Autowired
|
||||||
|
private CharacterEncodingFilter characterEncodingFilter;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void before() throws Exception {
|
public void before() throws Exception {
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ import jakarta.servlet.ServletException;
|
|||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import io.qameta.allure.Feature;
|
||||||
|
import io.qameta.allure.Story;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
@@ -29,9 +31,6 @@ import org.mockito.Mock;
|
|||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
import org.mockito.junit.jupiter.MockitoExtension;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
|
|
||||||
import io.qameta.allure.Feature;
|
|
||||||
import io.qameta.allure.Story;
|
|
||||||
|
|
||||||
@Feature("Unit Tests - Security")
|
@Feature("Unit Tests - Security")
|
||||||
@Story("Exclude path aware shallow ETag filter")
|
@Story("Exclude path aware shallow ETag filter")
|
||||||
@ExtendWith(MockitoExtension.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
|
|||||||
@@ -14,11 +14,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import io.qameta.allure.Description;
|
import io.qameta.allure.Description;
|
||||||
import io.qameta.allure.Feature;
|
import io.qameta.allure.Feature;
|
||||||
import io.qameta.allure.Story;
|
import io.qameta.allure.Story;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@Feature("Unit Tests - Management API")
|
@Feature("Unit Tests - Management API")
|
||||||
@Story("Error Handling")
|
@Story("Error Handling")
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ import jakarta.servlet.ServletOutputStream;
|
|||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import io.qameta.allure.Feature;
|
||||||
|
import io.qameta.allure.Story;
|
||||||
import org.eclipse.hawkbit.artifact.repository.model.DbArtifact;
|
import org.eclipse.hawkbit.artifact.repository.model.DbArtifact;
|
||||||
import org.eclipse.hawkbit.artifact.repository.model.DbArtifactHash;
|
import org.eclipse.hawkbit.artifact.repository.model.DbArtifactHash;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
@@ -34,12 +36,10 @@ import org.springframework.http.HttpHeaders;
|
|||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
|
|
||||||
import io.qameta.allure.Feature;
|
|
||||||
import io.qameta.allure.Story;
|
|
||||||
|
|
||||||
@Feature("Component Tests - Management API")
|
@Feature("Component Tests - Management API")
|
||||||
@Story("File streaming")
|
@Story("File streaming")
|
||||||
class FileStreamingUtilTest {
|
class FileStreamingUtilTest {
|
||||||
|
|
||||||
private final static String CONTENT = "This is some very long string which is intended to test";
|
private final static String CONTENT = "This is some very long string which is intended to test";
|
||||||
private final static byte[] CONTENT_BYTES = CONTENT.getBytes(StandardCharsets.UTF_8);
|
private final static byte[] CONTENT_BYTES = CONTENT.getBytes(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.eclipse.hawkbit.rest.util;
|
package org.eclipse.hawkbit.rest.util;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -30,8 +32,6 @@ import org.json.JSONException;
|
|||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builder class for building certain json strings.
|
* Builder class for building certain json strings.
|
||||||
*/
|
*/
|
||||||
@@ -73,12 +73,6 @@ public abstract class JsonBuilder {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void createTagLine(final StringBuilder builder, final Tag tag) throws JSONException {
|
|
||||||
builder.append(new JSONObject().put("name", tag.getName()).put("description", tag.getDescription())
|
|
||||||
.put("colour", tag.getColour()).put("createdAt", "0").put("updatedAt", "0")
|
|
||||||
.put("createdBy", "fghdfkjghdfkjh").put("updatedBy", "fghdfkjghdfkjh").toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String tag(final Tag tag) throws JSONException {
|
public static String tag(final Tag tag) throws JSONException {
|
||||||
final StringBuilder builder = new StringBuilder();
|
final StringBuilder builder = new StringBuilder();
|
||||||
|
|
||||||
@@ -189,12 +183,9 @@ public abstract class JsonBuilder {
|
|||||||
/**
|
/**
|
||||||
* Build an invalid request body with missing result for feedback message.
|
* Build an invalid request body with missing result for feedback message.
|
||||||
*
|
*
|
||||||
* @param id
|
* @param id id of the action
|
||||||
* id of the action
|
* @param execution the execution
|
||||||
* @param execution
|
* @param message the message
|
||||||
* the execution
|
|
||||||
* @param message
|
|
||||||
* the message
|
|
||||||
* @return a invalid request body
|
* @return a invalid request body
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
@@ -210,12 +201,9 @@ public abstract class JsonBuilder {
|
|||||||
* Build an invalid request body with missing finished result for feedback
|
* Build an invalid request body with missing finished result for feedback
|
||||||
* message.
|
* message.
|
||||||
*
|
*
|
||||||
* @param id
|
* @param id id of the action
|
||||||
* id of the action
|
* @param execution the execution
|
||||||
* @param execution
|
* @param message the message
|
||||||
* the execution
|
|
||||||
* @param message
|
|
||||||
* the message
|
|
||||||
* @return a invalid request body
|
* @return a invalid request body
|
||||||
* @throws JSONException
|
* @throws JSONException
|
||||||
*/
|
*/
|
||||||
@@ -486,7 +474,7 @@ public abstract class JsonBuilder {
|
|||||||
final long distributionSetId, final String targetFilterQuery, final RolloutGroupConditions conditions,
|
final long distributionSetId, final String targetFilterQuery, final RolloutGroupConditions conditions,
|
||||||
final String type) {
|
final String type) {
|
||||||
return rollout(name, description, groupSize, distributionSetId, targetFilterQuery, conditions, null, type,
|
return rollout(name, description, groupSize, distributionSetId, targetFilterQuery, conditions, null, type,
|
||||||
null, null, null, null);
|
null, null, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String rolloutWithGroups(final String name, final String description, final Integer groupSize,
|
public static String rolloutWithGroups(final String name, final String description, final Integer groupSize,
|
||||||
@@ -511,13 +499,13 @@ public abstract class JsonBuilder {
|
|||||||
final List<String> groupJsonList, final String type, final Integer weight, final Long startAt, final Long forceTime,
|
final List<String> groupJsonList, final String type, final Integer weight, final Long startAt, final Long forceTime,
|
||||||
final Boolean confirmationRequired) {
|
final Boolean confirmationRequired) {
|
||||||
return rollout(name, description, groupSize, distributionSetId, targetFilterQuery, conditions, groupJsonList, type,
|
return rollout(name, description, groupSize, distributionSetId, targetFilterQuery, conditions, groupJsonList, type,
|
||||||
weight, startAt, forceTime, confirmationRequired, false, null, 0);
|
weight, startAt, forceTime, confirmationRequired, false, null, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String rollout(final String name, final String description, final Integer groupSize,
|
public static String rollout(final String name, final String description, final Integer groupSize,
|
||||||
final long distributionSetId, final String targetFilterQuery, final RolloutGroupConditions conditions,
|
final long distributionSetId, final String targetFilterQuery, final RolloutGroupConditions conditions,
|
||||||
final List<String> groupJsonList, final String type, final Integer weight, final Long startAt, final Long forceTime,
|
final List<String> groupJsonList, final String type, final Integer weight, final Long startAt, final Long forceTime,
|
||||||
final Boolean confirmationRequired, final boolean isDynamic, final String dynamicGroupSuffix, final int dynamicGroupTargetsCount) {
|
final Boolean confirmationRequired, final boolean isDynamic, final String dynamicGroupSuffix, final int dynamicGroupTargetsCount) {
|
||||||
final JSONObject json = new JSONObject();
|
final JSONObject json = new JSONObject();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -576,7 +564,8 @@ public abstract class JsonBuilder {
|
|||||||
|
|
||||||
final JSONObject dynamicGroupTemplate = new JSONObject();
|
final JSONObject dynamicGroupTemplate = new JSONObject();
|
||||||
json.put("dynamicGroupTemplate", dynamicGroupTemplate);
|
json.put("dynamicGroupTemplate", dynamicGroupTemplate);
|
||||||
dynamicGroupTemplate.put("nameSuffix", (dynamicGroupSuffix == null || dynamicGroupSuffix.isEmpty()) ? "-dynamic" : dynamicGroupSuffix);
|
dynamicGroupTemplate.put("nameSuffix",
|
||||||
|
(dynamicGroupSuffix == null || dynamicGroupSuffix.isEmpty()) ? "-dynamic" : dynamicGroupSuffix);
|
||||||
dynamicGroupTemplate.put("targetCount", dynamicGroupTargetsCount < 0 ? 1 : dynamicGroupTargetsCount);
|
dynamicGroupTemplate.put("targetCount", dynamicGroupTargetsCount < 0 ? 1 : dynamicGroupTargetsCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -602,14 +591,6 @@ public abstract class JsonBuilder {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static RolloutGroupConditions getConditions(final RolloutGroup rolloutGroup) {
|
|
||||||
return new RolloutGroupConditionBuilder()
|
|
||||||
.errorCondition(rolloutGroup.getErrorCondition(), rolloutGroup.getErrorConditionExp())
|
|
||||||
.errorAction(rolloutGroup.getErrorAction(), rolloutGroup.getErrorActionExp())
|
|
||||||
.successAction(rolloutGroup.getSuccessAction(), rolloutGroup.getSuccessActionExp())
|
|
||||||
.successCondition(rolloutGroup.getSuccessCondition(), rolloutGroup.getSuccessConditionExp()).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String rolloutGroup(final String name, final String description, final String targetFilterQuery,
|
public static String rolloutGroup(final String name, final String description, final String targetFilterQuery,
|
||||||
final Float targetPercentage, final Boolean confirmationRequired,
|
final Float targetPercentage, final Boolean confirmationRequired,
|
||||||
final RolloutGroupConditions rolloutGroupConditions) {
|
final RolloutGroupConditions rolloutGroupConditions) {
|
||||||
@@ -705,4 +686,18 @@ public abstract class JsonBuilder {
|
|||||||
}
|
}
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void createTagLine(final StringBuilder builder, final Tag tag) throws JSONException {
|
||||||
|
builder.append(new JSONObject().put("name", tag.getName()).put("description", tag.getDescription())
|
||||||
|
.put("colour", tag.getColour()).put("createdAt", "0").put("updatedAt", "0")
|
||||||
|
.put("createdBy", "fghdfkjghdfkjh").put("updatedBy", "fghdfkjghdfkjh").toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static RolloutGroupConditions getConditions(final RolloutGroup rolloutGroup) {
|
||||||
|
return new RolloutGroupConditionBuilder()
|
||||||
|
.errorCondition(rolloutGroup.getErrorCondition(), rolloutGroup.getErrorConditionExp())
|
||||||
|
.errorAction(rolloutGroup.getErrorAction(), rolloutGroup.getErrorActionExp())
|
||||||
|
.successAction(rolloutGroup.getSuccessAction(), rolloutGroup.getSuccessActionExp())
|
||||||
|
.successCondition(rolloutGroup.getSuccessCondition(), rolloutGroup.getSuccessConditionExp()).build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,9 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import io.qameta.allure.Description;
|
||||||
|
import io.qameta.allure.Feature;
|
||||||
|
import io.qameta.allure.Story;
|
||||||
import org.eclipse.hawkbit.repository.TargetFields;
|
import org.eclipse.hawkbit.repository.TargetFields;
|
||||||
import org.eclipse.hawkbit.rest.exception.SortParameterSyntaxErrorException;
|
import org.eclipse.hawkbit.rest.exception.SortParameterSyntaxErrorException;
|
||||||
import org.eclipse.hawkbit.rest.exception.SortParameterUnsupportedDirectionException;
|
import org.eclipse.hawkbit.rest.exception.SortParameterUnsupportedDirectionException;
|
||||||
@@ -21,16 +24,13 @@ import org.eclipse.hawkbit.rest.exception.SortParameterUnsupportedFieldException
|
|||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.data.domain.Sort.Order;
|
import org.springframework.data.domain.Sort.Order;
|
||||||
|
|
||||||
import io.qameta.allure.Description;
|
|
||||||
import io.qameta.allure.Feature;
|
|
||||||
import io.qameta.allure.Story;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Feature("Component Tests - Management API")
|
@Feature("Component Tests - Management API")
|
||||||
@Story("Sorting parameter")
|
@Story("Sorting parameter")
|
||||||
public class SortUtilityTest {
|
public class SortUtilityTest {
|
||||||
|
|
||||||
private static final String SORT_PARAM_1 = "NAME:ASC";
|
private static final String SORT_PARAM_1 = "NAME:ASC";
|
||||||
private static final String SORT_PARAM_2 = "NAME:ASC, DESCRIPTION:DESC";
|
private static final String SORT_PARAM_2 = "NAME:ASC, DESCRIPTION:DESC";
|
||||||
private static final String SYNTAX_FAILURE_SORT_PARAM = "NAME:ASC DESCRIPTION:DESC";
|
private static final String SYNTAX_FAILURE_SORT_PARAM = "NAME:ASC DESCRIPTION:DESC";
|
||||||
|
|||||||
@@ -10,13 +10,11 @@
|
|||||||
package org.eclipse.hawkbit.rest.util;
|
package org.eclipse.hawkbit.rest.util;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param <T>
|
* @param <T>
|
||||||
*/
|
*/
|
||||||
public interface SuccessCondition<T> {
|
public interface SuccessCondition<T> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param result
|
* @param result
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user