Sonar Fixes (#2233)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2025-01-24 15:41:06 +02:00
committed by GitHub
parent 0280d96d2c
commit a61e9cd6ae
66 changed files with 401 additions and 387 deletions

View File

@@ -18,6 +18,7 @@ import jakarta.validation.Validation;
import org.eclipse.hawkbit.ContextAware;
import org.eclipse.hawkbit.artifact.repository.ArtifactRepository;
import org.eclipse.hawkbit.cache.TenancyCacheManager;
import org.eclipse.hawkbit.repository.ArtifactEncryption;
import org.eclipse.hawkbit.repository.ArtifactEncryptionSecretsStore;
import org.eclipse.hawkbit.repository.ArtifactEncryptionService;
@@ -130,6 +131,8 @@ import org.eclipse.hawkbit.repository.jpa.repository.TargetMetadataRepository;
import org.eclipse.hawkbit.repository.jpa.repository.TargetRepository;
import org.eclipse.hawkbit.repository.jpa.repository.TargetTagRepository;
import org.eclipse.hawkbit.repository.jpa.repository.TargetTypeRepository;
import org.eclipse.hawkbit.repository.jpa.repository.TenantConfigurationRepository;
import org.eclipse.hawkbit.repository.jpa.repository.TenantMetaDataRepository;
import org.eclipse.hawkbit.repository.jpa.rollout.RolloutScheduler;
import org.eclipse.hawkbit.repository.jpa.rollout.condition.PauseRolloutGroupAction;
import org.eclipse.hawkbit.repository.jpa.rollout.condition.RolloutGroupActionEvaluator;
@@ -160,6 +163,7 @@ import org.eclipse.hawkbit.security.SecurityTokenGenerator;
import org.eclipse.hawkbit.security.SystemSecurityContext;
import org.eclipse.hawkbit.tenancy.TenantAware;
import org.eclipse.hawkbit.tenancy.UserAuthoritiesResolver;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties;
import org.eclipse.hawkbit.utils.TenantConfigHelper;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
@@ -170,6 +174,8 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties;
import org.springframework.cache.CacheManager;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
@@ -476,8 +482,23 @@ public class RepositoryApplicationConfiguration {
*/
@Bean
@ConditionalOnMissingBean
SystemManagement systemManagement(final JpaProperties properties) {
return new JpaSystemManagement(properties);
SystemManagement systemManagement(
final TargetRepository targetRepository, final TargetTypeRepository targetTypeRepository,
final TargetTagRepository targetTagRepository, final TargetFilterQueryRepository targetFilterQueryRepository,
final SoftwareModuleRepository softwareModuleRepository, final SoftwareModuleTypeRepository softwareModuleTypeRepository,
final DistributionSetRepository distributionSetRepository, final DistributionSetTypeRepository distributionSetTypeRepository,
final DistributionSetTagRepository distributionSetTagRepository, final RolloutRepository rolloutRepository,
final TenantConfigurationRepository tenantConfigurationRepository, final TenantMetaDataRepository tenantMetaDataRepository,
final TenantStatsManagement systemStatsManagement, final SystemManagementCacheKeyGenerator currentTenantCacheKeyGenerator,
final SystemSecurityContext systemSecurityContext, final TenantAware tenantAware, final PlatformTransactionManager txManager,
final TenancyCacheManager cacheManager, final RolloutStatusCache rolloutStatusCache,
final EntityManager entityManager, final RepositoryProperties repositoryProperties,
final JpaProperties properties) {
return new JpaSystemManagement(targetRepository, targetTypeRepository, targetTagRepository,
targetFilterQueryRepository, softwareModuleRepository, softwareModuleTypeRepository, distributionSetRepository,
distributionSetTypeRepository, distributionSetTagRepository, rolloutRepository, tenantConfigurationRepository,
tenantMetaDataRepository, systemStatsManagement, currentTenantCacheKeyGenerator, systemSecurityContext,
tenantAware, txManager, cacheManager, rolloutStatusCache, entityManager, repositoryProperties, properties);
}
/**
@@ -547,8 +568,10 @@ public class RepositoryApplicationConfiguration {
*/
@Bean
@ConditionalOnMissingBean
TenantStatsManagement tenantStatsManagement() {
return new JpaTenantStatsManagement();
TenantStatsManagement tenantStatsManagement(
final TargetRepository targetRepository, final LocalArtifactRepository artifactRepository, final ActionRepository actionRepository,
final TenantAware tenantAware) {
return new JpaTenantStatsManagement(targetRepository, artifactRepository, actionRepository, tenantAware);
}
/**
@@ -558,8 +581,13 @@ public class RepositoryApplicationConfiguration {
*/
@Bean
@ConditionalOnMissingBean
TenantConfigurationManagement tenantConfigurationManagement() {
return new JpaTenantConfigurationManagement();
TenantConfigurationManagement tenantConfigurationManagement(
final TenantConfigurationRepository tenantConfigurationRepository,
final TenantConfigurationProperties tenantConfigurationProperties,
final CacheManager cacheManager, final AfterTransactionCommitExecutor afterCommitExecutor,
final ApplicationContext applicationContext) {
return new JpaTenantConfigurationManagement(tenantConfigurationRepository, tenantConfigurationProperties,
cacheManager, afterCommitExecutor, applicationContext);
}
/**

View File

@@ -587,6 +587,7 @@ public class JpaRolloutManagement implements RolloutManagement {
return rollout;
}
@SuppressWarnings("java:S2259") // java:S2259 - false positive, see the java:S2259 comment in code
private Rollout createRolloutGroups(
final int amountOfGroups, final RolloutGroupConditions conditions,
final JpaRollout rollout, final boolean isConfirmationRequired, final DynamicRolloutGroupTemplate dynamicRolloutGroupTemplate) {
@@ -651,7 +652,7 @@ public class JpaRolloutManagement implements RolloutManagement {
publishRolloutGroupCreatedEventAfterCommit(lastGroup, rollout);
}
// lastSavedGroup is never null! amountOfGroups > 0 (and has static groups) or dynamicRolloutGroupTemplate is
// java:S2259 - lastSavedGroup is never null! amountOfGroups > 0 (and has static groups) or dynamicRolloutGroupTemplate is
// not null (validated) and (validated) the rollout is dynamic, so has dynamic group
rollout.setRolloutGroupsCreated(lastGroup.isDynamic() ? amountOfGroups + 1 : amountOfGroups);
final JpaRollout savedRollout = rolloutRepository.save(rollout);

View File

@@ -54,6 +54,7 @@ import org.springframework.dao.ConcurrencyFailureException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.lang.Nullable;
import org.springframework.orm.jpa.vendor.Database;
import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Retryable;
@@ -75,62 +76,76 @@ public class JpaSystemManagement implements CurrentTenantCacheKeyGenerator, Syst
private final String countArtifactQuery;
private final String countSoftwareModulesQuery;
@Autowired
private EntityManager entityManager;
@Autowired
private TargetRepository targetRepository;
@Autowired
private TargetFilterQueryRepository targetFilterQueryRepository;
@Autowired
private DistributionSetRepository distributionSetRepository;
@Autowired
private SoftwareModuleRepository softwareModuleRepository;
@Autowired
private TenantMetaDataRepository tenantMetaDataRepository;
@Autowired
private DistributionSetTypeRepository distributionSetTypeRepository;
@Autowired
private SoftwareModuleTypeRepository softwareModuleTypeRepository;
@Autowired
private TargetTagRepository targetTagRepository;
@Autowired
private TargetTypeRepository targetTypeRepository;
@Autowired
private DistributionSetTagRepository distributionSetTagRepository;
@Autowired
private TenantConfigurationRepository tenantConfigurationRepository;
@Autowired
private RolloutRepository rolloutRepository;
@Autowired
private TenantAware tenantAware;
@Autowired
private TenantStatsManagement systemStatsManagement;
@Autowired
private TenancyCacheManager cacheManager;
@Autowired
private SystemManagementCacheKeyGenerator currentTenantCacheKeyGenerator;
@Autowired
private SystemSecurityContext systemSecurityContext;
@Autowired
private PlatformTransactionManager txManager;
@Autowired
private RolloutStatusCache rolloutStatusCache;
@Autowired(required = false) // it's not required on dmf/ddi only instances
private ArtifactRepository artifactRepository;
@Autowired
private RepositoryProperties repositoryProperties;
private final TargetRepository targetRepository;
private final TargetTypeRepository targetTypeRepository;
private final TargetTagRepository targetTagRepository;
private final TargetFilterQueryRepository targetFilterQueryRepository;
private final SoftwareModuleRepository softwareModuleRepository;
private final SoftwareModuleTypeRepository softwareModuleTypeRepository;
private final DistributionSetRepository distributionSetRepository;
private final DistributionSetTypeRepository distributionSetTypeRepository;
private final DistributionSetTagRepository distributionSetTagRepository;
private final RolloutRepository rolloutRepository;
private final TenantConfigurationRepository tenantConfigurationRepository;
private final TenantMetaDataRepository tenantMetaDataRepository;
private final TenantStatsManagement systemStatsManagement;
private final SystemManagementCacheKeyGenerator currentTenantCacheKeyGenerator;
private final SystemSecurityContext systemSecurityContext;
private final TenantAware tenantAware;
private final PlatformTransactionManager txManager;
private final TenancyCacheManager cacheManager;
private final RolloutStatusCache rolloutStatusCache;
private final EntityManager entityManager;
private final RepositoryProperties repositoryProperties;
@Nullable
private ArtifactRepository artifactRepository;
@SuppressWarnings("squid:S00107")
public JpaSystemManagement(
final TargetRepository targetRepository, final TargetTypeRepository targetTypeRepository,
final TargetTagRepository targetTagRepository, final TargetFilterQueryRepository targetFilterQueryRepository,
final SoftwareModuleRepository softwareModuleRepository, final SoftwareModuleTypeRepository softwareModuleTypeRepository,
final DistributionSetRepository distributionSetRepository, final DistributionSetTypeRepository distributionSetTypeRepository,
final DistributionSetTagRepository distributionSetTagRepository, final RolloutRepository rolloutRepository,
final TenantConfigurationRepository tenantConfigurationRepository, final TenantMetaDataRepository tenantMetaDataRepository,
final TenantStatsManagement systemStatsManagement, final SystemManagementCacheKeyGenerator currentTenantCacheKeyGenerator,
final SystemSecurityContext systemSecurityContext, final TenantAware tenantAware, final PlatformTransactionManager txManager,
final TenancyCacheManager cacheManager, final RolloutStatusCache rolloutStatusCache,
final EntityManager entityManager, final RepositoryProperties repositoryProperties,
final JpaProperties properties) {
this.targetRepository = targetRepository;
this.targetTypeRepository = targetTypeRepository;
this.targetTagRepository = targetTagRepository;
this.targetFilterQueryRepository = targetFilterQueryRepository;
this.softwareModuleRepository = softwareModuleRepository;
this.softwareModuleTypeRepository = softwareModuleTypeRepository;
this.distributionSetRepository = distributionSetRepository;
this.distributionSetTypeRepository = distributionSetTypeRepository;
this.distributionSetTagRepository = distributionSetTagRepository;
this.rolloutRepository = rolloutRepository;
this.tenantConfigurationRepository = tenantConfigurationRepository;
this.tenantMetaDataRepository = tenantMetaDataRepository;
this.systemStatsManagement = systemStatsManagement;
this.currentTenantCacheKeyGenerator = currentTenantCacheKeyGenerator;
this.systemSecurityContext = systemSecurityContext;
this.tenantAware = tenantAware;
this.txManager = txManager;
this.cacheManager = cacheManager;
this.rolloutStatusCache = rolloutStatusCache;
this.entityManager = entityManager;
this.repositoryProperties = repositoryProperties;
/**
* Constructor.
*
* @param properties properties to get the underlying database
*/
public JpaSystemManagement(final JpaProperties properties) {
final String isDeleted = isPostgreSql(properties) ? "false" : "0";
countArtifactQuery = "SELECT COUNT(a.id) FROM sp_artifact a INNER JOIN sp_base_software_module sm ON a.software_module = sm.id WHERE sm.deleted = " + isDeleted;
countSoftwareModulesQuery = "select SUM(file_size) from sp_artifact a INNER JOIN sp_base_software_module sm ON a.software_module = sm.id WHERE sm.deleted = " + isDeleted;
}
@Autowired(required = false) // it's not required on dmf/ddi only instances
public void setArtifactRepository(ArtifactRepository artifactRepository) {
this.artifactRepository = artifactRepository;
}
@Override
@Transactional(propagation = Propagation.SUPPORTS)
public KeyGenerator currentTenantKeyGenerator() {

View File

@@ -44,7 +44,6 @@ import org.eclipse.hawkbit.security.SystemSecurityContext;
import org.eclipse.hawkbit.tenancy.configuration.DurationHelper;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.TenantConfigurationKey;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.CacheEvict;
@@ -68,16 +67,23 @@ public class JpaTenantConfigurationManagement implements TenantConfigurationMana
private static final ConfigurableConversionService CONVERSION_SERVICE = new DefaultConversionService();
@Autowired
private TenantConfigurationRepository tenantConfigurationRepository;
@Autowired
private TenantConfigurationProperties tenantConfigurationProperties;
@Autowired
private ApplicationContext applicationContext;
@Autowired
private CacheManager cacheManager;
@Autowired
private AfterTransactionCommitExecutor afterCommitExecutor;
private final TenantConfigurationRepository tenantConfigurationRepository;
private final TenantConfigurationProperties tenantConfigurationProperties;
private final ApplicationContext applicationContext;
private final CacheManager cacheManager;
private final AfterTransactionCommitExecutor afterCommitExecutor;
public JpaTenantConfigurationManagement(
final TenantConfigurationRepository tenantConfigurationRepository,
final TenantConfigurationProperties tenantConfigurationProperties,
final CacheManager cacheManager, final AfterTransactionCommitExecutor afterCommitExecutor,
final ApplicationContext applicationContext) {
this.tenantConfigurationRepository = tenantConfigurationRepository;
this.tenantConfigurationProperties = tenantConfigurationProperties;
this.cacheManager = cacheManager;
this.afterCommitExecutor = afterCommitExecutor;
this.applicationContext = applicationContext;
}
@Override
@CacheEvict(value = "tenantConfiguration", key = "#configurationKeyName")

View File

@@ -26,14 +26,19 @@ import org.springframework.validation.annotation.Validated;
@Validated
public class JpaTenantStatsManagement implements TenantStatsManagement {
@Autowired
private TargetRepository targetRepository;
@Autowired
private LocalArtifactRepository artifactRepository;
@Autowired
private ActionRepository actionRepository;
@Autowired
private TenantAware tenantAware;
private final TargetRepository targetRepository;
private final LocalArtifactRepository artifactRepository;
private final ActionRepository actionRepository;
private final TenantAware tenantAware;
public JpaTenantStatsManagement(
final TargetRepository targetRepository, final LocalArtifactRepository artifactRepository, final ActionRepository actionRepository,
final TenantAware tenantAware) {
this.targetRepository = targetRepository;
this.artifactRepository = artifactRepository;
this.actionRepository = actionRepository;
this.tenantAware = tenantAware;
}
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)

View File

@@ -15,7 +15,6 @@ import java.util.List;
import java.util.Set;
import java.util.function.BooleanSupplier;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.apache.commons.collections4.ListUtils;
import org.eclipse.hawkbit.repository.QuotaManagement;
@@ -87,7 +86,7 @@ public class OfflineDsAssignmentStrategy extends AbstractDsAssignmentStrategy {
TargetSpecifications.notEqualToTargetUpdateStatus(TargetUpdateStatus.PENDING))));
}
return ListUtils.partition(controllerIDs, Constants.MAX_ENTRIES_IN_STATEMENT).stream().map(mapper)
.flatMap(List::stream).collect(Collectors.toList());
.flatMap(List::stream).toList();
}
@Override

View File

@@ -112,7 +112,7 @@ public class OnlineDsAssignmentStrategy extends AbstractDsAssignmentStrategy {
.findAll(TargetSpecifications.hasControllerIdAndAssignedDistributionSetIdNot(ids, setId));
}
return ListUtils.partition(controllerIDs, Constants.MAX_ENTRIES_IN_STATEMENT).stream().map(mapper)
.flatMap(List::stream).collect(Collectors.toList());
.flatMap(List::stream).toList();
}
@Override
@@ -170,8 +170,7 @@ public class OnlineDsAssignmentStrategy extends AbstractDsAssignmentStrategy {
@Override
public void sendDeploymentEvents(final List<DistributionSetAssignmentResult> assignmentResults) {
if (isMultiAssignmentsEnabled()) {
sendDeploymentEvent(assignmentResults.stream().flatMap(result -> result.getAssignedEntity().stream())
.collect(Collectors.toList()));
sendDeploymentEvent(assignmentResults.stream().flatMap(result -> result.getAssignedEntity().stream()).toList());
} else {
assignmentResults.forEach(this::sendDistributionSetAssignedEvent);
}
@@ -196,7 +195,7 @@ public class OnlineDsAssignmentStrategy extends AbstractDsAssignmentStrategy {
if (actions == null || actions.isEmpty()) {
return Collections.emptyList();
}
return filterCancellations(actions).collect(Collectors.toList());
return filterCancellations(actions).toList();
}
private void sendMultiActionCancelEvent(final Action action) {
@@ -214,8 +213,7 @@ public class OnlineDsAssignmentStrategy extends AbstractDsAssignmentStrategy {
private DistributionSetAssignmentResult sendDistributionSetAssignedEvent(
final DistributionSetAssignmentResult assignmentResult) {
final List<Action> filteredActions = filterCancellations(assignmentResult.getAssignedEntity())
.collect(Collectors.toList());
final List<Action> filteredActions = filterCancellations(assignmentResult.getAssignedEntity()).toList();
final DistributionSet set = assignmentResult.getDistributionSet();
sendTargetAssignDistributionSetEvent(set.getTenant(), set.getId(), filteredActions);
return assignmentResult;

View File

@@ -96,7 +96,8 @@ import org.springframework.util.ObjectUtils;
@NamedEntityGraph(name = "Target.actions", attributeNodes = { @NamedAttributeNode("actions") }),
})
// exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for sub entities
@SuppressWarnings("squid:S2160")
// java:S1710 - not possible to use without group annotation
@SuppressWarnings({ "squid:S2160", "java:S1710" })
public class JpaTarget extends AbstractJpaNamedEntity implements Target, EventAwareEntity {
@Serial