Introduce useArtifactUrlHandler parameter
Signed-off-by: Sebastian Firsching <sebastian.firsching@bosch-si.com>
This commit is contained in:
@@ -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.
|
||||||
|
|||||||
@@ -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.
|
||||||
|
|||||||
@@ -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()) {
|
||||||
|
|||||||
@@ -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())
|
||||||
|
|||||||
Reference in New Issue
Block a user