From 64c7feded3e4a05daec8f209c00dd0809f0f4dae Mon Sep 17 00:00:00 2001 From: Avgustin Marinov Date: Wed, 6 Nov 2024 14:09:20 +0200 Subject: [PATCH] Refactor rest core (#1955) * remove unused methods * move mgmt resource dedicated classes to mgmt-resource * clean up code Signed-off-by: Avgustin Marinov --- .../rest/resource/DataConversionHelper.java | 2 +- .../rest/resource/DdiDeploymentBaseTest.java | 4 +- .../hawkbit/mgmt/rest/api/SortDirection.java | 25 ++ .../mgmt/rest/resource/MgmtActionMapper.java | 2 +- .../rest/resource/MgmtActionResource.java | 1 + .../resource/MgmtDistributionSetMapper.java | 2 +- .../resource/MgmtDistributionSetResource.java | 1 + .../MgmtDistributionSetTagResource.java | 1 + .../MgmtDistributionSetTypeMapper.java | 2 +- .../MgmtDistributionSetTypeResource.java | 1 + .../rest/resource/MgmtRolloutResource.java | 1 + .../resource/MgmtSoftwareModuleMapper.java | 2 +- .../resource/MgmtSoftwareModuleResource.java | 3 +- .../MgmtSoftwareModuleTypeMapper.java | 2 +- .../MgmtSoftwareModuleTypeResource.java | 1 + .../mgmt/rest/resource/MgmtTagMapper.java | 2 +- .../MgmtTargetFilterQueryResource.java | 1 + .../mgmt/rest/resource/MgmtTargetMapper.java | 4 +- .../rest/resource/MgmtTargetResource.java | 1 + .../rest/resource/MgmtTargetTagResource.java | 1 + .../rest/resource/MgmtTargetTypeMapper.java | 2 +- .../rest/resource/MgmtTargetTypeResource.java | 1 + .../SortParameterSyntaxErrorException.java | 13 +- ...arameterUnsupportedDirectionException.java | 28 +- ...ortParameterUnsupportedFieldException.java | 29 +- .../resource/{ => util}/PagingUtility.java | 35 +- .../mgmt/rest/resource/util/SortUtility.java | 90 ++++++ .../MgmtDistributionSetResourceTest.java | 1 + .../MgmtDistributionSetTagResourceTest.java | 1 + .../MgmtSoftwareModuleResourceTest.java | 1 + .../MgmtTargetFilterQueryResourceTest.java | 1 + .../rest/resource/MgmtTargetResourceTest.java | 1 + .../resource/MgmtTargetTagResourceTest.java | 1 + .../resource/{ => util}/ResourceUtility.java | 8 +- .../rest/resource}/util/SortUtilityTest.java | 11 +- .../hawkbit/rest/RestConfiguration.java | 299 +++++++++++++++++- .../hawkbit/rest/data/SortDirection.java | 41 --- .../MultiPartFileUploadException.java | 11 +- .../exception/ResponseExceptionHandler.java | 262 --------------- .../ExcludePathAwareShallowETagFilter.java | 60 ---- .../{data => json/model}/ResponseList.java | 2 +- .../util/FileStreamingFailedException.java | 22 +- .../util/FileStreamingProgressListener.java | 26 -- .../hawkbit/rest/util/FileStreamingUtil.java | 15 + .../eclipse/hawkbit/rest/util/HttpUtil.java | 11 +- .../hawkbit/rest/util/SortUtility.java | 114 ------- .../rest/AbstractRestIntegrationTest.java | 3 +- ...ExcludePathAwareShallowETagFilterTest.java | 6 +- 48 files changed, 516 insertions(+), 638 deletions(-) create mode 100644 hawkbit-rest/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/SortDirection.java rename hawkbit-rest/{hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest => hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource}/exception/SortParameterSyntaxErrorException.java (78%) rename hawkbit-rest/{hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest => hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource}/exception/SortParameterUnsupportedDirectionException.java (60%) rename hawkbit-rest/{hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest => hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource}/exception/SortParameterUnsupportedFieldException.java (57%) rename hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/{ => util}/PagingUtility.java (81%) create mode 100644 hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/util/SortUtility.java rename hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/{ => util}/ResourceUtility.java (80%) rename hawkbit-rest/{hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest => hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource}/util/SortUtilityTest.java (90%) delete mode 100644 hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/data/SortDirection.java delete mode 100644 hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/exception/ResponseExceptionHandler.java delete mode 100644 hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/filter/ExcludePathAwareShallowETagFilter.java rename hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/{data => json/model}/ResponseList.java (98%) delete mode 100644 hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/util/FileStreamingProgressListener.java delete mode 100644 hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/util/SortUtility.java rename hawkbit-rest/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/{filter => }/ExcludePathAwareShallowETagFilterTest.java (91%) diff --git a/hawkbit-rest/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DataConversionHelper.java b/hawkbit-rest/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DataConversionHelper.java index 7e082eaef6..d17f7a97d3 100644 --- a/hawkbit-rest/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DataConversionHelper.java +++ b/hawkbit-rest/hawkbit-ddi-resource/src/main/java/org/eclipse/hawkbit/ddi/rest/resource/DataConversionHelper.java @@ -34,7 +34,7 @@ import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata; import org.eclipse.hawkbit.repository.model.Target; -import org.eclipse.hawkbit.rest.data.ResponseList; +import org.eclipse.hawkbit.rest.json.model.ResponseList; import org.eclipse.hawkbit.tenancy.TenantAware; import org.springframework.hateoas.Link; import org.springframework.hateoas.server.mvc.WebMvcLinkBuilder; diff --git a/hawkbit-rest/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiDeploymentBaseTest.java b/hawkbit-rest/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiDeploymentBaseTest.java index f35040ecbc..d8f13cc03d 100644 --- a/hawkbit-rest/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiDeploymentBaseTest.java +++ b/hawkbit-rest/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiDeploymentBaseTest.java @@ -711,7 +711,7 @@ public void missingResultAttributeInFeedbackReturnsBadRequest() throws Exception Collections.singletonList("test")); postDeploymentFeedback("1080", action.getId(), missingResultInFeedback, status().isBadRequest()) .andExpect(jsonPath("$.*", hasSize(3))) - .andExpect(jsonPath("$.exceptionClass", equalTo(MessageNotReadableException.class.getCanonicalName()))); + .andExpect(jsonPath("$.exceptionClass", equalTo(MessageNotReadableException.class.getName()))); } @Test @@ -736,7 +736,7 @@ public void missingFinishedAttributeInFeedbackReturnsBadRequest() throws Excepti postDeploymentFeedback("1080", action.getId(), missingFinishedResultInFeedback, status().isBadRequest()) .andExpect(jsonPath("$.*", hasSize(3))) - .andExpect(jsonPath("$.exceptionClass", equalTo(MessageNotReadableException.class.getCanonicalName()))); + .andExpect(jsonPath("$.exceptionClass", equalTo(MessageNotReadableException.class.getName()))); } public long countActionStatusAll() { diff --git a/hawkbit-rest/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/SortDirection.java b/hawkbit-rest/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/SortDirection.java new file mode 100644 index 0000000000..2aa609ab90 --- /dev/null +++ b/hawkbit-rest/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/SortDirection.java @@ -0,0 +1,25 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.hawkbit.mgmt.rest.api; + +/** + * A definition of possible sorting direction. + */ +public enum SortDirection { + + /** + * Ascending. + */ + ASC, + /** + * Descending. + */ + DESC; +} diff --git a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtActionMapper.java b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtActionMapper.java index e22cfd9454..f0754d0c7b 100644 --- a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtActionMapper.java +++ b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtActionMapper.java @@ -19,7 +19,7 @@ import org.eclipse.hawkbit.mgmt.json.model.action.MgmtAction; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRepresentationMode; import org.eclipse.hawkbit.repository.model.Action; -import org.eclipse.hawkbit.rest.data.ResponseList; +import org.eclipse.hawkbit.rest.json.model.ResponseList; /** * A mapper which maps repository model to RESTful model representation and diff --git a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtActionResource.java b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtActionResource.java index c95ce0f45c..73e3df9c0f 100644 --- a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtActionResource.java +++ b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtActionResource.java @@ -14,6 +14,7 @@ import org.eclipse.hawkbit.mgmt.json.model.action.MgmtAction; import org.eclipse.hawkbit.mgmt.rest.api.MgmtActionRestApi; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRepresentationMode; +import org.eclipse.hawkbit.mgmt.rest.resource.util.PagingUtility; import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; diff --git a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetMapper.java b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetMapper.java index f55985693e..f358b83837 100644 --- a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetMapper.java +++ b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetMapper.java @@ -34,7 +34,7 @@ import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult; import org.eclipse.hawkbit.repository.model.DistributionSetMetadata; import org.eclipse.hawkbit.repository.model.MetaData; -import org.eclipse.hawkbit.rest.data.ResponseList; +import org.eclipse.hawkbit.rest.json.model.ResponseList; /** * A mapper which maps repository model to RESTful model representation and diff --git a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java index 3c6e2b51de..a1e9c65486 100644 --- a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java +++ b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java @@ -38,6 +38,7 @@ import org.eclipse.hawkbit.mgmt.json.model.targetfilter.MgmtTargetFilterQuery; import org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetRestApi; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; +import org.eclipse.hawkbit.mgmt.rest.resource.util.PagingUtility; import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.DistributionSetInvalidationManagement; import org.eclipse.hawkbit.repository.DistributionSetManagement; diff --git a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResource.java b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResource.java index 8f94d9ecd2..13cd6c3808 100644 --- a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResource.java +++ b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResource.java @@ -21,6 +21,7 @@ import org.eclipse.hawkbit.mgmt.json.model.tag.MgmtTagRequestBodyPut; import org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetTagRestApi; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; +import org.eclipse.hawkbit.mgmt.rest.resource.util.PagingUtility; import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.DistributionSetTagManagement; import org.eclipse.hawkbit.repository.EntityFactory; diff --git a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeMapper.java b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeMapper.java index 0ffd305fa1..1a79fb217f 100644 --- a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeMapper.java +++ b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeMapper.java @@ -26,7 +26,7 @@ import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.builder.DistributionSetTypeCreate; import org.eclipse.hawkbit.repository.model.DistributionSetType; -import org.eclipse.hawkbit.rest.data.ResponseList; +import org.eclipse.hawkbit.rest.json.model.ResponseList; /** * A mapper which maps repository model to RESTful model representation and diff --git a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResource.java b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResource.java index 65ee1b96af..d5b89fa8cf 100644 --- a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResource.java +++ b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResource.java @@ -20,6 +20,7 @@ import org.eclipse.hawkbit.mgmt.json.model.softwaremoduletype.MgmtSoftwareModuleType; import org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetTypeRestApi; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; +import org.eclipse.hawkbit.mgmt.rest.resource.util.PagingUtility; import org.eclipse.hawkbit.repository.DistributionSetTypeManagement; import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; diff --git a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResource.java b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResource.java index 8a82dff653..8409756042 100644 --- a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResource.java +++ b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResource.java @@ -27,6 +27,7 @@ import org.eclipse.hawkbit.mgmt.rest.api.MgmtRepresentationMode; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRolloutRestApi; +import org.eclipse.hawkbit.mgmt.rest.resource.util.PagingUtility; import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; diff --git a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleMapper.java b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleMapper.java index 5dc9584e2d..e86acd5f44 100644 --- a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleMapper.java +++ b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleMapper.java @@ -38,7 +38,7 @@ import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata; -import org.eclipse.hawkbit.rest.data.ResponseList; +import org.eclipse.hawkbit.rest.json.model.ResponseList; import org.springframework.hateoas.Link; /** diff --git a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResource.java b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResource.java index 74da7ae278..bd9e572552 100644 --- a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResource.java +++ b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResource.java @@ -30,6 +30,7 @@ import org.eclipse.hawkbit.mgmt.rest.api.MgmtRepresentationMode; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.mgmt.rest.api.MgmtSoftwareModuleRestApi; +import org.eclipse.hawkbit.mgmt.rest.resource.util.PagingUtility; import org.eclipse.hawkbit.repository.ArtifactManagement; import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; @@ -42,7 +43,7 @@ import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; -import org.eclipse.hawkbit.rest.data.ResponseList; +import org.eclipse.hawkbit.rest.json.model.ResponseList; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Slice; diff --git a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeMapper.java b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeMapper.java index 3e601462dd..e39d1ff1fa 100644 --- a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeMapper.java +++ b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeMapper.java @@ -23,7 +23,7 @@ import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.builder.SoftwareModuleTypeCreate; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; -import org.eclipse.hawkbit.rest.data.ResponseList; +import org.eclipse.hawkbit.rest.json.model.ResponseList; /** * A mapper which maps repository model to RESTful model representation and diff --git a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResource.java b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResource.java index 14efc83c25..9af12f9ff2 100644 --- a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResource.java +++ b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResource.java @@ -17,6 +17,7 @@ import org.eclipse.hawkbit.mgmt.json.model.softwaremoduletype.MgmtSoftwareModuleTypeRequestBodyPut; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.mgmt.rest.api.MgmtSoftwareModuleTypeRestApi; +import org.eclipse.hawkbit.mgmt.rest.resource.util.PagingUtility; import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.SoftwareModuleTypeManagement; diff --git a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTagMapper.java b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTagMapper.java index 3df1e95680..da4a94f3fe 100644 --- a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTagMapper.java +++ b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTagMapper.java @@ -29,7 +29,7 @@ import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.Tag; import org.eclipse.hawkbit.repository.model.TargetTag; -import org.eclipse.hawkbit.rest.data.ResponseList; +import org.eclipse.hawkbit.rest.json.model.ResponseList; /** * A mapper which maps repository model to RESTful model representation and back. diff --git a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetFilterQueryResource.java b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetFilterQueryResource.java index 8902b92028..23672d4257 100644 --- a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetFilterQueryResource.java +++ b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetFilterQueryResource.java @@ -20,6 +20,7 @@ import org.eclipse.hawkbit.mgmt.rest.api.MgmtRepresentationMode; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetFilterQueryRestApi; +import org.eclipse.hawkbit.mgmt.rest.resource.util.PagingUtility; import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.TargetFilterQueryManagement; diff --git a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetMapper.java b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetMapper.java index 140eea89da..9a140e2c13 100644 --- a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetMapper.java +++ b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetMapper.java @@ -34,6 +34,7 @@ import org.eclipse.hawkbit.mgmt.rest.api.MgmtRolloutRestApi; import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetRestApi; import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetTypeRestApi; +import org.eclipse.hawkbit.mgmt.rest.api.SortDirection; import org.eclipse.hawkbit.repository.ActionFields; import org.eclipse.hawkbit.repository.ActionStatusFields; import org.eclipse.hawkbit.repository.DeploymentManagement; @@ -49,8 +50,7 @@ import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetMetadata; -import org.eclipse.hawkbit.rest.data.ResponseList; -import org.eclipse.hawkbit.rest.data.SortDirection; +import org.eclipse.hawkbit.rest.json.model.ResponseList; import org.eclipse.hawkbit.util.IpUtil; import org.eclipse.hawkbit.utils.TenantConfigHelper; import org.springframework.data.domain.PageRequest; diff --git a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResource.java b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResource.java index 60e7d4b35d..39ad508a66 100644 --- a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResource.java +++ b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResource.java @@ -41,6 +41,7 @@ import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTargetRequestBody; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetRestApi; +import org.eclipse.hawkbit.mgmt.rest.resource.util.PagingUtility; import org.eclipse.hawkbit.repository.ConfirmationManagement; import org.eclipse.hawkbit.repository.DeploymentManagement; import org.eclipse.hawkbit.repository.EntityFactory; diff --git a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTagResource.java b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTagResource.java index 8acda69384..ffe641cf9e 100644 --- a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTagResource.java +++ b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTagResource.java @@ -23,6 +23,7 @@ import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTarget; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetTagRestApi; +import org.eclipse.hawkbit.mgmt.rest.resource.util.PagingUtility; import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.TargetManagement; diff --git a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTypeMapper.java b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTypeMapper.java index 797264f0ba..5bed68e3af 100644 --- a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTypeMapper.java +++ b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTypeMapper.java @@ -26,7 +26,7 @@ import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.builder.TargetTypeCreate; import org.eclipse.hawkbit.repository.model.TargetType; -import org.eclipse.hawkbit.rest.data.ResponseList; +import org.eclipse.hawkbit.rest.json.model.ResponseList; /** * A mapper which maps repository model to RESTful model representation and back. diff --git a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTypeResource.java b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTypeResource.java index c9374d0515..5de5ff44d2 100644 --- a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTypeResource.java +++ b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTypeResource.java @@ -21,6 +21,7 @@ import org.eclipse.hawkbit.mgmt.json.model.targettype.MgmtTargetTypeRequestBodyPut; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetTypeRestApi; +import org.eclipse.hawkbit.mgmt.rest.resource.util.PagingUtility; import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.TargetTypeManagement; diff --git a/hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/exception/SortParameterSyntaxErrorException.java b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/exception/SortParameterSyntaxErrorException.java similarity index 78% rename from hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/exception/SortParameterSyntaxErrorException.java rename to hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/exception/SortParameterSyntaxErrorException.java index d63c17a1a3..2f058c6514 100644 --- a/hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/exception/SortParameterSyntaxErrorException.java +++ b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/exception/SortParameterSyntaxErrorException.java @@ -7,7 +7,9 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.eclipse.hawkbit.rest.exception; +package org.eclipse.hawkbit.mgmt.rest.resource.exception; + +import java.io.Serial; import org.eclipse.hawkbit.exception.AbstractServerRtException; import org.eclipse.hawkbit.exception.SpServerError; @@ -17,16 +19,13 @@ */ public class SortParameterSyntaxErrorException extends AbstractServerRtException { - /** - * - */ + @Serial private static final long serialVersionUID = 1L; /** - * Creates a new SortParameterSyntaxErrorException with - * {@link SpServerError#SP_REST_SORT_PARAM_SYNTAX} error. + * Creates a new SortParameterSyntaxErrorException with {@link SpServerError#SP_REST_SORT_PARAM_SYNTAX} error. */ public SortParameterSyntaxErrorException() { super(SpServerError.SP_REST_SORT_PARAM_SYNTAX); } -} +} \ No newline at end of file diff --git a/hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/exception/SortParameterUnsupportedDirectionException.java b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/exception/SortParameterUnsupportedDirectionException.java similarity index 60% rename from hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/exception/SortParameterUnsupportedDirectionException.java rename to hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/exception/SortParameterUnsupportedDirectionException.java index 183264602a..8626c35a86 100644 --- a/hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/exception/SortParameterUnsupportedDirectionException.java +++ b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/exception/SortParameterUnsupportedDirectionException.java @@ -7,38 +7,28 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.eclipse.hawkbit.rest.exception; +package org.eclipse.hawkbit.mgmt.rest.resource.exception; + +import java.io.Serial; import org.eclipse.hawkbit.exception.AbstractServerRtException; import org.eclipse.hawkbit.exception.SpServerError; /** - * Exception used by the REST API in case of invalid sort parameter direction - * name. + * Exception used by the REST API in case of invalid sort parameter direction name. */ public class SortParameterUnsupportedDirectionException extends AbstractServerRtException { - /** - * - */ + @Serial private static final long serialVersionUID = 1L; /** - * Creates a new SortParameterSyntaxErrorException. - */ - public SortParameterUnsupportedDirectionException() { - super(SpServerError.SP_REST_SORT_PARAM_INVALID_DIRECTION); - } - - /** - * Creates a new SortParameterSyntaxErrorException with - * {@link SpServerError#SP_REST_SORT_PARAM_INVALID_DIRECTION} error. + * Creates a new SortParameterSyntaxErrorException with {@link SpServerError#SP_REST_SORT_PARAM_INVALID_DIRECTION} error. * - * @param cause the cause (which is saved for later retrieval by the - * getCause() method). (A null value is permitted, and indicates - * that the cause is nonexistent or unknown.) + * @param cause the cause (which is saved for later retrieval by the getCause() method). (A null value is permitted, and indicates + * that the cause is nonexistent or unknown.) */ public SortParameterUnsupportedDirectionException(final Throwable cause) { super(SpServerError.SP_REST_SORT_PARAM_INVALID_DIRECTION, cause); } -} +} \ No newline at end of file diff --git a/hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/exception/SortParameterUnsupportedFieldException.java b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/exception/SortParameterUnsupportedFieldException.java similarity index 57% rename from hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/exception/SortParameterUnsupportedFieldException.java rename to hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/exception/SortParameterUnsupportedFieldException.java index 4d7f595eb9..d62ffb9f5f 100644 --- a/hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/exception/SortParameterUnsupportedFieldException.java +++ b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/exception/SortParameterUnsupportedFieldException.java @@ -7,39 +7,28 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.eclipse.hawkbit.rest.exception; +package org.eclipse.hawkbit.mgmt.rest.resource.exception; + +import java.io.Serial; import org.eclipse.hawkbit.exception.AbstractServerRtException; import org.eclipse.hawkbit.exception.SpServerError; /** - * Exception used by the REST API in case of invalid field name in the sort - * parameter. + * Exception used by the REST API in case of invalid field name in the sort parameter. */ public class SortParameterUnsupportedFieldException extends AbstractServerRtException { - /** - * - */ + @Serial private static final long serialVersionUID = 1L; /** - * Creates a new SortParameterSyntaxErrorException with - * {@link SpServerError#SP_REST_SORT_PARAM_INVALID_FIELD} error. - */ - public SortParameterUnsupportedFieldException() { - super(SpServerError.SP_REST_SORT_PARAM_INVALID_FIELD); - } - - /** - * Creates a new SortParameterSyntaxErrorException with - * {@link SpServerError#SP_REST_SORT_PARAM_INVALID_FIELD} error. + * Creates a new SortParameterSyntaxErrorException with {@link SpServerError#SP_REST_SORT_PARAM_INVALID_FIELD} error. * - * @param cause the cause (which is saved for later retrieval by the - * getCause() method). (A null value is permitted, and indicates - * that the cause is nonexistent or unknown.) + * @param cause the cause (which is saved for later retrieval by the getCause() method). (A null value is permitted, and indicates + * that the cause is nonexistent or unknown.) */ public SortParameterUnsupportedFieldException(final Throwable cause) { super(SpServerError.SP_REST_SORT_PARAM_INVALID_FIELD, cause); } -} +} \ No newline at end of file diff --git a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/PagingUtility.java b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/util/PagingUtility.java similarity index 81% rename from hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/PagingUtility.java rename to hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/util/PagingUtility.java index a9f4fd0680..702c33d6fd 100644 --- a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/PagingUtility.java +++ b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/util/PagingUtility.java @@ -7,7 +7,7 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.eclipse.hawkbit.mgmt.rest.resource; +package org.eclipse.hawkbit.mgmt.rest.resource.util; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.repository.ActionFields; @@ -24,7 +24,6 @@ import org.eclipse.hawkbit.repository.TargetFields; import org.eclipse.hawkbit.repository.TargetFilterQueryFields; import org.eclipse.hawkbit.repository.TargetTypeFields; -import org.eclipse.hawkbit.rest.util.SortUtility; import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort.Direction; @@ -39,14 +38,14 @@ public final class PagingUtility { private PagingUtility() { } - static int sanitizeOffsetParam(final int offset) { + public static int sanitizeOffsetParam(final int offset) { if (offset < 0) { return MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET_VALUE; } return offset; } - static int sanitizePageLimitParam(final int pageLimit) { + public static int sanitizePageLimitParam(final int pageLimit) { if (pageLimit < 1) { return MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT_VALUE; } else if (pageLimit > MgmtRestConstants.REQUEST_PARAMETER_PAGING_MAX_LIMIT) { @@ -55,7 +54,7 @@ static int sanitizePageLimitParam(final int pageLimit) { return pageLimit; } - static Sort sanitizeTargetSortParam(final String sortParam) { + public static Sort sanitizeTargetSortParam(final String sortParam) { if (sortParam == null) { // default return Sort.by(Direction.ASC, TargetFields.CONTROLLERID.getJpaEntityFieldName()); @@ -63,7 +62,7 @@ static Sort sanitizeTargetSortParam(final String sortParam) { return Sort.by(SortUtility.parse(TargetFields.class, sortParam)); } - static Sort sanitizeTargetTypeSortParam(final String sortParam) { + public static Sort sanitizeTargetTypeSortParam(final String sortParam) { if (sortParam == null) { // default return Sort.by(Direction.ASC, TargetTypeFields.ID.getJpaEntityFieldName()); @@ -71,7 +70,7 @@ static Sort sanitizeTargetTypeSortParam(final String sortParam) { return Sort.by(SortUtility.parse(TargetTypeFields.class, sortParam)); } - static Sort sanitizeTagSortParam(final String sortParam) { + public static Sort sanitizeTagSortParam(final String sortParam) { if (sortParam == null) { // default return Sort.by(Direction.ASC, TagFields.ID.getJpaEntityFieldName()); @@ -79,7 +78,7 @@ static Sort sanitizeTagSortParam(final String sortParam) { return Sort.by(SortUtility.parse(TagFields.class, sortParam)); } - static Sort sanitizeTargetFilterQuerySortParam(final String sortParam) { + public static Sort sanitizeTargetFilterQuerySortParam(final String sortParam) { if (sortParam == null) { // default return Sort.by(Direction.ASC, TargetFilterQueryFields.ID.getJpaEntityFieldName()); @@ -87,7 +86,7 @@ static Sort sanitizeTargetFilterQuerySortParam(final String sortParam) { return Sort.by(SortUtility.parse(TargetFilterQueryFields.class, sortParam)); } - static Sort sanitizeSoftwareModuleSortParam(final String sortParam) { + public static Sort sanitizeSoftwareModuleSortParam(final String sortParam) { if (sortParam == null) { // default return Sort.by(Direction.ASC, SoftwareModuleFields.ID.getJpaEntityFieldName()); @@ -95,7 +94,7 @@ static Sort sanitizeSoftwareModuleSortParam(final String sortParam) { return Sort.by(SortUtility.parse(SoftwareModuleFields.class, sortParam)); } - static Sort sanitizeSoftwareModuleTypeSortParam(final String sortParam) { + public static Sort sanitizeSoftwareModuleTypeSortParam(final String sortParam) { if (sortParam == null) { // default return Sort.by(Direction.ASC, SoftwareModuleTypeFields.ID.getJpaEntityFieldName()); @@ -103,7 +102,7 @@ static Sort sanitizeSoftwareModuleTypeSortParam(final String sortParam) { return Sort.by(SortUtility.parse(SoftwareModuleTypeFields.class, sortParam)); } - static Sort sanitizeDistributionSetSortParam(final String sortParam) { + public static Sort sanitizeDistributionSetSortParam(final String sortParam) { if (sortParam == null) { // default return Sort.by(Direction.ASC, DistributionSetFields.ID.getJpaEntityFieldName()); @@ -111,7 +110,7 @@ static Sort sanitizeDistributionSetSortParam(final String sortParam) { return Sort.by(SortUtility.parse(DistributionSetFields.class, sortParam)); } - static Sort sanitizeDistributionSetTypeSortParam(final String sortParam) { + public static Sort sanitizeDistributionSetTypeSortParam(final String sortParam) { if (sortParam == null) { // default return Sort.by(Direction.ASC, DistributionSetTypeFields.ID.getJpaEntityFieldName()); @@ -119,7 +118,7 @@ static Sort sanitizeDistributionSetTypeSortParam(final String sortParam) { return Sort.by(SortUtility.parse(DistributionSetTypeFields.class, sortParam)); } - static Sort sanitizeActionSortParam(final String sortParam) { + public static Sort sanitizeActionSortParam(final String sortParam) { if (sortParam == null) { // default sort is DESC in case of action to match behavior // of management UI (last entry on top) @@ -128,7 +127,7 @@ static Sort sanitizeActionSortParam(final String sortParam) { return Sort.by(SortUtility.parse(ActionFields.class, sortParam)); } - static Sort sanitizeActionStatusSortParam(final String sortParam) { + public static Sort sanitizeActionStatusSortParam(final String sortParam) { if (sortParam == null) { // default sort is DESC in case of action status to match behavior // of management UI (last entry on top) @@ -137,7 +136,7 @@ static Sort sanitizeActionStatusSortParam(final String sortParam) { return Sort.by(SortUtility.parse(ActionStatusFields.class, sortParam)); } - static Sort sanitizeDistributionSetMetadataSortParam(final String sortParam) { + public static Sort sanitizeDistributionSetMetadataSortParam(final String sortParam) { if (sortParam == null) { // default return Sort.by(Direction.ASC, DistributionSetMetadataFields.KEY.getJpaEntityFieldName()); @@ -145,7 +144,7 @@ static Sort sanitizeDistributionSetMetadataSortParam(final String sortParam) { return Sort.by(SortUtility.parse(DistributionSetMetadataFields.class, sortParam)); } - static Sort sanitizeSoftwareModuleMetadataSortParam(final String sortParam) { + public static Sort sanitizeSoftwareModuleMetadataSortParam(final String sortParam) { if (sortParam == null) { // default return Sort.by(Direction.ASC, SoftwareModuleMetadataFields.KEY.getJpaEntityFieldName()); @@ -153,7 +152,7 @@ static Sort sanitizeSoftwareModuleMetadataSortParam(final String sortParam) { return Sort.by(SortUtility.parse(SoftwareModuleMetadataFields.class, sortParam)); } - static Sort sanitizeRolloutSortParam(final String sortParam) { + public static Sort sanitizeRolloutSortParam(final String sortParam) { if (sortParam == null) { // default return Sort.by(Direction.ASC, RolloutFields.ID.getJpaEntityFieldName()); @@ -161,7 +160,7 @@ static Sort sanitizeRolloutSortParam(final String sortParam) { return Sort.by(SortUtility.parse(RolloutFields.class, sortParam)); } - static Sort sanitizeRolloutGroupSortParam(final String sortParam) { + public static Sort sanitizeRolloutGroupSortParam(final String sortParam) { if (sortParam == null) { // default return Sort.by(Direction.ASC, RolloutGroupFields.ID.getJpaEntityFieldName()); diff --git a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/util/SortUtility.java b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/util/SortUtility.java new file mode 100644 index 0000000000..988b52467a --- /dev/null +++ b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/util/SortUtility.java @@ -0,0 +1,90 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.hawkbit.mgmt.rest.resource.util; + +import java.util.ArrayList; +import java.util.List; +import java.util.StringTokenizer; + +import lombok.AccessLevel; +import lombok.NoArgsConstructor; +import org.eclipse.hawkbit.mgmt.rest.resource.exception.SortParameterUnsupportedDirectionException; +import org.eclipse.hawkbit.repository.RsqlQueryField; +import org.eclipse.hawkbit.mgmt.rest.resource.exception.SortParameterSyntaxErrorException; +import org.eclipse.hawkbit.mgmt.rest.resource.exception.SortParameterUnsupportedFieldException; +import org.springframework.data.domain.Sort.Direction; +import org.springframework.data.domain.Sort.Order; + +/** + * A utility class for parsing query parameters which define the sorting of elements. + */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class SortUtility { + + /** + * the delimiter between the different field directions in the sort request. + */ + public static final String DELIMITER_SORT_TUPLE = ","; + /** + * the delimiter between the field and direction in the sort request. + */ + public static final String DELIMITER_FIELD_DIRECTION = ":"; + + /** + * Parses the sort string e.g. given in a REST call based on the definition + * of sorting: http://localhost/entity?s=field1:ASC,field2:DESC The fields + * will be split into the keys of the returned map. The direction of the + * sorting will be mapped into the {@link Direction} enum. + * + * @param enumType the class of the enum which the fields in the sort string should be related to. + * @param the type of the enumeration which must be derived from {@link RsqlQueryField} + * @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 {@link Direction} for them as a tuple. Never {@code null}. + * In case of no sorting parameters an empty map will be returned. + * @throws SortParameterSyntaxErrorException if the sorting query parameter is not well-formed + * @throws SortParameterUnsupportedFieldException if a field name cannot be mapped to the enum type + * @throws SortParameterUnsupportedDirectionException if the given direction is not "ASC" or "DESC" + */ + public static & RsqlQueryField> List parse(final Class enumType, final String sortString) + throws SortParameterSyntaxErrorException { + final List orders = new ArrayList<>(); + // scan the sort tuples e.g. field:direction + if (sortString != null) { + final StringTokenizer tupleTokenizer = new StringTokenizer(sortString, DELIMITER_SORT_TUPLE); + while (tupleTokenizer.hasMoreTokens()) { + final String sortTuple = tupleTokenizer.nextToken().trim(); + final StringTokenizer fieldDirectionTokenizer = new StringTokenizer(sortTuple, DELIMITER_FIELD_DIRECTION); + if (fieldDirectionTokenizer.countTokens() == 2) { + final String fieldName = fieldDirectionTokenizer.nextToken().trim().toUpperCase(); + final String sortDirectionStr = fieldDirectionTokenizer.nextToken().trim(); + + final T identifier; + try { + identifier = Enum.valueOf(enumType, fieldName.toUpperCase()); + } catch (final IllegalArgumentException e) { + throw new SortParameterUnsupportedFieldException(e); + } + + final Direction sortDirection; + try { + sortDirection = Direction.fromString(sortDirectionStr); + } catch (final IllegalArgumentException e) { + throw new SortParameterUnsupportedDirectionException(e); + } + + orders.add(new Order(sortDirection, identifier.getJpaEntityFieldName())); + } else { + throw new SortParameterSyntaxErrorException(); + } + } + } + return orders; + } +} \ No newline at end of file diff --git a/hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java b/hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java index 5666b1f9ff..b5f7749d8b 100644 --- a/hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java +++ b/hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java @@ -45,6 +45,7 @@ import org.eclipse.hawkbit.exception.SpServerError; import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtActionType; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; +import org.eclipse.hawkbit.mgmt.rest.resource.util.ResourceUtility; import org.eclipse.hawkbit.repository.exception.AssignmentQuotaExceededException; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.jpa.repository.ActionRepository; diff --git a/hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResourceTest.java b/hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResourceTest.java index 536052c469..e52072cf76 100644 --- a/hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResourceTest.java +++ b/hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTagResourceTest.java @@ -32,6 +32,7 @@ import io.qameta.allure.Feature; import io.qameta.allure.Story; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; +import org.eclipse.hawkbit.mgmt.rest.resource.util.ResourceUtility; import org.eclipse.hawkbit.repository.event.remote.DistributionSetTagDeletedEvent; import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetCreatedEvent; import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTagCreatedEvent; diff --git a/hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java b/hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java index 8403c5a898..7d237b973c 100644 --- a/hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java +++ b/hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java @@ -48,6 +48,7 @@ import org.eclipse.hawkbit.mgmt.json.model.artifact.MgmtArtifact; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRepresentationMode; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; +import org.eclipse.hawkbit.mgmt.rest.resource.util.ResourceUtility; import org.eclipse.hawkbit.repository.Constants; import org.eclipse.hawkbit.repository.exception.AssignmentQuotaExceededException; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; diff --git a/hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetFilterQueryResourceTest.java b/hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetFilterQueryResourceTest.java index fd8a0c8bee..a8008dbe92 100644 --- a/hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetFilterQueryResourceTest.java +++ b/hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetFilterQueryResourceTest.java @@ -33,6 +33,7 @@ import org.eclipse.hawkbit.exception.SpServerError; import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtActionType; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; +import org.eclipse.hawkbit.mgmt.rest.resource.util.ResourceUtility; import org.eclipse.hawkbit.repository.exception.AssignmentQuotaExceededException; import org.eclipse.hawkbit.repository.exception.DeletedException; import org.eclipse.hawkbit.repository.exception.IncompleteDistributionSetException; diff --git a/hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResourceTest.java b/hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResourceTest.java index 1be97f1356..9cb2dc7042 100644 --- a/hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResourceTest.java +++ b/hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResourceTest.java @@ -60,6 +60,7 @@ import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtActionType; import org.eclipse.hawkbit.mgmt.json.model.target.MgmtTargetAutoConfirmUpdate; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; +import org.eclipse.hawkbit.mgmt.rest.resource.util.ResourceUtility; import org.eclipse.hawkbit.repository.ActionFields; import org.eclipse.hawkbit.repository.Identifiable; import org.eclipse.hawkbit.repository.builder.ActionStatusCreate; diff --git a/hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTagResourceTest.java b/hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTagResourceTest.java index ae990e4957..814a2b3a40 100644 --- a/hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTagResourceTest.java +++ b/hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetTagResourceTest.java @@ -34,6 +34,7 @@ import io.qameta.allure.Story; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetTagRestApi; +import org.eclipse.hawkbit.mgmt.rest.resource.util.ResourceUtility; import org.eclipse.hawkbit.repository.event.remote.TargetTagDeletedEvent; import org.eclipse.hawkbit.repository.event.remote.entity.TargetCreatedEvent; import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagCreatedEvent; diff --git a/hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/ResourceUtility.java b/hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/util/ResourceUtility.java similarity index 80% rename from hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/ResourceUtility.java rename to hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/util/ResourceUtility.java index 7153a281cd..a7a2cc89d2 100644 --- a/hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/ResourceUtility.java +++ b/hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/util/ResourceUtility.java @@ -7,7 +7,7 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.eclipse.hawkbit.mgmt.rest.resource; +package org.eclipse.hawkbit.mgmt.rest.resource.util; import java.io.IOException; @@ -25,18 +25,18 @@ public final class ResourceUtility { private static final ObjectMapper mapper = new ObjectMapper(); - static ExceptionInfo convertException(final String jsonExceptionResponse) + public static ExceptionInfo convertException(final String jsonExceptionResponse) throws JsonParseException, JsonMappingException, IOException { return mapper.readValue(jsonExceptionResponse, ExceptionInfo.class); } - static MgmtArtifact convertArtifactResponse(final String jsonResponse) + public static MgmtArtifact convertArtifactResponse(final String jsonResponse) throws JsonParseException, JsonMappingException, IOException { return mapper.readValue(jsonResponse, MgmtArtifact.class); } - static PagedList mapResponse(final Class clazz, final String responseBody) + public static PagedList mapResponse(final Class clazz, final String responseBody) throws JsonParseException, JsonMappingException, IOException { return mapper.readValue(responseBody, PagedList.class); } diff --git a/hawkbit-rest/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/util/SortUtilityTest.java b/hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/util/SortUtilityTest.java similarity index 90% rename from hawkbit-rest/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/util/SortUtilityTest.java rename to hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/util/SortUtilityTest.java index a5b131f41a..8d49c5dd2b 100644 --- a/hawkbit-rest/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/util/SortUtilityTest.java +++ b/hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/util/SortUtilityTest.java @@ -7,7 +7,7 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.eclipse.hawkbit.rest.util; +package org.eclipse.hawkbit.mgmt.rest.resource.util; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -17,16 +17,13 @@ import io.qameta.allure.Description; import io.qameta.allure.Feature; import io.qameta.allure.Story; +import org.eclipse.hawkbit.mgmt.rest.resource.exception.SortParameterUnsupportedDirectionException; import org.eclipse.hawkbit.repository.TargetFields; -import org.eclipse.hawkbit.rest.exception.SortParameterSyntaxErrorException; -import org.eclipse.hawkbit.rest.exception.SortParameterUnsupportedDirectionException; -import org.eclipse.hawkbit.rest.exception.SortParameterUnsupportedFieldException; +import org.eclipse.hawkbit.mgmt.rest.resource.exception.SortParameterSyntaxErrorException; +import org.eclipse.hawkbit.mgmt.rest.resource.exception.SortParameterUnsupportedFieldException; import org.junit.jupiter.api.Test; import org.springframework.data.domain.Sort.Order; -/** - * - */ @Feature("Component Tests - Management API") @Story("Sorting parameter") public class SortUtilityTest { diff --git a/hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/RestConfiguration.java b/hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/RestConfiguration.java index e1991554cd..49e02f627d 100644 --- a/hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/RestConfiguration.java +++ b/hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/RestConfiguration.java @@ -9,15 +9,43 @@ */ package org.eclipse.hawkbit.rest; -import org.eclipse.hawkbit.rest.exception.ResponseExceptionHandler; -import org.eclipse.hawkbit.rest.filter.ExcludePathAwareShallowETagFilter; +import java.io.IOException; +import java.util.EnumMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.validation.ConstraintViolationException; +import jakarta.validation.ValidationException; + +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.exception.ExceptionUtils; +import org.eclipse.hawkbit.exception.AbstractServerRtException; +import org.eclipse.hawkbit.exception.SpServerError; +import org.eclipse.hawkbit.rest.exception.MessageNotReadableException; +import org.eclipse.hawkbit.rest.exception.MultiPartFileUploadException; +import org.eclipse.hawkbit.rest.json.model.ExceptionInfo; +import org.eclipse.hawkbit.rest.util.FileStreamingFailedException; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.hateoas.config.EnableHypermediaSupport; import org.springframework.hateoas.config.EnableHypermediaSupport.HypermediaType; import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.http.converter.HttpMessageNotReadableException; +import org.springframework.util.AntPathMatcher; +import org.springframework.util.ObjectUtils; +import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.filter.ShallowEtagHeaderFilter; +import org.springframework.web.method.annotation.HandlerMethodValidationException; +import org.springframework.web.multipart.MultipartException; /** * Configuration for Rest api. @@ -27,8 +55,9 @@ public class RestConfiguration { /** - * {@link ControllerAdvice} for mapping {@link RuntimeException}s from the - * repository to {@link HttpStatus} codes. + * {@link ControllerAdvice} for mapping {@link RuntimeException}s from the repository to {@link HttpStatus} codes. + * + * @return a controller advice for handling exceptions */ @Bean ResponseExceptionHandler responseExceptionHandler() { @@ -38,17 +67,15 @@ ResponseExceptionHandler responseExceptionHandler() { /** * Filter registration bean for spring etag filter. * - * @return the spring filter registration bean for registering an etag - * filter in the filter chain + * @return the spring filter registration bean for registering an etag filter in the filter chain */ @Bean FilterRegistrationBean eTagFilter() { - final FilterRegistrationBean filterRegBean = new FilterRegistrationBean<>(); + // Exclude the URLs for downloading artifacts, so no eTag is generated - // in the ShallowEtagHeaderFilter, just using the SH1 hash of the - // artifact itself as 'ETag', because otherwise the file will be copied - // in memory! + // in the ShallowEtagHeaderFilter, just using the SHA1 hash of the + // artifact itself as 'ETag', because otherwise the file will be copied in memory! filterRegBean.setFilter(new ExcludePathAwareShallowETagFilter( "/rest/v1/softwaremodules/{smId}/artifacts/{artId}/download", "/{tenant}/controller/v1/{controllerId}/softwaremodules/{softwareModuleId}/artifacts/**", @@ -56,4 +83,254 @@ FilterRegistrationBean eTagFilter() { return filterRegBean; } -} + + /** + * General controller advice for exception handling. + */ + @Slf4j + @ControllerAdvice + public static class ResponseExceptionHandler { + + private static final Map ERROR_TO_HTTP_STATUS = new EnumMap<>(SpServerError.class); + private static final HttpStatus DEFAULT_RESPONSE_STATUS = HttpStatus.INTERNAL_SERVER_ERROR; + + private static final String MESSAGE_FORMATTER_SEPARATOR = " "; + + static { + ERROR_TO_HTTP_STATUS.put(SpServerError.SP_REPO_ENTITY_NOT_EXISTS, HttpStatus.NOT_FOUND); + ERROR_TO_HTTP_STATUS.put(SpServerError.SP_REPO_ENTITY_ALREADY_EXISTS, HttpStatus.CONFLICT); + ERROR_TO_HTTP_STATUS.put(SpServerError.SP_REPO_ENTITY_READ_ONLY, HttpStatus.FORBIDDEN); + ERROR_TO_HTTP_STATUS.put(SpServerError.SP_REST_SORT_PARAM_INVALID_DIRECTION, HttpStatus.BAD_REQUEST); + ERROR_TO_HTTP_STATUS.put(SpServerError.SP_REST_SORT_PARAM_INVALID_FIELD, HttpStatus.BAD_REQUEST); + ERROR_TO_HTTP_STATUS.put(SpServerError.SP_REST_SORT_PARAM_SYNTAX, HttpStatus.BAD_REQUEST); + ERROR_TO_HTTP_STATUS.put(SpServerError.SP_REST_RSQL_PARAM_INVALID_FIELD, HttpStatus.BAD_REQUEST); + ERROR_TO_HTTP_STATUS.put(SpServerError.SP_REST_RSQL_SEARCH_PARAM_SYNTAX, HttpStatus.BAD_REQUEST); + ERROR_TO_HTTP_STATUS.put(SpServerError.SP_INSUFFICIENT_PERMISSION, HttpStatus.FORBIDDEN); + ERROR_TO_HTTP_STATUS.put(SpServerError.SP_ARTIFACT_UPLOAD_FAILED, HttpStatus.INTERNAL_SERVER_ERROR); + ERROR_TO_HTTP_STATUS.put(SpServerError.SP_ARTIFACT_ENCRYPTION_NOT_SUPPORTED, HttpStatus.BAD_REQUEST); + ERROR_TO_HTTP_STATUS.put(SpServerError.SP_ARTIFACT_ENCRYPTION_FAILED, HttpStatus.INTERNAL_SERVER_ERROR); + ERROR_TO_HTTP_STATUS.put(SpServerError.SP_ARTIFACT_UPLOAD_FAILED_SHA1_MATCH, HttpStatus.BAD_REQUEST); + ERROR_TO_HTTP_STATUS.put(SpServerError.SP_ARTIFACT_UPLOAD_FAILED_SHA256_MATCH, HttpStatus.BAD_REQUEST); + ERROR_TO_HTTP_STATUS.put(SpServerError.SP_ARTIFACT_UPLOAD_FAILED_MD5_MATCH, HttpStatus.BAD_REQUEST); + ERROR_TO_HTTP_STATUS.put(SpServerError.SP_ARTIFACT_DELETE_FAILED, HttpStatus.INTERNAL_SERVER_ERROR); + ERROR_TO_HTTP_STATUS.put(SpServerError.SP_ARTIFACT_BINARY_DELETED, HttpStatus.GONE); + ERROR_TO_HTTP_STATUS.put(SpServerError.SP_ARTIFACT_LOAD_FAILED, HttpStatus.INTERNAL_SERVER_ERROR); + ERROR_TO_HTTP_STATUS.put(SpServerError.SP_QUOTA_EXCEEDED, HttpStatus.FORBIDDEN); + ERROR_TO_HTTP_STATUS.put(SpServerError.SP_FILE_SIZE_QUOTA_EXCEEDED, HttpStatus.FORBIDDEN); + ERROR_TO_HTTP_STATUS.put(SpServerError.SP_STORAGE_QUOTA_EXCEEDED, HttpStatus.FORBIDDEN); + ERROR_TO_HTTP_STATUS.put(SpServerError.SP_ACTION_NOT_CANCELABLE, HttpStatus.METHOD_NOT_ALLOWED); + ERROR_TO_HTTP_STATUS.put(SpServerError.SP_ACTION_NOT_FORCE_QUITABLE, HttpStatus.METHOD_NOT_ALLOWED); + ERROR_TO_HTTP_STATUS.put(SpServerError.SP_DS_CREATION_FAILED_MISSING_MODULE, HttpStatus.BAD_REQUEST); + ERROR_TO_HTTP_STATUS.put(SpServerError.SP_DS_MODULE_UNSUPPORTED, HttpStatus.BAD_REQUEST); + ERROR_TO_HTTP_STATUS.put(SpServerError.SP_DS_TYPE_UNDEFINED, HttpStatus.BAD_REQUEST); + ERROR_TO_HTTP_STATUS.put(SpServerError.SP_REPO_TENANT_NOT_EXISTS, HttpStatus.BAD_REQUEST); + ERROR_TO_HTTP_STATUS.put(SpServerError.SP_ENTITY_LOCKED, HttpStatus.LOCKED); + ERROR_TO_HTTP_STATUS.put(SpServerError.SP_ROLLOUT_ILLEGAL_STATE, HttpStatus.BAD_REQUEST); + ERROR_TO_HTTP_STATUS.put(SpServerError.SP_CONFIGURATION_VALUE_INVALID, HttpStatus.BAD_REQUEST); + ERROR_TO_HTTP_STATUS.put(SpServerError.SP_CONFIGURATION_KEY_INVALID, HttpStatus.BAD_REQUEST); + ERROR_TO_HTTP_STATUS.put(SpServerError.SP_REPO_INVALID_TARGET_ADDRESS, HttpStatus.BAD_REQUEST); + ERROR_TO_HTTP_STATUS.put(SpServerError.SP_REPO_CONSTRAINT_VIOLATION, HttpStatus.BAD_REQUEST); + ERROR_TO_HTTP_STATUS.put(SpServerError.SP_REPO_OPERATION_NOT_SUPPORTED, HttpStatus.GONE); + ERROR_TO_HTTP_STATUS.put(SpServerError.SP_REPO_CONCURRENT_MODIFICATION, HttpStatus.CONFLICT); + ERROR_TO_HTTP_STATUS.put(SpServerError.SP_MAINTENANCE_SCHEDULE_INVALID, HttpStatus.BAD_REQUEST); + ERROR_TO_HTTP_STATUS.put(SpServerError.SP_TARGET_ATTRIBUTES_INVALID, HttpStatus.BAD_REQUEST); + ERROR_TO_HTTP_STATUS.put(SpServerError.SP_REPO_AUTO_CONFIRMATION_ALREADY_ACTIVE, HttpStatus.CONFLICT); + ERROR_TO_HTTP_STATUS.put(SpServerError.SP_AUTO_ASSIGN_ACTION_TYPE_INVALID, HttpStatus.BAD_REQUEST); + ERROR_TO_HTTP_STATUS.put(SpServerError.SP_CONFIGURATION_VALUE_CHANGE_NOT_ALLOWED, HttpStatus.FORBIDDEN); + ERROR_TO_HTTP_STATUS.put(SpServerError.SP_MULTIASSIGNMENT_NOT_ENABLED, HttpStatus.BAD_REQUEST); + ERROR_TO_HTTP_STATUS.put(SpServerError.SP_NO_WEIGHT_PROVIDED_IN_MULTIASSIGNMENT_MODE, HttpStatus.BAD_REQUEST); + ERROR_TO_HTTP_STATUS.put(SpServerError.SP_TARGET_TYPE_IN_USE, HttpStatus.CONFLICT); + ERROR_TO_HTTP_STATUS.put(SpServerError.SP_TARGET_TYPE_INCOMPATIBLE, HttpStatus.BAD_REQUEST); + ERROR_TO_HTTP_STATUS.put(SpServerError.SP_TARGET_TYPE_KEY_OR_NAME_REQUIRED, HttpStatus.BAD_REQUEST); + ERROR_TO_HTTP_STATUS.put(SpServerError.SP_DS_INVALID, HttpStatus.BAD_REQUEST); + ERROR_TO_HTTP_STATUS.put(SpServerError.SP_DS_INCOMPLETE, HttpStatus.BAD_REQUEST); + ERROR_TO_HTTP_STATUS.put(SpServerError.SP_LOCKED, HttpStatus.LOCKED); + ERROR_TO_HTTP_STATUS.put(SpServerError.SP_DELETED, HttpStatus.NOT_FOUND); + ERROR_TO_HTTP_STATUS.put(SpServerError.SP_STOP_ROLLOUT_FAILED, HttpStatus.LOCKED); + } + + /** + * method for handling exception of type AbstractServerRtException. Called by the Spring-Framework for exception handling. + * + * @param request the Http request + * @param ex the exception which occurred + * @return the entity to be responded containing the exception information as entity. + */ + @ExceptionHandler(AbstractServerRtException.class) + public ResponseEntity handleSpServerRtExceptions(final HttpServletRequest request, final Exception ex) { + logRequest(request, ex); + final ExceptionInfo response = createExceptionInfo(ex); + final HttpStatus responseStatus; + if (ex instanceof AbstractServerRtException) { + responseStatus = getStatusOrDefault(((AbstractServerRtException) ex).getError()); + } else { + responseStatus = DEFAULT_RESPONSE_STATUS; + } + return new ResponseEntity<>(response, responseStatus); + } + + /** + * Method for handling exception of type {@link FileStreamingFailedException} which is thrown in case the streaming of a file failed + * due to an internal server error. As the streaming of the file has already begun, no JSON response but only the ResponseStatus 500 + * is returned. + * Called by the Spring-Framework for exception handling. + * + * @param request the Http request + * @param ex the exception which occurred + * @return the entity to be responded containing the response status 500 + */ + @ExceptionHandler(FileStreamingFailedException.class) + public ResponseEntity handleFileStreamingFailedException(final HttpServletRequest request, final Exception ex) { + logRequest(request, ex); + log.warn("File streaming failed: {}", ex.getMessage()); + return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); + } + + /** + * Method for handling exception of type HttpMessageNotReadableException and MethodArgumentNotValidException which are thrown in case + * the request body is not well-formed (e.g. syntax failures, missing/invalid parameters) and cannot be deserialized. + * Called by the Spring-Framework for exception handling. + * + * @param request the Http request + * @param ex the exception which occurred + * @return the entity to be responded containing the exception information as entity. + */ + @ExceptionHandler({ + HttpMessageNotReadableException.class, + MethodArgumentNotValidException.class, HandlerMethodValidationException.class, + IllegalArgumentException.class }) + public ResponseEntity handleExceptionCausedByIncorrectRequestBody(final HttpServletRequest request, final Exception ex) { + logRequest(request, ex); + final ExceptionInfo response = createExceptionInfo(new MessageNotReadableException()); + return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST); + } + + /** + * Method for handling exception of type ConstraintViolationException which is thrown in case the request is rejected due to a + * constraint violation. + * Called by the Spring-Framework for exception handling. + * + * @param request the Http request + * @param ex the exception which occurred + * @return the entity to be responded containing the exception information as entity. + */ + @ExceptionHandler(ConstraintViolationException.class) + public ResponseEntity handleConstraintViolationException(final HttpServletRequest request, final ConstraintViolationException ex) { + logRequest(request, ex); + + final ExceptionInfo response = new ExceptionInfo(); + response.setMessage(ex.getConstraintViolations().stream() + .map(violation -> violation.getPropertyPath() + MESSAGE_FORMATTER_SEPARATOR + violation.getMessage() + ".") + .collect(Collectors.joining(MESSAGE_FORMATTER_SEPARATOR))); + response.setExceptionClass(ex.getClass().getName()); + response.setErrorCode(SpServerError.SP_REPO_CONSTRAINT_VIOLATION.getKey()); + + return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST); + } + + /** + * Method for handling exception of type ValidationException which is thrown in case the request is rejected due to invalid requests. + * Called by the Spring-Framework for exception handling. + * + * @param request the Http request + * @param ex the exception which occurred + * @return the entity to be responded containing the exception information as entity. + */ + @ExceptionHandler(ValidationException.class) + public ResponseEntity handleValidationException(final HttpServletRequest request, final ValidationException ex) { + logRequest(request, ex); + + final ExceptionInfo response = new ExceptionInfo(); + response.setMessage(ex.getMessage()); + response.setExceptionClass(ex.getClass().getName()); + response.setErrorCode(SpServerError.SP_REPO_CONSTRAINT_VIOLATION.getKey()); + + return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST); + } + + /** + * Method for handling exception of type {@link MultipartException} which is thrown in case the request body is not well-formed and + * cannot be deserialized. + * Called by the Spring-Framework for exception handling. + * + * @param request the Http request + * @param ex the exception which occurred + * @return the entity to be responded containing the exception information as entity. + */ + @ExceptionHandler(MultipartException.class) + public ResponseEntity handleMultipartException(final HttpServletRequest request, final Exception ex) { + logRequest(request, ex); + + final List throwables = ExceptionUtils.getThrowableList(ex); + final Throwable responseCause = throwables.get(throwables.size() - 1); + + if (ObjectUtils.isEmpty(responseCause.getMessage())) { + log.warn("Request {} lead to MultipartException without root cause message:\n{}", request.getRequestURL(), + ex.getStackTrace()); + } + + return new ResponseEntity<>(createExceptionInfo(new MultiPartFileUploadException(responseCause)), 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) { + log.debug("Handling exception {} of request {}", ex.getClass().getName(), request.getRequestURL()); + } + + private ExceptionInfo createExceptionInfo(final Exception ex) { + final ExceptionInfo response = new ExceptionInfo(); + response.setMessage(ex.getMessage()); + response.setExceptionClass(ex.getClass().getName()); + if (ex instanceof AbstractServerRtException) { + response.setErrorCode(((AbstractServerRtException) ex).getError().getKey()); + response.setInfo(((AbstractServerRtException) ex).getInfo()); + } + return response; + } + + } + + /** + * An {@link ShallowEtagHeaderFilter} with exclusion paths to exclude some paths + * where no ETag header should be generated due that calculating the ETag is an + * expensive operation and the response output need to be copied in memory which + * should be excluded in case of artifact downloads which could be big of size. + */ + static class ExcludePathAwareShallowETagFilter extends ShallowEtagHeaderFilter { + + private final String[] excludeAntPaths; + private final AntPathMatcher antMatcher = new AntPathMatcher(); + + /** + * @param excludeAntPaths + */ + public ExcludePathAwareShallowETagFilter(final String... excludeAntPaths) { + this.excludeAntPaths = excludeAntPaths; + } + + @Override + protected void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response, final FilterChain filterChain) + throws ServletException, IOException { + final boolean shouldExclude = shouldExclude(request); + if (shouldExclude) { + filterChain.doFilter(request, response); + } else { + super.doFilterInternal(request, response, filterChain); + } + } + + private boolean shouldExclude(final HttpServletRequest request) { + for (final String pattern : excludeAntPaths) { + if (antMatcher.match(request.getContextPath() + pattern, request.getRequestURI())) { + // exclude this request from eTag filter + return true; + } + } + return false; + } + } + +} \ No newline at end of file diff --git a/hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/data/SortDirection.java b/hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/data/SortDirection.java deleted file mode 100644 index cdb412f792..0000000000 --- a/hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/data/SortDirection.java +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.eclipse.hawkbit.rest.data; - -import org.eclipse.hawkbit.rest.exception.SortParameterUnsupportedDirectionException; - -/** - * A definition of possible sorting direction. - */ -public enum SortDirection { - /** - * Ascending. - */ - ASC, - /** - * Descending. - */ - DESC; - - /** - * Returns the sort direction for the given name. - * - * @param name the name of the enum - * @return the corresponding enum - * @throws SortParameterUnsupportedDirectionException if there is no matching enum for the specified name - */ - public static SortDirection getByName(final String name) { - try { - return valueOf(name.toUpperCase()); - } catch (final IllegalArgumentException ex) { - throw new SortParameterUnsupportedDirectionException(); - } - } -} diff --git a/hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/exception/MultiPartFileUploadException.java b/hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/exception/MultiPartFileUploadException.java index 00f498e4c1..395375d5a4 100644 --- a/hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/exception/MultiPartFileUploadException.java +++ b/hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/exception/MultiPartFileUploadException.java @@ -9,21 +9,20 @@ */ package org.eclipse.hawkbit.rest.exception; +import java.io.Serial; + import org.eclipse.hawkbit.exception.AbstractServerRtException; import org.eclipse.hawkbit.exception.SpServerError; /** - * Thrown if a multi part exception occurred. + * Thrown if a multipart exception occurred. */ public final class MultiPartFileUploadException extends AbstractServerRtException { + @Serial private static final long serialVersionUID = 1L; - /** - * @param cause for the exception - */ public MultiPartFileUploadException(final Throwable cause) { super(cause.getMessage(), SpServerError.SP_ARTIFACT_UPLOAD_FAILED, cause); } - -} +} \ No newline at end of file diff --git a/hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/exception/ResponseExceptionHandler.java b/hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/exception/ResponseExceptionHandler.java deleted file mode 100644 index a4eb75f5ee..0000000000 --- a/hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/exception/ResponseExceptionHandler.java +++ /dev/null @@ -1,262 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.eclipse.hawkbit.rest.exception; - -import java.util.EnumMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -import jakarta.servlet.http.HttpServletRequest; -import jakarta.validation.ConstraintViolationException; -import jakarta.validation.ValidationException; - -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.exception.ExceptionUtils; -import org.eclipse.hawkbit.exception.AbstractServerRtException; -import org.eclipse.hawkbit.exception.SpServerError; -import org.eclipse.hawkbit.rest.json.model.ExceptionInfo; -import org.eclipse.hawkbit.rest.util.FileStreamingFailedException; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.http.converter.HttpMessageNotReadableException; -import org.springframework.util.ObjectUtils; -import org.springframework.web.bind.MethodArgumentNotValidException; -import org.springframework.web.bind.annotation.ControllerAdvice; -import org.springframework.web.bind.annotation.ExceptionHandler; -import org.springframework.web.method.annotation.HandlerMethodValidationException; -import org.springframework.web.multipart.MultipartException; - -/** - * General controller advice for exception handling. - */ -@Slf4j -@ControllerAdvice -public class ResponseExceptionHandler { - - private static final Map ERROR_TO_HTTP_STATUS = new EnumMap<>(SpServerError.class); - private static final HttpStatus DEFAULT_RESPONSE_STATUS = HttpStatus.INTERNAL_SERVER_ERROR; - - private static final String MESSAGE_FORMATTER_SEPARATOR = " "; - - static { - ERROR_TO_HTTP_STATUS.put(SpServerError.SP_REPO_ENTITY_NOT_EXISTS, HttpStatus.NOT_FOUND); - ERROR_TO_HTTP_STATUS.put(SpServerError.SP_REPO_ENTITY_ALREADY_EXISTS, HttpStatus.CONFLICT); - ERROR_TO_HTTP_STATUS.put(SpServerError.SP_REPO_ENTITY_READ_ONLY, HttpStatus.FORBIDDEN); - ERROR_TO_HTTP_STATUS.put(SpServerError.SP_REST_SORT_PARAM_INVALID_DIRECTION, HttpStatus.BAD_REQUEST); - ERROR_TO_HTTP_STATUS.put(SpServerError.SP_REST_SORT_PARAM_INVALID_FIELD, HttpStatus.BAD_REQUEST); - ERROR_TO_HTTP_STATUS.put(SpServerError.SP_REST_SORT_PARAM_SYNTAX, HttpStatus.BAD_REQUEST); - ERROR_TO_HTTP_STATUS.put(SpServerError.SP_REST_RSQL_PARAM_INVALID_FIELD, HttpStatus.BAD_REQUEST); - ERROR_TO_HTTP_STATUS.put(SpServerError.SP_REST_RSQL_SEARCH_PARAM_SYNTAX, HttpStatus.BAD_REQUEST); - ERROR_TO_HTTP_STATUS.put(SpServerError.SP_INSUFFICIENT_PERMISSION, HttpStatus.FORBIDDEN); - ERROR_TO_HTTP_STATUS.put(SpServerError.SP_ARTIFACT_UPLOAD_FAILED, HttpStatus.INTERNAL_SERVER_ERROR); - ERROR_TO_HTTP_STATUS.put(SpServerError.SP_ARTIFACT_ENCRYPTION_NOT_SUPPORTED, HttpStatus.BAD_REQUEST); - ERROR_TO_HTTP_STATUS.put(SpServerError.SP_ARTIFACT_ENCRYPTION_FAILED, HttpStatus.INTERNAL_SERVER_ERROR); - ERROR_TO_HTTP_STATUS.put(SpServerError.SP_ARTIFACT_UPLOAD_FAILED_SHA1_MATCH, HttpStatus.BAD_REQUEST); - ERROR_TO_HTTP_STATUS.put(SpServerError.SP_ARTIFACT_UPLOAD_FAILED_SHA256_MATCH, HttpStatus.BAD_REQUEST); - ERROR_TO_HTTP_STATUS.put(SpServerError.SP_ARTIFACT_UPLOAD_FAILED_MD5_MATCH, HttpStatus.BAD_REQUEST); - ERROR_TO_HTTP_STATUS.put(SpServerError.SP_ARTIFACT_DELETE_FAILED, HttpStatus.INTERNAL_SERVER_ERROR); - ERROR_TO_HTTP_STATUS.put(SpServerError.SP_ARTIFACT_BINARY_DELETED, HttpStatus.GONE); - ERROR_TO_HTTP_STATUS.put(SpServerError.SP_ARTIFACT_LOAD_FAILED, HttpStatus.INTERNAL_SERVER_ERROR); - ERROR_TO_HTTP_STATUS.put(SpServerError.SP_QUOTA_EXCEEDED, HttpStatus.FORBIDDEN); - ERROR_TO_HTTP_STATUS.put(SpServerError.SP_FILE_SIZE_QUOTA_EXCEEDED, HttpStatus.FORBIDDEN); - ERROR_TO_HTTP_STATUS.put(SpServerError.SP_STORAGE_QUOTA_EXCEEDED, HttpStatus.FORBIDDEN); - ERROR_TO_HTTP_STATUS.put(SpServerError.SP_ACTION_NOT_CANCELABLE, HttpStatus.METHOD_NOT_ALLOWED); - ERROR_TO_HTTP_STATUS.put(SpServerError.SP_ACTION_NOT_FORCE_QUITABLE, HttpStatus.METHOD_NOT_ALLOWED); - ERROR_TO_HTTP_STATUS.put(SpServerError.SP_DS_CREATION_FAILED_MISSING_MODULE, HttpStatus.BAD_REQUEST); - ERROR_TO_HTTP_STATUS.put(SpServerError.SP_DS_MODULE_UNSUPPORTED, HttpStatus.BAD_REQUEST); - ERROR_TO_HTTP_STATUS.put(SpServerError.SP_DS_TYPE_UNDEFINED, HttpStatus.BAD_REQUEST); - ERROR_TO_HTTP_STATUS.put(SpServerError.SP_REPO_TENANT_NOT_EXISTS, HttpStatus.BAD_REQUEST); - ERROR_TO_HTTP_STATUS.put(SpServerError.SP_ENTITY_LOCKED, HttpStatus.LOCKED); - ERROR_TO_HTTP_STATUS.put(SpServerError.SP_ROLLOUT_ILLEGAL_STATE, HttpStatus.BAD_REQUEST); - ERROR_TO_HTTP_STATUS.put(SpServerError.SP_CONFIGURATION_VALUE_INVALID, HttpStatus.BAD_REQUEST); - ERROR_TO_HTTP_STATUS.put(SpServerError.SP_CONFIGURATION_KEY_INVALID, HttpStatus.BAD_REQUEST); - ERROR_TO_HTTP_STATUS.put(SpServerError.SP_REPO_INVALID_TARGET_ADDRESS, HttpStatus.BAD_REQUEST); - ERROR_TO_HTTP_STATUS.put(SpServerError.SP_REPO_CONSTRAINT_VIOLATION, HttpStatus.BAD_REQUEST); - ERROR_TO_HTTP_STATUS.put(SpServerError.SP_REPO_OPERATION_NOT_SUPPORTED, HttpStatus.GONE); - ERROR_TO_HTTP_STATUS.put(SpServerError.SP_REPO_CONCURRENT_MODIFICATION, HttpStatus.CONFLICT); - ERROR_TO_HTTP_STATUS.put(SpServerError.SP_MAINTENANCE_SCHEDULE_INVALID, HttpStatus.BAD_REQUEST); - ERROR_TO_HTTP_STATUS.put(SpServerError.SP_TARGET_ATTRIBUTES_INVALID, HttpStatus.BAD_REQUEST); - ERROR_TO_HTTP_STATUS.put(SpServerError.SP_REPO_AUTO_CONFIRMATION_ALREADY_ACTIVE, HttpStatus.CONFLICT); - ERROR_TO_HTTP_STATUS.put(SpServerError.SP_AUTO_ASSIGN_ACTION_TYPE_INVALID, HttpStatus.BAD_REQUEST); - ERROR_TO_HTTP_STATUS.put(SpServerError.SP_CONFIGURATION_VALUE_CHANGE_NOT_ALLOWED, HttpStatus.FORBIDDEN); - ERROR_TO_HTTP_STATUS.put(SpServerError.SP_MULTIASSIGNMENT_NOT_ENABLED, HttpStatus.BAD_REQUEST); - ERROR_TO_HTTP_STATUS.put(SpServerError.SP_NO_WEIGHT_PROVIDED_IN_MULTIASSIGNMENT_MODE, HttpStatus.BAD_REQUEST); - ERROR_TO_HTTP_STATUS.put(SpServerError.SP_TARGET_TYPE_IN_USE, HttpStatus.CONFLICT); - ERROR_TO_HTTP_STATUS.put(SpServerError.SP_TARGET_TYPE_INCOMPATIBLE, HttpStatus.BAD_REQUEST); - ERROR_TO_HTTP_STATUS.put(SpServerError.SP_TARGET_TYPE_KEY_OR_NAME_REQUIRED, HttpStatus.BAD_REQUEST); - ERROR_TO_HTTP_STATUS.put(SpServerError.SP_DS_INVALID, HttpStatus.BAD_REQUEST); - ERROR_TO_HTTP_STATUS.put(SpServerError.SP_DS_INCOMPLETE, HttpStatus.BAD_REQUEST); - ERROR_TO_HTTP_STATUS.put(SpServerError.SP_LOCKED, HttpStatus.LOCKED); - ERROR_TO_HTTP_STATUS.put(SpServerError.SP_DELETED, HttpStatus.NOT_FOUND); - ERROR_TO_HTTP_STATUS.put(SpServerError.SP_STOP_ROLLOUT_FAILED, HttpStatus.LOCKED); - } - - /** - * method for handling exception of type AbstractServerRtException. Called - * by the Spring-Framework for exception handling. - * - * @param request the Http request - * @param ex the exception which occurred - * @return the entity to be responded containing the exception information - * as entity. - */ - @ExceptionHandler(AbstractServerRtException.class) - public ResponseEntity handleSpServerRtExceptions(final HttpServletRequest request, - final Exception ex) { - logRequest(request, ex); - final ExceptionInfo response = createExceptionInfo(ex); - final HttpStatus responseStatus; - if (ex instanceof AbstractServerRtException) { - responseStatus = getStatusOrDefault(((AbstractServerRtException) ex).getError()); - } else { - responseStatus = DEFAULT_RESPONSE_STATUS; - } - return new ResponseEntity<>(response, responseStatus); - } - - /** - * Method for handling exception of type - * {@link FileStreamingFailedException} which is thrown in case the - * streaming of a file failed due to an internal server error. As the - * streaming of the file has already begun, no JSON response but only the - * ResponseStatus 500 is returned. Called by the Spring-Framework for - * exception handling. - * - * @param request the Http request - * @param ex the exception which occurred - * @return the entity to be responded containing the response status 500 - */ - @ExceptionHandler(FileStreamingFailedException.class) - public ResponseEntity handleFileStreamingFailedException(final HttpServletRequest request, - final Exception ex) { - logRequest(request, ex); - log.warn("File streaming failed: {}", ex.getMessage()); - return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); - } - - /** - * Method for handling exception of type HttpMessageNotReadableException and - * MethodArgumentNotValidException which are thrown in case the request body - * is not well formed (e.g. syntax failures, missing/invalid parameters) and - * cannot be deserialized. Called by the Spring-Framework for exception - * handling. - * - * @param request the Http request - * @param ex the exception which occurred - * @return the entity to be responded containing the exception information - * as entity. - */ - @ExceptionHandler({ - HttpMessageNotReadableException.class, - MethodArgumentNotValidException.class, HandlerMethodValidationException.class, - IllegalArgumentException.class }) - public ResponseEntity handleExceptionCausedByIncorrectRequestBody(final HttpServletRequest request, - final Exception ex) { - logRequest(request, ex); - final ExceptionInfo response = createExceptionInfo(new MessageNotReadableException()); - return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST); - } - - /** - * Method for handling exception of type ConstraintViolationException which - * is thrown in case the request is rejected due to a constraint violation. - * Called by the Spring-Framework for exception handling. - * - * @param request the Http request - * @param ex the exception which occurred - * @return the entity to be responded containing the exception information - * as entity. - */ - @ExceptionHandler(ConstraintViolationException.class) - public ResponseEntity handleConstraintViolationException(final HttpServletRequest request, - final ConstraintViolationException ex) { - logRequest(request, ex); - - final ExceptionInfo response = new ExceptionInfo(); - response.setMessage(ex.getConstraintViolations().stream().map( - violation -> violation.getPropertyPath() + MESSAGE_FORMATTER_SEPARATOR + violation.getMessage() + ".") - .collect(Collectors.joining(MESSAGE_FORMATTER_SEPARATOR))); - response.setExceptionClass(ex.getClass().getName()); - response.setErrorCode(SpServerError.SP_REPO_CONSTRAINT_VIOLATION.getKey()); - - return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST); - } - - /** - * Method for handling exception of type ValidationException which is thrown - * in case the request is rejected due to invalid requests. Called by the - * Spring-Framework for exception handling. - * - * @param request the Http request - * @param ex the exception which occurred - * @return the entity to be responded containing the exception information - * as entity. - */ - @ExceptionHandler(ValidationException.class) - public ResponseEntity handleValidationException(final HttpServletRequest request, - final ValidationException ex) { - logRequest(request, ex); - - final ExceptionInfo response = new ExceptionInfo(); - response.setMessage(ex.getMessage()); - response.setExceptionClass(ex.getClass().getName()); - response.setErrorCode(SpServerError.SP_REPO_CONSTRAINT_VIOLATION.getKey()); - - return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST); - } - - /** - * Method for handling exception of type {@link MultipartException} which is - * thrown in case the request body is not well formed and cannot be - * deserialized. Called by the Spring-Framework for exception handling. - * - * @param request the Http request - * @param ex the exception which occurred - * @return the entity to be responded containing the exception information - * as entity. - */ - @ExceptionHandler(MultipartException.class) - public ResponseEntity handleMultipartException(final HttpServletRequest request, - final Exception ex) { - - logRequest(request, ex); - - final List throwables = ExceptionUtils.getThrowableList(ex); - final Throwable responseCause = throwables.get(throwables.size() - 1); - - if (ObjectUtils.isEmpty(responseCause.getMessage())) { - log.warn("Request {} lead to MultipartException without root cause message:\n{}", request.getRequestURL(), - ex.getStackTrace()); - } - - final ExceptionInfo response = createExceptionInfo(new MultiPartFileUploadException(responseCause)); - 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) { - log.debug("Handling exception {} of request {}", ex.getClass().getName(), request.getRequestURL()); - } - - private ExceptionInfo createExceptionInfo(final Exception ex) { - final ExceptionInfo response = new ExceptionInfo(); - response.setMessage(ex.getMessage()); - response.setExceptionClass(ex.getClass().getName()); - if (ex instanceof AbstractServerRtException) { - response.setErrorCode(((AbstractServerRtException) ex).getError().getKey()); - response.setInfo(((AbstractServerRtException) ex).getInfo()); - } - return response; - } -} \ No newline at end of file diff --git a/hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/filter/ExcludePathAwareShallowETagFilter.java b/hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/filter/ExcludePathAwareShallowETagFilter.java deleted file mode 100644 index 45fdcaf917..0000000000 --- a/hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/filter/ExcludePathAwareShallowETagFilter.java +++ /dev/null @@ -1,60 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.eclipse.hawkbit.rest.filter; - -import java.io.IOException; - -import jakarta.servlet.FilterChain; -import jakarta.servlet.ServletException; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; - -import org.springframework.util.AntPathMatcher; -import org.springframework.web.filter.ShallowEtagHeaderFilter; - -/** - * An {@link ShallowEtagHeaderFilter} with exclusion paths to exclude some paths - * where no ETag header should be generated due that calculating the ETag is an - * expensive operation and the response output need to be copied in memory which - * should be excluded in case of artifact downloads which could be big of size. - */ -public class ExcludePathAwareShallowETagFilter extends ShallowEtagHeaderFilter { - - private final String[] excludeAntPaths; - private final AntPathMatcher antMatcher = new AntPathMatcher(); - - /** - * @param excludeAntPaths - */ - public ExcludePathAwareShallowETagFilter(final String... excludeAntPaths) { - this.excludeAntPaths = excludeAntPaths; - } - - @Override - protected void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response, - final FilterChain filterChain) throws ServletException, IOException { - final boolean shouldExclude = shouldExclude(request); - if (shouldExclude) { - filterChain.doFilter(request, response); - } else { - super.doFilterInternal(request, response, filterChain); - } - } - - private boolean shouldExclude(final HttpServletRequest request) { - for (final String pattern : excludeAntPaths) { - if (antMatcher.match(request.getContextPath() + pattern, request.getRequestURI())) { - // exclude this request from eTag filter - return true; - } - } - return false; - } -} diff --git a/hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/data/ResponseList.java b/hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/json/model/ResponseList.java similarity index 98% rename from hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/data/ResponseList.java rename to hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/json/model/ResponseList.java index cfbd977cf0..ee5632450e 100644 --- a/hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/data/ResponseList.java +++ b/hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/json/model/ResponseList.java @@ -7,7 +7,7 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.eclipse.hawkbit.rest.data; +package org.eclipse.hawkbit.rest.json.model; import java.util.Collection; import java.util.Iterator; diff --git a/hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/util/FileStreamingFailedException.java b/hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/util/FileStreamingFailedException.java index 3b35da1105..2ac0ed861a 100644 --- a/hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/util/FileStreamingFailedException.java +++ b/hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/util/FileStreamingFailedException.java @@ -9,6 +9,8 @@ */ package org.eclipse.hawkbit.rest.util; +import java.io.Serial; + import org.eclipse.hawkbit.exception.AbstractServerRtException; import org.eclipse.hawkbit.exception.SpServerError; @@ -17,25 +19,9 @@ */ public final class FileStreamingFailedException extends AbstractServerRtException { + @Serial private static final long serialVersionUID = 1L; - /** - * Creates a new FileUploadFailedException with - * {@link SpServerError#SP_ARTIFACT_LOAD_FAILED} error. - */ - public FileStreamingFailedException() { - super(SpServerError.SP_ARTIFACT_LOAD_FAILED); - } - - /** - * Constructor with Throwable. - * - * @param cause for the exception - */ - public FileStreamingFailedException(final Throwable cause) { - super(SpServerError.SP_ARTIFACT_LOAD_FAILED, cause); - } - /** * Constructor with error string. * @@ -54,4 +40,4 @@ public FileStreamingFailedException(final String message) { public FileStreamingFailedException(final String message, final Throwable cause) { super(message, SpServerError.SP_ARTIFACT_LOAD_FAILED, cause); } -} +} \ No newline at end of file diff --git a/hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/util/FileStreamingProgressListener.java b/hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/util/FileStreamingProgressListener.java deleted file mode 100644 index 331c20e24f..0000000000 --- a/hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/util/FileStreamingProgressListener.java +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.eclipse.hawkbit.rest.util; - -/** - * Listener for progress on artifact file streaming. - */ -@FunctionalInterface -public interface FileStreamingProgressListener { - - /** - * Called multiple times during streaming. - * - * @param requestedBytes requested bytes of the request - * @param shippedBytesSinceLast since the last report - * @param shippedBytesOverall during the request - */ - void progress(long requestedBytes, long shippedBytesSinceLast, long shippedBytesOverall); -} diff --git a/hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/util/FileStreamingUtil.java b/hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/util/FileStreamingUtil.java index 9642a2145a..ac143d8277 100644 --- a/hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/util/FileStreamingUtil.java +++ b/hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/util/FileStreamingUtil.java @@ -443,4 +443,19 @@ private long getTotal() { } + /** + * Listener for progress on artifact file streaming. + */ + @FunctionalInterface + public interface FileStreamingProgressListener { + + /** + * Called multiple times during streaming. + * + * @param requestedBytes requested bytes of the request + * @param shippedBytesSinceLast since the last report + * @param shippedBytesOverall during the request + */ + void progress(long requestedBytes, long shippedBytesSinceLast, long shippedBytesOverall); + } } diff --git a/hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/util/HttpUtil.java b/hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/util/HttpUtil.java index e62118f3f0..0799cfeb10 100644 --- a/hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/util/HttpUtil.java +++ b/hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/util/HttpUtil.java @@ -11,15 +11,15 @@ import java.util.Arrays; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + /** * Utility class for the Rest Source API. */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) public final class HttpUtil { - private HttpUtil() { - - } - /** * Checks given CSV string for defined match value or wildcard. * @@ -32,5 +32,4 @@ public static boolean matchesHttpHeader(final String matchHeader, final String t Arrays.sort(matchValues); return Arrays.binarySearch(matchValues, toMatch) > -1 || Arrays.binarySearch(matchValues, "*") > -1; } - -} +} \ No newline at end of file diff --git a/hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/util/SortUtility.java b/hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/util/SortUtility.java deleted file mode 100644 index 41a026c8b7..0000000000 --- a/hawkbit-rest/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/util/SortUtility.java +++ /dev/null @@ -1,114 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others - * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.eclipse.hawkbit.rest.util; - -import java.util.ArrayList; -import java.util.List; -import java.util.StringTokenizer; - -import org.eclipse.hawkbit.repository.RsqlQueryField; -import org.eclipse.hawkbit.rest.exception.SortParameterSyntaxErrorException; -import org.eclipse.hawkbit.rest.exception.SortParameterUnsupportedDirectionException; -import org.eclipse.hawkbit.rest.exception.SortParameterUnsupportedFieldException; -import org.springframework.data.domain.Sort.Direction; -import org.springframework.data.domain.Sort.Order; - -/** - * A utility class for parsing query parameters which define the sorting of - * elements. - */ -public final class SortUtility { - - /** - * the delimiter between the field and direction in the sort request. - */ - public static final String DELIMITER_FIELD_DIRECTION = ":"; - - private static final String DELIMITER_SORT_TUPLE = ","; - - /* - * utility constructor private. - */ - private SortUtility() { - } - - /** - * Parses the sort string e.g. given in a REST call based on the definition - * of sorting: http://localhost/entity?s=field1:ASC, field2:DESC The fields - * will be split into the keys of the returned map. The direction of the - * sorting will be mapped into the {@link Direction} enum. - * - * @param enumType the class of the enum which the fields in the sort string - * should be related to. - * @param the type of the enumeration which must be derived from - * {@link RsqlQueryField} - * @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 - * {@link Direction} for them as a tuple. Never {@code null}. In - * case of no sorting parameters an empty map will be returned. - * @throws SortParameterSyntaxErrorException if the sorting query parameter is not well-formed - * @throws SortParameterUnsupportedFieldException if a field name cannot be mapped to the enum type - * @throws SortParameterUnsupportedDirectionException if the given direction is not "ASC" or "DESC" - */ - public static & RsqlQueryField> List parse(final Class enumType, - final String sortString) throws SortParameterSyntaxErrorException { - final List parsedSortings = new ArrayList<>(); - // scan the sort tuples e.g. field:direction - if (sortString != null) { - final StringTokenizer tupleTokenizer = new StringTokenizer(sortString, DELIMITER_SORT_TUPLE); - while (tupleTokenizer.hasMoreTokens()) { - final String sortTuple = tupleTokenizer.nextToken().trim(); - final StringTokenizer fieldDirectionTokenizer = new StringTokenizer(sortTuple, - DELIMITER_FIELD_DIRECTION); - if (fieldDirectionTokenizer.countTokens() == 2) { - final String fieldName = fieldDirectionTokenizer.nextToken().trim().toUpperCase(); - final String sortDirectionStr = fieldDirectionTokenizer.nextToken().trim(); - - final T identifier = getAttributeIdentifierByName(enumType, fieldName); - - final Direction sortDirection = getDirection(sortDirectionStr); - parsedSortings.add(new Order(sortDirection, identifier.getJpaEntityFieldName())); - } else { - throw new SortParameterSyntaxErrorException(); - } - } - } - return parsedSortings; - } - - /** - * Returns the attribute identifier for the given name. - * - * @param enumType the class of the enum which the fields in the sort string - * should be related to. - * @param name the name of the enum - * @param the type of the enumeration which must be derived from - * {@link RsqlQueryField} - * @return the corresponding enum - * @throws SortParameterUnsupportedFieldException if there is no matching enum for the specified name - */ - private static & RsqlQueryField> T getAttributeIdentifierByName(final Class enumType, - final String name) { - try { - return Enum.valueOf(enumType, name.toUpperCase()); - } catch (final IllegalArgumentException e) { - throw new SortParameterUnsupportedFieldException(e); - } - } - - private static Direction getDirection(final String sortDirectionStr) { - try { - return Direction.fromString(sortDirectionStr); - } catch (final IllegalArgumentException e) { - throw new SortParameterUnsupportedDirectionException(e); - } - } -} diff --git a/hawkbit-rest/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/AbstractRestIntegrationTest.java b/hawkbit-rest/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/AbstractRestIntegrationTest.java index da4b977d90..915f29b343 100644 --- a/hawkbit-rest/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/AbstractRestIntegrationTest.java +++ b/hawkbit-rest/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/AbstractRestIntegrationTest.java @@ -12,7 +12,6 @@ import org.eclipse.hawkbit.repository.jpa.RepositoryApplicationConfiguration; import org.eclipse.hawkbit.repository.test.TestConfiguration; import org.eclipse.hawkbit.repository.test.util.AbstractIntegrationTest; -import org.eclipse.hawkbit.rest.filter.ExcludePathAwareShallowETagFilter; import org.junit.jupiter.api.BeforeEach; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; @@ -55,7 +54,7 @@ protected DefaultMockMvcBuilder createMvcWebAppContext(final WebApplicationConte // CharacterEncodingFilter is needed for the encoding properties to be imported properly createMvcWebAppContext.addFilter(characterEncodingFilter); createMvcWebAppContext.addFilter( - new ExcludePathAwareShallowETagFilter("/rest/v1/softwaremodules/{smId}/artifacts/{artId}/download", + new RestConfiguration.ExcludePathAwareShallowETagFilter("/rest/v1/softwaremodules/{smId}/artifacts/{artId}/download", "/{tenant}/controller/v1/{controllerId}/softwaremodules/{softwareModuleId}/artifacts/**", "/api/v1/downloadserver/**")); diff --git a/hawkbit-rest/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/filter/ExcludePathAwareShallowETagFilterTest.java b/hawkbit-rest/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/ExcludePathAwareShallowETagFilterTest.java similarity index 91% rename from hawkbit-rest/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/filter/ExcludePathAwareShallowETagFilterTest.java rename to hawkbit-rest/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/ExcludePathAwareShallowETagFilterTest.java index 4771022ead..15d9459804 100644 --- a/hawkbit-rest/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/filter/ExcludePathAwareShallowETagFilterTest.java +++ b/hawkbit-rest/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/ExcludePathAwareShallowETagFilterTest.java @@ -7,7 +7,7 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.eclipse.hawkbit.rest.filter; +package org.eclipse.hawkbit.rest; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mockingDetails; @@ -55,7 +55,7 @@ public void excludePathDoesNotCalculateETag() throws ServletException, IOExcepti when(servletRequestMock.getContextPath()).thenReturn(knownContextPath); when(servletRequestMock.getRequestURI()).thenReturn(knownUri); - final ExcludePathAwareShallowETagFilter filterUnderTest = new ExcludePathAwareShallowETagFilter( + final RestConfiguration.ExcludePathAwareShallowETagFilter filterUnderTest = new RestConfiguration.ExcludePathAwareShallowETagFilter( antPathExclusion); filterUnderTest.doFilterInternal(servletRequestMock, servletResponseMock, filterChainMock); @@ -77,7 +77,7 @@ public void pathNotExcludedETagIsCalculated() throws ServletException, IOExcepti when(servletRequestMock.getContextPath()).thenReturn(knownContextPath); when(servletRequestMock.getRequestURI()).thenReturn(knownUri); - final ExcludePathAwareShallowETagFilter filterUnderTest = new ExcludePathAwareShallowETagFilter( + final RestConfiguration.ExcludePathAwareShallowETagFilter filterUnderTest = new RestConfiguration.ExcludePathAwareShallowETagFilter( antPathExclusion); final ArgumentCaptor responseArgumentCaptor = ArgumentCaptor