Skip to content

Commit

Permalink
Fix sonar finding for string duplications
Browse files Browse the repository at this point in the history
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
  • Loading branch information
avgustinmm committed Nov 13, 2024
1 parent ca59da8 commit 72ed066
Showing 1 changed file with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import java.io.IOException;
import java.io.InputStream;
import java.util.Objects;
import java.util.Optional;

import jakarta.annotation.Nullable;
Expand Down Expand Up @@ -105,9 +104,7 @@ public long count() {
@Retryable(include = {
ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY))
public Artifact create(final ArtifactUpload artifactUpload) {
if (artifactRepository == null) {
throw new UnsupportedOperationException("ArtifactRepository is unavailable");
}
assertArtifactRepositoryAvailable();

final long moduleId = artifactUpload.getModuleId();
assertArtifactQuota(moduleId, 1);
Expand Down Expand Up @@ -198,9 +195,7 @@ public long countBySoftwareModule(final long softwareModuleId) {

@Override
public Optional<DbArtifact> loadArtifactBinary(final String sha1Hash, final long softwareModuleId, final boolean isEncrypted) {
if (artifactRepository == null) {
throw new UnsupportedOperationException("ArtifactRepository is unavailable");
}
assertArtifactRepositoryAvailable();

assertSoftwareModuleExists(softwareModuleId);

Expand Down Expand Up @@ -230,9 +225,7 @@ public Optional<DbArtifact> loadArtifactBinary(final String sha1Hash, final long
*/
@PreAuthorize(SpPermission.SpringEvalExpressions.HAS_AUTH_DELETE_REPOSITORY)
void clearArtifactBinary(final String sha1Hash) {
if (artifactRepository == null) {
throw new UnsupportedOperationException("ArtifactRepository is unavailable");
}
assertArtifactRepositoryAvailable();

// countBySha1HashAndTenantAndSoftwareModuleDeletedIsFalse will skip ACM checks and
// will return total count as it should be
Expand Down Expand Up @@ -339,4 +332,10 @@ private void assertSoftwareModuleExists(final long softwareModuleId) {
throw new EntityNotFoundException(SoftwareModule.class, softwareModuleId);
}
}

private void assertArtifactRepositoryAvailable() {
if (artifactRepository == null) {
throw new UnsupportedOperationException("ArtifactRepository is unavailable");
}
}
}

0 comments on commit 72ed066

Please sign in to comment.