Introduce useArtifactUrlHandler parameter

Signed-off-by: Sebastian Firsching <sebastian.firsching@bosch-si.com>
This commit is contained in:
Sebastian Firsching
2023-06-20 12:42:50 +02:00
parent 41922bfa0c
commit bdcb361ae5
4 changed files with 16 additions and 12 deletions

View File

@@ -272,9 +272,9 @@ public final class MgmtRestConstants {
public static final String AUTH_V1_REQUEST_MAPPING = BASE_V1_REQUEST_MAPPING + "/userinfo"; 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. // constant class, private constructor.

View File

@@ -52,7 +52,7 @@ public interface MgmtSoftwareModuleRestApi {
* checksum for uploaded content check * checksum for uploaded content check
* @param sha256Sum * @param sha256Sum
* checksum for uploaded content check * checksum for uploaded content check
* *
* @return In case all sets could successful be created the ResponseEntity * @return In case all sets could successful be created the ResponseEntity
* with status code 201 - Created but without ResponseBody. In any * with status code 201 - Created but without ResponseBody. In any
* failure the JsonResponseExceptionHandler is handling the * failure the JsonResponseExceptionHandler is handling the
@@ -101,7 +101,7 @@ public interface MgmtSoftwareModuleRestApi {
@ResponseBody ResponseEntity<MgmtArtifact> getArtifact( @ResponseBody ResponseEntity<MgmtArtifact> getArtifact(
@PathVariable("softwareModuleId") final Long softwareModuleId, @PathVariable("softwareModuleId") final Long softwareModuleId,
@PathVariable("artifactId") final Long artifactId, @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. * Handles the DELETE request for a single SoftwareModule.

View File

@@ -15,6 +15,8 @@ import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import javax.validation.ValidationException;
import org.eclipse.hawkbit.api.ArtifactUrlHandler; import org.eclipse.hawkbit.api.ArtifactUrlHandler;
import org.eclipse.hawkbit.mgmt.json.model.PagedList; import org.eclipse.hawkbit.mgmt.json.model.PagedList;
import org.eclipse.hawkbit.mgmt.json.model.artifact.MgmtArtifact; 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.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.validation.ValidationException;
/** /**
* REST Resource handling for {@link SoftwareModule} and related * REST Resource handling for {@link SoftwareModule} and related
* {@link Artifact} CRUD operations. * {@link Artifact} CRUD operations.
@@ -136,16 +136,16 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
@SuppressWarnings("squid:S3655") @SuppressWarnings("squid:S3655")
public ResponseEntity<MgmtArtifact> getArtifact(@PathVariable("softwareModuleId") final Long softwareModuleId, public ResponseEntity<MgmtArtifact> getArtifact(@PathVariable("softwareModuleId") final Long softwareModuleId,
@PathVariable("artifactId") final Long artifactId, @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 SoftwareModule module = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, artifactId);
final MgmtArtifact response = MgmtSoftwareModuleMapper.toResponse(module.getArtifact(artifactId).get()); final MgmtArtifact response = MgmtSoftwareModuleMapper.toResponse(module.getArtifact(artifactId).get());
if (!module.isDeleted()) { if (!module.isDeleted()) {
if(artifactDownloadUrlType == null || artifactDownloadUrlType == "default") { if(useArtifactUrlHandler != null && useArtifactUrlHandler) {
MgmtSoftwareModuleMapper.addLinks(module.getArtifact(artifactId).get(), response);
} else {
MgmtSoftwareModuleMapper.addLinks(module.getArtifact(artifactId).get(), response, artifactUrlHandler, MgmtSoftwareModuleMapper.addLinks(module.getArtifact(artifactId).get(), response, artifactUrlHandler,
systemManagement); systemManagement);
} else {
MgmtSoftwareModuleMapper.addLinks(module.getArtifact(artifactId).get(), response);
} }
} }
@@ -208,7 +208,7 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
LOG.debug("creating {} softwareModules", softwareModules.size()); LOG.debug("creating {} softwareModules", softwareModules.size());
for (MgmtSoftwareModuleRequestBodyPost sm : softwareModules) { for (final MgmtSoftwareModuleRequestBodyPost sm : softwareModules) {
final Optional<SoftwareModuleType> opt = softwareModuleTypeManagement.getByKey(sm.getType()); final Optional<SoftwareModuleType> opt = softwareModuleTypeManagement.getByKey(sm.getType());
opt.ifPresent(smType -> { opt.ifPresent(smType -> {
if (smType.isDeleted()) { if (smType.isDeleted()) {

View File

@@ -604,8 +604,12 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
final Artifact artifact = artifactManagement.create( final Artifact artifact = artifactManagement.create(
new ArtifactUpload(new ByteArrayInputStream(random), sm.getId(), "file1", false, artifactSize)); 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 // 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)) MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()) .andExpect(status().isOk())