From bdcb361ae5e28daa3c827e2744d7e0d5f6f1c5a1 Mon Sep 17 00:00:00 2001 From: Sebastian Firsching Date: Tue, 20 Jun 2023 12:42:50 +0200 Subject: [PATCH] Introduce useArtifactUrlHandler parameter Signed-off-by: Sebastian Firsching --- .../hawkbit/mgmt/rest/api/MgmtRestConstants.java | 4 ++-- .../mgmt/rest/api/MgmtSoftwareModuleRestApi.java | 4 ++-- .../rest/resource/MgmtSoftwareModuleResource.java | 14 +++++++------- .../resource/MgmtSoftwareModuleResourceTest.java | 6 +++++- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/hawkbit-rest/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtRestConstants.java b/hawkbit-rest/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtRestConstants.java index 83b26e132..8d9e0cdd3 100644 --- a/hawkbit-rest/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtRestConstants.java +++ b/hawkbit-rest/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtRestConstants.java @@ -272,9 +272,9 @@ public final class MgmtRestConstants { public static final String AUTH_V1_REQUEST_MAPPING = BASE_V1_REQUEST_MAPPING + "/userinfo"; /** - * The artifact download URL type + * Request parameter if the artifact url handler should be used */ - public static final String ARTIFACT_DOWNLOAD_URL_TYPE = "downloadurltype"; + public static final String REQUEST_PARAMETER_USE_ARTIFACT_URL_HANDLER = "useartifacturlhandler"; // constant class, private constructor. diff --git a/hawkbit-rest/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtSoftwareModuleRestApi.java b/hawkbit-rest/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtSoftwareModuleRestApi.java index efc1f280d..2055b07ef 100644 --- a/hawkbit-rest/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtSoftwareModuleRestApi.java +++ b/hawkbit-rest/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtSoftwareModuleRestApi.java @@ -52,7 +52,7 @@ public interface MgmtSoftwareModuleRestApi { * checksum for uploaded content check * @param sha256Sum * checksum for uploaded content check - * + * * @return In case all sets could successful be created the ResponseEntity * with status code 201 - Created but without ResponseBody. In any * failure the JsonResponseExceptionHandler is handling the @@ -101,7 +101,7 @@ public interface MgmtSoftwareModuleRestApi { @ResponseBody ResponseEntity getArtifact( @PathVariable("softwareModuleId") final Long softwareModuleId, @PathVariable("artifactId") final Long artifactId, - @RequestParam(value = MgmtRestConstants.ARTIFACT_DOWNLOAD_URL_TYPE, required = false) final String artifactDownloadUrlType); + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_USE_ARTIFACT_URL_HANDLER, required = false) final Boolean useArtifactUrlHandler); /** * Handles the DELETE request for a single SoftwareModule. 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 55200ee23..6b8be1b4e 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 @@ -15,6 +15,8 @@ import java.util.Collection; import java.util.List; import java.util.Optional; +import javax.validation.ValidationException; + import org.eclipse.hawkbit.api.ArtifactUrlHandler; import org.eclipse.hawkbit.mgmt.json.model.PagedList; import org.eclipse.hawkbit.mgmt.json.model.artifact.MgmtArtifact; @@ -53,8 +55,6 @@ import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; -import javax.validation.ValidationException; - /** * REST Resource handling for {@link SoftwareModule} and related * {@link Artifact} CRUD operations. @@ -136,16 +136,16 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi { @SuppressWarnings("squid:S3655") public ResponseEntity getArtifact(@PathVariable("softwareModuleId") final Long softwareModuleId, @PathVariable("artifactId") final Long artifactId, - @RequestParam(value = MgmtRestConstants.ARTIFACT_DOWNLOAD_URL_TYPE, required = false) final String artifactDownloadUrlType) { + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_USE_ARTIFACT_URL_HANDLER, required = false) final Boolean useArtifactUrlHandler) { final SoftwareModule module = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, artifactId); final MgmtArtifact response = MgmtSoftwareModuleMapper.toResponse(module.getArtifact(artifactId).get()); if (!module.isDeleted()) { - if(artifactDownloadUrlType == null || artifactDownloadUrlType == "default") { - MgmtSoftwareModuleMapper.addLinks(module.getArtifact(artifactId).get(), response); - } else { + if(useArtifactUrlHandler != null && useArtifactUrlHandler) { MgmtSoftwareModuleMapper.addLinks(module.getArtifact(artifactId).get(), response, artifactUrlHandler, systemManagement); + } else { + MgmtSoftwareModuleMapper.addLinks(module.getArtifact(artifactId).get(), response); } } @@ -208,7 +208,7 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi { LOG.debug("creating {} softwareModules", softwareModules.size()); - for (MgmtSoftwareModuleRequestBodyPost sm : softwareModules) { + for (final MgmtSoftwareModuleRequestBodyPost sm : softwareModules) { final Optional opt = softwareModuleTypeManagement.getByKey(sm.getType()); opt.ifPresent(smType -> { if (smType.isDeleted()) { 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 fefcdc9b5..67889db61 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 @@ -604,8 +604,12 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes final Artifact artifact = artifactManagement.create( new ArtifactUpload(new ByteArrayInputStream(random), sm.getId(), "file1", false, artifactSize)); + final MvcResult result = mvc.perform(get("/rest/v1/softwaremodules/{smId}/artifacts/{artId}?downloadurltype=cdn", sm.getId(), artifact.getId()).accept( + MediaType.APPLICATION_JSON)) + .andDo(MockMvcResultPrinter.print()).andReturn(); + // perform test - mvc.perform(get("/rest/v1/softwaremodules/{smId}/artifacts/{artId}?downloadurltype=cdn", sm.getId(), artifact.getId()).accept( + mvc.perform(get("/rest/v1/softwaremodules/{smId}/artifacts/{artId}?useartifacturlhandler=true", sm.getId(), artifact.getId()).accept( MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()) .andExpect(status().isOk())