Fix error for downloading soft deleted artifact binary (#1102)
* download soft deleted artifact throws binary gone exception Signed-off-by: Stefan Klotz <stefan.klotz@bosch.io> * add test and update documentation Signed-off-by: Stefan Klotz <stefan.klotz@bosch.io> * fix javadoc Signed-off-by: Stefan Klotz <stefan.klotz@bosch.io> * test soft deleted artifact has no download link Signed-off-by: Stefan Klotz <stefan.klotz@bosch.io>
This commit is contained in:
@@ -16,6 +16,7 @@ import org.eclipse.hawkbit.artifact.repository.model.AbstractDbArtifact;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtDownloadArtifactRestApi;
|
||||
import org.eclipse.hawkbit.repository.ArtifactManagement;
|
||||
import org.eclipse.hawkbit.repository.SoftwareModuleManagement;
|
||||
import org.eclipse.hawkbit.repository.exception.ArtifactBinaryNoLongerExistsException;
|
||||
import org.eclipse.hawkbit.repository.exception.ArtifactBinaryNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.model.Artifact;
|
||||
@@ -63,6 +64,9 @@ public class MgmtDownloadArtifactResource implements MgmtDownloadArtifactRestApi
|
||||
|
||||
final SoftwareModule module = softwareModuleManagement.get(softwareModuleId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(SoftwareModule.class, softwareModuleId));
|
||||
if (module.isDeleted()) {
|
||||
throw new ArtifactBinaryNoLongerExistsException();
|
||||
}
|
||||
final Artifact artifact = module.getArtifact(artifactId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(Artifact.class, artifactId));
|
||||
|
||||
|
||||
@@ -117,11 +117,12 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
|
||||
@SuppressWarnings("squid:S3655")
|
||||
public ResponseEntity<MgmtArtifact> getArtifact(@PathVariable("softwareModuleId") final Long softwareModuleId,
|
||||
@PathVariable("artifactId") final Long artifactId) {
|
||||
|
||||
final SoftwareModule module = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, artifactId);
|
||||
|
||||
final MgmtArtifact reponse = MgmtSoftwareModuleMapper.toResponse(module.getArtifact(artifactId).get());
|
||||
MgmtSoftwareModuleMapper.addLinks(module.getArtifact(artifactId).get(), reponse);
|
||||
if (!module.isDeleted()) {
|
||||
MgmtSoftwareModuleMapper.addLinks(module.getArtifact(artifactId).get(), reponse);
|
||||
}
|
||||
|
||||
return ResponseEntity.ok(reponse);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user