From 51054bdd2f16ce36c6955b2a1b002adf528128bf Mon Sep 17 00:00:00 2001 From: Avgustin Marinov Date: Fri, 24 Jan 2025 13:41:39 +0200 Subject: [PATCH] Sonar Fixes (#2231) Signed-off-by: Avgustin Marinov --- .../repository/jpa/JpaEntityFactory.java | 43 +++++++----- .../repository/jpa/JpaManagementHelper.java | 1 - .../repository/jpa/JpaRolloutExecutor.java | 1 + .../RepositoryApplicationConfiguration.java | 37 +++++++--- .../jpa/builder/JpaRolloutCreate.java | 1 - .../jpa/builder/JpaRolloutGroupCreate.java | 11 +-- .../management/JpaRolloutGroupManagement.java | 27 +++----- .../jpa/management/JpaRolloutManagement.java | 68 +++++++++++-------- .../repository/jpa/model/JpaRollout.java | 9 +-- .../jpa/rsql/JpaQueryRsqlVisitor.java | 1 + .../jpa/rsql/JpaQueryRsqlVisitorG2.java | 14 ++-- .../jpa/tenancy/MultiTenancyEntityTest.java | 16 ++--- 12 files changed, 123 insertions(+), 106 deletions(-) diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaEntityFactory.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaEntityFactory.java index 0826c9f18..f03fd41e1 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaEntityFactory.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaEntityFactory.java @@ -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.JpaTargetMetadata; import org.eclipse.hawkbit.repository.model.MetaData; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; /** @@ -38,23 +37,31 @@ import org.springframework.validation.annotation.Validated; @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(); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaManagementHelper.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaManagementHelper.java index 8aa9663b2..fc1e4bd57 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaManagementHelper.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaManagementHelper.java @@ -29,7 +29,6 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor; 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 diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutExecutor.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutExecutor.java index 929634e31..6984a869a 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutExecutor.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutExecutor.java @@ -121,6 +121,7 @@ public class JpaRolloutExecutor implements RolloutExecutor { private final RepositoryProperties repositoryProperties; private final Map lastDynamicGroupFill = new ConcurrentHashMap<>(); + @SuppressWarnings("java:S107") public JpaRolloutExecutor( final ActionRepository actionRepository, final RolloutGroupRepository rolloutGroupRepository, final RolloutTargetGroupRepository rolloutTargetGroupRepository, diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/RepositoryApplicationConfiguration.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/RepositoryApplicationConfiguration.java index 08e17075e..854ddaf3e 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/RepositoryApplicationConfiguration.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/RepositoryApplicationConfiguration.java @@ -181,6 +181,7 @@ import org.springframework.data.jpa.repository.config.EnableJpaAuditing; 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; @@ -702,16 +703,26 @@ public class RepositoryApplicationConfiguration { @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); } /** @@ -821,8 +832,14 @@ public class RepositoryApplicationConfiguration { */ @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); } /** diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/builder/JpaRolloutCreate.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/builder/JpaRolloutCreate.java index 8780478e8..9bb843657 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/builder/JpaRolloutCreate.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/builder/JpaRolloutCreate.java @@ -21,7 +21,6 @@ import org.eclipse.hawkbit.repository.builder.RolloutCreate; 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 implements RolloutCreate { diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/builder/JpaRolloutGroupCreate.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/builder/JpaRolloutGroupCreate.java index 829ad7f13..107f696ab 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/builder/JpaRolloutGroupCreate.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/builder/JpaRolloutGroupCreate.java @@ -33,17 +33,8 @@ public class JpaRolloutGroupCreate extends AbstractRolloutGroupCreate> 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); } @@ -180,7 +174,8 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement { // 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 ); } @@ -190,17 +185,14 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement { } @Override - public Page findTargetsOfRolloutGroupByRsql(final Pageable pageable, final long rolloutGroupId, - final String rsqlParam) { + public Page findTargetsOfRolloutGroupByRsql(final Pageable pageable, final long rolloutGroupId, final String rsqlParam) { throwExceptionIfRolloutGroupDoesNotExist(rolloutGroupId); final List> specList = Arrays.asList( RSQLUtility.buildRsqlSpecification(rsqlParam, TargetFields.class, virtualPropertyReplacer, database), (root, query, cb) -> { - final ListJoin rolloutTargetJoin = root - .join(JpaTarget_.rolloutTargetGroup); - return cb.equal(rolloutTargetJoin.get(RolloutTargetGroup_.rolloutGroup).get(JpaRolloutGroup_.id), - rolloutGroupId); + final ListJoin rolloutTargetJoin = root.join(JpaTarget_.rolloutTargetGroup); + return cb.equal(rolloutTargetJoin.get(RolloutTargetGroup_.rolloutGroup).get(AbstractJpaBaseEntity_.id), rolloutGroupId); }); return JpaManagementHelper.findAllWithCountBySpec(targetRepository, specList, pageable); @@ -273,8 +265,7 @@ public class JpaRolloutGroupManagement implements RolloutGroupManagement { private Predicate getRolloutGroupTargetWithRolloutGroupJoinCondition(final long rolloutGroupId, final CriteriaBuilder cb, final Root 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) { diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaRolloutManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaRolloutManagement.java index b70871e67..d5d7f686e 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaRolloutManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/management/JpaRolloutManagement.java @@ -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.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; @@ -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; + private final RepositoryProperties repositoryProperties; - public JpaRolloutManagement(final TargetManagement targetManagement, - final DistributionSetManagement distributionSetManagement, final EventPublisherHolder eventPublisherHolder, - final VirtualPropertyReplacer virtualPropertyReplacer, final Database database, + @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) { @@ -164,7 +174,7 @@ public class JpaRolloutManagement implements RolloutManagement { @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 diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRollout.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRollout.java index b0bbe657d..dce785e94 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRollout.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRollout.java @@ -12,7 +12,7 @@ package org.eclipse.hawkbit.repository.jpa.model; import java.io.Serial; import java.util.ArrayList; import java.util.Collections; -import java.util.HashMap; +import java.util.EnumMap; import java.util.List; import java.util.Optional; @@ -61,8 +61,9 @@ import org.eclipse.hawkbit.repository.model.helper.EventPublisherHolder; @Entity @Table(name = "sp_rollout", uniqueConstraints = @UniqueConstraint(columnNames = { "name", "tenant" }, name = "uk_rollout")) @NamedEntityGraphs({ @NamedEntityGraph(name = "Rollout.ds", attributeNodes = { @NamedAttributeNode("distributionSet") }) }) -// exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for sub entities -@SuppressWarnings("squid:S2160") +// squid:S2160 - BaseEntity equals/hashcode is handling correctly for sub entities +// 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 { @Serial @@ -226,7 +227,7 @@ public class JpaRollout extends AbstractJpaNamedEntity implements Rollout, Event public static class RolloutStatusConverter extends MapAttributeConverter { public RolloutStatusConverter() { - super(new HashMap<>() {{ + super(new EnumMap<>(RolloutStatus.class) {{ put(RolloutStatus.CREATING, 0); put(RolloutStatus.READY, 1); put(RolloutStatus.PAUSED, 2); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/JpaQueryRsqlVisitor.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/JpaQueryRsqlVisitor.java index 824b87ef5..0b7ae4140 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/JpaQueryRsqlVisitor.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/JpaQueryRsqlVisitor.java @@ -567,6 +567,7 @@ public class JpaQueryRsqlVisitor & RsqlQueryField, T> extends return childs; } + @SuppressWarnings("java:S1221") // java:S1221 - intentionally to match the SQL wording private Predicate equal(final Expression expressionToCompare, final String sqlValue) { return cb.equal(caseWise(cb, expressionToCompare), caseWise(sqlValue)); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/JpaQueryRsqlVisitorG2.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/JpaQueryRsqlVisitorG2.java index 692fc233d..86b483fa7 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/JpaQueryRsqlVisitorG2.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/JpaQueryRsqlVisitorG2.java @@ -288,13 +288,12 @@ public class JpaQueryRsqlVisitorG2 & RsqlQueryField, T> return fieldPath; } - // if root.get creates a join we call join directly in order to specify LEFT JOIN type, - // to include rows for missing in particular table / criteria (root.get creates INNER JOIN) - // (see org.eclipse.persistence.internal.jpa.querydef.FromImpl implementation for more details) - // otherwise delegate to root.get + // if root.get creates a join we call join directly in order to specify LEFT JOIN type, to include rows for missing in particular + // table / criteria (root.get creates INNER JOIN) (see org.eclipse.persistence.internal.jpa.querydef.FromImpl implementation + // for more details) otherwise delegate to root.get + @SuppressWarnings("java:S1066") // java:S1066 - better reading this way private Path getPath(final Root root, final String fieldNameSplit) { - // see org.eclipse.persistence.internal.jpa.querydef.FromImpl implementation for more details - // when root.get creates a join + // see org.eclipse.persistence.internal.jpa.querydef.FromImpl implementation for more details when root.get creates a join final Attribute attribute = root.getModel().getAttribute(fieldNameSplit); if (!attribute.isCollection()) { // it is a SingularAttribute and not join if it is of basic persistent type @@ -393,7 +392,7 @@ public class JpaQueryRsqlVisitorG2 & RsqlQueryField, T> } return enumField.getSubEntityMapTuple() .map(Entry::getValue) - .map(valueFieldName -> fieldPath. get(valueFieldName)) + .map(fieldPath::get) .orElseThrow(() -> new UnsupportedOperationException( "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 & RsqlQueryField, T> return children; } + @SuppressWarnings("java:S1221") // java:S1221 - intentionally to match the SQL wording private Predicate equal(final Path expressionToCompare, final String sqlValue) { if (caseWise(expressionToCompare)) { return cb.equal(cb.upper(expressionToCompare), sqlValue.toUpperCase()); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/tenancy/MultiTenancyEntityTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/tenancy/MultiTenancyEntityTest.java index 38bd7544e..201154cac 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/tenancy/MultiTenancyEntityTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/tenancy/MultiTenancyEntityTest.java @@ -38,11 +38,11 @@ import org.springframework.data.domain.Slice; @Feature("Component Tests - Repository") @Story("Multi Tenancy") @ExtendWith(DisposableSqlTestDatabaseExtension.class) -public class MultiTenancyEntityTest extends AbstractJpaIntegrationTest { +class MultiTenancyEntityTest extends AbstractJpaIntegrationTest { @Test @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 final String knownControllerId = "controllerId"; @@ -64,9 +64,9 @@ public class MultiTenancyEntityTest extends AbstractJpaIntegrationTest { } @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) - public void queryTargetFromDifferentTenantIsNotVisible() throws Exception { + void queryTargetFromDifferentTenantIsNotVisible() throws Exception { // create target for another tenant final String anotherTenant = "anotherTenant"; final String controllerAnotherTenant = "anotherController"; @@ -86,7 +86,7 @@ public class MultiTenancyEntityTest extends AbstractJpaIntegrationTest { @Test @Description(value = "Ensures that tenant with proper permissions can read and delete other tenants.") @WithUser(tenantId = "mytenant", allSpPermissions = true) - public void deleteAnotherTenantPossible() throws Exception { + void deleteAnotherTenantPossible() throws Exception { // create target for another tenant final String anotherTenant = "anotherTenant"; final String controllerAnotherTenant = "anotherController"; @@ -102,7 +102,7 @@ public class MultiTenancyEntityTest extends AbstractJpaIntegrationTest { @Test @Description(value = "Ensures that tenant metadata is retrieved for the current tenant.") @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 // autogenerated @@ -122,7 +122,7 @@ public class MultiTenancyEntityTest extends AbstractJpaIntegrationTest { @Test @Description(value = "Ensures that targets created from a different tenant cannot be deleted from other tenants") @WithUser(tenantId = "mytenant", allSpPermissions = true) - public void deleteTargetFromOtherTenantIsNotPossible() throws Exception { + void deleteTargetFromOtherTenantIsNotPossible() throws Exception { // create target for another tenant final String anotherTenant = "anotherTenant"; final String controllerAnotherTenant = "anotherController"; @@ -147,7 +147,7 @@ public class MultiTenancyEntityTest extends AbstractJpaIntegrationTest { @Test @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 final String tenant = "aTenant";