From bb9c9bfad8953196e2fa1f786163f2fc40ceb579 Mon Sep 17 00:00:00 2001 From: Avgustin Marinov Date: Thu, 23 Jan 2025 09:52:29 +0200 Subject: [PATCH] Remove some of the field injections (Sonar recomendtion) (#2218) Signed-off-by: Avgustin Marinov --- .../AbstractArtifactRepository.java | 3 + .../AbstractDDiApiIntegrationTest.java | 6 +- .../hawkbit/amqp/AmqpConfiguration.java | 24 ++- .../amqp/AmqpMessageHandlerService.java | 5 +- .../hawkbit/amqp/BaseAmqpServiceTest.java | 9 +- .../AbstractAmqpServiceIntegrationTest.java | 11 +- .../test/AbstractAmqpIntegrationTest.java | 1 + .../repository/ArtifactEncryptionService.java | 26 ++- .../remote/EventEntityManagerHolder.java | 7 +- .../repository/rsql/RsqlConfigHolder.java | 1 + .../model/helper/EventPublisherHolder.java | 28 ++- .../helper/SystemSecurityContextHolder.java | 15 +- .../TenantConfigurationManagementHolder.java | 16 +- .../AfterTransactionCommitExecutorHolder.java | 17 +- .../model/helper/EntityInterceptorHolder.java | 13 +- .../helper/SecurityTokenGeneratorHolder.java | 24 +-- .../jpa/model/helper/TenantAwareHolder.java | 21 +- .../hawkbit/repository/jpa/Statistics.java | 24 ++- .../hawkbit/repository/jpa/Statistics.java | 29 +-- .../jpa/rsql/AbstractRSQLVisitor.java | 1 + .../specifications/ActionSpecifications.java | 83 +++----- .../ArtifactSpecifications.java | 16 +- .../test/util/SystemManagementHolder.java | 9 +- .../repository/test/util/TestdataFactory.java | 194 +++++++----------- .../eclipse/hawkbit/sdk/dmf/amqp/Amqp.java | 1 + .../eclipse/hawkbit/security/MdcHandler.java | 7 +- 26 files changed, 294 insertions(+), 297 deletions(-) diff --git a/hawkbit-artifact/hawkbit-artifact-api/src/main/java/org/eclipse/hawkbit/artifact/repository/AbstractArtifactRepository.java b/hawkbit-artifact/hawkbit-artifact-api/src/main/java/org/eclipse/hawkbit/artifact/repository/AbstractArtifactRepository.java index 100af94e0..c6e0d8e5a 100644 --- a/hawkbit-artifact/hawkbit-artifact-api/src/main/java/org/eclipse/hawkbit/artifact/repository/AbstractArtifactRepository.java +++ b/hawkbit-artifact/hawkbit-artifact-api/src/main/java/org/eclipse/hawkbit/artifact/repository/AbstractArtifactRepository.java @@ -104,6 +104,9 @@ public abstract class AbstractArtifactRepository implements ArtifactRepository { protected abstract AbstractDbArtifact store(final String tenant, final DbArtifactHash base16Hashes, final String contentType, final String tempFile) throws IOException; + // java:S1066 - more readable with separate "if" statements + // java:S4042 - delete reason is not needed + @SuppressWarnings({ "java:S1066", "java:S4042" }) static File createTempFile(final boolean directory) { try { final File file = (directory diff --git a/hawkbit-ddi/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/AbstractDDiApiIntegrationTest.java b/hawkbit-ddi/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/AbstractDDiApiIntegrationTest.java index 789cc8192..ab427d03c 100644 --- a/hawkbit-ddi/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/AbstractDDiApiIntegrationTest.java +++ b/hawkbit-ddi/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/AbstractDDiApiIntegrationTest.java @@ -130,13 +130,13 @@ public abstract class AbstractDDiApiIntegrationTest extends AbstractRestIntegrat protected ResultActions postDeploymentFeedback(final String controllerId, final Long actionId, final String content, final ResultMatcher statusMatcher) throws Exception { - return postDeploymentFeedback(MediaType.APPLICATION_JSON_UTF8, controllerId, actionId, content.getBytes(), statusMatcher); + return postDeploymentFeedback(MediaType.APPLICATION_JSON, controllerId, actionId, content.getBytes(), statusMatcher); } protected ResultActions putInstalledBase(final String controllerId, final String content, final ResultMatcher statusMatcher) throws Exception { return mvc.perform(put(INSTALLED_BASE_ROOT, tenantAware.getCurrentTenant(), controllerId) - .content(content.getBytes()).contentType(MediaType.APPLICATION_JSON_UTF8)) + .content(content.getBytes()).contentType(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()) .andExpect(statusMatcher); } @@ -154,7 +154,7 @@ public abstract class AbstractDDiApiIntegrationTest extends AbstractRestIntegrat protected ResultActions postCancelFeedback( final String controllerId, final Long actionId, final String content, final ResultMatcher statusMatcher) throws Exception { - return postCancelFeedback(MediaType.APPLICATION_JSON_UTF8, controllerId, actionId, content.getBytes(), statusMatcher); + return postCancelFeedback(MediaType.APPLICATION_JSON, controllerId, actionId, content.getBytes(), statusMatcher); } protected ResultActions postCancelFeedback( diff --git a/hawkbit-dmf/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpConfiguration.java b/hawkbit-dmf/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpConfiguration.java index 7ea938820..bf63e0cb6 100644 --- a/hawkbit-dmf/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpConfiguration.java +++ b/hawkbit-dmf/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpConfiguration.java @@ -60,15 +60,22 @@ import org.springframework.util.ErrorHandler; @PropertySource("classpath:/hawkbit-dmf-defaults.properties") public class AmqpConfiguration { - @Autowired - private AmqpProperties amqpProperties; - @Autowired - private AmqpDeadletterProperties amqpDeadletterProperties; - @Autowired - private ConnectionFactory rabbitConnectionFactory; - @Autowired(required = false) + private final AmqpProperties amqpProperties; + private final AmqpDeadletterProperties amqpDeadletterProperties; + private final ConnectionFactory rabbitConnectionFactory; private ServiceMatcher serviceMatcher; + public AmqpConfiguration(final AmqpProperties amqpProperties, final AmqpDeadletterProperties amqpDeadletterProperties, final ConnectionFactory rabbitConnectionFactory) { + this.amqpProperties = amqpProperties; + this.amqpDeadletterProperties = amqpDeadletterProperties; + this.rabbitConnectionFactory = rabbitConnectionFactory; + } + + @Autowired(required = false) // spring setter injection + public void setServiceMatcher(final ServiceMatcher serviceMatcher) { + this.serviceMatcher = serviceMatcher; + } + /** * Creates a custom error handler bean. * @@ -262,8 +269,7 @@ public class AmqpConfiguration { } /** - * Create RabbitListenerContainerFactory bean if no listenerContainerFactory - * bean found + * Create RabbitListenerContainerFactory bean if no listenerContainerFactory bean found * * @return RabbitListenerContainerFactory bean */ diff --git a/hawkbit-dmf/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java b/hawkbit-dmf/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java index 48ec0f589..1af27e960 100644 --- a/hawkbit-dmf/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java +++ b/hawkbit-dmf/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java @@ -215,8 +215,7 @@ public class AmqpMessageHandlerService extends BaseAmqpService { return StringUtils.hasLength(message.getMessageProperties().getCorrelationId()); } - // Exception squid:MethodCyclomaticComplexity - false positive, is a simple mapping - @SuppressWarnings("squid:MethodCyclomaticComplexity") + @SuppressWarnings("java:S2637" ) // java:S2637 - logAndThrowMessageError throws exception, i.e. doesn't return null private static @NotNull Status mapStatus(final Message message, final DmfActionUpdateStatus actionUpdateStatus, final Action action) { Status status = null; switch (actionUpdateStatus.getActionStatus()) { @@ -261,7 +260,7 @@ public class AmqpMessageHandlerService extends BaseAmqpService { break; } default: { - logAndThrowMessageError(message, "Status for action does not exisit."); + logAndThrowMessageError(message, "Status for action does not exist."); } } diff --git a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/BaseAmqpServiceTest.java b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/BaseAmqpServiceTest.java index 86d14213a..d8b601a50 100644 --- a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/BaseAmqpServiceTest.java +++ b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/BaseAmqpServiceTest.java @@ -53,12 +53,9 @@ class BaseAmqpServiceTest { final DmfActionUpdateStatus actionUpdateStatus = createActionStatus(); when(rabbitTemplate.getMessageConverter()).thenReturn(new Jackson2JsonMessageConverter()); - final Message message = rabbitTemplate.getMessageConverter().toMessage(actionUpdateStatus, - createJsonProperties()); - final DmfActionUpdateStatus convertedActionUpdateStatus = baseAmqpService.convertMessage(message, - DmfActionUpdateStatus.class); - - assertThat(convertedActionUpdateStatus).isEqualToComparingFieldByField(actionUpdateStatus); + final Message message = rabbitTemplate.getMessageConverter().toMessage(actionUpdateStatus, createJsonProperties()); + final DmfActionUpdateStatus convertedActionUpdateStatus = baseAmqpService.convertMessage(message, DmfActionUpdateStatus.class); + assertThat(convertedActionUpdateStatus).usingRecursiveComparison().isEqualTo(actionUpdateStatus); } @Test diff --git a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AbstractAmqpServiceIntegrationTest.java b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AbstractAmqpServiceIntegrationTest.java index 26c796b97..c4eba8be4 100644 --- a/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AbstractAmqpServiceIntegrationTest.java +++ b/hawkbit-dmf/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/integration/AbstractAmqpServiceIntegrationTest.java @@ -398,15 +398,14 @@ abstract class AbstractAmqpServiceIntegrationTest extends AbstractAmqpIntegratio } @Step - protected DistributionSet createTargetAndDistributionSetAndAssign(final String controllerId, - final Action.ActionType actionType) { + protected DistributionSet createTargetAndDistributionSetAndAssign(final String controllerId, final Action.ActionType actionType) { registerAndAssertTargetWithExistingTenant(controllerId); - final DistributionSet distributionSet = testdataFactory.createDistributionSet(UUID.randomUUID().toString()); - testdataFactory.addSoftwareModuleMetadata(distributionSet); + final DistributionSet distributionSetLocal = testdataFactory.createDistributionSet(UUID.randomUUID().toString()); + testdataFactory.addSoftwareModuleMetadata(distributionSetLocal); - assignDistributionSet(distributionSet.getId(), controllerId, actionType); - return distributionSet; + assignDistributionSet(distributionSetLocal.getId(), controllerId, actionType); + return distributionSetLocal; } protected void assertSoftwareModules(final Set expectedSoftwareModules, diff --git a/hawkbit-dmf/hawkbit-dmf-rabbitmq-test/src/main/java/org/eclipse/hawkbit/rabbitmq/test/AbstractAmqpIntegrationTest.java b/hawkbit-dmf/hawkbit-dmf-rabbitmq-test/src/main/java/org/eclipse/hawkbit/rabbitmq/test/AbstractAmqpIntegrationTest.java index 5c1fd682c..6615c9b20 100644 --- a/hawkbit-dmf/hawkbit-dmf-rabbitmq-test/src/main/java/org/eclipse/hawkbit/rabbitmq/test/AbstractAmqpIntegrationTest.java +++ b/hawkbit-dmf/hawkbit-dmf-rabbitmq-test/src/main/java/org/eclipse/hawkbit/rabbitmq/test/AbstractAmqpIntegrationTest.java @@ -40,6 +40,7 @@ import org.springframework.test.context.ContextConfiguration; @Import(TestChannelBinderConfiguration.class) // Dirty context is necessary to create a new vhost and recreate all necessary beans after every test class. @DirtiesContext(classMode = ClassMode.AFTER_CLASS) +@SuppressWarnings("java:S6813") // constructor injects are not possible for test classes public abstract class AbstractAmqpIntegrationTest extends AbstractIntegrationTest { private static final Duration TIMEOUT = Duration.ofSeconds(5); diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ArtifactEncryptionService.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ArtifactEncryptionService.java index 10d3a527a..807d51221 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ArtifactEncryptionService.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ArtifactEncryptionService.java @@ -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; } -} +} \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/EventEntityManagerHolder.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/EventEntityManagerHolder.java index 73baa4dfd..aba4341fa 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/EventEntityManagerHolder.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/EventEntityManagerHolder.java @@ -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 */ diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/rsql/RsqlConfigHolder.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/rsql/RsqlConfigHolder.java index c077b1dc8..6051b011e 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/rsql/RsqlConfigHolder.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/rsql/RsqlConfigHolder.java @@ -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(); diff --git a/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/model/helper/EventPublisherHolder.java b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/model/helper/EventPublisherHolder.java index 937f20923..b7178c365 100644 --- a/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/model/helper/EventPublisherHolder.java +++ b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/model/helper/EventPublisherHolder.java @@ -18,21 +18,18 @@ import org.springframework.cloud.bus.ServiceMatcher; import org.springframework.context.ApplicationEventPublisher; /** - * A singleton bean which holds the event publisher and service origin Id in - * order to publish remote application events. It can be used in beans not - * instantiated by spring e.g. JPA entities which cannot be auto-wired. + * A singleton bean which holds the event publisher and service origin id in order to publish remote application events. + * It can be used in beans not instantiated by spring e.g. JPA entities which cannot be auto-wired. */ @NoArgsConstructor(access = AccessLevel.PRIVATE) +@SuppressWarnings("java:S6548") // java:S6548 - singleton holder ensures static access to spring resources in some places public final class EventPublisherHolder { private static final EventPublisherHolder SINGLETON = new EventPublisherHolder(); @Getter - @Autowired private ApplicationEventPublisher eventPublisher; - @Autowired(required = false) private ServiceMatcher serviceMatcher; - @Autowired private BusProperties bus; /** @@ -42,9 +39,24 @@ public final class EventPublisherHolder { return SINGLETON; } + @Autowired // spring setter injection + public void setApplicationEventPublisher(final ApplicationEventPublisher eventPublisher) { + this.eventPublisher = eventPublisher; + } + + @Autowired(required = false) // spring setter injection + public void setServiceMatcher(final ServiceMatcher serviceMatcher) { + this.serviceMatcher = serviceMatcher; + } + + @Autowired // spring setter injection + public void setBusProperties(final BusProperties bus) { + this.bus = bus; + } + /** - * @return the service origin Id coming either from {@link ServiceMatcher} - * when available or {@link BusProperties} otherwise. + * @return the service origin Id coming either from {@link ServiceMatcher} when available or {@link BusProperties} + * otherwise. */ public String getApplicationId() { String id = null; diff --git a/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/model/helper/SystemSecurityContextHolder.java b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/model/helper/SystemSecurityContextHolder.java index f07e462c3..c4f3700ba 100644 --- a/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/model/helper/SystemSecurityContextHolder.java +++ b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/model/helper/SystemSecurityContextHolder.java @@ -16,22 +16,27 @@ import org.eclipse.hawkbit.security.SystemSecurityContext; import org.springframework.beans.factory.annotation.Autowired; /** - * A singleton bean which holds {@link SystemSecurityContext} service and makes - * it accessible to beans which are not managed by spring, e.g. JPA entities. + * A singleton bean which holds {@link SystemSecurityContext} service and makes it accessible to beans which are not + * managed by spring, e.g. JPA entities. */ @NoArgsConstructor(access = AccessLevel.PRIVATE) +@SuppressWarnings("java:S6548") // java:S6548 - singleton holder ensures static access to spring resources in some places public final class SystemSecurityContextHolder { - private static final SystemSecurityContextHolder INSTANCE = new SystemSecurityContextHolder(); + private static final SystemSecurityContextHolder SINGLETON = new SystemSecurityContextHolder(); @Getter - @Autowired private SystemSecurityContext systemSecurityContext; /** * @return the singleton {@link SystemSecurityContextHolder} instance */ public static SystemSecurityContextHolder getInstance() { - return INSTANCE; + return SINGLETON; + } + + @Autowired // spring setter injection + public void setSystemSecurityContext(final SystemSecurityContext systemSecurityContext) { + this.systemSecurityContext = systemSecurityContext; } } \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/model/helper/TenantConfigurationManagementHolder.java b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/model/helper/TenantConfigurationManagementHolder.java index d4fdf55f4..8c66c9c04 100644 --- a/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/model/helper/TenantConfigurationManagementHolder.java +++ b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/model/helper/TenantConfigurationManagementHolder.java @@ -16,23 +16,27 @@ import org.eclipse.hawkbit.repository.TenantConfigurationManagement; import org.springframework.beans.factory.annotation.Autowired; /** - * A singleton bean which holds {@link TenantConfigurationManagement} service - * and makes it accessible to beans which are not managed by spring, e.g. JPA - * entities. + * A singleton bean which holds {@link TenantConfigurationManagement} service and makes it accessible to beans which are + * not managed by spring, e.g. JPA entities. */ @NoArgsConstructor(access = AccessLevel.PRIVATE) +@SuppressWarnings("java:S6548") // java:S6548 - singleton holder ensures static access to spring resources in some places public final class TenantConfigurationManagementHolder { - private static final TenantConfigurationManagementHolder INSTANCE = new TenantConfigurationManagementHolder(); + private static final TenantConfigurationManagementHolder SINGLETON = new TenantConfigurationManagementHolder(); @Getter - @Autowired private TenantConfigurationManagement tenantConfigurationManagement; /** * @return the singleton {@link TenantConfigurationManagementHolder} instance */ public static TenantConfigurationManagementHolder getInstance() { - return INSTANCE; + return SINGLETON; + } + + @Autowired // spring setter injection + public void setTenantConfigurationManagement(final TenantConfigurationManagement tenantConfigurationManagement) { + this.tenantConfigurationManagement = tenantConfigurationManagement; } } \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-jpa-api/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/AfterTransactionCommitExecutorHolder.java b/hawkbit-repository/hawkbit-repository-jpa-api/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/AfterTransactionCommitExecutorHolder.java index 79878af7a..d02a90c19 100644 --- a/hawkbit-repository/hawkbit-repository-jpa-api/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/AfterTransactionCommitExecutorHolder.java +++ b/hawkbit-repository/hawkbit-repository-jpa-api/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/AfterTransactionCommitExecutorHolder.java @@ -10,6 +10,7 @@ package org.eclipse.hawkbit.repository.jpa.model.helper; import lombok.AccessLevel; +import lombok.Getter; import lombok.NoArgsConstructor; import org.eclipse.hawkbit.repository.jpa.executor.AfterTransactionCommitExecutor; import org.springframework.beans.factory.annotation.Autowired; @@ -19,11 +20,12 @@ import org.springframework.beans.factory.annotation.Autowired; * entities which cannot be autowired. */ @NoArgsConstructor(access = AccessLevel.PRIVATE) +@SuppressWarnings("java:S6548") // java:S6548 - singleton holder ensures static access to spring resources in some places public final class AfterTransactionCommitExecutorHolder { private static final AfterTransactionCommitExecutorHolder SINGLETON = new AfterTransactionCommitExecutorHolder(); - @Autowired + @Getter private AfterTransactionCommitExecutor afterCommit; /** @@ -33,17 +35,8 @@ public final class AfterTransactionCommitExecutorHolder { return SINGLETON; } - /** - * @return the afterCommit - */ - public AfterTransactionCommitExecutor getAfterCommit() { - return afterCommit; - } - - /** - * @param afterCommit the afterCommit to set - */ - public void setAfterCommit(final AfterTransactionCommitExecutor afterCommit) { + @Autowired // spring setter injection + public void setAfterTransactionCommitExecutor(final AfterTransactionCommitExecutor afterCommit) { this.afterCommit = afterCommit; } } \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-jpa-api/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/EntityInterceptorHolder.java b/hawkbit-repository/hawkbit-repository-jpa-api/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/EntityInterceptorHolder.java index 58e570084..6c6a96844 100644 --- a/hawkbit-repository/hawkbit-repository-jpa-api/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/EntityInterceptorHolder.java +++ b/hawkbit-repository/hawkbit-repository-jpa-api/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/EntityInterceptorHolder.java @@ -12,13 +12,16 @@ package org.eclipse.hawkbit.repository.jpa.model.helper; import java.util.ArrayList; import java.util.List; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.eclipse.hawkbit.repository.jpa.EntityInterceptor; import org.springframework.beans.factory.annotation.Autowired; /** - * A singleton bean which holds the {@link EntityInterceptor} to have all - * interceptors in spring beans. + * A singleton bean which holds the {@link EntityInterceptor} to have all interceptors in spring beans. */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@SuppressWarnings("java:S6548") // java:S6548 - singleton holder ensures static access to spring resources in some places public final class EntityInterceptorHolder { private static final EntityInterceptorHolder SINGLETON = new EntityInterceptorHolder(); @@ -26,10 +29,6 @@ public final class EntityInterceptorHolder { @Autowired(required = false) private final List entityInterceptors = new ArrayList<>(); - private EntityInterceptorHolder() { - - } - /** * @return the entity intreceptor holder singleton instance */ @@ -40,4 +39,4 @@ public final class EntityInterceptorHolder { public List getEntityInterceptors() { return entityInterceptors; } -} +} \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-jpa-api/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/SecurityTokenGeneratorHolder.java b/hawkbit-repository/hawkbit-repository-jpa-api/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/SecurityTokenGeneratorHolder.java index 3f9a7803b..5826720cb 100644 --- a/hawkbit-repository/hawkbit-repository-jpa-api/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/SecurityTokenGeneratorHolder.java +++ b/hawkbit-repository/hawkbit-repository-jpa-api/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/SecurityTokenGeneratorHolder.java @@ -9,6 +9,8 @@ */ package org.eclipse.hawkbit.repository.jpa.model.helper; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.eclipse.hawkbit.security.SecurityTokenGenerator; import org.springframework.beans.factory.annotation.Autowired; @@ -16,25 +18,24 @@ import org.springframework.beans.factory.annotation.Autowired; * A singleton bean which holds the {@link SecurityTokenGenerator} and make it * accessible to beans which are not managed by spring, e.g. JPA entities. */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@SuppressWarnings("java:S6548") // java:S6548 - singleton holder ensures static access to spring resources in some places public final class SecurityTokenGeneratorHolder { - private static final SecurityTokenGeneratorHolder INSTANCE = new SecurityTokenGeneratorHolder(); + private static final SecurityTokenGeneratorHolder SINGLETON = new SecurityTokenGeneratorHolder(); - @Autowired private SecurityTokenGenerator securityTokenGenerator; - /** - * private constructor. - */ - private SecurityTokenGeneratorHolder() { - - } - /** * @return a singleton instance of the security token generator holder. */ public static SecurityTokenGeneratorHolder getInstance() { - return INSTANCE; + return SINGLETON; + } + + @Autowired // spring setter injection + public void setSecurityTokenGenerator(final SecurityTokenGenerator securityTokenGenerator) { + this.securityTokenGenerator = securityTokenGenerator; } /** @@ -45,5 +46,4 @@ public final class SecurityTokenGeneratorHolder { public String generateToken() { return securityTokenGenerator.generateToken(); } - -} +} \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-jpa-api/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/TenantAwareHolder.java b/hawkbit-repository/hawkbit-repository-jpa-api/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/TenantAwareHolder.java index 7dc0c5687..980804b54 100644 --- a/hawkbit-repository/hawkbit-repository-jpa-api/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/TenantAwareHolder.java +++ b/hawkbit-repository/hawkbit-repository-jpa-api/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/TenantAwareHolder.java @@ -9,6 +9,10 @@ */ package org.eclipse.hawkbit.repository.jpa.model.helper; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; +import lombok.Setter; +import org.eclipse.hawkbit.repository.SystemManagement; import org.eclipse.hawkbit.tenancy.TenantAware; import org.springframework.beans.factory.annotation.Autowired; @@ -16,21 +20,24 @@ import org.springframework.beans.factory.annotation.Autowired; * A singleton bean which holds {@link TenantAware} service and makes it * accessible to beans which are not managed by spring, e.g. JPA entities. */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@SuppressWarnings("java:S6548") // java:S6548 - singleton holder ensures static access to spring resources in some places public final class TenantAwareHolder { - private static final TenantAwareHolder INSTANCE = new TenantAwareHolder(); + private static final TenantAwareHolder SINGLETON = new TenantAwareHolder(); - @Autowired private TenantAware tenantAware; - private TenantAwareHolder() { - } - /** * @return the singleton {@link TenantAwareHolder} instance */ public static TenantAwareHolder getInstance() { - return INSTANCE; + return SINGLETON; + } + + @Autowired // spring setter injection + public void setTenantAware(final TenantAware tenantAware) { + this.tenantAware = tenantAware; } /** @@ -39,4 +46,4 @@ public final class TenantAwareHolder { public TenantAware getTenantAware() { return tenantAware; } -} +} \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-jpa-eclipselink/src/main/java/org/eclipse/hawkbit/repository/jpa/Statistics.java b/hawkbit-repository/hawkbit-repository-jpa-eclipselink/src/main/java/org/eclipse/hawkbit/repository/jpa/Statistics.java index 7fbbd3c92..3b6cffa88 100644 --- a/hawkbit-repository/hawkbit-repository-jpa-eclipselink/src/main/java/org/eclipse/hawkbit/repository/jpa/Statistics.java +++ b/hawkbit-repository/hawkbit-repository-jpa-eclipselink/src/main/java/org/eclipse/hawkbit/repository/jpa/Statistics.java @@ -21,7 +21,9 @@ import jakarta.persistence.EntityManagerFactory; import io.micrometer.core.instrument.Counter; import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.Timer; +import lombok.AccessLevel; import lombok.Getter; +import lombok.NoArgsConstructor; import org.eclipse.persistence.sessions.Session; import org.eclipse.persistence.tools.profiler.PerformanceMonitor; import org.springframework.beans.factory.annotation.Autowired; @@ -48,11 +50,13 @@ import org.springframework.scheduling.annotation.Scheduled; * * It encapsulates reporting the Eclipselink {@link PerformanceMonitor} statistics to the {@link MeterRegistry} and the Spring autoconfiguration. */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@SuppressWarnings("java:S6548") // java:S6548 - singleton holder ensures static access to spring resources in some places public class Statistics { public static final String METER_PREFIX = "eclipselink."; - private static final Statistics INSTANCE = new Statistics(); + private static final Statistics SINGLETON = new Statistics(); private static final Pattern PATTERN = Pattern.compile("(?(Counter|Timer)+):(?[^ -]+)"); private static final Map REPORTED_TIMER_VALUES = new HashMap<>(); @@ -68,7 +72,7 @@ public class Statistics { * @return the singleton {@link Statistics} instance */ public static Statistics getInstance() { - return INSTANCE; + return SINGLETON; } @Autowired @@ -80,36 +84,36 @@ public class Statistics { getPerformanceMonitor(entityManagerFactory).setDumpTime(dumpPeriod); } - @Autowired + @Autowired // spring setter injection public void setMeterRegistry(final MeterRegistry meterRegistry) { this.meterRegistry = meterRegistry; } // flushes the statistics to the meter registry (if needed) public static void flush() { - final MeterRegistry meterRegistry = INSTANCE.meterRegistry; + final MeterRegistry meterRegistry = SINGLETON.meterRegistry; if (meterRegistry == null) { // not a bean (i.e. no performance monitoring) is enabled or no meter registry available return; } - synchronized (INSTANCE) { - if (INSTANCE.flushing) { + synchronized (SINGLETON) { + if (SINGLETON.flushing) { // wait for flushing do { try { - INSTANCE.wait(1000); + SINGLETON.wait(1000); } catch (final InterruptedException e) { Thread.currentThread().interrupt(); } - } while (INSTANCE.flushing); + } while (SINGLETON.flushing); // flushed return; } // flush - INSTANCE.flushing = true; + SINGLETON.flushing = true; } - INSTANCE.flush0(); + SINGLETON.flush0(); } @Scheduled(initialDelayString = "${hawkbit.jpa.statistics.flush.fixedDelay:60000}", fixedDelayString = "${hawkbit.jpa.statistics.flush.fixedDelay:60000}") diff --git a/hawkbit-repository/hawkbit-repository-jpa-hibernate/src/main/java/org/eclipse/hawkbit/repository/jpa/Statistics.java b/hawkbit-repository/hawkbit-repository-jpa-hibernate/src/main/java/org/eclipse/hawkbit/repository/jpa/Statistics.java index a0f1e06d6..1931e81bb 100644 --- a/hawkbit-repository/hawkbit-repository-jpa-hibernate/src/main/java/org/eclipse/hawkbit/repository/jpa/Statistics.java +++ b/hawkbit-repository/hawkbit-repository-jpa-hibernate/src/main/java/org/eclipse/hawkbit/repository/jpa/Statistics.java @@ -10,7 +10,10 @@ package org.eclipse.hawkbit.repository.jpa; import io.micrometer.core.instrument.MeterRegistry; +import lombok.AccessLevel; import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; @@ -31,11 +34,13 @@ import org.springframework.context.annotation.Configuration; *
  • (?) When using in test the metrics MAYBE shall be enabled with @AutoConfigureObservability(tracing = false)
  • * */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) +@SuppressWarnings("java:S6548") // java:S6548 - singleton holder ensures static access to spring resources in some places public class Statistics { public static final String METER_PREFIX = "hibernate."; - private static final Statistics INSTANCE = new Statistics(); + private static final Statistics SINGLETON = new Statistics(); // if meter registry is unavailable, the statistics will not send to metrics @Getter @@ -45,17 +50,7 @@ public class Statistics { * @return the singleton {@link Statistics} instance */ public static Statistics getInstance() { - return INSTANCE; - } - - @Autowired - public void setMeterRegistry(final MeterRegistry meterRegistry) { - this.meterRegistry = meterRegistry; - } - - // flushes the statistics to the meter registry (if needed) - public static void flush() { - // nothing to do for Hibernate + return SINGLETON; } // autoconfigure after CompositeMeterRegistryAutoConfiguration, so when the autoconfiguration is being processed the MeterRegistry @@ -74,4 +69,14 @@ public class Statistics { return Statistics.getInstance(); } } + + @Autowired // spring setter injection + public void setMeterRegistry(final MeterRegistry meterRegistry) { + this.meterRegistry = meterRegistry; + } + + // flushes the statistics to the meter registry (if needed) + public static void flush() { + // nothing to do for Hibernate + } } \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/AbstractRSQLVisitor.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/AbstractRSQLVisitor.java index d60dd901a..c311d605d 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/AbstractRSQLVisitor.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/AbstractRSQLVisitor.java @@ -31,6 +31,7 @@ public abstract class AbstractRSQLVisitor & RsqlQueryField> { this.rsqlQueryFieldType = rsqlQueryFieldType; } + @SuppressWarnings("java:S1066") // java:S1066 - more readable with separate "if" statements protected QuertPath getQuertPath(final ComparisonNode node) { final int firstSeparatorIndex = node.getSelector().indexOf(RsqlQueryField.SUB_ATTRIBUTE_SEPARATOR); final String enumName = (firstSeparatorIndex == -1 diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/ActionSpecifications.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/ActionSpecifications.java index d72590a20..63c90926b 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/ActionSpecifications.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/ActionSpecifications.java @@ -9,12 +9,13 @@ */ package org.eclipse.hawkbit.repository.jpa.specifications; -import java.util.List; - import jakarta.persistence.criteria.Join; import jakarta.persistence.criteria.ListJoin; import jakarta.persistence.criteria.SetJoin; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; +import org.eclipse.hawkbit.repository.jpa.model.AbstractJpaBaseEntity_; import org.eclipse.hawkbit.repository.jpa.model.JpaAction; import org.eclipse.hawkbit.repository.jpa.model.JpaAction_; import org.eclipse.hawkbit.repository.jpa.model.JpaArtifact; @@ -28,18 +29,14 @@ import org.eclipse.hawkbit.repository.model.Action; import org.springframework.data.jpa.domain.Specification; /** - * Utility class for {@link Action}s {@link Specification}s. The class provides - * Spring Data JPQL Specifications. + * Utility class for {@link Action}s {@link Specification}s. The class provides Spring Data JPQL Specifications. */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) public final class ActionSpecifications { - private ActionSpecifications() { - // utility class - } - public static Specification byTargetIdAndIsActive(final Long targetId) { return (root, query, cb) -> cb.and( - cb.equal(root.get(JpaAction_.target).get(JpaTarget_.id), targetId), + cb.equal(root.get(JpaAction_.target).get(AbstractJpaBaseEntity_.id), targetId), cb.equal(root.get(JpaAction_.active), true)); } @@ -49,7 +46,7 @@ public final class ActionSpecifications { public static Specification byTargetIdAndIsActiveAndStatus(final Long targetId, final Action.Status status) { return (root, query, cb) -> cb.and( - cb.equal(root.get(JpaAction_.target).get(JpaTarget_.id), targetId), + cb.equal(root.get(JpaAction_.target).get(AbstractJpaBaseEntity_.id), targetId), cb.equal(root.get(JpaAction_.active), true), cb.equal(root.get(JpaAction_.status), status)); } @@ -67,15 +64,6 @@ public final class ActionSpecifications { cb.equal(root.get(JpaAction_.status), status)); } - public static Specification byTargetIdsAndActiveAndStatusAndDSNotRequiredMigrationStep( - final List targetIds, final boolean active, final Action.Status status) { - return (root, query, cb) -> cb.and( - root.get(JpaAction_.target).in(targetIds), - cb.equal(root.get(JpaAction_.active), active), - cb.equal(root.get(JpaAction_.status), status), - cb.equal(root.get(JpaAction_.distributionSet).get(JpaDistributionSet_.requiredMigrationStep), false)); - } - /** * Returns active actions by target controller that has null or non-null depending on isNull value. * @@ -84,73 +72,64 @@ public final class ActionSpecifications { * @return the matching action s. */ public static Specification byTargetControllerIdAndActiveAndWeightIsNull(final String controllerId, final boolean isNull) { - return (root, query, cb) -> - cb.and( - cb.equal(root.get(JpaAction_.target).get(JpaTarget_.controllerId), controllerId), - cb.equal(root.get(JpaAction_.active), true), - isNull ? cb.isNull(root.get(JpaAction_.weight)) : cb.isNotNull(root.get(JpaAction_.weight))); + return (root, query, cb) -> cb.and( + cb.equal(root.get(JpaAction_.target).get(JpaTarget_.controllerId), controllerId), + cb.equal(root.get(JpaAction_.active), true), + isNull ? cb.isNull(root.get(JpaAction_.weight)) : cb.isNotNull(root.get(JpaAction_.weight))); } public static Specification byDistributionSetId(final Long distributionSetId) { - return (root, query, cb) -> cb.equal(root.get(JpaAction_.distributionSet).get(JpaTarget_.id), distributionSetId); + return (root, query, cb) -> cb.equal(root.get(JpaAction_.distributionSet).get(AbstractJpaBaseEntity_.id), distributionSetId); } public static Specification byDistributionSetIdAndActive(final Long distributionSetId) { return (root, query, cb) -> cb.and( - cb.equal(root.get(JpaAction_.distributionSet).get(JpaTarget_.id), distributionSetId), + cb.equal(root.get(JpaAction_.distributionSet).get(AbstractJpaBaseEntity_.id), distributionSetId), cb.equal(root.get(JpaAction_.active), true)); } - public static Specification byDistributionSetIdAndActiveAndStatusIsNot( - final Long distributionSetId, final Action.Status status) { + public static Specification byDistributionSetIdAndActiveAndStatusIsNot(final Long distributionSetId, final Action.Status status) { return (root, query, cb) -> cb.and( - cb.equal(root.get(JpaAction_.distributionSet).get(JpaTarget_.id), distributionSetId), + cb.equal(root.get(JpaAction_.distributionSet).get(AbstractJpaBaseEntity_.id), distributionSetId), cb.equal(root.get(JpaAction_.active), true), cb.notEqual(root.get(JpaAction_.status), status)); } /** - * Specification which joins all necessary tables to retrieve the dependency - * between a target and a local file assignment through the assigned action - * of the target. All actions are included, not only active actions. + * Specification which joins all necessary tables to retrieve the dependency between a target and a local file assignment through the + * assigned action of the target. All actions are included, not only active actions. * - * @param controllerId the target to verify if the given artifact is currently - * assigned or had been assigned - * @param sha1Hash of the local artifact to check wherever the target had ever - * been assigned + * @param controllerId the target to verify if the given artifact is currently assigned or had been assigned + * @param sha1Hash of the local artifact to check wherever the target had ever been assigned * @return a specification to use with spring JPA */ public static Specification hasTargetAssignedArtifact(final String controllerId, final String sha1Hash) { return (actionRoot, query, criteriaBuilder) -> { final Join dsJoin = actionRoot.join(JpaAction_.distributionSet); final SetJoin modulesJoin = dsJoin.join(JpaDistributionSet_.modules); - final ListJoin artifactsJoin = modulesJoin - .join(JpaSoftwareModule_.artifacts); - return criteriaBuilder.and(criteriaBuilder.equal(artifactsJoin.get(JpaArtifact_.sha1Hash), sha1Hash), - criteriaBuilder.equal(actionRoot.get(JpaAction_.target).get(JpaTarget_.controllerId), - controllerId)); + final ListJoin artifactsJoin = modulesJoin.join(JpaSoftwareModule_.artifacts); + return criteriaBuilder.and( + criteriaBuilder.equal(artifactsJoin.get(JpaArtifact_.sha1Hash), sha1Hash), + criteriaBuilder.equal(actionRoot.get(JpaAction_.target).get(JpaTarget_.controllerId), controllerId)); }; } /** - * Specification which joins all necessary tables to retrieve the dependency - * between a target and a local file assignment through the assigned action - * of the target. All actions are included, not only active actions. + * Specification which joins all necessary tables to retrieve the dependency between a target and a local file assignment through the + * assigned action of the target. All actions are included, not only active actions. * - * @param targetId the target to verify if the given artifact is currently - * assigned or had been assigned - * @param sha1Hash of the local artifact to check wherever the target had ever - * been assigned + * @param targetId the target to verify if the given artifact is currently assigned or had been assigned + * @param sha1Hash of the local artifact to check wherever the target had ever been assigned * @return a specification to use with spring JPA */ public static Specification hasTargetAssignedArtifact(final Long targetId, final String sha1Hash) { return (actionRoot, query, criteriaBuilder) -> { final Join dsJoin = actionRoot.join(JpaAction_.distributionSet); final SetJoin modulesJoin = dsJoin.join(JpaDistributionSet_.modules); - final ListJoin artifactsJoin = modulesJoin - .join(JpaSoftwareModule_.artifacts); - return criteriaBuilder.and(criteriaBuilder.equal(artifactsJoin.get(JpaArtifact_.sha1Hash), sha1Hash), - criteriaBuilder.equal(actionRoot.get(JpaAction_.target).get(JpaTarget_.id), targetId)); + final ListJoin artifactsJoin = modulesJoin.join(JpaSoftwareModule_.artifacts); + return criteriaBuilder.and( + criteriaBuilder.equal(artifactsJoin.get(JpaArtifact_.sha1Hash), sha1Hash), + criteriaBuilder.equal(actionRoot.get(JpaAction_.target).get(AbstractJpaBaseEntity_.id), targetId)); }; } } \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/ArtifactSpecifications.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/ArtifactSpecifications.java index 3d49ea671..f05330776 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/ArtifactSpecifications.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/specifications/ArtifactSpecifications.java @@ -9,23 +9,21 @@ */ package org.eclipse.hawkbit.repository.jpa.specifications; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; +import org.eclipse.hawkbit.repository.jpa.model.AbstractJpaBaseEntity_; import org.eclipse.hawkbit.repository.jpa.model.JpaArtifact; import org.eclipse.hawkbit.repository.jpa.model.JpaArtifact_; -import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule_; import org.springframework.data.jpa.domain.Specification; /** - * Utility class for {@link JpaArtifact}s {@link Specification}s. The class provides - * Spring Data JPQL Specifications. + * Utility class for {@link JpaArtifact}s {@link Specification}s. The class provides Spring Data JPQL Specifications. */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) public final class ArtifactSpecifications { - private ArtifactSpecifications() { - // utility class - } - public static Specification bySoftwareModuleId(final Long softwareModuleId) { return (targetRoot, query, cb) -> cb.equal( - targetRoot.get(JpaArtifact_.softwareModule).get(JpaSoftwareModule_.id), softwareModuleId); + targetRoot.get(JpaArtifact_.softwareModule).get(AbstractJpaBaseEntity_.id), softwareModuleId); } -} +} \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/SystemManagementHolder.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/SystemManagementHolder.java index 04b000db6..d1ac5e73a 100644 --- a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/SystemManagementHolder.java +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/SystemManagementHolder.java @@ -12,7 +12,6 @@ package org.eclipse.hawkbit.repository.test.util; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; -import lombok.Setter; import org.eclipse.hawkbit.repository.SystemManagement; import org.springframework.beans.factory.annotation.Autowired; @@ -21,13 +20,12 @@ import org.springframework.beans.factory.annotation.Autowired; * accessible to beans which are not managed by spring, e.g. JPA entities. */ @NoArgsConstructor(access = AccessLevel.PRIVATE) +@SuppressWarnings("java:S6548") // java:S6548 - singleton holder ensures static access to spring resources in some places public final class SystemManagementHolder { private static final SystemManagementHolder INSTANCE = new SystemManagementHolder(); @Getter - @Setter - @Autowired private SystemManagement systemManagement; /** @@ -36,4 +34,9 @@ public final class SystemManagementHolder { public static SystemManagementHolder getInstance() { return INSTANCE; } + + @Autowired // spring setter injection + public void setSystemManagement(final SystemManagement systemManagement) { + this.systemManagement = systemManagement; + } } \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/TestdataFactory.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/TestdataFactory.java index 75c94bb55..84008b02d 100644 --- a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/TestdataFactory.java +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/TestdataFactory.java @@ -614,15 +614,14 @@ public class TestdataFactory { * {@link #SM_TYPE_RT} , {@link #SM_TYPE_APP}. */ public DistributionSetType findOrCreateDefaultTestDsType() { - final List mand = new ArrayList<>(); - mand.add(findOrCreateSoftwareModuleType(SM_TYPE_OS)); + final List swt = new ArrayList<>(); + swt.add(findOrCreateSoftwareModuleType(SM_TYPE_OS)); final List opt = new ArrayList<>(); opt.add(findOrCreateSoftwareModuleType(SM_TYPE_APP, Integer.MAX_VALUE)); opt.add(findOrCreateSoftwareModuleType(SM_TYPE_RT)); - return findOrCreateDistributionSetType(DS_TYPE_DEFAULT, "OS (FW) mandatory, runtime (FW) and app (SW) optional", - mand, opt); + return findOrCreateDistributionSetType(DS_TYPE_DEFAULT, "OS (FW) mandatory, runtime (FW) and app (SW) optional", swt, opt); } /** @@ -651,15 +650,18 @@ public class TestdataFactory { public DistributionSetType findOrCreateDistributionSetType(final String dsTypeKey, final String dsTypeName, final Collection mandatory, final Collection optional) { return distributionSetTypeManagement.findByKey(dsTypeKey) - .orElseGet(() -> distributionSetTypeManagement.create(entityFactory.distributionSetType().create() - .key(dsTypeKey).name(dsTypeName).description(randomDescriptionShort()).colour("black") - .optional(optional.stream().map(SoftwareModuleType::getId).collect(Collectors.toList())) - .mandatory(mandatory.stream().map(SoftwareModuleType::getId).collect(Collectors.toList())))); + .orElseGet(() -> distributionSetTypeManagement.create( + entityFactory.distributionSetType().create() + .key(dsTypeKey) + .name(dsTypeName) + .description(randomDescriptionShort()) + .colour("black") + .optional(optional.stream().map(SoftwareModuleType::getId).toList()) + .mandatory(mandatory.stream().map(SoftwareModuleType::getId).toList()))); } /** - * Finds {@link SoftwareModuleType} in repository with given - * {@link SoftwareModuleType#getKey()} or creates if it does not exist yet with + * Finds {@link SoftwareModuleType} in repository with given {@link SoftwareModuleType#getKey()} or creates if it does not exist yet with * {@link SoftwareModuleType#getMaxAssignments()} = 1. * * @param key {@link SoftwareModuleType#getKey()} @@ -670,8 +672,7 @@ public class TestdataFactory { } /** - * Finds {@link SoftwareModuleType} in repository with given - * {@link SoftwareModuleType#getKey()} or creates if it does not exist yet. + * Finds {@link SoftwareModuleType} in repository with given {@link SoftwareModuleType#getKey()} or creates if it does not exist yet. * * @param key {@link SoftwareModuleType#getKey()} * @param maxAssignments {@link SoftwareModuleType#getMaxAssignments()} @@ -680,7 +681,9 @@ public class TestdataFactory { public SoftwareModuleType findOrCreateSoftwareModuleType(final String key, final int maxAssignments) { return softwareModuleTypeManagement.findByKey(key) .orElseGet(() -> softwareModuleTypeManagement.create(entityFactory.softwareModuleType().create() - .key(key).name(key).description(randomDescriptionShort()).colour("#ffffff") + .key(key) + .name(key) + .description(randomDescriptionShort()).colour("#ffffff") .maxAssignments(maxAssignments))); } @@ -693,11 +696,14 @@ public class TestdataFactory { * @param modules {@link DistributionSet#getModules()} * @return the created {@link DistributionSet} */ - public DistributionSet createDistributionSet(final String name, final String version, - final DistributionSetType type, final Collection modules) { - return distributionSetManagement.create(entityFactory.distributionSet().create().name(name).version(version) - .description(randomDescriptionShort()).type(type) - .modules(modules.stream().map(SoftwareModule::getId).collect(Collectors.toList()))); + public DistributionSet createDistributionSet( + final String name, final String version, final DistributionSetType type, final Collection modules) { + return distributionSetManagement.create(entityFactory.distributionSet().create() + .type(type) + .name(name) + .version(version) + .description(randomDescriptionShort()) + .modules(modules.stream().map(SoftwareModule::getId).toList())); } /** @@ -710,13 +716,17 @@ public class TestdataFactory { * @param requiredMigrationStep {@link DistributionSet#isRequiredMigrationStep()} * @return the created {@link DistributionSet} */ - public DistributionSet generateDistributionSet(final String name, final String version, - final DistributionSetType type, final Collection modules, + public DistributionSet generateDistributionSet( + final String name, final String version, final DistributionSetType type, final Collection modules, final boolean requiredMigrationStep) { - return entityFactory.distributionSet().create().name(name).version(version) - .description(randomDescriptionShort()).type(type) - .modules(modules.stream().map(SoftwareModule::getId).collect(Collectors.toList())) - .requiredMigrationStep(requiredMigrationStep).build(); + return entityFactory.distributionSet().create() + .type(type) + .name(name) + .version(version) + .description(randomDescriptionShort()) + .modules(modules.stream().map(SoftwareModule::getId).toList()) + .requiredMigrationStep(requiredMigrationStep) + .build(); } /** @@ -728,8 +738,8 @@ public class TestdataFactory { * @param modules {@link DistributionSet#getModules()} * @return the created {@link DistributionSet} */ - public DistributionSet generateDistributionSet(final String name, final String version, - final DistributionSetType type, final Collection modules) { + public DistributionSet generateDistributionSet( + final String name, final String version, final DistributionSetType type, final Collection modules) { return generateDistributionSet(name, version, type, modules, false); } @@ -740,13 +750,11 @@ public class TestdataFactory { * @return the generated {@link DistributionSet} */ public DistributionSet generateDistributionSet(final String name) { - return generateDistributionSet(name, DEFAULT_VERSION, findOrCreateDefaultTestDsType(), Collections.emptyList(), - false); + return generateDistributionSet(name, DEFAULT_VERSION, findOrCreateDefaultTestDsType(), Collections.emptyList(), false); } /** - * Creates {@link Target}s in repository and with {@link #DEFAULT_CONTROLLER_ID} - * as prefix for {@link Target#getControllerId()}. + * Creates {@link Target}s in repository and with {@link #DEFAULT_CONTROLLER_ID} as prefix for {@link Target#getControllerId()}. * * @param number of {@link Target}s to create * @return {@link List} of {@link Target} entities @@ -764,7 +772,6 @@ public class TestdataFactory { for (int i = 0; i < number; i++) { targets.add(entityFactory.target().create().controllerId(prefix + (offset + i))); } - return createTargets(targets); } @@ -776,15 +783,11 @@ public class TestdataFactory { * @param targetType targetType of targets to create * @return {@link List} of {@link Target} entities */ - public List createTargetsWithType(final int number, final String controllerIdPrefix, - final TargetType targetType) { - + public List createTargetsWithType(final int number, final String controllerIdPrefix, final TargetType targetType) { final List targets = new ArrayList<>(number); for (int i = 0; i < number; i++) { - targets.add(entityFactory.target().create().controllerId(controllerIdPrefix + i) - .targetType(targetType.getId())); + targets.add(entityFactory.target().create().controllerId(controllerIdPrefix + i).targetType(targetType.getId())); } - return createTargets(targets); } @@ -795,12 +798,10 @@ public class TestdataFactory { * @return {@link List} of {@link Target} entities */ public List createTargets(final String... targetIds) { - final List targets = new ArrayList<>(); for (final String targetId : targetIds) { targets.add(entityFactory.target().create().controllerId(targetId)); } - return createTargets(targets); } @@ -835,14 +836,12 @@ public class TestdataFactory { * @param descriptionPrefix prefix used for the description * @return set of {@link Target} */ - public List createTargets(final int numberOfTargets, final String controllerIdPrefix, - final String descriptionPrefix) { - + public List createTargets(final int numberOfTargets, final String controllerIdPrefix, final String descriptionPrefix) { final List targets = IntStream.range(0, numberOfTargets) .mapToObj(i -> entityFactory.target().create() .controllerId(String.format("%s-%05d", controllerIdPrefix, i)) .description(descriptionPrefix + i)) - .collect(Collectors.toList()); + .toList(); return createTargets(targets); } @@ -855,14 +854,13 @@ public class TestdataFactory { * @param lastTargetQuery last time the target polled * @return set of {@link Target} */ - public List createTargets(final int numberOfTargets, final String controllerIdPrefix, - final String descriptionPrefix, final Long lastTargetQuery) { - + public List createTargets( + final int numberOfTargets, final String controllerIdPrefix, final String descriptionPrefix, final Long lastTargetQuery) { final List targets = IntStream.range(0, numberOfTargets) .mapToObj(i -> entityFactory.target().create() .controllerId(String.format("%s-%05d", controllerIdPrefix, i)) .description(descriptionPrefix + i).lastTargetQuery(lastTargetQuery)) - .collect(Collectors.toList()); + .toList(); return createTargets(targets); } @@ -875,12 +873,9 @@ public class TestdataFactory { */ public List createTargetTags(final int number, final String tagPrefix) { final List result = new ArrayList<>(number); - for (int i = 0; i < number; i++) { - result.add(entityFactory.tag().create().name(tagPrefix + i).description(tagPrefix + i) - .colour(String.valueOf(i))); + result.add(entityFactory.tag().create().name(tagPrefix + i).description(tagPrefix + i).colour(String.valueOf(i))); } - return targetTagManagement.create(result); } @@ -892,12 +887,9 @@ public class TestdataFactory { */ public List createDistributionSetTags(final int number) { final List result = new ArrayList<>(number); - for (int i = 0; i < number; i++) { - result.add( - entityFactory.tag().create().name("tag" + i).description("tagdesc" + i).colour(String.valueOf(i))); + result.add(entityFactory.tag().create().name("tag" + i).description("tagdesc" + i).colour(String.valueOf(i))); } - return distributionSetTagManagement.create(result); } @@ -909,8 +901,7 @@ public class TestdataFactory { * @param message to add * @return updated {@link Action}. */ - public List sendUpdateActionStatusToTargets(final Collection targets, final Status status, - final String message) { + public List sendUpdateActionStatusToTargets(final Collection targets, final Status status, final String message) { return sendUpdateActionStatusToTargets(targets, status, Arrays.asList(message)); } @@ -922,15 +913,11 @@ public class TestdataFactory { * @param msgs to add * @return updated {@link Action}. */ - public List sendUpdateActionStatusToTargets(final Collection targets, final Status status, - final Collection msgs) { + public List sendUpdateActionStatusToTargets(final Collection targets, final Status status, final Collection msgs) { final List result = new ArrayList<>(); for (final Target target : targets) { - final List findByTarget = deploymentManagement - .findActionsByTarget(target.getControllerId(), PageRequest.of(0, 400)).getContent(); - for (final Action action : findByTarget) { - result.add(sendUpdateActionStatusToTarget(status, action, msgs)); - } + deploymentManagement.findActionsByTarget(target.getControllerId(), PageRequest.of(0, 400)).getContent() + .forEach(action -> result.add(sendUpdateActionStatusToTarget(status, action, msgs))); } return result; } @@ -939,7 +926,6 @@ public class TestdataFactory { createTargets(quotaManagement.getMaxTargetsPerAutoAssignment()); final TargetFilterQuery targetFilterQuery = targetFilterQueryManagement .create(entityFactory.targetFilterQuery().create().name("testName").query("id==*")); - return targetFilterQueryManagement.updateAutoAssignDS(entityFactory.targetFilterQuery() .updateAutoAssign(targetFilterQuery.getId()).ds(createDistributionSet().getId())); } @@ -998,8 +984,7 @@ public class TestdataFactory { * @param errorCondition to switch to next group * @param actionType the type of the Rollout * @param weight weight of the Rollout - * @param confirmationRequired if the confirmation is required (considered with confirmation flow - * active) + * @param confirmationRequired if the confirmation is required (considered with confirmation flow active) * @param dynamic is dynamic * @return created {@link Rollout} */ @@ -1039,39 +1024,33 @@ public class TestdataFactory { } /** - * Create {@link Rollout} with a new {@link DistributionSet} and - * {@link Target}s. + * Create {@link Rollout} with a new {@link DistributionSet} and {@link Target}s. * - * @param prefix for rollouts name, description, {@link Target#getControllerId()} - * filter + * @param prefix for rollouts name, description, {@link Target#getControllerId()} filter * @return created {@link Rollout} */ public Rollout createRollout(final String prefix) { - createTargets(quotaManagement.getMaxTargetsPerRolloutGroup() * quotaManagement.getMaxRolloutGroupsPerRollout(), - prefix); + createTargets(quotaManagement.getMaxTargetsPerRolloutGroup() * quotaManagement.getMaxRolloutGroupsPerRollout(), prefix); return createRolloutByVariables(prefix, prefix + SPACE_AND_DESCRIPTION, quotaManagement.getMaxRolloutGroupsPerRollout(), "controllerId==" + prefix + "*", createDistributionSet(prefix), "50", "5"); } /** - * Create {@link Rollout} with a new {@link DistributionSet} and - * {@link Target}s. + * Create {@link Rollout} with a new {@link DistributionSet} and {@link Target}s. * * @return created {@link Rollout} */ public Rollout createRollout() { final String prefix = randomString(5); - createTargets(quotaManagement.getMaxTargetsPerRolloutGroup() * quotaManagement.getMaxRolloutGroupsPerRollout(), - prefix); + createTargets(quotaManagement.getMaxTargetsPerRolloutGroup() * quotaManagement.getMaxRolloutGroupsPerRollout(), prefix); return createRolloutByVariables(prefix, prefix + SPACE_AND_DESCRIPTION, quotaManagement.getMaxRolloutGroupsPerRollout(), "controllerId==" + prefix + "*", createDistributionSet(prefix), "50", "5"); } /** - * Create {@link Rollout} with a new {@link DistributionSet} and - * {@link Target}s. + * Create {@link Rollout} with a new {@link DistributionSet} and {@link Target}s. * * @return created {@link Rollout} */ @@ -1089,11 +1068,11 @@ public class TestdataFactory { * @param errorCondition error condition * @return the created {@link Rollout} */ - public Rollout createAndStartRollout(final int amountTargetsForRollout, final int amountOtherTargets, + public Rollout createAndStartRollout( + final int amountTargetsForRollout, final int amountOtherTargets, final int amountGroups, final String successCondition, final String errorCondition) { - - final Rollout createdRollout = createSimpleTestRolloutWithTargetsAndDistributionSet(amountTargetsForRollout, - amountOtherTargets, amountGroups, successCondition, errorCondition); + final Rollout createdRollout = createSimpleTestRolloutWithTargetsAndDistributionSet( + amountTargetsForRollout, amountOtherTargets, amountGroups, successCondition, errorCondition); return startAndReloadRollout(createdRollout); } @@ -1107,11 +1086,12 @@ public class TestdataFactory { * @param errorCondition error condition * @return the created {@link Rollout} */ - public Rollout createSimpleTestRolloutWithTargetsAndDistributionSet(final int amountTargetsForRollout, + public Rollout createSimpleTestRolloutWithTargetsAndDistributionSet( + final int amountTargetsForRollout, final int amountOtherTargets, final int amountOfGroups, final String successCondition, final String errorCondition) { - return createSimpleTestRolloutWithTargetsAndDistributionSet(amountTargetsForRollout, amountOtherTargets, - amountOfGroups, successCondition, errorCondition, ActionType.FORCED, null); + return createSimpleTestRolloutWithTargetsAndDistributionSet( + amountTargetsForRollout, amountOtherTargets, amountOfGroups, successCondition, errorCondition, ActionType.FORCED, null); } /** @@ -1139,11 +1119,9 @@ public class TestdataFactory { } /** - * Create the soft deleted {@link Rollout} with a new {@link DistributionSet} - * and {@link Target}s. + * Create the soft deleted {@link Rollout} with a new {@link DistributionSet} and {@link Target}s. * - * @param prefix for rollouts name, description, {@link Target#getControllerId()} - * filter + * @param prefix for rollouts name, description, {@link Target#getControllerId()} filter * @return created {@link Rollout} */ public Rollout createSoftDeletedRollout(final String prefix) { @@ -1156,8 +1134,7 @@ public class TestdataFactory { } /** - * Finds {@link TargetType} in repository with given - * {@link TargetType#getName()} or creates if it does not exist yet. No ds types + * Finds {@link TargetType} in repository with given {@link TargetType#getName()} or creates if it does not exist yet. No ds types * are assigned on creation. * * @param targetTypeName {@link TargetType#getName()} @@ -1171,8 +1148,7 @@ public class TestdataFactory { } /** - * Creates {@link TargetType} in repository with given - * {@link TargetType#getName()}. Compatible distribution set types are assigned + * Creates {@link TargetType} in repository with given {@link TargetType#getName()}. Compatible distribution set types are assigned * on creation * * @param targetTypeName {@link TargetType#getName()} @@ -1185,8 +1161,7 @@ public class TestdataFactory { } /** - * Creates {@link TargetType} in repository with given - * {@link TargetType#getName()}. No ds types are assigned on creation. + * Creates {@link TargetType} in repository with given {@link TargetType#getName()}. No ds types are assigned on creation. * * @param targetTypePrefix {@link TargetType#getName()} * @return persisted {@link TargetType} @@ -1202,15 +1177,15 @@ public class TestdataFactory { } /** - * Creates a distribution set and directly invalidates it. No actions will be - * canceled and no rollouts will be stopped with this invalidation. + * Creates a distribution set and directly invalidates it. No actions will be canceled and no rollouts will be stopped with this + * invalidation. * * @return created invalidated {@link DistributionSet} */ public DistributionSet createAndInvalidateDistributionSet() { final DistributionSet distributionSet = createDistributionSet(); distributionSetInvalidationManagement.invalidateDistributionSet( - new DistributionSetInvalidation(Arrays.asList(distributionSet.getId()), CancelationType.NONE, false)); + new DistributionSetInvalidation(List.of(distributionSet.getId()), CancelationType.NONE, false)); return distributionSet; } @@ -1239,7 +1214,6 @@ public class TestdataFactory { .key(VISIBLE_SM_MD_KEY).value(VISIBLE_SM_MD_VALUE).targetVisible(true)); softwareModuleManagement.updateMetaData(entityFactory.softwareModuleMetadata().create(module.getId()) .key(INVISIBLE_SM_MD_KEY).value(INVISIBLE_SM_MD_VALUE).targetVisible(false)); - } private void assertTargetProperlyCreated(final Target target) { @@ -1252,8 +1226,7 @@ public class TestdataFactory { } /** - * Builds {@link Target} objects with given prefix for - * {@link Target#getControllerId()} followed by a number suffix. + * Builds {@link Target} objects with given prefix for {@link Target#getControllerId()} followed by a number suffix. * * @param start value for the controllerId suffix * @param numberOfTargets of {@link Target}s to generate @@ -1265,36 +1238,27 @@ public class TestdataFactory { for (int i = start; i < start + numberOfTargets; i++) { targets.add(entityFactory.target().create().controllerId(controllerIdPrefix + i).build()); } - return targets; } private List createTargets(final Collection targetCreates) { - // init new instance of array list since the TargetManagement#create - // will - // provide a unmodifiable list - final List createdTargets = targetManagement.create(targetCreates); - return new ArrayList<>(createdTargets); + // init new instance of array list since the TargetManagement#create will provide a unmodifiable list + return new ArrayList<>(targetManagement.create(targetCreates)); } - private Action sendUpdateActionStatusToTarget(final Status status, final Action updActA, - final Collection msgs) { - + private Action sendUpdateActionStatusToTarget(final Status status, final Action updActA, final Collection msgs) { return controllerManagement.addUpdateActionStatus( entityFactory.actionStatus().create(updActA.getId()).status(status).messages(msgs)); } private Rollout startAndReloadRollout(final Rollout rollout) { rolloutManagement.start(rollout.getId()); - // Run here, because scheduler is disabled during tests rolloutHandler.handleAll(); - return reloadRollout(rollout); } private Rollout reloadRollout(final Rollout rollout) { return rolloutManagement.get(rollout.getId()).orElseThrow(NoSuchElementException::new); } - -} +} \ No newline at end of file diff --git a/hawkbit-sdk/hawkbit-sdk-dmf/src/main/java/org/eclipse/hawkbit/sdk/dmf/amqp/Amqp.java b/hawkbit-sdk/hawkbit-sdk-dmf/src/main/java/org/eclipse/hawkbit/sdk/dmf/amqp/Amqp.java index bd846ab3b..0b527107d 100644 --- a/hawkbit-sdk/hawkbit-sdk-dmf/src/main/java/org/eclipse/hawkbit/sdk/dmf/amqp/Amqp.java +++ b/hawkbit-sdk/hawkbit-sdk-dmf/src/main/java/org/eclipse/hawkbit/sdk/dmf/amqp/Amqp.java @@ -39,6 +39,7 @@ public class Amqp { vHosts.values().forEach(VHost::stop); } + @SuppressWarnings("java:S3358") // java:S3358 public VHost getVhost(final DMF dmf, final boolean initVHost) { final String vHost = dmf == null || ObjectUtils.isEmpty(dmf.getVirtualHost()) ? (rabbitProperties.getVirtualHost() == null ? "/" : rabbitProperties.getVirtualHost()) : diff --git a/hawkbit-security/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/security/MdcHandler.java b/hawkbit-security/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/security/MdcHandler.java index fd97baff6..25ed8d93f 100644 --- a/hawkbit-security/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/security/MdcHandler.java +++ b/hawkbit-security/hawkbit-security-core/src/main/java/org/eclipse/hawkbit/security/MdcHandler.java @@ -31,6 +31,7 @@ import org.springframework.security.web.access.intercept.AuthorizationFilter; import org.springframework.web.filter.OncePerRequestFilter; @NoArgsConstructor(access = AccessLevel.PRIVATE) +@SuppressWarnings("java:S6548") // java:S6548 - singleton holder ensures static access to spring resources in some places public class MdcHandler { public static final String MDC_KEY_TENANT = "tenant"; @@ -40,7 +41,6 @@ public class MdcHandler { @Value("${hawkbit.logging.mdchandler.enabled:true}") private boolean mdcEnabled; - @Autowired(required = false) private SpringSecurityAuditorAware springSecurityAuditorAware = new SpringSecurityAuditorAware(); /** @@ -50,6 +50,11 @@ public class MdcHandler { return SINGLETON; } + @Autowired(required = false) // spring setter injection + public void setSpringSecurityAuditorAware(final SpringSecurityAuditorAware springSecurityAuditorAware) { + this.springSecurityAuditorAware = springSecurityAuditorAware; + } + /** * Executes callable and returns the result. If MDC is enabled, it sets the tenant and / or user from the authentication in the MDC context. *