Skip to content

Commit

Permalink
Sonar Fixes (#2231)
Browse files Browse the repository at this point in the history
Signed-off-by: Avgustin Marinov <[email protected]>
  • Loading branch information
avgustinmm authored Jan 24, 2025
1 parent d488203 commit 51054bd
Show file tree
Hide file tree
Showing 12 changed files with 124 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetMetadata;
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetMetadata;
import org.eclipse.hawkbit.repository.model.MetaData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;

/**
Expand All @@ -38,23 +37,31 @@
@Validated
public class JpaEntityFactory implements EntityFactory {

@Autowired
private DistributionSetBuilder distributionSetBuilder;
@Autowired
private TargetBuilder targetBuilder;
@Autowired
private DistributionSetTypeBuilder distributionSetTypeBuilder;
@Autowired
private SoftwareModuleBuilder softwareModuleBuilder;
@Autowired
private RolloutBuilder rolloutBuilder;
@Autowired
private TargetFilterQueryBuilder targetFilterQueryBuilder;
@Autowired
private SoftwareModuleMetadataBuilder softwareModuleMetadataBuilder;
@Autowired
private TargetTypeBuilder targetTypeBuilder;

private final TargetBuilder targetBuilder;
private final TargetTypeBuilder targetTypeBuilder;
private final TargetFilterQueryBuilder targetFilterQueryBuilder;
private final SoftwareModuleBuilder softwareModuleBuilder;
private final SoftwareModuleMetadataBuilder softwareModuleMetadataBuilder;
private final DistributionSetBuilder distributionSetBuilder;
private final DistributionSetTypeBuilder distributionSetTypeBuilder;
private final RolloutBuilder rolloutBuilder;

@SuppressWarnings("java:S107")
public JpaEntityFactory(
final TargetBuilder targetBuilder, final TargetTypeBuilder targetTypeBuilder,
final TargetFilterQueryBuilder targetFilterQueryBuilder,
final SoftwareModuleBuilder softwareModuleBuilder, final SoftwareModuleMetadataBuilder softwareModuleMetadataBuilder,
final DistributionSetBuilder distributionSetBuilder, final DistributionSetTypeBuilder distributionSetTypeBuilder,
final RolloutBuilder rolloutBuilder) {
this.targetBuilder = targetBuilder;
this.targetTypeBuilder = targetTypeBuilder;
this.targetFilterQueryBuilder = targetFilterQueryBuilder;
this.softwareModuleBuilder = softwareModuleBuilder;
this.softwareModuleMetadataBuilder = softwareModuleMetadataBuilder;
this.distributionSetBuilder = distributionSetBuilder;
this.distributionSetTypeBuilder = distributionSetTypeBuilder;
this.rolloutBuilder = rolloutBuilder;
}
@Override
public ActionStatusBuilder actionStatus() {
return new JpaActionStatusBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.springframework.data.repository.CrudRepository;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

/**
* A collection of static helper methods for the management classes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public class JpaRolloutExecutor implements RolloutExecutor {
private final RepositoryProperties repositoryProperties;
private final Map<Long, AtomicLong> lastDynamicGroupFill = new ConcurrentHashMap<>();

@SuppressWarnings("java:S107")
public JpaRolloutExecutor(
final ActionRepository actionRepository, final RolloutGroupRepository rolloutGroupRepository,
final RolloutTargetGroupRepository rolloutTargetGroupRepository,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.integration.support.locks.LockRegistry;
import org.springframework.lang.NonNull;
import org.springframework.orm.jpa.vendor.Database;
import org.springframework.retry.annotation.EnableRetry;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.PlatformTransactionManager;
Expand Down Expand Up @@ -702,16 +703,26 @@ RolloutExecutor rolloutExecutor(

@Bean
@ConditionalOnMissingBean
RolloutManagement rolloutManagement(final TargetManagement targetManagement,
final DistributionSetManagement distributionSetManagement, final EventPublisherHolder eventPublisherHolder,
final VirtualPropertyReplacer virtualPropertyReplacer, final JpaProperties properties,
RolloutManagement rolloutManagement(
final RolloutRepository rolloutRepository,
final RolloutGroupRepository rolloutGroupRepository,
final RolloutApprovalStrategy rolloutApprovalStrategy,
final StartNextGroupRolloutGroupSuccessAction startNextRolloutGroupAction,
final RolloutStatusCache rolloutStatusCache,
final ActionRepository actionRepository,
final TargetManagement targetManagement,
final DistributionSetManagement distributionSetManagement,
final TenantConfigurationManagement tenantConfigurationManagement,
final SystemSecurityContext systemSecurityContext,
final ContextAware contextAware) {
return new JpaRolloutManagement(targetManagement, distributionSetManagement, eventPublisherHolder,
virtualPropertyReplacer, properties.getDatabase(), rolloutApprovalStrategy,
tenantConfigurationManagement, systemSecurityContext, contextAware);
final QuotaManagement quotaManagement,
final AfterTransactionCommitExecutor afterCommit, final EventPublisherHolder eventPublisherHolder,
final VirtualPropertyReplacer virtualPropertyReplacer,
final SystemSecurityContext systemSecurityContext, final ContextAware contextAware, final JpaProperties properties,
final RepositoryProperties repositoryProperties) {
return new JpaRolloutManagement(rolloutRepository, rolloutGroupRepository, rolloutApprovalStrategy,
startNextRolloutGroupAction, rolloutStatusCache, actionRepository, targetManagement,
distributionSetManagement, tenantConfigurationManagement, quotaManagement, afterCommit,
eventPublisherHolder, virtualPropertyReplacer, systemSecurityContext, contextAware, properties.getDatabase(),
repositoryProperties);
}

/**
Expand Down Expand Up @@ -821,8 +832,14 @@ ArtifactManagement artifactManagement(
*/
@Bean
@ConditionalOnMissingBean
EntityFactory entityFactory() {
return new JpaEntityFactory();
EntityFactory entityFactory(
final TargetBuilder targetBuilder, final TargetTypeBuilder targetTypeBuilder,
final TargetFilterQueryBuilder targetFilterQueryBuilder,
final SoftwareModuleBuilder softwareModuleBuilder, final SoftwareModuleMetadataBuilder softwareModuleMetadataBuilder,
final DistributionSetBuilder distributionSetBuilder, final DistributionSetTypeBuilder distributionSetTypeBuilder,
final RolloutBuilder rolloutBuilder) {
return new JpaEntityFactory(targetBuilder, targetTypeBuilder, targetFilterQueryBuilder, softwareModuleBuilder,
softwareModuleMetadataBuilder, distributionSetBuilder, distributionSetTypeBuilder, rolloutBuilder);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.eclipse.hawkbit.repository.jpa.model.JpaRollout;
import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.springframework.util.StringUtils;

public class JpaRolloutCreate extends AbstractNamedEntityBuilder<RolloutCreate> implements RolloutCreate {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,8 @@ public static void addSuccessAndErrorConditionsAndActions(final JpaRolloutGroup

/**
* Set the Success And Error conditions for the rollout group
*
* @param group The Rollout group
* @param successCondition The Rollout group success condition
* @param successConditionExp The Rollout group success expression
* @param successAction The Rollout group success action
* @param successActionExp The Rollout group success action expression
* @param errorCondition The Rollout group error condition
* @param errorConditionExp The Rollout group error expression
* @param errorAction The Rollout group error action
* @param errorActionExp The Rollout group error action expression
*/
@SuppressWarnings("java:S107")
public static void addSuccessAndErrorConditionsAndActions(final JpaRolloutGroup group,
final RolloutGroup.RolloutGroupSuccessCondition successCondition, final String successConditionExp,
final RolloutGroup.RolloutGroupSuccessAction successAction, final String successActionExp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
import org.eclipse.hawkbit.repository.TargetFields;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.jpa.JpaManagementHelper;
import org.eclipse.hawkbit.repository.jpa.model.AbstractJpaBaseEntity_;
import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup;
import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup_;
import org.eclipse.hawkbit.repository.jpa.model.JpaRollout_;
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget_;
import org.eclipse.hawkbit.repository.jpa.model.RolloutTargetGroup;
Expand Down Expand Up @@ -66,21 +66,15 @@
public class JpaRolloutGroupManagement implements RolloutGroupManagement {

private final RolloutGroupRepository rolloutGroupRepository;

private final RolloutRepository rolloutRepository;

private final ActionRepository actionRepository;

private final TargetRepository targetRepository;

private final EntityManager entityManager;

private final VirtualPropertyReplacer virtualPropertyReplacer;

private final RolloutStatusCache rolloutStatusCache;

private final Database database;

@SuppressWarnings("java:S107")
public JpaRolloutGroupManagement(final RolloutGroupRepository rolloutGroupRepository,
final RolloutRepository rolloutRepository, final ActionRepository actionRepository,
final TargetRepository targetRepository, final EntityManager entityManager,
Expand Down Expand Up @@ -130,7 +124,7 @@ public Page<RolloutGroup> findByRolloutAndRsql(final long rolloutId, final Strin
final List<Specification<JpaRolloutGroup>> specList = Arrays.asList(
RSQLUtility.buildRsqlSpecification(rsqlParam, RolloutGroupFields.class, virtualPropertyReplacer,
database),
(root, query, cb) -> cb.equal(root.get(JpaRolloutGroup_.rollout).get(JpaRollout_.id), rolloutId));
(root, query, cb) -> cb.equal(root.get(JpaRolloutGroup_.rollout).get(AbstractJpaBaseEntity_.id), rolloutId));

return JpaManagementHelper.findAllWithCountBySpec(rolloutGroupRepository, specList, pageable);
}
Expand Down Expand Up @@ -180,7 +174,8 @@ public Page<Target> findTargetsOfRolloutGroup(final long rolloutGroupId, final P
// in case of status ready the action has not been created yet and
// the relation information between target and rollout-group is
// stored in the #TargetRolloutGroup.
return JpaManagementHelper.findAllWithCountBySpec(targetRepository,
return JpaManagementHelper.findAllWithCountBySpec(
targetRepository,
Collections.singletonList(TargetSpecifications.isInRolloutGroup(rolloutGroupId)), page
);
}
Expand All @@ -190,17 +185,14 @@ public Page<Target> findTargetsOfRolloutGroup(final long rolloutGroupId, final P
}

@Override
public Page<Target> findTargetsOfRolloutGroupByRsql(final Pageable pageable, final long rolloutGroupId,
final String rsqlParam) {
public Page<Target> findTargetsOfRolloutGroupByRsql(final Pageable pageable, final long rolloutGroupId, final String rsqlParam) {
throwExceptionIfRolloutGroupDoesNotExist(rolloutGroupId);

final List<Specification<JpaTarget>> specList = Arrays.asList(
RSQLUtility.buildRsqlSpecification(rsqlParam, TargetFields.class, virtualPropertyReplacer, database),
(root, query, cb) -> {
final ListJoin<JpaTarget, RolloutTargetGroup> rolloutTargetJoin = root
.join(JpaTarget_.rolloutTargetGroup);
return cb.equal(rolloutTargetJoin.get(RolloutTargetGroup_.rolloutGroup).get(JpaRolloutGroup_.id),
rolloutGroupId);
final ListJoin<JpaTarget, RolloutTargetGroup> rolloutTargetJoin = root.join(JpaTarget_.rolloutTargetGroup);
return cb.equal(rolloutTargetJoin.get(RolloutTargetGroup_.rolloutGroup).get(AbstractJpaBaseEntity_.id), rolloutGroupId);
});

return JpaManagementHelper.findAllWithCountBySpec(targetRepository, specList, pageable);
Expand Down Expand Up @@ -273,8 +265,7 @@ private Map<Long, List<TotalTargetCountActionStatus>> getStatusCountItemForRollo

private Predicate getRolloutGroupTargetWithRolloutGroupJoinCondition(final long rolloutGroupId,
final CriteriaBuilder cb, final Root<RolloutTargetGroup> targetRoot) {
return cb.equal(targetRoot.get(RolloutTargetGroup_.rolloutGroup).get(JpaRolloutGroup_.id), //
rolloutGroupId);
return cb.equal(targetRoot.get(RolloutTargetGroup_.rolloutGroup).get(AbstractJpaBaseEntity_.id), rolloutGroupId);
}

private void throwExceptionIfRolloutGroupDoesNotExist(final Long rolloutGroupId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.eclipse.hawkbit.repository.jpa.builder.JpaRolloutGroupCreate;
import org.eclipse.hawkbit.repository.jpa.configuration.Constants;
import org.eclipse.hawkbit.repository.jpa.executor.AfterTransactionCommitExecutor;
import org.eclipse.hawkbit.repository.jpa.model.AbstractJpaBaseEntity_;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet;
import org.eclipse.hawkbit.repository.jpa.model.JpaRollout;
import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup;
Expand Down Expand Up @@ -109,48 +110,57 @@ public class JpaRolloutManagement implements RolloutManagement {
RolloutStatus.CREATING, RolloutStatus.PAUSED, RolloutStatus.READY, RolloutStatus.STARTING,
RolloutStatus.WAITING_FOR_APPROVAL, RolloutStatus.APPROVAL_DENIED);

private final RolloutRepository rolloutRepository;
private final RolloutGroupRepository rolloutGroupRepository;
private final RolloutApprovalStrategy rolloutApprovalStrategy;
private final StartNextGroupRolloutGroupSuccessAction startNextRolloutGroupAction;
private final RolloutStatusCache rolloutStatusCache;
private final ActionRepository actionRepository;
private final TargetManagement targetManagement;
private final DistributionSetManagement distributionSetManagement;
private final VirtualPropertyReplacer virtualPropertyReplacer;
private final RolloutApprovalStrategy rolloutApprovalStrategy;
private final TenantConfigurationManagement tenantConfigurationManagement;
private final SystemSecurityContext systemSecurityContext;
private final QuotaManagement quotaManagement;
private final AfterTransactionCommitExecutor afterCommit;
private final EventPublisherHolder eventPublisherHolder;
private final VirtualPropertyReplacer virtualPropertyReplacer;
private final SystemSecurityContext systemSecurityContext;
private final ContextAware contextAware;
private final Database database;
@Autowired
private RepositoryProperties repositoryProperties;
@Autowired
private RolloutRepository rolloutRepository;
@Autowired
private RolloutGroupRepository rolloutGroupRepository;
@Autowired
private ActionRepository actionRepository;
@Autowired
private AfterTransactionCommitExecutor afterCommit;
@Autowired
private QuotaManagement quotaManagement;
@Autowired
private RolloutStatusCache rolloutStatusCache;
@Autowired
private StartNextGroupRolloutGroupSuccessAction startNextRolloutGroupAction;

public JpaRolloutManagement(final TargetManagement targetManagement,
final DistributionSetManagement distributionSetManagement, final EventPublisherHolder eventPublisherHolder,
final VirtualPropertyReplacer virtualPropertyReplacer, final Database database,
private final RepositoryProperties repositoryProperties;

@SuppressWarnings("java:S107")
public JpaRolloutManagement(
final RolloutRepository rolloutRepository,
final RolloutGroupRepository rolloutGroupRepository,
final RolloutApprovalStrategy rolloutApprovalStrategy,
final StartNextGroupRolloutGroupSuccessAction startNextRolloutGroupAction,
final RolloutStatusCache rolloutStatusCache,
final ActionRepository actionRepository,
final TargetManagement targetManagement,
final DistributionSetManagement distributionSetManagement,
final TenantConfigurationManagement tenantConfigurationManagement,
final SystemSecurityContext systemSecurityContext,
final ContextAware contextAware) {
final QuotaManagement quotaManagement,
final AfterTransactionCommitExecutor afterCommit, final EventPublisherHolder eventPublisherHolder,
final VirtualPropertyReplacer virtualPropertyReplacer,
final SystemSecurityContext systemSecurityContext, final ContextAware contextAware, final Database database,
final RepositoryProperties repositoryProperties) {
this.rolloutRepository = rolloutRepository;
this.rolloutGroupRepository = rolloutGroupRepository;
this.rolloutApprovalStrategy = rolloutApprovalStrategy;
this.startNextRolloutGroupAction = startNextRolloutGroupAction;
this.rolloutStatusCache = rolloutStatusCache;
this.actionRepository = actionRepository;
this.targetManagement = targetManagement;
this.distributionSetManagement = distributionSetManagement;
this.virtualPropertyReplacer = virtualPropertyReplacer;
this.database = database;
this.rolloutApprovalStrategy = rolloutApprovalStrategy;
this.tenantConfigurationManagement = tenantConfigurationManagement;
this.systemSecurityContext = systemSecurityContext;
this.quotaManagement = quotaManagement;
this.afterCommit = afterCommit;
this.eventPublisherHolder = eventPublisherHolder;
this.virtualPropertyReplacer = virtualPropertyReplacer;
this.systemSecurityContext = systemSecurityContext;
this.contextAware = contextAware;
this.database = database;
this.repositoryProperties = repositoryProperties;
}

public static String createRolloutLockKey(final String tenant) {
Expand All @@ -164,7 +174,7 @@ public void publishRolloutGroupCreatedEventAfterCommit(final RolloutGroup group,

@Override
public long count() {
return rolloutRepository.count(RolloutSpecification.isDeleted(false, Sort.by(Direction.DESC, JpaRollout_.ID)));
return rolloutRepository.count(RolloutSpecification.isDeleted(false, Sort.by(Direction.DESC, AbstractJpaBaseEntity_.ID)));
}

@Override
Expand Down
Loading

0 comments on commit 51054bd

Please sign in to comment.