Remove some of the field injections (Sonar recomendtion) (#2218)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2025-01-23 09:52:29 +02:00
committed by GitHub
parent 4909a65d8c
commit bb9c9bfad8
26 changed files with 294 additions and 297 deletions

View File

@@ -15,25 +15,23 @@ import java.util.Map;
import java.util.Optional;
import java.util.Set;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.eclipse.hawkbit.repository.exception.ArtifactEncryptionUnsupportedException;
import org.springframework.beans.factory.annotation.Autowired;
/**
* Service responsible for encryption operations.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
@SuppressWarnings("java:S6548") // singleton holder ensures static access to spring resources in some places
public final class ArtifactEncryptionService {
private static final ArtifactEncryptionService SINGLETON = new ArtifactEncryptionService();
@Autowired(required = false)
private ArtifactEncryption artifactEncryption;
@Autowired(required = false)
private ArtifactEncryptionSecretsStore artifactEncryptionSecretsStore;
private ArtifactEncryptionService() {
}
/**
* @return the artifact encryption service singleton instance
*/
@@ -41,6 +39,16 @@ public final class ArtifactEncryptionService {
return SINGLETON;
}
@Autowired(required = false) // spring setter injection
public void setArtifactEncryption(final ArtifactEncryption artifactEncryption) {
this.artifactEncryption = artifactEncryption;
}
@Autowired(required = false) // spring setter injection
public void setArtifactEncryptionSecretsStore(final ArtifactEncryptionSecretsStore artifactEncryptionSecretsStore) {
this.artifactEncryptionSecretsStore = artifactEncryptionSecretsStore;
}
/**
* Checks if required encryption and secrets store beans are present.
*
@@ -51,8 +59,7 @@ public final class ArtifactEncryptionService {
}
/**
* Generates encryption secrets and saves them in secret store by software
* module id reference.
* Generates encryption secrets and saves them in secret store by software module id reference.
*
* @param smId software module id
*/
@@ -116,7 +123,6 @@ public final class ArtifactEncryptionService {
requiredSecretsKey);
requiredSecretsValue.ifPresent(secretValue -> requiredSecrets.put(requiredSecretsKey, secretValue));
}
return requiredSecrets;
}
}
}

View File

@@ -17,11 +17,11 @@ import org.springframework.beans.factory.annotation.Autowired;
* A singleton bean which holds the event entity manager to have autowiring in the events.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
@SuppressWarnings("java:S6548") // java:S6548 - singleton holder ensures static access to spring resources in some places
public final class EventEntityManagerHolder {
private static final EventEntityManagerHolder SINGLETON = new EventEntityManagerHolder();
@Autowired
private EventEntityManager eventEntityManager;
/**
@@ -31,6 +31,11 @@ public final class EventEntityManagerHolder {
return SINGLETON;
}
@Autowired // spring setter injection
public void setEventEntityManager(final EventEntityManager eventEntityManager) {
this.eventEntityManager = eventEntityManager;
}
/**
* @return the eventEntityManager
*/

View File

@@ -20,6 +20,7 @@ import org.springframework.beans.factory.annotation.Value;
*/
@NoArgsConstructor(access = lombok.AccessLevel.PRIVATE)
@Getter
@SuppressWarnings("java:S6548") // singleton holder ensures static access to spring resources in some places
public final class RsqlConfigHolder {
private static final RsqlConfigHolder SINGLETON = new RsqlConfigHolder();