Sonar Fixes (#2231)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2025-01-24 13:41:39 +02:00
committed by GitHub
parent d488203b5f
commit 51054bdd2f
12 changed files with 123 additions and 106 deletions

View File

@@ -29,7 +29,6 @@ import org.eclipse.hawkbit.repository.jpa.builder.JpaTagBuilder;
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetMetadata; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetMetadata;
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetMetadata; import org.eclipse.hawkbit.repository.jpa.model.JpaTargetMetadata;
import org.eclipse.hawkbit.repository.model.MetaData; import org.eclipse.hawkbit.repository.model.MetaData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
/** /**
@@ -38,23 +37,31 @@ import org.springframework.validation.annotation.Validated;
@Validated @Validated
public class JpaEntityFactory implements EntityFactory { public class JpaEntityFactory implements EntityFactory {
@Autowired private final TargetBuilder targetBuilder;
private DistributionSetBuilder distributionSetBuilder; private final TargetTypeBuilder targetTypeBuilder;
@Autowired private final TargetFilterQueryBuilder targetFilterQueryBuilder;
private TargetBuilder targetBuilder; private final SoftwareModuleBuilder softwareModuleBuilder;
@Autowired private final SoftwareModuleMetadataBuilder softwareModuleMetadataBuilder;
private DistributionSetTypeBuilder distributionSetTypeBuilder; private final DistributionSetBuilder distributionSetBuilder;
@Autowired private final DistributionSetTypeBuilder distributionSetTypeBuilder;
private SoftwareModuleBuilder softwareModuleBuilder; private final RolloutBuilder rolloutBuilder;
@Autowired
private RolloutBuilder rolloutBuilder; @SuppressWarnings("java:S107")
@Autowired public JpaEntityFactory(
private TargetFilterQueryBuilder targetFilterQueryBuilder; final TargetBuilder targetBuilder, final TargetTypeBuilder targetTypeBuilder,
@Autowired final TargetFilterQueryBuilder targetFilterQueryBuilder,
private SoftwareModuleMetadataBuilder softwareModuleMetadataBuilder; final SoftwareModuleBuilder softwareModuleBuilder, final SoftwareModuleMetadataBuilder softwareModuleMetadataBuilder,
@Autowired final DistributionSetBuilder distributionSetBuilder, final DistributionSetTypeBuilder distributionSetTypeBuilder,
private TargetTypeBuilder targetTypeBuilder; 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 @Override
public ActionStatusBuilder actionStatus() { public ActionStatusBuilder actionStatus() {
return new JpaActionStatusBuilder(); return new JpaActionStatusBuilder();

View File

@@ -29,7 +29,6 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.CrudRepository;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
/** /**
* A collection of static helper methods for the management classes * A collection of static helper methods for the management classes

View File

@@ -121,6 +121,7 @@ public class JpaRolloutExecutor implements RolloutExecutor {
private final RepositoryProperties repositoryProperties; private final RepositoryProperties repositoryProperties;
private final Map<Long, AtomicLong> lastDynamicGroupFill = new ConcurrentHashMap<>(); private final Map<Long, AtomicLong> lastDynamicGroupFill = new ConcurrentHashMap<>();
@SuppressWarnings("java:S107")
public JpaRolloutExecutor( public JpaRolloutExecutor(
final ActionRepository actionRepository, final RolloutGroupRepository rolloutGroupRepository, final ActionRepository actionRepository, final RolloutGroupRepository rolloutGroupRepository,
final RolloutTargetGroupRepository rolloutTargetGroupRepository, final RolloutTargetGroupRepository rolloutTargetGroupRepository,

View File

@@ -181,6 +181,7 @@ import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.integration.support.locks.LockRegistry; import org.springframework.integration.support.locks.LockRegistry;
import org.springframework.lang.NonNull; import org.springframework.lang.NonNull;
import org.springframework.orm.jpa.vendor.Database;
import org.springframework.retry.annotation.EnableRetry; import org.springframework.retry.annotation.EnableRetry;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.PlatformTransactionManager;
@@ -702,16 +703,26 @@ public class RepositoryApplicationConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
RolloutManagement rolloutManagement(final TargetManagement targetManagement, RolloutManagement rolloutManagement(
final DistributionSetManagement distributionSetManagement, final EventPublisherHolder eventPublisherHolder, final RolloutRepository rolloutRepository,
final VirtualPropertyReplacer virtualPropertyReplacer, final JpaProperties properties, final RolloutGroupRepository rolloutGroupRepository,
final RolloutApprovalStrategy rolloutApprovalStrategy, final RolloutApprovalStrategy rolloutApprovalStrategy,
final StartNextGroupRolloutGroupSuccessAction startNextRolloutGroupAction,
final RolloutStatusCache rolloutStatusCache,
final ActionRepository actionRepository,
final TargetManagement targetManagement,
final DistributionSetManagement distributionSetManagement,
final TenantConfigurationManagement tenantConfigurationManagement, final TenantConfigurationManagement tenantConfigurationManagement,
final SystemSecurityContext systemSecurityContext, final QuotaManagement quotaManagement,
final ContextAware contextAware) { final AfterTransactionCommitExecutor afterCommit, final EventPublisherHolder eventPublisherHolder,
return new JpaRolloutManagement(targetManagement, distributionSetManagement, eventPublisherHolder, final VirtualPropertyReplacer virtualPropertyReplacer,
virtualPropertyReplacer, properties.getDatabase(), rolloutApprovalStrategy, final SystemSecurityContext systemSecurityContext, final ContextAware contextAware, final JpaProperties properties,
tenantConfigurationManagement, systemSecurityContext, contextAware); final RepositoryProperties repositoryProperties) {
return new JpaRolloutManagement(rolloutRepository, rolloutGroupRepository, rolloutApprovalStrategy,
startNextRolloutGroupAction, rolloutStatusCache, actionRepository, targetManagement,
distributionSetManagement, tenantConfigurationManagement, quotaManagement, afterCommit,
eventPublisherHolder, virtualPropertyReplacer, systemSecurityContext, contextAware, properties.getDatabase(),
repositoryProperties);
} }
/** /**
@@ -821,8 +832,14 @@ public class RepositoryApplicationConfiguration {
*/ */
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
EntityFactory entityFactory() { EntityFactory entityFactory(
return new 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) {
return new JpaEntityFactory(targetBuilder, targetTypeBuilder, targetFilterQueryBuilder, softwareModuleBuilder,
softwareModuleMetadataBuilder, distributionSetBuilder, distributionSetTypeBuilder, rolloutBuilder);
} }
/** /**

View File

@@ -21,7 +21,6 @@ import org.eclipse.hawkbit.repository.builder.RolloutCreate;
import org.eclipse.hawkbit.repository.jpa.model.JpaRollout; import org.eclipse.hawkbit.repository.jpa.model.JpaRollout;
import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action;
import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.springframework.util.StringUtils;
public class JpaRolloutCreate extends AbstractNamedEntityBuilder<RolloutCreate> implements RolloutCreate { public class JpaRolloutCreate extends AbstractNamedEntityBuilder<RolloutCreate> implements RolloutCreate {

View File

@@ -33,17 +33,8 @@ public class JpaRolloutGroupCreate extends AbstractRolloutGroupCreate<RolloutGro
/** /**
* Set the Success And Error conditions for the rollout group * 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, public static void addSuccessAndErrorConditionsAndActions(final JpaRolloutGroup group,
final RolloutGroup.RolloutGroupSuccessCondition successCondition, final String successConditionExp, final RolloutGroup.RolloutGroupSuccessCondition successCondition, final String successConditionExp,
final RolloutGroup.RolloutGroupSuccessAction successAction, final String successActionExp, final RolloutGroup.RolloutGroupSuccessAction successAction, final String successActionExp,

View File

@@ -29,9 +29,9 @@ import org.eclipse.hawkbit.repository.RolloutStatusCache;
import org.eclipse.hawkbit.repository.TargetFields; import org.eclipse.hawkbit.repository.TargetFields;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.jpa.JpaManagementHelper; 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.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.JpaTarget_; import org.eclipse.hawkbit.repository.jpa.model.JpaTarget_;
import org.eclipse.hawkbit.repository.jpa.model.RolloutTargetGroup; import org.eclipse.hawkbit.repository.jpa.model.RolloutTargetGroup;
@@ -66,21 +66,15 @@ import org.springframework.validation.annotation.Validated;
public class JpaRolloutGroupManagement implements RolloutGroupManagement { public class JpaRolloutGroupManagement implements RolloutGroupManagement {
private final RolloutGroupRepository rolloutGroupRepository; private final RolloutGroupRepository rolloutGroupRepository;
private final RolloutRepository rolloutRepository; private final RolloutRepository rolloutRepository;
private final ActionRepository actionRepository; private final ActionRepository actionRepository;
private final TargetRepository targetRepository; private final TargetRepository targetRepository;
private final EntityManager entityManager; private final EntityManager entityManager;
private final VirtualPropertyReplacer virtualPropertyReplacer; private final VirtualPropertyReplacer virtualPropertyReplacer;
private final RolloutStatusCache rolloutStatusCache; private final RolloutStatusCache rolloutStatusCache;
private final Database database; private final Database database;
@SuppressWarnings("java:S107")
public JpaRolloutGroupManagement(final RolloutGroupRepository rolloutGroupRepository, public JpaRolloutGroupManagement(final RolloutGroupRepository rolloutGroupRepository,
final RolloutRepository rolloutRepository, final ActionRepository actionRepository, final RolloutRepository rolloutRepository, final ActionRepository actionRepository,
final TargetRepository targetRepository, final EntityManager entityManager, final TargetRepository targetRepository, final EntityManager entityManager,
@@ -130,7 +124,7 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
final List<Specification<JpaRolloutGroup>> specList = Arrays.asList( final List<Specification<JpaRolloutGroup>> specList = Arrays.asList(
RSQLUtility.buildRsqlSpecification(rsqlParam, RolloutGroupFields.class, virtualPropertyReplacer, RSQLUtility.buildRsqlSpecification(rsqlParam, RolloutGroupFields.class, virtualPropertyReplacer,
database), 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); return JpaManagementHelper.findAllWithCountBySpec(rolloutGroupRepository, specList, pageable);
} }
@@ -180,7 +174,8 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
// in case of status ready the action has not been created yet and // in case of status ready the action has not been created yet and
// the relation information between target and rollout-group is // the relation information between target and rollout-group is
// stored in the #TargetRolloutGroup. // stored in the #TargetRolloutGroup.
return JpaManagementHelper.findAllWithCountBySpec(targetRepository, return JpaManagementHelper.findAllWithCountBySpec(
targetRepository,
Collections.singletonList(TargetSpecifications.isInRolloutGroup(rolloutGroupId)), page Collections.singletonList(TargetSpecifications.isInRolloutGroup(rolloutGroupId)), page
); );
} }
@@ -190,17 +185,14 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
} }
@Override @Override
public Page<Target> findTargetsOfRolloutGroupByRsql(final Pageable pageable, final long rolloutGroupId, public Page<Target> findTargetsOfRolloutGroupByRsql(final Pageable pageable, final long rolloutGroupId, final String rsqlParam) {
final String rsqlParam) {
throwExceptionIfRolloutGroupDoesNotExist(rolloutGroupId); throwExceptionIfRolloutGroupDoesNotExist(rolloutGroupId);
final List<Specification<JpaTarget>> specList = Arrays.asList( final List<Specification<JpaTarget>> specList = Arrays.asList(
RSQLUtility.buildRsqlSpecification(rsqlParam, TargetFields.class, virtualPropertyReplacer, database), RSQLUtility.buildRsqlSpecification(rsqlParam, TargetFields.class, virtualPropertyReplacer, database),
(root, query, cb) -> { (root, query, cb) -> {
final ListJoin<JpaTarget, RolloutTargetGroup> rolloutTargetJoin = root final ListJoin<JpaTarget, RolloutTargetGroup> rolloutTargetJoin = root.join(JpaTarget_.rolloutTargetGroup);
.join(JpaTarget_.rolloutTargetGroup); return cb.equal(rolloutTargetJoin.get(RolloutTargetGroup_.rolloutGroup).get(AbstractJpaBaseEntity_.id), rolloutGroupId);
return cb.equal(rolloutTargetJoin.get(RolloutTargetGroup_.rolloutGroup).get(JpaRolloutGroup_.id),
rolloutGroupId);
}); });
return JpaManagementHelper.findAllWithCountBySpec(targetRepository, specList, pageable); return JpaManagementHelper.findAllWithCountBySpec(targetRepository, specList, pageable);
@@ -273,8 +265,7 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement {
private Predicate getRolloutGroupTargetWithRolloutGroupJoinCondition(final long rolloutGroupId, private Predicate getRolloutGroupTargetWithRolloutGroupJoinCondition(final long rolloutGroupId,
final CriteriaBuilder cb, final Root<RolloutTargetGroup> targetRoot) { final CriteriaBuilder cb, final Root<RolloutTargetGroup> targetRoot) {
return cb.equal(targetRoot.get(RolloutTargetGroup_.rolloutGroup).get(JpaRolloutGroup_.id), // return cb.equal(targetRoot.get(RolloutTargetGroup_.rolloutGroup).get(AbstractJpaBaseEntity_.id), rolloutGroupId);
rolloutGroupId);
} }
private void throwExceptionIfRolloutGroupDoesNotExist(final Long rolloutGroupId) { private void throwExceptionIfRolloutGroupDoesNotExist(final Long rolloutGroupId) {

View File

@@ -52,6 +52,7 @@ import org.eclipse.hawkbit.repository.jpa.JpaManagementHelper;
import org.eclipse.hawkbit.repository.jpa.builder.JpaRolloutGroupCreate; import org.eclipse.hawkbit.repository.jpa.builder.JpaRolloutGroupCreate;
import org.eclipse.hawkbit.repository.jpa.configuration.Constants; import org.eclipse.hawkbit.repository.jpa.configuration.Constants;
import org.eclipse.hawkbit.repository.jpa.executor.AfterTransactionCommitExecutor; 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.JpaDistributionSet;
import org.eclipse.hawkbit.repository.jpa.model.JpaRollout; import org.eclipse.hawkbit.repository.jpa.model.JpaRollout;
import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup; import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup;
@@ -109,48 +110,57 @@ public class JpaRolloutManagement implements RolloutManagement {
RolloutStatus.CREATING, RolloutStatus.PAUSED, RolloutStatus.READY, RolloutStatus.STARTING, RolloutStatus.CREATING, RolloutStatus.PAUSED, RolloutStatus.READY, RolloutStatus.STARTING,
RolloutStatus.WAITING_FOR_APPROVAL, RolloutStatus.APPROVAL_DENIED); 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 TargetManagement targetManagement;
private final DistributionSetManagement distributionSetManagement; private final DistributionSetManagement distributionSetManagement;
private final VirtualPropertyReplacer virtualPropertyReplacer;
private final RolloutApprovalStrategy rolloutApprovalStrategy;
private final TenantConfigurationManagement tenantConfigurationManagement; private final TenantConfigurationManagement tenantConfigurationManagement;
private final SystemSecurityContext systemSecurityContext; private final QuotaManagement quotaManagement;
private final AfterTransactionCommitExecutor afterCommit;
private final EventPublisherHolder eventPublisherHolder; private final EventPublisherHolder eventPublisherHolder;
private final VirtualPropertyReplacer virtualPropertyReplacer;
private final SystemSecurityContext systemSecurityContext;
private final ContextAware contextAware; private final ContextAware contextAware;
private final Database database; private final Database database;
@Autowired private final RepositoryProperties repositoryProperties;
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, @SuppressWarnings("java:S107")
final DistributionSetManagement distributionSetManagement, final EventPublisherHolder eventPublisherHolder, public JpaRolloutManagement(
final VirtualPropertyReplacer virtualPropertyReplacer, final Database database, final RolloutRepository rolloutRepository,
final RolloutGroupRepository rolloutGroupRepository,
final RolloutApprovalStrategy rolloutApprovalStrategy, final RolloutApprovalStrategy rolloutApprovalStrategy,
final StartNextGroupRolloutGroupSuccessAction startNextRolloutGroupAction,
final RolloutStatusCache rolloutStatusCache,
final ActionRepository actionRepository,
final TargetManagement targetManagement,
final DistributionSetManagement distributionSetManagement,
final TenantConfigurationManagement tenantConfigurationManagement, final TenantConfigurationManagement tenantConfigurationManagement,
final SystemSecurityContext systemSecurityContext, final QuotaManagement quotaManagement,
final ContextAware contextAware) { 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.targetManagement = targetManagement;
this.distributionSetManagement = distributionSetManagement; this.distributionSetManagement = distributionSetManagement;
this.virtualPropertyReplacer = virtualPropertyReplacer;
this.database = database;
this.rolloutApprovalStrategy = rolloutApprovalStrategy;
this.tenantConfigurationManagement = tenantConfigurationManagement; this.tenantConfigurationManagement = tenantConfigurationManagement;
this.systemSecurityContext = systemSecurityContext; this.quotaManagement = quotaManagement;
this.afterCommit = afterCommit;
this.eventPublisherHolder = eventPublisherHolder; this.eventPublisherHolder = eventPublisherHolder;
this.virtualPropertyReplacer = virtualPropertyReplacer;
this.systemSecurityContext = systemSecurityContext;
this.contextAware = contextAware; this.contextAware = contextAware;
this.database = database;
this.repositoryProperties = repositoryProperties;
} }
public static String createRolloutLockKey(final String tenant) { public static String createRolloutLockKey(final String tenant) {
@@ -164,7 +174,7 @@ public class JpaRolloutManagement implements RolloutManagement {
@Override @Override
public long count() { 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 @Override

View File

@@ -12,7 +12,7 @@ package org.eclipse.hawkbit.repository.jpa.model;
import java.io.Serial; import java.io.Serial;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.EnumMap;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
@@ -61,8 +61,9 @@ import org.eclipse.hawkbit.repository.model.helper.EventPublisherHolder;
@Entity @Entity
@Table(name = "sp_rollout", uniqueConstraints = @UniqueConstraint(columnNames = { "name", "tenant" }, name = "uk_rollout")) @Table(name = "sp_rollout", uniqueConstraints = @UniqueConstraint(columnNames = { "name", "tenant" }, name = "uk_rollout"))
@NamedEntityGraphs({ @NamedEntityGraph(name = "Rollout.ds", attributeNodes = { @NamedAttributeNode("distributionSet") }) }) @NamedEntityGraphs({ @NamedEntityGraph(name = "Rollout.ds", attributeNodes = { @NamedAttributeNode("distributionSet") }) })
// exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for sub entities // 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", "java:S1171", "java:S3599" })
public class JpaRollout extends AbstractJpaNamedEntity implements Rollout, EventAwareEntity { public class JpaRollout extends AbstractJpaNamedEntity implements Rollout, EventAwareEntity {
@Serial @Serial
@@ -226,7 +227,7 @@ public class JpaRollout extends AbstractJpaNamedEntity implements Rollout, Event
public static class RolloutStatusConverter extends MapAttributeConverter<RolloutStatus, Integer> { public static class RolloutStatusConverter extends MapAttributeConverter<RolloutStatus, Integer> {
public RolloutStatusConverter() { public RolloutStatusConverter() {
super(new HashMap<>() {{ super(new EnumMap<>(RolloutStatus.class) {{
put(RolloutStatus.CREATING, 0); put(RolloutStatus.CREATING, 0);
put(RolloutStatus.READY, 1); put(RolloutStatus.READY, 1);
put(RolloutStatus.PAUSED, 2); put(RolloutStatus.PAUSED, 2);

View File

@@ -567,6 +567,7 @@ public class JpaQueryRsqlVisitor<A extends Enum<A> & RsqlQueryField, T> extends
return childs; return childs;
} }
@SuppressWarnings("java:S1221") // java:S1221 - intentionally to match the SQL wording
private Predicate equal(final Expression<String> expressionToCompare, final String sqlValue) { private Predicate equal(final Expression<String> expressionToCompare, final String sqlValue) {
return cb.equal(caseWise(cb, expressionToCompare), caseWise(sqlValue)); return cb.equal(caseWise(cb, expressionToCompare), caseWise(sqlValue));
} }

View File

@@ -288,13 +288,12 @@ public class JpaQueryRsqlVisitorG2<A extends Enum<A> & RsqlQueryField, T>
return fieldPath; return fieldPath;
} }
// if root.get creates a join we call join directly in order to specify LEFT JOIN type, // if root.get creates a join we call join directly in order to specify LEFT JOIN type, to include rows for missing in particular
// to include rows for missing in particular table / criteria (root.get creates INNER JOIN) // table / criteria (root.get creates INNER JOIN) (see org.eclipse.persistence.internal.jpa.querydef.FromImpl implementation
// (see org.eclipse.persistence.internal.jpa.querydef.FromImpl implementation for more details) // for more details) otherwise delegate to root.get
// otherwise delegate to root.get @SuppressWarnings("java:S1066") // java:S1066 - better reading this way
private Path<?> getPath(final Root<?> root, final String fieldNameSplit) { private Path<?> getPath(final Root<?> root, final String fieldNameSplit) {
// see org.eclipse.persistence.internal.jpa.querydef.FromImpl implementation for more details // see org.eclipse.persistence.internal.jpa.querydef.FromImpl implementation for more details when root.get creates a join
// when root.get creates a join
final Attribute<?, ?> attribute = root.getModel().getAttribute(fieldNameSplit); final Attribute<?, ?> attribute = root.getModel().getAttribute(fieldNameSplit);
if (!attribute.isCollection()) { if (!attribute.isCollection()) {
// it is a SingularAttribute and not join if it is of basic persistent type // it is a SingularAttribute and not join if it is of basic persistent type
@@ -393,7 +392,7 @@ public class JpaQueryRsqlVisitorG2<A extends Enum<A> & RsqlQueryField, T>
} }
return enumField.getSubEntityMapTuple() return enumField.getSubEntityMapTuple()
.map(Entry::getValue) .map(Entry::getValue)
.map(valueFieldName -> fieldPath.<String> get(valueFieldName)) .map(fieldPath::<String>get)
.orElseThrow(() -> .orElseThrow(() ->
new UnsupportedOperationException( new UnsupportedOperationException(
"For the fields, defined as Map, only Map java type or tuple in the form of SimpleImmutableEntry are allowed." + "For the fields, defined as Map, only Map java type or tuple in the form of SimpleImmutableEntry are allowed." +
@@ -434,6 +433,7 @@ public class JpaQueryRsqlVisitorG2<A extends Enum<A> & RsqlQueryField, T>
return children; return children;
} }
@SuppressWarnings("java:S1221") // java:S1221 - intentionally to match the SQL wording
private Predicate equal(final Path<String> expressionToCompare, final String sqlValue) { private Predicate equal(final Path<String> expressionToCompare, final String sqlValue) {
if (caseWise(expressionToCompare)) { if (caseWise(expressionToCompare)) {
return cb.equal(cb.upper(expressionToCompare), sqlValue.toUpperCase()); return cb.equal(cb.upper(expressionToCompare), sqlValue.toUpperCase());

View File

@@ -38,11 +38,11 @@ import org.springframework.data.domain.Slice;
@Feature("Component Tests - Repository") @Feature("Component Tests - Repository")
@Story("Multi Tenancy") @Story("Multi Tenancy")
@ExtendWith(DisposableSqlTestDatabaseExtension.class) @ExtendWith(DisposableSqlTestDatabaseExtension.class)
public class MultiTenancyEntityTest extends AbstractJpaIntegrationTest { class MultiTenancyEntityTest extends AbstractJpaIntegrationTest {
@Test @Test
@Description(value = "Ensures that multiple targets with same controller-ID can be created for different tenants.") @Description(value = "Ensures that multiple targets with same controller-ID can be created for different tenants.")
public void createMultipleTargetsWithSameIdForDifferentTenant() throws Exception { void createMultipleTargetsWithSameIdForDifferentTenant() throws Exception {
// known controller ID for overall tenants same // known controller ID for overall tenants same
final String knownControllerId = "controllerId"; final String knownControllerId = "controllerId";
@@ -64,9 +64,9 @@ public class MultiTenancyEntityTest extends AbstractJpaIntegrationTest {
} }
@Test @Test
@Description(value = "Ensures that targtes created by a tenant are not visible by another tenant.") @Description(value = "Ensures that targets created by a tenant are not visible by another tenant.")
@WithUser(tenantId = "mytenant", allSpPermissions = true) @WithUser(tenantId = "mytenant", allSpPermissions = true)
public void queryTargetFromDifferentTenantIsNotVisible() throws Exception { void queryTargetFromDifferentTenantIsNotVisible() throws Exception {
// create target for another tenant // create target for another tenant
final String anotherTenant = "anotherTenant"; final String anotherTenant = "anotherTenant";
final String controllerAnotherTenant = "anotherController"; final String controllerAnotherTenant = "anotherController";
@@ -86,7 +86,7 @@ public class MultiTenancyEntityTest extends AbstractJpaIntegrationTest {
@Test @Test
@Description(value = "Ensures that tenant with proper permissions can read and delete other tenants.") @Description(value = "Ensures that tenant with proper permissions can read and delete other tenants.")
@WithUser(tenantId = "mytenant", allSpPermissions = true) @WithUser(tenantId = "mytenant", allSpPermissions = true)
public void deleteAnotherTenantPossible() throws Exception { void deleteAnotherTenantPossible() throws Exception {
// create target for another tenant // create target for another tenant
final String anotherTenant = "anotherTenant"; final String anotherTenant = "anotherTenant";
final String controllerAnotherTenant = "anotherController"; final String controllerAnotherTenant = "anotherController";
@@ -102,7 +102,7 @@ public class MultiTenancyEntityTest extends AbstractJpaIntegrationTest {
@Test @Test
@Description(value = "Ensures that tenant metadata is retrieved for the current tenant.") @Description(value = "Ensures that tenant metadata is retrieved for the current tenant.")
@WithUser(tenantId = "mytenant", autoCreateTenant = false, allSpPermissions = true) @WithUser(tenantId = "mytenant", autoCreateTenant = false, allSpPermissions = true)
public void getTenanatMetdata() throws Exception { void getTenanatMetdata() throws Exception {
// logged in tenant mytenant - check if tenant default data is // logged in tenant mytenant - check if tenant default data is
// autogenerated // autogenerated
@@ -122,7 +122,7 @@ public class MultiTenancyEntityTest extends AbstractJpaIntegrationTest {
@Test @Test
@Description(value = "Ensures that targets created from a different tenant cannot be deleted from other tenants") @Description(value = "Ensures that targets created from a different tenant cannot be deleted from other tenants")
@WithUser(tenantId = "mytenant", allSpPermissions = true) @WithUser(tenantId = "mytenant", allSpPermissions = true)
public void deleteTargetFromOtherTenantIsNotPossible() throws Exception { void deleteTargetFromOtherTenantIsNotPossible() throws Exception {
// create target for another tenant // create target for another tenant
final String anotherTenant = "anotherTenant"; final String anotherTenant = "anotherTenant";
final String controllerAnotherTenant = "anotherController"; final String controllerAnotherTenant = "anotherController";
@@ -147,7 +147,7 @@ public class MultiTenancyEntityTest extends AbstractJpaIntegrationTest {
@Test @Test
@Description(value = "Ensures that multiple distribution sets with same name and version can be created for different tenants.") @Description(value = "Ensures that multiple distribution sets with same name and version can be created for different tenants.")
public void createMultipleDistributionSetsWithSameNameForDifferentTenants() throws Exception { void createMultipleDistributionSetsWithSameNameForDifferentTenants() throws Exception {
// known tenant names // known tenant names
final String tenant = "aTenant"; final String tenant = "aTenant";