Fix upload artifact (#852)
* fixed repository to check for file existence before trying to get the artifact * added additional existence checks before retrieving the artifact from repository Signed-off-by: Bogdan Bondar <Bogdan.Bondar@bosch-si.com>
This commit is contained in:
committed by
Jeroen Laverman
parent
34fc7a7012
commit
568848bb27
@@ -108,20 +108,20 @@ public class JpaArtifactManagement implements ArtifactManagement {
|
||||
assertMaxArtifactSizeQuota(filename, moduleId, artifactUpload.getFilesize());
|
||||
assertMaxArtifactStorageQuota(filename, artifactUpload.getFilesize());
|
||||
|
||||
return getOrCreateArtifact(artifactUpload)
|
||||
.map(artifact -> storeArtifactMetadata(softwareModule, filename, artifact, existing))
|
||||
.orElse(null);
|
||||
return getOrCreateArtifact(artifactUpload)
|
||||
.map(artifact -> storeArtifactMetadata(softwareModule, filename, artifact, existing)).orElse(null);
|
||||
}
|
||||
|
||||
private Optional<AbstractDbArtifact> getOrCreateArtifact(final ArtifactUpload artifactUpload) {
|
||||
final String providedSha1Sum = artifactUpload.getProvidedSha1Sum();
|
||||
AbstractDbArtifact artifact = null;
|
||||
|
||||
if (!StringUtils.isEmpty(providedSha1Sum)) {
|
||||
artifact = artifactRepository.getArtifactBySha1(tenantAware.getCurrentTenant(), providedSha1Sum);
|
||||
if (!StringUtils.isEmpty(providedSha1Sum)
|
||||
&& artifactRepository.existsByTenantAndSha1(tenantAware.getCurrentTenant(), providedSha1Sum)) {
|
||||
return Optional
|
||||
.ofNullable(artifactRepository.getArtifactBySha1(tenantAware.getCurrentTenant(), providedSha1Sum));
|
||||
}
|
||||
artifact = (artifact == null) ? storeArtifact(artifactUpload) : artifact;
|
||||
return Optional.ofNullable(artifact);
|
||||
|
||||
return Optional.of(storeArtifact(artifactUpload));
|
||||
}
|
||||
|
||||
private AbstractDbArtifact storeArtifact(final ArtifactUpload artifactUpload) {
|
||||
@@ -244,7 +244,9 @@ public class JpaArtifactManagement implements ArtifactManagement {
|
||||
|
||||
@Override
|
||||
public Optional<AbstractDbArtifact> loadArtifactBinary(final String sha1Hash) {
|
||||
return Optional.ofNullable(artifactRepository.getArtifactBySha1(tenantAware.getCurrentTenant(), sha1Hash));
|
||||
return Optional.ofNullable(artifactRepository.existsByTenantAndSha1(tenantAware.getCurrentTenant(), sha1Hash)
|
||||
? artifactRepository.getArtifactBySha1(tenantAware.getCurrentTenant(), sha1Hash)
|
||||
: null);
|
||||
}
|
||||
|
||||
private Artifact storeArtifactMetadata(final SoftwareModule softwareModule, final String providedFilename,
|
||||
|
||||
@@ -64,7 +64,9 @@ public class MgmtDownloadResource implements MgmtDownloadRestApi {
|
||||
AbstractDbArtifact artifact = null;
|
||||
|
||||
if (DownloadType.BY_SHA1 == artifactCache.getDownloadType()) {
|
||||
artifact = artifactRepository.getArtifactBySha1(tenant, artifactCache.getId());
|
||||
artifact = artifactRepository.existsByTenantAndSha1(tenant, artifactCache.getId())
|
||||
? artifactRepository.getArtifactBySha1(tenant, artifactCache.getId())
|
||||
: null;
|
||||
} else {
|
||||
LOGGER.warn("Download Type {} not supported", artifactCache.getDownloadType());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user